@reason-machines/cli-linux-x64 0.2.558 → 0.2.560
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-j5f603sy.js +2 -0
- package/bin/vm-hands/api-credentials-7rhpwe7n.js +2 -0
- package/bin/vm-hands/api-vkgf7wma.js +2 -0
- package/bin/vm-hands/ask-relay-2vf6fa2t.js +5 -0
- package/bin/vm-hands/connect-cli-06x1wfgv.js +2 -0
- package/bin/vm-hands/credentials-s7ps7y6s.js +2 -0
- package/bin/vm-hands/custom-endpoint-device-3xnrp33e.js +2 -0
- package/bin/vm-hands/desktop-account-eg8thn79.js +2 -0
- package/bin/vm-hands/device-workspace-h5rsecq8.js +2 -0
- package/bin/vm-hands/{fsevents-fev1pxw2.js → fsevents-vxv56sp5.js} +1 -1
- package/bin/vm-hands/hands-worker-source-vk664w8p.js +2 -0
- package/bin/vm-hands/{index-j6wffzfd.js → index-03p9c17x.js} +106 -106
- package/bin/vm-hands/install-receipt-j04hdw1k.js +2 -0
- package/bin/vm-hands/local-automation-8b1znx0p.js +2 -0
- package/bin/vm-hands/local-capabilities-m6pzcc94.js +2 -0
- package/bin/vm-hands/local-desktop-users-sq4trh07.js +2 -0
- package/bin/vm-hands/local-display-mac-yxcxvg2z.js +2 -0
- package/bin/vm-hands/local-display-session-zyd8s6n6.js +2 -0
- package/bin/vm-hands/local-display-video-rk680vwg.js +2 -0
- package/bin/vm-hands/local-managed-process-w26jhyfg.js +2 -0
- package/bin/vm-hands/local-pty-session-edd8ttf9.js +2 -0
- package/bin/vm-hands/managed-runtime-ykv5nyva.js +2 -0
- package/bin/vm-hands/network-auto-update-mrjz964a.js +3 -0
- package/bin/vm-hands/network-contract-8mxtma3w.js +2 -0
- package/bin/vm-hands/network-sign-in-8yvdx5rm.js +3 -0
- package/bin/vm-hands/package-vwvzjtn0.js +2 -0
- package/bin/vm-hands/permissions-nmxr8238.js +2 -0
- package/bin/vm-hands/reason-hands-protocol-1nkpw1v3.js +2 -0
- package/bin/vm-hands/serve-service-det934tz.js +2 -0
- package/bin/vm-hands/status-fr7192eh.js +96 -0
- package/bin/vm-hands/version-5d6gbmrd.js +2 -0
- package/bin/vm-hands/vm-hands-entry-lite-0as6nsks.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-0ex2twm5.js +4 -0
- package/bin/vm-hands/vm-hands-entry-lite-0wb1n769.js +9 -0
- package/bin/vm-hands/{vm-hands-entry-lite-a3p6xz53.js → vm-hands-entry-lite-2rgf8866.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-4jgykvd3.js +2 -0
- package/bin/vm-hands/vm-hands-entry-lite-52qz0n30.js +7 -0
- package/bin/vm-hands/vm-hands-entry-lite-57ajjwmh.js +2 -0
- package/bin/vm-hands/vm-hands-entry-lite-71ebge0c.js +42 -0
- package/bin/vm-hands/vm-hands-entry-lite-84mc1f7h.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-8pcs85ak.js +105 -0
- package/bin/vm-hands/vm-hands-entry-lite-8w0ah5j9.js +11 -0
- package/bin/vm-hands/vm-hands-entry-lite-8xv6c0rm.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-9g52kxyj.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-a6ss0ges.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-a7bf7xr7.js +5 -0
- package/bin/vm-hands/vm-hands-entry-lite-ab1pq3xg.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-bnpdn6fw.js +127 -0
- package/bin/vm-hands/vm-hands-entry-lite-cspd38hc.js +539 -0
- package/bin/vm-hands/{vm-hands-entry-lite-q1yvw4xz.js → vm-hands-entry-lite-e3fn8ys2.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-f8p11q6h.js +452 -0
- package/bin/vm-hands/{vm-hands-entry-lite-qzkxtymm.js → vm-hands-entry-lite-f95mg81d.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-fhx46jny.js +10 -0
- package/bin/vm-hands/{vm-hands-entry-lite-wptbvtg0.js → vm-hands-entry-lite-fk2s50nc.js} +5 -5
- package/bin/vm-hands/vm-hands-entry-lite-hjjbjpd7.js +4 -0
- package/bin/vm-hands/vm-hands-entry-lite-hs6sdn60.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-hxfxs7r9.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-2v4zh9ze.js → vm-hands-entry-lite-j10cw3d9.js} +9 -9
- package/bin/vm-hands/{vm-hands-entry-lite-rdnm87zp.js → vm-hands-entry-lite-jhsa4av7.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-jpvmkce5.js +2 -0
- package/bin/vm-hands/vm-hands-entry-lite-k5ytpgzz.js +65 -0
- package/bin/vm-hands/{vm-hands-entry-lite-s85p7tqp.js → vm-hands-entry-lite-krpqqx12.js} +2 -2
- package/bin/vm-hands/{vm-hands-entry-lite-q2h781jg.js → vm-hands-entry-lite-ms99mzp0.js} +3 -3
- package/bin/vm-hands/vm-hands-entry-lite-nn6zcvmp.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-46pwqvpf.js → vm-hands-entry-lite-ptycjmkc.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-pxtycfdv.js +5 -0
- package/bin/vm-hands/vm-hands-entry-lite-q3er9m6y.js +9 -0
- package/bin/vm-hands/vm-hands-entry-lite-q9djb28r.js +4 -0
- package/bin/vm-hands/vm-hands-entry-lite-q9s1e2y1.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-qegwyvyz.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-pzj5s203.js → vm-hands-entry-lite-qf990rxw.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite-rhx6adbr.js +52 -0
- package/bin/vm-hands/vm-hands-entry-lite-sy7dcccg.js +2 -0
- package/bin/vm-hands/vm-hands-entry-lite-tcmye5ny.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-tvnfm4xg.js +150 -0
- package/bin/vm-hands/{vm-hands-entry-lite-1yv5qqew.js → vm-hands-entry-lite-v4hr9x9h.js} +45 -45
- package/bin/vm-hands/vm-hands-entry-lite-vdv4nm5f.js +3 -0
- package/bin/vm-hands/vm-hands-entry-lite-weqam12f.js +6 -0
- package/bin/vm-hands/vm-hands-entry-lite-y4df9n3f.js +345 -0
- package/bin/vm-hands/vm-hands-entry-lite-yvws5zpx.js +4 -0
- package/bin/vm-hands/{vm-hands-entry-lite-qd46yhvz.js → vm-hands-entry-lite-z0ht62s4.js} +3 -3
- package/bin/vm-hands/vm-hands-entry-lite-zawytz09.js +3 -0
- package/bin/vm-hands/{vm-hands-entry-lite-h2rq71rj.js → vm-hands-entry-lite-zh6ncdjn.js} +2 -2
- package/bin/vm-hands/vm-hands-entry-lite.js +2 -2
- package/bin/vm-hands/{vm-hands-executor-a6c1j3gp.js → vm-hands-executor-qny3mx8f.js} +8 -8
- package/bin/vm-hands/vm-hands-op-runner-5q01rhkc.js +2 -0
- package/bin/vm-hands/{vm-hands-runtime-t5e8a0mn.js → vm-hands-runtime-gjjm5fzd.js} +3 -3
- package/bin/vm-hands/worker-preview-readiness-06tygyjs.js +2 -0
- package/bin/vm-hands/worker-sandbox-e1cpkzfz.js +2 -0
- package/package.json +1 -1
- package/bin/vm-hands/api-credentials-ds01769g.js +0 -2
- package/bin/vm-hands/api-tfq16a08.js +0 -2
- package/bin/vm-hands/connect-cli-ha9vbajx.js +0 -2
- package/bin/vm-hands/credentials-sbza33ac.js +0 -2
- package/bin/vm-hands/custom-endpoint-device-mydksbg8.js +0 -2
- package/bin/vm-hands/desktop-account-t0afsge2.js +0 -2
- package/bin/vm-hands/device-workspace-b534qy2c.js +0 -2
- package/bin/vm-hands/hands-worker-source-qj7s9dk5.js +0 -2
- package/bin/vm-hands/install-receipt-zv1bjbgh.js +0 -2
- package/bin/vm-hands/local-automation-29f2yk7r.js +0 -2
- package/bin/vm-hands/local-capabilities-1x36d69w.js +0 -2
- package/bin/vm-hands/local-desktop-users-5scb9930.js +0 -2
- package/bin/vm-hands/local-display-mac-pft73te9.js +0 -2
- package/bin/vm-hands/local-display-session-0sbtewn9.js +0 -2
- package/bin/vm-hands/local-display-video-vtd5xa7h.js +0 -2
- package/bin/vm-hands/local-managed-process-jz8h33nx.js +0 -2
- package/bin/vm-hands/local-pty-session-njd0tprg.js +0 -2
- package/bin/vm-hands/managed-runtime-c843ftzx.js +0 -2
- package/bin/vm-hands/network-contract-kx0hz3wt.js +0 -2
- package/bin/vm-hands/package-way7qesn.js +0 -2
- package/bin/vm-hands/permissions-qyfv0m6a.js +0 -2
- package/bin/vm-hands/reason-hands-protocol-g54rtrhd.js +0 -2
- package/bin/vm-hands/serve-service-fjr8vj0t.js +0 -2
- package/bin/vm-hands/status-yfp1ayay.js +0 -10
- package/bin/vm-hands/version-f3kptj80.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-04x5xjt6.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-07apxfh8.js +0 -42
- package/bin/vm-hands/vm-hands-entry-lite-0wsr8edk.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-1bbt37sr.js +0 -452
- package/bin/vm-hands/vm-hands-entry-lite-3gbf905c.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-46zcjqas.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-48rphbjm.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-4anjdcth.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-4rystkgj.js +0 -14
- package/bin/vm-hands/vm-hands-entry-lite-6dk00ch5.js +0 -150
- package/bin/vm-hands/vm-hands-entry-lite-73f4cgkf.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-7cmf6428.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-8dfw96ym.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-97agw762.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-ak0hd94p.js +0 -7
- package/bin/vm-hands/vm-hands-entry-lite-bpamn7ny.js +0 -9
- package/bin/vm-hands/vm-hands-entry-lite-cmfzxk3d.js +0 -126
- package/bin/vm-hands/vm-hands-entry-lite-dgfx0rbn.js +0 -5
- package/bin/vm-hands/vm-hands-entry-lite-efsp2wfz.js +0 -539
- package/bin/vm-hands/vm-hands-entry-lite-fs0bsr5q.js +0 -52
- package/bin/vm-hands/vm-hands-entry-lite-fxzadxz4.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-gje7xvy9.js +0 -6
- package/bin/vm-hands/vm-hands-entry-lite-h1qjggz0.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-n7bd44rm.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-ny6w4vgq.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-ravxhygk.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-tf0qzc0a.js +0 -9
- package/bin/vm-hands/vm-hands-entry-lite-tyem93c1.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-vj7xzb3y.js +0 -2
- package/bin/vm-hands/vm-hands-entry-lite-wf26hjeh.js +0 -105
- package/bin/vm-hands/vm-hands-entry-lite-wghmyfba.js +0 -4
- package/bin/vm-hands/vm-hands-entry-lite-wzv13c8k.js +0 -65
- package/bin/vm-hands/vm-hands-entry-lite-yptpy066.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-yretc2th.js +0 -3
- package/bin/vm-hands/vm-hands-entry-lite-z6znx10m.js +0 -2
- package/bin/vm-hands/vm-hands-op-runner-g81p656v.js +0 -2
- package/bin/vm-hands/worker-preview-readiness-gy36ejp9.js +0 -2
- package/bin/vm-hands/worker-sandbox-f1tfb3y0.js +0 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var
|
|
3
|
-
export{
|
|
2
|
+
var On={name:"github-native-engineer-device-worker-production",version:"0.2.560",private:!0,type:"module",engines:{node:">=22",bun:">=1.3.0"},workspaces:["../../packages/runtime-distribution"],dependencies:{"@agentclientprotocol/sdk":"1.9.0","@anthropic-ai/sandbox-runtime":"^0.0.80","@earendil-works/pi-tui":"1.0.0","@reason/runtime-distribution":"workspace:*",diff:"8.0.4","open-browser-use-sdk":"0.1.42","playwright-core":"1.60.0",toml:"5.0.1",zod:"^4.4.3"},overrides:{"@hono/node-server":"^1.19.15","@earendil-works/pi-agent-core":"1.0.0","@earendil-works/pi-ai":"1.0.0","@earendil-works/pi-coding-agent":"1.0.0","@earendil-works/chord":"1.0.0","@earendil-works/pi-codemode":"1.0.0","@earendil-works/pi-mcp":"1.0.0","@earendil-works/pi-telemetry":"1.0.0","@earendil-works/pi-tui":"1.0.0","brace-expansion":"2.1.7",axios:"^1.20.0","basic-ftp":"^6.2.1","@grpc/grpc-js":"^1.14.5",browserslist:"^4.28.8","engine.io":"^6.6.7","fast-uri":"^3.1.8",hono:"^4.13.7","ip-address":"^10.7.4",nanoid:"^3.3.18",dompurify:"^3.4.17",postcss:"^8.5.23",qs:"^6.16.0","shell-quote":"^1.11.0","socket.io-parser":"^4.2.7",tmp:"^0.2.7",toml:"^5.0.1",undici:"^8.10.2",ws:"^8.21.0","js-yaml":"^4.3.2","@modelcontextprotocol/sdk":"^1.31.0","proxy-addr":"^2.0.8","source-map-js":"^1.2.2"}};
|
|
3
|
+
export{On};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{to}from"./vm-hands-entry-lite-84mc1f7h.js";import{spawnSync as p}from"child_process";import{createHash as de}from"crypto";import{chmodSync as ge,closeSync as pe,existsSync as w,linkSync as fe,lstatSync as me,mkdirSync as Q,mkdtempSync as he,openSync as we,readdirSync as ye,readFileSync as Ee,readSync as ke,realpathSync as Ne,renameSync as E,rmSync as k,statSync as Y,symlinkSync as W,writeFileSync as I}from"fs";import{connect as Se}from"net";import{homedir as m}from"os";import{basename as Z,dirname as R,join as u}from"path";import{inflateRawSync as be}from"zlib";var oe=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",ie=(e)=>e.length===1&&e>="!"&&e<="~",G=(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(ie)||ae(a)};return n.map((r,s)=>oe.has(r)&&t(s+1)?"[":r).join("")}function ae(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":G(t)?t.toLowerCase():t,s="reason".indexOf(r),o=s<0?0:1<<s;if(n=1|(G(t)?0:n)|(n&o)<<1,n&64)return!0}return!1}var ce=/[\u0000-\u0008\u000B-\u001F\u007F-\u009F]/g;function U(e){return J(e.replace(ce," ").replace(/[\u2028\u2029]/g," "))}var le=["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 ue(e=process.env,n=Boolean(process.stderr.isTTY)){let t=le.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=ue()){return n?e:U(e)}class Ce extends Error{}var f="reason-network",g="0.12.10",_e={"aarch64-apple-darwin":"fd3e6eccf76aa3f3cdcbe516bb2e0885bc9416e89378d858c5d96e58a37a2996","x86_64-apple-darwin":"68a224c4e51ec91c4754fdda2724de0e72ba3f27b687b2466a7c7d5e492ad72c","aarch64-unknown-linux-musl":"ca6177ba2ac3fc2d1ca0a06953cb33ee09ab6d83f5b957bee54339b41b6672b4","x86_64-unknown-linux-musl":"d872f3e96066ed717cc775f9c580a2ab68feace60e06427ff216cec985f2115a","aarch64-pc-windows-msvc":"67b4f3f9c3f7e69e285eef863009fa014195b1c91a4e8b1abca81f1a085e55ed","x86_64-pc-windows-msvc":"9fad0c86fdc56e7b837b7c98960f685dd63721f4e6be5a172f8198eee82e5869"},Re="https://reasonmachines.com/cli/engine",N="REASON_AGENT_NETWORK_BIN";function ve(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`${f}-${e}${e.endsWith("-windows-msvc")?".zip":".tar.gz"}`}function xe(e){let n=_e[e];return n?{url:`${Re}/${g}/${ee(e)}`,sha256:n}:null}function A(e){let n=p(e,["--version"],{encoding:"utf8",timeout:5000}),[t,r]=n.status===0?n.stdout.trim().split(/\s+/):[];return t===f?r??null:null}function _(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 S(e=m(),n=process.platform){return u(e,".reason","bin",`${f}${n==="win32"?".exe":""}`)}var v=process.platform==="win32"?`~\\.local\\bin\\${f}.exe`:`~/.local/bin/${f}`;async function Te(e=process.env,n=()=>{}){if(e[N])return e[N];let t=S(),r=T(),s=r?.path===t&&y(t)===r.fingerprint?r:null,o=s?.kept,i=M(e)?null:$e(o);if(s?.version===g&&!i)return t;let a=w(t)?A(t):null;if(i){let c=A(i.path),d=a&&_(a,g)?a:g;if(!c||!_(d,c)){if(c)n(`Reason Network: ${v} (${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===g&&!i)return F(t,o);if(!a||!_(a,g))await ne(t);let l=p(t,["setup",...M(e)?["--no-service"]:[]],{env:await C(e),encoding:"utf8",timeout:60000});if(l.status!==0){let c=b((l.stderr||l.stdout||"").trim().split(`
|
|
4
|
+
`).pop()??"");if(s)return B(m(),{...s,fingerprint:y(t)??s.fingerprint,...o?{kept:o}:{}}),n(i?`Reason Network: couldn't move your agents off ${v}${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 Ce(`Couldn't connect this computer's agents to the network${c?` (${c})`:""}. Run reason network to try again.`)}if(i)o=Pe(i,t,n);return F(t,o),p(t,["stop"],{env:e,stdio:"ignore",timeout:15000}),t}function $e(e){let n=u(m(),".local","bin",Z(S())),t;try{t=me(n)}catch{return null}let r=`${t.size}:${t.mtimeMs}:${t.ino}`;if(!t.isFile()||r===e)return null;try{let s=Y(S());if(s.ino===t.ino&&s.dev===t.dev)return null}catch{}try{let s=Buffer.alloc(2),o=we(n,"r");try{ke(o,s,0,2,0)}finally{pe(o)}if(s.toString("latin1")==="#!")return null}catch{return null}return{path:n,fingerprint:r}}function Pe(e,n,t){let r=`${e.path}.reason-${process.pid}`;try{if(k(r,{force:!0}),process.platform==="win32"){try{W(n,r,"file")}catch{fe(n,r)}te(r,e.path,"win32")}else W(n,r),E(r,e.path);t(`Reason Network: your agents on this computer now use the version \`reason network\` keeps up to date (${v} points to it). Restart a running agent to pick it up.`);return}catch(s){return k(r,{force:!0}),t(`Reason Network: your agents on this computer now use the version \`reason network\` keeps up to date, but ${v} 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 al(e={}){let n=e.env??process.env,t=e.home??m(),r=S(t),s=T(t);if(n[N]||s?.path!==r||y(r)!==s.fingerprint)return!1;if(s.version===g)return!1;let o=A(r);if(o&&_(o,g))return!1;return await ne(r),B(t,{...s,fingerprint:y(r)??""}),e.beforeRestart?.(),p(r,["stop"],{env:n,stdio:"ignore",timeout:15000}),!0}async function C(e){if(e[j])return e;try{let{defaultWorkerServiceHost:n,workerServiceLauncher:t}=await import("./serve-service-det934tz.js");return{...e,[j]:t(n(m()),e)}}catch{return e}}var j="REASON_NETWORK_REASON_BIN";function M(e=process.env){return Boolean(e.REASON_NETWORK_NO_SERVICE||e.TINCAN_NO_SERVICE)}var L=(e)=>u(e,".reason","ask-engine.json");function y(e){try{let n=Y(e);return`${n.size}:${n.mtimeMs}:${n.ino}`}catch{return null}}function cl(e=m()){return T(e)?.version??null}function T(e=m()){try{let n=JSON.parse(Ee(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(R(L(e)),{recursive:!0}),I(L(e),JSON.stringify(n))}function F(e,n){let t=y(e);if(t)B(m(),{path:e,fingerprint:t,version:g,...n?{kept:n}:{}});return e}async function ne(e){let n=ve(),t=n?xe(n):null;if(!n||!t)throw new Ce(`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 Ce(`Couldn't download Reason Network from ${new URL(r).host} (${l}). Check the connection and run reason network again.`)}if(de("sha256").update(o).digest("hex")!==s)throw new Ce("The Reason Network download didn't match its checksum, so it wasn't installed.");Oe(o,n,e)}var H="Couldn't unpack the Reason Network download.";function Oe(e,n,t,r=process.platform){Q(R(t),{recursive:!0});let s=he(u(R(t),".reason-engine-"));try{let o=u(s,f);if(ee(n).endsWith(".zip"))o=u(s,`${f}.exe`),I(o,Ie(e,`${f}.exe`));else{I(u(s,"engine.tar.gz"),e);let i=p("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 ${f} in it`;throw new Ce(`Couldn't unpack the Reason Network download (${l}).`)}}ge(o,493),te(o,t,r)}finally{k(s,{recursive:!0,force:!0})}}function Ie(e,n){let t=e.lastIndexOf(Buffer.from("PK\x05\x06","latin1"));if(t<0||t+22>e.length)throw new Ce(H);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),P;try{P=i===0?Buffer.from(h):i===8?be(h):Buffer.alloc(0)}catch{break}if(i!==0&&i!==8||P.length!==l)break;return P}r+=46+o+e.readUInt16LE(r+30)+e.readUInt16LE(r+32)}throw new Ce(H)}function te(e,n,t){if(t!=="win32"||!w(n)){E(e,n);return}let r=R(n),s=(i)=>i.startsWith(`${Z(n)}.`)&&i.endsWith(".old");for(let i of ye(r).filter(s))try{k(u(r,i),{force:!0})}catch{}let o=`${n}.${process.pid}-${Date.now()}.old`;E(n,o);try{E(e,n)}catch(i){throw E(o,n),i}try{k(o,{force:!0})}catch{}}function Ae(e=process.env,n=m()){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!K(r)&&K(s)?s:r}var K=(e)=>w(u(e,"network.db"))||w(u(e,"tincan.db"));function Me(e,n=process.platform,t=Ne.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"}-${z(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}`,`${z(s)}.sock`)}function z(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 qr extends Error{code;constructor(e,n){super(e);this.code=n}}function Ji(e){return e instanceof qr&&/isn't registered/.test(e.message)}var re="not_in_team",se=15000,Le=new Set(["who","team","inbox","unread","held"]),Be=90000,De="Reason Network on this computer closed the connection";class x{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":De)))}static open(e){return new Promise((n,t)=>{let r=Se(e);r.once("connect",()=>n(new x(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)?re:null;s.reject(new qr(b(o),i))}}call(e,n={},t=se){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 O=/^(Claude Code|Grok|Codex) \u00B7 (.*)$/,Ge={"Claude Code":"claude-code",Grok:"grok",Codex:"codex"},Je=/^ask-[0-9a-f]{6}$/;function V(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 q(e){return{person:e.person,machine:e.machine,isMe:e.is_me,online:e.online,link:e.link,rttMs:e.rtt_ms}}class Ot{engine;env;connection=null;waits=new Set;constructor(e,n){this.engine=e;this.env=n}static async open(e=process.env,n){return new Ot(await Te(e,n),e)}static openInstalled(e=process.env){if(e[N])return new Ot(e[N],e);let n=S(),t=T();return t?.path===n&&y(n)===t.fingerprint?new Ot(n,e):null}socketPath(){return Me(Ae(this.env))}async open(){try{return await x.open(this.socketPath())}catch{return p(this.engine,["who","--json"],{env:this.env,stdio:"ignore",timeout:15000}),await x.open(this.socketPath())}}async call(e,n={},t){if(!this.connection||this.connection.isClosed)this.connection=await this.open();try{return await this.connection.call(e,n,t)}catch(r){if(!/closed|ECONNRESET|EPIPE/.test(String(r)))throw r;if(this.connection=await this.open(),!Le.has(e))throw r;return await this.connection.call(e,n)}}async waitOn(e,n){let t=await this.open();this.waits.add(t);try{return await t.call(e,n,n.wait_secs*1000+se)}finally{this.waits.delete(t),t.close()}}close(){this.connection?.close(),this.connection=null;for(let e of this.waits)e.close();this.waits.clear()}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=to.safeParse(o);return i.success?[i.data]:[]}):null;return{...t,...typeof e==="string"&&e?{teamId:e}:{},machines:t.machines.map(q),...typeof r==="string"&&r?{endpoint:r}:{},...s?{messageCounts:s}:{}}}catch(e){if(e instanceof qr&&e.code===re)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)=>O.test(s.doing??"")).map((s)=>`${s.person}/${s.machine}:${s.cwd}`)),r=n.sessions.filter((s)=>e.all||!Je.test(s.name)).filter((s)=>O.test(s.doing??"")||!t.has(`${s.person}/${s.machine}:${s.cwd}`)).map((s)=>{let o=O.exec(s.doing??"");return{address:s.address,name:s.name,person:s.person,machine:s.machine,agent:o?Ge[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(q),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(V),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(V);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,Be)}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=p(this.engine,["endpoint"],{encoding:"utf8",env:this.env,timeout:30000}),n=e.status===0?e.stdout.trim():"";if(!n)throw new Ce(`Reason Network on this computer couldn't say its endpoint${X(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 qr&&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 Ce("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(){this.close();let e=p(this.engine,["setup",...M(this.env)?["--no-service"]:[]],{encoding:"utf8",env:await C(this.env),timeout:60000});if(e.status!==0)throw new Ce(`Couldn't connect this computer's agents to the network${X(e)}.`);return[...e.stdout.matchAll(/^ {2}([^:\n]+): (?!skipped)/gm)].map((n)=>n[1]).filter((n)=>n!=="service")}async setup(e,n={}){return this.passthrough(["setup",...e],n,await C(this.env))}passthrough(e,n={},t=this.env){this.close();let r=p(this.engine,e,{stdio:["inherit","pipe",n.person?"inherit":"pipe"],encoding:"utf8",env:t});if(!n.quiet||r.status!==0)process.stdout.write(Fe(b(r.stdout??""))),process.stderr.write(Fe(b(r.stderr??"")));return r.status??1}}function X(e){let n=b(((e.stderr||e.stdout)??"").trim().split(`
|
|
9
|
+
`).pop()??"");return n?` (${n})`:""}function b(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,Ce,al,cl,qr,Ji,Ot};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{Gt,lc,le,Kt,yn,wn,T}from"./vm-hands-entry-lite-bnpdn6fw.js";import{ue}from"./vm-hands-entry-lite-q9djb28r.js";import{Er}from"./vm-hands-entry-lite-j10cw3d9.js";import{kr}from"./vm-hands-entry-lite-q3er9m6y.js";import{Li}from"./vm-hands-entry-lite-rhx6adbr.js";import{Br,pa}from"./vm-hands-entry-lite-z0ht62s4.js";import{Te,Ft}from"./vm-hands-entry-lite-tvnfm4xg.js";import{de,Ue}from"./vm-hands-entry-lite-8pcs85ak.js";import{Tr}from"./vm-hands-entry-lite-71ebge0c.js";import{s}from"./vm-hands-entry-lite-zawytz09.js";import{B}from"./vm-hands-entry-lite-8xv6c0rm.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{spawn as k,spawnSync as rt}from"child_process";import{createHash as nt,randomUUID as ge}from"crypto";import{closeSync as st,copyFileSync as ne,existsSync as M,fstatSync as it,mkdirSync as se,openSync as at,readdirSync as D,readFileSync as G,readlinkSync as ct,renameSync as he,rmSync as lt,statSync as ut,writeFileSync as dt}from"fs";import{connect as pt}from"net";import{tmpdir as L,userInfo as _e}from"os";import{basename as ie,delimiter as mt,dirname as U,join as f}from"path";var K=`import { spawn, execFileSync } from "node:child_process";
|
|
3
3
|
import { createHash, randomUUID } from "node:crypto";
|
|
4
4
|
import { readFileSync, readlinkSync, lstatSync, realpathSync, statSync, mkdtempSync, mkdirSync, chmodSync, writeFileSync, readdirSync, rmSync, openSync, readSync, closeSync, renameSync } from "node:fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
@@ -950,7 +950,7 @@ if(process.env.REASON_CLOUD_GATEWAY_EXEC === "1") {
|
|
|
950
950
|
process.stdout.write(JSON.stringify(cloudAutomationFailure(error))+"\\n");process.exitCode=1;
|
|
951
951
|
}
|
|
952
952
|
}
|
|
953
|
-
`;import{spawn as Ce}from"child_process";import{lstatSync as
|
|
954
|
-
`).at(-1)?.slice(-300)??"";if(!
|
|
955
|
-
`);if(A)return u(A);u(new r("desktop_delegate_failed",`Reason's desktop operation failed (${J}${Y?`: ${Y}`:""}).`))})),t.aborted)S();c.stdin.end(JSON.stringify(o))})}async function Q(e,o,t,n={}){let s=await Bt(e,{op:"automation",call:o},t,n);if(!Number.isSafeInteger(s.code)||typeof s.stdout!=="string"||typeof s.stderr!=="string")throw new r("desktop_delegate_failed","Reason's desktop reply is malformed.");return{code:s.code,stdout:Buffer.from(s.stdout,"base64"),stderr:s.stderr}}import{execFile as He,spawn as Ge}from"child_process";import{closeSync as je,mkdirSync as Ke,openSync as Ye}from"fs";import{dirname as E,join as ze}from"path";import{promisify as Ve}from"util";var Ze=Ve(He),ee="x-apple.systempreferences:com.apple.preference.security",Qe={accessibility:`${ee}?Privacy_Accessibility`,screen:`${ee}?Privacy_ScreenCapture`},et=64,O=new Map;function T(e,o){let t=O.get(e);if(t?.has(o))return!1;if(!t){if(O.size>=et)O.delete(O.keys().next().value);t=new Set,O.set(e,t)}return t.add(o),!0}function tt(){let e=a(),o=Jn(xe(e),process.env),t=ze(e,".local","share","reason","desktop-install.log");Ke(E(t),{recursive:!0,mode:448});let n=Ye(t,"a",384);try{let s=Ge(o,["desktop","install"],{detached:!0,stdio:["ignore",n,n],env:{...process.env,REASON_DESKTOP_BACKGROUND:"1"}});s.on("error",()=>{return}),s.unref()}finally{je(n)}}var N={open:async(e,o)=>{await Ze("/usr/bin/open",e,{signal:o,timeout:1e4,maxBuffer:8192})},request:(e,o)=>ft(e,o),tile:qr,installDesktop:tt},te=!1;async function oe(e,o,t){try{await o.open(["-a","Google Chrome",e],t)}catch{t.throwIfAborted(),await o.open([e],t)}}async function ne(e,o,t,n){if(await t.open([Qe[o]],n).catch(()=>{}),e[0]&&!n.aborted)t.tile(E(E(E(e[0]))),o)}async function ot(e,o,t,n,s){for(let i of t){if(!T(e,`grant:${i}`))continue;s.throwIfAborted(),await n.request(o,i).catch(()=>null),await ne(o,i,n,s)}}var rt={name:"open_tab",description:"Open a web page in the user's own Chrome on this Mac. Reason cannot read, screenshot or click in that tab, and no tab_id is returned: browser control needs Reason's Chrome extension. An actual browser call opens its setup page.",inputSchema:{type:"object",properties:{url:{type:"string",description:"An http or https URL."}},required:["url"],additionalProperties:!1}};function re(e){return{code:0,stderr:"",stdout:Buffer.from(JSON.stringify({ok:!0,...e}))}}function nt(e){if(typeof e!=="string")return null;try{let o=new URL(e);return o.protocol==="https:"||o.protocol==="http:"?o.href:null}catch{return null}}async function se(e,o=N){let{call:t,runId:n,signal:s}=e;if(t.kind==="browser"){if(t.operation==="discover")return re({result:{tools:[rt]}});if(t.operation!=="call")throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet. Request a browser operation or connect Chrome from Reason to set it up.")}if(e.desktopMissing&&!te){te=!0;try{o.installDesktop()}catch{}}if(t.kind==="computer"){if(e.identity.length>0&&T(n,"grant:probe")){let c=await o.request(e.identity).catch(()=>null),d=c?[...c.accessibility?[]:["accessibility"],...c.screen?[]:["screen"]]:[];for(let m of d)T(n,`grant:${m}`);for(let m of d)await ne(e.identity,m,o,s)}throw new r("automation_computer_setup_required","Computer use is not set up on this Mac yet; Reason asked macOS for any missing permission.")}if(T(n,"page:chrome-extension"))await oe(wo,o,s).catch(()=>{});let i=t.arguments,u=t.operation==="call"&&t.tool==="open_tab"&&i&&typeof i==="object"&&!Array.isArray(i)?nt(i.url):null;if(!u)throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet; Reason opened its Chrome Web Store page. open_tab still opens pages.");return await oe(u,o,s),re({result:{content:[{type:"text",text:JSON.stringify({opened:u,browser:"the user's Chrome",controllable:!1,note:"Opened for the user to see. Reason cannot read or act in this tab until Reason's Chrome extension is added (its Chrome Web Store page is open)."})}]}})}async function ie(e,o=N){if(e.call.kind!=="computer"||e.call.operation!=="permission_status"||e.output.code!==0||e.identity.length===0)return e.output;let t;try{t=JSON.parse(e.output.stdout.toString("utf8"))}catch{return e.output}if(!t||typeof t!=="object"||Array.isArray(t))return e.output;let n=t.permissions;if(!n||typeof n!=="object")return e.output;let s=n,i=[...s.accessibility==="missing"?["accessibility"]:[],...s.screenRecording==="missing"?["screen"]:[]];if(i.length===0)return e.output;return await ot(e.runId,e.identity,i,o,e.signal),{...e.output,stdout:Buffer.from(JSON.stringify({...t,requested:i}))}}var j=172032,wt=18874368,yt=8192,bt=65536,xt=55000,kt=60000,vt=4,It=40000,Rt=/^[0-9a-f-]{36}$/,ue=z,At=ge();function P(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function M(){throw new r("invalid_automation_request","Reason automation request is malformed.")}function we(e){let o=Object.keys(e).sort().join(",");if(o==="call"||o==="browser,call"){let t=e.call,n=o==="browser,call";if(!P(t)||t.version!==1||t.kind!=="computer"&&t.kind!=="browser"||n&&(e.browser!==St||t.kind!=="browser")||JSON.stringify(t).length>bt)M();return{call:t,userChrome:n}}if(o==="offset,output_id"){if(typeof e.output_id!=="string"||!Rt.test(e.output_id)||!Number.isSafeInteger(e.offset)||e.offset<0)M();return{output_id:e.output_id,offset:e.offset}}return M()}function Pn(e=process.platform,o=x){if(e==="darwin")return!0;return(e==="linux"||e==="win32")&&o()?.features.computer===!0}var Ot="__computer-use";function Us(e=x){return e()?.userChrome??{code:"user_chrome_browser_use_missing"}}function ye(e,o,t,n){return new Promise((s)=>{let i=v(e,o,{env:t,stdio:"ignore",windowsHide:!0}),u=setTimeout(()=>{i.kill("SIGKILL"),s(-1)},n);i.once("error",()=>{clearTimeout(u),s(-1)}),i.once("exit",(c)=>{clearTimeout(u),s(c??-1)})})}function Et(e,o,t,n){return new Promise((s)=>{let i=v(e,o,{env:t,stdio:["ignore","pipe","ignore"],windowsHide:!0}),u="";i.stdout.setEncoding("utf8").on("data",(d)=>{u+=d});let c=setTimeout(()=>{i.kill("SIGKILL"),s(null)},n);i.once("error",()=>{clearTimeout(c),s(null)}),i.once("close",(d)=>{clearTimeout(c),s(d===0?u:null)})})}function Tt(e){return R(e)?f(B(),"open-browser-use"):"/tmp/open-browser-use"}function R(e){return e.platform==="win32-x64"||e.platform==="win32-arm64"}var Ct=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,Nt=33554432;function Mt(e,o){let t;try{t=e===null?null:JSON.parse(e)}catch{return null}let n=P(t)&&P(t.result)?t.result.metadata:null;if(!P(n)||n.extensionId!==o)return null;return typeof n.extensionInstanceId==="string"&&Ct.test(n.extensionInstanceId)?n.extensionInstanceId:null}async function be(e,o,t){let n=t.storages.map((c)=>{try{return L(c).filter((d)=>d.endsWith(".log")||d.endsWith(".ldb")).map((d)=>f(c,d))}catch{return[]}}),s;try{s=n.some((c)=>c.length>0)?L(t.socketDir).filter((c)=>c.endsWith(".sock")):[]}catch{return[]}let i=[];for(let c of s){let d=f(t.socketDir,c),m=Mt(await Et(e,["info","--socket",d,"--timeout","2s"],o,5000),t.extensionId);if(m)i.push({instance:m,socket:d})}let u=[];for(let[c,d]of(i.length>0?n:[]).entries())for(let m of d)try{if(pt(m).size>Nt)continue;let l=X(m),p=i.find((g)=>l.includes(g.instance));if(p){u.push({storage:t.storages[c],...p});break}}catch{}return u}async function Dt(e,o,t){return(await be(e,o,t))[0]?.instance??null}function Se(e,o,t){return Dt(e.nativeHost,o,{socketDir:Tt(e),extensionId:U,storages:[f(t,"browser-profile","Default","Local Extension Settings",U)]})}var de=/^(Default|Profile ([0-9]+))$/;async function Lt(e,o,t=a(),n=Jt){let s=f(t,"Library","Application Support","Google","Chrome"),i=[];try{i=L(s)}catch(l){if(l.code==="EPERM")throw new r("browser_use_chrome_access_denied","macOS blocked Reason from reading Chrome's profiles. Allow Full Disk Access for Reason on this Mac and try again.")}let u=(l)=>Number(de.exec(l)?.[2]??-1),c=i.filter((l)=>de.test(l)&&D(f(s,l,"Extensions",Je))).sort((l,p)=>u(l)-u(p)),d=(l)=>f(s,l,"Local Extension Settings",Je);return(await be(e,o,{socketDir:n,extensionId:Je,storages:c.map(d)})).map(({storage:l,instance:p,socket:g})=>({profile:c.find((_)=>d(_)===l),instance:p,socket:g}))}async function Ut(e,o,t=a(),n=Jt){let s=(await Lt(e,o,t,n))[0]?.instance;if(!s)throw new r("automation_user_chrome_not_connected","No Chrome profile on this Mac is connected to Reason. Open Chrome with the Reason extension, then try again.");return s}function pe(e){return new Promise((o)=>{let t=ht({path:e}),n=(s)=>{t.destroy(),o(s)};t.setTimeout(1000,()=>n(!1)),t.once("error",()=>n(!1)),t.once("connect",()=>n(!0))})}async function ke(e,o){let t=Date.now()+o;while(Date.now()<t){if(await e())return!0;await new Promise((n)=>setTimeout(n,200))}return!1}var F=new Map;function H(e,o){let t=F.get(e);if(!t)t=o().finally(()=>F.delete(e)),F.set(e,t);return t}async function $t(e,o){if(await pe(e))return;if(dt(e,{force:!0}),await ye("dbus-daemon",["--session",`--address=unix:path=${e}`,"--fork"],o,1e4)!==0||!await ke(()=>pe(e),5000))throw new r("automation_unavailable","Reason could not start the desktop session bus.")}async function me(e,o,t){let n=e.platform==="darwin-arm64"||R(e)?async()=>await Se(e,o,t)!==null:async()=>await ye(e.nativeHost,["info"],o,5000)===0;if(await n())return;let s=["--profile-directory=Default",`--load-extension=${e.extensionDir}`,"--no-first-run","--no-default-browser-check","--window-size=1280,800","about:blank"],i,u=null,c=0;if(e.platform==="darwin-arm64"){let l=f(t,"browser-profile");G(l);let p=f(l,"NativeMessagingHosts");ce(p,{recursive:!0,mode:448});let g=zr(e.platform).nativeHostManifests[0];ae(g,f(p,le(g)));let _=e.browser.slice(0,e.browser.indexOf(".app/")+4),h=s.filter((I)=>I!=="about:blank").concat("--no-startup-window","--use-mock-keychain");i=v("/usr/bin/open",["-g","-n","-a",_,"--args",`--user-data-dir=${l}`,...h],{env:o,stdio:"ignore"})}else if(R(e)){let l=f(t,"browser-profile");G(l),st(C("icacls"),[q(e.browser),"/grant","*S-1-15-2-1:(OI)(CI)(RX)","*S-1-15-2-2:(OI)(CI)(RX)"],{stdio:"ignore",windowsHide:!0,timeout:60000});let p=s.filter((g)=>g!=="about:blank").concat("--no-startup-window","--keep-alive-for-test");i=v(e.browser,[`--user-data-dir=${l}`,...p],{detached:!0,stdio:"ignore",env:o})}else{let l=f(o.HOME,".config","google-chrome"),p=f(l,"NativeMessagingHosts");ce(p,{recursive:!0,mode:448});let g=zr(e.platform).nativeHostManifests[0];ae(g,f(p,le(g)));let _=process.geteuid?.()===0?["--no-sandbox"]:[];u=f(t,"browser.log");let h=lt(u,"a",384);c=ct(h).size,i=v(e.browser,[`--user-data-dir=${l}`,...s,..._,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",h,h],env:{...o,ACCESSIBILITY_ENABLED:"1"}}),at(h)}let d=!1;i.once("error",()=>{d=!0}),i.once("exit",(l)=>{d||=l!==0}),i.unref();let m=!1;if(await ke(async()=>d||(m=await n()),It),!m){if(u&&X(u).subarray(c).toString("utf8").includes("No usable sandbox"))throw new r("automation_browser_sandbox_unavailable","Chromium found no usable sandbox on this machine. Run the worker as a non-root user with unprivileged user namespaces enabled, or in a container with seccomp unconfined.");throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function zs(e){await Re(e,!0)}function qs(e){return ve(e,Ie(e))}function ve(e,o){return e.platform==="darwin-arm64"||R(e)?f(o,"browser-profile"):f(o,"home",".config","google-chrome")}function Ie(e){let o=f(e.root,"automation");if(!D(o)||!qt(e.automation))return e.automation;if(!Wt(ve(e,o)))try{he(o,e.automation)}catch{}return D(o)?o:e.automation}function qt(e){try{return L(e).length===0}catch(o){return o.code==="ENOENT"}}function Wt(e){let o;try{o=ut(f(e,"SingletonLock"))}catch{return!1}let t=Number(o.slice(o.lastIndexOf("-")+1));if(!Number.isSafeInteger(t)||t<=0)return!0;try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}async function Re(e,o){Pt({root:e.root,automation:e.automation,extensionDir:e.extensionDir});let t=Ie(e);G(t);let n=_e().username,s={USER:n,LOGNAME:n,REASON_AUTOMATION_OCU:e.ocu,REASON_AUTOMATION_OBU:e.nativeHost};if(e.platform==="darwin-arm64"||R(e)){let l=R(e)?{...s,...Ft(),HOME:a()}:{...s,HOME:a(),PATH:`${q(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:Ot};if(!o)return l;await H("browser",()=>me(e,l,t));let p=await Se(e,l,t);if(!p)throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...l,REASON_AUTOMATION_OBU_INSTANCE:p,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let i=await qe(),u=f(t,"home"),c=f(t,"runtime");G(u),G(c);let d=f(t,"bus"),m={...s,HOME:u,PATH:`${q(e.node)}:/usr/bin:/bin`,DISPLAY:i.display,XAUTHORITY:i.xauthority,XDG_RUNTIME_DIR:c,DBUS_SESSION_BUS_ADDRESS:`unix:path=${d}`,...i.sound?{PULSE_SERVER:Xe(i.sound)}:{}};if(await H("bus",()=>$t(d,m)),o)await H("browser",()=>me(e,m,t));return m}function Ft(){let e=process.env.SystemRoot??"C:\\Windows",o=Object.fromEntries(["SystemDrive","USERPROFILE","LOCALAPPDATA","APPDATA","ProgramData","ProgramFiles","PATHEXT","ComSpec","USERNAME","USERDOMAIN","COMPUTERNAME","NUMBER_OF_PROCESSORS","PROCESSOR_ARCHITECTURE","PSModuleAnalysisCachePath"].flatMap((n)=>process.env[n]?[[n,process.env[n]]]:[])),t=f(e,"System32");return{...o,SystemRoot:e,windir:e,TEMP:B(),TMP:B(),PATH:[t,f(t,"WindowsPowerShell","v1.0"),e].join(_t)}}async function Ht(e,o,t){let n=_e().username,s={USER:n,LOGNAME:n,HOME:a(),PATH:`${q(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:o,REASON_AUTOMATION_BACKGROUND_TABS:"1"},i=await Ut(o,s);return t.throwIfAborted(),{...s,REASON_AUTOMATION_OBU_INSTANCE:i}}function Gt(e){if(process.platform!=="win32")return["--input-type=module","--eval",e];let o=f(B(),`reason-automation-${it("sha256").update(e).digest("hex").slice(0,16)}.mjs`);if(!D(o)||X(o,"utf8")!==e){let t=`${o}.${process.pid}.tmp`;mt(t,e,{mode:384}),he(t,o)}return[o]}function Ae(e,o,t,n){if(typeof ue!=="string")return Promise.reject(new r("automation_unavailable","This Reason build has no automation runtime."));let s=ue;return new Promise((i,u)=>{let c=v(e,Gt(s),{env:{...o,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:process.platform!=="win32",windowsHide:!0}),d=[],m=0,l="",p=null,g=!1,_=(w)=>{if(p??=w,process.platform==="win32"&&c.pid){v(f(process.env.SystemRoot??"C:\\Windows","System32","taskkill.exe"),["/pid",String(c.pid),"/t","/f"],{stdio:"ignore",windowsHide:!0}).once("error",()=>c.kill("SIGKILL"));return}try{process.kill(-c.pid,"SIGKILL")}catch{c.kill("SIGKILL")}},h=(w)=>{if(g)return;g=!0,clearTimeout(I),n.removeEventListener("abort",S),w()},I=setTimeout(()=>_(new r("automation_timed_out","Reason automation did not finish in time.")),xt),S=()=>_(new r("cancelled","Reason cancelled the automation call."));if(n.addEventListener("abort",S,{once:!0}),c.stdout.on("data",(w)=>{if(m+=w.byteLength,m>wt)_(new r("automation_output_too_large","Reason automation output is too large."));else d.push(w)}),c.stderr.setEncoding("utf8").on("data",(w)=>{l=(l+w).slice(-yt)}),c.stdin.on("error",()=>{}),c.once("error",()=>h(()=>u(p??new r("automation_unavailable","Reason could not start the automation runtime.")))),c.once("close",(w)=>h(()=>{if(p)u(p);else i({code:w??1,stdout:Buffer.concat(d),stderr:l})})),n.aborted)S();c.stdin.end(t)})}var k=new Map;function jt(e,o,t){for(let[s,i]of k)if(i.expiresAt<=t)k.delete(s);while(k.size>=vt)k.delete(k.keys().next().value);let n=ge();return k.set(n,{runId:e,bytes:o,expiresAt:t+kt}),n}async function Oe(e,o,t,n={}){let s=await(n.environment??Re)(e,o.kind==="browser");return t.throwIfAborted(),await(n.runtime??Ae)(e.node,s,JSON.stringify(o),t)}async function Ws(e,o){let t=we({call:e});if(!("call"in t))M();let n=x();if(!n?.features.computer||t.call.kind==="browser"&&!n.features.browser)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await Oe(n,t.call,o)}function fe(e,o,t){let n=e.stdout.byteLength>j?jt(o,e.stdout,t):void 0;return{code:e.code,stderr:e.stderr,instance_id:At,output_bytes:e.stdout.byteLength,chunk:e.stdout.subarray(0,j).toString("base64"),...n?{output_id:n}:{}}}async function Rn(e,o={}){let t=we(e.payload),n=(o.now??Date.now)();if("output_id"in t){let h=k.get(t.output_id);if(!h||h.runId!==e.runId||h.expiresAt<=n||t.offset>h.bytes.byteLength)throw new r("automation_output_unavailable","Reason automation output expired.");return{chunk:h.bytes.subarray(t.offset,t.offset+j).toString("base64")}}let s=(o.components??x)(),i=(o.platform??process.platform)==="darwin",u=i?(o.macIdentity??gt)():[],c=o.macSetup??N,d=!s?.features.computer||t.call.kind==="browser"&&!t.userChrome&&!s.features.browser;if(i&&(d||u.length===0||t.call.kind==="browser"&&t.userChrome&&!e.userChrome))return fe(await se({runId:e.runId,call:t.call,identity:u,desktopMissing:d,signal:e.signal},c),e.runId,n);if(!s?.features.computer)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let m=t.userChrome?e.userChrome:void 0;if(t.userChrome&&!m)throw new r("automation_user_chrome_unavailable","Your own Chrome is not enabled on this computer: run `reason desktop install` on this Mac (and `reason connect --user-chrome on` if you turned it off).");if(t.call.kind==="browser"&&!m&&!s.features.browser)throw new r("automation_browser_not_installed",!s.platform.startsWith("linux")?"Browser use is unavailable on this machine: re-run `reason desktop install`.":"Browser use is unavailable on this machine: install a non-snap Chromium at /usr/bin/chromium, then re-run `reason desktop install`.");e.signal.throwIfAborted();let l=t.call.kind==="browser"&&t.call.operation!=="record_start"&&t.call.operation!=="record_stop",p=await Hi(e.runId,e.signal,o.now,l?"call":"run"),g="account"in o?o.account??null:K(),_;try{if(m){let h=await(o.userChromeEnvironment??Ht)(s,m,e.signal);e.signal.throwIfAborted(),_=await(o.runtime??Ae)(s.node,h,JSON.stringify(t.call),e.signal)}else if(g)_=await(o.delegate??Q)(g,t.call,e.signal);else _=await Oe(s,t.call,e.signal,o)}finally{p()}if(i)_=await ie({runId:e.runId,call:t.call,identity:u,output:_,signal:e.signal},c);return fe(_,e.runId,n)}
|
|
956
|
-
export{
|
|
953
|
+
`;import{spawn as Ce}from"child_process";import{lstatSync as J,readFileSync as Y,rmSync as Ne}from"fs";import{basename as Pe}from"path";var Me="__desktop-call",De="/usr/bin/setpriv",Le=27262976,$e=8192,Be=2000;function q(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function qe(e){try{return JSON.parse(e)}catch{return null}}function We(){return[process.execPath,...Pe(process.execPath).startsWith("bun")&&process.argv[1]?[process.argv[1]]:[],Me]}function Fe(e){let o=(a)=>{try{return J(a).uid}catch{return null}},t=J("/tmp/.X11-unix",{throwIfNoEntry:!1});if(!t?.isDirectory()||t.uid!==0)return;let n=["/tmp/.X99-lock","/tmp/.X11-unix/X99"].filter((a)=>{let u=o(a);return u!==null&&u!==e.uid});if(!n.length)return;let i="";try{let a=Y("/tmp/.X99-lock","utf8").trim();if(/^\d+$/.test(a))i=Y(`/proc/${a}/comm`,"utf8").trim()}catch{}if(/^X/.test(i))return;for(let a of n)Ne(a,{force:!0})}function nn(e,o,t,n={}){if(t.throwIfAborted(),(o.op==="display"||o.op==="automation")&&process.platform==="linux"&&process.getuid?.()===0)try{Fe(e)}catch{}let i=n.command??We();return new Promise((a,u)=>{let c=(n.spawnProcess??Ce)(De,[`--reuid=${e.uid}`,`--regid=${e.gid}`,"--clear-groups","--no-new-privs","--",...i],{cwd:e.home,detached:!0,stdio:["pipe","pipe","pipe"],env:{HOME:e.home,USER:e.username,LOGNAME:e.username,PATH:"/usr/local/bin:/usr/bin:/bin"}}),d=[],m=0,l="",p=null,g=!1,_,h=(y)=>{try{process.kill(-c.pid,y)}catch{c.kill(y)}},v=(y)=>{p??=y,h("SIGTERM"),_??=setTimeout(()=>h("SIGKILL"),Be)},S=()=>v(new r("cancelled","Reason cancelled the desktop operation."));t.addEventListener("abort",S,{once:!0});let w=(y)=>{if(g)return;g=!0,clearTimeout(_),t.removeEventListener("abort",S),y()};if(c.stdout.on("data",(y)=>{if(m+=y.byteLength,m>Le)v(new r("desktop_delegate_failed","Reason's desktop reply is too large."));else d.push(y)}),c.stderr.setEncoding("utf8").on("data",(y)=>{l=(l+y).slice(-$e)}),c.stdin.on("error",()=>{}),c.once("error",()=>w(()=>u(p??new r("desktop_delegate_unavailable","Reason could not start its desktop as the desktop account.")))),c.once("close",(y,Oe)=>w(()=>{if(p)return u(p);let b=qe(Buffer.concat(d).toString("utf8"));if(q(b)&&b.ok===!0&&q(b.result))return a(b.result);let R=q(b)&&b.ok===!1&&typeof b.code==="string"&&typeof b.message==="string"?new r(b.code.slice(0,120),b.message.slice(0,2000)):null,j=`exited ${y??Oe}${R?"":" with no reply"}`,X=l.trim().split(`
|
|
954
|
+
`).at(-1)?.slice(-300)??"";if(!R||R.code==="desktop_delegate_failed")process.stderr.write(`Reason worker: desktop call ${j}${l?`: ${l.trim().slice(-500)}`:""}
|
|
955
|
+
`);if(R)return u(R);u(new r("desktop_delegate_failed",`Reason's desktop operation failed (${j}${X?`: ${X}`:""}).`))})),t.aborted)S();c.stdin.end(JSON.stringify(o))})}async function z(e,o,t,n={}){let i=await nn(e,{op:"automation",call:o},t,n);if(!Number.isSafeInteger(i.code)||typeof i.stdout!=="string"||typeof i.stderr!=="string")throw new r("desktop_delegate_failed","Reason's desktop reply is malformed.");return{code:i.code,stdout:Buffer.from(i.stdout,"base64"),stderr:i.stderr}}import{execFile as He,spawn as Ge}from"child_process";import{closeSync as je,mkdirSync as Xe,openSync as Ke}from"fs";import{dirname as O,join as Je}from"path";import{promisify as Ye}from"util";var ze=Ye(He),V="x-apple.systempreferences:com.apple.preference.security",Ve={accessibility:`${V}?Privacy_Accessibility`,screen:`${V}?Privacy_ScreenCapture`},Ze=64,A=new Map;function E(e,o){let t=A.get(e);if(t?.has(o))return!1;if(!t){if(A.size>=Ze)A.delete(A.keys().next().value);t=new Set,A.set(e,t)}return t.add(o),!0}function Qe(){let e=s(),o=Ue(de(e),process.env),t=Je(e,".local","share","reason","desktop-install.log");Xe(O(t),{recursive:!0,mode:448});let n=Ke(t,"a",384);try{let i=Ge(o,["desktop","install"],{detached:!0,stdio:["ignore",n,n],env:{...process.env,REASON_DESKTOP_BACKGROUND:"1"}});i.on("error",()=>{return}),i.unref()}finally{je(n)}}var C={open:async(e,o)=>{await ze("/usr/bin/open",e,{signal:o,timeout:1e4,maxBuffer:8192})},request:(e,o)=>Er(e,o),tile:Li,installDesktop:Qe},Z=!1;async function Q(e,o,t){try{await o.open(["-a","Google Chrome",e],t)}catch{t.throwIfAborted(),await o.open([e],t)}}async function te(e,o,t,n){if(await t.open([Ve[o]],n).catch(()=>{}),e[0]&&!n.aborted)t.tile(O(O(O(e[0]))),o)}async function et(e,o,t,n,i){for(let a of t){if(!E(e,`grant:${a}`))continue;i.throwIfAborted(),await n.request(o,a).catch(()=>null),await te(o,a,n,i)}}var tt={name:"open_tab",description:"Open a web page in the user's own Chrome on this Mac. Reason cannot read, screenshot or click in that tab, and no tab_id is returned: browser control needs Reason's Chrome extension. An actual browser call opens its setup page.",inputSchema:{type:"object",properties:{url:{type:"string",description:"An http or https URL."}},required:["url"],additionalProperties:!1}};function ee(e){return{code:0,stderr:"",stdout:Buffer.from(JSON.stringify({ok:!0,...e}))}}function ot(e){if(typeof e!=="string")return null;try{let o=new URL(e);return o.protocol==="https:"||o.protocol==="http:"?o.href:null}catch{return null}}async function oe(e,o=C){let{call:t,runId:n,signal:i}=e;if(t.kind==="browser"){if(t.operation==="discover")return ee({result:{tools:[tt]}});if(t.operation!=="call")throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet. Request a browser operation or connect Chrome from Reason to set it up.")}if(e.desktopMissing&&!Z){Z=!0;try{o.installDesktop()}catch{}}if(t.kind==="computer"){if(e.identity.length>0&&E(n,"grant:probe")){let c=await o.request(e.identity).catch(()=>null),d=c?[...c.accessibility?[]:["accessibility"],...c.screen?[]:["screen"]]:[];for(let m of d)E(n,`grant:${m}`);for(let m of d)await te(e.identity,m,o,i)}throw new r("automation_computer_setup_required","Computer use is not set up on this Mac yet; Reason asked macOS for any missing permission.")}if(E(n,"page:chrome-extension"))await Q(lc,o,i).catch(()=>{});let a=t.arguments,u=t.operation==="call"&&t.tool==="open_tab"&&a&&typeof a==="object"&&!Array.isArray(a)?ot(a.url):null;if(!u)throw new r("automation_browser_setup_required","Browser control is not set up on this Mac yet; Reason opened its Chrome Web Store page. open_tab still opens pages.");return await Q(u,o,i),ee({result:{content:[{type:"text",text:JSON.stringify({opened:u,browser:"the user's Chrome",controllable:!1,note:"Opened for the user to see. Reason cannot read or act in this tab until Reason's Chrome extension is added (its Chrome Web Store page is open)."})}]}})}async function re(e,o=C){if(e.call.kind!=="computer"||e.call.operation!=="permission_status"||e.output.code!==0||e.identity.length===0)return e.output;let t;try{t=JSON.parse(e.output.stdout.toString("utf8"))}catch{return e.output}if(!t||typeof t!=="object"||Array.isArray(t))return e.output;let n=t.permissions;if(!n||typeof n!=="object")return e.output;let i=n,a=[...i.accessibility==="missing"?["accessibility"]:[],...i.screenRecording==="missing"?["screen"]:[]];if(a.length===0)return e.output;return await et(e.runId,e.identity,a,o,e.signal),{...e.output,stdout:Buffer.from(JSON.stringify({...t,requested:a}))}}var H=172032,ft=18874368,gt=8192,ht=65536,_t=55000,wt=60000,yt=4,bt=40000,St=/^[0-9a-f-]{36}$/,ae=K,xt=ge();function N(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function P(){throw new r("invalid_automation_request","Reason automation request is malformed.")}function we(e){let o=Object.keys(e).sort().join(",");if(o==="call"||o==="browser,call"){let t=e.call,n=o==="browser,call";if(!N(t)||t.version!==1||t.kind!=="computer"&&t.kind!=="browser"||n&&(e.browser!==Tr||t.kind!=="browser")||JSON.stringify(t).length>ht)P();return{call:t,userChrome:n}}if(o==="offset,output_id"){if(typeof e.output_id!=="string"||!St.test(e.output_id)||!Number.isSafeInteger(e.offset)||e.offset<0)P();return{output_id:e.output_id,offset:e.offset}}return P()}function hr(e=process.platform,o=T){if(e==="darwin")return!0;return(e==="linux"||e==="win32")&&o()?.features.computer===!0}var kt="__computer-use";function To(e=T){return e()?.userChrome??{code:"user_chrome_browser_use_missing"}}function ye(e,o,t,n){return new Promise((i)=>{let a=k(e,o,{env:t,stdio:"ignore",windowsHide:!0}),u=setTimeout(()=>{a.kill("SIGKILL"),i(-1)},n);a.once("error",()=>{clearTimeout(u),i(-1)}),a.once("exit",(c)=>{clearTimeout(u),i(c??-1)})})}function vt(e,o,t,n){return new Promise((i)=>{let a=k(e,o,{env:t,stdio:["ignore","pipe","ignore"],windowsHide:!0}),u="";a.stdout.setEncoding("utf8").on("data",(d)=>{u+=d});let c=setTimeout(()=>{a.kill("SIGKILL"),i(null)},n);a.once("error",()=>{clearTimeout(c),i(null)}),a.once("close",(d)=>{clearTimeout(c),i(d===0?u:null)})})}function It(e){return I(e)?f(L(),"open-browser-use"):"/tmp/open-browser-use"}function I(e){return e.platform==="win32-x64"||e.platform==="win32-arm64"}var Rt=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/,At=33554432;function Ot(e,o){let t;try{t=e===null?null:JSON.parse(e)}catch{return null}let n=N(t)&&N(t.result)?t.result.metadata:null;if(!N(n)||n.extensionId!==o)return null;return typeof n.extensionInstanceId==="string"&&Rt.test(n.extensionInstanceId)?n.extensionInstanceId:null}async function be(e,o,t){let n=t.storages.map((c)=>{try{return D(c).filter((d)=>d.endsWith(".log")||d.endsWith(".ldb")).map((d)=>f(c,d))}catch{return[]}}),i;try{i=n.some((c)=>c.length>0)?D(t.socketDir).filter((c)=>c.endsWith(".sock")):[]}catch{return[]}let a=[];for(let c of i){let d=f(t.socketDir,c),m=Ot(await vt(e,["info","--socket",d,"--timeout","2s"],o,5000),t.extensionId);if(m)a.push({instance:m,socket:d})}let u=[];for(let[c,d]of(a.length>0?n:[]).entries())for(let m of d)try{if(ut(m).size>At)continue;let l=G(m),p=a.find((g)=>l.includes(g.instance));if(p){u.push({storage:t.storages[c],...p});break}}catch{}return u}async function Et(e,o,t){return(await be(e,o,t))[0]?.instance??null}function Se(e,o,t){return Et(e.nativeHost,o,{socketDir:It(e),extensionId:le,storages:[f(t,"browser-profile","Default","Local Extension Settings",le)]})}var ce=/^(Default|Profile ([0-9]+))$/;async function Tt(e,o,t=s(),n=yn){let i=f(t,"Library","Application Support","Google","Chrome"),a=[];try{a=D(i)}catch(l){if(l.code==="EPERM")throw new r("browser_use_chrome_access_denied","macOS blocked Reason from reading Chrome's profiles. Allow Full Disk Access for Reason on this Mac and try again.")}let u=(l)=>Number(ce.exec(l)?.[2]??-1),c=a.filter((l)=>ce.test(l)&&M(f(i,l,"Extensions",Gt))).sort((l,p)=>u(l)-u(p)),d=(l)=>f(i,l,"Local Extension Settings",Gt);return(await be(e,o,{socketDir:n,extensionId:Gt,storages:c.map(d)})).map(({storage:l,instance:p,socket:g})=>({profile:c.find((_)=>d(_)===l),instance:p,socket:g}))}async function Ct(e,o,t=s(),n=yn){let i=(await Tt(e,o,t,n))[0]?.instance;if(!i)throw new r("automation_user_chrome_not_connected","No Chrome profile on this Mac is connected to Reason. Open Chrome with the Reason extension, then try again.");return i}function pe(e){return new Promise((o)=>{let t=pt({path:e}),n=(i)=>{t.destroy(),o(i)};t.setTimeout(1000,()=>n(!1)),t.once("error",()=>n(!1)),t.once("connect",()=>n(!0))})}async function xe(e,o){let t=Date.now()+o;while(Date.now()<t){if(await e())return!0;await new Promise((n)=>setTimeout(n,200))}return!1}var W=new Map;function F(e,o){let t=W.get(e);if(!t)t=o().finally(()=>W.delete(e)),W.set(e,t);return t}async function Nt(e,o){if(await pe(e))return;if(lt(e,{force:!0}),await ye("dbus-daemon",["--session",`--address=unix:path=${e}`,"--fork"],o,1e4)!==0||!await xe(()=>pe(e),5000))throw new r("automation_unavailable","Reason could not start the desktop session bus.")}async function me(e,o,t){let n=e.platform==="darwin-arm64"||I(e)?async()=>await Se(e,o,t)!==null:async()=>await ye(e.nativeHost,["info"],o,5000)===0;if(await n())return;let i=["--profile-directory=Default",`--load-extension=${e.extensionDir}`,"--no-first-run","--no-default-browser-check","--window-size=1280,800","about:blank"],a,u=null,c=0;if(e.platform==="darwin-arm64"){let l=f(t,"browser-profile");Te(l);let p=f(l,"NativeMessagingHosts");se(p,{recursive:!0,mode:448});let g=wn(e.platform).nativeHostManifests[0];ne(g,f(p,ie(g)));let _=e.browser.slice(0,e.browser.indexOf(".app/")+4),h=i.filter((v)=>v!=="about:blank").concat("--no-startup-window","--use-mock-keychain");a=k("/usr/bin/open",["-g","-n","-a",_,"--args",`--user-data-dir=${l}`,...h],{env:o,stdio:"ignore"})}else if(I(e)){let l=f(t,"browser-profile");Te(l),rt(B("icacls"),[U(e.browser),"/grant","*S-1-15-2-1:(OI)(CI)(RX)","*S-1-15-2-2:(OI)(CI)(RX)"],{stdio:"ignore",windowsHide:!0,timeout:60000});let p=i.filter((g)=>g!=="about:blank").concat("--no-startup-window","--keep-alive-for-test");a=k(e.browser,[`--user-data-dir=${l}`,...p],{detached:!0,stdio:"ignore",env:o})}else{let l=f(o.HOME,".config","google-chrome"),p=f(l,"NativeMessagingHosts");se(p,{recursive:!0,mode:448});let g=wn(e.platform).nativeHostManifests[0];ne(g,f(p,ie(g)));let _=process.geteuid?.()===0?["--no-sandbox"]:[];u=f(t,"browser.log");let h=at(u,"a",384);c=it(h).size,a=k(e.browser,[`--user-data-dir=${l}`,...i,..._,"--force-renderer-accessibility"],{detached:!0,stdio:["ignore",h,h],env:{...o,ACCESSIBILITY_ENABLED:"1"}}),st(h)}let d=!1;a.once("error",()=>{d=!0}),a.once("exit",(l)=>{d||=l!==0}),a.unref();let m=!1;if(await xe(async()=>d||(m=await n()),bt),!m){if(u&&G(u).subarray(c).toString("utf8").includes("No usable sandbox"))throw new r("automation_browser_sandbox_unavailable","Chromium found no usable sandbox on this machine. Run the worker as a non-root user with unprivileged user namespaces enabled, or in a container with seccomp unconfined.");throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.")}}async function Io(e){await Ie(e,!0)}function Do(e){return ke(e,ve(e))}function ke(e,o){return e.platform==="darwin-arm64"||I(e)?f(o,"browser-profile"):f(o,"home",".config","google-chrome")}function ve(e){let o=f(e.root,"automation");if(!M(o)||!Pt(e.automation))return e.automation;if(!Mt(ke(e,o)))try{he(o,e.automation)}catch{}return M(o)?o:e.automation}function Pt(e){try{return D(e).length===0}catch(o){return o.code==="ENOENT"}}function Mt(e){let o;try{o=ct(f(e,"SingletonLock"))}catch{return!1}let t=Number(o.slice(o.lastIndexOf("-")+1));if(!Number.isSafeInteger(t)||t<=0)return!0;try{return process.kill(t,0),!0}catch(n){return n.code==="EPERM"}}async function Ie(e,o){Br({root:e.root,automation:e.automation,extensionDir:e.extensionDir});let t=ve(e);Te(t);let n=_e().username,i={USER:n,LOGNAME:n,REASON_AUTOMATION_OCU:e.ocu,REASON_AUTOMATION_OBU:e.nativeHost};if(e.platform==="darwin-arm64"||I(e)){let l=I(e)?{...i,...Dt(),HOME:s()}:{...i,HOME:s(),PATH:`${U(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OCU:process.execPath,REASON_AUTOMATION_OCU_SUBCOMMAND:kt};if(!o)return l;await F("browser",()=>me(e,l,t));let p=await Se(e,l,t);if(!p)throw new r("automation_browser_unavailable","Reason could not connect the desktop browser.");return{...l,REASON_AUTOMATION_OBU_INSTANCE:p,REASON_AUTOMATION_BACKGROUND_TABS:"1"}}let a=await Ft(),u=f(t,"home"),c=f(t,"runtime");Te(u),Te(c);let d=f(t,"bus"),m={...i,HOME:u,PATH:`${U(e.node)}:/usr/bin:/bin`,DISPLAY:a.display,XAUTHORITY:a.xauthority,XDG_RUNTIME_DIR:c,DBUS_SESSION_BUS_ADDRESS:`unix:path=${d}`,...a.sound?{PULSE_SERVER:Kt(a.sound)}:{}};if(await F("bus",()=>Nt(d,m)),o)await F("browser",()=>me(e,m,t));return m}function Dt(){let e=process.env.SystemRoot??"C:\\Windows",o=Object.fromEntries(["SystemDrive","USERPROFILE","LOCALAPPDATA","APPDATA","ProgramData","ProgramFiles","PATHEXT","ComSpec","USERNAME","USERDOMAIN","COMPUTERNAME","NUMBER_OF_PROCESSORS","PROCESSOR_ARCHITECTURE","PSModuleAnalysisCachePath"].flatMap((n)=>process.env[n]?[[n,process.env[n]]]:[])),t=f(e,"System32");return{...o,SystemRoot:e,windir:e,TEMP:L(),TMP:L(),PATH:[t,f(t,"WindowsPowerShell","v1.0"),e].join(mt)}}async function Lt(e,o,t){let n=_e().username,i={USER:n,LOGNAME:n,HOME:s(),PATH:`${U(e.node)}:/usr/bin:/bin:/usr/sbin:/sbin`,REASON_AUTOMATION_OBU:o,REASON_AUTOMATION_BACKGROUND_TABS:"1"},a=await Ct(o,i);return t.throwIfAborted(),{...i,REASON_AUTOMATION_OBU_INSTANCE:a}}function Ut(e){if(process.platform!=="win32")return["--input-type=module","--eval",e];let o=f(L(),`reason-automation-${nt("sha256").update(e).digest("hex").slice(0,16)}.mjs`);if(!M(o)||G(o,"utf8")!==e){let t=`${o}.${process.pid}.tmp`;dt(t,e,{mode:384}),he(t,o)}return[o]}function Re(e,o,t,n){if(typeof ae!=="string")return Promise.reject(new r("automation_unavailable","This Reason build has no automation runtime."));let i=ae;return new Promise((a,u)=>{let c=k(e,Ut(i),{env:{...o,REASON_CLOUD_GATEWAY_EXEC:"1",REASON_AUTOMATION_INLINE_RESULT:"1"},stdio:["pipe","pipe","pipe"],detached:process.platform!=="win32",windowsHide:!0}),d=[],m=0,l="",p=null,g=!1,_=(w)=>{if(p??=w,process.platform==="win32"&&c.pid){k(f(process.env.SystemRoot??"C:\\Windows","System32","taskkill.exe"),["/pid",String(c.pid),"/t","/f"],{stdio:"ignore",windowsHide:!0}).once("error",()=>c.kill("SIGKILL"));return}try{process.kill(-c.pid,"SIGKILL")}catch{c.kill("SIGKILL")}},h=(w)=>{if(g)return;g=!0,clearTimeout(v),n.removeEventListener("abort",S),w()},v=setTimeout(()=>_(new r("automation_timed_out","Reason automation did not finish in time.")),_t),S=()=>_(new r("cancelled","Reason cancelled the automation call."));if(n.addEventListener("abort",S,{once:!0}),c.stdout.on("data",(w)=>{if(m+=w.byteLength,m>ft)_(new r("automation_output_too_large","Reason automation output is too large."));else d.push(w)}),c.stderr.setEncoding("utf8").on("data",(w)=>{l=(l+w).slice(-gt)}),c.stdin.on("error",()=>{}),c.once("error",()=>h(()=>u(p??new r("automation_unavailable","Reason could not start the automation runtime.")))),c.once("close",(w)=>h(()=>{if(p)u(p);else a({code:w??1,stdout:Buffer.concat(d),stderr:l})})),n.aborted)S();c.stdin.end(t)})}var x=new Map;function $t(e,o,t){for(let[i,a]of x)if(a.expiresAt<=t)x.delete(i);while(x.size>=yt)x.delete(x.keys().next().value);let n=ge();return x.set(n,{runId:e,bytes:o,expiresAt:t+wt}),n}async function Ae(e,o,t,n={}){let i=await(n.environment??Ie)(e,o.kind==="browser");return t.throwIfAborted(),await(n.runtime??Re)(e.node,i,JSON.stringify(o),t)}async function wl(e,o){let t=we({call:e});if(!("call"in t))P();let n=T();if(!n?.features.computer||t.call.kind==="browser"&&!n.features.browser)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");return await Ae(n,t.call,o)}function fe(e,o,t){let n=e.stdout.byteLength>H?$t(o,e.stdout,t):void 0;return{code:e.code,stderr:e.stderr,instance_id:xt,output_bytes:e.stdout.byteLength,chunk:e.stdout.subarray(0,H).toString("base64"),...n?{output_id:n}:{}}}async function Oo(e,o={}){let t=we(e.payload),n=(o.now??Date.now)();if("output_id"in t){let h=x.get(t.output_id);if(!h||h.runId!==e.runId||h.expiresAt<=n||t.offset>h.bytes.byteLength)throw new r("automation_output_unavailable","Reason automation output expired.");return{chunk:h.bytes.subarray(t.offset,t.offset+H).toString("base64")}}let i=(o.components??T)(),a=(o.platform??process.platform)==="darwin",u=a?(o.macIdentity??kr)():[],c=o.macSetup??C,d=!i?.features.computer||t.call.kind==="browser"&&!t.userChrome&&!i.features.browser;if(a&&(d||u.length===0||t.call.kind==="browser"&&t.userChrome&&!e.userChrome))return fe(await oe({runId:e.runId,call:t.call,identity:u,desktopMissing:d,signal:e.signal},c),e.runId,n);if(!i?.features.computer)throw new r("automation_unavailable","Run `reason desktop install` on this machine to enable computer and browser use.");let m=t.userChrome?e.userChrome:void 0;if(t.userChrome&&!m)throw new r("automation_user_chrome_unavailable","Your own Chrome is not enabled on this computer: run `reason desktop install` on this Mac (and `reason connect --user-chrome on` if you turned it off).");if(t.call.kind==="browser"&&!m&&!i.features.browser)throw new r("automation_browser_not_installed",!i.platform.startsWith("linux")?"Browser use is unavailable on this machine: re-run `reason desktop install`.":"Browser use is unavailable on this machine: install a non-snap Chromium at /usr/bin/chromium, then re-run `reason desktop install`.");e.signal.throwIfAborted();let l=t.call.kind==="browser"&&t.call.operation!=="record_start"&&t.call.operation!=="record_stop",p=await pa(e.runId,e.signal,o.now,l?"call":"run"),g="account"in o?o.account??null:ue(),_;try{if(m){let h=await(o.userChromeEnvironment??Lt)(i,m,e.signal);e.signal.throwIfAborted(),_=await(o.runtime??Re)(i.node,h,JSON.stringify(t.call),e.signal)}else if(g)_=await(o.delegate??z)(g,t.call,e.signal);else _=await Ae(i,t.call,e.signal,o)}finally{p()}if(a)_=await re({runId:e.runId,call:t.call,identity:u,output:_,signal:e.signal},c);return fe(_,e.runId,n)}
|
|
956
|
+
export{nn,hr,To,Io,Do,wl,Oo};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{w}from"./vm-hands-entry-lite-q9s1e2y1.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 ma(t=l()){return c(t).replace(/\.json$/,"-login.json")}function ga(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 _a(t,e=l()){k(N(c(e)),{recursive:!0}),b(c(e),`${JSON.stringify(t)}
|
|
3
|
+
`,{mode:384}),y(p(e),{force:!0})}function Ur(t=l()){let e=A(t);return e?{orgId:e.orgId,team:e.team}:null}function zr(t){let e=f(t);return e&&e.machines.length>0?{teamId:e.team,teamName:e.name,secret:e.secret}:null}
|
|
4
|
+
export{ma,ga,_a,Ur,zr};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{randomBytes as z}from"crypto";import{chmodSync as H,closeSync as B,constants as yn,linkSync as Q,lstatSync as w,mkdirSync as Z,openSync as dn,readdirSync as E,readFileSync as Y,readlinkSync as v,renameSync as D,rmdirSync as x,symlinkSync as h,unlinkSync as g}from"fs";import{createRequire as gn}from"module";import{constants as pn}from"os";import{basename as O,join as s,sep as bn}from"path";import{existsSync as R,lstatSync as U,readdirSync as an,readFileSync as ln,readlinkSync as un,realpathSync as fn}from"fs";import{join as d,sep as mn}from"path";function K(n,...r){let e=d(n,"ara"),t=d(n,"reason");if(!Ni(e))return d(t,...r);if(!R(t))return d(e,...r);return R(d(e,...r))&&!R(d(t,...r))?d(e,...r):d(t,...r)}function Ni(n){try{let r=U(n);if(!r.isSymbolicLink())return r.isDirectory();return un(n)!=="reason"&&R(n)}catch{return!1}}function W(n,r=[]){if(!Ni(n))return!1;let e;try{e=[n,...an(n,{withFileTypes:!0}).filter((t)=>t.isDirectory()).map((t)=>d(n,t.name))]}catch{return!1}return e.some((t)=>["connect","connect-once"].filter((i)=>!r.includes(d(t,i))).some((i)=>{let c=d(t,i,"worker.json");try{U(c)}catch{return!1}try{let a=JSON.parse(ln(c,"utf8"))?.stateDirectory;if(typeof a!=="string")return!0;let l=(o,u)=>o===u||o.startsWith(u+mn);return l(a,n)||l(X(a),X(n))}catch{return!0}}))}function X(n){try{return fn(n)}catch{return n}}var j=new Set(["credentials.json","local-device.json","local-device.revoked.json","local-device.auth-migration.json","local-device.json.registration-pending.json","local-daemon.json","local-daemon.json.workspaces.json","local-root-fingerprint-key.json","instances","workspaces"]),F=new Set(["local-device.proxy.json"]),kn=new Set(["local-device.key","local-device.binding"]),q=new Map;function De(n,r,e){let t=s(n,"ara");if(process.platform==="win32"||/[/\\]\.reason-ssh[/\\][^/\\]+[/\\]installer-home[/\\]\.config$/.test(n))return{state:f(t)?.isDirectory()?"kept":"absent"};return rn(t,s(n,"reason"),{linkAlways:!0,kept:(i)=>W(i,e??[]),native:r===void 0?wt:()=>r},e!==void 0)}function yt(n,...r){return De(n),K(n,...r)}function es(n,r=process.platform){if(r==="win32")return s(n,"AppData","Local","Reason","Logs");let e=s(n,"Library","Logs");if(r==="darwin")for(let t of[""," Staging"," Development"])rn(s(e,`Ara${t}`),s(e,`Reason${t}`),{linkAlways:!1,kept:()=>!1,native:wt});return s(e,"Reason")}var nn="config_rename_unavailable:busy";function rn(n,r,e,t=!1){let i=t?void 0:q.get(n);if(i)return i;let c;try{c=En(n,r,e)}catch(a){let l=`config_rename_unavailable:${k(a)??"failed"}`;try{return{state:f(n)?.isDirectory()?"kept":"absent",problem:l}}catch{return{state:"kept",problem:l}}}if(!(c.state==="absent"&&e.linkAlways)&&c.problem!==nn&&!(c.state==="kept"&&!c.problem))q.set(n,c);return c}function En(n,r,e){vn(r,e.native);let t=!1;for(let i=0;i<8;i+=1){let c=f(n);if(c?.isSymbolicLink())return v(n)===O(r)?{state:t?"renamed":"linked"}:{state:"kept"};if(!c){if(A(r))m(()=>g(r),"ENOENT");if(!(t||e.linkAlways)||!N(r))return{state:"absent"};let o=_(r,"link");h(O(r),o);try{m(()=>D(o,n),"EISDIR","ENOTEMPTY","EEXIST","ENOTDIR")}finally{m(()=>g(o),"ENOENT")}continue}if(!c.isDirectory())return{state:"absent"};if(e.kept(n))return G(r),{state:"kept"};let a=e.native();if(!a)return G(r),{state:"kept",problem:"config_rename_unavailable:no_native"};let l=Nn(a,n);if(!l)return{state:"kept",problem:nn};try{if(w(n).isSymbolicLink())continue;let o=Sn(a,n,r);if(o)return{state:"kept",problem:o};t=!0}finally{l()}}throw Object.assign(Error("legacy directory rename did not settle"),{code:"unsettled"})}function Sn(n,r,e){let t=f(e);if(!t||A(e)){if(!t)h(O(e),e);try{n.exchange(r,e)}catch(o){if(A(e))m(()=>g(e),"ENOENT");return`config_rename_unavailable:${k(o)??"exchange_failed"}`}return null}if(!t.isDirectory())return"config_rename_unavailable:ENOTDIR";if(t.dev!==w(r).dev)return"config_rename_unavailable:EXDEV";let i=[_(e,"probe"),_(e,"probe")];try{h("a",i[0]),h("b",i[1]),n.exchange(i[0],i[1])}catch(o){return`config_rename_unavailable:${k(o)??"exchange_failed"}`}finally{for(let o of i)m(()=>g(o),"ENOENT")}let c=cn(e);for(let o of kn){let u=f(s(e,o)),y=f(s(r,o));if(u&&y&&u.ino!==y.ino)Z(`${c}-replaced`,{mode:448,recursive:!0}),D(s(e,o),s(`${c}-replaced`,o))}let a={linked:new Map,unitsKept:new Set};en(r,e,"",a);let l=_(e,"rename");h(O(e),l);try{n.exchange(r,l)}catch(o){return m(()=>g(l),"ENOENT"),`config_rename_unavailable:${k(o)??"exchange_failed"}`}return tn(l,e,a,c),null}function M(n){return n===""||!n.includes(bn)}function en(n,r,e,t){let i=M(e)&&I(s(r,e),s(n,e));if(i)t.unitsKept.add(e);for(let c of E(s(n,e))){if(i&&(j.has(c)||F.has(c)))continue;let a=s(e,c),l=s(n,a),o=s(r,a),u=f(l);if(!u)continue;let y=f(o);if(u.isDirectory()){if(!y)m(()=>Z(o,{mode:u.mode&4095}),"EEXIST"),H(o,u.mode&4095);if(N(o))en(n,r,a,t)}else if(!y){if(u.isSymbolicLink())m(()=>h(v(l),o),"EEXIST");else if(m(()=>Q(l,o),"EEXIST","ENOENT"))t.linked.set(a,u.ino)}}}function vn(n,r){let e;try{if(!N(n))return;e=E(n)}catch{return}for(let t of e){let i=/^\.(rename|link|probe|claim)-(\d+)-[0-9a-f]+$/.exec(t);if(!i)continue;let c=s(n,t),a=f(c);if(!a)continue;if(!a.isDirectory()){if(!J(Number(i[2])))m(()=>g(c),"ENOENT");continue}let l=r(),o=null;if(l){try{o=l.lock(c)}catch{continue}if(!o)continue}else if(J(Number(i[2])))continue;try{let u=_(n,"claim");if(m(()=>D(c,u),"ENOENT"))tn(u,n,null,cn(n))}finally{o?.()}}}function tn(n,r,e,t){for(let[i,c]of e?.linked??[])if(!f(s(n,i))&&f(s(r,i))?.ino===c)m(()=>g(s(r,i)),"ENOENT");if(on(n,r,"",e),m(()=>x(n),"ENOTEMPTY","EEXIST"))return;D(n,t),H(t,448)}function on(n,r,e,t){let i=M(e)&&(t?t.unitsKept.has(e):I(s(r,e),s(n,e)));for(let c of E(s(n,e))){let a=s(e,c),l=s(n,a),o=s(r,a),u=w(l),y=f(o);if(y&&u.ino===y.ino&&u.dev===y.dev){g(l);continue}if(u.isFile()&&y?.isFile()&&t?.linked.get(a)===y.ino){D(l,o);continue}if(i&&(j.has(c)||F.has(c)))continue;if(!y){if(u.isFile()){if(m(()=>Q(l,o),"EEXIST"))g(l)}else m(()=>D(l,o),"EEXIST","ENOTEMPTY");continue}if(u.isDirectory()&&y.isDirectory())on(n,r,a,t),m(()=>x(l),"ENOTEMPTY","EEXIST")}}function mc(n){let r=s(n,"ara"),e=s(n,"reason");if(!N(r)||!N(e))return null;let t=["",...E(r,{withFileTypes:!0}).filter((i)=>i.isDirectory()&&!i.name.startsWith(".")).map((i)=>i.name)];for(let i of t){let c=s(r,i),a=s(e,i);if(!I(c,a)||!I(a,c))continue;if([...j,...F].some((o)=>P(s(c,o),s(a,o))===!1))return i}return null}function gc(n){let r=s(n,"ara"),e=s(n,"reason");if(!N(r)||!N(e))return null;let t=(i)=>{for(let c of E(s(r,i))){let a=s(i,c);if(M(i)&&(c==="connect"||c==="connect-once"))continue;let l=w(s(r,a)),o=f(s(e,a));if(!o||l.ino===o.ino&&l.dev===o.dev)continue;if(l.isDirectory()&&o.isDirectory()&&!o.isSymbolicLink()){let u=t(a);if(u!==null)return u}else if(l.isSymbolicLink()||o.isSymbolicLink()){if(!(l.isSymbolicLink()&&o.isSymbolicLink()&&v(s(r,a))===v(s(e,a))))return a}else if(P(s(r,a),s(e,a))!==!0)return a}return null};return t("")}function P(n,r){let e=f(n),t=f(r);if(!e&&!t)return null;if(!e||!t||e.isDirectory()!==t.isDirectory())return!1;if(e.ino===t.ino&&e.dev===t.dev)return!0;if(e.isDirectory())return[...new Set([...E(n),...E(r)])].every((c)=>P(s(n,c),s(r,c))===!0);try{return Y(n).equals(Y(r))}catch{return!1}}function I(n,r){for(let e of j)if(sn(s(n,e),s(r,e)))return!0;return!1}function sn(n,r){let e=f(n);if(!e)return!1;let t=f(r);if(!t)return!0;if(e.isDirectory()){if(!t.isDirectory())return!0;return E(n).some((i)=>sn(s(n,i),s(r,i)))}if(e.isSymbolicLink())return!t.isSymbolicLink()||v(n)!==v(r);return e.ino!==t.ino||e.dev!==t.dev}function G(n){if(A(n))m(()=>g(n),"ENOENT")}function cn(n){return s(n,`.pre-rename-${new Date().toISOString().replace(/[:.]/g,"-")}-${z(3).toString("hex")}`)}function A(n){try{return w(n).isSymbolicLink()&&v(n)===O(n)}catch{return!1}}function N(n){let r=f(n);return r!==null&&r.isDirectory()}function Nn(n,r){for(let e=0;e<40;e+=1){let t=n.lock(r);if(t)return t;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,50)}return null}function _(n,r){return s(n,`.${r}-${process.pid}-${z(6).toString("hex")}`)}function J(n){if(n===process.pid)return!1;try{return process.kill(n,0),!0}catch(r){return k(r)==="EPERM"}}function f(n){try{return w(n)}catch(r){if(k(r)==="ENOENT"||k(r)==="ENOTDIR")return null;throw r}}function m(n,...r){try{return n(),!0}catch(e){if(r.includes(k(e)??""))return!1;throw e}}function k(n){return n instanceof Error&&"code"in n&&typeof n.code==="string"?n.code:void 0}var T,hn=2,Dn=4,wn=2,Tn=2,V=-100;function wt(){if(T!==void 0)return T;if(T=null,process.platform!=="linux"&&process.platform!=="darwin")return null;let n;try{n=gn(import.meta.url)("bun:ffi")}catch{return null}let r=process.platform==="darwin",e=r?"__error":"__errno_location",t=r?["/usr/lib/libSystem.B.dylib"]:["libc.so.6",`libc.musl-${process.arch==="arm64"?"aarch64":"x86_64"}.so.1`],{FFIType:i}=n;for(let c of t)try{let a=r?"renamex_np":"renameat2",o=n.dlopen(c,{flock:{args:[i.i32,i.i32],returns:i.i32},[e]:{args:[],returns:i.ptr},[a]:r?{args:[i.ptr,i.ptr,i.u32],returns:i.i32}:{args:[i.i32,i.ptr,i.i32,i.ptr,i.u32],returns:i.i32}}).symbols,u=o[e]();if(u===null)continue;let y=(S)=>{let b=n.read.i32(u),p=Object.entries(pn.errno).find(([,L])=>L===b)?.[0]??`errno_${b}`;return Object.assign(Error(`${S} failed: ${p}`),{code:p})},C=(S)=>Buffer.from(`${S}\x00`,"utf8");return T={exchange(S,b){let p=C(S),L=C(b);if((r?o[a](n.ptr(p),n.ptr(L),wn):o[a](V,n.ptr(p),V,n.ptr(L),Tn))!==0)throw y("exchange")},lock(S){let b=dn(S,yn.O_RDONLY);if(o.flock(b,hn|Dn)===0)return()=>B(b);let p=y("lock");if(B(b),p.code==="EWOULDBLOCK"||p.code==="EAGAIN")return null;throw p}},T}catch{}return null}
|
|
3
|
+
export{Ni,De,yt,es,mc,gc,wt};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{te}from"./vm-hands-entry-lite-9g52kxyj.js";import{_r}from"./vm-hands-entry-lite-jpvmkce5.js";import{dn}from"./vm-hands-entry-lite-zh6ncdjn.js";import{Se}from"./vm-hands-entry-lite-pxtycfdv.js";import{Ve}from"./vm-hands-entry-lite-zawytz09.js";import{Dt}from"./vm-hands-entry-lite-ab1pq3xg.js";import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{existsSync as D,realpathSync as W,statSync as J}from"fs";import{platform as h}from"os";import{isAbsolute as q,sep as X}from"path";import{existsSync as F}from"fs";import{createRequire as H}from"module";var k=Dt(dn)(()=>H(import.meta.url)("bun:ffi"),F);function fi(){return process.platform==="win32"&&typeof globalThis.Bun<"u"&&k.available()}function E(e=process.env){return k.defaultShell(e)}function C(e){return k.shellArgs(e)}function M(e){let n=k.spawn({...e,env:e.environment});return n.exited.then(()=>n.close()),{write:(o)=>n.write(o),resize:(o,t)=>n.resize(o,t),kill:()=>n.close(),exited:n.exited}}var mi=43200000,an=_r,gi=4,Y=/^[A-Za-z0-9._:-]{1,160}$/,K=1000;function z(e){return Boolean(e)&&typeof e==="object"&&!Array.isArray(e)}function P(e,n){if(typeof e!=="number"||!Number.isFinite(e)||e<=0)return n;return Math.min(K,Math.max(1,Math.floor(e)))}function G(e,n=Date.now()){let o=["relay_url","session_id","expires_at"],t=new Set([...o,"cols","rows","cwd","workspace"]);if(!z(e)||o.some((b)=>!(b in e))||Object.keys(e).some((b)=>!t.has(b)))throw new r("invalid_pty_request","Reason terminal request is malformed.");let{relay_url:c,session_id:m,expires_at:g}=e;if(typeof c!=="string")throw new r("invalid_pty_request","Reason terminal relay URL is missing.");let d;try{d=new URL(c)}catch{throw new r("invalid_pty_request","Reason terminal relay URL is invalid.")}if(d.protocol!=="wss:"&&d.protocol!=="ws:"||d.username||d.password)throw new r("invalid_pty_request","Reason terminal relay URL is invalid.");if(typeof m!=="string"||!Y.test(m))throw new r("invalid_pty_request","Reason terminal session identity is invalid.");let p=typeof g==="string"?Date.parse(g):Number.NaN;if(!Number.isFinite(p)||p<=n)throw new r("invalid_pty_request","Reason terminal session has already expired.");if(e.cwd!==void 0&&typeof e.cwd!=="string")throw new r("invalid_pty_request","Reason terminal working directory is invalid.");let a=e.workspace===void 0?void 0:te(e.workspace);if(a===null||a&&e.cwd!==void 0)throw new r("invalid_pty_request","Reason terminal workspace is invalid.");return{relay_url:c,session_id:m,expires_at:new Date(Math.min(p,n+mi)).toISOString(),cols:P(e.cols,80),rows:P(e.rows,24),...e.cwd===void 0?{}:{cwd:e.cwd},...a?{workspace:a}:{}}}function Q(e,n){if(h()==="win32")[e,n]=[e.toLowerCase(),n.toLowerCase()];return n===e||n.startsWith(e+X)}function N(e,n){if(n===void 0)return e;if(!q(n))throw new r("pty_cwd_invalid","Reason terminal working directory must be absolute.");let o;try{o=W(n)}catch{throw new r("pty_cwd_invalid","Reason terminal working directory does not exist.")}if(!Q(e,o))throw new r("pty_cwd_outside_root","Reason terminal working directory escapes the granted root.");if(!J(o).isDirectory())throw new r("pty_cwd_invalid","Reason terminal working directory is not a directory.");return o}function Yc(e=process.env){if(h()==="win32")return E(e);let n=e.SHELL;if(n&&q(n)&&D(n))return n;for(let o of h()==="darwin"?["/bin/zsh","/bin/bash","/bin/sh"]:["/bin/bash","/bin/sh"])if(D(o))return o;return"/bin/sh"}function V(){let e=globalThis.Bun;if(!e)throw new r("pty_unavailable","Reason terminals require the Bun runtime.");return e.spawn}function Lo(){if(h()==="win32")return fi();return typeof globalThis.Bun<"u"}var Z=(e)=>{if(h()==="win32")try{return M({...e,file:e.shell,args:C(e.shell),environment:{...e.environment,TERM:"xterm-256color"}})}catch{throw new r("pty_unavailable","Reason could not allocate a pseudo-terminal.")}let n=V()({cmd:[e.shell,"-i","-l"],cwd:e.cwd,env:{...e.environment,TERM:"xterm-256color"},terminal:{cols:e.cols,rows:e.rows,data:(t,c)=>{e.onData(c)}}}),o=n.terminal;if(!o){try{n.kill()}catch{}throw new r("pty_unavailable","Reason could not allocate a pseudo-terminal.")}return{write:(t)=>o.write(t),resize:(t,c)=>o.resize(t,c),kill:()=>{try{n.kill()}catch{}},exited:n.exited.then((t)=>typeof t==="number"?t:null,()=>null)}},_i=(e,n)=>n===void 0?new WebSocket(e):new WebSocket(e,{proxy:n}),v=new Set;function ee(e){if(v.size>=gi||v.has(e))return null;v.add(e);let n=!1;return()=>{if(n)return;n=!0,v.delete(e)}}async function $o(e,n={}){let o=n.now??Date.now,t=G(e.payload,o()),c=ee(e.operationId);if(!c)throw new r("pty_slot_busy","This Reason Device already runs the maximum number of terminals.");let m=o(),g,d,p;try{let a=t.workspace?Ve(e.root,t.workspace):void 0;g=a?N(D(a.boundary)?W(a.boundary):a.boundary,a.path):N(e.root,t.cwd),d=n.environment??process.env,p=n.shellPath??Yc(d)}catch(a){throw c(),a}return await new Promise((a,b)=>{let w=null,i=null,S=!1,x=!1,y=!1,T=null,U=0,B=0,O=[],R=0,A=null,l=(s)=>{if(y)return;if(y=!0,A)clearTimeout(A);e.signal.removeEventListener("abort",L);try{w?.kill()}catch{}try{i?.close(1000,"pty_session_over")}catch{}if(c(),s.kind==="rejected"){b(s.error);return}let u={reason:s.reason,exit_code:T,output_bytes:U,input_bytes:B,duration_ms:Math.max(0,o()-m)};e.emitEvent("pty.stopped",{...u}).catch(()=>{return}),a({...u})},L=()=>{let s=e.signal.reason;l({kind:"rejected",error:s instanceof r?s:new r("cancelled","Reason closed the terminal session.")})};if(e.signal.aborted){L();return}e.signal.addEventListener("abort",L,{once:!0}),A=setTimeout(()=>l({kind:"resolved",reason:"session_expired"}),Math.max(1,Date.parse(t.expires_at)-o()));let I=(s)=>{if(U+=s.byteLength,!S||!i){if(O.push(s),R+=s.byteLength,R>an)l({kind:"resolved",reason:"output_backpressure"});return}try{i.send(s)}catch{l({kind:"resolved",reason:"relay_closed"});return}if(i.bufferedAmount>an)l({kind:"resolved",reason:"output_backpressure"})};try{w=(n.spawnPty??Z)({shell:p,args:["-i","-l"],cwd:g,cols:t.cols,rows:t.rows,environment:d,onData:(s)=>{if(!y)I(s)}})}catch(s){l({kind:"rejected",error:s instanceof r?s:new r("pty_spawn_failed","Reason could not start the terminal shell.")});return}w.exited.then((s)=>{if(y)return;if(T=s,S&&i)try{i.send(JSON.stringify({t:"exit",code:s}))}catch{}l({kind:"resolved",reason:"shell_exited"})});let j=(n.loadProxy??Se)()?.url;try{i=(n.connect??_i)(t.relay_url,j)}catch{l({kind:"rejected",error:new r("pty_relay_unavailable","Reason could not reach the terminal relay.")});return}i.binaryType="arraybuffer",i.onopen=()=>{if(y||!i)return;S=!0;try{i.send(JSON.stringify({t:"open",cols:t.cols,rows:t.rows}));for(let s of O.splice(0))i.send(s);R=0}catch{l({kind:"resolved",reason:"relay_closed"});return}x=!0,e.emitEvent("pty.ready",{session_id:t.session_id,cols:t.cols,rows:t.rows}).catch(()=>{return})},i.onmessage=(s)=>{if(y||!w)return;let u=s.data;if(typeof u==="string"){let f;try{f=JSON.parse(u)}catch{return}if(!z(f))return;if(f.t==="resize"){try{w.resize(P(f.cols,t.cols),P(f.rows,t.rows))}catch{}return}if(f.t==="close")l({kind:"resolved",reason:"client_closed"});return}let _=u instanceof ArrayBuffer?new Uint8Array(u):ArrayBuffer.isView(u)?new Uint8Array(u.buffer,u.byteOffset,u.byteLength):null;if(!_||_.byteLength===0)return;B+=_.byteLength;try{w.write(_)}catch{}},i.onclose=()=>{if(y)return;if(!x){l({kind:"rejected",error:new r("pty_relay_unavailable","Reason could not reach the terminal relay.")});return}l({kind:"resolved",reason:"relay_closed"})},i.onerror=()=>{if(y||x)return;l({kind:"rejected",error:new r("pty_relay_unavailable","Reason could not reach the terminal relay.")})}})}
|
|
3
|
+
export{fi,mi,an,gi,Yc,Lo,_i,$o};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{execFile as se,spawn as E}from"child_process";var
|
|
2
|
+
import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{execFile as se,spawn as E}from"child_process";var vc="h264_ws_v1",Sc="video",Sr=["smooth","sharp","data_saver","balanced"];var Ec="video_presets";var M=8388608,O=65536,kc="control",xc="v1",X=200;function ts(t){if(!t||typeof t!=="object"||Array.isArray(t))return null;let e=t,n=(i)=>typeof i==="string"&&i.length>0&&i.length<=X;if(Object.keys(e).length!==2||!n(e.user_id)||!n(e.name))return null;return{user_id:e.user_id,name:e.name}}var Cc="windows",Ac="v1",Pc="look",Rc="v1",J=["reason","grok"];function rs(t){return typeof t==="string"&&J.includes(t)?t:null}var _=200,Z=(t)=>typeof t==="string"&&Sr.includes(t);function Tc(t){if(!t||typeof t!=="object"||Array.isArray(t))return null;let e=t;if(Object.keys(e).length!==2||e.format!=="h264_ws_v1"||!Z(e.preset))return null;return{format:"h264_ws_v1",preset:e.preset}}var o={hello:1,frame:2,stats:3,pong:4,serverClipboard:5,error:6,audioHello:7,audio:8,control:9,windows:10,pointer:16,key:17,config:18,ping:19,clientClipboard:20,keyframeRequest:21,ack:22,audioEnable:23,resize:24};class l extends Error{constructor(t){super(t);this.name="DisplayVideoProtocolError"}}var Q=new TextEncoder,ee=new TextDecoder("utf-8",{fatal:!0});function p(t,e){if(e.byteLength+1>M)throw new l("message_too_large");let n=new Uint8Array(5+e.byteLength),i=new DataView(n.buffer);return i.setUint32(0,e.byteLength+1),i.setUint8(4,t),n.set(e,5),n}function w(t){let e=Q.encode(t);if(e.byteLength>O)throw new l("text_too_large");return e}function m(t,e){if(!Number.isInteger(t)||t<0||t>65535)throw new l(`invalid_${e}`);return t}function te(t){if(!Number.isFinite(t))throw new l("invalid_window");return Math.max(-2147483648,Math.min(2147483647,Math.round(t)))}function Rn(t){switch(t.type){case"hello":{let e=w(t.codec),n=new Uint8Array(6+e.byteLength),i=new DataView(n.buffer);return i.setUint16(0,m(t.width,"width")),i.setUint16(2,m(t.height,"height")),i.setUint8(4,Math.max(1,Math.min(240,Math.round(t.fps)))),i.setUint8(5,Sr.indexOf(t.preset)),n.set(e,6),p(o.hello,n)}case"frame":{let e=new Uint8Array(13+t.data.byteLength),n=new DataView(e.buffer);return n.setUint8(0,t.key?1:0),n.setUint32(1,t.seq>>>0),n.setBigUint64(5,BigInt(Math.max(0,Math.floor(t.captureMicros)))),e.set(t.data,13),p(o.frame,e)}case"stats":return p(o.stats,w(JSON.stringify(t.stats)));case"pong":case"ping":{let e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t.token),p(t.type==="ping"?o.ping:o.pong,e)}case"serverClipboard":return p(o.serverClipboard,w(t.text));case"clientClipboard":return p(o.clientClipboard,w(t.text));case"error":return p(o.error,w(t.code));case"pointer":{let e=new Uint8Array(5),n=new DataView(e.buffer);return n.setUint16(0,m(t.x,"x")),n.setUint16(2,m(t.y,"y")),n.setUint8(4,t.buttons&255),p(o.pointer,e)}case"key":{let e=new Uint8Array(5),n=new DataView(e.buffer);return n.setUint8(0,t.down?1:0),n.setUint32(1,t.keysym>>>0),p(o.key,e)}case"config":return p(o.config,Uint8Array.of(Sr.indexOf(t.preset)));case"keyframeRequest":return p(o.keyframeRequest,new Uint8Array(0));case"audioHello":{let e=w(t.codec),n=new Uint8Array(5+e.byteLength),i=new DataView(n.buffer);return i.setUint32(0,t.sampleRate>>>0),i.setUint8(4,t.channels&255),n.set(e,5),p(o.audioHello,n)}case"audio":{let e=new Uint8Array(8+t.data.byteLength);return new DataView(e.buffer).setBigUint64(0,BigInt(Math.max(0,Math.floor(t.captureMicros)))),e.set(t.data,8),p(o.audio,e)}case"control":return p(o.control,w(JSON.stringify(t.control)));case"windows":{let e=t.bounds.slice(0,_),n=new Uint8Array(e.length*16),i=new DataView(n.buffer);return e.forEach((s,a)=>{[s.x,s.y,s.width,s.height].forEach((c,d)=>i.setInt32(a*16+d*4,te(c)))}),p(o.windows,n)}case"audioEnable":return p(o.audioEnable,Uint8Array.of(t.on?1:0));case"resize":{let e=new Uint8Array(4),n=new DataView(e.buffer);return n.setUint16(0,m(t.width,"width")),n.setUint16(2,m(t.height,"height")),p(o.resize,e)}case"ack":{let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t.seq>>>0),p(o.ack,e)}}}function L(t){let e=Sr[t];if(!e)throw new l("invalid_preset");return e}function y(t,e){if(t.byteLength!==e)throw new l("invalid_length")}function S(t){if(t.byteLength>O)throw new l("text_too_large");try{return ee.decode(t)}catch{throw new l("invalid_text")}}function ne(t){let e;try{e=JSON.parse(S(t))}catch{throw new l("invalid_stats")}let n=e;if(!n||typeof n!=="object"||["fps","kbps","dropped","restarts","queued_bytes"].some((s)=>typeof n[s]!=="number"||!Number.isFinite(n[s])))throw new l("invalid_stats");return{fps:n.fps,kbps:n.kbps,dropped:n.dropped,restarts:n.restarts,queued_bytes:n.queued_bytes}}function re(t){let e;try{e=JSON.parse(S(t))}catch{throw new l("invalid_control")}let n=e;if(!n||typeof n!=="object"||typeof n.you!=="boolean"||typeof n.same_user!=="boolean")throw new l("invalid_control");let i=n.holder===null?null:ts(n.holder);if(i===null&&n.holder!==null)throw new l("invalid_control");return{holder:i,you:n.you,same_user:n.same_user}}function ie(t,e){let n=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(t){case o.hello:if(e.byteLength<6)throw new l("invalid_length");return{type:"hello",width:n.getUint16(0),height:n.getUint16(2),fps:n.getUint8(4),preset:L(n.getUint8(5)),codec:S(e.subarray(6))};case o.frame:if(e.byteLength<14)throw new l("invalid_length");if(n.getUint8(0)>1)throw new l("invalid_frame_flags");return{type:"frame",key:n.getUint8(0)===1,seq:n.getUint32(1),captureMicros:Number(n.getBigUint64(5)),data:e.subarray(13)};case o.stats:return{type:"stats",stats:ne(e)};case o.ping:case o.pong:return y(e,8),{type:t===o.ping?"ping":"pong",token:n.getFloat64(0)};case o.serverClipboard:return{type:"serverClipboard",text:S(e)};case o.clientClipboard:return{type:"clientClipboard",text:S(e)};case o.error:return{type:"error",code:S(e)};case o.pointer:return y(e,5),{type:"pointer",x:n.getUint16(0),y:n.getUint16(2),buttons:n.getUint8(4)};case o.key:if(y(e,5),n.getUint8(0)>1)throw new l("invalid_key_flags");return{type:"key",down:n.getUint8(0)===1,keysym:n.getUint32(1)};case o.config:return y(e,1),{type:"config",preset:L(n.getUint8(0))};case o.keyframeRequest:return y(e,0),{type:"keyframeRequest"};case o.audioHello:if(e.byteLength<5)throw new l("invalid_length");return{type:"audioHello",sampleRate:n.getUint32(0),channels:n.getUint8(4),codec:S(e.subarray(5))};case o.audio:if(e.byteLength<9)throw new l("invalid_length");return{type:"audio",captureMicros:Number(n.getBigUint64(0)),data:e.subarray(8)};case o.audioEnable:if(y(e,1),n.getUint8(0)>1)throw new l("invalid_audio_flags");return{type:"audioEnable",on:n.getUint8(0)===1};case o.resize:return y(e,4),{type:"resize",width:n.getUint16(0),height:n.getUint16(2)};case o.control:return{type:"control",control:re(e)};case o.windows:{if(e.byteLength%16!==0||e.byteLength>_*16)throw new l("invalid_length");let i=[];for(let s=0;s<e.byteLength;s+=16)i.push({x:n.getInt32(s),y:n.getInt32(s+4),width:n.getInt32(s+8),height:n.getInt32(s+12)});return{type:"windows",bounds:i}}case o.ack:return y(e,4),{type:"ack",seq:n.getUint32(0)};default:return null}}class ns{buffer=new Uint8Array(0);push(t){let e=new Uint8Array(this.buffer.byteLength+t.byteLength);e.set(this.buffer),e.set(t,this.buffer.byteLength);let n=[],i=0;while(e.byteLength-i>=4){let s=new DataView(e.buffer,e.byteOffset+i,4).getUint32(0);if(s<1||s>M)throw new l("invalid_message_length");if(e.byteLength-i-4<s)break;let a=e[i+4],c=e.slice(i+5,i+4+s),d=ie(a,c);if(d)n.push(d);i+=4+s}return this.buffer=e.slice(i),n}}var j="/usr/bin/osascript",oe=5000,ae=1048576,ce=String.raw`
|
|
3
3
|
ObjC.import("CoreGraphics");
|
|
4
4
|
ObjC.import("ApplicationServices");
|
|
5
5
|
ObjC.import("AppKit");
|
|
@@ -29,7 +29,7 @@ function run(argv) {
|
|
|
29
29
|
const text = clipboard.stringForType($.NSPasteboardTypeString);
|
|
30
30
|
if (!text) continue;
|
|
31
31
|
const bytes = text.dataUsingEncoding($.NSUTF8StringEncoding);
|
|
32
|
-
if (Number(bytes.length) > ${
|
|
32
|
+
if (Number(bytes.length) > ${O}) continue;
|
|
33
33
|
stdout.writeData($("c " + bytes.base64EncodedStringWithOptions(0).js + "\n").dataUsingEncoding($.NSUTF8StringEncoding));
|
|
34
34
|
}
|
|
35
35
|
return;
|
|
@@ -70,7 +70,7 @@ function run(argv) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
`;function q(t){let e;try{e=JSON.parse(t)}catch{return null}if(!e||typeof e!=="object")return null;let n=e,i=(c)=>typeof c==="number"&&Number.isFinite(c)?Math.min(65535,Math.round(c)):0;if(typeof n.screen!=="boolean"||typeof n.accessibility!=="boolean")return null;let s=i(n.width),a=i(n.height);return s>0&&a>0?{screen:n.screen,accessibility:n.accessibility,width:s,height:a}:null}function v(t,...e){let[n,...i]=[...t,j,"-l","JavaScript","-e",ce,...e];return[n,i]}function H(t,...e){return new Promise((n)=>{se(...v(t,...e),{env:{},timeout:oe,killSignal:"SIGKILL",maxBuffer:65536,encoding:"utf8"},(i,s)=>n(i?null:q(s.split(`
|
|
73
|
-
`)[0]??"")))})}function
|
|
73
|
+
`)[0]??"")))})}function Xt(t=[]){return H(t,"probe")}function Er(t,e){return H(t,"request",...e?[e]:[])}var N=2,ue=8,le=String.raw`
|
|
74
74
|
ObjC.import("CoreGraphics");
|
|
75
75
|
ObjC.import("Foundation");
|
|
76
76
|
ObjC.bindFunction("getppid", ["int", []]);
|
|
@@ -84,7 +84,7 @@ function run() {
|
|
|
84
84
|
const list = ObjC.castRefToObject($.CGWindowListCopyWindowInfo($.kCGWindowListOptionOnScreenOnly | $.kCGWindowListExcludeDesktopElements, 0));
|
|
85
85
|
const bounds = [];
|
|
86
86
|
const count = Number(list.count);
|
|
87
|
-
for (let i = 0; i < count && bounds.length < ${
|
|
87
|
+
for (let i = 0; i < count && bounds.length < ${_}; i++) {
|
|
88
88
|
const window = list.objectAtIndex(i);
|
|
89
89
|
if (Number(window.objectForKey("kCGWindowLayer").js) !== 0) continue;
|
|
90
90
|
const b = window.objectForKey("kCGWindowBounds");
|
|
@@ -101,12 +101,12 @@ function run() {
|
|
|
101
101
|
$.NSThread.sleepForTimeInterval(wait);
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
`;function de(t){let e;try{e=JSON.parse(t)}catch{return null}if(!Array.isArray(e))return null;let n=[];for(let i of e.slice(0,
|
|
104
|
+
`;function de(t){let e;try{e=JSON.parse(t)}catch{return null}if(!Array.isArray(e))return null;let n=[];for(let i of e.slice(0,_)){if(!Array.isArray(i)||i.length!==4||!i.every((u)=>typeof u==="number"&&Number.isFinite(u)))return null;let[s,a,c,d]=i.map(Math.round);if(c>0&&d>0)n.push({x:s,y:a,width:c,height:d})}return n}function is(t){let e=Date.now(),n=0,i=!1,s=(u,b={})=>{try{process.stderr.write(`${JSON.stringify({event:"display.windows_helper",state:u,...b})}
|
|
105
105
|
`)}catch{}},a=(u,b={})=>{if(i)return;i=!0,s(u,{updates:n,duration_ms:Date.now()-e,...b})},c=E(j,["-l","JavaScript","-e",le],{env:{},stdio:["ignore","pipe","ignore"]});s("started");let d="";return c.stdout.on("data",(u)=>{if(i)return;d+=u.toString("utf8");for(let b=d.indexOf(`
|
|
106
106
|
`);b>=0;b=d.indexOf(`
|
|
107
|
-
`)){let
|
|
107
|
+
`)){let x=de(d.slice(0,b));if(d=d.slice(b+1),x)n++,t(x)}if(d.length>65536)d=""}),c.once("error",(u)=>a("failed",{code:u.code??"spawn_failed"})),c.once("exit",(u,b)=>a("failed",{code:"exited",exit_code:u,signal:b})),{close(){a("stopped"),c.kill("SIGKILL")}}}var T=5,R=[{bit:1,button:0,down:1,up:2,drag:6},{bit:4,button:1,down:3,up:4,drag:7},{bit:2,button:2,down:25,up:26,drag:27}],fe=[[8,1,0],[16,-1,0],[32,0,1],[64,0,-1]],P=50,pe=500,V=4,I=131072,W=262144,D=524288,F=1048576,B=new Map([[65505,[56,I]],[65506,[60,I]],[65507,[59,W]],[65508,[62,W]],[65511,[58,D]],[65512,[61,D]],[65513,[58,D]],[65514,[61,D]],[65027,[61,D]],[65515,[55,F]],[65516,[54,F]]]),be=new Map([[65288,51],[65289,48],[65056,48],[65293,36],[65307,53],[65535,117],[65509,57],[65360,115],[65361,123],[65362,126],[65363,124],[65364,125],[65365,116],[65366,121],[65367,119],[65379,114],[65386,114],[65291,71],[65408,49],[65421,76],[65429,115],[65430,123],[65431,126],[65432,124],[65433,125],[65434,116],[65435,121],[65436,119],[65437,71],[65438,114],[65439,117],[65450,67],[65451,69],[65452,65],[65453,78],[65454,65],[65455,75],[65469,81],...[82,83,84,85,86,87,88,89,91,92].map((t,e)=>[65456+e,t]),...[122,120,99,118,96,97,98,100,101,109,103,111,105,107,113,106,64,79,80,90].map((t,e)=>[65470+e,t])]),G="asdfhgzxcv\x00bqweryt123465=97-80]ou[ip\x00lj'k;\\,/nm.\x00 `",Y='~!@#$%^&*()_+{}|:"<>?',he="`1234567890-=[]\\;',./",k=new Map;for(let t=0;t<G.length;t++){let e=G[t];if(e==="\x00")continue;if(k.set(e.charCodeAt(0),[t,!1]),e>="a"&&e<="z")k.set(e.toUpperCase().charCodeAt(0),[t,!0])}for(let t=0;t<Y.length;t++)k.set(Y.charCodeAt(t),[k.get(he.charCodeAt(t))[0],!0]);class K{now;x=-1;y=-1;mask=0;clicks=0;lastDown=null;held=new Set;constructor(t=()=>performance.now()){this.now=t}flags(){let t=0;for(let e of this.held)t|=B.get(e)[1];return t}mouse(t,e){return`m ${t} ${this.x} ${this.y} ${e} ${t===T?0:this.clicks} ${this.flags()}`}pointer(t,e,n){let i=[];if(t!==this.x||e!==this.y){this.x=t,this.y=e;let s=R.find((a)=>this.mask&a.bit);i.push(s?this.mouse(s.drag,s.button):this.mouse(T,0))}for(let s of R){let a=(this.mask&s.bit)!==0,c=(n&s.bit)!==0;if(!a&&c){let d=this.now(),u=this.lastDown;this.clicks=u&&u.button===s.button&&d-u.at<=pe&&Math.abs(t-u.x)<=V&&Math.abs(e-u.y)<=V?this.clicks+1:1,this.lastDown={button:s.button,at:d,x:t,y:e},i.push(this.mouse(s.down,s.button))}else if(a&&!c)i.push(this.mouse(s.up,s.button))}for(let[s,a,c]of fe)if(!(this.mask&s)&&n&s)i.push(`w ${a*P} ${c*P} ${this.flags()}`);return this.mask=n,i}key(t,e){let n=t?1:0,i=B.get(e);if(i){if(t)this.held.add(e);else this.held.delete(e);return[`k ${i[0]} ${n} ${this.flags()}`]}let s=be.get(e);if(s!==void 0)return[`k ${s} ${n} ${this.flags()}`];let a=e<256?e:(e&4278190080)===16777216?e&16777215:0,c=k.get(a);if(c)return[`k ${c[0]} ${n} ${this.flags()|(c[1]?I:0)}`];if(a<160||a>65535||a>=55296&&a<57344)return[];return[`u ${n} ${a} ${this.flags()}`]}}function os(t,e=[]){let n=E(...v(e),{env:{},stdio:["pipe","pipe","ignore"]}),i=new K,s="",a=!1,c=null,d=()=>{n.kill("SIGKILL"),c?.kill("SIGKILL")},u=(f)=>{if(a)return;a=!0,d(),t.end(f)},b=(f)=>u({error:new r("display_unavailable",f)}),x=(f)=>{if(a||f.length===0)return;if(n.stdin.write(f.map((g)=>`${g}
|
|
108
108
|
`).join("")),n.stdin.writableLength>ae)u({reason:"input_backpressure"})},z=()=>{c=E(...v(e,"clipboard"),{env:{},stdio:["ignore","pipe","ignore"]});let f="";c.stdout?.on("data",(g)=>{if(a)return;f+=g.toString("ascii");for(let h=f.indexOf(`
|
|
109
109
|
`);h>=0;h=f.indexOf(`
|
|
110
|
-
`)){let U=f.slice(0,h);if(f=f.slice(h+1),!U.startsWith("c "))continue;let A=U.slice(2);if(A.length>Math.ceil(
|
|
111
|
-
`);if(g<0){if(s.length>4096)u({reason:"display_protocol"});return}let h=q(s.slice(0,g));if(s=null,!h)u({reason:"display_protocol"});else if(!h.screen||!h.accessibility)b(e.length>0?"Reason's background worker needs Screen Recording and Accessibility on this Mac (its own Reason entry in System Settings > Privacy & Security, not the Reason app's): run `reason permissions allow` on this Mac.":"Allow Screen Recording and Accessibility for this Mac's Reason worker, then restart it.");else z(),t.ready({width:h.width,height:h.height})}),n.stdin.on("error",()=>{return}),n.once("error",()=>b("Reason could not start this Mac's desktop input.")),n.once("exit",()=>{if(s!==null)b("Reason could not start this Mac's desktop input.");else u({reason:"display_closed"})}),{pointer:(f,g,h)=>
|
|
112
|
-
export{
|
|
110
|
+
`)){let U=f.slice(0,h);if(f=f.slice(h+1),!U.startsWith("c "))continue;let A=U.slice(2);if(A.length>Math.ceil(O/3)*4||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(A)){u({reason:"display_protocol"});return}let C=Buffer.from(A,"base64");if(C.byteLength<=O)t.clipboard(C.toString("utf8"));if(a)return}if(f.length>Math.ceil(O/3)*4+2)u({reason:"display_protocol"})}),c.once("error",()=>b("Reason could not watch this Mac's desktop clipboard.")),c.once("exit",()=>{if(!a)b("Reason could not watch this Mac's desktop clipboard.")})};return n.stdout.on("data",(f)=>{if(a||s===null)return;s+=f.toString("utf8");let g=s.indexOf(`
|
|
111
|
+
`);if(g<0){if(s.length>4096)u({reason:"display_protocol"});return}let h=q(s.slice(0,g));if(s=null,!h)u({reason:"display_protocol"});else if(!h.screen||!h.accessibility)b(e.length>0?"Reason's background worker needs Screen Recording and Accessibility on this Mac (its own Reason entry in System Settings > Privacy & Security, not the Reason app's): run `reason permissions allow` on this Mac.":"Allow Screen Recording and Accessibility for this Mac's Reason worker, then restart it.");else z(),t.ready({width:h.width,height:h.height})}),n.stdin.on("error",()=>{return}),n.once("error",()=>b("Reason could not start this Mac's desktop input.")),n.once("exit",()=>{if(s!==null)b("Reason could not start this Mac's desktop input.");else u({reason:"display_closed"})}),{pointer:(f,g,h)=>x(i.pointer(f,g,h)),key:(f,g)=>x(i.key(f,g)),clipboard:(f)=>x([`c ${Buffer.from(f,"utf8").toString("base64")}`]),close(){a=!0,d()}}}
|
|
112
|
+
export{vc,Sc,Sr,Ec,O,kc,xc,ts,Cc,Ac,Pc,Rc,rs,Tc,Rn,ns,Xt,Er,is,os};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{readdirSync as b,readFileSync as P}from"fs";import{userInfo as k}from"os";var
|
|
3
|
-
export{
|
|
2
|
+
import{r}from"./vm-hands-entry-lite-qy9xg6em.js";import{readdirSync as b,readFileSync as P}from"fs";import{userInfo as k}from"os";var jn="--vm-hands-op-runner-kind=person",Hn="--vm-hands-op-runner-kind=surface",Fr="--vm-hands-surface-uid=",jr="--vm-hands-surface-dir=",Hr=new Set(["automation.call.v1","display.stream.v1","preview.serve.v1"]);function R(t){let c=new Set([t]),l=[];try{l=b("/proc")}catch{}for(let o of l){if(!/^\d+$/.test(o))continue;try{let d=P(`/proc/${o}/stat`,"utf8");if(Number(d.slice(d.lastIndexOf(")")+2).split(" ")[3])===t)c.add(Number(o))}catch{}}for(let o of c)try{process.kill(o,"SIGKILL")}catch{}}var A=(t)=>{let c=globalThis.Bun;if(!c)throw new r("pty_unavailable","Reason terminals require the Bun runtime.");let l=c.spawn({cmd:[t.shell,...t.args],cwd:t.cwd,env:{...t.environment,TERM:"xterm-256color"},terminal:{cols:t.cols,rows:t.rows,data:(i,s)=>t.onData(s)}}),o=l.terminal,d=()=>{R(l.pid);try{o?.close()}catch{}};if(!o)throw d(),new r("pty_unavailable","Reason could not allocate a pseudo-terminal.");return{write:(i)=>o.write(i),resize:(i,s)=>o.resize(i,s),kill:d,exited:l.exited.then((i)=>typeof i==="number"?i:null,()=>null)}};function x(){let t=(()=>{try{return k().username}catch{return}})();return{PATH:process.env.PATH,HOME:process.env.HOME,SHELL:process.env.SHELL,LANG:"C.UTF-8",...t?{USER:t,LOGNAME:t}:{}}}async function E(t){let[{localAutomationAvailable:c},{localDisplayReady:l},{localDisplayVideoAvailable:o},{probeWorkerPreview:d},y]=await Promise.all([import("./local-automation-8b1znx0p.js"),import("./local-display-session-zyd8s6n6.js"),import("./local-display-video-rk680vwg.js"),import("./worker-preview-readiness-06tygyjs.js"),import("fs")]),i=AbortSignal.timeout(15000),s=null;try{y.mkdirSync(t,{recursive:!0,mode:448}),s=y.mkdtempSync(`${t}/probe-`);let[g,p,m]=await Promise.all([Promise.resolve().then(()=>c()).catch(()=>!1),l().catch(()=>!1),d(s,i).catch(()=>!1)]);return{t:"readiness",display_video:p&&await o().catch(()=>!1),lanes:{"automation.call.v1":g,"display.stream.v1":p,"preview.serve.v1":m,"tunnel.open":m,"tunnel.close":m}}}finally{if(s)y.rmSync(s,{recursive:!0,force:!0})}}async function sl(){let[{executeLocalOperation:t,spawnCaptured:c},{runLocalPtySession:l},{configureDesktopAccount:o,desktopAccount:d},{configureWorkerSandbox:y}]=await Promise.all([import("./local-capabilities-m6pzcc94.js"),import("./local-pty-session-edd8ttf9.js"),import("./desktop-account-eg8thn79.js"),import("./worker-sandbox-e1cpkzfz.js")]);y();let i=process.argv.includes(jn),s=process.argv.includes(Hn),g=(a,e,u)=>c(a,e[0]==="-lic"?["-lc",...e.slice(1)]:e,u),p=(process.geteuid?.()??0)!==0;if(s){p=!1;let a=process.argv.find((e)=>e.startsWith(Fr))?.slice(Fr.length);if((process.geteuid?.()??-1)===0&&a)try{p=o({value:a})!==null&&d()!==null}catch{p=!1}}let m=new Map,v=new Map,f=(a)=>{try{process.send?.(a)}catch{}};if(process.on("message",(a)=>{let e=a;if(e?.t==="cancel"){m.get(e.id)?.abort();return}if(e?.t==="control"){let n=v.get(e.id);if(s&&n&&e.control&&typeof e.control.kind==="string")import("./local-managed-process-w26jhyfg.js").then(({controlManagedDeviceProcess:_})=>_(n,{kind:e.control.kind,payload:e.control.payload??{}})).catch(()=>!1);return}if(e?.t==="retire"){if(s&&typeof e.operation_id==="string"&&typeof e.status==="string")import("./local-managed-process-w26jhyfg.js").then(({retireManagedDeviceProcess:n})=>n(e.operation_id,e.status)).catch(()=>!1);return}if(e?.t!=="op")return;if(!p){f({t:"done",id:e.id,completion:{status:"failed",error_code:"vm_hands_payload_account_unavailable"}});return}let u=e.claim.capability;if(u==="pty.start"&&!i){f({t:"done",id:e.id,completion:{status:"failed",error_code:"capability_not_granted"}});return}if(Hr.has(u)!==s){f({t:"done",id:e.id,completion:{status:"failed",error_code:"capability_not_granted"}});return}let w=new AbortController;m.set(e.id,w),v.set(e.id,e.claim);let S=u==="pty.start"?{runPtySession:(n)=>l(n,{spawnPty:A,environment:x(),loadProxy:()=>null})}:{worker:e.worker,...u==="exec.full"?{spawnFullControl:g}:{}};t(e.state,e.claim,{...S,signal:w.signal,emit:(n)=>{let{deliverySignal:_,...h}=n;f({t:"event",id:e.id,event:h})}}).then((n)=>f({t:"done",id:e.id,completion:n}),(n)=>f({t:"done",id:e.id,completion:{status:"failed",error_code:n&&typeof n==="object"&&"code"in n&&typeof n.code==="string"?n.code:"vm_hands_op_failed"}})).finally(()=>{m.delete(e.id),v.delete(e.id)})}),process.on("disconnect",()=>process.exit(0)),s){let a=process.argv.find((u)=>u.startsWith(jr))?.slice(jr.length),e={t:"readiness",display_video:!1,lanes:{}};f(p&&a?await E(a).catch(()=>e):e)}await new Promise(()=>{})}
|
|
3
|
+
export{jn,Hn,Fr,jr,Hr,sl};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{te}from"./vm-hands-entry-lite-9g52kxyj.js";var ic=32;var oc="__ARA_PI_TOOL_CONFINED_SCRIPT_5f0c9e2a__",sc=262144;var F=2,bi=33554432,vi=200000,Mo=4000000,_r=240000;var Bo=2000;var Si=16384,zt=32768,gt=128,Fo=64,qt=2097152,pn=1,He=16384,Wt=32768,jo=8388608,_t=1000,hn=2500,Ei=2000,fn=hn+Ei,R=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$/,h=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i,ki={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},V=new Map(Object.entries(ki).map(([t,n])=>[n,t]));var N=["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"],I=new Set(N),Ho=16384,y=["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 r extends Error{code;constructor(t){super(t);this.name="HandsProtocolError",this.code=t}}function m(t){return new TextEncoder().encode(t).byteLength}function a(t){return typeof t==="object"&&t!==null&&!Array.isArray(t)}function i(t,n){let e=new Set(n);return Object.keys(t).every((s)=>e.has(s))}function rt(t){return typeof t==="string"&&R.test(t)}function Ee(t){return Number.isSafeInteger(t)&&Number(t)>=1}function ce(t){return typeof t==="string"&&h.test(t)}function nt(t){return typeof t==="string"&&t.startsWith("pty-")&&ce(t.slice(4))}function p(t){return[t.cols,t.rows].every((n)=>Number.isSafeInteger(n)&&Number(n)>=1&&Number(n)<=_t)}function _(t){if(typeof t!=="string"||t.length>Math.ceil(He/3)*4||t.length%4!==0||!/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t))return-1;let n=t.endsWith("==")?2:t.endsWith("=")?1:0;if(n&&"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(t[t.length-n-1])&(n===2?15:3))return-1;let s=t.length/4*3-n;return s<=He?s:-1}function l(t){if(m(t)>bi)throw new r("frame_too_large");try{return JSON.parse(t)}catch{throw new r("invalid_json")}}function xi(t){let n=l(t);if(!a(n)||!i(n,["type","version","generation","id","jobId","action","input"])||n.type!=="job"||n.version!==F||!Ee(n.generation)||!rt(n.id)||!rt(n.jobId)||!a(n.input))throw new r("invalid_job_request");let e=n.input,s=Number.isSafeInteger(e.leaseExpiresAtMs)&&Number(e.leaseExpiresAtMs)>0,d=Number.isSafeInteger(e.sequence)&&Number(e.sequence)>=1;if(!(n.action==="start"?e.mode==="pty"?i(e,["mode","cols","rows","leaseExpiresAtMs"])&&nt(n.jobId)&&p(e)&&s:i(e,["script","leaseExpiresAtMs"])&&typeof e.script==="string"&&e.script.length<=vi&&s:n.action==="inspect"?i(e,["after"])&&Number.isSafeInteger(e.after)&&Number(e.after)>=0:n.action==="input"?"dataBase64"in e?i(e,["sequence","dataBase64"])&&nt(n.jobId)&&d&&_(e.dataBase64)>0:i(e,["sequence","data","eof"])&&d&&typeof e.data==="string"&&e.data.length<=Si&&typeof e.eof==="boolean":n.action==="resize"?i(e,["sequence","cols","rows"])&&nt(n.jobId)&&d&&p(e):n.action==="renew"?i(e,["leaseExpiresAtMs"])&&s:n.action==="cancel"&&i(e,[])))throw new r("invalid_job_request");return n}function Ci(t){let n=l(t);if(!a(n)||!i(n,["type","version","generation","id","ok","job","error"])||n.type!=="job_result"||n.version!==F||!Ee(n.generation)||!rt(n.id))throw new r("invalid_job_result");if(n.ok===!1&&n.job===void 0&&typeof n.error==="string"&&y.some((o)=>o===n.error))return n;let e=n.job;if(n.ok!==!0||n.error!==void 0||!a(e)||!i(e,["jobId","state","startedAtMs","finishedAtMs","leaseExpiresAtMs","exitCode","inputSequence","output","firstCursor","nextCursor","truncated","process","environmentRevision","environmentSnapshotId","pty"])||!rt(e.jobId)||!["starting","running","exited","cancelled","expired","uncertain"].includes(String(e.state))||!Number.isSafeInteger(e.startedAtMs)||Number(e.startedAtMs)<1||!Number.isSafeInteger(e.leaseExpiresAtMs)||Number(e.leaseExpiresAtMs)<1||e.finishedAtMs!==null&&(!Number.isSafeInteger(e.finishedAtMs)||Number(e.finishedAtMs)<Number(e.startedAtMs))||e.exitCode!==null&&(!Number.isSafeInteger(e.exitCode)||Number(e.exitCode)<0||Number(e.exitCode)>255)||!Number.isSafeInteger(e.inputSequence)||Number(e.inputSequence)<0||!Number.isSafeInteger(e.firstCursor)||Number(e.firstCursor)<1||!Number.isSafeInteger(e.nextCursor)||Number(e.nextCursor)<Number(e.firstCursor)-1||typeof e.truncated!=="boolean"||!Array.isArray(e.output)||e.output.length>gt)throw new r("invalid_job_result");if(e.environmentRevision===void 0!==(e.environmentSnapshotId===void 0)||e.environmentRevision!==void 0&&(!Number.isSafeInteger(e.environmentRevision)||Number(e.environmentRevision)<1||!ce(e.environmentSnapshotId)))throw new r("invalid_job_result");let s=Number(e.firstCursor)-1,d=0;for(let o of e.output){if(!a(o)||!i(o,["cursor","stream","text"])||!Number.isSafeInteger(o.cursor)||Number(o.cursor)<=s||Number(o.cursor)>Number(e.nextCursor)||!["stdout","stderr"].includes(String(o.stream))||typeof o.text!=="string")throw new r("invalid_job_result");d+=o.text.length,s=Number(o.cursor)}if(d>zt)throw new r("invalid_job_result");let c=e.state==="starting"||e.state==="running";if(c&&(e.finishedAtMs!==null||e.exitCode!==null)||!c&&e.finishedAtMs===null||e.state==="uncertain"&&e.exitCode!==null||e.state==="exited"&&e.exitCode===null||e.state==="cancelled"&&e.exitCode!==130||e.state==="expired"&&e.exitCode!==124)throw new r("invalid_job_result");if(e.process!==void 0){let o=e.process;if(!a(o)||!i(o,["pid","processGroupId","executorLaunchId"])||!Number.isSafeInteger(o.pid)||Number(o.pid)<1||o.processGroupId!==o.pid||!ce(o.executorLaunchId)||!["starting","running"].includes(String(e.state)))throw new r("invalid_job_result")}if(e.pty!==void 0){let o=e.pty;if(!a(o)||!i(o,["version","cols","rows","output","cleanup"])||o.version!==pn||!nt(e.jobId)||!p(o)||e.output.length!==0||!Array.isArray(o.output)||o.output.length>gt||(c?o.cleanup!=="pending":e.state==="uncertain"?o.cleanup!=="unconfirmed":o.cleanup!=="confirmed")||e.state==="running"&&(e.process===void 0||e.environmentRevision===void 0))throw new r("invalid_job_result");let g=Number(e.firstCursor)-1,b=0;for(let u of o.output){if(!a(u)||!i(u,["cursor","dataBase64"])||!Number.isSafeInteger(u.cursor)||Number(u.cursor)<=g||Number(u.cursor)>Number(e.nextCursor))throw new r("invalid_job_result");let f=_(u.dataBase64);if(f<=0||(b+=f)>Wt)throw new r("invalid_job_result");g=Number(u.cursor)}}return n}function Uo(t){if(m(t)>qt)throw new r("frame_too_large");let n=l(t);if(!a(n)||!i(n,["version","sessionId","operationId","runId","deviceId","rootId","workspace","binding","targetRevision","rootGrantRevision","generation","fenceId","executorLaunchId","job"])||n.version!==pn||![n.sessionId,n.operationId,n.runId].every(rt)||![n.deviceId,n.rootId,n.fenceId,n.executorLaunchId].every(ce)||!Ee(n.generation)||!Number.isSafeInteger(n.rootGrantRevision)||Number(n.rootGrantRevision)<1||!["workspace_source","mcp_control"].includes(String(n.binding))||!Number.isSafeInteger(n.targetRevision)||Number(n.targetRevision)<0||n.binding==="workspace_source"&&n.targetRevision!==0||!a(n.workspace))throw new r("invalid_pty_receipt");if(!te(n.workspace))throw new r("invalid_pty_receipt");let e=Ci(JSON.stringify({type:"job_result",version:F,generation:n.generation,id:n.operationId,ok:!0,job:n.job}));if(!e.ok||!e.job.pty||e.job.pty.output.length!==0||e.job.process&&e.job.process.executorLaunchId!==n.executorLaunchId)throw new r("invalid_pty_receipt");return n}export{ic,oc,sc,F,bi,vi,Mo,_r,Bo,Si,zt,gt,Fo,qt,pn,He,Wt,jo,_t,hn,Ei,fn,ki,Ho,rt,Ee,ce,nt,xi,Ci,Uo};
|