@reason-machines/cli-linux-x64 0.2.568 → 0.2.570
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/reason +2 -2
- package/bin/vm-hands/agent-network-nswyx8m2.js +2 -0
- package/bin/vm-hands/{api-credentials-ntpwt7rg.js → api-credentials-kp2sjeds.js} +1 -1
- package/bin/vm-hands/api-h2pwjbr1.js +2 -0
- package/bin/vm-hands/{ask-relay-hfa5kzxn.js → ask-relay-eqv9sq9m.js} +2 -2
- package/bin/vm-hands/connect-cli-gc79h47t.js +2 -0
- package/bin/vm-hands/{credentials-nfx99zxr.js → credentials-gwh93z0q.js} +1 -1
- package/bin/vm-hands/{custom-endpoint-device-5047vdn3.js → custom-endpoint-device-fdemgypq.js} +1 -1
- package/bin/vm-hands/desktop-account-15zym6ze.js +2 -0
- package/bin/vm-hands/desktop-components-py12mt6g.js +2 -0
- package/bin/vm-hands/{hands-worker-source-8a4kh44t.js → hands-worker-source-vd87swg4.js} +1 -1
- package/bin/vm-hands/{install-receipt-rckwjqmt.js → install-receipt-7hvy0181.js} +1 -1
- package/bin/vm-hands/local-automation-bt51qn3g.js +2 -0
- package/bin/vm-hands/local-capabilities-q9jvmztz.js +2 -0
- package/bin/vm-hands/local-display-session-j807vr40.js +2 -0
- package/bin/vm-hands/local-display-video-3b5qegyk.js +2 -0
- package/bin/vm-hands/local-managed-process-48t1899b.js +2 -0
- package/bin/vm-hands/{local-pty-session-w0yhjdvz.js → local-pty-session-bk7pp5nb.js} +1 -1
- package/bin/vm-hands/{managed-runtime-e4cj6r2s.js → managed-runtime-v7fz5zzh.js} +1 -1
- package/bin/vm-hands/{network-auto-update-8f2745gk.js → network-auto-update-1pfqzgd6.js} +2 -2
- package/bin/vm-hands/{network-contract-ht0psj5j.js → network-contract-8fjtkgma.js} +1 -1
- package/bin/vm-hands/{network-sign-in-s00679q9.js → network-sign-in-xdx20n1p.js} +1 -1
- package/bin/vm-hands/{permissions-74rj58e1.js → permissions-19yptfxx.js} +1 -1
- package/bin/vm-hands/{reason-hands-protocol-9r62swp0.js → reason-hands-protocol-yga8dh1m.js} +1 -1
- package/bin/vm-hands/{serve-service-19s965ze.js → serve-service-1sp5n0cm.js} +1 -1
- package/bin/vm-hands/{status-099b2ec1.js → status-pbv2pezp.js} +6 -6
- package/bin/vm-hands/{version-avq09c5d.js → version-w7r1n5k3.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-ksfd234v.js → vm-hands-entry-lite-10fwwbwj.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-bbjsnjct.js → vm-hands-entry-lite-13pzgnj9.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-fp3gaa2c.js → vm-hands-entry-lite-43ja1g10.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-8s5n4wps.js → vm-hands-entry-lite-4x9p79j4.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-vvhfaxpd.js → vm-hands-entry-lite-6dkjbe2b.js} +3 -3
- package/bin/vm-hands/{vm-hands-entry-lite-ezkb7f6j.js → vm-hands-entry-lite-7pj0tvht.js} +8 -8
- package/bin/vm-hands/{vm-hands-entry-lite-mktndd2r.js → vm-hands-entry-lite-7x2dnf35.js} +14 -14
- package/bin/vm-hands/{vm-hands-entry-lite-jm9jpj77.js → vm-hands-entry-lite-7z05qb3m.js} +11 -11
- package/bin/vm-hands/{vm-hands-entry-lite-bcz4qpp6.js → vm-hands-entry-lite-92qqzeas.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-0xfme8gg.js → vm-hands-entry-lite-a4fn6ye1.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-a8pm6cqb.js +10 -0
- package/bin/vm-hands/{vm-hands-entry-lite-7jmt3q38.js → vm-hands-entry-lite-asyv9pk8.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-t2rhwchw.js → vm-hands-entry-lite-cg84jcgd.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-7aeqbfc8.js → vm-hands-entry-lite-ck130wm6.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-vha0pf8k.js → vm-hands-entry-lite-ea3cts1t.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-bt6skt4h.js → vm-hands-entry-lite-ef0ergar.js} +3 -3
- package/bin/vm-hands/{vm-hands-entry-lite-9meg54bs.js → vm-hands-entry-lite-epzkdacr.js} +4 -4
- package/bin/vm-hands/{vm-hands-entry-lite-3594pdj0.js → vm-hands-entry-lite-f6np7g11.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-dhn0fs5e.js → vm-hands-entry-lite-g4e21m1g.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-4kb5rq3d.js → vm-hands-entry-lite-hnsdwskm.js} +3 -3
- package/bin/vm-hands/{vm-hands-entry-lite-rpf4t8r4.js → vm-hands-entry-lite-m4zkvq9s.js} +15 -15
- package/bin/vm-hands/{vm-hands-entry-lite-kzygj0q8.js → vm-hands-entry-lite-mayj6bpv.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-mzw2vcah.js → vm-hands-entry-lite-mkha0rqp.js} +96 -96
- package/bin/vm-hands/{vm-hands-entry-lite-1cdtev4n.js → vm-hands-entry-lite-pnx4zgd6.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-bc9zq8gx.js → vm-hands-entry-lite-sk4qxvzq.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-1as6h9ed.js → vm-hands-entry-lite-ttemn34n.js} +4 -4
- package/bin/vm-hands/{vm-hands-entry-lite-y2vqwds4.js → vm-hands-entry-lite-vgwm0t9m.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-h5x725z8.js → vm-hands-entry-lite-w4vnk4tg.js} +6 -6
- package/bin/vm-hands/{vm-hands-entry-lite-8twdd0ff.js → vm-hands-entry-lite-yqzy5wp8.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-2qh3rat2.js → vm-hands-entry-lite-ysmjfpef.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-r131db1f.js → vm-hands-entry-lite-zhxpfb3n.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-n9277v11.js → vm-hands-entry-lite-zm0707rq.js} +1 -1
- package/bin/vm-hands/vm-hands-entry-lite.js +2 -2
- package/bin/vm-hands/{vm-hands-executor-xd8v5v0e.js → vm-hands-executor-e75we703.js} +1 -1
- package/bin/vm-hands/{vm-hands-op-runner-nr4ncs4p.js → vm-hands-op-runner-86zndw34.js} +1 -1
- package/bin/vm-hands/{vm-hands-runtime-qvy5s122.js → vm-hands-runtime-ad8q3cjr.js} +3 -3
- package/bin/vm-hands/{worker-sandbox-2trfs79b.js → worker-sandbox-6aepsk73.js} +1 -1
- package/package.json +1 -1
- package/bin/vm-hands/agent-network-dw7yrrwt.js +0 -2
- package/bin/vm-hands/api-xvjq0bka.js +0 -2
- package/bin/vm-hands/connect-cli-2ja7aj4w.js +0 -2
- package/bin/vm-hands/desktop-account-d1g1m6yb.js +0 -2
- package/bin/vm-hands/desktop-components-577haqrs.js +0 -2
- package/bin/vm-hands/local-automation-fxdb4ynz.js +0 -2
- package/bin/vm-hands/local-capabilities-8fgrfpj4.js +0 -2
- package/bin/vm-hands/local-display-session-8b2hx1k6.js +0 -2
- package/bin/vm-hands/local-display-video-511qjgmq.js +0 -2
- package/bin/vm-hands/local-managed-process-h0fypn67.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-rd7bm9we.js +0 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{us,ds,Mc,On}from"./vm-hands-entry-lite-hh0kba1y.js";import{A}from"./vm-hands-entry-lite-
|
|
2
|
+
import{us,ds,Mc,On}from"./vm-hands-entry-lite-hh0kba1y.js";import{A}from"./vm-hands-entry-lite-epzkdacr.js";import{Ue,wr,br}from"./vm-hands-entry-lite-g0bpdyfz.js";import{qr}from"./vm-hands-entry-lite-t3k90kdn.js";import{Go,Kt,_c,Ko,Jo,Xo,Jt}from"./vm-hands-entry-lite-10fwwbwj.js";import{vi}from"./vm-hands-entry-lite-f6np7g11.js";import{Ee}from"./vm-hands-entry-lite-ttemn34n.js";import{s}from"./vm-hands-entry-lite-tzv8s0e7.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{execFile as se,spawn as ce}from"child_process";import{randomBytes as Ce}from"crypto";import{chmodSync as Ge,existsSync as ne,lstatSync as Oe,mkdirSync as he,readFileSync as S,rmSync as ae,writeFileSync as R}from"fs";import{connect as Je}from"net";import{join as p}from"path";var B=32,N=76;var M="./desktop-wallpaper-fd8f2wb2.jpg";var v="./dock-browser-y53t41cx.png";var Z="./dock-files-cp52htdw.png";var V="./dock-terminal-1es514yq.png";var z="./grok-wallpaper-71zwn2pj.jpg";var W="./grok-dock-browser-pzw59wnd.png";var j="./grok-dock-files-eckq444x.png";var U="./grok-dock-terminal-hcpz3e43.png";var ee=`# Sets the X root window background and _XROOTPMAP_ID, as feh --bg-fill does.
|
|
3
3
|
# The native Blaxel image ships no feh, hsetroot or compositor, but it does ship
|
|
4
4
|
# python3-gi and libX11. tint2 reads _XROOTPMAP_ID to draw its transparent panel.
|
|
5
5
|
# Usage: DISPLAY=:99 python3 set-root-wallpaper.py IMAGE
|
|
@@ -56,7 +56,7 @@ x.XSetWindowBackgroundPixmap(d, root, pix)
|
|
|
56
56
|
x.XClearWindow(d, root)
|
|
57
57
|
x.XSetCloseDownMode(d, 1) # RetainPermanent: the pixmap outlives this process
|
|
58
58
|
x.XCloseDisplay(d)
|
|
59
|
-
`;function
|
|
59
|
+
`;function Pe(e){return`<?xml version="1.0" encoding="UTF-8"?>
|
|
60
60
|
<openbox_config xmlns="http://openbox.org/3.4/rc">
|
|
61
61
|
<theme><keepBorder>no</keepBorder></theme>
|
|
62
62
|
<applications>
|
|
@@ -67,7 +67,7 @@ x.XCloseDisplay(d)
|
|
|
67
67
|
<size><width>${e.width-B*2}</width><height>${e.height-B-N}</height></size>
|
|
68
68
|
</application>
|
|
69
69
|
</applications>
|
|
70
|
-
</openbox_config>`}var
|
|
70
|
+
</openbox_config>`}var Ye=`# Remote sandbox dock \u2014 launcher icons only, centred, no panel fill
|
|
71
71
|
panel_items = L
|
|
72
72
|
panel_size = 100% 46
|
|
73
73
|
panel_margin = 0 10
|
|
@@ -88,7 +88,7 @@ launcher_tooltip = 1
|
|
|
88
88
|
launcher_item_app = /tmp/ara-chromium.desktop
|
|
89
89
|
launcher_item_app = /tmp/ara-files.desktop
|
|
90
90
|
launcher_item_app = /tmp/ara-terminal.desktop
|
|
91
|
-
`,re=32,
|
|
91
|
+
`,re=32,Ne=`# Remote sandbox dock (grok look) \u2014 small launcher icons only, centred, no panel fill
|
|
92
92
|
panel_items = L
|
|
93
93
|
panel_size = 100% ${re+16}
|
|
94
94
|
panel_margin = 0 0
|
|
@@ -109,7 +109,7 @@ launcher_tooltip = 1
|
|
|
109
109
|
launcher_item_app = /tmp/ara-chromium.desktop
|
|
110
110
|
launcher_item_app = /tmp/ara-files.desktop
|
|
111
111
|
launcher_item_app = /tmp/ara-terminal.desktop
|
|
112
|
-
`,
|
|
112
|
+
`,ue=`corner-radius = 12;
|
|
113
113
|
rounded-corners-exclude = [
|
|
114
114
|
"class_g = 'tint2'",
|
|
115
115
|
"window_type = 'dock'",
|
|
@@ -121,13 +121,13 @@ fading = false;
|
|
|
121
121
|
vsync = false;
|
|
122
122
|
inactive-opacity = 1.0;
|
|
123
123
|
active-opacity = 1.0;
|
|
124
|
-
`,
|
|
124
|
+
`,Re="/tmp/ara-dock-browser.png",ge=`[Desktop Entry]
|
|
125
125
|
Name=Chrome
|
|
126
126
|
Exec=chromium --no-sandbox %U
|
|
127
|
-
Icon=${
|
|
127
|
+
Icon=${Re}
|
|
128
128
|
Type=Application
|
|
129
129
|
Categories=Network;WebBrowser;
|
|
130
|
-
`,
|
|
130
|
+
`,Ke=`[Desktop Entry]
|
|
131
131
|
Name=Terminal
|
|
132
132
|
Exec=bash -c "DISPLAY=:99 xterm -fa DejaVuSansMono -fs 11 -bg black -fg white"
|
|
133
133
|
Icon=/tmp/ara-dock-terminal.png
|
|
@@ -139,12 +139,12 @@ Exec=bash -c "DISPLAY=:99 pcmanfm --no-desktop"
|
|
|
139
139
|
Icon=/tmp/ara-dock-files.png
|
|
140
140
|
Type=Application
|
|
141
141
|
Categories=System;FileManager;
|
|
142
|
-
`;var te={"wallpaper.jpg":M,"dock-browser.png":v,"dock-terminal.png":V,"dock-files.png":Z,"grok-wallpaper.jpg":z,"grok-dock-browser.png":W,"grok-dock-terminal.png":U,"grok-dock-files.png":j},
|
|
142
|
+
`;var te={"wallpaper.jpg":M,"dock-browser.png":v,"dock-terminal.png":V,"dock-files.png":Z,"grok-wallpaper.jpg":z,"grok-dock-browser.png":W,"grok-dock-terminal.png":U,"grok-dock-files.png":j},Fe=ee,qe='set_wallpaper() { if command -v feh >/dev/null 2>&1; then feh --bg-fill "$1"; else python3 "$2" "$1"; fi; }';function $e(e){let D=(I)=>I.replaceAll("DISPLAY=:99",`DISPLAY=${e.display}`).replaceAll("/tmp/ara-",`${e.root}/ara-`),n=e.look==="grok",d=new Set(e.absent??[]),t=d.has("files")&&e.filesViewerExec?e.filesViewerExec:null;if(t)d.delete("files");let c=(n?Ne:Ye).split(`
|
|
143
143
|
`).filter((I)=>!(d.has("terminal")&&I.endsWith("/ara-terminal.desktop"))&&!(d.has("files")&&I.endsWith("/ara-files.desktop"))).join(`
|
|
144
|
-
`),a=(I)=>n?I.replace("/tmp/ara-dock-","/tmp/ara-grok-dock-"):I,o=t?De.replace(/^Exec=.*$/m,`Exec=${t}`).replace("Categories=System;FileManager;","Categories=Utility;Viewer;"):De,f=n?"ara-grok-wallpaper.jpg":"ara-wallpaper.jpg",i={"openbox/rc.xml":
|
|
144
|
+
`),a=(I)=>n?I.replace("/tmp/ara-dock-","/tmp/ara-grok-dock-"):I,o=t?De.replace(/^Exec=.*$/m,`Exec=${t}`).replace("Categories=System;FileManager;","Categories=Utility;Viewer;"):De,f=n?"ara-grok-wallpaper.jpg":"ara-wallpaper.jpg",i={"openbox/rc.xml":Pe(e.screen),"tint2/tint2rc":D(c),"picom/picom.conf":ue,...d.has("terminal")?{}:{"ara-terminal.desktop":D(a(Ke))},...d.has("files")?{}:{"ara-files.desktop":D(a(o))},"ara-chromium.desktop":D(a(ge)).replace("chromium --no-sandbox %U",e.browserExec),"ara-set-root-wallpaper.py":Fe},X=[...u.slice(0,3),qe,`[ ! -f "$ROOT/${f}" ] || set_wallpaper "$ROOT/${f}" "$ROOT/ara-set-root-wallpaper.py" || true`,'if alive tint2 && ! cmp -s "$ROOT/tint2/tint2rc" "$ROOT/tint2/applied"; then read -r pid _ <"$ROOT/tint2.pid"; kill -USR1 "$pid" 2>/dev/null || true; fi','cp "$ROOT/tint2/tint2rc" "$ROOT/tint2/applied" 2>/dev/null || true',...u.slice(3)];return{files:i,start:X}}var u=['ticks() { line=$(cat "/proc/$1/stat" 2>/dev/null) || return 1; rest=${line##*) }; case $rest in Z*|X*) return 1;; esac; printf "%s" "$rest" | cut -d " " -f20; }','alive() { [ -f "$ROOT/$1.pid" ] || return 1; read -r pid start <"$ROOT/$1.pid"; current=$(ticks "$pid") || return 1; [ "$current" = "$start" ] && kill -0 "$pid" 2>/dev/null; }','launch() { name=$1; shift; "$@" 9>&- >"$ROOT/$name.log" 2>&1 & pid=$!; start=$(ticks "$pid"); printf "%s %s\\n" "$pid" "$start" >"$ROOT/$name.pid"; }','if [ -f "$ROOT/tint2/tint2rc" ] && ! alive tint2 && command -v tint2 >/dev/null 2>&1; then launch tint2 tint2 -c "$ROOT/tint2/tint2rc"; fi','if [ -f "$ROOT/picom/picom.conf" ] && ! alive picom && command -v picom >/dev/null 2>&1; then launch picom picom --config "$ROOT/picom/picom.conf"; fi'];var Qe=43200000,y=":99",Se=60000,Y=15000,g={width:1280,height:800},ke=/^[A-Za-z0-9._:-]{1,160}$/;function _e(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}var we=["video","viewer","viewer_same_network","viewer_network","look"];function me(e,D=Date.now()){let n=["relay_url","session_id","expires_at"];if(!_e(e)||n.some((f)=>!(f in e))||Object.keys(e).some((f)=>!n.includes(f)&&!we.includes(f)))throw new r("invalid_display_request","Reason desktop request is malformed.");let d="video"in e?Mc(e.video):void 0,t="viewer"in e?us(e.viewer):null,c="look"in e?ds(e.look):null;if(d===null)throw new r("invalid_display_request","Reason desktop video request is invalid.");let a=null;try{a=typeof e.relay_url==="string"?new URL(e.relay_url):null}catch{}if(!a||a.protocol!=="wss:"&&a.protocol!=="ws:"||a.username||a.password)throw new r("invalid_display_request","Reason desktop relay URL is invalid.");if(typeof e.session_id!=="string"||!ke.test(e.session_id))throw new r("invalid_display_request","Reason desktop session identity is invalid.");let o=typeof e.expires_at==="string"?Date.parse(e.expires_at):Number.NaN;if(!Number.isFinite(o)||o<=D)throw new r("invalid_display_request","Reason desktop session has already expired.");return{relay_url:e.relay_url,session_id:e.session_id,expires_at:new Date(Math.min(o,D+Qe)).toISOString(),...d?{video:d}:{},...t?{viewer:t}:{},...d&&e.viewer_same_network===!0?{viewer_same_network:!0}:{},...c?{look:c}:{}}}function dn(e=process.platform){return(e==="linux"||e==="darwin"||e==="win32")&&A()?.features.display===!0}async function Bo(){if(process.platform==="win32")return dn()&&await Jt();if(process.platform!=="darwin")return dn();return await Jt()}function Te(e){he(e,{recursive:!0,mode:448});let D=Oe(e);if(!D.isDirectory()||D.isSymbolicLink()||process.getuid&&D.uid!==process.getuid())throw new r("display_unavailable","Reason desktop state directory is not private.");Ge(e,448)}function Me(e,D){let n=(t)=>{let c=Buffer.alloc(2);return c.writeUInt16BE(t.length),Buffer.concat([c,t])},d=Buffer.from([255,255]);return Buffer.concat([d,n(Buffer.alloc(0)),n(Buffer.from(e)),n(Buffer.from("MIT-MAGIC-COOKIE-1")),n(D)])}function x(e,D,n=2000){return new Promise((d)=>{let t=Je(e),c="",a=(o)=>{t.destroy(),d(o)};t.setTimeout(n,()=>a(!1)),t.once("error",()=>a(!1)),t.once("close",()=>a(!1)),t.once("connect",()=>{if(!D)a(!0)}),t.on("data",(o)=>{if(c+=o.toString("latin1"),c.length>=4)a(c.startsWith("RFB "))})})}async function Q(e,D){let n=Date.now()+D;while(Date.now()<n){if(await e())return!0;await new Promise((d)=>setTimeout(d,100))}return!1}function K(e,D,n,d=!1){return new Promise((t)=>{let c=ce(e,D,{detached:!0,stdio:"ignore",env:n});if(d)Ue(c.pid);c.once("error",()=>t(-1)),c.once("exit",(a)=>t(a)),c.unref(),setTimeout(()=>t(null),Y).unref()})}var J=null;function jt(e=s()){return J??=ve(e).finally(()=>{J=null}),J}async function ve(e){let D=A({home:e});if(!D?.xvfb||!D.x11vnc||!D.openbox)throw new r("display_unavailable","Run `reason desktop install` on this machine to enable its desktop.");qr({root:D.root,automation:D.automation,extensionDir:D.extensionDir});let n=p(D.root,"display");Te(n);let d=await ze(e,n,D.x11vnc);if(d)return d;let t={display:y,xauthority:p(n,"Xauthority"),rfbSocket:p(n,"rfb.sock")},c=p(n,"pulse"),a=(async()=>{try{Te(c)}catch{return null}return await _c(c,D.pulseaudio)})();Te(p(n,"home"));let o=k(n,t,D.pulseaudio),f=async()=>({...t,sound:await a});if(await x({path:t.rfbSocket},!0))return pe(p(n,"theme"),u,o),await f();if(!ne(t.xauthority))R(t.xauthority,Me(y.slice(1),Ce(16)),{mode:384,flag:"wx"});let i=T(p(n,"theme"),t.display,g,e),X={path:`/tmp/.X11-unix/X${y.slice(1)}`};if(!await x(X,!1)){let I=`${g.width}x${g.height}`,L;if(D.xvnc)ae(t.rfbSocket,{force:!0}),L=K(D.xvnc,[t.display,"-geometry",I,"-depth","24","-nolisten","tcp","-auth",t.xauthority,"-rfbport","-1","-rfbunixpath",t.rfbSocket,"-SecurityTypes","None","-UseBlacklist=0","-AlwaysShared","-desktop","Reason"],o,!0);else L=K(D.xvfb,[t.display,"-screen","0",`${I}x24`,"-nolisten","tcp","-auth",t.xauthority],o,!0);if(!await Q(()=>x(X,!1),Y)||D.xvnc&&!await Q(()=>x({path:t.rfbSocket},!0),Y)){if(await L!==null&&Ze())wr("display");throw new r("display_unavailable","Reason could not start the virtual display.")}K(D.openbox,["--config-file",i.openboxConfig],o,!0)}if(await _(i,o),!await oe(D.x11vnc,t,n,"x11vnc.log",o))throw new r("display_unavailable","Reason could not start the desktop server.");return await f()}function Ze(){let e=0;try{e=Number(S(`/tmp/.X${y.slice(1)}-lock`,"utf8").trim())}catch{return!1}if(!Number.isSafeInteger(e)||e<=1)return!1;try{return process.kill(e,0),!0}catch(D){return D.code==="EPERM"}}function k(e,D,n){let d={HOME:p(e,"home"),PATH:"/usr/local/bin:/usr/bin:/bin",DISPLAY:D.display,XAUTHORITY:D.xauthority};if(n)d.PULSE_SERVER=Kt(Go(p(e,"pulse")));return d}async function oe(e,D,n,d,t){if(await x({path:D.rfbSocket},!0))return!0;ae(D.rfbSocket,{force:!0});let c=await K(e,["-display",D.display,"-auth",D.xauthority,"-rfbport","0","-rfbportv6","-1","-unixsock",D.rfbSocket,"-nopw","-forever","-shared","-noxdamage","-sb","0","-rfbversion","3.7","-quiet","-bg","-o",p(n,d)],t);if(c!==null&&c!==0)return!1;if(!await Q(()=>x({path:D.rfbSocket},!0),Y))return!1;return br("x11vnc",D.rfbSocket),!0}async function Ve(){let e=["DISPLAY","XAUTHORITY","WAYLAND_DISPLAY","XDG_SESSION_TYPE"],D=(n)=>Object.fromEntries(e.flatMap((d)=>n[d]?[[d,n[d]]]:[]));if(process.env.DISPLAY)return D(process.env);try{let n=await new Promise((d,t)=>se("systemctl",["--user","show-environment"],{encoding:"utf8",timeout:2000},(c,a)=>c?t(c):d(a)));return D(Object.fromEntries(n.split(`
|
|
145
145
|
`).flatMap((d)=>{let t=d.indexOf("=");return t>0?[[d.slice(0,t),d.slice(t+1)]]:[]})))}catch{return{}}}var de=new Set;async function ze(e,D,n){let d=await Ve(),t=/^:(\d+)(?:\.\d+)?$/.exec(d.DISPLAY??"")?.[1];if(!t||`:${t}`===y||d.WAYLAND_DISPLAY||d.XDG_SESSION_TYPE==="wayland")return null;let c={display:`:${t}`,xauthority:d.XAUTHORITY??p(e,".Xauthority"),rfbSocket:p(D,`rfb-${t}.sock`)},a=`${c.display} ${c.xauthority}`;if(de.has(a)||!await x({path:`/tmp/.X11-unix/X${t}`},!1))return null;let o={HOME:e,PATH:"/usr/local/bin:/usr/bin:/bin",DISPLAY:c.display,XAUTHORITY:c.xauthority};if(await oe(n,c,D,`x11vnc-${t}.log`,o))return{...c,sound:null};return de.add(a),process.stderr.write(`Reason worker: your screen ${c.display} could not be served; using the virtual desktop
|
|
146
146
|
`),null}var ie="look";function fe(e){try{return ds(S(p(e,ie),"utf8").trim())??"reason"}catch{return"reason"}}function T(e,D,n,d,t=fe(e)){let c=`chromium --no-first-run --no-default-browser-check${process.geteuid?.()===0?" --no-sandbox":""} %U`,a=[["terminal","xterm"],["files","pcmanfm"]].filter(([,i])=>!ne(`/usr/bin/${i}`)).map(([i])=>i),o=`${c.replace(/ %U$/,"")} --app=file://${p(d,".reason","workspace")}/`,f=$e({root:e,display:D,screen:n,browserExec:c,absent:a,look:t,filesViewerExec:o});for(let i of["","openbox","tint2","picom"])Te(p(e,i));R(p(e,ie),`${t}
|
|
147
147
|
`,{mode:384});for(let[i,X]of Object.entries(f.files))R(p(e,i),X,{mode:384});for(let[i,X]of Object.entries(te))R(p(e,`ara-${i}`),S(X),{mode:384});return{root:e,openboxConfig:p(e,"openbox","rc.xml"),start:f.start}}function _(e,D){return pe(e.root,[...e.start,"openbox --reconfigure >/dev/null 2>&1 || true"],D)}function pe(e,D,n){let d=[`ROOT=${JSON.stringify(e)}`,...D].join(`
|
|
148
148
|
`);return new Promise((t)=>{let c=ce("/bin/sh",["-c",d],{stdio:"ignore",env:{...n,PATH:"/usr/bin:/bin"}}),a=setTimeout(()=>{c.kill(),t()},Y);c.once("error",()=>{clearTimeout(a),t()}),c.once("exit",()=>{clearTimeout(a),t()})})}var We=2073600,je=320;function er(e,D){let n=Math.min(1,Math.sqrt(We/(e.width*e.height))),d=(t,c)=>Math.min(Math.floor(c/8)*8,Math.max(je,Math.round(t*n/8)*8));return{width:d(e.width,D.width),height:d(e.height,D.height)}}function w(e,D,n){return new Promise((d)=>se(e,D,{env:n,encoding:"utf8",timeout:5000},(t,c)=>d(t?null:c)))}function Ie(e){let D=/current (\d+) x (\d+), maximum (\d+) x (\d+)/.exec(e),n=e.split(`
|
|
149
|
-
`),d=n.findIndex((c)=>/^\S+ connected/.test(c));if(!D||d<0)return null;let t=[];for(let c of n.slice(d+1)){let a=/^\s+(\d+x\d+)\s/.exec(c);if(!a)break;t.push(a[1])}return{current:{width:Number(D[1]),height:Number(D[2])},maximum:{width:Number(D[3]),height:Number(D[4])},output:n[d].split(" ")[0],modes:t}}async function rr(e,D,n){if(e.display!==y)return null;let d={PATH:"/usr/bin:/bin",DISPLAY:e.display,XAUTHORITY:e.xauthority},t=(f)=>w("xrandr",f,d),c=Ie(await t(["--query"])??"");if(!c||c.maximum.width<=c.current.width&&c.maximum.height<=c.current.height)return null;let a=er(D,c.maximum);if(a.width===c.current.width&&a.height===c.current.height)return{size:a,changed:!1};let o=`${a.width}x${a.height}`;if(!c.modes.includes(o)){if(await t(["--newmode",o,"60",...[a.width,a.width,a.width,a.width,a.height,a.height,a.height,a.height].map(String)]),await t(["--addmode",c.output,o])===null)return null}return n(),await t(["--output",c.output,"--mode",o])===null?null:{size:a,changed:!0}}async function Dr(e,D){let n=s(),d=A({home:n});if(!d)return;let t=p(d.root,"display"),c=k(t,e,d.pulseaudio);await _(T(p(t,"theme"),e.display,D,n),c);let a=D.width-B*2,o=D.height-B-N;await w("xdotool",["search","--onlyvisible","--class","Chromium","windowsize","%@",String(a),String(o),"windowmove","%@",String(B),String(B)],{...c,PATH:"/usr/bin:/bin"})}var F=Promise.resolve();function tr(e,D,n=()=>{}){let d=F.then(()=>rr(e,D,n));return F=d.then((t)=>t?.changed?Dr(e,t.size):void 0).catch(()=>{}),d.then((t)=>t?.size??null,()=>null)}function $r(e,D){if(e.display!==y)return Promise.resolve();let n=F.then(async()=>{let d=s(),t=A({home:d});if(!t)return;let c=p(t.root,"display"),a=p(c,"theme");if(fe(a)===D)return;let o=k(c,e,t.pulseaudio),f=Ie(await w("xrandr",["--query"],{PATH:"/usr/bin:/bin",DISPLAY:e.display,XAUTHORITY:e.xauthority})??"");await _(T(a,e.display,f?.current??g,d,D),o)});return F=n.catch(()=>{}),n.catch(()=>{})}async function pn(e,D={}){let n=D.now??Date.now,d=me(e.payload,n());if(e.signal.throwIfAborted(),!d.video)throw new r("display_video_required","Reason desktops stream as video now; this request came without it.");let t=D.platform??process.platform;if(t!=="linux"&&t!=="darwin"&&t!=="win32")throw new r("display_video_unsupported","This machine does not serve desktop video.");let{video:c,look:a}=d,o=(D.video?.desktop??(t==="darwin"?async()=>Ko:t==="win32"?async()=>Jo:async()=>{let f=await jt();if(a)await $r(f,a);return f}))();return await dr(e.signal,d,D,n,(f)=>Xo(f,{request:c,desktop:o,...d.viewer?{viewer:d.viewer}:{},viewerSameNetwork:d.viewer_same_network===!0},{resizeDesktop:tr,...D.video}),(f)=>On({type:"error",code:f}))}function dr(e,D,n,d,t,c){let a=d();return new Promise((o,f)=>{let i=null,X=!1,I=!1,L,q,P,C=!1,l=null,E=(b)=>{if(I)return;if(l)b=l.outcome;I=!0,clearTimeout(L),clearTimeout(q),e.removeEventListener("abort",O),P?.close();try{i?.close(1000,"display_session_over")}catch{}if("error"in b){f(b.error);return}o({reason:b.reason,...P?.summary(),duration_ms:Math.max(0,d()-a)})},G=()=>E({error:new r("display_relay_unavailable","Reason could not reach the desktop relay.")}),O=()=>{let b=e.reason;E({error:b instanceof r?b:new r("cancelled","Reason closed the desktop session.")})},m=()=>{if(!l||!i)return;let{outcome:b}=l,H=!("error"in b)?b.reason:b.error instanceof r?b.error.code:"display_unavailable";if(!l.told)try{i.send(c(H))}catch{}E(b)};if(P=t({get done(){return I||l!==null},get open(){return X&&!I&&l===null},get bufferedAmount(){return i?.bufferedAmount??0},send(b){if(I||l||!X||!i)return;try{i.send(b)}catch{E({reason:"relay_closed"})}},end:(b)=>{if(I||l)return;if(!("error"in b)&&C&&X){E(b);return}if(l={outcome:b,told:!("error"in b)&&X},C&&X)m()}}),I){P.close();return}if(e.aborted){O();return}e.addEventListener("abort",O,{once:!0}),L=setTimeout(()=>E({reason:"session_expired"}),Math.max(1,Date.parse(D.expires_at)-d())),q=setTimeout(()=>E({reason:"viewer_absent"}),n.viewerWaitMs??
|
|
149
|
+
`),d=n.findIndex((c)=>/^\S+ connected/.test(c));if(!D||d<0)return null;let t=[];for(let c of n.slice(d+1)){let a=/^\s+(\d+x\d+)\s/.exec(c);if(!a)break;t.push(a[1])}return{current:{width:Number(D[1]),height:Number(D[2])},maximum:{width:Number(D[3]),height:Number(D[4])},output:n[d].split(" ")[0],modes:t}}async function rr(e,D,n){if(e.display!==y)return null;let d={PATH:"/usr/bin:/bin",DISPLAY:e.display,XAUTHORITY:e.xauthority},t=(f)=>w("xrandr",f,d),c=Ie(await t(["--query"])??"");if(!c||c.maximum.width<=c.current.width&&c.maximum.height<=c.current.height)return null;let a=er(D,c.maximum);if(a.width===c.current.width&&a.height===c.current.height)return{size:a,changed:!1};let o=`${a.width}x${a.height}`;if(!c.modes.includes(o)){if(await t(["--newmode",o,"60",...[a.width,a.width,a.width,a.width,a.height,a.height,a.height,a.height].map(String)]),await t(["--addmode",c.output,o])===null)return null}return n(),await t(["--output",c.output,"--mode",o])===null?null:{size:a,changed:!0}}async function Dr(e,D){let n=s(),d=A({home:n});if(!d)return;let t=p(d.root,"display"),c=k(t,e,d.pulseaudio);await _(T(p(t,"theme"),e.display,D,n),c);let a=D.width-B*2,o=D.height-B-N;await w("xdotool",["search","--onlyvisible","--class","Chromium","windowsize","%@",String(a),String(o),"windowmove","%@",String(B),String(B)],{...c,PATH:"/usr/bin:/bin"})}var F=Promise.resolve();function tr(e,D,n=()=>{}){let d=F.then(()=>rr(e,D,n));return F=d.then((t)=>t?.changed?Dr(e,t.size):void 0).catch(()=>{}),d.then((t)=>t?.size??null,()=>null)}function $r(e,D){if(e.display!==y)return Promise.resolve();let n=F.then(async()=>{let d=s(),t=A({home:d});if(!t)return;let c=p(t.root,"display"),a=p(c,"theme");if(fe(a)===D)return;let o=k(c,e,t.pulseaudio),f=Ie(await w("xrandr",["--query"],{PATH:"/usr/bin:/bin",DISPLAY:e.display,XAUTHORITY:e.xauthority})??"");await _(T(a,e.display,f?.current??g,d,D),o)});return F=n.catch(()=>{}),n.catch(()=>{})}async function pn(e,D={}){let n=D.now??Date.now,d=me(e.payload,n());if(e.signal.throwIfAborted(),!d.video)throw new r("display_video_required","Reason desktops stream as video now; this request came without it.");let t=D.platform??process.platform;if(t!=="linux"&&t!=="darwin"&&t!=="win32")throw new r("display_video_unsupported","This machine does not serve desktop video.");let{video:c,look:a}=d,o=(D.video?.desktop??(t==="darwin"?async()=>Ko:t==="win32"?async()=>Jo:async()=>{let f=await jt();if(a)await $r(f,a);return f}))();return await dr(e.signal,d,D,n,(f)=>Xo(f,{request:c,desktop:o,...d.viewer?{viewer:d.viewer}:{},viewerSameNetwork:d.viewer_same_network===!0},{resizeDesktop:tr,...D.video}),(f)=>On({type:"error",code:f}))}function dr(e,D,n,d,t,c){let a=d();return new Promise((o,f)=>{let i=null,X=!1,I=!1,L,q,P,C=!1,l=null,E=(b)=>{if(I)return;if(l)b=l.outcome;I=!0,clearTimeout(L),clearTimeout(q),e.removeEventListener("abort",O),P?.close();try{i?.close(1000,"display_session_over")}catch{}if("error"in b){f(b.error);return}o({reason:b.reason,...P?.summary(),duration_ms:Math.max(0,d()-a)})},G=()=>E({error:new r("display_relay_unavailable","Reason could not reach the desktop relay.")}),O=()=>{let b=e.reason;E({error:b instanceof r?b:new r("cancelled","Reason closed the desktop session.")})},m=()=>{if(!l||!i)return;let{outcome:b}=l,H=!("error"in b)?b.reason:b.error instanceof r?b.error.code:"display_unavailable";if(!l.told)try{i.send(c(H))}catch{}E(b)};if(P=t({get done(){return I||l!==null},get open(){return X&&!I&&l===null},get bufferedAmount(){return i?.bufferedAmount??0},send(b){if(I||l||!X||!i)return;try{i.send(b)}catch{E({reason:"relay_closed"})}},end:(b)=>{if(I||l)return;if(!("error"in b)&&C&&X){E(b);return}if(l={outcome:b,told:!("error"in b)&&X},C&&X)m()}}),I){P.close();return}if(e.aborted){O();return}e.addEventListener("abort",O,{once:!0}),L=setTimeout(()=>E({reason:"session_expired"}),Math.max(1,Date.parse(D.expires_at)-d())),q=setTimeout(()=>E({reason:"viewer_absent"}),n.viewerWaitMs??Se);try{i=(n.connect??vi)(D.relay_url,(n.loadProxy??Ee)()?.url)}catch{G();return}i.binaryType="arraybuffer",i.onopen=()=>{if(I||!i)return;X=!0,P?.opened()},i.onmessage=(b)=>{if(I)return;let H=b.data,h=H instanceof ArrayBuffer?new Uint8Array(H):ArrayBuffer.isView(H)?new Uint8Array(H.buffer,H.byteOffset,H.byteLength):null;if(!h||h.byteLength===0)return;if(clearTimeout(q),C=!0,l){m();return}P?.received(h)},i.onclose=()=>{if(I)return;if(!X){G();return}E({reason:"relay_closed"})},i.onerror=()=>{if(I||X)return;G()}})}
|
|
150
150
|
export{dn,Bo,Te,jt,pn};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Pr,Rr}from"./vm-hands-entry-lite-hh0kba1y.js";import{g}from"./vm-hands-entry-lite-
|
|
2
|
+
import{Pr,Rr}from"./vm-hands-entry-lite-hh0kba1y.js";import{g}from"./vm-hands-entry-lite-zm0707rq.js";import{Bc,st,Yt,Tr,Ln}from"./vm-hands-entry-lite-ysmjfpef.js";import{L}from"./vm-hands-entry-lite-hpe54h0b.js";import{s,Et}from"./vm-hands-entry-lite-tzv8s0e7.js";import{spawnSync as se}from"child_process";import{dirname as S}from"path";import{spawn as U}from"child_process";import{accessSync as H,constants as J}from"fs";import{basename as q,join as B}from"path";var d=null;function R(e){if(d===e)d=null;if(e.exitCode===null&&e.signalCode===null)e.kill("SIGTERM")}var Fi=(e,t)=>{if(d)R(d);let r=B(e,Bc);try{H(r,J.X_OK)}catch{return()=>{}}let n;try{n=U(r,["--app",e,"--name",q(e,".app"),"--permission",t==="screen"?"screen_recording":"accessibility"],{detached:!0,stdio:"ignore"})}catch{return()=>{}}return n.on("error",()=>{if(d===n)d=null}),n.once("exit",()=>{if(d===n)d=null}),n.unref(),d=n,()=>R(n)};import{chmodSync as K,existsSync as I,mkdirSync as V,readFileSync as Y,realpathSync as A,renameSync as X,statSync as _,writeFileSync as z}from"fs";import{dirname as v,isAbsolute as Q,join as Z,resolve as C,sep as w}from"path";function k(e=s()){return Z(Et(e),"reason","protected-path-grants.json")}var p=null;function ee(e){let t=JSON.parse(e);if(!Array.isArray(t?.grants))return[];return t.grants.flatMap((r)=>{let n=r;return n&&typeof n.path==="string"&&Q(n.path)&&(n.kind==="file"||n.kind==="folder")&&typeof n.grantedAt==="number"?[{path:n.path,kind:n.kind,grantedAt:n.grantedAt}]:[]})}function m(e=k()){try{let{mtimeMs:t}=_(e);if(p&&p.file===e&&p.mtimeMs===t)return p.grants;let r=ee(Y(e,"utf8"));return p={file:e,mtimeMs:t,grants:r},r}catch{return[]}}function te(e,t){return e.kind==="file"?t===e.path:t===e.path||t.startsWith(`${e.path}${w}`)}function ne(e,t){let r=C(e);return m(t).some((n)=>te(n,r))}function xc(e,t){return L(e)&&!ne(e,t)}function O(e,t){V(v(t),{recursive:!0,mode:448});let r=`${t}.${process.pid}.tmp`;z(r,`${JSON.stringify({version:1,grants:e},null,2)}
|
|
3
3
|
`,{mode:384}),K(r,384),X(r,t),p=null}function D(e,t=k(),r=Date.now()){if(!I(e))throw Error(`No file or folder at ${e}.`);let n=A(e),i=v(t);if(i===n||i.startsWith(`${n}${w}`)||n.startsWith(`${i}${w}`))throw Error("Reason's own configuration folder cannot be allowed.");let o={path:n,kind:_(n).isDirectory()?"folder":"file",grantedAt:r},a=m(t).filter((l)=>l.path!==n);return O([...a,o],t),o}function j(e,t=k()){let r=I(e)?A(e):C(e),n=m(t),i=n.filter((o)=>o.path!==r);if(i.length===n.length)return!1;return O(i,t),!0}function Cc(e,t,r){let n=t?"file-read* file-write*":"file-read*";return m(r).filter((i)=>i.path===e||i.path.startsWith(`${e}${w}`)).map((i)=>`(allow ${n} (${i.kind==="file"?"literal":"subpath"} ${JSON.stringify(i.path)}))`)}var G=`Reason permissions
|
|
4
4
|
|
|
5
5
|
Usage:
|
|
@@ -20,7 +20,7 @@ this Mac may open. Only you can change this list; Sessions cannot.
|
|
|
20
20
|
allow asks for each missing one, or the one named. macOS cannot ask for Full
|
|
21
21
|
Disk Access: allow disk opens its pane, shows the file to add in Finder and
|
|
22
22
|
waits until the worker has it.
|
|
23
|
-
`,b="x-apple.systempreferences:com.apple.preference.security",re="curl -fsSL https://reasonmachines.com/install.sh | bash",ie=180000,oe=2000,M=["screen","accessibility","disk"],x={screen:{label:"Screen & System Audio Recording",purpose:"desktop video, computer-use screenshots",level:"required",pane:`${b}?Privacy_ScreenCapture`},accessibility:{label:"Accessibility",purpose:"computer-use clicks and typing, desktop input",level:"required",pane:`${b}?Privacy_Accessibility`},disk:{label:"Full Disk Access",purpose:"Sessions in Desktop, Documents, Downloads, iCloud Drive and Mail",level:"recommended",pane:`${b}?Privacy_AllFiles`}};function F(e){return e.executable}function ae(e,t){if(e==="computer_use_identity_missing")return`Reason's background identity is not installed (${e}); reinstall Reason: ${re}`;if(e==="computer_use_identity_outdated")return`Reason's background identity is outdated (${Yt(t)??"unknown"}; this CLI is ${g}) (${e}); \`reason update\` installs this release's`;return`Reason's background identity cannot run computer use for this CLI (${e}); run the installed \`reason\``}function sl(e=s()){let t=Tr(e);if(t.length>0)return{state:"ready",path:S(S(S(t[0]))),prefix:t};let r=Ln(t,e)??"computer_use_identity_unavailable";return{state:r,path:st(e),detail:ae(r,e)}}function E(){return{identity:()=>sl(),grants:(e)=>Pr(e),request:(e,t)=>Rr(e,t),worker:async()=>(await import("./status-
|
|
23
|
+
`,b="x-apple.systempreferences:com.apple.preference.security",re="curl -fsSL https://reasonmachines.com/install.sh | bash",ie=180000,oe=2000,M=["screen","accessibility","disk"],x={screen:{label:"Screen & System Audio Recording",purpose:"desktop video, computer-use screenshots",level:"required",pane:`${b}?Privacy_ScreenCapture`},accessibility:{label:"Accessibility",purpose:"computer-use clicks and typing, desktop input",level:"required",pane:`${b}?Privacy_Accessibility`},disk:{label:"Full Disk Access",purpose:"Sessions in Desktop, Documents, Downloads, iCloud Drive and Mail",level:"recommended",pane:`${b}?Privacy_AllFiles`}};function F(e){return e.executable}function ae(e,t){if(e==="computer_use_identity_missing")return`Reason's background identity is not installed (${e}); reinstall Reason: ${re}`;if(e==="computer_use_identity_outdated")return`Reason's background identity is outdated (${Yt(t)??"unknown"}; this CLI is ${g}) (${e}); \`reason update\` installs this release's`;return`Reason's background identity cannot run computer use for this CLI (${e}); run the installed \`reason\``}function sl(e=s()){let t=Tr(e);if(t.length>0)return{state:"ready",path:S(S(S(t[0]))),prefix:t};let r=Ln(t,e)??"computer_use_identity_unavailable";return{state:r,path:st(e),detail:ae(r,e)}}function E(){return{identity:()=>sl(),grants:(e)=>Pr(e),request:(e,t)=>Rr(e,t),worker:async()=>(await import("./status-pbv2pezp.js")).connectionMacState(),open:(e)=>{se("/usr/bin/open",e,{stdio:"ignore",timeout:1e4})},tile:Fi,restartConnection:async()=>(await import("./connect-cli-gc79h47t.js")).restartConnection(),sleep:(e)=>new Promise((t)=>setTimeout(t,e)),now:()=>Date.now()}}function N(e,t,r){if(e.state!=="ready"||!t)return"unknown";return t[r]?"granted":"missing"}async function Ac(e){let t=e.identity(),r=t.state==="ready"?await e.grants(t.prefix):null,n=await e.worker(),i=n?F(n):null,o=!i||n?.full_disk_access==="unknown"?"unknown":n?.full_disk_access==="granted"?"granted":"missing",a=(l,u,c)=>{let{label:f,purpose:y,level:h}=x[l];return{id:l,label:f,purpose:y,level:h,state:u,holder:c}};return{identity:{state:t.state,path:t.path,detail:t.state==="ready"?null:t.detail},worker_detail:i?null:"Full Disk Access is read from this computer's running worker; `reason connect` starts it.",permissions:[a("screen",N(t,r,"screen"),t.path),a("accessibility",N(t,r,"accessibility"),t.path),a("disk",o,i)]}}function Rl(e){let t=e.identity.state==="ready"?null:e.identity.state,r=e.permissions.filter((o)=>o.state==="granted").length,n=[...t?[t]:[],...e.permissions.filter((o)=>o.state!=="granted"&&!(t&&o.id!=="disk")).map((o)=>`${o.label} ${o.state}`)],i=!t&&e.permissions.some((o)=>o.state==="missing");return`Permissions: ${r} of ${e.permissions.length}${n.length>0?` (${n.join(", ")})`:""}`+(i?" \u2014 reason permissions allow":n.length>0?" \u2014 reason permissions":"")}function ce(e){let t=[];if(e.identity.detail)t.push(e.identity.detail);t.push(`Reason: ${e.identity.path}`);let r=e.permissions.find((n)=>n.id==="disk");t.push(r?.holder?`Worker: ${r.holder}`:`Worker: ${e.worker_detail}`),t.push("");for(let n of e.permissions){let i=`${n.label}${n.level==="recommended"?" (recommended)":""}`;t.push(` ${n.id.padEnd(13)} ${n.state.padEnd(7)} ${i}: ${n.purpose}`)}if(e.permissions.some((n)=>n.state==="missing"))t.push("","Allow the missing ones: reason permissions allow");return`${t.join(`
|
|
24
24
|
`)}
|
|
25
25
|
`}async function T(e,t){let r=t.now()+ie;for(;;){if(await e())return!0;if(t.now()>=r)return!1;await t.sleep(oe)}}async function al(e,t){let r=t.host??E(),{io:n}=t,i=await Ac(r),o=i.permissions.filter((c)=>e.includes(c.id)&&c.state!=="granted");if(o.length===0)return n.stdout.write(`Reason permissions: ${e.map((c)=>x[c].label).join(", ")} already allowed.
|
|
26
26
|
`),0;let a=!1,l=!1,u=r.identity();for(let c of o){let{label:f,pane:y}=x[c.id];if(c.id!=="disk"){if(u.state!=="ready"){if(!a)n.stderr.write(`Reason permissions: ${u.detail}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{R}from"./vm-hands-entry-lite-ys4jhf7n.js";import{basename as o}from"path";var xr=["production","staging"],s="https://api.reasonmachines.com",l="https://staging-api.reasonmachines.com";var r={production:{api:"https://api.reasonmachines.ai",app:"https://reasonmachines.ai"},staging:{api:"https://staging-api.reasonmachines.ai",app:"https://staging.reasonmachines.ai"}},p=new Set(["ara-staging","ara-staging.exe","reason-staging","reason-staging.exe"]);function w(n={}){let t=R(n.env??process.env,"REASON_CLI_CHANNEL")?.trim().toLowerCase();if(t){if(xr.includes(t))return t;throw Error(`Unknown Reason CLI channel: ${t}`)}let e=o(n.executablePath??process.execPath).toLowerCase();return p.has(e)?"staging":"production"}function Ve(n){return n==="staging"?l:s}function kc(n){return`${Ve(n)}/mcp/ara`}var i={production:["https://api.ara.so",r.production.api],staging:["https://api-staging.ara.so",r.staging.api]};function
|
|
3
|
-
export{xr,w,Ve,kc,
|
|
2
|
+
import{R}from"./vm-hands-entry-lite-ys4jhf7n.js";import{basename as o}from"path";var xr=["production","staging"],s="https://api.reasonmachines.com",l="https://staging-api.reasonmachines.com";var r={production:{api:"https://api.reasonmachines.ai",app:"https://reasonmachines.ai"},staging:{api:"https://staging-api.reasonmachines.ai",app:"https://staging.reasonmachines.ai"}},p=new Set(["ara-staging","ara-staging.exe","reason-staging","reason-staging.exe"]);function w(n={}){let t=R(n.env??process.env,"REASON_CLI_CHANNEL")?.trim().toLowerCase();if(t){if(xr.includes(t))return t;throw Error(`Unknown Reason CLI channel: ${t}`)}let e=o(n.executablePath??process.execPath).toLowerCase();return p.has(e)?"staging":"production"}function Ve(n){return n==="staging"?l:s}function kc(n){return`${Ve(n)}/mcp/ara`}var i={production:["https://api.ara.so",r.production.api],staging:["https://api-staging.ara.so",r.staging.api]};function we(n){let t;try{t=new URL(n).origin}catch{return n}let e=xr.find((a)=>i[a].includes(t));return e?Ve(e):t}function W(n,t){return n===t||we(n)===we(t)}function An(n,t){return xr.some((e)=>i[e].includes(n)&&t===Ve(e))}function Pn(n,t){try{let e=new URL(t);return!e.username&&!e.password&&(e.origin===Ve(n)||e.origin===r[n].api)}catch{return!1}}function Cr(n){try{let t=new URL(n).hostname.replace(/^\[|\]$/g,"").toLowerCase();return t==="localhost"||t==="127.0.0.1"||t==="::1"}catch{return!1}}
|
|
3
|
+
export{xr,w,Ve,kc,we,W,An,Pn,Cr};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{oo}from"./vm-hands-entry-lite-zhxpfb3n.js";import{spawnSync as g}from"child_process";import{createHash as ge}from"crypto";import{chmodSync as pe,closeSync as me,existsSync as w,linkSync as fe,lstatSync as he,mkdirSync as Q,mkdtempSync as we,openSync as ye,readdirSync as Ee,readFileSync as ke,readSync as Ne,realpathSync as Se,renameSync as k,rmSync as N,statSync as Y,symlinkSync as W,writeFileSync as C}from"fs";import{connect as be}from"net";import{homedir as f}from"os";import{basename as Z,dirname as v,join as u}from"path";import{inflateRawSync as _e}from"zlib";var ie=new Set(["<","\u02C2","\u1438","\u2039","\u3008","\u276C","\u276E","\u2770","\u16B2","\u2D66","\uD800\uDF2D","\uD81A\uDEEC","\uD834\uDE36","\u27E8","\u27EA","\u29FC","\u3008","\u300A","\uFE64","\uFF1C"]),D=(e)=>e===" "||e==="\t"||e===`
|
|
3
|
+
`||e==="\f"||e==="\r",ae=(e)=>e.length===1&&e>="!"&&e<="~",J=(e)=>e.length===1&&/[A-Za-z]/.test(e);function j(e){let n=Array.from(e),t=(r)=>{let s=r+Math.min(n.length-r,64),o=r;while(o<s&&(D(n[o])||n[o]==="/"))o+=1;let i=o-r,a=[];while(o<s&&!D(n[o])&&n[o]!==">"&&n[o]!=="\uFF1E")a.push(n[o++]);return i+a.length===s-r&&n.length-r>64||!a.every(ae)||ce(a)};return n.map((r,s)=>ie.has(r)&&t(s+1)?"[":r).join("")}function ce(e){let n=1;for(let t of e){let r=t==="0"?"o":t==="3"?"e":t==="4"||t==="@"?"a":t==="5"||t==="$"?"s":J(t)?t.toLowerCase():t,s="reason".indexOf(r),o=s<0?0:1<<s;if(n=1|(J(t)?0:n)|(n&o)<<1,n&64)return!0}return!1}var le=/[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g;function U(e){return j(e.replace(le," ").replace(/[\u2028\u2029]/g," "))}var ue=["CLAUDECODE","CLAUDE_CODE_SESSION_ID","CODEX_THREAD_ID","CODEX_SESSION_ID","GROK_SESSION_ID","GROK_WORKSPACE_ROOT","GEMINI_CLI","CURSOR_AGENT","OPENCODE","COPILOT_CLI","COPILOT_AGENT_SESSION_ID","AI_AGENT"];function de(e=process.env,n=Boolean(process.stderr.isTTY)){let t=ue.some((r)=>e[r]!==void 0)||Object.keys(e).some((r)=>r.startsWith("CODEX_SANDBOX"))||Boolean(e.REASON_NETWORK_AGENT)||Boolean(e.TINCAN_AGENT);return n&&!t}function Fe(e,n=de()){return n?e:U(e)}class ne extends Error{}var m="reason-network",p="0.12.11",Re={"aarch64-apple-darwin":"4626279ee457d15566bcee47ba11ce270d545bd1137c48208e0df3878606197b","x86_64-apple-darwin":"17ea926bce47913882c7b3ba0ae42d03694a7720518ee726e4ae3028bb293f62","aarch64-unknown-linux-musl":"3bc31d0db0263ac27020ac4598415e3e16cfb672d6a9a9ca093775d300ef4fc2","x86_64-unknown-linux-musl":"0ab91ac33af6704f4836bbedc5b55bed4b0a9fdfdc8da1a1d16db8a07d2fc1c4","aarch64-pc-windows-msvc":"91c4c06ebbae929af5494efe9b506b6abc8bdd2989c5d246515bc5133932e5bd","x86_64-pc-windows-msvc":"ff01324b27ebcac0f698df59d2fdc8ef6e3094ead09210c6fa39238cd4cdbee7"},ve="https://reasonmachines.com/cli/engine",S="REASON_AGENT_NETWORK_BIN";function $e(e=process.platform,n=process.arch){let t=n==="arm64"?"aarch64":n==="x64"?"x86_64":null,r=e==="darwin"?"apple-darwin":e==="linux"?"unknown-linux-musl":e==="win32"?"pc-windows-msvc":null;return t&&r?`${t}-${r}`:null}function ee(e){return`${m}-${e}${e.endsWith("-windows-msvc")?".zip":".tar.gz"}`}function xe(e){let n=Re[e];return n?{url:`${ve}/${p}/${ee(e)}`,sha256:n}:null}function A(e){let n=g(e,["--version"],{encoding:"utf8",timeout:5000}),[t,r]=n.status===0?n.stdout.trim().split(/\s+/):[];return t===m?r??null:null}function R(e,n){let t=e.split(".").map(Number),r=n.split(".").map(Number);for(let s=0;s<3;s+=1)if((t[s]??0)!==(r[s]??0))return(t[s]??0)>(r[s]??0);return!0}function b(e=f(),n=process.platform){return u(e,".reason","bin",`${m}${n==="win32"?".exe":""}`)}var x=process.platform==="win32"?`~\\.local\\bin\\${m}.exe`:`~/.local/bin/${m}`;async function Pe(e=process.env,n=()=>{}){if(e[S])return e[S];let t=b(),r=P(),s=r?.path===t&&E(t)===r.fingerprint?r:null,o=s?.kept,i=G(e)?null:Oe(o);if(s?.version===p&&!i)return t;let a=w(t)?A(t):null;if(i){let c=A(i.path),d=a&&R(a,p)?a:p;if(!c||!R(d,c)){if(c)n(`Reason Network: ${x} (${c}) is newer than the version \`reason network\` keeps up to date (${d}), so it was left as it is.`);o=i.fingerprint,i=null}}if(s?.version===p&&!i)return H(t,o);if(!a||!R(a,p))await te(t);let l=g(t,["setup",...G(e)?["--no-service"]:[]],{env:await M(e),encoding:"utf8",timeout:60000});if(l.status!==0){let c=_((l.stderr||l.stdout||"").trim().split(`
|
|
4
|
+
`).pop()??"");if(s)return B(f(),{...s,fingerprint:E(t)??s.fingerprint,...o?{kept:o}:{}}),n(i?`Reason Network: couldn't move your agents off ${x}${c?` (${c})`:""}; they keep using it. Run reason network to try again.`:`Reason Network: couldn't finish setting up on this computer${c?` (${c})`:""}. Run reason network to try again.`),t;throw new ne(`Couldn't connect this computer's agents to the network${c?` (${c})`:""}. Run reason network to try again.`)}if(i)o=Te(i,t,n);return H(t,o),g(t,["stop"],{env:e,stdio:"ignore",timeout:15000}),t}function Oe(e){let n=u(f(),".local","bin",Z(b())),t;try{t=he(n)}catch{return null}let r=`${t.size}:${t.mtimeMs}:${t.ino}`;if(!t.isFile()||r===e)return null;try{let s=Y(b());if(s.ino===t.ino&&s.dev===t.dev)return null}catch{}try{let s=Buffer.alloc(2),o=ye(n,"r");try{Ne(o,s,0,2,0)}finally{me(o)}if(s.toString("latin1")==="#!")return null}catch{return null}return{path:n,fingerprint:r}}function Te(e,n,t){let r=`${e.path}.reason-${process.pid}`;try{if(N(r,{force:!0}),process.platform==="win32"){try{W(n,r,"file")}catch{fe(n,r)}re(r,e.path,"win32")}else W(n,r),k(r,e.path);t(`Reason Network: your agents on this computer now use the version \`reason network\` keeps up to date (${x} points to it). Restart a running agent to pick it up.`);return}catch(s){return N(r,{force:!0}),t(`Reason Network: your agents on this computer now use the version \`reason network\` keeps up to date, but ${x} couldn't be pointed to it (${s instanceof Error?s.message:String(s)}). Remove that copy so it can't take them back.`),e.fingerprint}}async function fl(e={}){let n=e.env??process.env,t=e.home??f(),r=b(t),s=P(t);if(n[S]||s?.path!==r||E(r)!==s.fingerprint)return!1;if(s.version===p)return!1;let o=A(r);if(o&&R(o,p))return!1;return await te(r),B(t,{...s,fingerprint:E(r)??""}),e.beforeRestart?.(),g(r,["stop"],{env:n,stdio:"ignore",timeout:15000}),!0}async function M(e){if(e[F])return e;try{let{defaultWorkerServiceHost:n,workerServiceLauncher:t}=await import("./serve-service-1sp5n0cm.js");return{...e,[F]:t(n(f()),e)}}catch{return e}}var F="REASON_NETWORK_REASON_BIN";function G(e=process.env){return Boolean(e.REASON_NETWORK_NO_SERVICE||e.TINCAN_NO_SERVICE)}var L=(e)=>u(e,".reason","ask-engine.json");function E(e){try{let n=Y(e);return`${n.size}:${n.mtimeMs}:${n.ino}`}catch{return null}}function ml(e=f()){return P(e)?.version??null}function P(e=f()){try{let n=JSON.parse(ke(L(e),"utf8"));if(typeof n.path!=="string"||typeof n.fingerprint!=="string"||typeof n.version!=="string")return null;return{path:n.path,fingerprint:n.fingerprint,version:n.version,...typeof n.kept==="string"?{kept:n.kept}:{}}}catch{return null}}function B(e,n){Q(v(L(e)),{recursive:!0}),C(L(e),JSON.stringify(n))}function H(e,n){let t=E(e);if(t)B(f(),{path:e,fingerprint:t,version:p,...n?{kept:n}:{}});return e}async function te(e){let n=$e(),t=n?xe(n):null;if(!n||!t)throw new ne(`Reason Network runs on macOS, Linux and Windows (arm64 or x64); this is ${process.platform} ${process.arch}.`);let{url:r,sha256:s}=t,o;try{let a=await fetch(r,{signal:AbortSignal.timeout(120000)});if(!a.ok)throw Error(`HTTP ${a.status}`);o=Buffer.from(await a.arrayBuffer())}catch(a){let l=a instanceof Error&&a.name==="TimeoutError"?"no download within 2 minutes":a instanceof Error?a.message.replace(/\.$/,""):String(a);throw new ne(`Couldn't download Reason Network from ${new URL(r).host} (${l}). Check the connection and run reason network again.`)}if(ge("sha256").update(o).digest("hex")!==s)throw new ne("The Reason Network download didn't match its checksum, so it wasn't installed.");Ie(o,n,e)}var K="Couldn't unpack the Reason Network download.";function Ie(e,n,t,r=process.platform){Q(v(t),{recursive:!0});let s=we(u(v(t),".reason-engine-"));try{let o=u(s,m);if(ee(n).endsWith(".zip"))o=u(s,`${m}.exe`),C(o,Ce(e,`${m}.exe`));else{C(u(s,"engine.tar.gz"),e);let i=g("tar",["--no-same-owner","-xzf",u(s,"engine.tar.gz"),"-C",s],{encoding:"utf8"});if(i.status!==0||!w(o)){let a=(i.stderr??"").trim().split(`
|
|
5
|
+
`).slice(-3).join("; "),l=i.error?`tar failed: ${i.error.message}`:i.signal?`tar was stopped by ${i.signal}`:i.status!==0?`tar exited ${i.status}${a?`: ${a}`:""}`:`no ${m} in it`;throw new ne(`Couldn't unpack the Reason Network download (${l}).`)}}pe(o,493),re(o,t,r)}finally{N(s,{recursive:!0,force:!0})}}function Ce(e,n){let t=e.lastIndexOf(Buffer.from("PK\x05\x06","latin1"));if(t<0||t+22>e.length)throw new ne(K);let r=e.readUInt32LE(t+16);for(let s=e.readUInt16LE(t+10);s>0;s-=1){if(r+46>e.length||e.readUInt32LE(r)!==33639248)break;let o=e.readUInt16LE(r+28);if(e.toString("utf8",r+46,r+46+o)===n){let i=e.readUInt16LE(r+10),a=e.readUInt32LE(r+20),l=e.readUInt32LE(r+24),c=e.readUInt32LE(r+42);if(c+30>e.length||e.readUInt32LE(c)!==67324752)break;let d=c+30+e.readUInt16LE(c+26)+e.readUInt16LE(c+28);if(d+a>e.length)break;let h=e.subarray(d,d+a),O;try{O=i===0?Buffer.from(h):i===8?_e(h):Buffer.alloc(0)}catch{break}if(i!==0&&i!==8||O.length!==l)break;return O}r+=46+o+e.readUInt16LE(r+30)+e.readUInt16LE(r+32)}throw new ne(K)}function re(e,n,t){if(t!=="win32"||!w(n)){k(e,n);return}let r=v(n),s=(i)=>i.startsWith(`${Z(n)}.`)&&i.endsWith(".old");for(let i of Ee(r).filter(s))try{N(u(r,i),{force:!0})}catch{}let o=`${n}.${process.pid}-${Date.now()}.old`;k(n,o);try{k(e,n)}catch(i){throw k(o,n),i}try{N(o,{force:!0})}catch{}}function Ae(e=process.env,n=f()){let t=e.REASON_NETWORK_HOME?.trim()||e.TINCAN_HOME?.trim();if(t)return t;let r=u(n,".reason","network"),s=u(n,".tincan");return!z(r)&&z(s)?s:r}var z=(e)=>w(u(e,"network.db"))||w(u(e,"tincan.db"));function Me(e,n=process.platform,t=Se.native){let r=w(u(e,"network.db"))||!w(u(e,"tincan.db"));if(n==="win32"){let o=e;try{o=t(e),o=o.startsWith("\\\\?\\")?o.slice(4):o.startsWith("\\\\")?`UNC\\${o.slice(2)}`:o}catch{}return`\\\\.\\pipe\\${r?"reason-network":"tincan"}-${V(o)}`}let s=u(e,r?"network.sock":"tincan.sock");if(Buffer.byteLength(s)<100)return s;return u("/tmp",`${r?"reason-network":"tincan"}-${process.getuid?.()??0}`,`${V(s)}.sock`)}function V(e){let n=0xcbf29ce484222325n;for(let t of Buffer.from(e))n=BigInt.asUintN(64,(n^BigInt(t))*0x100000001b3n);return n.toString(16).padStart(16,"0")}class Xr extends Error{code;constructor(e,n){super(e);this.code=n}}function Qi(e){return e instanceof Xr&&/isn't registered/.test(e.message)}var se="not_in_team",oe=15000,Ge=new Set(["who","team","inbox","unread","held"]),Le=90000,Be="Reason Network on this computer closed the connection";class y{socket;nextId=1;buffer="";pending=new Map;closed=null;hungUp=!1;constructor(e){this.socket=e;e.setEncoding("utf8"),e.on("data",(t)=>this.read(t));let n=(t)=>{this.closed=t;for(let r of this.pending.values())r.reject(t);this.pending.clear()};e.on("error",(t)=>n(t)),e.on("close",()=>n(Error(this.hungUp?"the connection to Reason Network on this computer was closed here":Be)))}static open(e){return new Promise((n,t)=>{let r=be(e);r.once("connect",()=>n(new y(r))),r.once("error",t)})}read(e){this.buffer+=e;let n=this.buffer.indexOf(`
|
|
6
|
+
`);while(n>=0){let t=this.buffer.slice(0,n);if(this.buffer=this.buffer.slice(n+1),n=this.buffer.indexOf(`
|
|
7
|
+
`),!t.trim())continue;let r;try{r=JSON.parse(t)}catch{continue}if(typeof r.id!=="number")continue;let s=this.pending.get(r.id);if(!s)continue;if(this.pending.delete(r.id),r.ok){s.resolve(r.result);continue}let o=r.error??"Reason Network on this computer refused the request",i=typeof r.code==="string"?r.code:/not (in|connected to) a team/i.test(o)?se:null;s.reject(new Xr(_(o),i))}}call(e,n={},t=oe){if(this.closed)return Promise.reject(this.closed);let r=this.nextId++;return this.socket.write(`${JSON.stringify({id:r,op:e,...n})}
|
|
8
|
+
`),new Promise((s,o)=>{let i=setTimeout(()=>{this.pending.delete(r),o(Error(`Reason Network on this computer didn't answer ${e} within ${Math.round(t/1000)}s`))},t);this.pending.set(r,{resolve:(a)=>{clearTimeout(i),s(a)},reject:(a)=>{clearTimeout(i),o(a)}})})}get isClosed(){return this.closed!==null}close(){this.hungUp=!0,this.socket.end()}}var T=/^(Claude Code|Grok|Codex) \u00B7 (.*)$/,De={"Claude Code":"claude-code",Grok:"grok",Codex:"codex"},Je=/^ask-[0-9a-f]{6}$/;function q(e){return{id:e.id,from:e.from,fromAgent:e.from_agent,to:e.to,replyTo:e.reply_to,body:e.body,sentAt:e.sent_at}}function X(e){return{person:e.person,machine:e.machine,isMe:e.is_me,online:e.online,link:e.link,rttMs:e.rtt_ms}}class Nt{engine;env;startup;connection=null;connectionOpening=null;generation=0;waits=new Set;constructor(e,n,t){this.engine=e;this.env=n;this.startup=t}static async open(e=process.env,n){let t=new Nt(await Pe(e,n),e,"recover");try{return await t.getConnection(),t}catch(r){throw t.close(),r}}static openInstalled(e=process.env){if(e[S])return new Nt(e[S],e,"installed");let n=b(),t=P();return t?.path===n&&E(n)===t.fingerprint?new Nt(n,e,"installed"):null}socketPath(){return Me(Ae(this.env))}assertGeneration(e){if(e!==this.generation)throw Error("the connection to Reason Network on this computer was closed here")}async open(e){let n;try{return await y.open(this.socketPath())}catch(s){n=s,this.assertGeneration(e)}let t=g(this.engine,["who","--json"],{env:this.env,encoding:"utf8",timeout:15000});if(t.status===0&&!t.error)try{return await y.open(this.socketPath())}catch(s){n=s}if(this.startup==="installed")throw new ne(`Couldn't connect to Reason Network on this computer (${String(n)}).`);this.assertGeneration(e),await this.setupAgentsForRecovery(e),this.assertGeneration(e);let r=g(this.engine,["who","--json"],{env:this.env,encoding:"utf8",timeout:15000});if(r.status!==0||r.error)throw new ne(`Couldn't start Reason Network on this computer${I(r)}${r.error?` (${r.error.message})`:""}.`);try{return await y.open(this.socketPath())}catch(s){throw new ne(`Couldn't connect to Reason Network on this computer (${String(s||n)}).`)}}async getConnection(){if(this.connection&&!this.connection.isClosed)return this.connection;if(this.connectionOpening)return this.connectionOpening;let e=this.generation,n=this.open(e).then((t)=>{if(e!==this.generation)throw t.close(),Error("the connection to Reason Network on this computer was closed here");return this.connection=t,t}).finally(()=>{if(this.connectionOpening===n)this.connectionOpening=null});return this.connectionOpening=n,n}async call(e,n={},t){let r=this.generation,s=await this.getConnection();this.assertGeneration(r);try{return await s.call(e,n,t)}catch(o){if(this.assertGeneration(r),!/closed|ECONNRESET|EPIPE/.test(String(o)))throw o;if(s=await this.getConnection(),this.assertGeneration(r),!Ge.has(e))throw o;return await s.call(e,n)}}async waitOn(e,n){let t=this.generation;await this.getConnection(),this.assertGeneration(t);let r=await y.open(this.socketPath());if(t!==this.generation)throw r.close(),Error("the connection to Reason Network on this computer was closed here");this.waits.add(r);try{return await r.call(e,n,n.wait_secs*1000+oe)}finally{this.waits.delete(r),r.close()}}closeConnections(){this.connection?.close(),this.connection=null;for(let e of this.waits)e.close();this.waits.clear()}close(){this.generation+=1,this.connectionOpening=null,this.closeConnections()}async team(){try{let{team_id:e,messages:n,...t}=await this.call("team"),r=t.machines.find((o)=>o.is_me)?.endpoint,s=Array.isArray(n)?n.flatMap((o)=>{let i=oo.safeParse(o);return i.success?[i.data]:[]}):null;return{...t,...typeof e==="string"&&e?{teamId:e}:{},machines:t.machines.map(X),...typeof r==="string"&&r?{endpoint:r}:{},...s?{messageCounts:s}:{}}}catch(e){if(e instanceof Xr&&e.code===se)return null;throw e}}async snapshot(e={}){let n=await this.call("who",{all:Boolean(e.all),...e.filter?{filter:e.filter}:{}}),t=new Set(n.sessions.filter((s)=>T.test(s.doing??"")).map((s)=>`${s.person}/${s.machine}:${s.cwd}`)),r=n.sessions.filter((s)=>e.all||!Je.test(s.name)).filter((s)=>T.test(s.doing??"")||!t.has(`${s.person}/${s.machine}:${s.cwd}`)).map((s)=>{let o=T.exec(s.doing??"");return{address:s.address,name:s.name,person:s.person,machine:s.machine,agent:o?De[o[1]]:s.agent,cwd:s.cwd,repo:s.repo,branch:s.branch,status:o?o[2]==="ready for work"?"idle":o[2]==="stopped"?"offline":"busy":s.status,since:s.since,doing:o?o[2]:s.doing,isMe:s.is_me,worker:Boolean(o),tier:s.tier??null}});return{team:n.team,person:n.person,machine:n.machine,machines:n.machines.map(X),sessions:r}}async send(e,n,t={}){if(!t.from)await this.call("hook",{agent:"cli",event:"stop",session_id:"terminal",name:"terminal",cwd:process.cwd(),mail:!1});let r=await this.call("send",{from:t.from??"cli:terminal",to:e,body:n,...t.replyTo?{reply_to:t.replyTo}:{},wake:t.wake??!0,...t.notify?{notify:!0}:{}});return{ids:r.ids,recipients:r.recipients.map((s)=>s.address),deliveries:r.recipients.map((s)=>({address:s.address,state:s.state,note:s.note??""}))}}async session(e,n={}){let t=n.agent??"cli",r=(a,l={})=>this.call("hook",{agent:t,event:a,session_id:e,name:e,cwd:process.cwd(),mail:!1,...l}),s=await r("stop"),o=`${t}:${e}`,i=s.address??e;return{name:e,get address(){return i},next:async(a)=>(await this.waitOn("inbox",{key:o,wait_secs:a,peek:!0})).messages.map(q),ack:async(a)=>{if(a.length)await this.call("delivered",{key:o,ids:a})},busy:async(a)=>{if(await r("prompt"),a)await r("doing",{doing:a})},idle:async(a)=>{if(await r("stop"),a)await r("doing",{doing:a})},doing:async(a)=>{await r("doing",{doing:a})},end:async()=>{await r("end")},rename:async(a)=>{i=(await this.call("set_status",{key:o,name:a})).address},send:(a,l,c,d)=>this.send(a,l,{from:o,...c?{replyTo:c}:{},...d?.notify?{notify:!0}:{}})}}async inbox(e={}){let t=(await this.waitOn("inbox",{key:"cli:terminal",wait_secs:e.waitSeconds??0,peek:!0}).catch((r)=>{if(/isn't registered/.test(String(r)))return{messages:[]};throw r})).messages.map(q);if(t.length&&!e.peek)await this.call("delivered",{key:"cli:terminal",ids:t.map((r)=>r.id)});return t}async link(e={}){return await this.call("link",{new:Boolean(e.new)})}async changeTeam(e,n){try{return await this.call(e,n,Le)}finally{this.close()}}async changeOntoTeam(e,n){try{await this.changeTeam(e,n)}catch(t){if(!/closed|ECONNRESET|EPIPE/.test(String(t)))throw t;if(await this.team())return;await this.changeTeam(e,n)}}async createTeam(e,n){await this.changeOntoTeam("create_team",{name:e,person:n})}async join(e,n){await this.changeOntoTeam("join",{ticket:e,person:n})}async leave(){return await this.changeTeam("leave",{force:!0})}async remove(e){return await this.call("remove",{who:e})}endpoint(){let e=g(this.engine,["endpoint"],{encoding:"utf8",env:this.env,timeout:30000}),n=e.status===0?e.stdout.trim():"";if(!n)throw new ne(`Reason Network on this computer couldn't say its endpoint${I(e)}.`);return n}async enterTeam(e,n,t){let r=t?{proof:t}:{},[s,o]="create"in e?["create_team",{name:e.create,person:n,...r}]:["join",{ticket:e.join,person:n,...r}],i=null;for(let a=0;a<2&&!i?.person;a+=1)try{i=await this.changeTeam(s,o)}catch(l){let c=String(l),d=l instanceof Xr&&l.code?l.code:/\(same_account_needs_owner\)/.test(c)?"same_account_needs_owner":/already in this team/.test(c)?"name_taken":null;if(d==="same_account_needs_owner")return{state:"needs_owner"};if(d==="name_taken")return{state:"name_taken"};if(!/closed|ECONNRESET|EPIPE/.test(c))throw l;let h=await this.team();if(h)i={name:h.name,person:h.person,machine:h.machine}}if(!i?.person)throw new ne("Reason Network on this computer didn't join the team. Run reason network again.");return{state:"entered",teamId:i.team_id??"",teamName:i.team_name||i.name||"",person:i.person??n,machine:i.machine??""}}async setupAgents(){return this.close(),this.runSetupAgents()}async setupAgentsForRecovery(e){this.assertGeneration(e),this.closeConnections(),await this.runSetupAgents(e)}async runSetupAgents(e){let n=await M(this.env);if(e!==void 0)this.assertGeneration(e);let t=g(this.engine,["setup",...G(this.env)?["--no-service"]:[]],{encoding:"utf8",env:n,timeout:60000});if(t.status!==0||t.error)throw new ne(`Couldn't connect this computer's agents to the network${I(t)}${t.error?` (${t.error.message})`:""}.`);return[...(t.stdout??"").matchAll(/^ {2}([^:\n]+): (?!skipped)/gm)].map((r)=>r[1]).filter((r)=>r!=="service")}async setup(e,n={}){return this.passthrough(["setup",...e],n,await M(this.env))}passthrough(e,n={},t=this.env){this.close();let r=g(this.engine,e,{stdio:["inherit","pipe",n.person?"inherit":"pipe"],encoding:"utf8",env:t});if(!n.quiet||r.status!==0)process.stdout.write(Fe(_(r.stdout??""))),process.stderr.write(Fe(_(r.stderr??"")));return r.status??1}}function I(e){let n=_(((e.stderr||e.stdout)??"").trim().split(`
|
|
9
|
+
`).pop()??"");return n?` (${n})`:""}function _(e){return e.replace(/not in a team yet:[^\n]*/g,"this computer isn't on a network yet: run `reason network`").replace(/`tincan (\w+)/g,"`reason network $1").replace(/\btincan (who|send|inbox|invite|join|team|link|setup|doctor|remove|leave|listen)\b/g,"reason network $1").replace(/(?<![\w./-])tincan(?![\w./-])/gi,"Reason Network")}
|
|
10
|
+
export{Fe,ne,fl,ml,Xr,Qi,Nt};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{te}from"./vm-hands-entry-lite-hpw27zfb.js";import{U,H,T}from"./vm-hands-entry-lite-
|
|
3
|
-
`)}).finally(()=>{if(a.get(h.port)===k)a.delete(h.port)})},dispose(){for(let p of a.values())p.abort();a.clear()}}}class lr extends r{observation;constructor(e){super("process_authority_lost","Process authority was lost; the owned process group has stopped.");this.observation=e}}var le=256,J=new Map,pe="preview.serve.v1",M=new Map;function ue(e){let a=M.get(e.operation_id);if(a){if(a.claim!==e)throw D("process_authority_lost");return a}if(M.size>=le)throw D("process_journal_capacity");let p={claim:e,executing:!1,cancelRequested:!1,phase:"pending"};return M.set(e.operation_id,p),p}function ae(e){return{version:1,process_id:e,state:"cancelled_before_start",exit_code:null,output:[],first_cursor:0,next_cursor:0,truncated:!1,cancellation_requested:!1,reason_code:"cancelled_before_start"}}var ce=(e)=>new Promise((a)=>setTimeout(a,e)),D=(e="process_outcome_uncertain")=>new r(e,"The managed process outcome could not be confirmed; inspect its saved receipt before starting another intent.");function Ve(e=s(),a=He()){let p=Le(gt({},e)),l=We(Et(e),p),[E,...h]=l.split(Ne);return{directory:A(a,l,"processes"),previous:[A(p,"processes"),...E==="reason"?[A(a,"ara",...h,"processes")]:[]]}}function He(){if(process.platform!=="darwin")throw new r("process_unavailable","Managed Mac process execution is unavailable.");let e=qc();if(!e)throw new r("process_unavailable","The private per-user process directory is unavailable.");return e}async function ei(e){if(!e.claim.owner||e.signal.aborted||e.expiresAtMs<=Date.now())throw D("process_authority_lost");let a=ue(e.claim);if(a.executing)throw D("process_busy");if(a.executing=!0,a.cancelRequested)return a.phase="settling",ae(e.claim.operation_id);a.phase="starting";let p=e.journals??Ve();Oe(p.directory,{recursive:!0,mode:448});let l=$t({runtimeDirectory:q(p.directory),previousRuntimeDirectories:(p.previous??[]).filter((u)=>Y(u)).map((u)=>q(u)),root:e.root,runId:JSON.stringify([e.claim.owner,e.claim.run_id,e.claim.root_id,e.claim.operation_id]),maxScopes:le,folders:[e.root,e.cwd]});try{for(let u of[e.root,e.cwd])if(!
|
|
2
|
+
import{te}from"./vm-hands-entry-lite-hpw27zfb.js";import{U,H,T}from"./vm-hands-entry-lite-13pzgnj9.js";import{_e,$t,oi,Po,Ro,ur}from"./vm-hands-entry-lite-7x2dnf35.js";import{gt}from"./vm-hands-entry-lite-ttemn34n.js";import{v,pr,Io,ht,ft}from"./vm-hands-entry-lite-sxnvhzy5.js";import{b,m}from"./vm-hands-entry-lite-2927z566.js";import{s,Et,qc}from"./vm-hands-entry-lite-tzv8s0e7.js";import{Xi,I,t,V,o,_,cl,Rt,_a,d,n,be,P,$e,c,i,Yi}from"./vm-hands-entry-lite-ef0ergar.js";import{Ye,G}from"./vm-hands-entry-lite-04nx5y4f.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{randomUUID as X}from"crypto";import{spawn as ke}from"child_process";import{existsSync as Y,lstatSync as de,mkdirSync as Oe,readFileSync as Me,realpathSync as q,rmSync as Te,writeFileSync as je}from"fs";import{dirname as Le,join as A,relative as We,sep as Ne}from"path";var ge=["process.run.v1","process.full.v1"],ve=600000,we=1800000,ye=20000,re="process.cancel.v1",oe=n({action:i("start"),request_id:t().uuid(),command:t().min(1).max(16000).refine((e)=>!e.includes("\x00")),cwd:t().min(1).max(4096).refine((e)=>!e.includes("\x00")&&!e.startsWith("/")&&!e.split(/[\\/]/).includes("..")).describe("Path relative to the granted device root; omit to use that root. Must not start with /, contain a .. path segment, or contain a NUL character.").optional(),mode:c(["host","confined"]).default("host"),timeout_ms:o().int().min(1000).max(we).default(ve).describe("Absolute process budget including queue and startup time. Defaults to ten minutes; longer explicit requests require the selected root's advertised max_timeout_ms. Retrying never renews the deadline.")}).strict(),B={device_id:t().uuid(),root_id:t().uuid()},Se=P("action",[oe.extend(B),n({...B,action:i("inspect"),process_id:t().uuid(),after:o().int().min(0).default(0),wait_ms:o().int().min(0).max(ye).default(0).describe("Wait for new output or a state change, bounded by this call's wait budget. Expiring this wait does not cancel the process or extend its deadline.")}).strict(),n({...B,action:i("cancel"),process_id:t().uuid()}).strict()]),qe=Xi(Se,{io:"input"}),Je=oe.extend({process_brain_fence:t().uuid(),process_expires_at:I.datetime()}).strict(),W=n({version:i(1),process_id:t().uuid(),state:c(["starting","running","exited","cancelled","expired","uncertain"]),exit_code:o().int().nullable(),first_cursor:o().int().min(0),next_cursor:o().int().min(0),truncated:_(),observed_at:I.datetime(),output:d(n({cursor:o().int().min(1),stream:c(["stdout","stderr"]),text:t().max(32768)}).strict()).max(128)}).strict().refine((e)=>{if(Buffer.byteLength(JSON.stringify(e))>1e5||e.next_cursor<e.first_cursor-1)return!1;if((e.state==="starting"||e.state==="running"||e.state==="uncertain")&&e.exit_code!==null)return!1;if(e.state==="exited"&&(e.exit_code===null||e.exit_code<0||e.exit_code>255))return!1;if(e.state==="cancelled"&&e.exit_code!==130||e.state==="expired"&&e.exit_code!==124)return!1;let p=e.first_cursor-1;for(let l of e.output){if(l.cursor<=p||l.cursor>e.next_cursor)return!1;p=l.cursor}return!0});function Qn(e){return ge.includes(e)}var ze=n({operation_constraints:$e(t(),Rt())}),Ge=n({ready:i(!0),version:i(1),execution_mode:c(["host","confined"]),max_timeout_ms:o().int().min(1000).optional()});var xe=n({version:i(1),process_id:t().uuid(),state:c(["queued","cancelled_before_start","not_started"]),exit_code:cl(),output:d(_a()).length(0),first_cursor:i(0),next_cursor:i(0),truncated:i(!1),cancellation_requested:i(!1),reason_code:c(["cancelled_before_start","process_journal_capacity","path_not_found","process_timeout_unsupported"]).optional(),expires_at:I.datetime().optional().describe("Accepted absolute process deadline. Reading, waiting and retrying do not extend it.")}).strict(),Pe=n({...W.shape,state:c(["queued","starting","running","exited","cancelled","expired","uncertain","cancelled_before_start","not_started"]),observed_at:I.datetime().optional(),expires_at:I.datetime().optional().describe("Accepted absolute process deadline. Reading, waiting and retrying do not extend it."),cancellation_requested:_(),reason_code:t().nullable().optional(),execution_authority:i("lost").optional().describe("Historical receipt only; the current Brain cannot control this older-generation process."),recovery:n({cause:i("brain_generation_changed"),terminal_confirmed:_(),next_step:c(["inspect_until_terminal","reconcile_effects_before_new_intent"])}).strict().optional().describe("Historical process recovery only. An unconfirmed outcome forbids replay. A confirmed terminal observation proves the old process stopped, not that its command had no effects. Reconcile the result; only restart still-needed, safely repeatable work with a new request_id and current authority. Respect user cancellation."),last_observed_state:W.shape.state.or(i("cancelled_before_start")).nullable().optional().describe("Last saved observation before authority was lost; a running observation does not establish current child liveness.")}).strict(),Be=Xi(Pe),Fe=be([W,xe.refine((e)=>e.state==="cancelled_before_start")]),F=n({version:i(1),process_id:t().uuid(),state:c(["exited","cancelled","expired"]),exit_code:o().int().min(0).max(255),observed_at:I.datetime()}).strict().refine((e)=>(e.state!=="cancelled"||e.exit_code===130)&&(e.state!=="expired"||e.exit_code===124)),Ee=n({process_terminal_observation:F}).strict();function Ba(e,a){let p=Ee.safeParse(e);return p.success&&p.data.process_terminal_observation.process_id===a?p.data:null}var Fa="preview.serve.v1",ja=43200000;var Ha=3,ne="preview.open.v1",se=1,yo="gid_proxy_v1",Ua="egress",wo=/^(?:\*\.)?[a-z0-9](?:[a-z0-9.-]{0,251}[a-z0-9])?(?::[1-9][0-9]{0,4})?$/,Re=n({version:i(yo),allowed_domains:d(t().max(260).regex(wo)).max(1024)}).strict(),Ie=Yi((e)=>te(e)!==null,"invalid workspace"),De=n({version:i(1),request_id:V(),session_id:V(),command:t().min(1).max(16000).refine((e)=>!e.includes("\x00")),port:o().int().min(1024).max(65535),workspace:Ie,egress:Re.optional()}).strict(),za=De.extend({expires_at:I.datetime()}).strict();var Ce=4,Ae=5000;function K(e,a,p){let l=null;try{l=pr(e)}catch{}Io({deviceRelayUrl:l?.deviceRelayUrl??"",binding:l?.binding??null,jobId:a,port:l?.binding.port??0,reason:l?p:"binding_invalid"})}function ie(e){let a=new Map;return{open(p){let l=(w)=>K(p,e.claim.operation_id,w),E;try{E=pr(p)}catch{return l("binding_invalid")}let{binding:h,deviceRelayUrl:N}=E,S=e.claim.owner;if(!S||h.organizationId!==S.organization_id||h.userId!==S.user_id||h.deviceId!==S.device_id||h.rootId!==e.claim.root_id||h.jobId!==e.claim.operation_id||h.fenceId!==e.claim.operation_id||h.generation!==se||h.expiresAtMs>Math.min(Date.now()+v.lifetimeMs+Ae,e.expiresAtMs))return l("binding_mismatch");if(h.expiresAtMs<=Date.now())return l("binding_expired");if(a.get(h.port)?.abort(),a.delete(h.port),a.size>=Ce)return l("preview_capacity");let k=new AbortController;a.set(h.port,k);let y=ft({binding:h,deniedPorts:e.deniedPorts,readCurrentJob:async()=>{if(k.signal.aborted)return null;let w=await e.inspect();return w?{binding:h,executorLaunchId:e.executorLaunchId,job:w}:null}});ht({binding:h,deviceRelayUrl:N,port:y,signal:k.signal}).then((w)=>w.closed,(w)=>{let x=w instanceof Error?w.message:"preview_failed";if(x!=="preview_not_authorized")process.stderr.write(`${JSON.stringify({event:"worker_preview.open_failed",job_id:h.jobId,port:h.port,reason_code:x})}
|
|
3
|
+
`)}).finally(()=>{if(a.get(h.port)===k)a.delete(h.port)})},dispose(){for(let p of a.values())p.abort();a.clear()}}}class lr extends r{observation;constructor(e){super("process_authority_lost","Process authority was lost; the owned process group has stopped.");this.observation=e}}var le=256,J=new Map,pe="preview.serve.v1",M=new Map;function ue(e){let a=M.get(e.operation_id);if(a){if(a.claim!==e)throw D("process_authority_lost");return a}if(M.size>=le)throw D("process_journal_capacity");let p={claim:e,executing:!1,cancelRequested:!1,phase:"pending"};return M.set(e.operation_id,p),p}function ae(e){return{version:1,process_id:e,state:"cancelled_before_start",exit_code:null,output:[],first_cursor:0,next_cursor:0,truncated:!1,cancellation_requested:!1,reason_code:"cancelled_before_start"}}var ce=(e)=>new Promise((a)=>setTimeout(a,e)),D=(e="process_outcome_uncertain")=>new r(e,"The managed process outcome could not be confirmed; inspect its saved receipt before starting another intent.");function Ve(e=s(),a=He()){let p=Le(gt({},e)),l=We(Et(e),p),[E,...h]=l.split(Ne);return{directory:A(a,l,"processes"),previous:[A(p,"processes"),...E==="reason"?[A(a,"ara",...h,"processes")]:[]]}}function He(){if(process.platform!=="darwin")throw new r("process_unavailable","Managed Mac process execution is unavailable.");let e=qc();if(!e)throw new r("process_unavailable","The private per-user process directory is unavailable.");return e}async function ei(e){if(!e.claim.owner||e.signal.aborted||e.expiresAtMs<=Date.now())throw D("process_authority_lost");let a=ue(e.claim);if(a.executing)throw D("process_busy");if(a.executing=!0,a.cancelRequested)return a.phase="settling",ae(e.claim.operation_id);a.phase="starting";let p=e.journals??Ve();Oe(p.directory,{recursive:!0,mode:448});let l=$t({runtimeDirectory:q(p.directory),previousRuntimeDirectories:(p.previous??[]).filter((u)=>Y(u)).map((u)=>q(u)),root:e.root,runId:JSON.stringify([e.claim.owner,e.claim.run_id,e.claim.root_id,e.claim.operation_id]),maxScopes:le,folders:[e.root,e.cwd]});try{for(let u of[e.root,e.cwd])if(!_e(q(u),l.journalDirectory))throw new r("process_journal_inside_workspace","The selected root contains the private process journal. Select an existing narrower granted workspace root outside the journal; no command was dispatched.")}catch(u){throw l.disposeSocket(),u}let E=de(l.journalDirectory),h=e.claim.capability===pe,N=()=>J.set(e.claim.operation_id,{path:l.journalDirectory,ino:E.ino,dev:E.dev,anyCompletion:h}),S=l.launchDirectory,k=A(S,"config.json"),y={url:"",transport:"local_job_ipc",directShell:{mode:e.mode,executable:e.shell,jobId:e.claim.operation_id},workerVersion:U,protocolVersion:2,workerArtifactSha256:T,workerEntrypoint:H,targetGeneration:1,fenceId:X(),...process.platform==="win32"?{bashExecutable:Ye()}:{},workRoot:e.root,workspaceAliasPath:e.root,repoPath:e.cwd,jobEnvPath:A(S,"unused.env"),replSocketPath:A(S,"unused.sock"),readyPath:A(S,"ready.json"),directTerminalReceiptPath:A(S,"terminal.json"),launchId:X(),expiresAtMs:e.expiresAtMs+5000,bashTimeoutMs:60000,replTimeoutMs:1000,allowedTools:["bash"],managedJobs:{journalDirectory:l.journalDirectory,scopeId:l.scopeId},jobControlSocketPath:l.socketPath,...e.prefix?{bashCommandPrefix:e.prefix}:{},...e.jobsUser?{jobsUser:e.jobsUser}:{}},w;try{je(k,JSON.stringify(y),{mode:384});let u=Po({configPath:k,root:e.cwd,grantedRoot:e.root,workRoot:e.root,temporaryDirectory:S});w=e.spawnWorker?.(k,y)??ke(u.command,u.args,{...u.options,env:e.environment,stdio:[Ro,"ignore","ignore"]})}catch(u){throw l.disposeSocket(),u}let x=!1,z=new Promise((u,g)=>{w.once("exit",(f)=>{x=!0,u(f)}),w.once("error",(f)=>{x=!0,g(f)})});z.catch(()=>{});let me={root:e.root,runId:e.claim.run_id,scopeId:l.scopeId,socketPath:l.socketPath,generation:1,fenceId:y.fenceId,executorLaunchId:y.launchId,expiresAtMs:y.expiresAtMs},O=async(u)=>{let g=await oi(me,{type:"job",version:2,generation:1,id:X(),jobId:e.claim.operation_id,...u==="start"?{action:u,input:{script:e.command,leaseExpiresAtMs:e.expiresAtMs}}:u==="inspect"?{action:u,input:{after:0}}:u==="probe"?{action:"inspect",input:{after:Number.MAX_SAFE_INTEGER}}:{action:u,input:{}}},new AbortController().signal);if(!g.ok)throw D(g.error);return g.job},j=!1,L=!1,Q,Z=()=>{j=!0,ur(w,"SIGTERM")};e.signal.addEventListener("abort",Z,{once:!0});let C,ee=0,fe=async(u)=>{let g=[...u.output],f={version:1,process_id:e.claim.operation_id,state:u.state,exit_code:u.exitCode,first_cursor:u.firstCursor,next_cursor:u.nextCursor,truncated:u.truncated,output:g,observed_at:new Date().toISOString()};while(Buffer.byteLength(JSON.stringify(f))>90000&&g.length)g.shift(),f.truncated=!0,f.first_cursor=g[0]?.cursor??f.next_cursor+1;C=W.parse(f),await e.emit(C),ee=Date.now()};try{let u=Math.min(Date.now()+1e4,e.expiresAtMs);while(!Y(y.readyPath)){if(x)throw new r("process_start_failed","The managed process supervisor exited before accepting a command; no command was dispatched.");if(e.signal.aborted||Date.now()>=u)throw D("process_start_unconfirmed");await ce(25)}let g=JSON.parse(Me(y.readyPath,"utf8"));if(g.launchId!==y.launchId||g.fenceId!==y.fenceId||g.workerArtifactSha256!==T)throw D();if(e.signal.throwIfAborted(),a.cancelRequested)return ae(e.claim.operation_id);let f;try{L=!0,f=await O("start")}catch(R){if(!(R instanceof r)||R.code!=="hands_job_result_unknown")throw R;f=await O("inspect")}if(a.phase="running",a.cancel=async()=>{await O("cancel")},h&&e.preview)a.tunnels=ie({claim:e.claim,executorLaunchId:y.launchId,expiresAtMs:e.expiresAtMs,deniedPorts:e.preview.deniedPorts,inspect:async()=>a.phase==="running"&&!x?await O("probe"):null});if(a.cancelRequested)await a.cancel(),f=await O("inspect");for(;;){if(!["starting","running"].includes(f.state))a.phase="settling",a.cancel=void 0;if(!C||C.state!==f.state||C.next_cursor!==f.nextCursor&&Date.now()-ee>=5000)await fe(f);if(!["starting","running"].includes(f.state))break;if(e.signal.aborted||x)throw D();await ce(1000);try{f=await O("inspect"),Q=void 0}catch(R){if(!(R instanceof r)||R.code!=="hands_job_result_unknown"||e.signal.aborted||x||Date.now()-(Q??=Date.now())>120000)throw R}}if(!C||C.state==="uncertain")throw D();return C}finally{if(a.phase="settling",a.cancel=void 0,a.tunnels?.dispose(),a.tunnels=void 0,await a.cancelInFlight?.catch(()=>{}),e.signal.removeEventListener("abort",Z),!x&&!j)ur(w,"SIGTERM");let u,g=await Promise.race([z.then((f)=>({code:f})),new Promise((f)=>{u=setTimeout(()=>f(null),6000)})]).finally(()=>{clearTimeout(u)});if(!g){try{ur(w,"SIGKILL")}catch{}try{await z}finally{if(x)l.disposeSocket()}throw D("process_cleanup_unconfirmed")}try{if((j||e.signal.aborted)&&g.code===0&&L){b(S);let f=JSON.parse(m(y.directTerminalReceiptPath)),R=F.safeParse(f.observation);if(Object.keys(f).length===4&&f.launch_id===y.launchId&&f.fence_id===y.fenceId&&f.scope_id===l.scopeId&&R.success&&R.data.process_id===e.claim.operation_id){if(h)N();throw new lr(R.data)}}}catch(f){if(f instanceof lr)throw f}finally{if(x)l.disposeSocket()}if(g.code!==0&&!j&&L)throw D("process_cleanup_unconfirmed");if(!j&&g.code===0&&(C&&["exited","cancelled","expired"].includes(C.state)||!L&&a.cancelRequested)||h&&g.code===0&&!L)N()}}async function bo(e,a){if(a.kind===ne&&e.capability===pe){let E=M.get(e.operation_id);if(E?.claim===e&&E.tunnels)E.tunnels.open(a.payload);else K(a.payload,e.operation_id,"server_not_running");return!0}if(a.kind!==re||!Qn(e.capability)||!e.owner||a.payload.process_id!==e.operation_id)return!1;let p=M.get(e.operation_id);if(p&&p.claim!==e)return!1;let l=ue(e);if(l.cancelRequested=!0,l.phase==="running"&&l.cancel)l.cancelInFlight??=l.cancel(),await l.cancelInFlight;return!0}function ti(e,a){M.delete(e);let p=J.get(e);if(!p||a!=="succeeded"&&!p.anyCompletion)return J.delete(e),!1;try{let l=de(p.path);if(!l.isDirectory()||l.isSymbolicLink()||l.ino!==p.ino||l.dev!==p.dev||!G(l)||q(p.path)!==p.path||Y(A(p.path,"owner.lock")))return!1;return Te(p.path,{recursive:!0}),J.delete(e),!0}catch{return!1}}
|
|
4
4
|
export{Qn,Ba,Fa,ja,Ha,yo,Ua,wo,za,lr,ei,bo,ti};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import{s}from"./vm-hands-entry-lite-tzv8s0e7.js";import{readFileSync as l}from"fs";import{isAbsolute as i,normalize as m}from"path";var p="REASON_WORKER_DESKTOP_USER",u=null;function d(t,o){for(let c of o.split(`
|
|
3
|
-
`)){let e=c.split(":");if(e.length<7||Number(e[2])!==t||!/^\d+$/.test(e[2])||!/^\d+$/.test(e[3]))continue;let n=e[5];if(!/^[a-z_][a-z0-9_-]*$/i.test(e[0])||!i(n)||m(n)!==n||n==="/")return null;return{username:e[0],uid:t,gid:Number(e[3]),home:n}}return null}function kr(t={}){let o="value"in t?t.value:process.env[p];if(u=null,o===void 0||o==="")return null;let c=t.platform??process.platform,e="euid"in t?t.euid:process.geteuid?.(),n=/^[1-9]\d{0,9}$/.test(o)?Number(o):NaN,r=c==="linux"&&e===0&&Number.isSafeInteger(n)?d(n,(t.passwd??(()=>l("/etc/passwd","utf8")))()):null;if(!r||r.gid===0)throw Error("worker_desktop_user_invalid");return u=r,r}function
|
|
4
|
-
export{kr,
|
|
3
|
+
`)){let e=c.split(":");if(e.length<7||Number(e[2])!==t||!/^\d+$/.test(e[2])||!/^\d+$/.test(e[3]))continue;let n=e[5];if(!/^[a-z_][a-z0-9_-]*$/i.test(e[0])||!i(n)||m(n)!==n||n==="/")return null;return{username:e[0],uid:t,gid:Number(e[3]),home:n}}return null}function kr(t={}){let o="value"in t?t.value:process.env[p];if(u=null,o===void 0||o==="")return null;let c=t.platform??process.platform,e="euid"in t?t.euid:process.geteuid?.(),n=/^[1-9]\d{0,9}$/.test(o)?Number(o):NaN,r=c==="linux"&&e===0&&Number.isSafeInteger(n)?d(n,(t.passwd??(()=>l("/etc/passwd","utf8")))()):null;if(!r||r.gid===0)throw Error("worker_desktop_user_invalid");return u=r,r}function de(){return u}function ns(){return u?.home??s()}
|
|
4
|
+
export{kr,de,ns};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{cr,La}from"./vm-hands-entry-lite-bqs4pkyb.js";function
|
|
3
|
-
export{
|
|
2
|
+
import{cr,La}from"./vm-hands-entry-lite-bqs4pkyb.js";function ie(o=process.platform){if(cr(),o==="linux"||o==="win32")La("strict")}
|
|
3
|
+
export{ie};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{w}from"./vm-hands-entry-lite-
|
|
2
|
+
import{w}from"./vm-hands-entry-lite-a4fn6ye1.js";import{existsSync as T,mkdirSync as k,readFileSync as d,rmSync as y,writeFileSync as b}from"fs";import{homedir as l,hostname as M}from"os";import{dirname as N,join as h}from"path";function f(t){let e=t.trim().slice(t.trim().indexOf("#")+1),o=["rn1-","tincan1"].find((a)=>e.startsWith(a));if(!o)return null;let n=Buffer.from(e.slice(o.length),"base64url"),r=32,i=(a)=>(r+=a,r<=n.length),m=()=>{let a=n[r];if(a===void 0||!i(1))return!1;if(a!==255)return i(a);let s=n[r];return s!==void 0&&i(1)&&i(s)};if(n.length<32||!m()||!m()||!m())return null;let u=n[r];if(u===void 0||!i(1))return null;for(let a=0;a<u;a+=1){let s=n[r];if(!i(1)||!i(s===4?4:s===6?16:Number.NaN)||!i(2))return null}let g=[];for(;r+32<=n.length;r+=32)g.push(n.subarray(r,r+32).toString("hex"));return{team:n.subarray(0,16).toString("hex"),name:n.subarray(33,33+n[32]).toString("utf8"),secret:n.subarray(16,32).toString("hex"),machines:g}}var p=(t)=>h(t,".reason","ask.json");function A(t){try{let e=JSON.parse(d(p(t),"utf8"));if(typeof e.orgId!=="string"||typeof e.team!=="string")return null;let o=e.pendingRotation;return{orgId:e.orgId,team:e.team,...typeof e.checkedAt==="number"?{checkedAt:e.checkedAt}:{},...o&&typeof o.link==="string"&&typeof o.team==="string"&&typeof o.replaces==="string"?{pendingRotation:o}:{}}}catch{return null}}var c=(t)=>{let e=w();return h(t,".reason",e==="production"?"network-team.json":`network-team.${e}.json`)};function ka(t=l()){return c(t).replace(/\.json$/,"-login.json")}function xa(t=l()){try{let e=JSON.parse(d(c(t),"utf8"));return typeof e.team==="string"?{team:e.team,setupDone:e.setupDone===!0,registered:typeof e.registered==="string"?e.registered:null,account:typeof e.account==="string"?e.account:null}:null}catch{return null}}function Ca(t,e=l()){k(N(c(e)),{recursive:!0}),b(c(e),`${JSON.stringify(t)}
|
|
3
3
|
`,{mode:384}),y(p(e),{force:!0})}function Kr(t=l()){let e=A(t);return e?{orgId:e.orgId,team:e.team}:null}function Jr(t){let e=f(t);return e&&e.machines.length>0?{teamId:e.team,teamName:e.name,secret:e.secret}:null}
|
|
4
4
|
export{ka,xa,Ca,Kr,Jr};
|