@reason-machines/cli-linux-arm64-musl 0.2.358 → 0.2.360

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/bin/ara +1 -1
  2. package/bin/vm-hands/api-credentials-vtpssnm1.js +2 -0
  3. package/bin/vm-hands/api-dvwzjwmh.js +2 -0
  4. package/bin/vm-hands/ask-relay-0y716ck6.js +8 -0
  5. package/bin/vm-hands/connect-cli-sbczes1h.js +2 -0
  6. package/bin/vm-hands/custom-endpoint-device-8v87dhjx.js +2 -0
  7. package/bin/vm-hands/desktop-account-q57958y1.js +2 -0
  8. package/bin/vm-hands/{device-workspace-7yg5x68n.js → device-workspace-c05vq771.js} +1 -1
  9. package/bin/vm-hands/hands-worker-source-wfv9csj2.js +2 -0
  10. package/bin/vm-hands/{index-swa20ch8.js → index-80ep9259.js} +1 -1
  11. package/bin/vm-hands/install-receipt-pbfhgaxc.js +2 -0
  12. package/bin/vm-hands/local-automation-j8402b7e.js +2 -0
  13. package/bin/vm-hands/local-capabilities-yekmdbpc.js +2 -0
  14. package/bin/vm-hands/local-desktop-users-m7rexsex.js +2 -0
  15. package/bin/vm-hands/local-display-mac-9de01n3r.js +2 -0
  16. package/bin/vm-hands/local-display-session-d3hvgjqs.js +2 -0
  17. package/bin/vm-hands/local-pty-session-e7j0kj19.js +2 -0
  18. package/bin/vm-hands/managed-runtime-r1138kvq.js +2 -0
  19. package/bin/vm-hands/{network-contract-rm9x646s.js → network-contract-zjq3w2n3.js} +1 -1
  20. package/bin/vm-hands/package-44a3p8yk.js +2 -0
  21. package/bin/vm-hands/permissions-g0asz6w1.js +2 -0
  22. package/bin/vm-hands/{reason-hands-protocol-3z7bas06.js → reason-hands-protocol-aj1zwpk0.js} +1 -1
  23. package/bin/vm-hands/serve-service-9jd2zcmb.js +2 -0
  24. package/bin/vm-hands/{status-psxtsknj.js → status-7v31d0ab.js} +2 -2
  25. package/bin/vm-hands/version-2fvzdbmj.js +2 -0
  26. package/bin/vm-hands/vm-hands-entry-lite-0763vz5v.js +3 -0
  27. package/bin/vm-hands/vm-hands-entry-lite-1hv536wk.js +3 -0
  28. package/bin/vm-hands/{vm-hands-entry-lite-0hv9ek0t.js → vm-hands-entry-lite-2j67g42s.js} +9 -68
  29. package/bin/vm-hands/{vm-hands-entry-lite-0tdpjsxc.js → vm-hands-entry-lite-3qxye8en.js} +2 -2
  30. package/bin/vm-hands/vm-hands-entry-lite-3tf5zyba.js +9 -0
  31. package/bin/vm-hands/{vm-hands-entry-lite-rr0hhz7g.js → vm-hands-entry-lite-4rd6b2ra.js} +3 -3
  32. package/bin/vm-hands/vm-hands-entry-lite-4xfs7y6w.js +3 -0
  33. package/bin/vm-hands/{vm-hands-entry-lite-xhjbc3e4.js → vm-hands-entry-lite-5y2kfnv2.js} +2 -2
  34. package/bin/vm-hands/{vm-hands-entry-lite-trcg4jv7.js → vm-hands-entry-lite-6fvjbwqq.js} +2 -2
  35. package/bin/vm-hands/{vm-hands-entry-lite-dys7am1h.js → vm-hands-entry-lite-7nk0873d.js} +2 -2
  36. package/bin/vm-hands/{vm-hands-entry-lite-zrvaqawr.js → vm-hands-entry-lite-97zxda1y.js} +2 -2
  37. package/bin/vm-hands/{vm-hands-entry-lite-c9wp99nr.js → vm-hands-entry-lite-avstvbbc.js} +2 -2
  38. package/bin/vm-hands/vm-hands-entry-lite-cety9pka.js +5 -0
  39. package/bin/vm-hands/vm-hands-entry-lite-cwf21py1.js +3 -0
  40. package/bin/vm-hands/{vm-hands-entry-lite-84d59wrf.js → vm-hands-entry-lite-dqnhebfx.js} +1 -1
  41. package/bin/vm-hands/{vm-hands-entry-lite-nvhzj5b0.js → vm-hands-entry-lite-f4gvypnx.js} +1 -1
  42. package/bin/vm-hands/{vm-hands-entry-lite-qf01e5f1.js → vm-hands-entry-lite-fr2k6eah.js} +2 -2
  43. package/bin/vm-hands/{vm-hands-entry-lite-wpx6sg6d.js → vm-hands-entry-lite-gxjxx1r2.js} +2 -2
  44. package/bin/vm-hands/vm-hands-entry-lite-hfq6jjnh.js +3 -0
  45. package/bin/vm-hands/{vm-hands-entry-lite-nd1k2jz9.js → vm-hands-entry-lite-hw8vgsmm.js} +1 -1
  46. package/bin/vm-hands/{vm-hands-entry-lite-8jmwhybq.js → vm-hands-entry-lite-jc229h5p.js} +2 -2
  47. package/bin/vm-hands/{vm-hands-entry-lite-6f5eypjm.js → vm-hands-entry-lite-jjkkee8q.js} +2 -2
  48. package/bin/vm-hands/{vm-hands-entry-lite-beannz0s.js → vm-hands-entry-lite-jpkf3569.js} +2 -2
  49. package/bin/vm-hands/{vm-hands-entry-lite-k17ntg9v.js → vm-hands-entry-lite-k7fkfytm.js} +2 -2
  50. package/bin/vm-hands/{vm-hands-entry-lite-tj1y61bg.js → vm-hands-entry-lite-kxtjkzzh.js} +1 -1
  51. package/bin/vm-hands/{vm-hands-entry-lite-he2z2137.js → vm-hands-entry-lite-ne0nrjkn.js} +2 -2
  52. package/bin/vm-hands/{vm-hands-entry-lite-3zxjyj62.js → vm-hands-entry-lite-nnvyvx1n.js} +3 -3
  53. package/bin/vm-hands/vm-hands-entry-lite-npqaxsmx.js +11 -0
  54. package/bin/vm-hands/vm-hands-entry-lite-p1nb6n3r.js +3 -0
  55. package/bin/vm-hands/vm-hands-entry-lite-qqyrwyfz.js +37 -0
  56. package/bin/vm-hands/{vm-hands-entry-lite-jfwz0br7.js → vm-hands-entry-lite-qy9xzp2m.js} +2 -2
  57. package/bin/vm-hands/{vm-hands-entry-lite-c8hfat7y.js → vm-hands-entry-lite-rkt48xf4.js} +2 -2
  58. package/bin/vm-hands/{vm-hands-entry-lite-5b29hq7h.js → vm-hands-entry-lite-tbps80f1.js} +2 -2
  59. package/bin/vm-hands/vm-hands-entry-lite-v1amz3pq.js +62 -0
  60. package/bin/vm-hands/{vm-hands-entry-lite-mybm2kyz.js → vm-hands-entry-lite-vcm4389c.js} +2 -2
  61. package/bin/vm-hands/vm-hands-entry-lite-wej1p1ry.js +3 -0
  62. package/bin/vm-hands/{vm-hands-entry-lite-gcn3rmz6.js → vm-hands-entry-lite-wry37am5.js} +1 -1
  63. package/bin/vm-hands/vm-hands-entry-lite-x7204pcv.js +340 -0
  64. package/bin/vm-hands/{vm-hands-entry-lite-nbtpm59m.js → vm-hands-entry-lite-xhr0m9r0.js} +2 -2
  65. package/bin/vm-hands/vm-hands-entry-lite-xj0p1ax7.js +5 -0
  66. package/bin/vm-hands/{vm-hands-entry-lite-95k4g3jj.js → vm-hands-entry-lite-zn303jrg.js} +1 -1
  67. package/bin/vm-hands/vm-hands-entry-lite.js +1 -1
  68. package/bin/vm-hands/{vm-hands-executor-dqqdgtqq.js → vm-hands-executor-xcscxb3s.js} +1 -1
  69. package/bin/vm-hands/vm-hands-op-runner-tm0sh7y6.js +2 -0
  70. package/bin/vm-hands/{vm-hands-runtime-y89fmev1.js → vm-hands-runtime-3yg846f8.js} +3 -3
  71. package/bin/vm-hands/worker-sandbox-wb5thd4n.js +2 -0
  72. package/package.json +1 -1
  73. package/bin/vm-hands/api-credentials-emdf5nm5.js +0 -2
  74. package/bin/vm-hands/api-js29ghm5.js +0 -2
  75. package/bin/vm-hands/ask-relay-qv9ddzr1.js +0 -8
  76. package/bin/vm-hands/connect-cli-8nxph9td.js +0 -2
  77. package/bin/vm-hands/custom-endpoint-device-j3e3zjd5.js +0 -2
  78. package/bin/vm-hands/desktop-account-gcysz0m3.js +0 -2
  79. package/bin/vm-hands/hands-worker-source-hbp5n31r.js +0 -2
  80. package/bin/vm-hands/local-automation-nw3bj9b5.js +0 -2
  81. package/bin/vm-hands/local-capabilities-7m54wthn.js +0 -2
  82. package/bin/vm-hands/local-desktop-users-pccz3sz9.js +0 -2
  83. package/bin/vm-hands/local-display-mac-gj72gkfb.js +0 -2
  84. package/bin/vm-hands/local-display-session-5ajajxtg.js +0 -2
  85. package/bin/vm-hands/local-pty-session-zen80k1k.js +0 -2
  86. package/bin/vm-hands/package-1e3w44ve.js +0 -2
  87. package/bin/vm-hands/permissions-0ej6xgrj.js +0 -2
  88. package/bin/vm-hands/version-fw3dwa12.js +0 -2
  89. package/bin/vm-hands/vm-hands-entry-lite-33ttamma.js +0 -5
  90. package/bin/vm-hands/vm-hands-entry-lite-3ms5bb0b.js +0 -43
  91. package/bin/vm-hands/vm-hands-entry-lite-6qfax5p2.js +0 -3
  92. package/bin/vm-hands/vm-hands-entry-lite-d9k3dzaq.js +0 -3
  93. package/bin/vm-hands/vm-hands-entry-lite-dyy62gt3.js +0 -3
  94. package/bin/vm-hands/vm-hands-entry-lite-pm0j47qj.js +0 -343
  95. package/bin/vm-hands/vm-hands-entry-lite-tdgbgcer.js +0 -3
  96. package/bin/vm-hands/vm-hands-op-runner-msdteb31.js +0 -2
  97. package/bin/vm-hands/worker-sandbox-yw24sxyp.js +0 -2
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{ce as xe}from"./vm-hands-entry-lite-qf01e5f1.js";import{Ae as W,Be as oe,De as _t,Ee as Ne,He as St,Ie as wt,Je as $,Se as z,Te as Je}from"./vm-hands-entry-lite-he2z2137.js";import{Ye as Se}from"./vm-hands-entry-lite-xhjbc3e4.js";import{_e as Jt,bf as xt,ef as Z,gf as zt,hf as ae}from"./vm-hands-entry-lite-3ms5bb0b.js";import{Lf as Ae,Mf as se}from"./vm-hands-entry-lite-c9wp99nr.js";import{Eh as Ot,sh as v,uh as tt,vh as D}from"./vm-hands-entry-lite-6qfax5p2.js";import{Kh as q}from"./vm-hands-entry-lite-5b29hq7h.js";import{ji as pe,pi as ye}from"./vm-hands-entry-lite-6f5eypjm.js";import{qi as _}from"./vm-hands-entry-lite-tj1y61bg.js";import{spawn as I}from"child_process";import{randomUUID as Oe}from"crypto";import{closeSync as Vr,copyFileSync as de,existsSync as ut,fstatSync as Er,mkdirSync as fe,openSync as vr,readdirSync as V,readFileSync as ge,readlinkSync as to,renameSync as eo,rmSync as ro,statSync as oo}from"fs";import{connect as so}from"net";import{userInfo as Te}from"os";import{basename as le,dirname as mt,join as b}from"path";var At=`import { spawn, execFileSync } from "node:child_process";
2
+ import{Id as ie,Kd as oe}from"./vm-hands-entry-lite-v1amz3pq.js";import{jf as he}from"./vm-hands-entry-lite-fr2k6eah.js";import{Hf as q,If as ee,Kf as D,Lf as ye,Of as W,Pf as z,Qf as v,Zf as T,_f as Fe}from"./vm-hands-entry-lite-ne0nrjkn.js";import{Eg as ge}from"./vm-hands-entry-lite-5y2kfnv2.js";import{qi as re}from"./vm-hands-entry-lite-qqyrwyfz.js";import{Mi as J}from"./vm-hands-entry-lite-3tf5zyba.js";import{Si as y}from"./vm-hands-entry-lite-tbps80f1.js";import{Jj as xe,Kj as te}from"./vm-hands-entry-lite-avstvbbc.js";import{Qj as be,Wj as we}from"./vm-hands-entry-lite-jjkkee8q.js";import{Xj as f}from"./vm-hands-entry-lite-kxtjkzzh.js";import{spawn as O}from"child_process";import{randomUUID as Se}from"crypto";import{closeSync as ct,copyFileSync as ce,existsSync as G,fstatSync as lt,mkdirSync as le,openSync as ut,readdirSync as F,readFileSync as Ae,readlinkSync as dt,renameSync as ft,rmSync as mt,statSync as pt}from"fs";import{connect as _t}from"net";import{userInfo as Oe}from"os";import{basename as ue,dirname as U,join as _}from"path";var V=`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";
@@ -691,70 +691,11 @@ if(process.env.REASON_CLOUD_GATEWAY_EXEC === "1") {
691
691
  process.stdout.write(JSON.stringify(cloudAutomationFailure(error))+"\\n");process.exitCode=1;
692
692
  }
693
693
  }
694
- `;import{spawn as De}from"child_process";import{basename as Me}from"path";var Pe="__desktop-call",Ze="/usr/bin/setpriv",he=27262976,Qe=8192,ke=2000;function E(t){return Boolean(t)&&typeof t==="object"&&!Array.isArray(t)}function Ye(t){try{return JSON.parse(t)}catch{return null}}function Xe(){return[process.execPath,...Me(process.execPath).startsWith("bun")&&process.argv[1]?[process.argv[1]]:[],Pe]}function We(t,e,r,o={}){r.throwIfAborted();let s=o.command??Xe();return new Promise((a,c)=>{let i=(o.spawnProcess??De)(Ze,[`--reuid=${t.uid}`,`--regid=${t.gid}`,"--clear-groups","--no-new-privs","--",...s],{cwd:t.home,detached:!0,stdio:["pipe","pipe","pipe"],env:{HOME:t.home,USER:t.username,LOGNAME:t.username,PATH:"/usr/local/bin:/usr/bin:/bin"}}),d=[],f=0,n="",l=null,u=!1,m,S=(x)=>{try{process.kill(-i.pid,x)}catch{i.kill(x)}},B=(x)=>{l??=x,S("SIGTERM"),m??=setTimeout(()=>S("SIGKILL"),ke)},g=()=>B(new _("cancelled","Reason cancelled the desktop operation."));r.addEventListener("abort",g,{once:!0});let w=(x)=>{if(u)return;u=!0,clearTimeout(m),r.removeEventListener("abort",g),x()};if(i.stdout.on("data",(x)=>{if(f+=x.byteLength,f>he)B(new _("desktop_delegate_failed","Reason's desktop reply is too large."));else d.push(x)}),i.stderr.setEncoding("utf8").on("data",(x)=>{n=(n+x).slice(-Qe)}),i.stdin.on("error",()=>{}),i.once("error",()=>w(()=>c(l??new _("desktop_delegate_unavailable","Reason could not start its desktop as the desktop account.")))),i.once("close",(x,ze)=>w(()=>{if(l)return c(l);let y=Ye(Buffer.concat(d).toString("utf8"));if(E(y)&&y.ok===!0&&E(y.result))return a(y.result);let F=E(y)&&y.ok===!1&&typeof y.code==="string"&&typeof y.message==="string"?new _(y.code.slice(0,120),y.message.slice(0,2000)):null,pt=`exited ${x??ze}${F?"":" with no reply"}`,yt=n.trim().split(`
695
- `).at(-1)?.slice(-300)??"";if(!F||F.code==="desktop_delegate_failed")process.stderr.write(`Reason worker: desktop call ${pt}${n?`: ${n.trim().slice(-500)}`:""}
696
- `);if(F)return c(F);c(new _("desktop_delegate_failed",`Reason's desktop operation failed (${pt}${yt?`: ${yt}`:""}).`))})),r.aborted)g();i.stdin.end(JSON.stringify(e))})}async function Nt(t,e,r,o={}){let s=await We(t,{op:"automation",call:e},r,o);if(!Number.isSafeInteger(s.code)||typeof s.stdout!=="string"||typeof s.stderr!=="string")throw new _("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 zr,spawn as jr}from"child_process";import{closeSync as Dr,mkdirSync as Mr,openSync as Pr}from"fs";import{dirname as k,join as Zr}from"path";import{promisify as hr}from"util";import{spawnSync as P}from"child_process";import{createHash as Sr,randomUUID as pr}from"crypto";import{chmodSync as yr,existsSync as st,mkdirSync as Ar,readdirSync as es,readFileSync as U,renameSync as Nr,rmSync as N,statSync as Or,writeFileSync as gr}from"fs";import{dirname as Tr,isAbsolute as jt,join as G}from"path";import{chmodSync as Mo,existsSync as He,mkdirSync as Po,readlinkSync as Ke,readFileSync as Ve,renameSync as Zo,unlinkSync as ho,writeFileSync as Qo}from"fs";import{homedir as gt}from"os";import{basename as Ee,dirname as Tt,isAbsolute as qt,join as R,normalize as ve,relative as tr,resolve as er}from"path";var et=3,rr=1,or=2,sr=1,ar=1,ir="Reason may read and write files and run commands in this signed-in OS account, subject to saved restrictions and operating system permissions.",cr="Reason may later execute on this computer inside a Reason sandbox, limited to folders explicitly attached by the user.",nr=[cr,"Ara may later execute on this computer inside an Ara sandbox, limited to folders explicitly attached by the user."];function dr(t){return typeof t==="string"&&nr.includes(t)}var fr=["future_device","updates_only","cli_only"];function Ct(t){return typeof t==="string"&&fr.some((e)=>e===t)}function lr(t=process.env,e=gt()){return t.XDG_CONFIG_HOME?.trim()||R(e,".config")}function rt(t=process.env,e=gt()){let r=D({env:t}),o=lr(t,e);return R(o,Ot(o).state==="kept"?"ara":"reason",...r==="staging"?["staging"]:[],"installation.json")}function p(t){return typeof t==="string"&&t.trim().length>0}var _r=/^[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 ur(t){return typeof t==="string"&&_r.test(t)}function j(t){return p(t)&&qt(t)&&ve(t)===t}function Bt(t){if(!t||typeof t!=="object"||Array.isArray(t))return!1;let e=t;return j(e.path)&&(e.role==="launcher"&&(e.kind==="file"||e.kind==="symlink")||e.role==="worker_root"&&e.kind==="directory"||e.role==="alias"&&e.kind==="symlink"&&j(e.target))}function It(t){return t.owned_paths?.every((e)=>e.role!=="alias"||t.installer==="shell"&&e.path===R(t.install_dir,t.channel==="staging"?"reason-staging":"reason")&&e.target===R(t.install_dir,t.channel==="staging"?"ara-staging":"ara")&&t.owned_paths?.some((r)=>r.role==="launcher"&&r.path===e.target))??!1}function mr(t,e){try{return er(Tt(t),Ke(t))===e}catch{return!1}}function ot(t){let e=Ee(t),r=e==="ara"?"reason":e==="ara-staging"?"reason-staging":null;if(!r)return t;let o=R(Tt(t),r);return mr(o,t)?o:t}function $t(t,e){let r=tr(t,e);return r.length>0&&!r.startsWith("..")&&!qt(r)}function Ft(t){if(t===null)return!0;if(!t||typeof t!=="object"||Array.isArray(t))return!1;let e=t;return e.kind==="shell_profile"&&p(e.location)&&p(e.value)&&(typeof e.added_by_installer==="boolean"||typeof e.added_by_ara==="boolean")&&(e.added_by_installer===void 0||typeof e.added_by_installer==="boolean")&&(e.added_by_ara===void 0||typeof e.added_by_ara==="boolean")}function Rt(t,e){if(e===null)return t==="cli_only";if(!e||typeof e!=="object"||Array.isArray(e))return!1;let r=e;if(r.version!==sr||!p(r.recorded_at))return!1;if(t==="future_device")return r.decision==="authorized"&&dr(r.scope);return r.scope===null&&r.decision===(t==="updates_only"?"ask":"disabled")}function br(t){if(!t||typeof t!=="object"||Array.isArray(t))return null;let e=t;if(e.schema_version!==rr||!tt.includes(e.channel)||e.install_method!=="curl"||e.installer!=="shell"||!p(e.installed_at)||!p(e.version)||!p(e.target)||!j(e.install_dir)||!Array.isArray(e.owned_paths)||!e.owned_paths.every(Bt)||!e.owned_paths.every((r)=>$t(e.install_dir,r.path))||!It(e)||!Ft(e.path_entry))return null;return{...e,schema_version:et,installation_id:null,background_mode:"cli_only",device_consent:null}}function wr(t){if(!t||typeof t!=="object"||Array.isArray(t))return null;let e=t;if(e.schema_version!==or||!Gt(e)||!Ct(e.background_mode)||!Rt(e.background_mode,e.device_consent))return null;return{...e,schema_version:et,installation_id:null}}function Gt(t){return tt.includes(t.channel)&&(t.install_method==="curl"&&t.installer==="shell"||t.install_method==="desktop"&&t.installer==="desktop"&&Array.isArray(t.owned_paths)&&t.owned_paths.length===0&&t.path_entry===null)&&p(t.installed_at)&&p(t.version)&&p(t.target)&&j(t.install_dir)&&Array.isArray(t.owned_paths)&&t.owned_paths.every(Bt)&&t.owned_paths.every((e)=>$t(t.install_dir,e.path))&&It(t)&&Ft(t.path_entry)}function xr(t){let e=br(t);if(e)return e;let r=wr(t);if(r)return r;if(!t||typeof t!=="object"||Array.isArray(t))return null;let o=t;if(o.schema_version!==et||!ur(o.installation_id)||!Gt(o)||!Ct(o.background_mode)||!Rt(o.background_mode,o.device_consent)||o.desktop_account_access!==void 0&&(o.desktop_account_access===null||typeof o.desktop_account_access!=="object"||Array.isArray(o.desktop_account_access)||o.desktop_account_access.version!==ar||o.desktop_account_access.scope!==ir||!p(o.desktop_account_access.recorded_at)||!Number.isFinite(Date.parse(o.desktop_account_access.recorded_at))))return null;return o}function Ut(t=rt()){if(!He(t))return null;try{return xr(JSON.parse(Ve(t,"utf8")))}catch{return null}}var at="REASON_WORKER_SERVICE",qr="worker_identity_unavailable";function Dt(t){return{platform:process.platform,home:t,uid:process.getuid?.(),command:(e,r)=>P(e,[...r],{stdio:"ignore"}).status??1,read:(e,r)=>{let o=P(e,[...r],{stdio:["ignore","pipe","ignore"],encoding:"utf8",timeout:1e4});return o.status===0?o.stdout:null},sleep:(e)=>Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e),workerIdentity:(e)=>zt(t,e),insideService:(e)=>Cr(e,process.platform,process.getuid?.())}}function Cr(t,e,r){if(process.env[at]===t||process.env.XPC_SERVICE_NAME===t)return!0;if(e==="linux")try{return U("/proc/self/cgroup","utf8").includes(`/${t}.service`)}catch{return!0}if(e!=="darwin")return!1;if(typeof r!=="number")return!0;let o=P("/bin/launchctl",["print",`gui/${r}/${t}`],{encoding:"utf8",timeout:5000});if(o.status===Br)return!1;if(o.error||o.status!==0)return!0;let s=Number(/^\s*pid = (\d+)$/m.exec(o.stdout??"")?.[1]??0);if(!s)return!1;let a=process.pid;for(let c=0;c<64&&a>1;c+=1){if(a===s)return!0;let i=P("/bin/ps",["-o","ppid=","-p",String(a)],{encoding:"utf8",timeout:5000}),d=Number(i.stdout?.trim());if(i.error||i.status!==0||!Number.isSafeInteger(d)||d<=0)return!0;if(d===a)return!1;a=d}return a>1}var Br=113;class A extends Error{code;constructor(t,e){super(t);this.code=e}}function Mt(t,e){if(t.platform!=="darwin"&&t.platform!=="linux")throw new A("A background service needs macOS (launchd) or Linux (systemd --user).");if(t.platform==="darwin")L(t);let o=[Ut(rt(e,t.home))?.owned_paths.find((s)=>s.role==="launcher")?.path,v(e,"REASON_CLI_LAUNCHER_PATH")?.trim(),G(t.home,".local","bin",D({env:e})==="staging"?"ara-staging":"ara")];for(let s of o)try{if(s&&jt(s)&&Or(s).isFile())return ot(s)}catch{}throw new A("A background service runs the installed Reason launcher, which was not found. Install Reason with: curl -fsSL https://reasonmachines.com/install | sh","worker_launcher_missing")}var it=/(<key>ProgramArguments<\/key>\s*<array>\n)((?:\s*<string>[^<]*<\/string>\n)*)(\s*<\/array>)/,M=new RegExp(`(\\n\\s*<key>${Z}</key>\\s*<string>)[^<]*(</string>)`),Ir=/(<key>EnvironmentVariables<\/key>\s*<dict>[\s\S]*?)(\n\s*<\/dict>)/;function $r(t){return t.replaceAll("&lt;","<").replaceAll("&gt;",">").replaceAll("&quot;",'"').replaceAll("&apos;","'").replaceAll("&amp;","&")}function Pt(t){let e=[...(it.exec(t)?.[2]??"").matchAll(/<string>([^<]*)<\/string>/g)].map((o)=>$r(o[1])),r=e[1]==="--run-worker"?e.slice(2):e;return r[0]?{launcher:r[0],args:r.slice(1)}:null}function Zt(t,e,r){let o=r.workerIdentity?.(t)??null;return{program:o?[o.executable,"--run-worker",t,...e]:[t,...e],identity:o}}function ct(t){return t.map((e)=>` <string>${O(e)}</string>`).join(`
697
- `)}function ht(t,e){let r;try{r=U(t,"utf8")}catch{return null}let o=Pt(r);if(!o)return null;let s=jt(o.launcher)?ot(o.launcher):o.launcher,{program:a,identity:c}=Zt(s,o.args,e),i=r.replace(it,(d,f,n,l)=>`${f}${ct(a)}
698
- ${l}`);if(!c)i=i.replace(M,"");else if(M.test(i))i=i.replace(M,(d,f,n)=>`${f}${O(c.app)}${n}`);else i=i.replace(Ir,(d,f,n)=>`${f}
699
- <key>${Z}</key>
700
- <string>${O(c.app)}</string>${n}`);return i===r?null:i}function Fr(t,e){let r=ht(t,e);if(r!==null)Q(t,r)}function cs(t,e,r){if(e.platform!=="darwin")return!1;let o=dt(t,e,r);return o!==null&&ht(o.definition,e)!==null}var h="com.reasonmachines.worker.",nt="so.reason.worker.",Qt=[h,nt];function kt(t,e=h){return`${e}connect${t==="production"?"":`.${t}`}`}function ns(t,e){return Qt.some((r)=>t===kt(e,r))}function Rr(t,e,r){if(e==="connect")return kt(t.channel,r);let o=Sr("sha256").update(t.workspaceRoot).digest("hex").slice(0,8);return`${r}${t.name.toLowerCase()}.${o}`}function Gr(t,e){if(e==="darwin")return{directory:G(t,"Library","LaunchAgents"),suffix:".plist"};if(e==="linux")return{directory:G(t,".config","systemd","user"),suffix:".service"};return null}function T(t,e,r,o=h){let s=Rr(t,r,o),a=Gr(e.home,e.platform);if(!a)return null;return{label:s,definition:G(a.directory,`${s}${a.suffix}`),logs:e.platform==="darwin"?G(t.stateDirectory,"service.log"):`journalctl --user -u ${s}.service`}}function dt(t,e,r="serve"){return Yt(t,e,r)[0]??null}function Yt(t,e,r){return Qt.map((o)=>T(t,e,r,o)).filter((o)=>o!==null&&st(o.definition))}function Xt(t,e,r){let o=T(t,e,r,nt);return o&&st(o.definition)?o:null}function Ur(t,e,r){let o=T(t,e,r),s=Xt(t,e,r);if(!o||!s||!st(o.definition)||e.insideService?.(s.label))return null;if(!Lr(o,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}/${s.label}`]);return N(s.definition,{force:!0}),"retired"}return e.command("systemctl",["--user","disable","--now",`${s.label}.service`]),N(s.definition,{force:!0}),e.command("systemctl",["--user","daemon-reload"]),"retired"}function Lr(t,e){if(e.platform==="darwin")return typeof e.uid==="number"&&e.uid>0&&e.command("/bin/launchctl",["print",`gui/${e.uid}/${t.label}`])===0;let r=`${t.label}.service`;return e.command("systemctl",["--user","is-enabled","--quiet",r])===0&&Jr.has(e.read("systemctl",["--user","show","--property=ActiveState","--value",r])?.trim()??"")}var Jr=new Set(["active","activating","reloading"]);function ds(t,e){if(e.platform==="darwin"){if(typeof e.uid!=="number"||e.uid<=0)return!1;let r=e.read("/bin/launchctl",["print",`gui/${e.uid}/${t.label}`]);return Number(/^\s*pid = (\d+)$/m.exec(r??"")?.[1]??0)>0}return Number(e.read("systemctl",["--user","show","--property=MainPID","--value",`${t.label}.service`])?.trim()??0)>0}function fs(t){let{config:e,launcher:r,host:o,kind:s}=t,a=T(e,o,s);if(!a)return!1;let c;try{c=U(a.definition,"utf8")}catch{return!1}if(o.platform!=="darwin")return c===Kt(e,s,a,r,o.home,t.path);let i=Pt(c);return c.replace(M,"").replace(it,(f,n,l,u)=>`${n}${i?`${ct([i.launcher,...i.args])}
701
- `:""}${u}`)===Ht(e,s,a,r,{...o,workerIdentity:()=>null},t.path).plist}function Wt(t,e){if(e==="connect")return{args:["connect"],environment:{REASON_CLI_CHANNEL:t.channel},description:"Reason connection of this computer"};return{args:["serve",t.name,"--dir",t.workspaceRoot,...t.executionMode==="confined"?["--sandbox"]:[]],environment:{},description:`Reason machine ${t.name} worker`}}function O(t){return t.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&apos;")}function Lt(t,e=!1){if(/[\0-\x1f\x7f]/.test(t))throw new A("A background service cannot use a path with control characters.");let r=t.replaceAll("\\","\\\\").replaceAll('"',"\\\"").replaceAll("%","%%");return`"${e?r.replaceAll("$","$$$$"):r}"`}function Ht(t,e,r,o,s,a){let c=Wt(t,e),i=Zt(o,c.args,s),d={HOME:s.home,PATH:a,[at]:r.label,...c.environment,...i.identity?{[Z]:i.identity.app}:{}};return{identity:i.identity,plist:`<?xml version="1.0" encoding="UTF-8"?>
702
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
703
- <plist version="1.0">
704
- <dict>
705
- <key>Label</key>
706
- <string>${O(r.label)}</string>
707
- <key>AssociatedBundleIdentifiers</key>
708
- <array>
709
- <string>${Jt}</string>
710
- </array>
711
- <key>ProgramArguments</key>
712
- <array>
713
- ${ct(i.program)}
714
- </array>
715
- <key>EnvironmentVariables</key>
716
- <dict>
717
- ${Object.entries(d).map(([f,n])=>` <key>${f}</key>
718
- <string>${O(n)}</string>`).join(`
719
- `)}
720
- </dict>
721
- <key>RunAtLoad</key>
722
- <true/>
723
- <key>KeepAlive</key>
724
- <dict>
725
- <key>SuccessfulExit</key>
726
- <false/>
727
- </dict>
728
- <key>ThrottleInterval</key>
729
- <integer>10</integer>
730
- <key>ExitTimeOut</key>
731
- <integer>${Math.ceil(t.shutdownGraceMs/1000)+10}</integer>
732
- <key>ProcessType</key>
733
- <string>Standard</string>
734
- <key>Umask</key>
735
- <integer>63</integer>
736
- <key>StandardOutPath</key>
737
- <string>${O(r.logs)}</string>
738
- <key>StandardErrorPath</key>
739
- <string>${O(r.logs)}</string>
740
- </dict>
741
- </plist>
742
- `}}function Kt(t,e,r,o,s,a){let c=Wt(t,e);return`[Unit]
743
- Description=${c.description}
744
-
745
- [Service]
746
- ExecStart=${[o,...c.args].map((i)=>Lt(i,!0)).join(" ")}
747
- Environment=${[`HOME=${s}`,`PATH=${a}`,`${at}=${r.label}`,...Object.entries(c.environment).map(([i,d])=>`${i}=${d}`)].map((i)=>Lt(i)).join(" ")}
748
- Restart=on-failure
749
- RestartSec=10
750
- TimeoutStopSec=${Math.ceil(t.shutdownGraceMs/1000)+10}
751
- UMask=0077
752
-
753
- [Install]
754
- WantedBy=default.target
755
- `}function Q(t,e){Ar(Tr(t),{recursive:!0,mode:448});let r=`${t}.${pr()}.tmp`;try{gr(r,e,{mode:384,flag:"wx"}),yr(r,384),Nr(r,t)}finally{N(r,{force:!0})}}function L(t){if(typeof t.uid!=="number"||!Number.isSafeInteger(t.uid)||t.uid<=0)throw new A("Set up a background service as your own user, not with sudo.","worker_service_root_user");return`gui/${t.uid}`}function ls(t){let{config:e,launcher:r,host:o}=t,s=t.kind??"serve",a=Xt(e,o,s),c=a!==null&&o.insideService?.(a.label)===!0,i=T(e,o,s,c?nt:h);if(!i)throw new A("A background service needs macOS (launchd) or Linux (systemd --user).");if(o.platform==="darwin")L(o);if(o.platform==="linux"&&o.command("systemctl",["--user","show-environment"])!==0)throw new A("No background service here: this computer has no systemd user session.","worker_service_manager_missing");let d=o.platform==="darwin"?Ht(e,s,i,r,o,t.path):null;if(Q(i.definition,d?d.plist:Kt(e,s,i,r,o.home,t.path)),Vt(e,o,i,c?null:a),d)return d.identity?i:{...i,identityProblem:qr};return{...i,lingering:o.command("loginctl",["enable-linger"])===0}}function Vt(t,e,r,o){if(e.platform==="darwin"){let c=L(e);if(o)e.command("/bin/launchctl",["bootout",`${c}/${o.label}`]);if(Et(t,r,e)){if(o)N(o.definition,{force:!0});return}if(N(r.definition,{force:!0}),o)e.command("/bin/launchctl",["bootstrap",c,o.definition]);throw new A("Could not start the background service (launchctl bootstrap failed).","worker_service_start_failed")}let s=`${r.label}.service`,a=o?`${o.label}.service`:null;if(e.command("systemctl",["--user","daemon-reload"])!==0||a!==null&&e.command("systemctl",["--user","disable","--now",a])!==0||e.command("systemctl",["--user","enable",s])!==0||e.command("systemctl",["--user","restart",s])!==0){if(e.command("systemctl",["--user","disable",s]),N(r.definition,{force:!0}),e.command("systemctl",["--user","daemon-reload"]),a)e.command("systemctl",["--user","enable","--now",a]);throw new A("Could not start the background service (systemctl --user failed).","worker_service_start_failed")}if(o)N(o.definition,{force:!0}),e.command("systemctl",["--user","daemon-reload"])}function Et(t,e,r){let o=L(r);r.command("/bin/launchctl",["bootout",`${o}/${e.label}`]);let s=(Math.ceil(t.shutdownGraceMs/1000)+10)*1000;for(let a=0,c=100;;c=Math.min(c*2,2000)){if(r.command("/bin/launchctl",["bootstrap",o,e.definition])===0)return!0;if(a>=s)return!1;r.sleep(c),a+=c}}function _s(t,e,r){let o=dt(t,e,r);if(!o)return null;let s=e.insideService?.(o.label)===!0;if(e.platform==="darwin"&&!s)Fr(o.definition,e);let a=T(t,e,r);if(a&&o.label!==a.label&&!s)return Q(a.definition,U(o.definition,"utf8").replaceAll(o.label,a.label)),Vt(t,e,a,o),a;let c=e.platform==="darwin"&&s,i;if(c)i=e.command("/bin/launchctl",["kickstart","-k",`${L(e)}/${o.label}`])===0;else if(e.platform==="darwin")i=Et(t,o,e);else e.command("systemctl",["--user","enable",`${o.label}.service`]),i=e.command("systemctl",["--user","restart",`${o.label}.service`])===0;if(!i)throw new A(`Could not restart the background service ${o.label}.`,"worker_service_restart_failed");if(a&&o.label===a.label)Ur(t,e,r);return o}function us(t,e,r,o){let s=dt(t,r,o),a=T(e,r,o);if(r.platform!=="darwin"||!s||!a)return;let c=`<string>${O(s.logs)}</string>`,i=U(s.definition,"utf8");if(i.includes(c))Q(s.definition,i.replaceAll(c,`<string>${O(a.logs)}</string>`))}function ms(t,e,r="serve"){let o=Yt(t,e,r);for(let s of o){if(e.platform==="darwin"){if(typeof e.uid==="number"&&e.uid>0)e.command("/bin/launchctl",["bootout",`gui/${e.uid}/${s.label}`]);N(s.definition,{force:!0});continue}e.command("systemctl",["--user","disable","--now",`${s.label}.service`]),N(s.definition,{force:!0}),e.command("systemctl",["--user","daemon-reload"])}return o[0]??null}var Qr=hr(zr),vt="x-apple.systempreferences:com.apple.preference.security",kr={accessibility:`${vt}?Privacy_Accessibility`,screen:`${vt}?Privacy_ScreenCapture`},Yr=64,J=new Map;function Y(t,e){let r=J.get(t);if(r?.has(e))return!1;if(!r){if(J.size>=Yr)J.delete(J.keys().next().value);r=new Set,J.set(t,r)}return r.add(e),!0}function Xr(){let t=q(),e=Mt(Dt(t),process.env),r=Zr(t,".local","share","reason","desktop-install.log");Mr(k(r),{recursive:!0,mode:448});let o=Pr(r,"a",384);try{let s=jr(e,["desktop","install"],{detached:!0,stdio:["ignore",o,o],env:{...process.env,REASON_DESKTOP_BACKGROUND:"1"}});s.on("error",()=>{return}),s.unref()}finally{Dr(o)}}var X={open:async(t,e)=>{await Qr("/usr/bin/open",t,{signal:e,timeout:1e4,maxBuffer:8192})},request:(t,e)=>se(t,e),tile:ae,installDesktop:Xr},te=!1;async function ee(t,e,r){try{await e.open(["-a","Google Chrome",t],r)}catch{r.throwIfAborted(),await e.open([t],r)}}async function ie(t,e,r,o){if(await r.open([kr[e]],o).catch(()=>{}),t[0]&&!o.aborted)r.tile(k(k(k(t[0]))),e)}async function Wr(t,e,r,o,s){for(let a of r){if(!Y(t,`grant:${a}`))continue;s.throwIfAborted(),await o.request(e,a).catch(()=>null),await ie(e,a,o,s)}}var Hr={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(t){return{code:0,stderr:"",stdout:Buffer.from(JSON.stringify({ok:!0,...t}))}}function Kr(t){if(typeof t!=="string")return null;try{let e=new URL(t);return e.protocol==="https:"||e.protocol==="http:"?e.href:null}catch{return null}}async function ce(t,e=X){let{call:r,runId:o,signal:s}=t;if(r.kind==="browser"){if(r.operation==="discover")return re({result:{tools:[Hr]}});if(r.operation!=="call")throw new _("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(t.desktopMissing&&!te){te=!0;try{e.installDesktop()}catch{}}if(r.kind==="computer"){if(t.identity.length>0&&Y(o,"grant:probe")){let i=await e.request(t.identity).catch(()=>null),d=i?[...i.accessibility?[]:["accessibility"],...i.screen?[]:["screen"]]:[];for(let f of d)Y(o,`grant:${f}`);for(let f of d)await ie(t.identity,f,e,s)}throw new _("automation_computer_setup_required","Computer use is not set up on this Mac yet; Reason asked macOS for any missing permission.")}if(Y(o,"page:chrome-extension"))await ee(oe,e,s).catch(()=>{});let a=r.arguments,c=r.operation==="call"&&r.tool==="open_tab"&&a&&typeof a==="object"&&!Array.isArray(a)?Kr(a.url):null;if(!c)throw new _("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(c,e,s),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 ne(t,e=X){if(t.call.kind!=="computer"||t.call.operation!=="permission_status"||t.output.code!==0||t.identity.length===0)return t.output;let r;try{r=JSON.parse(t.output.stdout.toString("utf8"))}catch{return t.output}if(!r||typeof r!=="object"||Array.isArray(r))return t.output;let o=r.permissions;if(!o||typeof o!=="object")return t.output;let s=o,a=[...s.accessibility==="missing"?["accessibility"]:[],...s.screenRecording==="missing"?["screen"]:[]];if(a.length===0)return t.output;return await Wr(t.runId,t.identity,a,e,t.signal),{...t.output,stdout:Buffer.from(JSON.stringify({...r,requested:a}))}}var bt=172032,ao=18874368,io=8192,co=65536,no=55000,fo=60000,lo=4,_o=40000,uo=/^[0-9a-f-]{36}$/,_e=At,mo=Oe();function H(t){return Boolean(t)&&typeof t==="object"&&!Array.isArray(t)}function K(){throw new _("invalid_automation_request","Reason automation request is malformed.")}function qe(t){let e=Object.keys(t).sort().join(",");if(e==="call"||e==="browser,call"){let r=t.call,o=e==="browser,call";if(!H(r)||r.version!==1||r.kind!=="computer"&&r.kind!=="browser"||o&&(t.browser!==xe||r.kind!=="browser")||JSON.stringify(r).length>co)K();return{call:r,userChrome:o}}if(e==="offset,output_id"){if(typeof t.output_id!=="string"||!uo.test(t.output_id)||!Number.isSafeInteger(t.offset)||t.offset<0)K();return{output_id:t.output_id,offset:t.offset}}return K()}function Ws(t=process.platform,e=$){if(t==="darwin")return!0;return t==="linux"&&e()?.features.computer===!0}var bo="__computer-use";function wo(t){let e=(r)=>r?"granted":"missing";return`Permissions: accessibility=${e(t.accessibility)}, screenRecording=${e(t.screen)}
756
- `}function xo(t,e,r,o={stdin:process.stdin,stdout:process.stdout}){return new Promise((s)=>{let a=I(t,e,{env:r,stdio:["pipe","pipe","inherit"]}),c=(n)=>{a.kill(n)},i=["SIGTERM","SIGINT","SIGHUP"];for(let n of i)process.on(n,c);o.stdin.pipe(a.stdin),a.stdin.on("error",()=>{return}),a.stdout.pipe(o.stdout,{end:!1});let d=!1,f=(n)=>{if(d)return;d=!0;for(let l of i)process.off(l,c);o.stdin.unpipe(a.stdin),o.stdout.write("",()=>s(n))};a.once("error",()=>f(127)),a.once("close",(n)=>f(n??1))})}async function Hs(t,e={}){let r=e.stderr??process.stderr,o=(e.identity??xt)(),s=(e.components??$)();if(o.length===0||s?.platform!=="darwin-arm64")return r.write(`Reason computer use: Reason's background identity cannot run Open Computer Use here (computer_use_identity_unavailable)
757
- `),1;if(t.length===1&&t[0]==="doctor"){let i=await(e.grants??Ae)(o);if(!i)return r.write(`Reason computer use: Reason's permissions could not be read (computer_use_permission_status_unavailable)
758
- `),1;return(e.stdout??process.stdout).write(wo(i)),0}if(t.length!==1||t[0]!=="mcp")return r.write(`Usage: reason __computer-use mcp|doctor
759
- `),2;let[a,...c]=o;return(e.run??xo)(a,[...c,s.ocu,"mcp"],{...process.env,OPEN_COMPUTER_USE_DISABLE_APP_AGENT_PROXY:"1"})}function Ks(t=$){return t()?.userChrome??{code:"user_chrome_browser_use_missing"}}function Ce(t,e,r,o){return new Promise((s)=>{let a=I(t,e,{env:r,stdio:"ignore"}),c=setTimeout(()=>{a.kill("SIGKILL"),s(-1)},o);a.once("error",()=>{clearTimeout(c),s(-1)}),a.once("exit",(i)=>{clearTimeout(c),s(i??-1)})})}function So(t,e,r,o){return new Promise((s)=>{let a=I(t,e,{env:r,stdio:["ignore","pipe","ignore"]}),c="";a.stdout.setEncoding("utf8").on("data",(d)=>{c+=d});let i=setTimeout(()=>{a.kill("SIGKILL"),s(null)},o);a.once("error",()=>{clearTimeout(i),s(null)}),a.once("close",(d)=>{clearTimeout(i),s(d===0?c:null)})})}var po="/tmp/open-browser-use",yo=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,Ao=33554432;function No(t,e){let r;try{r=t===null?null:JSON.parse(t)}catch{return null}let o=H(r)&&H(r.result)?r.result.metadata:null;if(!H(o)||o.extensionId!==e)return null;return typeof o.extensionInstanceId==="string"&&yo.test(o.extensionInstanceId)?o.extensionInstanceId:null}async function Be(t,e,r){let o=r.storages.map((i)=>{try{return V(i).filter((d)=>d.endsWith(".log")||d.endsWith(".ldb")).map((d)=>b(i,d))}catch{return[]}}),s;try{s=o.some((i)=>i.length>0)?V(r.socketDir).filter((i)=>i.endsWith(".sock")):[]}catch{return[]}let a=[];for(let i of s){let d=b(r.socketDir,i),f=No(await So(t,["info","--socket",d,"--timeout","2s"],e,5000),r.extensionId);if(f)a.push({instance:f,socket:d})}let c=[];for(let[i,d]of(a.length>0?o:[]).entries())for(let f of d)try{if(oo(f).size>Ao)continue;let n=ge(f),l=a.find((u)=>n.includes(u.instance));if(l){c.push({storage:r.storages[i],...l});break}}catch{}return c}async function Oo(t,e,r){return(await Be(t,e,r))[0]?.instance??null}function Ie(t,e,r){return Oo(t,e,{socketDir:po,extensionId:_t,storages:[b(r,"browser-profile","Default","Local Extension Settings",_t)]})}var ue=/^(Default|Profile ([0-9]+))$/;async function go(t,e,r=q(),o=St){let s=b(r,"Library","Application Support","Google","Chrome"),a=[];try{a=V(s)}catch(n){if(n.code==="EPERM")throw new _("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(ue.exec(n)?.[2]??-1),i=a.filter((n)=>ue.test(n)&&ut(b(s,n,"Extensions",W))).sort((n,l)=>c(n)-c(l)),d=(n)=>b(s,n,"Local Extension Settings",W);return(await Be(t,e,{socketDir:o,extensionId:W,storages:i.map(d)})).map(({storage:n,instance:l,socket:u})=>({profile:i.find((m)=>d(m)===n),instance:l,socket:u}))}async function To(t,e,r=q(),o=St){let s=(await go(t,e,r,o))[0]?.instance;if(!s)throw new _("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 me(t){return new Promise((e)=>{let r=so({path:t}),o=(s)=>{r.destroy(),e(s)};r.setTimeout(1000,()=>o(!1)),r.once("error",()=>o(!1)),r.once("connect",()=>o(!0))})}async function $e(t,e){let r=Date.now()+e;while(Date.now()<r){if(await t())return!0;await new Promise((o)=>setTimeout(o,200))}return!1}var ft=new Map;function lt(t,e){let r=ft.get(t);if(!r)r=e().finally(()=>ft.delete(t)),ft.set(t,r);return r}async function qo(t,e){if(await me(t))return;if(ro(t,{force:!0}),await Ce("dbus-daemon",["--session",`--address=unix:path=${t}`,"--fork"],e,1e4)!==0||!await $e(()=>me(t),5000))throw new _("automation_unavailable","Reason could not start the desktop session bus.")}async function be(t,e,r){let o=t.platform==="darwin-arm64"?async()=>await Ie(t.nativeHost,e,r)!==null:async()=>await Ce(t.nativeHost,["info"],e,5000)===0;if(await o())return;let s=["--profile-directory=Default",`--load-extension=${t.extensionDir}`,"--no-first-run","--no-default-browser-check","--window-size=1280,800","about:blank"],a,c=null,i=0;if(t.platform==="darwin-arm64"){let n=b(r,"browser-profile");z(n);let l=b(n,"NativeMessagingHosts");fe(l,{recursive:!0,mode:448});let u=wt(t.platform).nativeHostManifests[0];de(u,b(l,le(u)));let m=t.browser.slice(0,t.browser.indexOf(".app/")+4),S=s.filter((B)=>B!=="about:blank").concat("--no-startup-window","--use-mock-keychain");a=I("/usr/bin/open",["-g","-n","-a",m,"--args",`--user-data-dir=${n}`,...S],{env:e,stdio:"ignore"})}else{let n=b(e.HOME,".config","google-chrome"),l=b(n,"NativeMessagingHosts");fe(l,{recursive:!0,mode:448});let u=wt(t.platform).nativeHostManifests[0];de(u,b(l,le(u)));let m=process.geteuid?.()===0?["--no-sandbox"]:[];c=b(r,"browser.log");let S=vr(c,"a",384);i=Er(S).size,a=I(t.browser,[`--user-data-dir=${n}`,...s,...m,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",S,S],env:{...e,ACCESSIBILITY_ENABLED:"1"}}),Vr(S)}let d=!1;a.once("error",()=>{d=!0}),a.once("exit",(n)=>{d||=n!==0}),a.unref();let f=!1;if(await $e(async()=>d||(f=await o()),_o),!f){if(c&&ge(c).subarray(i).toString("utf8").includes("No usable sandbox"))throw new _("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 _("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function Vs(t){await Ge(t,!0)}function Es(t){return Fe(t,Re(t))}function Fe(t,e){return t.platform==="darwin-arm64"?b(e,"browser-profile"):b(e,"home",".config","google-chrome")}function Re(t){let e=b(t.root,"automation");if(!ut(e)||!Co(t.automation))return t.automation;if(!Bo(Fe(t,e)))try{eo(e,t.automation)}catch{}return ut(e)?e:t.automation}function Co(t){try{return V(t).length===0}catch(e){return e.code==="ENOENT"}}function Bo(t){let e;try{e=to(b(t,"SingletonLock"))}catch{return!1}let r=Number(e.slice(e.lastIndexOf("-")+1));if(!Number.isSafeInteger(r)||r<=0)return!0;try{return process.kill(r,0),!0}catch(o){return o.code==="EPERM"}}async function Ge(t,e){pe({root:t.root,automation:t.automation,extensionDir:t.extensionDir});let r=Re(t);z(r);let o=Te().username,s={USER:o,LOGNAME:o,REASON_AUTOMATION_OCU:t.ocu,REASON_AUTOMATION_OBU:t.nativeHost};if(t.platform==="darwin-arm64"){let n={...s,HOME:q(),PATH:`${mt(t.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:bo};if(!e)return n;await lt("browser",()=>be(t,n,r));let l=await Ie(t.nativeHost,n,r);if(!l)throw new _("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...n,REASON_AUTOMATION_OBU_INSTANCE:l,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let a=await Je(),c=b(r,"home"),i=b(r,"runtime");z(c),z(i);let d=b(r,"bus"),f={...s,HOME:c,PATH:`${mt(t.node)}:/usr/bin:/bin`,DISPLAY:a.display,XAUTHORITY:a.xauthority,XDG_RUNTIME_DIR:i,DBUS_SESSION_BUS_ADDRESS:`unix:path=${d}`,...a.sound?{PULSE_SERVER:Ne(a.sound)}:{}};if(await lt("bus",()=>qo(d,f)),e)await lt("browser",()=>be(t,f,r));return f}async function Io(t,e,r){let o=Te().username,s={USER:o,LOGNAME:o,HOME:q(),PATH:`${mt(t.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:e,REASON_AUTOMATION_BACKGROUND_TABS:"1"},a=await To(e,s);return r.throwIfAborted(),{...s,REASON_AUTOMATION_OBU_INSTANCE:a}}function Ue(t,e,r,o){if(typeof _e!=="string")return Promise.reject(new _("automation_unavailable","This Reason build has no automation runtime."));let s=_e;return new Promise((a,c)=>{let i=I(t,["--input-type=module","--eval",s],{env:{...e,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:!0}),d=[],f=0,n="",l=null,u=!1,m=(w)=>{l??=w;try{process.kill(-i.pid,"SIGKILL")}catch{i.kill("SIGKILL")}},S=(w)=>{if(u)return;u=!0,clearTimeout(B),o.removeEventListener("abort",g),w()},B=setTimeout(()=>m(new _("automation_timed_out","Reason automation did not finish in time.")),no),g=()=>m(new _("cancelled","Reason cancelled the automation call."));if(o.addEventListener("abort",g,{once:!0}),i.stdout.on("data",(w)=>{if(f+=w.byteLength,f>ao)m(new _("automation_output_too_large","Reason automation output is too large."));else d.push(w)}),i.stderr.setEncoding("utf8").on("data",(w)=>{n=(n+w).slice(-io)}),i.stdin.on("error",()=>{}),i.once("error",()=>S(()=>c(l??new _("automation_unavailable","Reason could not start the automation runtime.")))),i.once("close",(w)=>S(()=>{if(l)c(l);else a({code:w??1,stdout:Buffer.concat(d),stderr:n})})),o.aborted)g();i.stdin.end(r)})}var C=new Map;function $o(t,e,r){for(let[s,a]of C)if(a.expiresAt<=r)C.delete(s);while(C.size>=lo)C.delete(C.keys().next().value);let o=Oe();return C.set(o,{runId:t,bytes:e,expiresAt:r+fo}),o}async function Le(t,e,r,o={}){let s=await(o.environment??Ge)(t,e.kind==="browser");return r.throwIfAborted(),await(o.runtime??Ue)(t.node,s,JSON.stringify(e),r)}async function vs(t,e){let r=qe({call:t});if(!("call"in r))K();let o=$();if(!o?.features.computer||r.call.kind==="browser"&&!o.features.browser)throw new _("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await Le(o,r.call,e)}function we(t,e,r){let o=t.stdout.byteLength>bt?$o(e,t.stdout,r):void 0;return{code:t.code,stderr:t.stderr,instance_id:mo,output_bytes:t.stdout.byteLength,chunk:t.stdout.subarray(0,bt).toString("base64"),...o?{output_id:o}:{}}}async function ta(t,e={}){let r=qe(t.payload),o=(e.now??Date.now)();if("output_id"in r){let m=C.get(r.output_id);if(!m||m.runId!==t.runId||m.expiresAt<=o||r.offset>m.bytes.byteLength)throw new _("automation_output_unavailable","Reason automation output expired.");return{chunk:m.bytes.subarray(r.offset,r.offset+bt).toString("base64")}}let s=(e.components??$)(),a=(e.platform??process.platform)==="darwin",c=a?(e.macIdentity??xt)():[],i=e.macSetup??X,d=!s?.features.computer||r.call.kind==="browser"&&!r.userChrome&&!s.features.browser;if(a&&(d||c.length===0||r.call.kind==="browser"&&r.userChrome&&!t.userChrome))return we(await ce({runId:t.runId,call:r.call,identity:c,desktopMissing:d,signal:t.signal},i),t.runId,o);if(!s?.features.computer)throw new _("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let f=r.userChrome?t.userChrome:void 0;if(r.userChrome&&!f)throw new _("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(r.call.kind==="browser"&&!f&&!s.features.browser)throw new _("automation_browser_not_installed",s.platform==="darwin-arm64"?"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`.");t.signal.throwIfAborted();let n=await ye(t.runId,t.signal,e.now),l="account"in e?e.account??null:Se(),u;try{if(f){let m=await(e.userChromeEnvironment??Io)(s,f,t.signal);t.signal.throwIfAborted(),u=await(e.runtime??Ue)(s.node,m,JSON.stringify(r.call),t.signal)}else if(l)u=await(e.delegate??Nt)(l,r.call,t.signal);else u=await Le(s,r.call,t.signal,e)}finally{n()}if(a)u=await ne({runId:t.runId,call:r.call,identity:c,output:u,signal:t.signal},i);return we(u,t.runId,o)}
760
- export{Ut as Gc,at as Hc,Dt as Ic,A as Jc,Mt as Kc,cs as Lc,kt as Mc,ns as Nc,dt as Oc,Ur as Pc,ds as Qc,fs as Rc,ls as Sc,_s as Tc,us as Uc,ms as Vc,We as Wc,bt as Xc,qe as Yc,Ws as Zc,xo as _c,Hs as $c,Ks as ad,go as bd,To as cd,Vs as dd,Es as ed,vs as fd,ta as gd};
694
+ `;import{spawn as Le}from"child_process";import{basename as De}from"path";var Ge="__desktop-call",Ue="/usr/bin/setpriv",Me=27262976,ze=8192,Je=2000;function P(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function We(e){try{return JSON.parse(e)}catch{return null}}function je(){return[process.execPath,...De(process.execPath).startsWith("bun")&&process.argv[1]?[process.argv[1]]:[],Ge]}function Ke(e,r,t,i={}){t.throwIfAborted();let o=i.command??je();return new Promise((a,c)=>{let s=(i.spawnProcess??Le)(Ue,[`--reuid=${e.uid}`,`--regid=${e.gid}`,"--clear-groups","--no-new-privs","--",...o],{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"}}),l=[],u=0,n="",d=null,m=!1,p,b=(g)=>{try{process.kill(-s.pid,g)}catch{s.kill(g)}},A=(g)=>{d??=g,b("SIGTERM"),p??=setTimeout(()=>b("SIGKILL"),Je)},x=()=>A(new f("cancelled","Reason cancelled the desktop operation."));t.addEventListener("abort",x,{once:!0});let h=(g)=>{if(m)return;m=!0,clearTimeout(p),t.removeEventListener("abort",x),g()};if(s.stdout.on("data",(g)=>{if(u+=g.byteLength,u>Me)A(new f("desktop_delegate_failed","Reason's desktop reply is too large."));else l.push(g)}),s.stderr.setEncoding("utf8").on("data",(g)=>{n=(n+g).slice(-ze)}),s.stdin.on("error",()=>{}),s.once("error",()=>h(()=>c(d??new f("desktop_delegate_unavailable","Reason could not start its desktop as the desktop account.")))),s.once("close",(g,Pe)=>h(()=>{if(d)return c(d);let w=We(Buffer.concat(l).toString("utf8"));if(P(w)&&w.ok===!0&&P(w.result))return a(w.result);let N=P(w)&&w.ok===!1&&typeof w.code==="string"&&typeof w.message==="string"?new f(w.code.slice(0,120),w.message.slice(0,2000)):null,j=`exited ${g??Pe}${N?"":" with no reply"}`,K=n.trim().split(`
695
+ `).at(-1)?.slice(-300)??"";if(!N||N.code==="desktop_delegate_failed")process.stderr.write(`Reason worker: desktop call ${j}${n?`: ${n.trim().slice(-500)}`:""}
696
+ `);if(N)return c(N);c(new f("desktop_delegate_failed",`Reason's desktop operation failed (${j}${K?`: ${K}`:""}).`))})),t.aborted)x();s.stdin.end(JSON.stringify(r))})}async function X(e,r,t,i={}){let o=await Ke(e,{op:"automation",call:r},t,i);if(!Number.isSafeInteger(o.code)||typeof o.stdout!=="string"||typeof o.stderr!=="string")throw new f("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 Ve,spawn as Xe}from"child_process";import{closeSync as Ze,mkdirSync as Ye,openSync as Qe}from"fs";import{dirname as C,join as He}from"path";import{promisify as et}from"util";var tt=et(Ve),Z="x-apple.systempreferences:com.apple.preference.security",rt={accessibility:`${Z}?Privacy_Accessibility`,screen:`${Z}?Privacy_ScreenCapture`},it=64,R=new Map;function I(e,r){let t=R.get(e);if(t?.has(r))return!1;if(!t){if(R.size>=it)R.delete(R.keys().next().value);t=new Set,R.set(e,t)}return t.add(r),!0}function ot(){let e=y(),r=oe(ie(e),process.env),t=He(e,".local","share","reason","desktop-install.log");Ye(C(t),{recursive:!0,mode:448});let i=Qe(t,"a",384);try{let o=Xe(r,["desktop","install"],{detached:!0,stdio:["ignore",i,i],env:{...process.env,REASON_DESKTOP_BACKGROUND:"1"}});o.on("error",()=>{return}),o.unref()}finally{Ze(i)}}var k={open:async(e,r)=>{await tt("/usr/bin/open",e,{signal:r,timeout:1e4,maxBuffer:8192})},request:(e,r)=>te(e,r),tile:re,installDesktop:ot},Y=!1;async function Q(e,r,t){try{await r.open(["-a","Google Chrome",e],t)}catch{t.throwIfAborted(),await r.open([e],t)}}async function ae(e,r,t,i){if(await t.open([rt[r]],i).catch(()=>{}),e[0]&&!i.aborted)t.tile(C(C(C(e[0]))),r)}async function at(e,r,t,i,o){for(let a of t){if(!I(e,`grant:${a}`))continue;o.throwIfAborted(),await i.request(r,a).catch(()=>null),await ae(r,a,i,o)}}var st={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 H(e){return{code:0,stderr:"",stdout:Buffer.from(JSON.stringify({ok:!0,...e}))}}function nt(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 se(e,r=k){let{call:t,runId:i,signal:o}=e;if(t.kind==="browser"){if(t.operation==="discover")return H({result:{tools:[st]}});if(t.operation!=="call")throw new f("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&&!Y){Y=!0;try{r.installDesktop()}catch{}}if(t.kind==="computer"){if(e.identity.length>0&&I(i,"grant:probe")){let s=await r.request(e.identity).catch(()=>null),l=s?[...s.accessibility?[]:["accessibility"],...s.screen?[]:["screen"]]:[];for(let u of l)I(i,`grant:${u}`);for(let u of l)await ae(e.identity,u,r,o)}throw new f("automation_computer_setup_required","Computer use is not set up on this Mac yet; Reason asked macOS for any missing permission.")}if(I(i,"page:chrome-extension"))await Q(ee,r,o).catch(()=>{});let a=t.arguments,c=t.operation==="call"&&t.tool==="open_tab"&&a&&typeof a==="object"&&!Array.isArray(a)?nt(a.url):null;if(!c)throw new f("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 Q(c,r,o),H({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 ne(e,r=k){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,a=[...o.accessibility==="missing"?["accessibility"]:[],...o.screenRecording==="missing"?["screen"]:[]];if(a.length===0)return e.output;return await at(e.runId,e.identity,a,r,e.signal),{...e.output,stdout:Buffer.from(JSON.stringify({...t,requested:a}))}}var M=172032,ht=18874368,gt=8192,bt=65536,wt=55000,xt=60000,yt=4,St=40000,At=/^[0-9a-f-]{36}$/,de=V,Ot=Se();function E(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function B(){throw new f("invalid_automation_request","Reason automation request is malformed.")}function ve(e){let r=Object.keys(e).sort().join(",");if(r==="call"||r==="browser,call"){let t=e.call,i=r==="browser,call";if(!E(t)||t.version!==1||t.kind!=="computer"&&t.kind!=="browser"||i&&(e.browser!==he||t.kind!=="browser")||JSON.stringify(t).length>bt)B();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)B();return{output_id:e.output_id,offset:e.offset}}return B()}function Or(e=process.platform,r=v){if(e==="darwin")return!0;return e==="linux"&&r()?.features.computer===!0}var vt="__computer-use";function Nt(e){let r=(t)=>t?"granted":"missing";return`Permissions: accessibility=${r(e.accessibility)}, screenRecording=${r(e.screen)}
697
+ `}function Rt(e,r,t,i={stdin:process.stdin,stdout:process.stdout}){return new Promise((o)=>{let a=O(e,r,{env:t,stdio:["pipe","pipe","inherit"]}),c=(n)=>{a.kill(n)},s=["SIGTERM","SIGINT","SIGHUP"];for(let n of s)process.on(n,c);i.stdin.pipe(a.stdin),a.stdin.on("error",()=>{return}),a.stdout.pipe(i.stdout,{end:!1});let l=!1,u=(n)=>{if(l)return;l=!0;for(let d of s)process.off(d,c);i.stdin.unpipe(a.stdin),i.stdout.write("",()=>o(n))};a.once("error",()=>u(127)),a.once("close",(n)=>u(n??1))})}async function vr(e,r={}){let t=r.stderr??process.stderr,i=(r.identity??J)(),o=(r.components??v)();if(i.length===0||o?.platform!=="darwin-arm64")return t.write(`Reason computer use: Reason's background identity cannot run Open Computer Use here (computer_use_identity_unavailable)
698
+ `),1;if(e.length===1&&e[0]==="doctor"){let s=await(r.grants??xe)(i);if(!s)return t.write(`Reason computer use: Reason's permissions could not be read (computer_use_permission_status_unavailable)
699
+ `),1;return(r.stdout??process.stdout).write(Nt(s)),0}if(e.length!==1||e[0]!=="mcp")return t.write(`Usage: reason __computer-use mcp|doctor
700
+ `),2;let[a,...c]=i;return(r.run??Rt)(a,[...c,o.ocu,"mcp"],{...process.env,OPEN_COMPUTER_USE_DISABLE_APP_AGENT_PROXY:"1"})}function Nr(e=v){return e()?.userChrome??{code:"user_chrome_browser_use_missing"}}function Ne(e,r,t,i){return new Promise((o)=>{let a=O(e,r,{env:t,stdio:"ignore"}),c=setTimeout(()=>{a.kill("SIGKILL"),o(-1)},i);a.once("error",()=>{clearTimeout(c),o(-1)}),a.once("exit",(s)=>{clearTimeout(c),o(s??-1)})})}function Tt(e,r,t,i){return new Promise((o)=>{let a=O(e,r,{env:t,stdio:["ignore","pipe","ignore"]}),c="";a.stdout.setEncoding("utf8").on("data",(l)=>{c+=l});let s=setTimeout(()=>{a.kill("SIGKILL"),o(null)},i);a.once("error",()=>{clearTimeout(s),o(null)}),a.once("close",(l)=>{clearTimeout(s),o(l===0?c:null)})})}var Ct="/tmp/open-browser-use",It=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,kt=33554432;function qt(e,r){let t;try{t=e===null?null:JSON.parse(e)}catch{return null}let i=E(t)&&E(t.result)?t.result.metadata:null;if(!E(i)||i.extensionId!==r)return null;return typeof i.extensionInstanceId==="string"&&It.test(i.extensionInstanceId)?i.extensionInstanceId:null}async function Re(e,r,t){let i=t.storages.map((s)=>{try{return F(s).filter((l)=>l.endsWith(".log")||l.endsWith(".ldb")).map((l)=>_(s,l))}catch{return[]}}),o;try{o=i.some((s)=>s.length>0)?F(t.socketDir).filter((s)=>s.endsWith(".sock")):[]}catch{return[]}let a=[];for(let s of o){let l=_(t.socketDir,s),u=qt(await Tt(e,["info","--socket",l,"--timeout","2s"],r,5000),t.extensionId);if(u)a.push({instance:u,socket:l})}let c=[];for(let[s,l]of(a.length>0?i:[]).entries())for(let u of l)try{if(pt(u).size>kt)continue;let n=Ae(u),d=a.find((m)=>n.includes(m.instance));if(d){c.push({storage:t.storages[s],...d});break}}catch{}return c}async function Et(e,r,t){return(await Re(e,r,t))[0]?.instance??null}function Te(e,r,t){return Et(e,r,{socketDir:Ct,extensionId:D,storages:[_(t,"browser-profile","Default","Local Extension Settings",D)]})}var fe=/^(Default|Profile ([0-9]+))$/;async function Bt(e,r,t=y(),i=W){let o=_(t,"Library","Application Support","Google","Chrome"),a=[];try{a=F(o)}catch(n){if(n.code==="EPERM")throw new f("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(fe.exec(n)?.[2]??-1),s=a.filter((n)=>fe.test(n)&&G(_(o,n,"Extensions",q))).sort((n,d)=>c(n)-c(d)),l=(n)=>_(o,n,"Local Extension Settings",q);return(await Re(e,r,{socketDir:i,extensionId:q,storages:s.map(l)})).map(({storage:n,instance:d,socket:m})=>({profile:s.find((p)=>l(p)===n),instance:d,socket:m}))}async function Ft(e,r,t=y(),i=W){let o=(await Bt(e,r,t,i))[0]?.instance;if(!o)throw new f("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 me(e){return new Promise((r)=>{let t=_t({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 $=new Map;function L(e,r){let t=$.get(e);if(!t)t=r().finally(()=>$.delete(e)),$.set(e,t);return t}async function Pt(e,r){if(await me(e))return;if(mt(e,{force:!0}),await Ne("dbus-daemon",["--session",`--address=unix:path=${e}`,"--fork"],r,1e4)!==0||!await Ce(()=>me(e),5000))throw new f("automation_unavailable","Reason could not start the desktop session bus.")}async function pe(e,r,t){let i=e.platform==="darwin-arm64"?async()=>await Te(e.nativeHost,r,t)!==null:async()=>await Ne(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"],a,c=null,s=0;if(e.platform==="darwin-arm64"){let n=_(t,"browser-profile");T(n);let d=_(n,"NativeMessagingHosts");le(d,{recursive:!0,mode:448});let m=z(e.platform).nativeHostManifests[0];ce(m,_(d,ue(m)));let p=e.browser.slice(0,e.browser.indexOf(".app/")+4),b=o.filter((A)=>A!=="about:blank").concat("--no-startup-window","--use-mock-keychain");a=O("/usr/bin/open",["-g","-n","-a",p,"--args",`--user-data-dir=${n}`,...b],{env:r,stdio:"ignore"})}else{let n=_(r.HOME,".config","google-chrome"),d=_(n,"NativeMessagingHosts");le(d,{recursive:!0,mode:448});let m=z(e.platform).nativeHostManifests[0];ce(m,_(d,ue(m)));let p=process.geteuid?.()===0?["--no-sandbox"]:[];c=_(t,"browser.log");let b=ut(c,"a",384);s=lt(b).size,a=O(e.browser,[`--user-data-dir=${n}`,...o,...p,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",b,b],env:{...r,ACCESSIBILITY_ENABLED:"1"}}),ct(b)}let l=!1;a.once("error",()=>{l=!0}),a.once("exit",(n)=>{l||=n!==0}),a.unref();let u=!1;if(await Ce(async()=>l||(u=await i()),St),!u){if(c&&Ae(c).subarray(s).toString("utf8").includes("No usable sandbox"))throw new f("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 f("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function Rr(e){await qe(e,!0)}function Tr(e){return Ie(e,ke(e))}function Ie(e,r){return e.platform==="darwin-arm64"?_(r,"browser-profile"):_(r,"home",".config","google-chrome")}function ke(e){let r=_(e.root,"automation");if(!G(r)||!$t(e.automation))return e.automation;if(!Lt(Ie(e,r)))try{ft(r,e.automation)}catch{}return G(r)?r:e.automation}function $t(e){try{return F(e).length===0}catch(r){return r.code==="ENOENT"}}function Lt(e){let r;try{r=dt(_(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){be({root:e.root,automation:e.automation,extensionDir:e.extensionDir});let t=ke(e);T(t);let i=Oe().username,o={USER:i,LOGNAME:i,REASON_AUTOMATION_OCU:e.ocu,REASON_AUTOMATION_OBU:e.nativeHost};if(e.platform==="darwin-arm64"){let n={...o,HOME:y(),PATH:`${U(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:vt};if(!r)return n;await L("browser",()=>pe(e,n,t));let d=await Te(e.nativeHost,n,t);if(!d)throw new f("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...n,REASON_AUTOMATION_OBU_INSTANCE:d,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let a=await Fe(),c=_(t,"home"),s=_(t,"runtime");T(c),T(s);let l=_(t,"bus"),u={...o,HOME:c,PATH:`${U(e.node)}:/usr/bin:/bin`,DISPLAY:a.display,XAUTHORITY:a.xauthority,XDG_RUNTIME_DIR:s,DBUS_SESSION_BUS_ADDRESS:`unix:path=${l}`,...a.sound?{PULSE_SERVER:ye(a.sound)}:{}};if(await L("bus",()=>Pt(l,u)),r)await L("browser",()=>pe(e,u,t));return u}async function Dt(e,r,t){let i=Oe().username,o={USER:i,LOGNAME:i,HOME:y(),PATH:`${U(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:r,REASON_AUTOMATION_BACKGROUND_TABS:"1"},a=await Ft(r,o);return t.throwIfAborted(),{...o,REASON_AUTOMATION_OBU_INSTANCE:a}}function Ee(e,r,t,i){if(typeof de!=="string")return Promise.reject(new f("automation_unavailable","This Reason build has no automation runtime."));let o=de;return new Promise((a,c)=>{let s=O(e,["--input-type=module","--eval",o],{env:{...r,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:!0}),l=[],u=0,n="",d=null,m=!1,p=(h)=>{d??=h;try{process.kill(-s.pid,"SIGKILL")}catch{s.kill("SIGKILL")}},b=(h)=>{if(m)return;m=!0,clearTimeout(A),i.removeEventListener("abort",x),h()},A=setTimeout(()=>p(new f("automation_timed_out","Reason automation did not finish in time.")),wt),x=()=>p(new f("cancelled","Reason cancelled the automation call."));if(i.addEventListener("abort",x,{once:!0}),s.stdout.on("data",(h)=>{if(u+=h.byteLength,u>ht)p(new f("automation_output_too_large","Reason automation output is too large."));else l.push(h)}),s.stderr.setEncoding("utf8").on("data",(h)=>{n=(n+h).slice(-gt)}),s.stdin.on("error",()=>{}),s.once("error",()=>b(()=>c(d??new f("automation_unavailable","Reason could not start the automation runtime.")))),s.once("close",(h)=>b(()=>{if(d)c(d);else a({code:h??1,stdout:Buffer.concat(l),stderr:n})})),i.aborted)x();s.stdin.end(t)})}var S=new Map;function Gt(e,r,t){for(let[o,a]of S)if(a.expiresAt<=t)S.delete(o);while(S.size>=yt)S.delete(S.keys().next().value);let i=Se();return S.set(i,{runId:e,bytes:r,expiresAt:t+xt}),i}async function Be(e,r,t,i={}){let o=await(i.environment??qe)(e,r.kind==="browser");return t.throwIfAborted(),await(i.runtime??Ee)(e.node,o,JSON.stringify(r),t)}async function Cr(e,r){let t=ve({call:e});if(!("call"in t))B();let i=v();if(!i?.features.computer||t.call.kind==="browser"&&!i.features.browser)throw new f("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await Be(i,t.call,r)}function _e(e,r,t){let i=e.stdout.byteLength>M?Gt(r,e.stdout,t):void 0;return{code:e.code,stderr:e.stderr,instance_id:Ot,output_bytes:e.stdout.byteLength,chunk:e.stdout.subarray(0,M).toString("base64"),...i?{output_id:i}:{}}}async function Ir(e,r={}){let t=ve(e.payload),i=(r.now??Date.now)();if("output_id"in t){let p=S.get(t.output_id);if(!p||p.runId!==e.runId||p.expiresAt<=i||t.offset>p.bytes.byteLength)throw new f("automation_output_unavailable","Reason automation output expired.");return{chunk:p.bytes.subarray(t.offset,t.offset+M).toString("base64")}}let o=(r.components??v)(),a=(r.platform??process.platform)==="darwin",c=a?(r.macIdentity??J)():[],s=r.macSetup??k,l=!o?.features.computer||t.call.kind==="browser"&&!t.userChrome&&!o.features.browser;if(a&&(l||c.length===0||t.call.kind==="browser"&&t.userChrome&&!e.userChrome))return _e(await se({runId:e.runId,call:t.call,identity:c,desktopMissing:l,signal:e.signal},s),e.runId,i);if(!o?.features.computer)throw new f("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let u=t.userChrome?e.userChrome:void 0;if(t.userChrome&&!u)throw new f("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"&&!u&&!o.features.browser)throw new f("automation_browser_not_installed",o.platform==="darwin-arm64"?"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 we(e.runId,e.signal,r.now),d="account"in r?r.account??null:ge(),m;try{if(u){let p=await(r.userChromeEnvironment??Dt)(o,u,e.signal);e.signal.throwIfAborted(),m=await(r.runtime??Ee)(o.node,p,JSON.stringify(t.call),e.signal)}else if(d)m=await(r.delegate??X)(d,t.call,e.signal);else m=await Be(o,t.call,e.signal,r)}finally{n()}if(a)m=await ne({runId:e.runId,call:t.call,identity:c,output:m,signal:e.signal},s);return _e(m,e.runId,i)}
701
+ export{Ke as td,M as ud,ve as vd,Or as wd,Rt as xd,vr as yd,Nr as zd,Bt as Ad,Ft as Bd,Rr as Cd,Tr as Dd,Cr as Ed,Ir as Fd};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{qi as M}from"./vm-hands-entry-lite-tj1y61bg.js";import{wi as G}from"./vm-hands-entry-lite-nd1k2jz9.js";import{readdirSync as D,readFileSync as I}from"fs";import{userInfo as A}from"os";var O="--vm-hands-op-runner-kind=person";function x(q){let Q=new Set([q]),K=[];try{K=D("/proc")}catch{}for(let z of K){if(!/^\d+$/.test(z))continue;try{let X=I(`/proc/${z}/stat`,"utf8");if(Number(X.slice(X.lastIndexOf(")")+2).split(" ")[3])===q)Q.add(Number(z))}catch{}}for(let z of Q)try{process.kill(z,"SIGKILL")}catch{}}var C=(q)=>{let Q=globalThis.Bun;if(!Q)throw new M("pty_unavailable","Reason terminals require the Bun runtime.");let K=Q.spawn({cmd:[q.shell,...q.args],cwd:q.cwd,env:{...q.environment,TERM:"xterm-256color"},terminal:{cols:q.cols,rows:q.rows,data:(J,Y)=>q.onData(Y)}}),z=K.terminal,X=()=>{x(K.pid);try{z?.close()}catch{}};if(!z)throw X(),new M("pty_unavailable","Reason could not allocate a pseudo-terminal.");return{write:(J)=>z.write(J),resize:(J,Y)=>z.resize(J,Y),kill:X,exited:K.exited.then((J)=>typeof J==="number"?J:null,()=>null)}};function L(){let q=(()=>{try{return A().username}catch{return}})();return{PATH:process.env.PATH,HOME:process.env.HOME,SHELL:process.env.SHELL,LANG:"C.UTF-8",...q?{USER:q,LOGNAME:q}:{}}}async function P(){let[{executeLocalOperation:q,spawnCaptured:Q},{runLocalPtySession:K},{configureDesktopAccount:z},{configureWorkerSandbox:X}]=await Promise.all([import("./local-capabilities-7m54wthn.js"),import("./local-pty-session-zen80k1k.js"),import("./desktop-account-gcysz0m3.js"),import("./worker-sandbox-yw24sxyp.js")]);X();let T=process.argv.includes(O),J=($,j,F)=>Q($,j[0]==="-lic"?["-lc",...j.slice(1)]:j,F),Y=(process.geteuid?.()??0)!==0,H=new Map,Z=($)=>{try{process.send?.($)}catch{}};process.on("message",($)=>{let j=$;if(j?.t==="cancel"){H.get(j.id)?.abort();return}if(j?.t!=="op")return;if(!Y){Z({t:"done",id:j.id,completion:{status:"failed",error_code:"vm_hands_payload_account_unavailable"}});return}let F=j.claim.capability;if(F==="pty.start"&&!T){Z({t:"done",id:j.id,completion:{status:"failed",error_code:"capability_not_granted"}});return}let U=new AbortController;H.set(j.id,U);let V=F==="pty.start"?{runPtySession:(B)=>K(B,{spawnPty:C,environment:L(),loadProxy:()=>null})}:{worker:j.worker,...F==="exec.full"?{spawnFullControl:J}:{}};q(j.state,j.claim,{...V,signal:U.signal,emit:(B)=>{let{deliverySignal:N,...W}=B;Z({t:"event",id:j.id,event:W})}}).then((B)=>Z({t:"done",id:j.id,completion:B}),(B)=>Z({t:"done",id:j.id,completion:{status:"failed",error_code:B&&typeof B==="object"&&"code"in B&&typeof B.code==="string"?B.code:"vm_hands_op_failed"}})).finally(()=>H.delete(j.id))}),process.on("disconnect",()=>process.exit(0)),await new Promise(()=>{})}
3
- export{O as a,C as b,P as c};
2
+ import{Xj as M}from"./vm-hands-entry-lite-kxtjkzzh.js";import{bk as G}from"./vm-hands-entry-lite-hw8vgsmm.js";import{readdirSync as D,readFileSync as I}from"fs";import{userInfo as A}from"os";var O="--vm-hands-op-runner-kind=person";function x(q){let Q=new Set([q]),K=[];try{K=D("/proc")}catch{}for(let z of K){if(!/^\d+$/.test(z))continue;try{let X=I(`/proc/${z}/stat`,"utf8");if(Number(X.slice(X.lastIndexOf(")")+2).split(" ")[3])===q)Q.add(Number(z))}catch{}}for(let z of Q)try{process.kill(z,"SIGKILL")}catch{}}var C=(q)=>{let Q=globalThis.Bun;if(!Q)throw new M("pty_unavailable","Reason terminals require the Bun runtime.");let K=Q.spawn({cmd:[q.shell,...q.args],cwd:q.cwd,env:{...q.environment,TERM:"xterm-256color"},terminal:{cols:q.cols,rows:q.rows,data:(J,Y)=>q.onData(Y)}}),z=K.terminal,X=()=>{x(K.pid);try{z?.close()}catch{}};if(!z)throw X(),new M("pty_unavailable","Reason could not allocate a pseudo-terminal.");return{write:(J)=>z.write(J),resize:(J,Y)=>z.resize(J,Y),kill:X,exited:K.exited.then((J)=>typeof J==="number"?J:null,()=>null)}};function L(){let q=(()=>{try{return A().username}catch{return}})();return{PATH:process.env.PATH,HOME:process.env.HOME,SHELL:process.env.SHELL,LANG:"C.UTF-8",...q?{USER:q,LOGNAME:q}:{}}}async function P(){let[{executeLocalOperation:q,spawnCaptured:Q},{runLocalPtySession:K},{configureDesktopAccount:z},{configureWorkerSandbox:X}]=await Promise.all([import("./local-capabilities-yekmdbpc.js"),import("./local-pty-session-e7j0kj19.js"),import("./desktop-account-q57958y1.js"),import("./worker-sandbox-wb5thd4n.js")]);X();let T=process.argv.includes(O),J=($,j,F)=>Q($,j[0]==="-lic"?["-lc",...j.slice(1)]:j,F),Y=(process.geteuid?.()??0)!==0,H=new Map,Z=($)=>{try{process.send?.($)}catch{}};process.on("message",($)=>{let j=$;if(j?.t==="cancel"){H.get(j.id)?.abort();return}if(j?.t!=="op")return;if(!Y){Z({t:"done",id:j.id,completion:{status:"failed",error_code:"vm_hands_payload_account_unavailable"}});return}let F=j.claim.capability;if(F==="pty.start"&&!T){Z({t:"done",id:j.id,completion:{status:"failed",error_code:"capability_not_granted"}});return}let U=new AbortController;H.set(j.id,U);let V=F==="pty.start"?{runPtySession:(B)=>K(B,{spawnPty:C,environment:L(),loadProxy:()=>null})}:{worker:j.worker,...F==="exec.full"?{spawnFullControl:J}:{}};q(j.state,j.claim,{...V,signal:U.signal,emit:(B)=>{let{deliverySignal:N,...W}=B;Z({t:"event",id:j.id,event:W})}}).then((B)=>Z({t:"done",id:j.id,completion:B}),(B)=>Z({t:"done",id:j.id,completion:{status:"failed",error_code:B&&typeof B==="object"&&"code"in B&&typeof B.code==="string"?B.code:"vm_hands_op_failed"}})).finally(()=>H.delete(j.id))}),process.on("disconnect",()=>process.exit(0)),await new Promise(()=>{})}
3
+ export{O as s,C as t,P as u};
@@ -0,0 +1,9 @@
1
+ // @bun
2
+ import{Si as F}from"./vm-hands-entry-lite-tbps80f1.js";import{qj as b}from"./vm-hands-entry-lite-rkt48xf4.js";import{randomUUID as d}from"crypto";import{spawnSync as C}from"child_process";import{chmodSync as zj,cpSync as Jj,existsSync as U,lstatSync as M,mkdirSync as h,readdirSync as Wj,readFileSync as I,readlinkSync as Zj,realpathSync as R,renameSync as P,rmdirSync as $j,rmSync as G,symlinkSync as E,writeFileSync as qj}from"fs";import{dirname as B,join as K,relative as Kj,resolve as Qj}from"path";var s="so.ara.cli",Vj="5LJFSBRY2F",wj="Background/Reason.app",m="ReasonBackgroundIdentity",Sj="Contents/Helpers/ReasonPermissionTile";var S="AraBackgroundIdentity",Xj="Reason",Dj=`anchor apple generic and identifier "${s}" and certificate leaf[subject.OU] = "${Vj}"`;class H extends Error{code;constructor(j,z){super(z);this.code=j;this.name="MacOSBackgroundIdentityError"}}var T="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister";function v(j=F()){return K(j,"Library","Application Support","Reason","Background","Reason.app")}function _(j=F()){return K(j,"Library","Application Support","Ara","Background","Ara.app")}function fj(j=process.execPath){return K(B(R(j)),wj)}function Fj(j){try{return M(j).isFile()}catch{return!1}}function f(j){return[m,S].map((z)=>K(j,"Contents","MacOS",z)).find(Fj)??null}function w(j){try{if(!M(j).isDirectory())return!1;let z=I(K(j,"Contents","Info.plist"),"utf8");return z.includes(`<string>${s}</string>`)&&(z.includes(`<string>${Xj}</string>`)||z.includes("<string>Ara</string>"))&&f(j)!==null}catch{return!1}}function u(j=F()){let z=v(j);if(!w(z))return null;try{let J=I(K(z,"Contents","Info.plist"),"utf8");return/<key>CFBundleVersion<\/key>\s*<string>(\d+\.\d+\.\d+)<\/string>/.exec(J)?.[1]??null}catch{return null}}function Gj(j,z=F()){let J=u(z);return J===null||p(A(J.split(".")),A(j.split(/[.-]/).slice(0,3)))}var Yj=1e4;function i(j,z){return C(j,[...z],{stdio:"ignore",timeout:Yj}).status??1}var l=new Set;function r(j){if(process.env.REASON_TEST_REFUSE_REAL_IDENTITY!=="1")return;let z=(J)=>{try{return R(J)}catch{return Qj(J)}};if(j!==void 0&&z(j)!==z(F()))return;throw Error("A test tried to change this computer's real Reason background identity; pass a temporary home. Refused by scripts/test-env.ts.")}var c=/\/(?:runtime|CLI)\/versions\/(\d+)\.(\d+)\.(\d+)[^/]*\/[^/]+$|\/\.ara(?:-staging)?-worker-(\d+)\.(\d+)\.(\d+)[^/]*\/[^/]+$/,o=new Set(["ara","ara.exe","reason","reason.exe"]);function A(j){return j.map((z)=>Number(z))}function p(j,z){for(let J=0;J<3;J+=1)if(j[J]!==z[J])return j[J]<z[J];return!1}var Nj=[0,2,161];function Pj(j){if(j===null)return!0;let z=Nj,J=null;try{J=R(process.execPath)}catch{}return j.some((W)=>{let Z=c.exec(W);if(Z){let X=Z[1]===void 0?Z.slice(4,7):Z.slice(1,4);return p(A(X),z)}let $=W.slice(W.lastIndexOf("/")+1);return o.has($)&&W!==J&&W!==process.execPath})}function Bj(){let j=C("/bin/ps",["-xo","pid=,comm="],{encoding:"utf8",timeout:5000});if(j.status!==0)return null;let z=[];for(let J of j.stdout.split(`
3
+ `)){let W=/^\s*(\d+)\s+(\S.*)$/.exec(J);if(!W||Number(W[1])===process.pid)continue;let Z=W[2].trimEnd(),$=Z.slice(Z.lastIndexOf("/")+1);if(!c.test(Z)&&o.has($)){let Q=C("/usr/sbin/lsof",["-a","-p",W[1],"-d","txt","-Fn"],{encoding:"utf8",timeout:5000}).stdout?.split(`
4
+ `).find((V)=>V.startsWith("n/"));if(Q)Z=Q.slice(1)}z.push(Z)}return z}function vj(j){if(r(j.home),!w(j.sourceApp))throw new H("identity_invalid","The packaged Reason background identity is missing or invalid.");let z=j.command??i,J=v(j.home),W=B(J);h(W,{recursive:!0,mode:448}),zj(W,448);let Z=R(j.sourceApp),$=null;try{$=R(J)}catch{}if(Z!==$){let X=`${process.pid}.${d()}`,Q=K(W,`.Reason.app.${X}.tmp`),V=K(W,`.Reason.app.${X}.old`),Y=!1;try{if(Jj(Z,Q,{recursive:!0,errorOnExist:!0,preserveTimestamps:!0}),!w(Q))throw new H("identity_invalid","The copied Reason background identity is invalid.");let O=j.releaseSigned?["--test-requirement",`=${Dj}`]:[];if(z("/usr/bin/codesign",["--verify","--strict",...O,Q])!==0)throw new H("identity_invalid_signature","The installed Reason background identity has an invalid signature.");let L=!1;for(let D=0;D<4;D+=1){let N=!1;try{P(J,V),N=!0,Y=!0}catch(q){if(q.code!=="ENOENT")throw q}if(D===0)j.beforePublish?.();try{P(Q,J),L=!0}catch(q){let jj=q.code;if(!["EEXIST","ENOTEMPTY"].includes(jj??""))throw q;if(N)G(V,{recursive:!0,force:!0}),Y=!1;if(D===3)throw q;continue}if(N)G(V,{recursive:!0,force:!0}),Y=!1;break}if(!L)throw Error("Could not publish Reason's background identity.")}catch(O){if(Y&&!U(J)&&U(V))P(V,J);throw O}finally{G(Q,{recursive:!0,force:!0}),G(V,{recursive:!0,force:!0})}}return e(J,j,{verified:Z!==$}),J}function n(j){return K(B(j),".Reason.app.registered")}function t(j){try{let z=M(j);return z.isDirectory()?`${z.ino}:${z.birthtimeMs}`:null}catch{return null}}function k(j){let z=t(j);try{return z!==null&&I(n(j),"utf8")===z}catch{return!1}}function a(j){if(w(j))return"bundle";try{if(M(K(j,"Contents","Info.plist"),{throwIfNoEntry:!1}))return null;return M(K(j,"Contents","MacOS",S)).isSymbolicLink()?"retired":null}catch{return null}}function e(j,z,J={}){let W=z.command??i;if(!J.verified&&W("/usr/bin/codesign",["--verify","--strict",j])!==0)throw new H("identity_invalid_signature","The installed Reason background identity has an invalid signature.");if(W(T,["-f",j])!==0)throw new H("identity_register_failed","Could not register Reason's macOS background identity.");let Z=t(j);try{if(Z)qj(n(j),Z,{mode:384})}catch{}try{Oj(j,z.home,W,z.runningExecutables??Bj)}catch($){let X=$.code??"unknown";process.stderr.write(`Reason background identity: legacy_identity_retire_failed (${X})
5
+ `)}}function Oj(j,z,J,W){let Z=f(j);if(!Z)return;let $=_(z),X=B($),Q=(q)=>K(q,"Contents","MacOS",S),V=Kj(B(Q($)),Z),Y=`${process.pid}.${d()}`,O=a($);if(O===null)return;let L=O==="bundle";if(L)J(T,["-u",$]);let D=K(X,`.Ara.app.${Y}.old`);if(!l.has($)&&!Pj(W())){if(!L)J(T,["-u",$]);try{P($,D)}catch(q){if(q.code==="ENOENT")return;throw q}G(D,{recursive:!0,force:!0}),Lj(X);return}if(!L){if(Zj(Q($))===V)return;let q=`${Q($)}.${Y}`;E(V,q);try{P(q,Q($))}finally{G(q,{force:!0})}return}let N=K(X,`.Ara.app.${Y}.shim`);h(B(Q(N)),{recursive:!0}),E(V,Q(N));try{try{P($,D)}catch(q){if(q.code==="ENOENT")return;throw q}try{P(N,$)}catch(q){if(U($))return;throw P(D,$),q}}finally{G(N,{recursive:!0,force:!0}),G(D,{recursive:!0,force:!0})}}function Lj(j){try{if(Wj(j).some((J)=>J!==".DS_Store"))return;G(K(j,".DS_Store"),{force:!0}),$j(j)}catch{}}var x=new Map;function Hj(j=F()){let z=x.get(j);if(z)return z;if(process.platform!=="darwin")return[];let J=g(j);if(J===null&&U(B(v(j))))Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,100),J=g(j);if(J===null)return[];return x.set(j,J),J}function g(j){let z=v(j),J=_(j);if(!w(z)||!k(z))try{Mj({home:j,skipWhenSettled:!0})}catch{}let W=w(z)&&(k(z)||!w(J))?z:w(J)?J:null,Z=W?f(W):null;if(!Z)return null;if(W===J)l.add(J);let $=C(Z,["--can-spawn"],{env:{},timeout:2000,encoding:"utf8"});return $.status===0&&$.stdout===`spawn
6
+ `?[Z,"--spawn"]:[]}var y=new Map;function Cj(j=F()){let z=Hj(j),J=z[0];if(!J)return[];let W=y.get(J);if(W===void 0){let Z=C(J,["--can-spawn-computer-use"],{env:{},timeout:2000,encoding:"utf8"});W=Z.status===0&&Z.stdout===`spawn
7
+ `,y.set(J,W)}return W?z:[]}function Ej(j=Cj(),z=F()){if(j.length>0)return null;if(u(z)===null)return"computer_use_identity_missing";return Gj(b,z)?"computer_use_identity_outdated":"computer_use_identity_unavailable"}function Mj(j={}){r(j.home);let z=v(j.home);if(j.skipWhenSettled&&w(z)&&k(z)&&a(_(j.home))===null)return!0;if(!w(z)){let J=_(j.home);if(!w(J))return!1;try{return vj({...j,sourceApp:J}),!0}catch(W){if(!w(z))throw W}}return e(z,j),!0}var Rj="REASON_WORKER_IDENTITY_APP";function xj(j,z=process.env,J=F()){let W=z[Rj];return W&&W===v(J)?W:j}function gj(j,z){if(process.platform!=="darwin")return null;let J=v(j),W=K(J,"Contents","MacOS",m),Z=C(W,["--can-run-worker",z],{env:{},timeout:2000,encoding:"utf8"});return Z.status===0&&Z.stdout===`run-worker
8
+ `?{app:J,executable:W}:null}
9
+ export{s as Bi,Vj as Ci,Sj as Di,H as Ei,T as Fi,v as Gi,fj as Hi,u as Ii,Gj as Ji,vj as Ki,Hj as Li,Cj as Mi,Ej as Ni,Mj as Oi,Rj as Pi,xj as Qi,gj as Ri};