@reason-machines/cli-linux-arm64-musl 0.2.358 → 0.2.360
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ara +1 -1
- package/bin/vm-hands/api-credentials-vtpssnm1.js +2 -0
- package/bin/vm-hands/api-dvwzjwmh.js +2 -0
- package/bin/vm-hands/ask-relay-0y716ck6.js +8 -0
- package/bin/vm-hands/connect-cli-sbczes1h.js +2 -0
- package/bin/vm-hands/custom-endpoint-device-8v87dhjx.js +2 -0
- package/bin/vm-hands/desktop-account-q57958y1.js +2 -0
- package/bin/vm-hands/{device-workspace-7yg5x68n.js → device-workspace-c05vq771.js} +1 -1
- package/bin/vm-hands/hands-worker-source-wfv9csj2.js +2 -0
- package/bin/vm-hands/{index-swa20ch8.js → index-80ep9259.js} +1 -1
- package/bin/vm-hands/install-receipt-pbfhgaxc.js +2 -0
- package/bin/vm-hands/local-automation-j8402b7e.js +2 -0
- package/bin/vm-hands/local-capabilities-yekmdbpc.js +2 -0
- package/bin/vm-hands/local-desktop-users-m7rexsex.js +2 -0
- package/bin/vm-hands/local-display-mac-9de01n3r.js +2 -0
- package/bin/vm-hands/local-display-session-d3hvgjqs.js +2 -0
- package/bin/vm-hands/local-pty-session-e7j0kj19.js +2 -0
- package/bin/vm-hands/managed-runtime-r1138kvq.js +2 -0
- package/bin/vm-hands/{network-contract-rm9x646s.js → network-contract-zjq3w2n3.js} +1 -1
- package/bin/vm-hands/package-44a3p8yk.js +2 -0
- package/bin/vm-hands/permissions-g0asz6w1.js +2 -0
- package/bin/vm-hands/{reason-hands-protocol-3z7bas06.js → reason-hands-protocol-aj1zwpk0.js} +1 -1
- package/bin/vm-hands/serve-service-9jd2zcmb.js +2 -0
- package/bin/vm-hands/{status-psxtsknj.js → status-7v31d0ab.js} +2 -2
- package/bin/vm-hands/version-2fvzdbmj.js +2 -0
- package/bin/vm-hands/vm-hands-entry-lite-0763vz5v.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-1hv536wk.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-0hv9ek0t.js → vm-hands-entry-lite-2j67g42s.js} +9 -68
- package/bin/vm-hands/{vm-hands-entry-lite-0tdpjsxc.js → vm-hands-entry-lite-3qxye8en.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-3tf5zyba.js +9 -0
- package/bin/vm-hands/{vm-hands-entry-lite-rr0hhz7g.js → vm-hands-entry-lite-4rd6b2ra.js} +3 -3
- package/bin/vm-hands/vm-hands-entry-lite-4xfs7y6w.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-xhjbc3e4.js → vm-hands-entry-lite-5y2kfnv2.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-trcg4jv7.js → vm-hands-entry-lite-6fvjbwqq.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-dys7am1h.js → vm-hands-entry-lite-7nk0873d.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-zrvaqawr.js → vm-hands-entry-lite-97zxda1y.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-c9wp99nr.js → vm-hands-entry-lite-avstvbbc.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-cety9pka.js +5 -0
- package/bin/vm-hands/vm-hands-entry-lite-cwf21py1.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-84d59wrf.js → vm-hands-entry-lite-dqnhebfx.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-nvhzj5b0.js → vm-hands-entry-lite-f4gvypnx.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-qf01e5f1.js → vm-hands-entry-lite-fr2k6eah.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-wpx6sg6d.js → vm-hands-entry-lite-gxjxx1r2.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-hfq6jjnh.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-nd1k2jz9.js → vm-hands-entry-lite-hw8vgsmm.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-8jmwhybq.js → vm-hands-entry-lite-jc229h5p.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-6f5eypjm.js → vm-hands-entry-lite-jjkkee8q.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-beannz0s.js → vm-hands-entry-lite-jpkf3569.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-k17ntg9v.js → vm-hands-entry-lite-k7fkfytm.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-tj1y61bg.js → vm-hands-entry-lite-kxtjkzzh.js} +1 -1
- package/bin/vm-hands/{vm-hands-entry-lite-he2z2137.js → vm-hands-entry-lite-ne0nrjkn.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-3zxjyj62.js → vm-hands-entry-lite-nnvyvx1n.js} +3 -3
- package/bin/vm-hands/vm-hands-entry-lite-npqaxsmx.js +11 -0
- package/bin/vm-hands/vm-hands-entry-lite-p1nb6n3r.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-qqyrwyfz.js +37 -0
- package/bin/vm-hands/{vm-hands-entry-lite-jfwz0br7.js → vm-hands-entry-lite-qy9xzp2m.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-c8hfat7y.js → vm-hands-entry-lite-rkt48xf4.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-5b29hq7h.js → vm-hands-entry-lite-tbps80f1.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-v1amz3pq.js +62 -0
- package/bin/vm-hands/{vm-hands-entry-lite-mybm2kyz.js → vm-hands-entry-lite-vcm4389c.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-wej1p1ry.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-gcn3rmz6.js → vm-hands-entry-lite-wry37am5.js} +1 -1
- package/bin/vm-hands/vm-hands-entry-lite-x7204pcv.js +340 -0
- package/bin/vm-hands/{vm-hands-entry-lite-nbtpm59m.js → vm-hands-entry-lite-xhr0m9r0.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-xj0p1ax7.js +5 -0
- package/bin/vm-hands/{vm-hands-entry-lite-95k4g3jj.js → vm-hands-entry-lite-zn303jrg.js} +1 -1
- package/bin/vm-hands/vm-hands-entry-lite.js +1 -1
- package/bin/vm-hands/{vm-hands-executor-dqqdgtqq.js → vm-hands-executor-xcscxb3s.js} +1 -1
- package/bin/vm-hands/vm-hands-op-runner-tm0sh7y6.js +2 -0
- package/bin/vm-hands/{vm-hands-runtime-y89fmev1.js → vm-hands-runtime-3yg846f8.js} +3 -3
- package/bin/vm-hands/worker-sandbox-wb5thd4n.js +2 -0
- package/package.json +1 -1
- package/bin/vm-hands/api-credentials-emdf5nm5.js +0 -2
- package/bin/vm-hands/api-js29ghm5.js +0 -2
- package/bin/vm-hands/ask-relay-qv9ddzr1.js +0 -8
- package/bin/vm-hands/connect-cli-8nxph9td.js +0 -2
- package/bin/vm-hands/custom-endpoint-device-j3e3zjd5.js +0 -2
- package/bin/vm-hands/desktop-account-gcysz0m3.js +0 -2
- package/bin/vm-hands/hands-worker-source-hbp5n31r.js +0 -2
- package/bin/vm-hands/local-automation-nw3bj9b5.js +0 -2
- package/bin/vm-hands/local-capabilities-7m54wthn.js +0 -2
- package/bin/vm-hands/local-desktop-users-pccz3sz9.js +0 -2
- package/bin/vm-hands/local-display-mac-gj72gkfb.js +0 -2
- package/bin/vm-hands/local-display-session-5ajajxtg.js +0 -2
- package/bin/vm-hands/local-pty-session-zen80k1k.js +0 -2
- package/bin/vm-hands/package-1e3w44ve.js +0 -2
- package/bin/vm-hands/permissions-0ej6xgrj.js +0 -2
- package/bin/vm-hands/version-fw3dwa12.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-33ttamma.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-3ms5bb0b.js +0 -43
- package/bin/vm-hands/vm-hands-entry-lite-6qfax5p2.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-d9k3dzaq.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-dyy62gt3.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-pm0j47qj.js +0 -343
- package/bin/vm-hands/vm-hands-entry-lite-tdgbgcer.js +0 -3
- package/bin/vm-hands/vm-hands-op-runner-msdteb31.js +0 -2
- package/bin/vm-hands/worker-sandbox-yw24sxyp.js +0 -2
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{Di as v,Gi as _,Ii as w,Mi as S,Ni as x}from"./vm-hands-entry-lite-3tf5zyba.js";import{Si as I}from"./vm-hands-entry-lite-tbps80f1.js";import{qj as O}from"./vm-hands-entry-lite-rkt48xf4.js";import{Jj as L,Kj as T}from"./vm-hands-entry-lite-avstvbbc.js";import{bk as G}from"./vm-hands-entry-lite-hw8vgsmm.js";import{spawnSync as l}from"child_process";import{dirname as B}from"path";import{spawn as y}from"child_process";import{accessSync as c,constants as g}from"fs";import{basename as h,join as m}from"path";var j=null;function U(q){if(j===q)j=null;if(q.exitCode===null&&q.signalCode===null)q.kill("SIGTERM")}var C=(q,z)=>{if(j)U(j);let J=m(q,v);try{c(J,g.X_OK)}catch{return()=>{}}let F;try{F=y(J,["--app",q,"--name",h(q,".app"),"--permission",z==="screen"?"screen_recording":"accessibility"],{detached:!0,stdio:"ignore"})}catch{return()=>{}}return F.on("error",()=>{if(j===F)j=null}),F.once("exit",()=>{if(j===F)j=null}),F.unref(),j=F,()=>U(F)};var M=`Reason permissions
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
reason permissions [--json]
|
|
6
|
+
reason permissions allow [screen|accessibility|disk]
|
|
7
|
+
|
|
8
|
+
The macOS privacy permissions of this computer's Reason worker:
|
|
9
|
+
screen Screen & System Audio Recording: desktop video, computer-use screenshots
|
|
10
|
+
accessibility Accessibility: computer-use clicks and typing, desktop input
|
|
11
|
+
disk Full Disk Access (recommended): Sessions in Desktop, Documents,
|
|
12
|
+
Downloads, iCloud Drive and Mail
|
|
13
|
+
|
|
14
|
+
allow asks for each missing one, or the one named. macOS cannot ask for Full
|
|
15
|
+
Disk Access: allow disk opens its pane, shows the file to add in Finder and
|
|
16
|
+
waits until the worker has it.
|
|
17
|
+
`,D="x-apple.systempreferences:com.apple.preference.security",a="curl -fsSL https://reasonmachines.com/install.sh | bash",d=180000,n=2000,E=["screen","accessibility","disk"],N={screen:{label:"Screen & System Audio Recording",purpose:"desktop video, computer-use screenshots",level:"required",pane:`${D}?Privacy_ScreenCapture`},accessibility:{label:"Accessibility",purpose:"computer-use clicks and typing, desktop input",level:"required",pane:`${D}?Privacy_Accessibility`},disk:{label:"Full Disk Access",purpose:"Sessions in Desktop, Documents, Downloads, iCloud Drive and Mail",level:"recommended",pane:`${D}?Privacy_AllFiles`}};function k(q){return q.executable}function p(q,z){if(q==="computer_use_identity_missing")return`Reason's background identity is not installed (${q}); reinstall Reason: ${a}`;if(q==="computer_use_identity_outdated")return`Reason's background identity is outdated (${w(z)??"unknown"}; this CLI is ${O}) (${q}); \`reason update\` installs this release's`;return`Reason's background identity cannot run computer use for this CLI (${q}); run the installed \`reason\``}function s(q=I()){let z=S(q);if(z.length>0)return{state:"ready",path:B(B(B(z[0]))),prefix:z};let J=x(z,q)??"computer_use_identity_unavailable";return{state:J,path:_(q),detail:p(J,q)}}function u(){return{identity:()=>s(),grants:(q)=>L(q),request:(q,z)=>T(q,z),worker:async()=>(await import("./status-7v31d0ab.js")).connectionMacState(),open:(q)=>{l("/usr/bin/open",q,{stdio:"ignore",timeout:1e4})},tile:C,restartConnection:async()=>(await import("./connect-cli-sbczes1h.js")).restartConnection(),sleep:(q)=>new Promise((z)=>setTimeout(z,q)),now:()=>Date.now()}}function P(q,z,J){if(q.state!=="ready"||!z)return"unknown";return z[J]?"granted":"missing"}async function b(q){let z=q.identity(),J=z.state==="ready"?await q.grants(z.prefix):null,F=await q.worker(),X=F?k(F):null,Q=!X||F?.full_disk_access==="unknown"?"unknown":F?.full_disk_access==="granted"?"granted":"missing",$=(K,H,Z)=>{let{label:R,purpose:W,level:V}=N[K];return{id:K,label:R,purpose:W,level:V,state:H,holder:Z}};return{identity:{state:z.state,path:z.path,detail:z.state==="ready"?null:z.detail},worker_detail:X?null:"Full Disk Access is read from this computer's running worker; `reason connect` starts it.",permissions:[$("screen",P(z,J,"screen"),z.path),$("accessibility",P(z,J,"accessibility"),z.path),$("disk",Q,X)]}}function Rq(q){let z=q.identity.state==="ready"?null:q.identity.state,J=q.permissions.filter((Q)=>Q.state==="granted").length,F=[...z?[z]:[],...q.permissions.filter((Q)=>Q.state!=="granted"&&!(z&&Q.id!=="disk")).map((Q)=>`${Q.label} ${Q.state}`)],X=!z&&q.permissions.some((Q)=>Q.state==="missing");return`Permissions: ${J} of ${q.permissions.length}${F.length>0?` (${F.join(", ")})`:""}`+(X?" \u2014 reason permissions allow":F.length>0?" \u2014 reason permissions":"")}function t(q){let z=[];if(q.identity.detail)z.push(q.identity.detail);z.push(`Reason: ${q.identity.path}`);let J=q.permissions.find((F)=>F.id==="disk");z.push(J?.holder?`Worker: ${J.holder}`:`Worker: ${q.worker_detail}`),z.push("");for(let F of q.permissions){let X=`${F.label}${F.level==="recommended"?" (recommended)":""}`;z.push(` ${F.id.padEnd(13)} ${F.state.padEnd(7)} ${X}: ${F.purpose}`)}if(q.permissions.some((F)=>F.state==="missing"))z.push("","Allow the missing ones: reason permissions allow");return`${z.join(`
|
|
18
|
+
`)}
|
|
19
|
+
`}async function A(q,z){let J=z.now()+d;for(;;){if(await q())return!0;if(z.now()>=J)return!1;await z.sleep(n)}}async function o(q,z){let J=z.host??u(),{io:F}=z,X=await b(J),Q=X.permissions.filter((Z)=>q.includes(Z.id)&&Z.state!=="granted");if(Q.length===0)return F.stdout.write(`Reason permissions: ${q.map((Z)=>N[Z].label).join(", ")} already allowed.
|
|
20
|
+
`),0;let $=!1,K=!1,H=J.identity();for(let Z of Q){let{label:R,pane:W}=N[Z.id];if(Z.id!=="disk"){if(H.state!=="ready"){if(!$)F.stderr.write(`Reason permissions: ${H.detail}
|
|
21
|
+
`);$=!0;continue}let Y=Z.id;await J.request(H.prefix,Y),J.open([W]);let f=J.tile(H.path,Y);if(F.stdout.write(`Allow Reason in System Settings > Privacy & Security > ${R}.
|
|
22
|
+
`),!z.wait)continue;if(F.stdout.write(`Waiting for it (Ctrl-C to stop)\u2026
|
|
23
|
+
`),await A(async()=>(await J.grants(H.prefix))?.[Y]===!0,J).finally(f))F.stdout.write(`${R}: granted.
|
|
24
|
+
`),K=!0;else F.stderr.write(`${R} is not allowed yet; turn on Reason there, then run \`reason permissions\`.
|
|
25
|
+
`),$=!0;continue}let V=k(await J.worker()??{executable:null});if(!V){F.stderr.write(`Reason permissions: ${X.worker_detail} Then run \`reason permissions allow disk\`.
|
|
26
|
+
`),$=!0;continue}if(J.open([W]),J.open(["-R",V]),F.stdout.write(`Full Disk Access: click + and choose ${V} (shown in Finder), or drag it into the list.
|
|
27
|
+
`),!z.wait)continue;if(F.stdout.write(`Waiting for the worker to report it (Ctrl-C to stop)\u2026
|
|
28
|
+
`),await A(async()=>(await J.worker())?.full_disk_access==="granted",J))F.stdout.write(`Full Disk Access: granted.
|
|
29
|
+
`);else F.stderr.write("Full Disk Access is not reported yet. If you allowed it, `reason connect` restarts the worker with it.\n"),$=!0}if(K)try{if(await J.restartConnection())F.stdout.write(`This computer's Reason connection restarted to use them.
|
|
30
|
+
`)}catch(Z){F.stderr.write(`This computer's Reason connection uses them after it restarts (\`reason connect\`): ${Z instanceof Error?Z.message:String(Z)}
|
|
31
|
+
`)}return $?1:0}function i(q){if(q.some((F)=>["--help","-h","help"].includes(F)))return{command:"help"};let[z,...J]=q;if(z===void 0||z==="--json")return q.length<=1?{command:"list",json:z==="--json"}:{error:`Unknown option: ${q[1]}`};if(z!=="allow")return{error:`Unknown permissions command: ${z}`};if(J.length>1)return{error:`Unknown option: ${J[1]}`};if(J.length===0)return{command:"allow",ids:[...E]};if(!E.includes(J[0]))return{error:`allow expects ${E.join(", ")}.`};return{command:"allow",ids:[J[0]]}}async function Vq(q,z={}){let J=z.io??{stdout:process.stdout,stderr:process.stderr},F=i(q);if("error"in F)return J.stderr.write(`${F.error}
|
|
32
|
+
|
|
33
|
+
${M}`),1;if(F.command==="help")return J.stdout.write(M),0;let X=z.platform??process.platform;if(X!=="darwin")return J.stdout.write(F.command==="list"&&F.json?`${JSON.stringify({platform:X,applicable:!1})}
|
|
34
|
+
`:`Reason permissions: macOS privacy permissions do not apply on this computer.
|
|
35
|
+
`),0;let Q=z.host??u();if(F.command==="allow")return o(F.ids,{io:J,wait:!0,host:Q});let $=await b(Q);return J.stdout.write(F.json?`${JSON.stringify({platform:X,applicable:!0,...$},null,2)}
|
|
36
|
+
`:t($)),0}
|
|
37
|
+
export{C as qi,M as ri,E as si,k as ti,s as ui,b as vi,Rq as wi,t as xi,o as yi,i as zi,Vq as Ai};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
3
|
-
export{r as
|
|
2
|
+
import{zg as m}from"./vm-hands-entry-lite-xj0p1ax7.js";import{Ng as w}from"./vm-hands-entry-lite-vcm4389c.js";import{Ti as h}from"./vm-hands-entry-lite-tbps80f1.js";import{ej as x}from"./vm-hands-entry-lite-dqnhebfx.js";import{Xj as Q}from"./vm-hands-entry-lite-kxtjkzzh.js";import{existsSync as B,realpathSync as k,statSync as s}from"fs";import{platform as p}from"os";import{isAbsolute as y,sep as d}from"path";var r=43200000,A=w,l=4,u=/^[A-Za-z0-9._:-]{1,160}$/,a=1000;function v(z){return Boolean(z)&&typeof z==="object"&&!Array.isArray(z)}function q(z,H){if(typeof z!=="number"||!Number.isFinite(z)||z<=0)return H;return Math.min(a,Math.max(1,Math.floor(z)))}function n(z,H=Date.now()){let V=["relay_url","session_id","expires_at"],J=new Set([...V,"cols","rows","cwd","workspace"]);if(!v(z)||V.some((L)=>!(L in z))||Object.keys(z).some((L)=>!J.has(L)))throw new Q("invalid_pty_request","Reason terminal request is malformed.");let{relay_url:j,session_id:Y,expires_at:C}=z;if(typeof j!=="string")throw new Q("invalid_pty_request","Reason terminal relay URL is missing.");let D;try{D=new URL(j)}catch{throw new Q("invalid_pty_request","Reason terminal relay URL is invalid.")}if(D.protocol!=="wss:"&&D.protocol!=="ws:"||D.username||D.password)throw new Q("invalid_pty_request","Reason terminal relay URL is invalid.");if(typeof Y!=="string"||!u.test(Y))throw new Q("invalid_pty_request","Reason terminal session identity is invalid.");let R=typeof C==="string"?Date.parse(C):Number.NaN;if(!Number.isFinite(R)||R<=H)throw new Q("invalid_pty_request","Reason terminal session has already expired.");if(z.cwd!==void 0&&typeof z.cwd!=="string")throw new Q("invalid_pty_request","Reason terminal working directory is invalid.");let Z=z.workspace===void 0?void 0:x(z.workspace);if(Z===null||Z&&z.cwd!==void 0)throw new Q("invalid_pty_request","Reason terminal workspace is invalid.");return{relay_url:j,session_id:Y,expires_at:new Date(Math.min(R,H+r)).toISOString(),cols:q(z.cols,80),rows:q(z.rows,24),...z.cwd===void 0?{}:{cwd:z.cwd},...Z?{workspace:Z}:{}}}function o(z,H){return H===z||H.startsWith(z+d)}function U(z,H){if(H===void 0)return z;if(!y(H))throw new Q("pty_cwd_invalid","Reason terminal working directory must be absolute.");let V;try{V=k(H)}catch{throw new Q("pty_cwd_invalid","Reason terminal working directory does not exist.")}if(!o(z,V))throw new Q("pty_cwd_outside_root","Reason terminal working directory escapes the granted root.");if(!s(V).isDirectory())throw new Q("pty_cwd_invalid","Reason terminal working directory is not a directory.");return V}function t(z=process.env){let H=z.SHELL;if(H&&y(H)&&B(H))return H;for(let V of p()==="darwin"?["/bin/zsh","/bin/bash","/bin/sh"]:["/bin/bash","/bin/sh"])if(B(V))return V;return"/bin/sh"}function e(){let z=globalThis.Bun;if(!z)throw new Q("pty_unavailable","Reason terminals require the Bun runtime.");return z.spawn}function Dz(){return typeof globalThis.Bun<"u"}var zz=(z)=>{let H=e()({cmd:[z.shell,"-i","-l"],cwd:z.cwd,env:{...z.environment,TERM:"xterm-256color"},terminal:{cols:z.cols,rows:z.rows,data:(J,j)=>{z.onData(j)}}}),V=H.terminal;if(!V){try{H.kill()}catch{}throw new Q("pty_unavailable","Reason could not allocate a pseudo-terminal.")}return{write:(J)=>V.write(J),resize:(J,j)=>V.resize(J,j),kill:()=>{try{H.kill()}catch{}},exited:H.exited.then((J)=>typeof J==="number"?J:null,()=>null)}},Hz=(z,H)=>{return H===void 0?new WebSocket(z):new WebSocket(z,{proxy:H})},S=new Set;function Jz(z){if(S.size>=l||S.has(z))return null;S.add(z);let H=!1;return()=>{if(H)return;H=!0,S.delete(z)}}async function Kz(z,H={}){let V=H.now??Date.now,J=n(z.payload,V()),j=Jz(z.operationId);if(!j)throw new Q("pty_slot_busy","This Reason Device already runs the maximum number of terminals.");let Y=V(),C,D,R;try{let Z=J.workspace?h(z.root,J.workspace):void 0;C=Z?U(B(Z.boundary)?k(Z.boundary):Z.boundary,Z.path):U(z.root,J.cwd),D=H.environment??process.env,R=H.shellPath??t(D)}catch(Z){throw j(),Z}return await new Promise((Z,L)=>{let X=null,W=null,M=!1,f=!1,K=!1,T=null,_=0,b=0,O=[],P=0,g=null,$=(N)=>{if(K)return;if(K=!0,g)clearTimeout(g);z.signal.removeEventListener("abort",I);try{X?.kill()}catch{}try{W?.close(1000,"pty_session_over")}catch{}if(j(),N.kind==="rejected"){L(N.error);return}let G={reason:N.reason,exit_code:T,output_bytes:_,input_bytes:b,duration_ms:Math.max(0,V()-Y)};z.emitEvent("pty.stopped",{...G}).catch(()=>{return}),Z({...G})},I=()=>{let N=z.signal.reason;$({kind:"rejected",error:N instanceof Q?N:new Q("cancelled","Reason closed the terminal session.")})};if(z.signal.aborted){I();return}z.signal.addEventListener("abort",I,{once:!0}),g=setTimeout(()=>$({kind:"resolved",reason:"session_expired"}),Math.max(1,Date.parse(J.expires_at)-V()));let i=(N)=>{if(_+=N.byteLength,!M||!W){if(O.push(N),P+=N.byteLength,P>A)$({kind:"resolved",reason:"output_backpressure"});return}try{W.send(N)}catch{$({kind:"resolved",reason:"relay_closed"});return}if(W.bufferedAmount>A)$({kind:"resolved",reason:"output_backpressure"})};try{X=(H.spawnPty??zz)({shell:R,args:["-i","-l"],cwd:C,cols:J.cols,rows:J.rows,environment:D,onData:(N)=>{if(!K)i(N)}})}catch(N){$({kind:"rejected",error:N instanceof Q?N:new Q("pty_spawn_failed","Reason could not start the terminal shell.")});return}X.exited.then((N)=>{if(K)return;if(T=N,M&&W)try{W.send(JSON.stringify({t:"exit",code:N}))}catch{}$({kind:"resolved",reason:"shell_exited"})});let c=(H.loadProxy??m)()?.url;try{W=(H.connect??Hz)(J.relay_url,c)}catch{$({kind:"rejected",error:new Q("pty_relay_unavailable","Reason could not reach the terminal relay.")});return}W.binaryType="arraybuffer",W.onopen=()=>{if(K||!W)return;M=!0;try{W.send(JSON.stringify({t:"open",cols:J.cols,rows:J.rows}));for(let N of O.splice(0))W.send(N);P=0}catch{$({kind:"resolved",reason:"relay_closed"});return}f=!0,z.emitEvent("pty.ready",{session_id:J.session_id,cols:J.cols,rows:J.rows}).catch(()=>{return})},W.onmessage=(N)=>{if(K||!X)return;let G=N.data;if(typeof G==="string"){let F;try{F=JSON.parse(G)}catch{return}if(!v(F))return;if(F.t==="resize"){try{X.resize(q(F.cols,J.cols),q(F.rows,J.rows))}catch{}return}if(F.t==="close")$({kind:"resolved",reason:"client_closed"});return}let E=G instanceof ArrayBuffer?new Uint8Array(G):ArrayBuffer.isView(G)?new Uint8Array(G.buffer,G.byteOffset,G.byteLength):null;if(!E||E.byteLength===0)return;b+=E.byteLength;try{X.write(E)}catch{}},W.onclose=()=>{if(K)return;if(!f){$({kind:"rejected",error:new Q("pty_relay_unavailable","Reason could not reach the terminal relay.")});return}$({kind:"resolved",reason:"relay_closed"})},W.onerror=()=>{if(K||f)return;$({kind:"rejected",error:new Q("pty_relay_unavailable","Reason could not reach the terminal relay.")})}})}
|
|
3
|
+
export{r as ag,A as bg,l as cg,n as dg,U as eg,t as fg,Dz as gg,zz as hg,Hz as ig,Kz as jg};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
3
|
-
export{O as
|
|
2
|
+
import{uj as $}from"./vm-hands-entry-lite-jc229h5p.js";var O=$.version,Z=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;function S(B,D){if(!Z.test(B)||!Z.test(D))throw Error("cannot compare invalid CLI versions");let J=(q)=>{let y=q.indexOf("-");return y===-1?[q,void 0]:[q.slice(0,y),q.slice(y+1)]},[j,F]=J(B),[w,G]=J(D),K=j.split(".").map(BigInt),M=w.split(".").map(BigInt);for(let q=0;q<3;q+=1){if(K[q]===M[q])continue;return K[q]<M[q]?-1:1}if(F===void 0||G===void 0){if(F===G)return 0;return F===void 0?1:-1}let Q=F.split("."),U=G.split("."),A=Math.max(Q.length,U.length);for(let q=0;q<A;q+=1){let y=Q[q],z=U[q];if(y===void 0||z===void 0){if(y===z)return 0;return y===void 0?-1:1}if(y===z)continue;let H=/^\d+$/.test(y),W=/^\d+$/.test(z);if(H&&W){let X=BigInt(y),Y=BigInt(z);if(X===Y)continue;return X<Y?-1:1}if(H!==W)return H?-1:1;return y<z?-1:1}return 0}function k(B,D){return D?`cli ${B} \xB7 agent ${D}`:`cli ${B}`}
|
|
3
|
+
export{O as qj,Z as rj,S as sj,k as tj};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
3
|
-
export{Q as
|
|
2
|
+
import{$i as X,bj as Y,dj as Z}from"./vm-hands-entry-lite-dqnhebfx.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 Si,O as Ti,_ as Ui,b as Vi,g as Wi};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{de as p,fe as V,ie as f}from"./vm-hands-entry-lite-cety9pka.js";import{_h as E}from"./vm-hands-entry-lite-p1nb6n3r.js";import{oi as y}from"./vm-hands-entry-lite-4xfs7y6w.js";import{Bi as m,Pi as w,Ri as u}from"./vm-hands-entry-lite-3tf5zyba.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("<","<").replaceAll(">",">").replaceAll(""",'"').replaceAll("'","'").replaceAll("&","&")}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("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}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 Gd,jz as Hd,Iz as Id,q as Jd,bz as Kd,Sz as Ld,_z as Md,l as Nd,xz as Od,Rz as Pd,x as Qd,Lz as Rd,kz as Sd,yz as Td,Ez as Ud,mz as Vd,uz as Wd,pz as Xd};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{ej as f}from"./vm-hands-entry-lite-dqnhebfx.js";var j=["Click browser element","Double click browser element","Type text","Clear browser field","Press key","Scroll browser element into view","Drag on computer","Select browser option","Check browser control","Uncheck browser control","Hover browser element","Focus browser element","Open browser page","Reload browser page","Go back in browser","Go forward in browser","Take browser screenshot"],$A=32;function R(x){if(!Array.isArray(x)||x.length>32||!x.every((A)=>typeof A==="string"&&j.includes(A)))return;return x.slice()}var KA="__ARA_PI_TOOL_CONFINED_SCRIPT_5f0c9e2a__",QA=262144;function Y(x){if(!x||typeof x!=="object"||Array.isArray(x))return!1;let A=x,W=Object.keys(A);return W.length===2&&W.includes("template")&&W.includes("quoteDepth")&&typeof A.template==="string"&&A.template.length<=262144&&!A.template.includes("\x00")&&A.template.split("__ARA_PI_TOOL_CONFINED_SCRIPT_5f0c9e2a__").length===2&&(A.quoteDepth===1||A.quoteDepth===2||A.quoteDepth===3)}var I=2,b=33554432,K=200000,D=4000000,_=240000,YA=`
|
|
3
3
|
...[executor output truncated]`,p=2000,k=1,i=16384,d=32768,y=128,LA=64,s=2097152,H=1,m=16384,c=32768,OA=8388608,n=1000,t=2500,r=2000,zA=t+r,o=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$/,v=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,l={text_only:4430,invalid_json:4431,invalid_cancel_request:4432,invalid_sdk_response:4433,claim_required:4434,invalid_claim:4435,executor_mismatch:4436,stale_generation:4437,fence_conflict:4438,frame_too_large:4439,result_too_large:4440,progress_too_large:4441,terminal_cleanup_started:4442,job_journal_unavailable:4443},u=new Map(Object.entries(l).map(([x,A])=>[A,x]));function SA(x,A){return A||(u.get(x)??"")}var a=["cancelled","command_failed","duplicate_request_id","duplicate_result_evicted","invalid_repl_response","invalid_request","process_group_cleanup_unconfirmed","repl_failed","result_too_large","repl_response_too_large","repl_transport_failed","request_ledger_full","request_journal_unavailable","request_outcome_uncertain","maintenance_held","request_not_found","resume_digest_mismatch","spawn_failed","stale_generation","timeout"],e=new Set(a),w=16384,AA=200,xA=2000,WA=["maintenance_held","invalid_job_request","jobs_disabled","job_not_found","job_conflict","job_capacity","job_journal_unavailable","job_not_running","job_lease_expired","job_input_sequence","job_input_backpressure","stale_generation","pty_unsupported","job_mode_mismatch"];class G extends Error{code;constructor(x){super(x);this.name="HandsProtocolError",this.code=x}}function g(x){return new TextEncoder().encode(x).byteLength}function U(x){return typeof x==="object"&&x!==null&&!Array.isArray(x)}function B(x,A){let W=new Set(A);return Object.keys(x).every((N)=>W.has(N))}function M(x){return typeof x==="string"&&o.test(x)}function Z(x){return Number.isSafeInteger(x)&&Number(x)>=1}function J(x){return typeof x==="string"&&v.test(x)}function C(x){return typeof x==="string"&&x.startsWith("pty-")&&J(x.slice(4))}function z(x){return[x.cols,x.rows].every((A)=>Number.isSafeInteger(A)&&Number(A)>=1&&Number(A)<=n)}function E(x){if(typeof x!=="string"||x.length>Math.ceil(m/3)*4||x.length%4!==0||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(x))return-1;let A=x.endsWith("==")?2:x.endsWith("=")?1:0;if(A&&"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(x[x.length-A-1])&(A===2?15:3))return-1;let N=x.length/4*3-A;return N<=m?N:-1}function S(x){return typeof x==="string"&&/^[0-9a-f]{64}$/.test(x)}function $(x){if(g(x)>b)throw new G("frame_too_large");try{return JSON.parse(x)}catch{throw new G("invalid_json")}}function BA(x){let A=$(x);if(!U(A)||!B(A,["version","generation","id","tool","input","semanticDigest","lifecycleLeaseId","workspaceBefore"])||A.version!==I||!Z(A.generation)||!M(A.id)||!["bash","repl","resume","read","edit","write","pi_tool"].includes(String(A.tool))||!U(A.input)||A.lifecycleLeaseId!==void 0&&(A.tool!=="bash"||!J(A.lifecycleLeaseId))||A.workspaceBefore!==void 0&&(!(A.tool==="bash"||A.tool==="repl"||A.tool==="pi_tool"&&A.input.tool==="bash")||!U(A.workspaceBefore)||!B(A.workspaceBefore,["script"])||typeof A.workspaceBefore.script!=="string"||A.workspaceBefore.script.length>K))throw new G("invalid_request");let W=U(A.workspaceBefore)&&typeof A.workspaceBefore.script==="string"?{workspaceBefore:{script:A.workspaceBefore.script}}:{};if(A.tool==="bash"){if(!B(A.input,["script","retainBackground","machineSdk"])||typeof A.input.script!=="string"||A.input.script.length>K||A.input.retainBackground!==void 0&&A.input.retainBackground!==!0||A.input.machineSdk!==void 0&&A.input.machineSdk!==!0||A.semanticDigest!==void 0&&!S(A.semanticDigest))throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"bash",input:{script:A.input.script,...A.input.retainBackground===!0?{retainBackground:!0}:{},...A.input.machineSdk===!0?{machineSdk:!0}:{}},...A.semanticDigest===void 0?{}:{semanticDigest:A.semanticDigest},...A.lifecycleLeaseId===void 0?{}:{lifecycleLeaseId:A.lifecycleLeaseId},...W}}if(A.tool==="resume"){if(A.semanticDigest!==void 0||!B(A.input,["semanticDigest"])||!S(A.input.semanticDigest))throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"resume",input:{semanticDigest:A.input.semanticDigest}}}if(A.tool==="repl"){if(!B(A.input,["code"])||typeof A.input.code!=="string"||A.input.code.length>K||A.semanticDigest!==void 0)throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"repl",input:{code:A.input.code},...W}}if(A.tool==="pi_tool"){let N=A.semanticDigest===void 0?GA(A.input):null;if(!N)throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"pi_tool",input:N,...W}}if(A.tool==="read"){if(!B(A.input,["path","offset","limit"])||typeof A.input.path!=="string"||A.input.path.length<1||A.input.path.length>K||A.semanticDigest!==void 0||A.input.offset!==void 0&&(!Number.isSafeInteger(A.input.offset)||Number(A.input.offset)<1)||A.input.limit!==void 0&&(!Number.isSafeInteger(A.input.limit)||Number(A.input.limit)<1||Number(A.input.limit)>2000))throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"read",input:{path:A.input.path,...A.input.offset===void 0?{}:{offset:Number(A.input.offset)},...A.input.limit===void 0?{}:{limit:Number(A.input.limit)}}}}if(A.tool==="edit"){if(!B(A.input,["path","edits"])||typeof A.input.path!=="string"||A.input.path.length<1||!Array.isArray(A.input.edits)||A.input.edits.length<1||A.input.edits.length>128||A.semanticDigest!==void 0)throw new G("invalid_request");let N=A.input.path.length,X=[];for(let V of A.input.edits){if(!U(V)||!B(V,["oldText","newText"])||typeof V.oldText!=="string"||V.oldText.length<1||typeof V.newText!=="string")throw new G("invalid_request");if(N+=V.oldText.length+V.newText.length,N>D)throw new G("invalid_request");X.push({oldText:V.oldText,newText:V.newText})}return{version:I,generation:A.generation,id:A.id,tool:"edit",input:{path:A.input.path,edits:X}}}if(A.tool!=="write"||!B(A.input,["path","content"])||typeof A.input.path!=="string"||A.input.path.length<1||typeof A.input.content!=="string"||A.input.path.length+A.input.content.length>D||A.semanticDigest!==void 0)throw new G("invalid_request");return{version:I,generation:A.generation,id:A.id,tool:"write",input:{path:A.input.path,content:A.input.content}}}function L(x){return x===void 0||typeof x==="number"&&Number.isFinite(x)}function GA(x){let A=x.args;if(!B(x,["tool","args"])||!U(A))return null;if(x.tool==="bash")return B(A,["command","timeout"])&&typeof A.command==="string"&&A.command.length<=K&&L(A.timeout)?{tool:"bash",args:{command:A.command,...A.timeout===void 0?{}:{timeout:Number(A.timeout)}}}:null;if(typeof A.path!=="string"||A.path.length>K)return null;if(x.tool==="read")return B(A,["path","offset","limit"])&&L(A.offset)&&L(A.limit)?{tool:"read",args:{path:A.path,...A.offset===void 0?{}:{offset:Number(A.offset)},...A.limit===void 0?{}:{limit:Number(A.limit)}}}:null;if(x.tool==="write")return B(A,["path","content"])&&typeof A.content==="string"&&A.path.length+A.content.length<=D?{tool:"write",args:{path:A.path,content:A.content}}:null;if(x.tool!=="edit"||!B(A,["path","edits"])||!Array.isArray(A.edits))return null;let W=A.path.length,N=[];for(let X of A.edits){if(!U(X)||!B(X,["oldText","newText"])||typeof X.oldText!=="string"||typeof X.newText!=="string")return null;if(W+=X.oldText.length+X.newText.length,W>D)return null;N.push({oldText:X.oldText,newText:X.newText})}return{tool:"edit",args:{path:A.path,edits:N}}}function NA(x){if(!U(x))return null;if("thrown"in x)return B(x,["thrown"])&&typeof x.thrown==="string"?{thrown:x.thrown}:null;let A=x.structuredContent;if(!B(x,["content","details","structuredContent","isError"])||!Array.isArray(x.content)||x.isError!==void 0&&x.isError!==!0||A!==void 0&&(!U(A)||!B(A,["output","truncated","full_output_path","exit_code","wall_time_seconds"])||typeof A.output!=="string"||typeof A.truncated!=="boolean"||A.full_output_path!==void 0&&typeof A.full_output_path!=="string"||typeof A.exit_code!=="number"||typeof A.wall_time_seconds!=="number"))return null;let W=[];for(let N of x.content)if(U(N)&&N.type==="text"&&B(N,["type","text"])&&typeof N.text==="string")W.push({type:"text",text:N.text});else if(U(N)&&N.type==="image"&&B(N,["type","data","mimeType"])&&typeof N.data==="string"&&typeof N.mimeType==="string")W.push({type:"image",data:N.data,mimeType:N.mimeType});else return null;return{content:W,...x.details===void 0?{}:{details:x.details},...U(A)?{structuredContent:{output:String(A.output),truncated:A.truncated===!0,...typeof A.full_output_path==="string"?{full_output_path:A.full_output_path}:{},exit_code:Number(A.exit_code),wall_time_seconds:Number(A.wall_time_seconds)}}:{},...x.isError===!0?{isError:!0}:{}}}function UA(x){let A=$(x);if(!U(A)||!B(A,["version","generation","id","ok","exitCode","stdout","stderr","cwd","error","resumed","browserActions","automaticProgressImage","piToolOutcome","workerElapsedMs","environmentWaitMs","workspaceBefore"])||A.version!==I||!Z(A.generation)||!M(A.id)||typeof A.ok!=="boolean"||!Number.isSafeInteger(A.exitCode)||Number(A.exitCode)<0||Number(A.exitCode)>255||typeof A.stdout!=="string"||A.stdout.length>_||typeof A.stderr!=="string"||A.stderr.length>_||A.cwd!==void 0&&(typeof A.cwd!=="string"||A.cwd.length<1||A.cwd.length>4096||!A.cwd.startsWith("/")||A.cwd.includes("\x00"))||A.error!==void 0&&(typeof A.error!=="string"||A.error.length<1||A.error.length>p||!e.has(A.error))||A.browserActions!==void 0&&!R(A.browserActions)||A.automaticProgressImage!==void 0&&(A.automaticProgressImage!==!0||!A.ok)||A.resumed!==void 0&&A.resumed!==!0||A.workerElapsedMs!==void 0&&(!Number.isSafeInteger(A.workerElapsedMs)||Number(A.workerElapsedMs)<0)||A.environmentWaitMs!==void 0&&(!Number.isSafeInteger(A.environmentWaitMs)||Number(A.environmentWaitMs)<0)||A.workspaceBefore!==void 0&&!h(A.workspaceBefore)||A.ok&&(A.exitCode!==0||A.error!==void 0)||!A.ok&&A.exitCode===0)throw new G("invalid_result");let W=A.piToolOutcome===void 0?void 0:NA(A.piToolOutcome);if(W===null||W&&!A.ok)throw new G("invalid_result");return{version:I,generation:A.generation,id:A.id,ok:A.ok,exitCode:Number(A.exitCode),stdout:A.stdout,stderr:A.stderr,...typeof A.cwd==="string"?{cwd:A.cwd}:{},...A.browserActions!==void 0?{browserActions:R(A.browserActions)}:{},...typeof A.error==="string"?{error:A.error}:{},...A.automaticProgressImage===!0?{automaticProgressImage:!0}:{},...A.resumed===!0?{resumed:!0}:{},...W?{piToolOutcome:W}:{},...A.workerElapsedMs!==void 0?{workerElapsedMs:Number(A.workerElapsedMs)}:{},...A.environmentWaitMs!==void 0?{environmentWaitMs:Number(A.environmentWaitMs)}:{},...h(A.workspaceBefore)?{workspaceBefore:{exitCode:A.workspaceBefore.exitCode,stdout:A.workspaceBefore.stdout,stderr:A.workspaceBefore.stderr}}:{}}}function h(x){return U(x)&&B(x,["exitCode","stdout","stderr"])&&Number.isSafeInteger(x.exitCode)&&Number(x.exitCode)>=0&&Number(x.exitCode)<=255&&typeof x.stdout==="string"&&x.stdout.length<=w&&typeof x.stderr==="string"&&x.stderr.length<=w}function FA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","id","sequence","stdout","stderr"])||A.type!=="progress"||A.version!==I||!Z(A.generation)||!M(A.id)||!Number.isSafeInteger(A.sequence)||Number(A.sequence)<1||typeof A.stdout!=="string"||A.stdout.length>_||typeof A.stderr!=="string"||A.stderr.length>_)throw new G("invalid_progress");return{type:"progress",version:I,generation:Number(A.generation),id:A.id,sequence:Number(A.sequence),stdout:A.stdout,stderr:A.stderr}}function IA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","fenceId","executorLaunchId","requestCancelVersion","managedJobsVersion","browserRunEnvelopeVersion","terminalCleanupVersion","guestMemoryVersion","guestMemoryDiagnosticsVersion","piToolsVersion","piToolsConfinement","backgroundBashVersion","machineSdkVersion","executionTimingVersion","environmentWaitVersion","workspaceBeforeVersion"])||A.type!=="claim"||A.version!==I||!Z(A.generation)||!J(A.fenceId)||!J(A.executorLaunchId)||A.requestCancelVersion!==void 0&&A.requestCancelVersion!==1||A.managedJobsVersion!==void 0&&A.managedJobsVersion!==k||A.guestMemoryVersion!==void 0&&A.guestMemoryVersion!==1||A.guestMemoryDiagnosticsVersion!==void 0&&(A.guestMemoryDiagnosticsVersion!==1||A.guestMemoryVersion!==1)||A.terminalCleanupVersion!==void 0&&A.terminalCleanupVersion!==1||A.browserRunEnvelopeVersion!==void 0&&A.browserRunEnvelopeVersion!==1||A.piToolsVersion!==void 0&&A.piToolsVersion!==1||A.piToolsConfinement!==void 0&&(!Y(A.piToolsConfinement)||A.piToolsVersion!==1)||A.backgroundBashVersion!==void 0&&A.backgroundBashVersion!==1||A.machineSdkVersion!==void 0&&A.machineSdkVersion!==1||A.executionTimingVersion!==void 0&&A.executionTimingVersion!==1||A.environmentWaitVersion!==void 0&&(A.environmentWaitVersion!==1||A.executionTimingVersion!==1)||A.workspaceBeforeVersion!==void 0&&A.workspaceBeforeVersion!==1)throw new G("invalid_claim");return{type:"claim",version:I,generation:A.generation,fenceId:A.fenceId,executorLaunchId:A.executorLaunchId,...A.requestCancelVersion===1?{requestCancelVersion:1}:{},...A.managedJobsVersion===1?{managedJobsVersion:1}:{},...A.guestMemoryVersion===1?{guestMemoryVersion:1}:{},...A.guestMemoryDiagnosticsVersion===1?{guestMemoryDiagnosticsVersion:1}:{},...A.terminalCleanupVersion===1?{terminalCleanupVersion:1}:{},...A.browserRunEnvelopeVersion===1?{browserRunEnvelopeVersion:1}:{},...A.piToolsVersion===1?{piToolsVersion:1}:{},...Y(A.piToolsConfinement)?{piToolsConfinement:{template:A.piToolsConfinement.template,quoteDepth:A.piToolsConfinement.quoteDepth}}:{},...A.backgroundBashVersion===1?{backgroundBashVersion:1}:{},...A.machineSdkVersion===1?{machineSdkVersion:1}:{},...A.executionTimingVersion===1?{executionTimingVersion:1}:{},...A.environmentWaitVersion===1?{environmentWaitVersion:1}:{},...A.workspaceBeforeVersion===1?{workspaceBeforeVersion:1}:{}}}function XA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","fenceId","executorLaunchId","workerVersion","workerArtifactSha256","requestCancelVersion","managedJobsVersion","lifecycleVersion","browserRunEnvelopeVersion","terminalCleanupVersion","guestMemoryVersion","guestMemoryDiagnosticsVersion","piToolsVersion","piToolsConfinementVersion","backgroundBashVersion","machineSdkVersion","executionTimingVersion","environmentWaitVersion","workspaceBeforeVersion"])||A.lifecycleVersion!==void 0&&A.lifecycleVersion!==1||A.workspaceBeforeVersion!==void 0&&A.workspaceBeforeVersion!==1||A.piToolsVersion!==void 0&&A.piToolsVersion!==1||A.piToolsConfinementVersion!==void 0&&(A.piToolsConfinementVersion!==1||A.piToolsVersion!==1)||A.backgroundBashVersion!==void 0&&A.backgroundBashVersion!==1||A.machineSdkVersion!==void 0&&A.machineSdkVersion!==1||A.executionTimingVersion!==void 0&&A.executionTimingVersion!==1||A.environmentWaitVersion!==void 0&&(A.environmentWaitVersion!==1||A.executionTimingVersion!==1)||A.guestMemoryVersion!==void 0&&A.guestMemoryVersion!==1||A.guestMemoryDiagnosticsVersion!==void 0&&(A.guestMemoryDiagnosticsVersion!==1||A.guestMemoryVersion!==1)||A.terminalCleanupVersion!==void 0&&A.terminalCleanupVersion!==1||A.browserRunEnvelopeVersion!==void 0&&A.browserRunEnvelopeVersion!==1||A.type!=="claim_ack"||A.version!==I||!Z(A.generation)||!J(A.fenceId)||!J(A.executorLaunchId)||!Number.isSafeInteger(A.workerVersion)||Number(A.workerVersion)<1||!S(A.workerArtifactSha256)||A.requestCancelVersion!==void 0&&A.requestCancelVersion!==1||A.managedJobsVersion!==void 0&&A.managedJobsVersion!==k)throw new G("invalid_claim_ack");return{type:"claim_ack",...A.guestMemoryVersion===1?{guestMemoryVersion:1}:{},...A.guestMemoryDiagnosticsVersion===1?{guestMemoryDiagnosticsVersion:1}:{},...A.terminalCleanupVersion===1?{terminalCleanupVersion:1}:{},...A.browserRunEnvelopeVersion===1?{browserRunEnvelopeVersion:1}:{},...A.lifecycleVersion===1?{lifecycleVersion:1}:{},...A.piToolsVersion===1?{piToolsVersion:1}:{},...A.piToolsConfinementVersion===1?{piToolsConfinementVersion:1}:{},...A.backgroundBashVersion===1?{backgroundBashVersion:1}:{},...A.machineSdkVersion===1?{machineSdkVersion:1}:{},...A.executionTimingVersion===1?{executionTimingVersion:1}:{},...A.environmentWaitVersion===1?{environmentWaitVersion:1}:{},...A.workspaceBeforeVersion===1?{workspaceBeforeVersion:1}:{},version:I,generation:A.generation,fenceId:A.fenceId,executorLaunchId:A.executorLaunchId,workerVersion:Number(A.workerVersion),workerArtifactSha256:A.workerArtifactSha256,...A.requestCancelVersion===1?{requestCancelVersion:1}:{},...A.managedJobsVersion===1?{managedJobsVersion:1}:{}}}function TA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","id","jobId","action","input"])||A.type!=="job"||A.version!==I||!Z(A.generation)||!M(A.id)||!M(A.jobId)||!U(A.input))throw new G("invalid_job_request");let W=A.input,N=Number.isSafeInteger(W.leaseExpiresAtMs)&&Number(W.leaseExpiresAtMs)>0,X=Number.isSafeInteger(W.sequence)&&Number(W.sequence)>=1;if(!(A.action==="start"?W.mode==="pty"?B(W,["mode","cols","rows","leaseExpiresAtMs"])&&C(A.jobId)&&z(W)&&N:B(W,["script","leaseExpiresAtMs"])&&typeof W.script==="string"&&W.script.length<=K&&N:A.action==="inspect"?B(W,["after"])&&Number.isSafeInteger(W.after)&&Number(W.after)>=0:A.action==="input"?"dataBase64"in W?B(W,["sequence","dataBase64"])&&C(A.jobId)&&X&&E(W.dataBase64)>0:B(W,["sequence","data","eof"])&&X&&typeof W.data==="string"&&W.data.length<=i&&typeof W.eof==="boolean":A.action==="resize"?B(W,["sequence","cols","rows"])&&C(A.jobId)&&X&&z(W):A.action==="renew"?B(W,["leaseExpiresAtMs"])&&N:A.action==="cancel"&&B(W,[])))throw new G("invalid_job_request");return A}function MA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","id","ok","job","error"])||A.type!=="job_result"||A.version!==I||!Z(A.generation)||!M(A.id))throw new G("invalid_job_result");if(A.ok===!1&&A.job===void 0&&typeof A.error==="string"&&WA.some((F)=>F===A.error))return A;let W=A.job;if(A.ok!==!0||A.error!==void 0||!U(W)||!B(W,["jobId","state","startedAtMs","finishedAtMs","leaseExpiresAtMs","exitCode","inputSequence","output","firstCursor","nextCursor","truncated","process","environmentRevision","environmentSnapshotId","pty"])||!M(W.jobId)||!["starting","running","exited","cancelled","expired","uncertain"].includes(String(W.state))||!Number.isSafeInteger(W.startedAtMs)||Number(W.startedAtMs)<1||!Number.isSafeInteger(W.leaseExpiresAtMs)||Number(W.leaseExpiresAtMs)<1||W.finishedAtMs!==null&&(!Number.isSafeInteger(W.finishedAtMs)||Number(W.finishedAtMs)<Number(W.startedAtMs))||W.exitCode!==null&&(!Number.isSafeInteger(W.exitCode)||Number(W.exitCode)<0||Number(W.exitCode)>255)||!Number.isSafeInteger(W.inputSequence)||Number(W.inputSequence)<0||!Number.isSafeInteger(W.firstCursor)||Number(W.firstCursor)<1||!Number.isSafeInteger(W.nextCursor)||Number(W.nextCursor)<Number(W.firstCursor)-1||typeof W.truncated!=="boolean"||!Array.isArray(W.output)||W.output.length>y)throw new G("invalid_job_result");if(W.environmentRevision===void 0!==(W.environmentSnapshotId===void 0)||W.environmentRevision!==void 0&&(!Number.isSafeInteger(W.environmentRevision)||Number(W.environmentRevision)<1||!J(W.environmentSnapshotId)))throw new G("invalid_job_result");let N=Number(W.firstCursor)-1,X=0;for(let F of W.output){if(!U(F)||!B(F,["cursor","stream","text"])||!Number.isSafeInteger(F.cursor)||Number(F.cursor)<=N||Number(F.cursor)>Number(W.nextCursor)||!["stdout","stderr"].includes(String(F.stream))||typeof F.text!=="string")throw new G("invalid_job_result");X+=F.text.length,N=Number(F.cursor)}if(X>d)throw new G("invalid_job_result");let V=W.state==="starting"||W.state==="running";if(V&&(W.finishedAtMs!==null||W.exitCode!==null)||!V&&W.finishedAtMs===null||W.state==="uncertain"&&W.exitCode!==null||W.state==="exited"&&W.exitCode===null||W.state==="cancelled"&&W.exitCode!==130||W.state==="expired"&&W.exitCode!==124)throw new G("invalid_job_result");if(W.process!==void 0){let F=W.process;if(!U(F)||!B(F,["pid","processGroupId","executorLaunchId"])||!Number.isSafeInteger(F.pid)||Number(F.pid)<1||F.processGroupId!==F.pid||!J(F.executorLaunchId)||!["starting","running"].includes(String(W.state)))throw new G("invalid_job_result")}if(W.pty!==void 0){let F=W.pty;if(!U(F)||!B(F,["version","cols","rows","output","cleanup"])||F.version!==H||!C(W.jobId)||!z(F)||W.output.length!==0||!Array.isArray(F.output)||F.output.length>y||(V?F.cleanup!=="pending":W.state==="uncertain"?F.cleanup!=="unconfirmed":F.cleanup!=="confirmed")||W.state==="running"&&(W.process===void 0||W.environmentRevision===void 0))throw new G("invalid_job_result");let T=Number(W.firstCursor)-1,P=0;for(let Q of F.output){if(!U(Q)||!B(Q,["cursor","dataBase64"])||!Number.isSafeInteger(Q.cursor)||Number(Q.cursor)<=T||Number(Q.cursor)>Number(W.nextCursor))throw new G("invalid_job_result");let q=E(Q.dataBase64);if(q<=0||(P+=q)>c)throw new G("invalid_job_result");T=Number(Q.cursor)}}return A}function qA(x){if(g(x)>s)throw new G("frame_too_large");let A=$(x);if(!U(A)||!B(A,["version","sessionId","operationId","runId","deviceId","rootId","workspace","binding","targetRevision","rootGrantRevision","generation","fenceId","executorLaunchId","job"])||A.version!==H||![A.sessionId,A.operationId,A.runId].every(M)||![A.deviceId,A.rootId,A.fenceId,A.executorLaunchId].every(J)||!Z(A.generation)||!Number.isSafeInteger(A.rootGrantRevision)||Number(A.rootGrantRevision)<1||!["workspace_source","mcp_control"].includes(String(A.binding))||!Number.isSafeInteger(A.targetRevision)||Number(A.targetRevision)<0||A.binding==="workspace_source"&&A.targetRevision!==0||!U(A.workspace))throw new G("invalid_pty_receipt");if(!f(A.workspace))throw new G("invalid_pty_receipt");let W=MA(JSON.stringify({type:"job_result",version:I,generation:A.generation,id:A.operationId,ok:!0,job:A.job}));if(!W.ok||!W.job.pty||W.job.pty.output.length!==0||W.job.process&&W.job.process.executorLaunchId!==A.executorLaunchId)throw new G("invalid_pty_receipt");return A}function yA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","id","targetId"])||A.type!=="cancel_request"||A.version!==I||!Z(A.generation)||!M(A.id)||!M(A.targetId))throw new G("invalid_cancel_request");return A}function mA(x){let A=$(x);if(!U(A)||!B(A,["type","version","generation","id","targetId","status"])||A.type!=="cancel_ack"||A.version!==I||!Z(A.generation)||!M(A.id)||!M(A.targetId)||!["cancelled","settled","not_found","unsupported","unconfirmed"].includes(String(A.status)))throw new G("invalid_cancel_ack");return A}function wA(x){let A=JSON.stringify(x);return BA(A),A}function hA(x){let A=JSON.stringify(x);return UA(A),A}function fA(x){let A=JSON.stringify(x);return FA(A),A}function kA(x){let A=JSON.stringify(x);return IA(A),A}function HA(x){let A=JSON.stringify(x);return XA(A),A}function O(x){return typeof x==="string"&&x.length>=1&&x.length<=AA&&!x.includes("\x00")}function VA(x){let A=["type","version","generation","id","jobRequestId","verb"];if(x.verb==="help")return B(x,A)?{verb:"help"}:null;if(x.verb==="describe"||x.verb==="namespace")return B(x,[...A,"name"])&&O(x.name)?{verb:x.verb,name:x.name}:null;if(x.verb==="search"){let W=x.args;if(!B(x,[...A,"query","args"])||typeof x.query!=="string"||x.query.trim().length<1||x.query.length>xA)return null;if(W===void 0)return{verb:"search",query:x.query};if(!U(W)||!B(W,["namespace","limit"])||W.namespace!==void 0&&!O(W.namespace)||W.limit!==void 0&&(!Number.isSafeInteger(W.limit)||Number(W.limit)<1||Number(W.limit)>50))return null;return{verb:"search",query:x.query,args:{...typeof W.namespace==="string"?{namespace:W.namespace}:{},...W.limit===void 0?{}:{limit:Number(W.limit)}}}}if(x.verb!=="call"||!B(x,[...A,"name","args"])||!O(x.name)||!U(x.args)||JSON.stringify(x.args).length>K)return null;return{verb:"call",name:x.name,args:x.args}}function gA(x){let A=$(x);if(!U(A)||A.type!=="sdk_request"||A.version!==I||!Z(A.generation)||!M(A.id)||!M(A.jobRequestId))throw new G("invalid_sdk_request");let W=VA(A);if(!W)throw new G("invalid_sdk_request");return{type:"sdk_request",version:I,generation:Number(A.generation),id:A.id,jobRequestId:A.jobRequestId,...W}}function ZA(x){let A=$(x);if(!U(A)||A.type!=="sdk_response"||A.version!==I||!Z(A.generation)||!M(A.id))throw new G("invalid_sdk_response");let W={type:"sdk_response",version:I,generation:Number(A.generation),id:A.id},N=["type","version","generation","id","ok"];if(A.ok===!0&&B(A,[...N,"result"])&&typeof A.result==="string"&&A.result.length<=_)return{...W,ok:!0,result:A.result};if(A.ok===!1&&B(A,[...N,"error"])&&typeof A.error==="string"&&A.error.length>=1&&A.error.length<=_)return{...W,ok:!1,error:A.error};throw new G("invalid_sdk_response")}function EA(x){let A=JSON.stringify(x);return ZA(A),A}
|
|
4
|
-
export{$A as
|
|
4
|
+
export{$A as Gg,KA as Hg,QA as Ig,I as Jg,b as Kg,K as Lg,D as Mg,_ as Ng,YA as Og,p as Pg,k as Qg,i as Rg,d as Sg,y as Tg,LA as Ug,s as Vg,H as Wg,m as Xg,c as Yg,OA as Zg,n as _g,t as $g,r as ah,zA as bh,l as ch,SA as dh,a as eh,w as fh,AA as gh,xA as hh,WA as ih,G as jh,M as kh,Z as lh,J as mh,C as nh,S as oh,BA as ph,UA as qh,FA as rh,IA as sh,XA as th,TA as uh,MA as vh,qA as wh,yA as xh,mA as yh,wA as zh,hA as Ah,fA as Bh,kA as Ch,HA as Dh,gA as Eh,ZA as Fh,EA as Gh};
|
|
@@ -0,0 +1,3 @@
|
|
|
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 Yc,W as Zc,X as _c};
|