@reason-machines/cli-linux-arm64-musl 0.2.381 → 0.2.383

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 (111) hide show
  1. package/README.md +3 -1
  2. package/bin/ara +2 -2
  3. package/bin/vm-hands/api-credentials-xppmbg0m.js +2 -0
  4. package/bin/vm-hands/api-xmpbsm6b.js +2 -0
  5. package/bin/vm-hands/{ask-relay-fc0jc3t5.js → ask-relay-h8f5dmfh.js} +3 -3
  6. package/bin/vm-hands/connect-cli-qvfxpk5t.js +2 -0
  7. package/bin/vm-hands/{custom-endpoint-device-zhpake9f.js → custom-endpoint-device-bm94e9r0.js} +1 -1
  8. package/bin/vm-hands/desktop-account-3tnm4z5w.js +2 -0
  9. package/bin/vm-hands/{device-workspace-vbcry9d6.js → device-workspace-0xsj5ykf.js} +1 -1
  10. package/bin/vm-hands/hands-worker-source-azdrrhsz.js +2 -0
  11. package/bin/vm-hands/{index-bbk6a9sk.js → index-7f2kwwen.js} +1 -1
  12. package/bin/vm-hands/{install-receipt-7x81ek76.js → install-receipt-3xyx3rdd.js} +1 -1
  13. package/bin/vm-hands/local-automation-pvy9revm.js +2 -0
  14. package/bin/vm-hands/local-capabilities-zfzyknay.js +2 -0
  15. package/bin/vm-hands/local-desktop-users-ajb81vjm.js +2 -0
  16. package/bin/vm-hands/local-display-mac-9h6btvvq.js +2 -0
  17. package/bin/vm-hands/local-display-session-xqncvp30.js +2 -0
  18. package/bin/vm-hands/local-pty-session-cjas515w.js +2 -0
  19. package/bin/vm-hands/managed-runtime-s414h5nm.js +2 -0
  20. package/bin/vm-hands/{network-contract-zqvt1v0t.js → network-contract-dsw79qkc.js} +1 -1
  21. package/bin/vm-hands/package-smk3nqjs.js +2 -0
  22. package/bin/vm-hands/permissions-3mkk9mfw.js +2 -0
  23. package/bin/vm-hands/{reason-hands-protocol-8fxjynte.js → reason-hands-protocol-7d7xj1h3.js} +1 -1
  24. package/bin/vm-hands/serve-service-txzqn5kj.js +2 -0
  25. package/bin/vm-hands/status-23eqx9t3.js +96 -0
  26. package/bin/vm-hands/version-3gj9bqhc.js +2 -0
  27. package/bin/vm-hands/{vm-hands-entry-lite-7shpbsw8.js → vm-hands-entry-lite-1gxktkpe.js} +2 -2
  28. package/bin/vm-hands/vm-hands-entry-lite-2e18tm6w.js +245 -0
  29. package/bin/vm-hands/{vm-hands-entry-lite-g036gtem.js → vm-hands-entry-lite-2t0vcvd8.js} +1 -1
  30. package/bin/vm-hands/vm-hands-entry-lite-3dc4v5bd.js +11 -0
  31. package/bin/vm-hands/{vm-hands-entry-lite-hgkf1svv.js → vm-hands-entry-lite-41nygv3p.js} +2 -2
  32. package/bin/vm-hands/{vm-hands-entry-lite-j2q1k9vb.js → vm-hands-entry-lite-51hmj6am.js} +1 -1
  33. package/bin/vm-hands/{vm-hands-entry-lite-zfwg7ehq.js → vm-hands-entry-lite-5n4vsm6b.js} +2 -2
  34. package/bin/vm-hands/{vm-hands-entry-lite-k7wwza46.js → vm-hands-entry-lite-7xbgw4m0.js} +2 -2
  35. package/bin/vm-hands/vm-hands-entry-lite-8fj07njx.js +3 -0
  36. package/bin/vm-hands/{vm-hands-entry-lite-3hbe4em3.js → vm-hands-entry-lite-9cmfthkq.js} +1 -1
  37. package/bin/vm-hands/{vm-hands-entry-lite-4q8tsaqv.js → vm-hands-entry-lite-9r5tz2dx.js} +2 -2
  38. package/bin/vm-hands/{vm-hands-entry-lite-45j8qwsf.js → vm-hands-entry-lite-9w5vs9zv.js} +1 -1
  39. package/bin/vm-hands/vm-hands-entry-lite-a0yfp7s2.js +251 -0
  40. package/bin/vm-hands/{vm-hands-entry-lite-za55dtte.js → vm-hands-entry-lite-ammr3xbc.js} +2 -2
  41. package/bin/vm-hands/vm-hands-entry-lite-dh5gwmyf.js +3 -0
  42. package/bin/vm-hands/{vm-hands-entry-lite-5pm6bhb8.js → vm-hands-entry-lite-e0gdt6r5.js} +1 -1
  43. package/bin/vm-hands/{vm-hands-entry-lite-5kgvss4p.js → vm-hands-entry-lite-e2mjbqmr.js} +2 -2
  44. package/bin/vm-hands/vm-hands-entry-lite-ejm5er3h.js +7 -0
  45. package/bin/vm-hands/vm-hands-entry-lite-eqhsewc0.js +105 -0
  46. package/bin/vm-hands/{vm-hands-entry-lite-mh0xecf3.js → vm-hands-entry-lite-f02906k8.js} +4 -4
  47. package/bin/vm-hands/vm-hands-entry-lite-f5230h6t.js +67 -0
  48. package/bin/vm-hands/{vm-hands-entry-lite-zh8p7ndn.js → vm-hands-entry-lite-fb5dzy9x.js} +2 -2
  49. package/bin/vm-hands/{vm-hands-entry-lite-yjn6sk08.js → vm-hands-entry-lite-fcrqyxz0.js} +1 -1
  50. package/bin/vm-hands/vm-hands-entry-lite-fyvgav60.js +3 -0
  51. package/bin/vm-hands/vm-hands-entry-lite-g5grabna.js +540 -0
  52. package/bin/vm-hands/vm-hands-entry-lite-g7h6wjqy.js +3 -0
  53. package/bin/vm-hands/{vm-hands-entry-lite-34e71nbe.js → vm-hands-entry-lite-g8pj1jxa.js} +174 -16
  54. package/bin/vm-hands/vm-hands-entry-lite-h1rxv02g.js +458 -0
  55. package/bin/vm-hands/vm-hands-entry-lite-h8dbw0c7.js +4 -0
  56. package/bin/vm-hands/{vm-hands-entry-lite-nhtb458c.js → vm-hands-entry-lite-hnsm5t36.js} +1 -1
  57. package/bin/vm-hands/{vm-hands-entry-lite-0asdf4pm.js → vm-hands-entry-lite-jzcc9h71.js} +3 -3
  58. package/bin/vm-hands/{vm-hands-entry-lite-r6pap1kh.js → vm-hands-entry-lite-ma001vzh.js} +1 -1
  59. package/bin/vm-hands/{vm-hands-entry-lite-anmv8hp7.js → vm-hands-entry-lite-mn64e4pt.js} +286 -104
  60. package/bin/vm-hands/{vm-hands-entry-lite-9cgm6g8t.js → vm-hands-entry-lite-pk3q774c.js} +1 -1
  61. package/bin/vm-hands/vm-hands-entry-lite-qef2ndkd.js +6 -0
  62. package/bin/vm-hands/vm-hands-entry-lite-qnnfvm5r.js +5 -0
  63. package/bin/vm-hands/vm-hands-entry-lite-r8qg3wp1.js +3 -0
  64. package/bin/vm-hands/vm-hands-entry-lite-rd0ak4ye.js +4 -0
  65. package/bin/vm-hands/{vm-hands-entry-lite-00qsbphw.js → vm-hands-entry-lite-rpn0frzb.js} +2 -2
  66. package/bin/vm-hands/{vm-hands-entry-lite-g9rvf5qk.js → vm-hands-entry-lite-rtt2w6c6.js} +1 -1
  67. package/bin/vm-hands/vm-hands-entry-lite-sex82vb1.js +3 -0
  68. package/bin/vm-hands/vm-hands-entry-lite-vcwgh8tr.js +346 -0
  69. package/bin/vm-hands/{vm-hands-entry-lite-dgxxsdwb.js → vm-hands-entry-lite-xrthfx3q.js} +2 -2
  70. package/bin/vm-hands/{vm-hands-entry-lite-kxdw4myj.js → vm-hands-entry-lite-y2s2w174.js} +1 -1
  71. package/bin/vm-hands/{vm-hands-entry-lite-hc3p6r9p.js → vm-hands-entry-lite-zjfr0zh8.js} +2 -2
  72. package/bin/vm-hands/vm-hands-entry-lite.js +1 -1
  73. package/bin/vm-hands/{vm-hands-executor-qssgfea1.js → vm-hands-executor-9p92j0mv.js} +1 -1
  74. package/bin/vm-hands/vm-hands-op-runner-ers4cefp.js +2 -0
  75. package/bin/vm-hands/{vm-hands-runtime-5me6cpmn.js → vm-hands-runtime-en4gj0t0.js} +3 -3
  76. package/bin/vm-hands/worker-sandbox-tgqbmy6b.js +2 -0
  77. package/package.json +1 -1
  78. package/bin/vm-hands/api-af9g18n7.js +0 -2
  79. package/bin/vm-hands/api-credentials-65mrr3tn.js +0 -2
  80. package/bin/vm-hands/connect-cli-j478km3s.js +0 -2
  81. package/bin/vm-hands/desktop-account-5zvgspyw.js +0 -2
  82. package/bin/vm-hands/hands-worker-source-h0b1j53p.js +0 -2
  83. package/bin/vm-hands/local-automation-c86tjeft.js +0 -2
  84. package/bin/vm-hands/local-capabilities-1h99gkt6.js +0 -2
  85. package/bin/vm-hands/local-desktop-users-0hadyvx1.js +0 -2
  86. package/bin/vm-hands/local-display-mac-v1pc7177.js +0 -2
  87. package/bin/vm-hands/local-display-session-tzq0hne8.js +0 -2
  88. package/bin/vm-hands/local-pty-session-hs7rq03x.js +0 -2
  89. package/bin/vm-hands/managed-runtime-5dqaaw1x.js +0 -2
  90. package/bin/vm-hands/package-3cd7cfyv.js +0 -2
  91. package/bin/vm-hands/permissions-vbyqjbyb.js +0 -2
  92. package/bin/vm-hands/serve-service-be739c9s.js +0 -2
  93. package/bin/vm-hands/status-s8ny6men.js +0 -96
  94. package/bin/vm-hands/version-8s4syrp2.js +0 -2
  95. package/bin/vm-hands/vm-hands-entry-lite-1085xsma.js +0 -5
  96. package/bin/vm-hands/vm-hands-entry-lite-4m40gwkf.js +0 -3
  97. package/bin/vm-hands/vm-hands-entry-lite-62wmnm7g.js +0 -540
  98. package/bin/vm-hands/vm-hands-entry-lite-98076n5g.js +0 -62
  99. package/bin/vm-hands/vm-hands-entry-lite-bvbfcp1k.js +0 -4
  100. package/bin/vm-hands/vm-hands-entry-lite-c01eyep6.js +0 -3
  101. package/bin/vm-hands/vm-hands-entry-lite-dcynw6t2.js +0 -3
  102. package/bin/vm-hands/vm-hands-entry-lite-hh24bq0d.js +0 -3
  103. package/bin/vm-hands/vm-hands-entry-lite-jb2sr2r7.js +0 -3
  104. package/bin/vm-hands/vm-hands-entry-lite-kt5aj2ax.js +0 -11
  105. package/bin/vm-hands/vm-hands-entry-lite-n9nnb482.js +0 -459
  106. package/bin/vm-hands/vm-hands-entry-lite-sb9a1jcn.js +0 -4
  107. package/bin/vm-hands/vm-hands-entry-lite-xg3d0a2y.js +0 -340
  108. package/bin/vm-hands/vm-hands-entry-lite-zamt8xp7.js +0 -181
  109. package/bin/vm-hands/vm-hands-entry-lite-ze9msfq1.js +0 -3
  110. package/bin/vm-hands/vm-hands-op-runner-b76rjaps.js +0 -2
  111. package/bin/vm-hands/worker-sandbox-wpzkvwer.js +0 -2
@@ -1,62 +0,0 @@
1
- // @bun
2
- import{ae as p,ce as V,fe as f}from"./vm-hands-entry-lite-1085xsma.js";import{Zh as E}from"./vm-hands-entry-lite-5kgvss4p.js";import{ni as y}from"./vm-hands-entry-lite-r6pap1kh.js";import{Hi as m,Vi as w,Xi as u}from"./vm-hands-entry-lite-4q8tsaqv.js";import{spawnSync as F}from"child_process";import{createHash as e,randomUUID as zz}from"crypto";import{chmodSync as Hz,existsSync as P,mkdirSync as Jz,readdirSync as Mz,readFileSync as L,renameSync as Qz,rmSync as T,statSync as Zz,writeFileSync as $z}from"fs";import{dirname as Bz,isAbsolute as v,join as A}from"path";var W="REASON_WORKER_SERVICE",jz="worker_identity_unavailable";function Iz(H){return{platform:process.platform,home:H,uid:process.getuid?.(),command:(z,M)=>F(z,[...M],{stdio:"ignore"}).status??1,read:(z,M)=>{let J=F(z,[...M],{stdio:["ignore","pipe","ignore"],encoding:"utf8",timeout:1e4});return J.status===0?J.stdout:null},sleep:(z)=>Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,z),workerIdentity:(z)=>u(H,z),insideService:(z)=>qz(z,process.platform,process.getuid?.())}}function qz(H,z,M){if(process.env[W]===H||process.env.XPC_SERVICE_NAME===H)return!0;if(z==="linux")try{return L("/proc/self/cgroup","utf8").includes(`/${H}.service`)}catch{return!0}if(z!=="darwin")return!1;if(typeof M!=="number")return!0;let J=F("/bin/launchctl",["print",`gui/${M}/${H}`],{encoding:"utf8",timeout:5000});if(J.status===Tz)return!1;if(J.error||J.status!==0)return!0;let Q=Number(/^\s*pid = (\d+)$/m.exec(J.stdout??"")?.[1]??0);if(!Q)return!1;let Z=process.pid;for(let B=0;B<64&&Z>1;B+=1){if(Z===Q)return!0;let $=F("/bin/ps",["-o","ppid=","-p",String(Z)],{encoding:"utf8",timeout:5000}),j=Number($.stdout?.trim());if($.error||$.status!==0||!Number.isSafeInteger(j)||j<=0)return!0;if(j===Z)return!1;Z=j}return Z>1}var Tz=113;class q extends Error{code;constructor(H,z){super(H);this.code=z}}function bz(H,z){if(H.platform!=="darwin"&&H.platform!=="linux")throw new q("A background service needs macOS (launchd) or Linux (systemd --user).");if(H.platform==="darwin")U(H);let J=[f(p(z,H.home))?.owned_paths.find((Q)=>Q.role==="launcher")?.path,y(z,"REASON_CLI_LAUNCHER_PATH")?.trim(),A(H.home,".local","bin",E({env:z})==="staging"?"ara-staging":"ara")];for(let Q of J)try{if(Q&&v(Q)&&Zz(Q).isFile())return V(Q)}catch{}throw new q("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 I=/(<key>ProgramArguments<\/key>\s*<array>\n)((?:\s*<string>[^<]*<\/string>\n)*)(\s*<\/array>)/,X=new RegExp(`(\\n\\s*<key>${w}</key>\\s*<string>)[^<]*(</string>)`),Gz=/(<key>EnvironmentVariables<\/key>\s*<dict>[\s\S]*?)(\n\s*<\/dict>)/;function Yz(H){return H.replaceAll("&lt;","<").replaceAll("&gt;",">").replaceAll("&quot;",'"').replaceAll("&apos;","'").replaceAll("&amp;","&")}function b(H){let z=[...(I.exec(H)?.[2]??"").matchAll(/<string>([^<]*)<\/string>/g)].map((J)=>Yz(J[1])),M=z[1]==="--run-worker"?z.slice(2):z;return M[0]?{launcher:M[0],args:M.slice(1)}:null}function Sz(H,z){if(!Az(z))return null;try{return b(L(A(H,"Library","LaunchAgents",`${z}.plist`),"utf8"))?.launcher??null}catch{return null}}function d(H,z,M){let J=M.workerIdentity?.(H)??null;return{program:J?[J.executable,"--run-worker",H,...z]:[H,...z],identity:J}}function S(H){return H.map((z)=>` <string>${G(z)}</string>`).join(`
3
- `)}function g(H,z){let M;try{M=L(H,"utf8")}catch{return null}let J=b(M);if(!J)return null;let Q=v(J.launcher)?V(J.launcher):J.launcher,{program:Z,identity:B}=d(Q,J.args,z),$=M.replace(I,(j,Y,N,R)=>`${Y}${S(Z)}
4
- ${R}`);if(!B)$=$.replace(X,"");else if(X.test($))$=$.replace(X,(j,Y,N)=>`${Y}${G(B.app)}${N}`);else $=$.replace(Gz,(j,Y,N)=>`${Y}
5
- <key>${w}</key>
6
- <string>${G(B.app)}</string>${N}`);return $===M?null:$}function Nz(H,z){let M=g(H,z);if(M!==null)C(H,M)}function _z(H,z,M){if(z.platform!=="darwin")return!1;let J=x(H,z,M);return J!==null&&g(J.definition,z)!==null}var K="com.reasonmachines.worker.",_="so.reason.worker.",O=[K,_];function Az(H){return O.some((z)=>H.startsWith(z)&&/^[A-Za-z0-9._-]+$/.test(H.slice(z.length)))}function l(H,z=K){return`${z}connect${H==="production"?"":`.${H}`}`}function xz(H,z){return O.some((M)=>H===l(z,M))}function Dz(H,z,M){if(z==="connect")return l(H.channel,M);let J=e("sha256").update(H.workspaceRoot).digest("hex").slice(0,8);return`${M}${H.name.toLowerCase()}.${J}`}function a(H,z){if(z==="darwin")return{directory:A(H,"Library","LaunchAgents"),suffix:".plist"};if(z==="linux")return{directory:A(H,".config","systemd","user"),suffix:".service"};return null}function D(H,z,M,J=K){let Q=Dz(H,M,J),Z=a(z.home,z.platform);if(!Z)return null;return{label:Q,definition:A(Z.directory,`${Q}${Z.suffix}`),logs:z.platform==="darwin"?A(H.stateDirectory,"service.log"):`journalctl --user -u ${Q}.service`}}function Rz(H,z){let M=a(H,z);if(!M)return[];try{return Mz(M.directory).filter((J)=>O.some((Q)=>J.startsWith(Q))&&J.endsWith(M.suffix)).sort().map((J)=>A(M.directory,J))}catch{return[]}}function x(H,z,M="serve"){return h(H,z,M)[0]??null}function h(H,z,M){return O.map((J)=>D(H,z,M,J)).filter((J)=>J!==null&&P(J.definition))}function c(H,z,M){let J=D(H,z,M,_);return J&&P(J.definition)?J:null}function Lz(H,z,M){let J=D(H,z,M),Q=c(H,z,M);if(!J||!Q||!P(J.definition)||z.insideService?.(Q.label))return null;if(!Uz(J,z))return"current_not_running";if(z.platform==="darwin"){if(typeof z.uid==="number"&&z.uid>0)z.command("/bin/launchctl",["bootout",`gui/${z.uid}/${Q.label}`]);return T(Q.definition,{force:!0}),"retired"}return z.command("systemctl",["--user","disable","--now",`${Q.label}.service`]),T(Q.definition,{force:!0}),z.command("systemctl",["--user","daemon-reload"]),"retired"}function Uz(H,z){if(z.platform==="darwin")return typeof z.uid==="number"&&z.uid>0&&z.command("/bin/launchctl",["print",`gui/${z.uid}/${H.label}`])===0;let M=`${H.label}.service`;return z.command("systemctl",["--user","is-enabled","--quiet",M])===0&&Xz.has(z.read("systemctl",["--user","show","--property=ActiveState","--value",M])?.trim()??"")}var Xz=new Set(["active","activating","reloading"]);function kz(H,z){if(z.platform==="darwin"){if(typeof z.uid!=="number"||z.uid<=0)return!1;let M=z.read("/bin/launchctl",["print",`gui/${z.uid}/${H.label}`]);return Number(/^\s*pid = (\d+)$/m.exec(M??"")?.[1]??0)>0}return Number(z.read("systemctl",["--user","show","--property=MainPID","--value",`${H.label}.service`])?.trim()??0)>0}function yz(H){let{config:z,launcher:M,host:J,kind:Q}=H,Z=D(z,J,Q);if(!Z)return!1;let B;try{B=L(Z.definition,"utf8")}catch{return!1}if(J.platform!=="darwin")return B===s(z,Q,Z,M,J.home,H.path);let $=b(B);return B.replace(X,"").replace(I,(Y,N,R,o)=>`${N}${$?`${S([$.launcher,...$.args])}
7
- `:""}${o}`)===r(z,Q,Z,M,{...J,workerIdentity:()=>null},H.path).plist}function n(H,z){if(z==="connect")return{args:["connect"],environment:{REASON_CLI_CHANNEL:H.channel},description:"Reason connection of this computer"};return{args:["serve",H.name,"--dir",H.workspaceRoot,...H.executionMode==="confined"?["--sandbox"]:[]],environment:{},description:`Reason machine ${H.name} worker`}}function G(H){return H.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&apos;")}function k(H,z=!1){if(/[\0-\x1f\x7f]/.test(H))throw new q("A background service cannot use a path with control characters.");let M=H.replaceAll("\\","\\\\").replaceAll('"',"\\\"").replaceAll("%","%%");return`"${z?M.replaceAll("$","$$$$"):M}"`}function r(H,z,M,J,Q,Z){let B=n(H,z),$=d(J,B.args,Q),j={HOME:Q.home,PATH:Z,[W]:M.label,...B.environment,...$.identity?{[w]:$.identity.app}:{}};return{identity:$.identity,plist:`<?xml version="1.0" encoding="UTF-8"?>
8
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
9
- <plist version="1.0">
10
- <dict>
11
- <key>Label</key>
12
- <string>${G(M.label)}</string>
13
- <key>AssociatedBundleIdentifiers</key>
14
- <array>
15
- <string>${m}</string>
16
- </array>
17
- <key>ProgramArguments</key>
18
- <array>
19
- ${S($.program)}
20
- </array>
21
- <key>EnvironmentVariables</key>
22
- <dict>
23
- ${Object.entries(j).map(([Y,N])=>` <key>${Y}</key>
24
- <string>${G(N)}</string>`).join(`
25
- `)}
26
- </dict>
27
- <key>RunAtLoad</key>
28
- <true/>
29
- <key>KeepAlive</key>
30
- <dict>
31
- <key>SuccessfulExit</key>
32
- <false/>
33
- </dict>
34
- <key>ThrottleInterval</key>
35
- <integer>10</integer>
36
- <key>ExitTimeOut</key>
37
- <integer>${Math.ceil(H.shutdownGraceMs/1000)+10}</integer>
38
- <key>ProcessType</key>
39
- <string>Standard</string>
40
- <key>Umask</key>
41
- <integer>63</integer>
42
- <key>StandardOutPath</key>
43
- <string>${G(M.logs)}</string>
44
- <key>StandardErrorPath</key>
45
- <string>${G(M.logs)}</string>
46
- </dict>
47
- </plist>
48
- `}}function s(H,z,M,J,Q,Z){let B=n(H,z);return`[Unit]
49
- Description=${B.description}
50
-
51
- [Service]
52
- ExecStart=${[J,...B.args].map(($)=>k($,!0)).join(" ")}
53
- Environment=${[`HOME=${Q}`,`PATH=${Z}`,`${W}=${M.label}`,...Object.entries(B.environment).map(([$,j])=>`${$}=${j}`)].map(($)=>k($)).join(" ")}
54
- Restart=on-failure
55
- RestartSec=10
56
- TimeoutStopSec=${Math.ceil(H.shutdownGraceMs/1000)+10}
57
- UMask=0077
58
-
59
- [Install]
60
- WantedBy=default.target
61
- `}function C(H,z){Jz(Bz(H),{recursive:!0,mode:448});let M=`${H}.${zz()}.tmp`;try{$z(M,z,{mode:384,flag:"wx"}),Hz(M,384),Qz(M,H)}finally{T(M,{force:!0})}}function U(H){if(typeof H.uid!=="number"||!Number.isSafeInteger(H.uid)||H.uid<=0)throw new q("Set up a background service as your own user, not with sudo.","worker_service_root_user");return`gui/${H.uid}`}function Ez(H){let{config:z,launcher:M,host:J}=H,Q=H.kind??"serve",Z=c(z,J,Q),B=Z!==null&&J.insideService?.(Z.label)===!0,$=D(z,J,Q,B?_:K);if(!$)throw new q("A background service needs macOS (launchd) or Linux (systemd --user).");if(J.platform==="darwin")U(J);if(J.platform==="linux"&&J.command("systemctl",["--user","show-environment"])!==0)throw new q("No background service here: this computer has no systemd user session.","worker_service_manager_missing");let j=J.platform==="darwin"?r(z,Q,$,M,J,H.path):null;if(C($.definition,j?j.plist:s(z,Q,$,M,J.home,H.path)),i(z,J,$,B?null:Z),j)return j.identity?$:{...$,identityProblem:jz};return{...$,lingering:J.command("loginctl",["enable-linger"])===0}}function i(H,z,M,J){if(z.platform==="darwin"){let B=U(z);if(J)z.command("/bin/launchctl",["bootout",`${B}/${J.label}`]);if(t(H,M,z)){if(J)T(J.definition,{force:!0});return}if(T(M.definition,{force:!0}),J)z.command("/bin/launchctl",["bootstrap",B,J.definition]);throw new q("Could not start the background service (launchctl bootstrap failed).","worker_service_start_failed")}let Q=`${M.label}.service`,Z=J?`${J.label}.service`:null;if(z.command("systemctl",["--user","daemon-reload"])!==0||Z!==null&&z.command("systemctl",["--user","disable","--now",Z])!==0||z.command("systemctl",["--user","enable",Q])!==0||z.command("systemctl",["--user","restart",Q])!==0){if(z.command("systemctl",["--user","disable",Q]),T(M.definition,{force:!0}),z.command("systemctl",["--user","daemon-reload"]),Z)z.command("systemctl",["--user","enable","--now",Z]);throw new q("Could not start the background service (systemctl --user failed).","worker_service_start_failed")}if(J)T(J.definition,{force:!0}),z.command("systemctl",["--user","daemon-reload"])}function t(H,z,M){let J=U(M);M.command("/bin/launchctl",["bootout",`${J}/${z.label}`]);let Q=(Math.ceil(H.shutdownGraceMs/1000)+10)*1000;for(let Z=0,B=100;;B=Math.min(B*2,2000)){if(M.command("/bin/launchctl",["bootstrap",J,z.definition])===0)return!0;if(Z>=Q)return!1;M.sleep(B),Z+=B}}function mz(H,z,M){let J=x(H,z,M);if(!J)return null;let Q=z.insideService?.(J.label)===!0;if(z.platform==="darwin"&&!Q)Nz(J.definition,z);let Z=D(H,z,M);if(Z&&J.label!==Z.label&&!Q)return C(Z.definition,L(J.definition,"utf8").replaceAll(J.label,Z.label)),i(H,z,Z,J),Z;let B=z.platform==="darwin"&&Q,$;if(B)$=z.command("/bin/launchctl",["kickstart","-k",`${U(z)}/${J.label}`])===0;else if(z.platform==="darwin")$=t(H,J,z);else z.command("systemctl",["--user","enable",`${J.label}.service`]),$=z.command("systemctl",["--user","restart",`${J.label}.service`])===0;if(!$)throw new q(`Could not restart the background service ${J.label}.`,"worker_service_restart_failed");if(Z&&J.label===Z.label)Lz(H,z,M);return J}function uz(H,z,M,J){let Q=x(H,M,J),Z=D(z,M,J);if(M.platform!=="darwin"||!Q||!Z)return;let B=`<string>${G(Q.logs)}</string>`,$=L(Q.definition,"utf8");if($.includes(B))C(Q.definition,$.replaceAll(B,`<string>${G(Z.logs)}</string>`))}function pz(H,z,M="serve"){let J=h(H,z,M);for(let Q of J){if(z.platform==="darwin"){if(typeof z.uid==="number"&&z.uid>0)z.command("/bin/launchctl",["bootout",`gui/${z.uid}/${Q.label}`]);T(Q.definition,{force:!0});continue}z.command("systemctl",["--user","disable","--now",`${Q.label}.service`]),T(Q.definition,{force:!0}),z.command("systemctl",["--user","daemon-reload"])}return J[0]??null}
62
- export{W as Dd,jz as Ed,Iz as Fd,q as Gd,bz as Hd,Sz as Id,_z as Jd,l as Kd,xz as Ld,Rz as Md,x as Nd,Lz as Od,kz as Pd,yz as Qd,Ez as Rd,mz as Sd,uz as Td,pz as Ud};
@@ -1,4 +0,0 @@
1
- // @bun
2
- import{bk as C}from"./vm-hands-entry-lite-j2q1k9vb.js";import{execFileSync as W}from"child_process";import{mkdirSync as b,readdirSync as R,readFileSync as F,rmSync as B,statSync as K,writeFileSync as f}from"fs";import{join as $}from"path";import{setTimeout as k}from"timers/promises";var A=3000,X=null;function G(z){return $(z,"users")}function m(z){if(X?.root===z.root)return;let H=G(z.root);b(H,{recursive:!0,mode:448}),f($(H,String(process.pid)),"",{mode:384}),X=z}function S(){if(!X)return;B($(G(X.root),String(process.pid)),{force:!0}),X=null}function x(z){try{return process.kill(z,0),!0}catch(H){return H instanceof Error&&"code"in H&&H.code==="EPERM"}}function L(){let z=process.getuid?.();if(process.platform==="linux")return R("/proc").flatMap((N)=>{if(!/^\d+$/.test(N))return[];try{if(K(`/proc/${N}`).uid!==z)return[];let Q=F(`/proc/${N}/cmdline`).toString("utf8").split("\x00").join(" ").trim();return Q?[{pid:Number(N),command:Q}]:[]}catch{return[]}});return W("/bin/ps",["-axww","-o","pid=,uid=,command="],{encoding:"utf8",maxBuffer:16777216}).split(`
3
- `).flatMap((N)=>{let Q=/^\s*(\d+)\s+(\d+)\s+(.+)$/.exec(N);return Q&&Number(Q[2])===z?[{pid:Number(Q[1]),command:Q[3]}]:[]})}async function p(){let z=X;if(!z)return{released:"unused",stopped:0};let H=G(z.root);B($(H,String(process.pid)),{force:!0}),X=null;let N=!1;for(let J of R(H)){let U=Number(J);if(Number.isSafeInteger(U)&&U>0&&x(U))N=!0;else B($(H,J),{force:!0})}if(N)return{released:"shared",stopped:0};let Q=L().filter((J)=>J.pid!==process.pid&&(J.command.includes(`${z.root}/`)||J.command.includes(`${z.automation}/`)||J.command.includes(z.extensionDir))),Y=(J,U)=>{try{process.kill(J,U)}catch{}};for(let J of Q)Y(J.pid,"SIGTERM");for(let J=Date.now()+A;Date.now()<J&&Q.some((U)=>x(U.pid));)await new Promise((U)=>setTimeout(U,100));for(let J of Q)if(x(J.pid))Y(J.pid,"SIGKILL");return{released:"stopped",stopped:Q.length}}var O=20000,j=30000,v=100,Z=new Map,V=null,q=[];function h(z){Z.set(z,(Z.get(z)??0)+1);let H=!1;return()=>{if(H)return;H=!0;let N=(Z.get(z)??1)-1;if(N>0){Z.set(z,N);return}if(Z.delete(z),V?.run===z)V.idleUntil=0}}function M(){return new C("automation_desktop_busy","Another Session, or another agent of this Session, is using this worker's desktop. Retry after it finishes.")}function P(z,H){return V!==null&&V.run!==z&&(V.calls>0||H<V.idleUntil)}async function I(z,H,N=Date.now){let Q=Symbol(z);q.push(Q);try{let U=N()+j;for(;;){if(!P(z,N())&&(V?.run===z||q[0]===Q))break;if(N()>=U)throw M();await k(v,void 0,{signal:H}).catch(()=>H.throwIfAborted())}}finally{q.splice(q.indexOf(Q),1)}if(V?.run!==z)V={run:z,calls:0,idleUntil:0};let Y=V;Y.calls+=1;let J=!1;return()=>{if(J)return;J=!0,Y.calls-=1,Y.idleUntil=N()+O}}
4
- export{m as Wj,S as Xj,p as Yj,O as Zj,j as _j,h as $j,I as ak};
@@ -1,3 +0,0 @@
1
- // @bun
2
- import{fj as X,hj as Y,jj as Z}from"./vm-hands-entry-lite-9cgm6g8t.js";import{execFileSync as z}from"child_process";import{existsSync as V,realpathSync as M}from"fs";import{userInfo as D}from"os";import{isAbsolute as $,join as C,normalize as F,parse as K}from"path";function Q(){let q=F(D().homedir);if(!$(q)||q===K(q).root)throw Error("Could not resolve the canonical macOS user home.");return q}function O(q,B,J=Q()){let L=Z(B);if(B.kind==="managed"&&B.base){let G=M(J);return{anchor:G,boundary:C(G,B.base),path:C(G,L)}}if(B.kind==="root"&&Y(B.path)){let G=M(J);return{anchor:G,boundary:C(G,X),path:C(G,L)}}return{anchor:q,boundary:q,path:C(q,L)}}function _(q=Q()){return C(q,".config")}function b(){if(process.platform!=="darwin")return null;try{let q=z("/usr/bin/getconf",["DARWIN_USER_DIR"],{encoding:"utf8",timeout:5000}).trim();return $(q)?M(q):null}catch{return null}}function g(q=Q()){let B=C(q,"Library","Application Support","Ara"),J=C(q,"Library","Application Support","Reason");return V(B)&&!V(J)?B:J}
3
- export{Q as Yi,O as Zi,_ as _i,b as $i,g as aj};
@@ -1,3 +0,0 @@
1
- // @bun
2
- import{Ac as R}from"./vm-hands-entry-lite-sb9a1jcn.js";import{Tc as D}from"./vm-hands-entry-lite-hh24bq0d.js";import{bk as $}from"./vm-hands-entry-lite-j2q1k9vb.js";import{spawn as i,spawnSync as n}from"child_process";import{existsSync as I,mkdtempSync as E,readFileSync as O,readdirSync as t,realpathSync as r,rmSync as y,statSync as o}from"fs";import{platform as b,tmpdir as h}from"os";import{dirname as N,join as Y}from"path";import{fileURLToPath as e,pathToFileURL as M}from"url";var jj=["bwrap","socat","rg"],qj=2000,_=20000,zj=3,S=4000,Gj=new Set([".git",".hg",".svn","node_modules"]),Hj=["runAsHostUid","sysrq-trigger"],Jj=Y(N(N(e(import.meta.url))),"packages/sandbox-runtime/src/index.ts"),l=!1;function Cj(){l=!0}async function g(){let q=l?Y(N(r(process.execPath)),"runtime","srt"):void 0;if(q&&process.platform==="linux"&&!I(Y(q,"vendor","seccomp",process.arch,"apply-seccomp")))throw Error("packaged_sandbox_runtime_vendor_missing");if(q){let H=O(Y(q,"sandbox-runtime.mjs"),"utf8");for(let W of Hj)if(!H.includes(W))throw Error(`packaged_sandbox_runtime_fork_missing:${W}`)}let G=(await import(q?M(Y(q,"sandbox-runtime.mjs")).href:M(Jj).href)).SandboxManager;if(!G||typeof G.initialize!=="function"||typeof G.wrapWithSandboxArgv!=="function")throw Error("sandbox-runtime does not expose the expected SandboxManager API.");return{SandboxManager:G}}function Qj(j={}){if((j.platformName??b())!=="linux")return!1;let z=j.fileExists??I,J=j.readFile??((G)=>O(G,"utf8"));for(let G of["/.dockerenv","/run/.containerenv"])try{if(z(G))return!0}catch{}try{return/docker|containerd|kubepods|lxc|libpod/.test(J("/proc/1/cgroup"))}catch{return!1}}function u(j){return["/bin/true","/usr/bin/true"].find((q)=>j(q))??null}function Vj(j,q){return j==="strict"?["--ro-bind","/","/","--unshare-pid","--unshare-user","--cap-drop","ALL","--proc","/proc","--",q]:["--ro-bind","/","/","--unshare-pid","--unshare-user","--bind","/proc","/proc","--",q]}function Wj(j,q){try{let z=n("bwrap",Vj(j,q),{stdio:"ignore",timeout:qj});return!z.error&&z.status===0}catch{return!1}}function Yj(j){let q=j.platformName??b();if(q!=="linux")return null;let z=j.hasExecutable??D;if(!jj.every((Q)=>z(Q)))return null;let J=j.fileExists??I,G=u(J);if(!G)return null;let H=B??(j.containerized??Qj({platformName:q})?"weak":"strict");return(j.probeNamespaces??((Q)=>Wj(Q,G)))(H)?H:null}var L=null,w=!1,k=null,T=null,f=null,B=null,U=null;function A(){throw F("sandbox_mode_conflict"),new $("sandbox_unavailable","Sandbox process policy conflicts with an existing probe or session. Restart the worker.")}function Mj(j){if(B!==null&&B!==j||w&&L!==null&&L!==j||U!==null&&U!==j)A();B=j}function F(j){k=j}function c(j){if(k)return!1;if(!w){if(L=Yj(j??{}),w=!0,L&&!j)d()}return L!==null}function Zj(){return c()?L:null}var X=null,C=0;function m(j){if(k)throw new $("sandbox_unavailable","Confined execution is unavailable in this worker process.");if(B&&j.sandboxMode&&B!==j.sandboxMode)A();let q=B??j.sandboxMode??Zj();if(!q)throw new $("sandbox_unavailable","Confined command execution is unavailable on this operating system.");if(U&&U!==q)A();return U=q,X??=(async()=>{let{SandboxManager:z}=await(j.loadSandboxRuntime??g)();return await z.initialize(Kj(q)),z})().catch((z)=>{throw X=null,F(`initialize_failed: ${String(z)}`),z instanceof $?z:new $("sandbox_unavailable","The confined execution sandbox failed to start.")}),X.then((z)=>{if(k)throw new $("sandbox_unavailable","Confined execution became unavailable during sandbox initialization.");return z})}async function $j(){let j=X;if(X=null,!j)return;try{await(await j).reset()}catch{}}async function d(j={}){if(k)return!1;if(j.loadSandboxRuntime)return P(j.loadSandboxRuntime);if(!c())return!1;return T??=P(g),T}async function P(j){try{let{SandboxManager:q}=await j(),z=q.checkDependencies().errors;if(z.length>0)return F(`dependencies_missing: ${z.join(", ")}`),!1;return!k}catch(q){return F(`load_failed: ${String(q)}`),!1}}async function _j(j={}){if(!j.loadSandboxRuntime&&!j.sandboxMode){if(!await d())return!1;return f??=x({}),f}return x(j)}async function x(j){let q;try{q=await m(j)}catch{return!1}let z=await Bj(q);if(!z)F("confined_command_failed");if(C===0)await $j();return z}async function Bj(j){let q=u(I);if(!q)return!1;let z=E(Y(h(),"reason-device-probe-"));try{let{argv:J}=await j.wrapWithSandboxArgv(s([q]),p(),{filesystem:a({root:z,allowWrite:!1,temporaryDirectory:z,protectedPaths:[]})},void 0,z),[G,...H]=J;if(!G)return!1;return await Lj(G,H,z)}catch{return!1}finally{try{j.cleanupAfterCommand()}catch{}y(z,{recursive:!0,force:!0})}}function Lj(j,q,z,J={}){return new Promise((G)=>{let H=!1,W,Q=(K)=>{if(H)return;H=!0,clearTimeout(W),G(K)},V;try{V=(J.spawnChild??i)(j,q,{cwd:z,env:{PATH:R,HOME:z,TMPDIR:z},stdio:"ignore"})}catch{Q(!1);return}V.once("error",()=>Q(!1));let Z=(K,v)=>Q(K===0&&v===null);if(V.once("exit",Z),V.once("close",Z),V.exitCode!==null||V.signalCode!==null)Z(V.exitCode,V.signalCode);if(H)return;W=setTimeout(()=>{Q(!1);try{V.kill("SIGKILL")}catch{}},Math.min(J.timeoutMs??_,_))})}function p(j=I){return["/bin/bash","/bin/sh"].find((q)=>j(q))??"/bin/sh"}function s(j){return j.map((q)=>`'${q.replaceAll("'","'\\''")}'`).join(" ")}function kj(j,q,z=(J)=>t(J,{withFileTypes:!0}).filter((G)=>G.isDirectory()||G.isFile()).map((G)=>G.name)){let J=[],G=[{path:j,depth:0}],H=0;while(G.length>0&&H<S){let W=G.pop(),Q;try{Q=z(W.path)}catch{continue}for(let V of Q){if(H+=1,H>S)break;let Z=Y(W.path,V);if(q(Z)){J.push(Z);continue}if(W.depth+1<zj&&!Gj.has(V))G.push({path:Z,depth:W.depth+1})}}return J}function a(j){let q=Y(j.root,".git"),z=[];try{if(o(q).isDirectory())z=[Y(q,"config"),Y(q,"hooks")]}catch{}return{denyRead:["/home","/root","/tmp","/tmp/.X11-unix",...j.protectedPaths],allowRead:[j.root,j.temporaryDirectory],allowWrite:[...j.allowWrite?[j.root]:[],j.temporaryDirectory],denyWrite:[...j.protectedPaths,...z]}}function Kj(j){return{network:{allowedDomains:[],deniedDomains:[]},filesystem:{denyRead:[],allowRead:[],allowWrite:[],denyWrite:[]},...j==="weak"?{enableWeakerNestedSandbox:!0}:{}}}function Sj(j){let q=j.createTemporaryDirectory??(()=>E(Y(h(),"reason-device-"))),z=j.removeTemporaryDirectory??((J)=>y(J,{recursive:!0,force:!0}));return async(J,G,H)=>{let W=await m(j),Q=q();C+=1;try{let V;try{V=await W.wrapWithSandboxArgv(s([J,...G]),j.shell??p(),{filesystem:a({root:H.root,allowWrite:H.allowWrite,temporaryDirectory:Q,protectedPaths:kj(H.root,j.isProtectedPath)})},H.signal,H.cwd)}catch(v){throw v instanceof $?v:new $("sandbox_unavailable","The confined execution sandbox could not wrap the command.")}let[Z,...K]=V.argv;if(!Z)throw new $("sandbox_unavailable","The confined execution sandbox produced no command.");return await j.spawnCaptured(Z,K,{cwd:H.cwd,timeoutMs:H.timeoutMs,signal:H.signal,env:j.scrubEnvironment(H.root,Q)})}finally{C-=1;try{W.cleanupAfterCommand()}catch{}z(Q)}}}
3
- export{Cj as uc,Mj as vc,c as wc,_j as xc,p as yc,Sj as zc};
@@ -1,3 +0,0 @@
1
- // @bun
2
- import{spawn as K}from"child_process";import{statSync as L}from"fs";import{delimiter as M,join as N}from"path";function V(q,x=process.env.PATH??""){if(!q||q.includes("/")||q.includes("\x00"))return!1;return x.split(M).some((z)=>{if(!z)return!1;try{let C=L(N(z,q));return C.isFile()&&(C.mode&73)!==0}catch{return!1}})}async function G(q){if(!q)return"";let x=[];try{for await(let z of q)x.push(Buffer.from(z))}catch{}return Buffer.concat(x).toString("utf8")}async function W(q,x){let[z,...C]=q;if(!z)throw Error("A child process probe requires a program.");if(x.signal?.aborted)return{exitCode:-1,stdout:"",stderr:""};let A=K(z,C,{stdio:["ignore","pipe","pipe"],...x.env?{env:x.env}:{}}),H=G(A.stdout),I=G(A.stderr),D=()=>{try{A.kill()}catch{}};if(x.signal?.aborted)D();else x.signal?.addEventListener("abort",D,{once:!0});let F;try{return{exitCode:await Promise.race([new Promise((E)=>{A.once("error",()=>E(-1)),A.once("close",(J)=>E(J??-1))}),new Promise((E)=>{F=setTimeout(()=>{D(),E(-1)},x.timeoutMs)})]),stdout:await H,stderr:await I}}finally{if(F)clearTimeout(F);x.signal?.removeEventListener("abort",D)}}function X(q){if(!(q>0))return;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,q)}
3
- export{V as Tc,W as Uc,X as Vc};
@@ -1,3 +0,0 @@
1
- // @bun
2
- import{uc as j,vc as q}from"./vm-hands-entry-lite-dcynw6t2.js";function y(v=process.platform){if(j(),v==="linux")q("strict")}
3
- export{y as r};
@@ -1,11 +0,0 @@
1
- // @bun
2
- import{Uc as dq,Vc as cq}from"./vm-hands-entry-lite-hh24bq0d.js";import{Gh as zq,Hh as fq,Lh as Rq,Mh as Uq,Nh as X,Qh as mq,Sh as Fq,Th as vq,Vh as h,Wh as P,Xh as Mq}from"./vm-hands-entry-lite-kxdw4myj.js";import{ni as _q}from"./vm-hands-entry-lite-r6pap1kh.js";import{Ii as hq,Ki as lq,Ni as oq,Oi as sq,Pi as uq,Qi as Nq}from"./vm-hands-entry-lite-4q8tsaqv.js";import{Yi as c}from"./vm-hands-entry-lite-c01eyep6.js";import{randomUUID as O}from"crypto";import{chmodSync as qq,closeSync as m,constants as v,existsSync as B,fstatSync as pq,lstatSync as T,mkdirSync as r,openSync as rq,readFileSync as g,readdirSync as Iq,readlinkSync as E,realpathSync as C,renameSync as k,rmSync as d,statSync as x,symlinkSync as Gq,unlinkSync as D,writeFileSync as l}from"fs";import{basename as p,dirname as I,isAbsolute as jG,join as K,relative as HG,resolve as A,sep as nq}from"path";import{spawnSync as Tq}from"child_process";import{createRequire as zG}from"module";var Wq=1,iq=1,aq=128,FG=65536,MG="https://reasonmachines.com/api/runtime-manifest-v2",NG=30000,IG=600000,kq=1e4,TG=60000,AG=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;var xq=/^[a-z0-9_.-]{1,80}$/,BG=64,DG="so.ara.device-broker",Vq=["com.apple.security.cs.allow-jit","com.apple.security.cs.allow-unsigned-executable-memory"],OG=["service.install_started","service.install_completed","service.install_failed","service.launcher_adopted","service.launcher_conflict","service.started","service.reconnecting","service.reconnected","service.idle_sleep_held","service.idle_sleep_released","service.idle_sleep_failed","service.start_failed","service.stopped","service.exit_failed","service.singleton_rejected","credential.migration_started","credential.migration_completed","credential.migration_failed","credential.store_started","credential.store_completed","credential.store_failed","credential.delete_started","credential.delete_completed","credential.delete_failed","update.check_started","update.not_available","update.download_started","update.downloaded","update.verified","update.activated","update.rollback","update.failed","executor.update.check_started","executor.update.not_available","executor.update.download_started","executor.update.downloaded","executor.update.verified","executor.update.activated","executor.update.rollback","executor.update.failed","identity.refresh_completed","identity.refresh_failed","update.device_moved","update.components_installed","update.deferred","update.deferral_expired","worker.previous_exit","worker.capabilities_withheld","identity.computer_use_unavailable"];function e(q){if(q?.aborted)throw new X("update_cancelled","Managed runtime update request was cancelled.")}function Aq(q){return Boolean(q)&&typeof q==="object"&&!Array.isArray(q)}function Bq(q,G,J=[]){let Q=new Set([...G,...J]);return G.every((R)=>(R in q))&&Object.keys(q).every((R)=>Q.has(R))}function N(q){return typeof q==="string"&&AG.test(q)}function eq(q){return typeof q==="string"&&!Number.isNaN(Date.parse(q))&&new Date(q).toISOString()===q}function EG(q){return Uq.includes(q)}function y(q){r(q,{recursive:!0,mode:448}),qq(q,448)}function tq(q,G){y(I(q));let J=`${q}.${process.pid}.${O()}.tmp`;try{l(J,G,{mode:384,flag:"wx"}),qq(J,384),k(J,q)}finally{if(B(J))D(J)}}function Dq(q={}){if((q.platform??process.platform)!=="darwin")throw new X("unsupported_platform","The managed Reason runtime is currently available only on macOS.");let J=q.environment??process.env,Q=_q(J,"REASON_CLI_CHANNEL")==="staging",R=Q?_q(J,"REASON_MANAGED_RUNTIME_ROOT")?.trim():void 0,W=q.root!==void 0||Boolean(R&&jG(R))?null:K(q.home??c(),"Library","Application Support"),Z=q.root??(W?K(W,Q?"Reason Staging":"Reason","CLI"):R);return{executableName:"reason",root:Z,...W?{legacyRoot:K(W,"Ara",...Q?["staging","runtime"]:["runtime"])}:{},versions:K(Z,"versions"),current:K(Z,"current"),previous:K(Z,"previous"),brokerLock:K(Z,"broker.lock"),transitionLock:K(Z,"transition.lock"),lifecycleEvents:K(Z,"lifecycle-events")}}function CJ(q){let G=q.legacyRoot;if(!G)return null;return{root:G,versions:K(G,"versions"),current:K(G,"current"),previous:K(G,"previous"),brokerLock:K(G,"broker.lock"),transitionLock:K(G,"transition.lock"),lifecycleEvents:K(G,"lifecycle-events")}}function S(q,G){if(!N(G))throw new X("invalid_version","Invalid managed Reason runtime version.");let J=K(q.versions,G,"ara");if(!q.executableName)return J;let Q=K(q.versions,G,q.executableName),R=(Z)=>{try{return T(Z),!0}catch(_){if(_.code==="ENOENT")return!1;throw _}},U=R(J),W=R(Q);if(U&&W)throw new X("installed_artifact_mismatch","Ambiguous managed runtime executable layout.");return U?J:Q}function n(q,G){if(!N(G))throw new X("invalid_version","Invalid managed Reason runtime version.");return Oq(S(q,G))}function Oq(q){return K(I(q),p(q)==="reason"?fq:zq)}function qG(q,G){if(!N(q)||!N(G))throw new X("invalid_version","Invalid managed Reason runtime version.");let[J,Q]=q.split("-",2),[R,U]=G.split("-",2),W=J.split(".").map(Number),Z=R.split(".").map(Number);for(let H=0;H<3;H+=1){let j=W[H]-Z[H];if(j!==0)return j<0?-1:1}if(Q===void 0||U===void 0){if(Q===U)return 0;return Q===void 0?1:-1}let _=Q.split("."),$=U.split("."),Y=Math.max(_.length,$.length);for(let H=0;H<Y;H+=1){let j=_[H],z=$[H];if(j===void 0||z===void 0){if(j===z)return 0;return j===void 0?-1:1}if(j===z)continue;let F=/^\d+$/.test(j),w=/^\d+$/.test(z);if(F&&w)return Number(j)<Number(z)?-1:1;if(F!==w)return F?-1:1;return j<z?-1:1}return 0}function CG(q=process.arch){let G=`darwin-${q}`;if(!EG(G))throw new X("unsupported_architecture","The managed Reason runtime supports only Apple Silicon and Intel Macs.");return G}function Pq(q){return[...q.matchAll(/<key>\s*([^<]+?)\s*<\/key>/g)].map((G)=>G[1].trim())}function gq(q){let G=q.match(/^CodeDirectory .*$/gm)??[];return G.length>0&&G.every((J)=>{return(/ flags=0x[0-9a-f]+\(([^)]*)\)(?: |$)/.exec(J)?.[1]?.split(/[ ,]+/).filter(Boolean)??[]).includes("runtime")})}function SG(q){let G=`TeamIdentifier=${hq}`,J=`Identifier=${DG}`,Q=Pq(q.brokerEntitlements),R=Pq(q.credentialLibraryEntitlements);if(!q.brokerDetail.split(`
3
- `).includes(G)||!q.brokerDetail.split(`
4
- `).includes(J)||!gq(q.brokerDetail)||Q.length!==Vq.length||Vq.some((U)=>!new RegExp(`<key>\\s*${U.replaceAll(".","\\.")}\\s*</key>\\s*<true\\s*/>`).test(q.brokerEntitlements)))throw new X("invalid_code_signature","Managed runtime broker has an invalid Reason signature, identifier, or entitlement set.");if(!q.credentialLibraryDetail.split(`
5
- `).includes(G)||!gq(q.credentialLibraryDetail)||R.length!==0)throw new X("invalid_code_signature","Managed runtime credential library has an invalid signature or entitlement.")}function b(q,G){let J=Tq("/usr/bin/codesign",q,{stdio:["ignore","pipe","pipe"]});if(J.status!==0)throw new X("invalid_code_signature",G);return[new TextDecoder().decode(J.stdout??new Uint8Array),new TextDecoder().decode(J.stderr??new Uint8Array)].join("")}var Eq=(q,G)=>{b(["--verify","--strict","--verbose=2",q],"Managed runtime broker code signature is invalid."),b(["--verify","--strict","--verbose=2",G],"Managed runtime credential library code signature is invalid."),SG({brokerDetail:b(["-d","--verbose=4",q],"Managed runtime broker signer could not be inspected."),brokerEntitlements:b(["-d","--entitlements",":-",q],"Managed runtime broker entitlements could not be inspected."),credentialLibraryDetail:b(["-d","--verbose=4",G],"Managed runtime credential library signer could not be inspected."),credentialLibraryEntitlements:b(["-d","--entitlements",":-",G],"Managed runtime credential library entitlements could not be inspected.")})};async function LG(q,G,J){let Q=q.headers.get("content-length");if(Q!==null){let Y=Number(Q);if(!Number.isSafeInteger(Y)||Y<0||Y>G)throw new X("response_too_large","Managed runtime response exceeded its size limit.")}if(!q.body){let Y=new Uint8Array(await q.arrayBuffer());if(Y.byteLength>G)throw new X("response_too_large","Managed runtime response exceeded its size limit.");return Y}let R=q.body.getReader(),U=[],W=0,Z=()=>{if(!J)return R.read();return new Promise((Y,H)=>{let j=()=>{J.removeEventListener("abort",j),R.cancel(J.reason).catch(()=>{}),H(J.reason??new DOMException("Aborted","AbortError"))};if(J.aborted){j();return}J.addEventListener("abort",j,{once:!0}),R.read().then((z)=>{J.removeEventListener("abort",j),Y(z)},(z)=>{J.removeEventListener("abort",j),H(z)})})};try{while(!0){let Y=await Z();if(Y.done)break;if(W+=Y.value.byteLength,W>G)throw await R.cancel(),new X("response_too_large","Managed runtime response exceeded its size limit.");U.push(Y.value)}}finally{try{R.releaseLock()}catch{}}let _=new Uint8Array(W),$=0;for(let Y of U)_.set(Y,$),$+=Y.byteLength;return _}async function u(q){let G;try{G=new URL(q.url)}catch{throw new X("invalid_update_url","Managed runtime update URL is invalid.")}if(G.protocol!=="https:"||G.username||G.password||G.hash)throw new X("invalid_update_url","Managed runtime update URL must use HTTPS.");let J=new AbortController,Q,R=()=>{Q??="caller",J.abort(q.signal?.reason)};if(q.signal?.aborted)R();else q.signal?.addEventListener("abort",R,{once:!0});let U=setTimeout(()=>{Q??="timeout",J.abort(Error("managed runtime fetch timed out"))},q.timeoutMs),W=(Z,_)=>{if(Z instanceof X)return Z;if(Q==="caller")return new X("update_cancelled","Managed runtime update request was cancelled.");if(Q==="timeout")return new X("update_fetch_timeout","Managed runtime update request timed out.");return new X("update_fetch_failed",_)};try{let Z;try{if(Z=await q.fetchImpl(G,{headers:{accept:q.accept},signal:J.signal}),J.signal.aborted)throw W(J.signal.reason,"Managed runtime update request was cancelled.")}catch(_){throw W(_,"Managed runtime update request failed.")}if(!Z.ok)throw new X("update_http_error","Managed runtime update request was rejected.");if(Z.url&&new URL(Z.url).protocol!=="https:")throw new X("insecure_redirect","Managed runtime update redirected to an insecure URL.");try{let _=await LG(Z,q.maximumBytes,J.signal);if(J.signal.aborted)throw W(J.signal.reason,"Managed runtime update response was cancelled.");return _}catch(_){throw W(_,"Managed runtime update response failed.")}}finally{clearTimeout(U),q.signal?.removeEventListener("abort",R)}}async function GG(q,G,J=kq,Q){let R=typeof J==="number"?J:kq,U=typeof J==="number"?Q:J;if(U?.aborted)return!1;let W=await dq([q,"--version"],{timeoutMs:R,...U?{signal:U}:{}});return W.exitCode===0&&W.stdout.trim().replace(/^v/,"")===G}async function wG(q){let G=!1,J=null,Q=null,R=(U)=>{try{M(q.paths,U,{now:q.now})}catch{}};try{let U=q.home??c();if(!uq(q.manifest.version,U))return{status:"current"};Q=sq(U);let W=await u({url:new URL(mq,q.manifest.artifacts[q.target].broker.url).toString(),maximumBytes:Rq,fetchImpl:async(j,z)=>{let F=await q.fetchImpl(j,z);return G=F.status===404,F},timeoutMs:q.timeoutMs,accept:"application/json",signal:q.signal}),{manifest:Z}=vq(new TextDecoder().decode(W),q.trustedKeys);if(Z.version!==q.manifest.version||Z.published_at!==q.manifest.published_at)throw new X("identity_manifest_mismatch","Background identity manifest names another release.");let _=Z.artifacts[q.target],$=await u({url:_.url,maximumBytes:_.size_bytes,fetchImpl:q.fetchImpl,timeoutMs:q.timeoutMs,accept:"application/octet-stream",signal:q.signal});P($,_),y(q.workDirectory),J=K(q.workDirectory,`.identity-${process.pid}-${O()}`),r(J,{mode:448});let Y=K(J,"identity.tgz");if(l(Y,$,{mode:384,flag:"wx"}),Tq("/usr/bin/tar",["-xzf",Y,"-C",J],{stdio:"ignore",timeout:60000}).status!==0)throw new X("identity_extract_failed","Background identity archive could not be extracted.");return Nq({sourceApp:K(J,"Reason.app"),home:U,releaseSigned:!0,...q.command?{command:q.command}:{}}),R({event:"identity.refresh_completed",runtime_version:q.manifest.version,...Q?{from_version:Q}:{},to_version:q.manifest.version}),{status:"installed"}}catch(U){if(G)return{status:"unpublished"};let W=U instanceof X||U instanceof lq?U.code:"identity_install_failed";return process.stderr.write(`Reason background identity: identity_update_failed (${W})
6
- `),R({event:"identity.refresh_failed",runtime_version:q.manifest.version,...Q?{from_version:Q}:{},to_version:q.manifest.version,reason_code:W}),{status:"failed",code:W}}finally{if(J)d(J,{recursive:!0,force:!0})}}async function SJ(q){if(!N(q.currentVersion))throw new X("invalid_version","Invalid current managed runtime version.");let G=q.paths??Dq(),J=q.target??CG(),Q=q.fetchImpl??fetch,R=q.timeoutMs??NG,U=q.timeoutMs??IG,W=q.healthCheck??((H,j,z)=>GG(H,j,TG,z)),Z=q.verifyCodeSignatures??Eq,_=q.now?.()??new Date,$,Y=!1;M(G,{event:"update.check_started",runtime_version:q.currentVersion,from_version:q.currentVersion},{now:()=>_});try{await vG({paths:G,verifyCodeSignatures:Z,healthCheck:W});let H=await u({url:q.manifestUrl??MG,maximumBytes:Rq,fetchImpl:Q,timeoutMs:R,accept:"application/json",signal:q.signal}),j=Fq(new TextDecoder().decode(H),q.trustedKeys);$=j.manifest.version;let z=()=>wG({paths:G,...q.now?{now:q.now}:{},manifest:j.manifest,target:J,trustedKeys:q.trustedKeys,fetchImpl:Q,timeoutMs:U,workDirectory:G.versions,...q.home?{home:q.home}:{},...q.identityCommand?{command:q.identityCommand}:{},...q.signal?{signal:q.signal}:{}});if(qG($,q.currentVersion)<=0)return M(G,{event:"update.not_available",runtime_version:q.currentVersion,from_version:q.currentVersion,to_version:$,duration_ms:Math.max(0,(q.now?.()??new Date).getTime()-_.getTime())},{now:q.now}),$q(G),{status:"not_available",currentVersion:q.currentVersion,offeredVersion:$,...$===q.currentVersion?{identity:await z()}:{}};let F=j.manifest.artifacts[J];M(G,{event:"update.download_started",runtime_version:q.currentVersion,from_version:q.currentVersion,to_version:$},{now:q.now});let w=await u({url:F.broker.url,maximumBytes:F.broker.size_bytes,fetchImpl:Q,timeoutMs:U,accept:"application/octet-stream",signal:q.signal});P(w,F.broker),e(q.signal);let a=await u({url:F.credential_library.url,maximumBytes:F.credential_library.size_bytes,fetchImpl:Q,timeoutMs:U,accept:"application/octet-stream",signal:q.signal});P(a,F.credential_library),M(G,{event:"update.downloaded",runtime_version:q.currentVersion,from_version:q.currentVersion,to_version:$},{now:q.now}),M(G,{event:"update.verified",runtime_version:q.currentVersion,from_version:q.currentVersion,to_version:$},{now:q.now}),e(q.signal);let Lq=JG({paths:G,version:$,artifact:F.broker,bytes:w,credentialLibraryArtifact:F.credential_library,credentialLibraryBytes:a,verifyCodeSignatures:Z}),wq;try{wq=await W(Lq.executablePath,$,q.signal)}catch(o){throw e(q.signal),o}if(e(q.signal),!wq)throw new X("pre_activation_health_failed","Managed runtime preflight failed.");let V=yG(G,$);if(!V.changed&&V.toVersion!==$)return M(G,{event:"update.not_available",runtime_version:V.toVersion,from_version:V.toVersion,to_version:$,duration_ms:Math.max(0,(q.now?.()??new Date).getTime()-_.getTime())},{now:q.now}),{status:"not_available",currentVersion:V.toVersion,offeredVersion:$};if(Y=V.changed,!await W(G.current,$)){if(V.fromVersion){let o=XG(G,$);M(G,{event:"update.rollback",runtime_version:o.toVersion,from_version:o.fromVersion,to_version:o.toVersion,reason_code:"post_activation_health_failed"},{now:q.now})}else ZG(G,$);throw f(G),Y=!1,new X("post_activation_health_failed","Managed runtime activation failed.")}return f(G),$q(G),M(G,{event:"update.activated",runtime_version:$,from_version:q.currentVersion,to_version:$,duration_ms:Math.max(0,(q.now?.()??new Date).getTime()-_.getTime())},{now:q.now}),{status:"activated",fromVersion:q.currentVersion,toVersion:$,installed:Lq.installed,identity:await z()}}catch(H){throw M(G,{event:"update.failed",runtime_version:Y?$??q.currentVersion:q.currentVersion,from_version:q.currentVersion,...$?{to_version:$}:{},reason_code:H instanceof X?H.code:"update_failed",duration_ms:Math.max(0,(q.now?.()??new Date).getTime()-_.getTime())},{now:q.now}),H}}function yq(q,G,J){try{let Q=T(I(q));if(!Q.isDirectory()||Q.isSymbolicLink())return!1;let R=T(q);if(!R.isFile()||R.isSymbolicLink()||R.size!==G.size_bytes)return!1;let U=Oq(q),W=T(U);return W.isFile()&&!W.isSymbolicLink()&&W.size===J.size_bytes&&h(g(q))===G.sha256&&h(g(U))===J.sha256}catch{return!1}}function JG(q){let G=S(q.paths,q.version);P(q.bytes,q.artifact),P(q.credentialLibraryBytes,q.credentialLibraryArtifact);let J=q.verifyCodeSignatures??Eq;if(y(q.paths.root),y(q.paths.versions),B(I(G))){if(!yq(G,q.artifact,q.credentialLibraryArtifact))throw new X("installed_artifact_mismatch","The installed runtime version does not match the verified artifact.");return J(G,n(q.paths,q.version)),{installed:!1,executablePath:G}}let Q=K(q.paths.versions,`.install-${q.version}-${process.pid}-${O()}`),R=K(Q,p(G)),U=Oq(R);r(Q,{mode:448});try{l(R,q.bytes,{mode:448,flag:"wx"}),qq(R,448),l(U,q.credentialLibraryBytes,{mode:448,flag:"wx"}),qq(U,448),J(R,U);try{k(Q,I(G))}catch(W){if(!yq(G,q.artifact,q.credentialLibraryArtifact))throw W;return{installed:!1,executablePath:G}}return{installed:!0,executablePath:G}}finally{d(Q,{recursive:!0,force:!0})}}function kG(q,G){if(!N(G))throw new X("invalid_version","Invalid managed Reason runtime version.");return`versions/${G}/${p(S(q,G))}`}function Jq(q,G){y(I(q));let J=`${q}.${process.pid}.${O()}.tmp`;try{Gq(G,J),k(J,q)}finally{if(B(J))D(J)}}var xG=/^\.ara-worker-(\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?)-(darwin-(?:arm64|x64))\.([0-9A-Za-z]{6})$/;function VG(q,G){let J=I(q),Q=A(J,G),R=I(Q),U=xG.exec(p(R));if(p(Q)!=="ara"||I(R)!==J||!U||!N(U[1])||!Uq.includes(U[2]))return!1;try{return T(R).isDirectory()&&I(C(R))===C(J)&&T(Q).isFile()&&T(Mq(R)).isFile()}catch(W){if(W.code==="ENOENT")return!1;throw W}}function QG(q,G,J){try{if(E(q)!==G)return!1;D(q)}catch(Q){if(Q.code==="ENOENT")return!1;throw Q}try{return Gq(J,q),!0}catch(Q){if(Q.code==="EEXIST")return!1;try{Gq(G,q)}catch(R){if(R.code!=="EEXIST")throw R}throw Q}}function RG(q,G){if(!q.legacyRoot)return!1;let J;try{if(!T(G).isSymbolicLink())return!1;J=E(G)}catch(R){if(R.code==="ENOENT")return!1;throw R}if(A(I(G),J)!==K(q.legacyRoot,"current"))return!1;if(!QG(G,J,q.current))return!1;let Q=L(q);if(Q)M(q,{event:"service.launcher_adopted",runtime_version:Q,to_version:Q,reason_code:"legacy_runtime_root"});return!0}function PG(q){let G=q.launcherPath??K(q.home??c(),".local","bin","ara");try{if(T(G).isSymbolicLink()){let Q=E(G);if(Q===q.paths.current)return"managed";if(VG(G,Q)&&QG(G,Q,q.paths.current)){let R=Xq(q.paths.current,q.paths.executableName)??"unknown";return M(q.paths,{event:"service.launcher_adopted",runtime_version:R,to_version:R,reason_code:"legacy_curl_entrypoint"}),"adopted"}if(RG(q.paths,G))return"adopted"}return"conflict"}catch(J){if(J.code!=="ENOENT")throw J}r(I(G),{recursive:!0,mode:448});for(let J=0;J<4;J+=1)try{return Gq(q.paths.current,G),"created"}catch(Q){if(Q.code!=="EEXIST")throw Q;try{return T(G).isSymbolicLink()&&E(G)===q.paths.current?"managed":"conflict"}catch(R){if(R.code!=="ENOENT")throw R}}return"conflict"}function Xq(q,G){let J;try{if(!T(q).isSymbolicLink())return null;J=E(q)}catch{return null}let Q=J.match(/^versions\/(\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?)\/(ara|Reason|reason)$/);return Q&&(Q[2]==="ara"||Q[2]===G)?Q[1]:null}function L(q){return Xq(q.current,q.executableName)}function LJ(q,G=process.execPath){try{return C(q.current)===C(G)}catch{return!1}}function Qq(q,G,J){let R=HG(G,q).split(nq);return R.length===2&&N(R[0])&&(R[1]==="ara"||J!==void 0&&R[1]===J)?R[0]:null}function UG(q,G){try{return T(G).isSymbolicLink()&&A(I(G),E(G))===A(q.current)}catch{return!1}}function wJ(q,G=process.execPath){try{return Qq(C(G),C(q.versions),q.executableName)!==null}catch{let J=A(G);return J===A(q.current)||UG(q,J)||Qq(J,A(q.versions),q.executableName)!==null}}function kJ(q,G=process.execPath){try{return Qq(C(G),C(q.versions),q.executableName)}catch{let J=A(G);if(J===A(q.current)||UG(q,J))return L(q);return Qq(J,A(q.versions),q.executableName)}}function gG(q,G,J={}){let Q=S(q,G),R=n(q,G);if(!B(Q)||!x(Q).isFile()||!B(R)||!x(R).isFile())throw new X("runtime_not_installed","Managed Reason runtime version is not installed.");let U=Cq(q,G,J.allowDowngrade);if(U)return U;return i(q,G,()=>{return WG(q,G,void 0,J.allowDowngrade)})}function Cq(q,G,J=!1){let Q=L(q);if(!Q)return null;if(Q===G)return{changed:!1,fromVersion:Q,toVersion:Q};if(!J&&qG(G,Q)<=0&&!(/^\d+\.\d+\.\d+-desktop\.v1\.\d+\.\d+\.\d+$/.test(G)&&/^\d+\.\d+\.\d+-desktopdev\./.test(Q)))return{changed:!1,fromVersion:Q,toVersion:Q};return null}function WG(q,G,J,Q=!1){let R=Cq(q,G,Q);if(R)return R;let U=L(q);if(J?.(U),U)Jq(q.previous,E(q.current));else if(B(q.previous))D(q.previous);return Jq(q.current,kG(q,G)),{changed:!0,fromVersion:U,toVersion:G}}function yG(q,G){let J=S(q,G),Q=n(q,G);if(!B(J)||!x(J).isFile()||!B(Q)||!x(Q).isFile())throw new X("runtime_not_installed","Managed Reason runtime version is not installed.");return i(q,G,()=>WG(q,G,(R)=>{mG(q,{schema_version:Wq,from_version:R,to_version:G})}))}function XG(q,G){return i(q,G,()=>{if(L(q)!==G)throw new X("rollback_fence_failed","Managed runtime changed before rollback could be applied.");let J=Xq(q.previous,q.executableName);if(!J||J===G)throw new X("rollback_unavailable","No previous managed runtime is available.");let Q=S(q,J),R=n(q,J);if(!B(Q)||!x(Q).isFile()||!B(R)||!x(R).isFile())throw new X("rollback_unavailable","Previous managed runtime is not installed.");let U=E(q.previous),W=E(q.current);if(A(I(q.previous),U)!==A(Q))throw new X("rollback_fence_failed","Previous runtime pointer does not match its installed layout.");return Jq(q.current,U),Jq(q.previous,W),{fromVersion:G,toVersion:J}})}function bG(){let q=Tq("/bin/ps",["-axww","-o","args="],{encoding:"utf8",stdio:["ignore","pipe","ignore"],timeout:5000,maxBuffer:16777216});return q.status===0&&typeof q.stdout==="string"?q.stdout:null}function $q(q){let G=[];try{let J=L(q);if(!J||Kq(q))return G;let Q=Iq(q.versions).filter((U)=>N(U));if(Q.length<=2)return G;let R=bG();if(R===null)return G;i(q,J,()=>{let U=new Set([L(q),Xq(q.previous,q.executableName)]);if(Kq(q))return;for(let W of Q){if(U.has(W))continue;let Z=K(q.versions,W);if(R.includes(`${Z}${nq}`))continue;try{d(Z,{recursive:!0,force:!0}),G.push(W)}catch{}}})}catch{}return G}function ZG(q,G){i(q,G,()=>{if(L(q)!==G)throw new X("rollback_fence_failed","Managed runtime changed before rollback could be applied.");D(q.current)})}function Sq(q){return q.activationState??K(q.root,"activation.json")}function fG(q){return Aq(q)&&Bq(q,["schema_version","from_version","to_version"])&&q.schema_version===Wq&&(q.from_version===null||N(q.from_version))&&N(q.to_version)}function Kq(q){try{let G=Sq(q),J=T(G);if(!J.isFile()||J.isSymbolicLink()||J.nlink!==1||(J.mode&63)!==0||J.size>4096)throw new X("invalid_activation_state","Managed runtime activation state is invalid.");let Q=JSON.parse(g(G,"utf8"));if(!fG(Q))throw new X("invalid_activation_state","Managed runtime activation state is invalid.");return Q}catch(G){if(G instanceof X)throw G;if(G.code==="ENOENT")return null;throw new X("invalid_activation_state","Managed runtime activation state is invalid.")}}function mG(q,G){tq(Sq(q),JSON.stringify(G)+`
7
- `)}function f(q){try{D(Sq(q))}catch(G){if(G.code!=="ENOENT")throw G}}async function vG(q){let G=Kq(q.paths);if(!G)return"none";let J=L(q.paths);if(J===G.from_version)return f(q.paths),"cleared";if(J!==G.to_version)throw new X("rollback_fence_failed","Managed runtime changed before activation recovery could be applied.");let Q=q.verifyCodeSignatures??Eq,R=q.healthCheck??GG,U=!1;try{let W=S(q.paths,G.to_version);Q(W,n(q.paths,G.to_version)),U=await R(W,G.to_version)}catch{U=!1}if(U)return f(q.paths),M(q.paths,{event:"update.activated",runtime_version:G.to_version,...G.from_version?{from_version:G.from_version}:{},to_version:G.to_version,reason_code:"restart_recovery"}),"committed";if(G.from_version){let W=XG(q.paths,G.to_version);return f(q.paths),M(q.paths,{event:"update.rollback",runtime_version:W.toVersion,from_version:W.fromVersion,to_version:W.toVersion,reason_code:"restart_recovery"}),"rolled_back"}return ZG(q.paths,G.to_version),f(q.paths),M(q.paths,{event:"update.rollback",runtime_version:G.to_version,from_version:G.to_version,reason_code:"restart_recovery"}),"rolled_back"}function dG(q){return Aq(q)&&Bq(q,["schema_version","pid","nonce","started_at","runtime_version"])&&q.schema_version===Wq&&typeof q.pid==="number"&&Number.isSafeInteger(q.pid)&&q.pid>0&&typeof q.nonce==="string"&&/^[0-9a-f-]{36}$/.test(q.nonce)&&eq(q.started_at)&&N(q.runtime_version)}function _G(q,G){try{let J=T(q);if(!J.isDirectory()||J.uid!==process.getuid?.()||(J.mode&63)!==0)return null;let Q=rq(K(q,G),v.O_RDONLY|v.O_NOFOLLOW|v.O_NONBLOCK);try{let R=pq(Q);if(!R.isFile()||R.nlink!==1||R.uid!==process.getuid?.()||(R.mode&63)!==0||R.size>4096)return null;return g(Q,"utf8")}finally{m(Q)}}catch{return null}}function Yq(q){try{let G=JSON.parse(_G(q,"owner.json")??"null");return dG(G)?G:null}catch{return null}}function $G(q){try{return process.kill(q,0),!0}catch(G){return!(G instanceof Error&&("code"in G)&&G.code==="ESRCH")}}var bq="lease",cG=2,hG=4,s;function lG(){if(s!==void 0)return s;if(s=null,process.platform!=="linux"&&process.platform!=="darwin")return null;let q;try{q=zG(import.meta.url)("bun:ffi")}catch{return null}let G=process.platform==="darwin"?"__error":"__errno_location",J=process.platform==="darwin"?["/usr/lib/libSystem.B.dylib"]:["libc.so.6",`libc.musl-${process.arch==="arm64"?"aarch64":"x86_64"}.so.1`];for(let Q of J)try{let R=q.dlopen(Q,{flock:{args:[q.FFIType.i32,q.FFIType.i32],returns:q.FFIType.i32},[G]:{args:[],returns:q.FFIType.ptr}}),U=R.symbols[G]();if(U===null)continue;return s={flock:(W,Z)=>R.symbols.flock(W,Z),errno:()=>q.read.i32(U),wouldBlock:process.platform==="darwin"?35:11},s}catch{}return null}function oG(q){let G=lG();if(!G)return null;let J=rq(`${q}.lease`,v.O_RDWR|v.O_CREAT|v.O_NOFOLLOW,384);try{let Q=pq(J);if(!Q.isFile()||Q.nlink!==1||Q.uid!==process.getuid?.()||(Q.mode&63)!==0)return m(J),"busy";if(G.flock(J,cG|hG)===0)return J;let R=G.errno();return m(J),R===G.wouldBlock?"busy":null}catch(Q){throw m(J),Q}}function jq(q){y(I(q.path));let G=oG(q.path);if(G==="busy")return{acquired:!1,owner:Yq(q.path),recoveredStaleOwner:!1};let J=G!==null;try{let Q=sG(q,G);if(Q.acquired)J=!1;return Q}finally{if(J)m(G)}}function sG(q,G){let J=q.alive??$G,Q=!1;for(let R=0;R<4;R+=1){let U={schema_version:Wq,pid:q.pid??process.pid,nonce:q.nonce?.()??O(),started_at:(q.now?.()??new Date).toISOString(),runtime_version:q.runtimeVersion},W=`${q.path}.init-${process.pid}-${O()}`,Z=!1;try{if(r(W,{mode:448}),l(K(W,"owner.json"),`${JSON.stringify(U)}
8
- `,{mode:384,flag:"wx"}),G!==null)l(K(W,bq),`flock
9
- `,{mode:384,flag:"wx"});q.beforePublish?.();try{throw T(q.path),Object.assign(Error("Managed runtime lock exists."),{code:"EEXIST"})}catch($){if($.code!=="ENOENT")throw $}k(W,q.path),Z=!0;let _=!1;return{acquired:!0,owner:U,recoveredStaleOwner:Q,release(){if(_)return;if(_=!0,Yq(q.path)?.nonce===U.nonce)d(q.path,{recursive:!0,force:!0});if(G!==null)m(G)}}}catch(_){let $=_.code;if(!["EEXIST","ENOTEMPTY"].includes($??""))throw _;let Y=Yq(q.path),H=(q.now?.()??new Date).getTime(),j=Y&&q.staleAfterMs!==void 0?H-Date.parse(Y.started_at)<q.staleAfterMs:!1,z=Y!==null&&!(G!==null&&_G(q.path,bq)!==null)&&J(Y.pid);if(!Y||z||j)return{acquired:!1,owner:Y,recoveredStaleOwner:!1};let F=`${q.path}.stale-${process.pid}-${O()}`;try{k(q.path,F),d(F,{recursive:!0,force:!0}),Q=!0}catch(w){let a=w.code;if(!["ENOENT","EEXIST"].includes(a??""))throw w}}finally{if(!Z)d(W,{recursive:!0,force:!0})}}throw new X("lock_unavailable","Could not acquire the managed Reason runtime lock.")}var uG=20000;function i(q,G,J){if(!N(G))throw new X("invalid_version","Invalid managed Reason runtime version.");let Q=Date.now()+uG,R=jq({path:q.transitionLock,runtimeVersion:G,staleAfterMs:60000});while(!R.acquired&&Date.now()<Q)cq(100),R=jq({path:q.transitionLock,runtimeVersion:G,staleAfterMs:60000});if(!R.acquired)throw new X("transition_busy","Another managed Reason runtime transition is in progress.");try{return J()}finally{R.release()}}function xJ(q){if(!N(q.runtimeVersion))throw new X("invalid_version","Invalid managed Reason runtime version.");let G=q.paths??Dq();return jq({path:G.brokerLock,runtimeVersion:q.runtimeVersion,...q.pid===void 0?{}:{pid:q.pid},...q.now===void 0?{}:{now:q.now},...q.nonce===void 0?{}:{nonce:q.nonce},...q.alive===void 0?{}:{alive:q.alive},...q.beforePublish===void 0?{}:{beforePublish:q.beforePublish}})}function KG(q){return Aq(q)&&Bq(q,["schema_version","event_id","occurred_at","event","runtime_version"],["from_version","to_version","reason_code","duration_ms","attempt_count","retry_in_ms","capabilities"])&&q.schema_version===iq&&typeof q.event_id==="string"&&/^[0-9a-f-]{36}$/.test(q.event_id)&&eq(q.occurred_at)&&typeof q.event==="string"&&OG.includes(q.event)&&N(q.runtime_version)&&(q.from_version===void 0||N(q.from_version))&&(q.to_version===void 0||N(q.to_version))&&(q.reason_code===void 0||typeof q.reason_code==="string"&&xq.test(q.reason_code))&&(q.duration_ms===void 0||typeof q.duration_ms==="number"&&Number.isSafeInteger(q.duration_ms)&&q.duration_ms>=0&&q.duration_ms<=86400000)&&(q.attempt_count===void 0||typeof q.attempt_count==="number"&&Number.isSafeInteger(q.attempt_count)&&q.attempt_count>=1&&q.attempt_count<=1e5)&&(q.retry_in_ms===void 0||typeof q.retry_in_ms==="number"&&Number.isSafeInteger(q.retry_in_ms)&&q.retry_in_ms>=0&&q.retry_in_ms<=30000)&&(q.capabilities===void 0||Array.isArray(q.capabilities)&&q.capabilities.length<=BG&&q.capabilities.every((G)=>typeof G==="string"&&xq.test(G)))}var pG=/^(\d{22}-[0-9a-f-]{36}\.json)$/,rG=/^(\d{22}-[0-9a-f-]{36}\.json)\.sending-(\d+)-[0-9a-f-]{36}$/,nG=300000,t=0n;function iG(q){let G=BigInt(new Date(q.occurred_at).getTime())*1000000n;return t=G>t?G:t+1n,`${String(t).padStart(22,"0")}-${q.event_id}.json`}function Zq(q){try{return Iq(q.lifecycleEvents).filter((G)=>pG.test(G)).sort()}catch{return[]}}function Hq(q){try{let G=JSON.parse(g(q,"utf8"));return KG(G)?G:null}catch{return null}}function YG(q,G=$G,J=Date.now()){let Q;try{Q=Iq(q.lifecycleEvents)}catch{return}for(let R of Q){let U=R.match(rG);if(!U)continue;let W=K(q.lifecycleEvents,R),Z=K(q.lifecycleEvents,U[1]),_=!G(Number(U[2]));if(!_)try{_=J-x(W).mtimeMs>=nG}catch{continue}if(!_)continue;try{k(W,Z)}catch($){let Y=$.code;if(Y==="EEXIST")D(W);else if(Y!=="ENOENT")throw $}}}function aG(q){let J=Zq(q).flatMap((R)=>{try{return[{name:R,size:x(K(q.lifecycleEvents,R)).size}]}catch{return[]}}),Q=J.reduce((R,U)=>R+U.size,0);while(J.length>aq||Q>FG){let R=J.shift();if(!R)break;try{D(K(q.lifecycleEvents,R.name)),Q-=R.size}catch(U){if(U.code!=="ENOENT")throw U}}}function VJ(q){return YG(q),Zq(q).map((G)=>Hq(K(q.lifecycleEvents,G))).filter((G)=>G!==null).slice(-aq)}function M(q,G,J={}){let Q={schema_version:iq,event_id:J.eventId?.()??O(),occurred_at:(J.now?.()??new Date).toISOString(),...G};if(!KG(Q))throw new X("invalid_lifecycle_event","Managed runtime lifecycle event is invalid.");return y(q.lifecycleEvents),tq(K(q.lifecycleEvents,iG(Q)),`${JSON.stringify(Q)}
10
- `),aG(q),Q}function PJ(q,G){if(G.length===0)return 0;let J=new Set(G),Q=0;for(let R of Zq(q)){let U=R.slice(23,-5);if(!J.has(U))continue;try{D(K(q.lifecycleEvents,R)),Q+=1}catch(W){if(W.code!=="ENOENT")throw W}}return Q}async function gJ(q,G,J){YG(q);let Q=0;for(let R of Zq(q)){let U=K(q.lifecycleEvents,R);if(J){let _=Hq(U);if(!_||!J(_))continue}let W=`${U}.sending-${process.pid}-${O()}`;try{k(U,W)}catch(_){if(_.code==="ENOENT")continue;throw _}let Z=Hq(W);if(!Z){D(W);continue}try{await G(Z),D(W),Q+=1}catch{try{k(W,U)}catch(_){if(_.code!=="ENOENT")throw _}break}}return Q}function yJ(q){let G=q.paths??Dq(),J=q.sourceExecutable??process.execPath,Q=q.sourceCredentialLibrary??Mq(I(C(J))),R=q.now?.()??new Date,U=B(S(G,q.version))&&Cq(G,q.version,q.allowDowngrade)!==null;if(!U)M(G,{event:"service.install_started",runtime_version:q.version,to_version:q.version},{now:()=>R});try{let W=g(J),Z;try{Z=g(Q)}catch{throw new X("credential_boundary_unavailable","Managed runtime credential boundary is unavailable.")}let _={url:"https://bootstrap.invalid/ara",sha256:h(W),size_bytes:W.byteLength},$={url:`https://bootstrap.invalid/${zq}`,sha256:h(Z),size_bytes:Z.byteLength},Y=JG({paths:G,version:q.version,artifact:_,bytes:W,credentialLibraryArtifact:$,credentialLibraryBytes:Z,...q.verifyCodeSignatures?{verifyCodeSignatures:q.verifyCodeSignatures}:{}}),H=oq(J);if(B(H))Nq({sourceApp:H,home:q.home??c()});let j=gG(G,q.version,{allowDowngrade:q.allowDowngrade});if(!U)$q(G);let z=q.home??c(),F=q.installLauncher===!1?"skipped":PG({paths:G,...q.launcherPath?{launcherPath:q.launcherPath}:{home:z}});if(q.installLauncher!==!1&&!q.launcherPath)RG(G,K(z,".local","bin","reason"));if(F==="conflict")M(G,{event:"service.launcher_conflict",runtime_version:q.version,to_version:q.version,reason_code:"existing_entrypoint"},{now:q.now});if(!U)M(G,{event:"service.install_completed",runtime_version:q.version,to_version:q.version,duration_ms:Math.max(0,(q.now?.()??new Date).getTime()-R.getTime())},{now:q.now});return{installed:Y.installed,activated:j.changed,activeVersion:j.toVersion,executablePath:S(G,j.toVersion),launcher:F}}catch(W){throw M(G,{event:"service.install_failed",runtime_version:q.version,to_version:q.version,reason_code:W instanceof X?W.code:"install_failed",duration_ms:Math.max(0,(q.now?.()??new Date).getTime()-R.getTime())},{now:q.now}),W}}
11
- export{Wq as L,iq as M,aq as N,FG as O,MG as P,NG as Q,IG as R,kq as S,TG as T,OG as U,Dq as V,CJ as W,S as X,n as Y,qG as Z,CG as _,SG as $,Eq as aa,u as ba,GG as ca,SJ as da,JG as ea,PG as fa,Xq as ga,L as ha,LJ as ia,wJ as ja,kJ as ka,gG as la,XG as ma,vG as na,jq as oa,xJ as pa,VJ as qa,M as ra,PJ as sa,gJ as ta,yJ as ua};