@hasna/hooks 0.12.23 → 0.13.0

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.
@@ -1,38 +1,38 @@
1
1
  // @bun
2
- import{homedir as M1}from"os";import{isAbsolute as b2}from"path";import{isAbsolute as A3,join as WZ,normalize as y3,resolve as R3,sep as v0}from"path";import{dirname as VZ,isAbsolute as aZ,join as _0,resolve as $Z}from"path";import{accessSync as x2,closeSync as h2,constants as nZ,fstatSync as w2,lstatSync as yZ,openSync as g2,readFileSync as u2,readlinkSync as l2,readSync as m2,realpathSync as I0,statSync as T0}from"fs";import{spawnSync as p2}from"child_process";var N1={missing:"No verified @hasna/trash guard was found on PATH.",unsafe_executable:"The Trash candidate is not an owned executable file or is writable by group or others.",unsafe_manifest:"The Trash package manifest is not a safe owned regular file.",unsafe_directory:"A Trash PATH or package directory is not owned safely or is writable by group or others.",unsafe_interpreter:"The Trash interpreter is missing, unsupported, or not a safe owned executable on its actual PATH.",unrecognized_package:"The candidate is not the registered @hasna/trash executable.",identity_failed:"The installed Trash identity probe failed or exceeded its deadline.",unsupported_protocol:"The installed Trash version does not expose the required guard protocol."};function RZ(Z){return Z===0||Z===process.getuid?.()}function oZ(Z,z=!1){let $=Z;for(let J=0;J<32;J++){if(!aZ($)||$.length>4096||!vZ("/"))return!1;let Y=$.split("/"),X=Y.pop();if(!X||X==="."||X==="..")return!1;let Q="/";for(let H of Y){if(!H||H===".")continue;if(H===".."){Q=VZ(Q);continue}let M=_0(Q,H),V=yZ(M);if(z&&M==="/bin"&&V.isSymbolicLink()&&V.uid===0){let G=I0(M);if(!vZ(G))return!1;Q=G;continue}if(!V.isDirectory()||!RZ(V.uid)||V.mode&18)return!1;Q=M}let B=_0(Q,X),K=yZ(B);if(!RZ(K.uid))return!1;if(K.isSymbolicLink()){let H=l2(B);$=aZ(H)?H:Q+"/"+H;continue}return K.isFile()&&Boolean(K.mode&73)&&!(K.mode&18)}return!1}function c2(Z){if(!aZ(Z)||$Z(Z)!==(Z.replace(/\/+$/,"")||"/"))return!1;for(let z=$Z(Z);;z=VZ(z)){try{return yZ(z),vZ(z)}catch($){if($.code!=="ENOENT")return!1}if(VZ(z)===z)return!1}}function i2(Z,z){let $=g2(Z,nZ.O_RDONLY|nZ.O_NONBLOCK|nZ.O_NOFOLLOW),J;try{if(!w2($).isFile())return!1;let X=Buffer.alloc(256),Q=m2($,X,0,X.length,0);J=X.subarray(0,Q).toString("utf8").split(`
3
- `)[0]}finally{h2($)}let Y=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(J);if(Y&&Y[1]!=="/usr/bin/env")return oZ(Y[1],!0);if(J!=="#!/usr/bin/env bun"||!oZ("/usr/bin/env",!0))return!1;for(let X of z.split(":").slice(0,64)){if(!c2(X))return!1;let Q=$Z(X,"bun");try{if(!T0(Q).isFile())continue;x2(Q,nZ.X_OK)}catch{continue}return oZ(Q,!0)}return!1}function vZ(Z){let z=Z;for(;;){let $=yZ(z);if(!$.isDirectory()||!RZ($.uid)||($.mode&18)!==0)return!1;let J=VZ(z);if(J===z)return!0;z=J}}function bZ(Z=process.env){let z=Z.PATH??"",$=Date.now()+2000,J="missing",Y=(X)=>{if(J==="missing"||J==="unrecognized_package"||X.startsWith("unsafe_"))J=X};for(let X of z.split(":").slice(0,64)){if(!aZ(X)||Date.now()>=$)continue;let Q=$Z(X,"trash");try{let B=T0(Q);if(!B.isFile()||!RZ(B.uid)||(B.mode&73)===0||(B.mode&18)!==0){Y("unsafe_executable");continue}let K=I0(Q);if(!vZ($Z(X))||!vZ(VZ(K))){Y("unsafe_directory");continue}if(!oZ(Q)){Y("unsafe_directory");continue}let H=$Z(VZ(K),"../.."),M=_0(H,"package.json"),V=T0(M);if(!V.isFile()||!RZ(V.uid)||V.size>16384||(V.mode&18)!==0||yZ(M).isSymbolicLink()){Y("unsafe_manifest");continue}let G=JSON.parse(u2(M,"utf8"));if(G.name!=="@hasna/trash"||typeof G.version!=="string"||typeof G.bin?.trash!=="string"||I0($Z(H,G.bin.trash))!==K){Y("unrecognized_package");continue}try{if(!i2(K,z)){Y("unsafe_interpreter");continue}}catch{Y("unsafe_interpreter");continue}let U=$-Date.now();if(U<=0){Y("identity_failed");break}let j=p2(Q,["--identity"],{encoding:"utf8",timeout:U,maxBuffer:2048,env:{PATH:z},stdio:["ignore","pipe","pipe"]});if(j.error||j.status!==0||Date.now()>=$){Y("identity_failed");continue}let F=JSON.parse(j.stdout);if(F.name==="@hasna/trash"&&F.version===G.version&&F.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:Q,version:G.version};Y("unsupported_protocol")}catch{}}return{ok:!1,code:J}}function rZ(Z=process.env){let z=bZ(Z);return z.ok?z.path:null}function GZ(Z){let z=Z.tool_input?.command;return typeof z==="string"?z:""}var D1=["/","/bin","/boot","/dev","/etc","/home","/lib","/lib32","/lib64","/libx32","/opt","/proc","/root","/run","/sbin","/srv","/sys","/usr","/var","/Applications","/Library","/System","/Users","/Volumes","/private"];var SZ=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,c=(Z)=>Z.split("/").pop()??"";function tZ(Z){let z=Z.startsWith("~")?Z.slice(1).split("/",1)[0]:"";if(z&&!/['"\\]/.test(z))return!0;let $=null,J=0;for(let Y=0;Y<Z.length;Y++){let X=Z[Y];if($==="'"){if(X==="'")$=null;continue}if(X==="\\"){Y++;continue}if($==='"'){if(X==='"')$=null;continue}if(X==="'"||X==='"')$=X;else if(X==="$"&&Z[Y+1]==="{")J++,Y++;else if(X==="}"&&J>0)J--;else if(X==="{"||X==="}")return!0}return!1}var q0=64;function _1(Z,z){let $=0;for(let J=z;J<Z.length;J++)if(Z[J]==="\\")J++;else if(Z[J]==="{")$++;else if(Z[J]==="}"&&--$===0)return J;return Z.length-1}function d2(Z){let z=Z.match(/^([-+]?\d+)\.\.([-+]?\d+)(?:\.\.([-+]?\d+))?$/),$=z?null:Z.match(/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([-+]?\d+))?$/),J=z??$;if(!J)return null;let Y=z?Number(J[1]):J[1].charCodeAt(0),X=z?Number(J[2]):J[2].charCodeAt(0),Q=Math.abs(Number(J[3]??1))||1;if(!Number.isSafeInteger(Y)||!Number.isSafeInteger(X)||!Number.isSafeInteger(Q))return"overflow";if(Math.floor(Math.abs(X-Y)/Q)+1>q0)return"overflow";let B=z&&(/^[-+]?0\d/.test(J[1])||/^[-+]?0\d/.test(J[2]))?Math.max(J[1].length,J[2].length):0,K=[];for(let H=Y;Y<=X?H<=X:H>=X;H+=Y<=X?Q:-Q)if(!z)K.push(String.fromCharCode(H));else K.push(H<0?`-${String(-H).padStart(B-1,"0")}`:String(H).padStart(B,"0"));return K}function s2(Z){let z=null,$=0;for(let J=0;J<Z.length;J++){let Y=Z[J];if(z==="'"){if(Y==="'")z=null;continue}if(Y==="\\"){J++;continue}if(z==='"'){if(Y==='"')z=null;continue}if(Y==="'"||Y==='"')z=Y;else if(Y==="$"&&Z[J+1]==="{")J=_1(Z,J+1);else if(Y==="{"){if(++$>q0)return"overflow";let X=null,Q=0,B=!0,K=[];for(let H=J;H<Z.length;H++){let M=Z[H];if(X==="'"){if(M==="'")X=null;continue}if(M==="\\"){B=!1,H++;continue}if(X==='"'){if(M==='"')X=null;continue}if(M==="'"||M==='"')X=M,B=!1;else if(M==="$"&&Z[H+1]==="{")H=_1(Z,H+1),B=!1;else if(M==="{")Q++;else if(M===","&&Q===1)K.push(H);else if(M==="}"&&--Q===0){if(K.length>0){let G=[J,...K,H];return{open:J,close:H,parts:G.slice(0,-1).map((U,j)=>Z.slice(U+1,G[j+1]))}}let V=B?d2(Z.slice(J+1,H)):null;if(V==="overflow")return V;if(V)return{open:J,close:H,parts:V};break}}}}return null}function JZ(Z){if(Z.length>4096&&Z.includes("{"))return null;let z=s2(Z);if(z===null)return[Z];if(z==="overflow")return null;let $=[];for(let J of z.parts){let Y=JZ(Z.slice(0,z.open)+J+Z.slice(z.close+1));if(Y===null||$.push(...Y)>q0)return null}return $}var W={arg:"none"},_={arg:"value"},EZ={arg:"optional"},s={arg:"none",effect:"lookup"},C={arg:"none",effect:"refuse"},o={help:C,version:C},n2=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,C0={timeout:{short:{k:_,s:_,v:W},long:{"kill-after":_,signal:_,verbose:W,foreground:W,"preserve-status":W,...o},positionals:[n2]},env:{short:{i:W,"0":W,v:W,u:_,a:_,C,S:C},long:{"ignore-environment":W,null:W,debug:W,unset:_,argv0:_,chdir:C,"split-string":C,"block-signal":EZ,"default-signal":EZ,"ignore-signal":EZ,"list-signal-handling":C,...o},env:!0},nice:{short:{n:_},long:{adjustment:_,...o},numericOption:!0},nohup:{short:{},long:{...o}},command:{short:{p:W,v:s,V:s},long:{}},exec:{short:{c:W,l:W,a:_},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:_,o:_,e:_},long:{input:_,output:_,error:_,...o}},time:{short:{p:W,a:W,q:W,v:W,f:_,o:C,V:C},long:{portability:W,append:W,quiet:W,verbose:W,format:_,output:C,...o}},ionice:{short:{c:_,n:_,t:W,p:C,P:C,u:C,h:C,V:C},long:{class:_,classdata:_,ignore:W,pid:C,pgid:C,uid:C,...o}},setsid:{short:{c:W,f:W,w:W,h:C,V:C},long:{ctty:W,fork:W,wait:W,...o}}},o2=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function a2(Z,z,$){let J=!1,Y=(X)=>{if(!X||X.effect==="refuse")return!1;if(X.effect==="lookup")J=!0;return!0};while($<z.length){let X=z[$];if(X.opaque)return null;let Q=X.text;if(Q==="--"){$++;break}if(Q==="-"&&Z.env){$++;continue}if(!Q.startsWith("-")||Q==="-")break;if(Z.numericOption&&/^-[-+]?\d+$/.test(Q)){$++;continue}if(Q.startsWith("--")){let B=Q.indexOf("="),K=B<0?Q.slice(2):Q.slice(2,B),H=Object.keys(Z.long),M=H.includes(K)?[K]:H.filter((G)=>K&&G.startsWith(K));if(M.length!==1)return null;let V=Z.long[M[0]];if(!Y(V))return null;if(V.arg==="none"&&B>=0)return null;if(V.arg==="value"&&B<0){let G=z[++$];if(!G||G.opaque)return null}$++;continue}for(let B=1;B<Q.length;B++){let K=Z.short[Q[B]];if(!Y(K))return null;if(K.arg==="value"){if(B===Q.length-1){let H=z[++$];if(!H||H.opaque)return null}break}}$++}if(J)return-1;for(let X of Z.positionals??[]){let Q=z[$];if(!Q||Q.opaque||!X.test(Q.text))return null;$++}if(Z.env||Z.assignments){for(;$<z.length&&SZ.test(z[$].text);$++)if(z[$].opaque)return null}return $}function zZ(Z,z=C0){let $=0;while($<Z.length&&(SZ.test(Z[$].text)||o2.has(Z[$].text)))$++;for(let J=0;J<16;J++){if($>=Z.length)return{index:-1};if(Z[$].opaque)return J===0?{index:$}:null;let Y=Object.hasOwn(z,c(Z[$].text))?z[c(Z[$].text)]:void 0;if(!Y)return{index:$};let X=a2(Y,Z,$+1);if(X===null)return null;if(X<0)return{index:-1};$=X}return null}function r2(Z){return/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred|trash)(?![A-Za-z0-9_.-])/.test(Z)}var a={on:!1};function YZ(Z,z){if(!Z.includes("\\")||!Z.includes('"'))return;let $=a.on;a.on=!0;try{return z()}finally{a.on=$}}var L0=(Z)=>Z.split("/").pop()??"",O0={perl:{letters:new Set(["e","E"]),long:new Set},python:{letters:new Set(["c"]),long:new Set},python2:{letters:new Set(["c"]),long:new Set},python3:{letters:new Set(["c"]),long:new Set},ruby:{letters:new Set(["e"]),long:new Set},node:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},nodejs:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},bun:{letters:new Set(["e"]),long:new Set(["--eval"])},deno:{letters:new Set(["e"]),long:new Set(["--eval"])},php:{letters:new Set(["r"]),long:new Set},lua:{letters:new Set(["e"]),long:new Set},luajit:{letters:new Set(["e"]),long:new Set},Rscript:{letters:new Set(["e"]),long:new Set}},C1=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,t2=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),e2=new Set(["ssh","scp","sftp"]),Z3=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),I1=new Set(["proxycommand","localcommand","knownhostscommand"]),$3=/(?:`|\$\()|\b(?:system|exec|execve|execvp|popen|spawn|posix_spawn|fork|subprocess|Popen|check_output|check_call|shell_exec|passthru|proc_open|pcntl_exec|qx|open|fopen|sysopen|unlink|remove|delete|rmtree|rmdir|mkdir|rename|truncate|ftruncate|chmod|chown|symlink|writeFile|createWriteStream|appendFile|child_process|FileUtils|shutil|Kernel|require|import|load|eval|os|sys|io|fs|File|IO|Dir|Path|pathlib|Deno|Bun)|%x\W/,J3=/[|>]|\b(?:system|getline|close|fflush|print\w*\s*>>?)/;function P1(Z){if(r2(Z.text))return!1;if(Z.kind==="awk")return!J3.test(Z.text);if(Z.kind==="c-interp")return!$3.test(Z.text);return!1}function z3(Z,z,$,J){let Y=O0[Z]??(C1.test(Z)?O0[Z.replace(/[0-9.]+$/,"")]:void 0);if(!Y)return null;let X=[],Q=!1,B=(K)=>{if(K+1>=z.length||J(K+1))return Q=!0,K;return X.push({text:z[K+1],kind:"c-interp"}),K+1};for(let K=$+1;K<z.length;K++){let H=z[K];if(H==="--")break;if(!H.startsWith("-")||H==="-")break;if(H.startsWith("--")){let V=H.indexOf("="),G=V<0?H:H.slice(0,V);if(Y.long.has(G))if(V>=0)X.push({text:H.slice(V+1),kind:"c-interp"});else K=B(K);continue}let M=H.slice(1);for(let V=0;V<M.length;V++){if(!Y.letters.has(M[V]))continue;if(V<M.length-1)X.push({text:M.slice(V+1),kind:"c-interp"});else K=B(K);break}}if(X.length===0&&!Q)return null;return{programs:X,unresolved:Q}}function Y3(Z,z,$){let J=z+1;for(;J<Z.length&&Z[J].startsWith("-");J++)if(Z[J]==="-L"||Z[J]==="--log-level")J++;if(Z[J]!=="eval"||$(J))return null;let Y=[],X=!1;for(J++;J<Z.length;J++){if($(J)){X=!0;continue}if(!Z[J].startsWith("-"))Y.push({text:Z[J],kind:"c-interp"})}return Y.length===0&&!X?null:{programs:Y,unresolved:X}}function X3(Z,z,$){let J=[],Y=!1,X=z+1;for(;X<Z.length;X++){let Q=Z[X];if(Q==="--"){X++;break}if(!Q.startsWith("-")||Q==="-")break;if(Q==="-e"||Q.startsWith("-e")){let B=Q==="-e"?null:Q.slice(2);if(B!==null)J.push({text:B,kind:"awk"});else if(X+1<Z.length&&!$(X+1))J.push({text:Z[++X],kind:"awk"});else Y=!0}else if(Q==="-f"||Q.startsWith("-f")){if(Y=!0,Q==="-f")X++}else if(Q==="-v"||Q.startsWith("-v")){if(Q==="-v")X++}}if(J.length===0&&!Y){if(X<Z.length)if($(X))Y=!0;else J.push({text:Z[X],kind:"awk"})}return{programs:J,unresolved:Y}}function Q3(Z,z,$){let J=Z[z],Y,X=z;if(J==="-o"){if(z+1>=Z.length)return{value:null,next:z};if($(z+1))return{value:null,next:z+1};Y=Z[z+1],X=z+1}else Y=J.slice(2);return{value:Y,next:X}}function K3(Z,z,$){let J=[],Y=!1;for(let X=z+1;X<Z.length;X++){let Q=Z[X];if(Q==="--")break;if(!Q.startsWith("-")||Q==="-")break;if(Q.startsWith("--"))continue;if(Q==="-o"||Q.startsWith("-o")){let{value:K,next:H}=Q3(Z,X,$);if(X=H,K===null){Y=!0;continue}let M=K.indexOf("="),V=M>=0?M:K.search(/\s/),G=(V>=0?K.slice(0,V):K).trim().toLowerCase(),U=V>=0?K.slice(V+1).trim():"";if(I1.has(G))J.push({text:U,kind:"shell"});continue}if(Q==="-F"||Q.startsWith("-F")){if(Y=!0,Q==="-F")X++;continue}if(Q==="-S"||Q.startsWith("-S")){let K=Q==="-S"?X+1<Z.length&&!$(X+1)?Z[++X]:null:Q.slice(2);if(K===null)Y=!0;else J.push({text:K,kind:"shell"});continue}let B=Q.slice(1);for(let K=0;K<B.length;K++){if(!Z3.has(B[K]))continue;if(K<B.length-1)break;if(B[K]==="o"||B[K]==="F"||B[K]==="S"){if(X+1<Z.length){let H=Z[X+1];if(B[K]==="o")if(!$(X+1)){let M=H.indexOf("="),V=M>=0?M:H.search(/\s/),G=(V>=0?H.slice(0,V):H).trim().toLowerCase();if(I1.has(G))J.push({text:V>=0?H.slice(V+1).trim():"",kind:"shell"})}else Y=!0;else if(B[K]==="F")Y=!0;else if(!$(X+1))J.push({text:H,kind:"shell"});X++}}else if(X+1<Z.length)X++}}return{programs:J,unresolved:Y}}function B3(Z,z,$){let J=[],Y=!1,X=!1;for(let Q=z+1;Q<Z.length;Q++){let B=Z[Q];if(B==="--")break;if(B==="-e"||B==="--rsh")if(X=!0,Q+1<Z.length&&!$(Q+1))J.push({text:Z[++Q],kind:"shell"});else Y=!0;else if(B.startsWith("--rsh="))X=!0,J.push({text:B.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(B)&&B.length>2&&!B.startsWith("--"))X=!0,J.push({text:B.slice(B.indexOf("e")+1),kind:"shell"})}return X?{programs:J,unresolved:Y}:null}var H3=/^(?:true|false|yes|no|on|off|1|0|)$/i,M3=[/^core\.(?:pager|editor|sshcommand|askpass|alternaterefscommand)$/,/^sequence\.editor$/,/^diff\.external$/,/^interactive\.difffilter$/,/^imap\.tunnel$/,/^gc\.recentobjectshook$/,/^gpg\.program$/,/^gpg\.ssh\.defaultkeycommand$/,/^uploadpack\.packobjectshook$/,/^instaweb\.(?:browser|httpd)$/,/^credential\.(?:.+\.)?helper$/,/^diff\..+\.(?:command|textconv)$/,/^(?:difftool|mergetool|man|browser)\..+\.(?:cmd|path)$/,/^guitool\..+\.cmd$/,/^merge\..+\.driver$/,/^gpg\..+\.program$/,/^remote\..+\.(?:uploadpack|receivepack)$/,/^filter\..+\.(?:clean|smudge|process)$/,/^tar\..+\.command$/,/^trailer\..+\.(?:cmd|command)$/,/^sendemail\.(?:.+\.)?(?:tocmd|cccmd|headercmd|sendmailcmd)$/];function O1(Z,z){let $=Z.toLowerCase(),J=(Y)=>Y===void 0?{kind:"unresolved"}:{kind:"command",text:Y};if(/^alias\./.test($))return z!==void 0&&z.trimStart().startsWith("!")?J(z.trimStart().slice(1)):{kind:"unresolved"};if(/^pager\./.test($)||$==="core.fsmonitor")return z!==void 0&&H3.test(z)?{kind:"harmless"}:J(z);if($==="core.gitproxy")return z!==void 0&&/^none(?:\s+for\s+\S+)?$/.test(z)?{kind:"harmless"}:J(z?.replace(/\s+for\s+\S+$/,""));if(/^submodule\..+\.update$/.test($))return z!==void 0&&z.trimStart().startsWith("!")?J(z.trimStart().slice(1)):z===void 0?{kind:"unresolved"}:{kind:"harmless"};if(/^sendemail\.(?:.+\.)?smtpserver$/.test($))return z!==void 0&&!z.startsWith("/")?{kind:"harmless"}:J(z);if(/^credential\.(?:.+\.)?helper$/.test($)){if(z==="")return{kind:"harmless"};if(z===void 0)return{kind:"unresolved"};let Y=z.trimStart();return J(Y.startsWith("!")?Y.slice(1):Y.startsWith("/")?Y:`git credential-${Y}`)}if(M3.some((Y)=>Y.test($)))return J(z);if($==="core.hookspath")return z==="/dev/null"?{kind:"harmless"}:{kind:"unresolved"};if($==="include.path"||/^includeif\..+\.path$/.test($))return{kind:"unresolved"};if($==="protocol.allow")return z!==void 0&&/^(?:never|user)$/i.test(z)?{kind:"harmless"}:{kind:"unresolved"};if($==="protocol.ext.allow")return z!==void 0&&/^never$/i.test(z)?{kind:"harmless"}:{kind:"unresolved"};return{kind:"harmless"}}function T1(Z){return/[$\x60]/.test(Z)||["","x","/x","!x"].some((z)=>O1(Z,z).kind!=="harmless")}var V3=new Set(["GIT_PAGER","GIT_EDITOR","GIT_SEQUENCE_EDITOR","GIT_EXTERNAL_DIFF","GIT_SSH","GIT_SSH_COMMAND","GIT_ASKPASS","SSH_ASKPASS","GIT_PROXY_COMMAND","PAGER","EDITOR","VISUAL"]),G3=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function U3(Z){let z=/'((?:[^']|'\\'')*)'/y,$=(X)=>X.replace(/'\\''/g,"'"),J=[],Y=0;while(Y<Z.length){if(/\s/.test(Z[Y])){Y++;continue}z.lastIndex=Y;let X=z.exec(Z);if(!X)return null;if(Y=z.lastIndex,Z[Y]==="="){z.lastIndex=Y+1;let Q=z.exec(Z);if(!Q)return null;Y=z.lastIndex,J.push([$(X[1]),$(Q[1])])}else{let Q=$(X[1]),B=Q.indexOf("=");J.push(B<0?[Q,void 0]:[Q.slice(0,B),Q.slice(B+1)])}}return J}function j3(Z,z,$){let J=[],Y=!1,X=(H,M,V=!0)=>{if(!V||/[$\x60]/.test(H)){Y=!0;return}let G=O1(H,M);if(G.kind==="unresolved")Y=!0;else if(G.kind==="command")J.push({text:G.text,kind:"shell"})},Q=(H,M)=>{let V=H.indexOf("="),G=V<0?H:H.slice(0,V),U=V<0?"true":H.slice(V+1);if(!M)return X(G,U);if(T1(G))Y=!0},B=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let H=z+1;H<Z.length;H++){let M=Z[H];if(!M.startsWith("-")||M==="-")break;if(M==="--")break;if(M==="-c"){if(H+1>=Z.length)break;Q(Z[H+1],$(H+1)),H++}else if(M.startsWith("-c")&&!M.startsWith("--"))Q(M.slice(2),$(H));else if(M==="--config-env"||M.startsWith("--config-env=")){let V=M==="--config-env"?Z[++H]??"":M.slice(13),G=V.indexOf("="),U=G<0?V:V.slice(0,G);if($(H)||T1(U))Y=!0}else if(M.startsWith("--exec-path="))Y=!0;else if(B.has(M))H++}let K=new Map;for(let H=0;H<z;H++){let M=Z[H].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!M)continue;let[,V,G]=M,U=$(H);if(V3.has(V))if(U)Y=!0;else J.push({text:G,kind:"shell"});else if(G3.has(V)){if(U||G!=="/dev/null"||V==="GIT_EXEC_PATH"||V==="GIT_TEMPLATE_DIR")Y=!0}else if(V==="GIT_ALLOW_PROTOCOL"){if(U||G.split(":").includes("ext"))Y=!0}else if(V==="GIT_CONFIG_PARAMETERS"){let j=U?null:U3(G);if(j===null)Y=!0;else for(let[F,L]of j)X(F,L??"true")}else if(/^GIT_CONFIG_(?:KEY|VALUE)_\d+$/.test(V)){let j=V.replace(/^GIT_CONFIG_(?:KEY|VALUE)_/,""),F=K.get(j)??{};if(V.startsWith("GIT_CONFIG_KEY_"))F.key=G;else F.value=G;if(U)F.opaque=!0;K.set(j,F)}}for(let H of K.values()){if(H.key===void 0)continue;if(H.opaque)Q(`${H.key}=`,!0);else X(H.key,H.value)}if(J.length===0&&!Y)return null;return{programs:J,unresolved:Y}}function fZ(Z){if(/^~/.test(Z))return null;let z="";for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return null;z+=Z.slice($+1,Y),$=Y}else if(J==="$"||J==="`")return null;else if(J==='"'){let Y=$+1;for(;Y<Z.length&&Z[Y]!=='"';Y++){let X=Z[Y];if(X==="$"||X==="`")return null;if(X==="\\"&&Y+1<Z.length&&/[$\x60"\\\n]/.test(Z[Y+1])){if(Z[++Y]!==`
4
- `||a.on)z+=Z[Y];continue}z+=X}if(Y>=Z.length)return null;$=Y}else if(J==="\\"){if($+1>=Z.length)return null;z+=Z[++$]}else if("*?[{}".includes(J))return null;else z+=J}return z}function q1(Z){let z=null;for(let $=0;$<Z.length;$++){let J=Z[$];if(z==="'"){if(J==="'")z=null;continue}if(J==="\\"){$++;continue}if(J==="$"||J==="`")return!1;if(z==='"'){if(J==='"')z=null;continue}if(J==="'"||J==='"'){z=J;continue}if(J==="<"&&Z[$+1]==="<"&&Z[$+2]!=="<")return!1}return z===null}var W3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]),F3=new Set(["--rcfile","--init-file"]),UZ=(Z)=>Z.replace(/\$'(?:[^'\\]|\\[\s\S])*'/g,(z)=>z.replace(/\\[\s\S]/g,($)=>$==="\\'"?"\\x27":$));function xZ(Z,z,$=fZ){if(z<0||z>=Z.length)return null;let J=L0($(Z[z])??"");if(J==="eval"){let B=z+1;if(fZ(Z[B]??"")==="--")B++;let K=Z.slice(B);if(K.length===0)return null;if(K.length>1)return{program:null,literal:!1};let H=fZ(K[0]);return H!==null&&q1(H)?{program:H,literal:!0}:{program:H,literal:!1}}if(!W3.has(J))return null;let Y=!1,X=z+1;for(;X<Z.length;X++){let B=fZ(Z[X]);if(B===null){if(Y)break;return/^"[^"]*"$/.test(Z[X])?null:{program:null,literal:!1}}if(B==="--"){X++;break}if(!/^[-+]./.test(B))break;if(B.startsWith("--")){if(F3.has(B))X++;continue}let K=B.slice(1);if(B[0]==="-"&&K.includes("c"))Y=!0;if(/[oO]/.test(K))X++}if(!Y||X>=Z.length)return null;let Q=fZ(Z[X]);return Q!==null&&q1(Q)?{program:Q,literal:!0}:{program:Q,literal:!1}}function N3(Z,z,$){let J=D3(Z,z,$);if(J===null)return{programs:[],unresolved:!0};let Y=new Set;for(let{scripts:X,mayFail:Q}of J){let B=_3(X.join(`
5
- `));if(B===null){if(Q)continue;return{programs:[],unresolved:!0}}if(B.executes)return{programs:X.map((K)=>({text:K,kind:"shell"})),unresolved:!0};for(let K of B.writes)Y.add(K)}if(Y.size===0)return null;return{programs:[],unresolved:!1,writes:[...Y]}}var P0="quiet silent debug follow-symlinks posix regexp-extended separate sandbox unbuffered null-data zero-terminated binary help version in-place file expression line-length".split(" ");function D3(Z,z,$){let J=[],Y=[],X=!1,Q=-1,B=!1,K=!1;for(let V=z+1;V<Z.length;V++){let G=Z[V];if(K||!/^-./.test(G)){Y.push(V);continue}if($(V))return null;if(G==="--"){K=!0;continue}let U,j;if(G[1]==="-"){let F=G.indexOf("="),L=(F<0?G:G.slice(0,F)).slice(2),y=P0.filter((l)=>l.startsWith(L)),E=P0.includes(L)?L:y.length===1?y[0]:"";if(P0.indexOf(E)<15){if(!E)return null;continue}if(U=E[0],F>=0)j=G.slice(F+1)}else{let F=1;while("nrEsuzb".includes(G[F]??"_"))F++;if(U=G[F]??"",U==="i"||U==="I"){let L=F===G.length-1&&V+1<Z.length&&!$(V+1)?Z[V+1]:void 0;if(U==="I"){if(B=X=!0,F===G.length-1){if(L===void 0)return null;Q=V+1}}else if(L===""||L?.startsWith("."))X=!0,Q=V+1;continue}if(U==="")continue;if(!"efl".includes(U))return null;j=G.slice(F+1)||void 0}if(U==="f")return null;if(j===void 0){if(j=Z[++V],j===void 0||$(V))return null}if(U==="e")J.push(j)}let H=(V)=>{if(J.length>0)return J;let G=Y.find((U)=>U!==V);return G===void 0?[]:$(G)?null:[Z[G]]},M=[];if(!B)M.push({scripts:H(-1),mayFail:Q>=0&&J.length===0&&Y[0]===Q});if(X)M.push({scripts:H(Q),mayFail:!1});return M.some((V)=>V.scripts===null)?null:M}function _3(Z){let z=[],$=!1,J=0,Y=Z.length,X=()=>Z[J]??"",Q=()=>{while(X()===" "||X()==="\t")J++;let H=J,M=Z.indexOf(`
6
- `,J);return J=M<0?Y:M,Z.slice(H,J)},B=()=>{let H=Q();if(H&&!/^\/dev\/std(?:out|err)$/.test(H))z.push(H)},K=(H,M)=>{for(;J<Y;J++){let V=Z[J];if(V===`
7
- `)return!1;if(V==="\\"){if(++J>=Y)return!1}else if(V===H)return J++,!0;else if(M&&V==="["){let G=J+1;if(Z[G]==="^")G++;if(Z[G]==="]")G++;for(;Z[G]!=="]";G++){if(G>=Y||Z[G]===`
8
- `)return!1;if(Z[G]==="["&&":.=".includes(Z[G+1]||`
9
- `)){let U=Z.indexOf(Z[G+1]+"]",G+2);if(U<0||Z.slice(G,U).includes(`
10
- `))return!1;G=U+1}}J=G}}return!1};while(J<Y){let H=Z[J++];if(H==="/"||H==="\\"){let M=H==="\\"?Z[J++]??"":"/";if(!M||M===`
11
- `||!K(M,!0))return null}else if(H==="#")Q();else if(":btTv".includes(H)){while(X()===" "||X()==="\t")J++;while(J<Y&&!/[\s;]/.test(X()))J++}else if("aic".includes(H)){while(X()===" "||X()==="\t")J++;if(X()==="\\")J+=2;for(;J<Y&&Z[J]!==`
12
- `;J++)if(Z[J]==="\\")J++}else if(H==="e")$=!0,Q();else if(H==="r"||H==="R")Q();else if(H==="w"||H==="W")B();else if(H==="s"||H==="y"){let M=Z[J++]??"";if(!M||M===`
13
- `||M==="\\"||!K(M,H==="s")||!K(M,!1))return null;for(;H==="s"&&" \tgpiImMe0123456789w".includes(X()||"_");J++){if(X()==="e")$=!0;if(X()==="w"){J++,B();break}}}}return{writes:z,executes:$}}var I3=new Set(["-exec","-execdir","-ok","-okdir"]),T3=new Set(["-exec","-execdir"]),q3=new Set("0oprtx"),C3=new Set("adEILnPsJRS"),P3=new Set("eil"),eZ={"--null":"flag","--open-tty":"flag","--interactive":"flag","--no-run-if-empty":"flag","--verbose":"flag","--exit":"flag","--show-limits":"flag","--help":"flag","--version":"flag","--arg-file":"value","--delimiter":"value","--max-args":"value","--max-procs":"value","--max-chars":"value","--process-slot-var":"value","--max-lines":"value","--eof":"optional","--replace":"optional"};function O3(Z){if(Object.hasOwn(eZ,Z))return eZ[Z];let z=Object.keys(eZ).filter(($)=>$.startsWith(Z));return z.length===1?eZ[z[0]]:null}function kZ(Z,z,$,J=0){while(z<Z.length){if($(z)){z++;continue}let Y=Z[z];if(Y==="--"){z++;break}if(!Y.startsWith("-")||Y==="-")break;if(Y.startsWith("--")){let B=Y.indexOf("="),K=O3(B<0?Y:Y.slice(0,B));if(K===null){if(J>=4)return[];return[...kZ(Z,z+1,$,J+1),...kZ(Z,z+2,$,J+1)]}z+=K==="value"&&B<0?2:1;continue}let X=!1,Q=!1;for(let B=1;B<Y.length;B++){let K=Y[B];if(q3.has(K))continue;if(P3.has(K))break;if(C3.has(K)){X=B===Y.length-1;break}Q=!0;break}if(Q){if(J>=4)return[];return[...kZ(Z,z+1,$,J+1),...kZ(Z,z+2,$,J+1)]}z+=X?2:1}while(z<Z.length&&$(z))z++;return z<Z.length?[z]:[]}function hZ(Z,z,$=()=>!1){if(z<0||z>=Z.length)return[];let J=L0(Z[z]);if(J==="xargs")return[...new Set(kZ(Z,z+1,$))].map((X)=>({start:X,end:Z.length}));if(J!=="find")return[];let Y=[];for(let X=z+1;X<Z.length;X++){if($(X)||!I3.has(Z[X]))continue;let Q=X+1,B=Q;for(;B<Z.length;B++){if($(B))continue;if(Z[B]===";")break;if(Z[B]==="+"&&B>Q&&Z[B-1]==="{}"&&T3.has(Z[X]))break}if(Q<B)Y.push({start:Q,end:B});X=B}return Y}function wZ(Z,z,$){if(z<0||z>=Z.length)return null;let J=L0(Z[z]);if(J==="deno"){let Y=Y3(Z,z,$);if(Y)return Y}if(Object.hasOwn(O0,J)||C1.test(J))return z3(J,Z,z,$);if(t2.has(J))return X3(Z,z,$);if(e2.has(J))return K3(Z,z,$);if(J==="rsync")return B3(Z,z,$);if(J==="git")return j3(Z,z,$);if(J==="sed")return N3(Z,z,$);return null}var v3=600000,b3="Delete via trash guard (rm intercepted and made recoverable)",E3=[".hasna/repos/clones","workspace/repos"],S3=[".hasna",".ssh",".aws"],A0={rmdir:"`rmdir` is a delete that trash-guard does not rewrite (it takes rmdir's flags, not rm's). Re-run it as `rm -d -- <path>` for an empty directory, or `rm -r -- <path>` for a non-empty one, and it is redirected into trash.",unlink:"`unlink` is a delete that trash-guard does not rewrite. Re-run it as `rm -- <path>` and it is redirected into trash.",shred:"`shred` destroys content irrecoverably and is never allowed. Re-run it as `rm -- <path>` and it is redirected into trash."},f3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env"]),k3={sudo:["-u","--user","-g","--group","-p","--prompt","-C","--chdir","-h","--host","-r","--role","-t","--type","-U","--other-user"],doas:["-u","-C"],env:["-u","--unset","-C","--chdir","-S","--split-string"],nice:["-n","--adjustment"],ionice:["-c","--class","-n","--classdata","-p","--pid"],stdbuf:["-i","-o","-e","--input","--output","--error"],time:["-f","--format","-o","--output"],timeout:["-s","--signal","-k","--kill-after"],nohup:[],setsid:[],command:[],builtin:[],exec:["-a"]},x3={timeout:1},h3={sudo:{short:{A:W,B:W,b:W,E:W,H:W,i:W,k:W,N:W,n:W,P:W,S:W,s:W,C:_,g:_,p:_,r:_,T:_,t:_,U:_,u:_,e:s,l:s,v:s,D:C,R:C,h:C,K:C,V:C},long:{askpass:W,bell:W,background:W,"close-from":_,chdir:C,"preserve-env":EZ,edit:s,group:_,"set-home":W,help:C,host:C,login:W,"remove-timestamp":C,"reset-timestamp":W,list:s,"no-update":W,"non-interactive":W,"preserve-groups":W,prompt:_,chroot:C,role:_,stdin:W,shell:W,type:_,"command-timeout":_,"other-user":_,user:_,version:C,validate:s},assignments:!0},doas:{short:{n:W,s:W,u:_,C,L:C},long:{}},flock:{short:{s:W,x:W,e:W,n:W,u:W,o:W,F:W,w:_,E:_,h:C,V:C},long:{shared:W,exclusive:W,unlock:W,nonblock:W,nonblocking:W,nb:W,timeout:_,wait:_,"conflict-exit-code":_,close:W,"no-fork":W,fcntl:W,verbose:W,help:C,version:C},positionals:[/^[\s\S]+$/]}},w3={...C0,...h3},k1=new Set(["-c","--command"]),g3=new Set(["busybox","toybox"]),b0=new Set(["rm","rmdir","unlink","shred"]),u3=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]),l3=new Set(["-C","-c","--git-dir","--work-tree","--namespace","--exec-path","--config-env"]),m3=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/;function i(Z){return m3.test(R(Z))}function uZ(Z){return Z.map((z)=>z.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var x1=/^[A-Za-z_][A-Za-z0-9_]*=/;function $0(Z){let z=Z.lastIndexOf("/");return z>=0?Z.slice(z+1):Z}var L1={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
14
- `,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function p3(Z,z){let $="",J=z;while(J<Z.length&&Z[J]!=="'"){if(Z[J]!=="\\"||J+1>=Z.length){$+=Z[J++];continue}let Y=Z[J+1],X=Z.slice(J+1),Q;if(Object.hasOwn(L1,Y))$+=L1[Y],J+=2;else if(Q=X.match(/^[0-7]{1,3}/))$+=String.fromCharCode(parseInt(Q[0],8)&255),J+=1+Q[0].length;else if((Q=X.match(/^x([0-9A-Fa-f]{1,2})/))||(Q=X.match(/^u([0-9A-Fa-f]{1,4})/))||(Q=X.match(/^U([0-9A-Fa-f]{1,8})/))){let B=parseInt(Q[1],16);$+=B<=1114111?String.fromCodePoint(B):"",J+=1+Q[0].length}else if(Y==="c"&&J+2<Z.length)$+=String.fromCharCode(Z.charCodeAt(J+2)&31),J+=3;else $+=`\\${Y}`,J+=2}return{text:$,end:Math.min(J+1,Z.length)}}function v(Z){return h1(Z,!0)}function h1(Z,z){let $="",J=0;while(J<Z.length){let Y=Z[J];if(z&&Y==="$"&&Z[J+1]==="'"){let X=p3(Z,J+2);$+=X.text,J=X.end;continue}if(z&&Y==="$"&&Z[J+1]==='"'){J++;continue}if(Y==="\\"){if(J+1<Z.length)$+=Z[J+1];J+=2;continue}if(Y==="'"){let X=Z.indexOf("'",J+1);if(X===-1){$+=Z.slice(J+1);break}$+=Z.slice(J+1,X),J=X+1;continue}if(Y==='"'){J++;while(J<Z.length&&Z[J]!=='"'){if(Z[J]==="\\"&&J+1<Z.length){let X=Z[J+1];$+=a.on||/[$`"\\]/.test(X)?X:X===`
15
- `?"":`\\${X}`,J+=2;continue}$+=Z[J],J++}J++;continue}$+=Y,J++}return $}function J0(Z){if(tZ(Z))return!0;let z=null;for(let $=0;$<Z.length;$++){let J=Z[$];if(z==="'"){if(J==="'")z=null;continue}if(J==="\\"){$++;continue}if(J==="`"||J==="$")return!0;if(J==='"'){z=z===null?'"':null;continue}if(z!==null)continue;if(J==="'")z="'";else if(J==="*"||J==="?")return!0;else if(J==="["&&c3(Z,$+1,"]"))return!0}return!1}function c3(Z,z,$){let J=null;for(let Y=z;Y<Z.length;Y++){let X=Z[Y];if(J!=="'"&&X==="\\")Y++;else if(J===null&&X===$)return!0;else if(X==="'"&&J!=='"')J=J==="'"?null:"'";else if(X==='"'&&J!=="'")J=J==='"'?null:'"'}return!1}function i3(Z){if(!J0(Z))return!1;let z=JZ(Z);return z===null||z.some(($)=>v($).split(/[^A-Za-z0-9_]+/).some((J)=>b0.has(J)))}function FZ(Z){return $0(v(Z))}var w1={deep:!0};function E0(Z,z){return Z.replace(/\\([$`\\"])/g,($,J)=>J==='"'&&!z?$:J)}function d3(Z,z,$){let J=[],Y=z+1;while(Y<$-1){let X=Z[Y];if(X==="\\"){Y+=2;continue}if(X==="`"){let Q=lZ(Z,Y);if(Q<0)return null;J.push(E0(Z.slice(Y+1,Q-1),!0)),Y=Q;continue}if(X==="$"&&Z[Y+1]==="("){let Q=XZ(Z,Y+1);if(Q<0)return null;J.push(Z.slice(Y+2,Q-1)),Y=Q;continue}Y++}return J}function s3(Z){let z=[],$=0;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==="`"){let Y=lZ(Z,$);if(Y<0)return null;z.push(E0(Z.slice($+1,Y-1),!1)),$=Y;continue}if(J==="$"&&Z[$+1]==="("){let Y=XZ(Z,$+1);if(Y<0)return null;z.push(Z.slice($+2,Y-1)),$=Y;continue}$++}return z}function A1(Z,z,$,J){let Y=z+1;for(let X of $){let Q=Math.min(Y,Z.length);for(;;){if(Y>Z.length){Y=Z.length+1;break}let K=Z.indexOf(`
16
- `,Y),H=K===-1?Z.length:K,M=Z.slice(Y,H).replace(/\r$/,"");if(X.stripTabs)M=M.replace(/^\t+/,"");if(M===X.delimiter)break;Y=H+1}let B=Z.slice(Q,Math.min(Y,Z.length));if(X.owner.push(B),!X.quoted){let K=s3(B);if(!K)return-1;J.push(...K)}if(Y<=Z.length){let K=Z.indexOf(`
17
- `,Y);Y=(K===-1?Z.length:K)+1}}return Math.min(Y-1,Z.length)}function g1(Z,z){let $=Z.indexOf("'",z+1);return $===-1?-1:$+1}function lZ(Z,z){let $=z+1;while($<Z.length){if(Z[$]==="\\"){$+=2;continue}if(Z[$]==="`")return $+1;$++}return-1}function u1(Z,z){let $=z+1;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==='"')return $+1;if(J==="`"){let Y=lZ(Z,$);if(Y<0)return-1;$=Y;continue}if(J==="$"&&Z[$+1]==="("){let Y=XZ(Z,$+1);if(Y<0)return-1;$=Y;continue}$++}return-1}function DZ(Z,z){if(Z[z]!=="<"||Z[z+1]!=="<"||Z[z+2]==="<")return null;let $=z+2,J=Z[$]==="-";if(J)$++;while(Z[$]===" "||Z[$]==="\t")$++;let Y="",X=!1;while($<Z.length&&!/[\s;|&<>()]/.test(Z[$])){let Q=Z[$];if(Q==="'"||Q==='"'){let B=Z.indexOf(Q,$+1);if(B<0)return null;Y+=Z.slice($+1,B),X=!0,$=B+1;continue}if(Q==="\\"){if($+1>=Z.length)return null;Y+=Z[$+1],X=!0,$+=2;continue}Y+=Q,$++}return Y?{delimiter:Y,stripTabs:J,quoted:X,end:$}:null}function z0(Z,z,$){let J=z+1;for(let Y of $)for(;;){if(J>Z.length)return-1;let X=Z.indexOf(`
18
- `,J),Q=X===-1?Z.length:X,B=Z.slice(J,Q);if(B.endsWith("\r"))B=B.slice(0,-1);let K=Y.stripTabs?B.length-B.replace(/^\t+/,"").length:0;if(Y.stripTabs)B=B.slice(K);if(B===Y.delimiter){J=Q+1;break}if(B.startsWith(Y.delimiter)&&/^\s*\)/.test(B.slice(Y.delimiter.length))){if(Y===$[$.length-1])return J+K+Y.delimiter.length;return-1}if(X===-1)return-1;J=X+1}return J-1}function XZ(Z,z){let $=Z.length,J=Z[z+1]==="(",Y=0,X=z,Q=[];while(X<$){let B=Z[X];if(B==="\\"){X+=2;continue}if(B==="'"){let K=g1(Z,X);if(K<0)return-1;X=K;continue}if(B==='"'){let K=u1(Z,X);if(K<0)return-1;X=K;continue}if(B==="`"){let K=lZ(Z,X);if(K<0)return-1;X=K;continue}if(!J&&B==="<"&&Z[X+1]==="<"){if(Z[X+2]==="<"){X+=3;continue}let K=DZ(Z,X);if(!K)return-1;Q.push(K),X=K.end;continue}if(B===`
19
- `&&Q.length>0){let K=z0(Z,X,Q);if(K<0)return-1;Q=[],X=K;continue}if(!J&&B==="#"&&/[\s;&|(]/.test(Z[X-1])){let K=Z.indexOf(`
20
- `,X);if(K<0)return-1;X=K;continue}if(B==="(")Y++;else if(B===")"){if(Y--,Y===0)return Q.length>0?-1:X+1}X++}return-1}function b(Z,z={}){let $=z.deep===!0,J=[],Y=[],X=[],Q=new Set,B=[],K=[],H=-1,M=!1,V=!0,G=0,U=Z.length,j=(q)=>{if(H>=0){let N=X.length;if(X.push({text:Z.slice(H,q),start:H,end:q}),M)Q.add(N);H=-1,M=!1}},F=(q)=>{if(j(q),X.length>0)J.push($?{words:X,redirects:Q,heredocs:B}:{words:X,redirects:Q});if(X=[],Q=new Set,$)B=[];M=!1},L=(q)=>g1(Z,q),y=(q)=>lZ(Z,q),E=(q)=>XZ(Z,q),l=(q)=>u1(Z,q);while(G<U){let q=Z[G];if(q===" "||q==="\t"||q==="\r"){j(G),G++;continue}if(q===`
21
- `){if(F(G),K.length>0){let N=A1(Z,G,K,Y);if(K=[],N<0)V=!1,G=U;else G=N;continue}G++;continue}if(q===";"){F(G),G++;continue}if(q==="&"){F(G),G+=Z[G+1]==="&"?2:1;continue}if(q==="|"){F(G),G+=Z[G+1]==="|"?2:1;continue}if($&&q==="("&&H>=0&&"?*+@!".includes(Z[G-1])){V=!1,G=U;continue}if(q==="("||q===")"){F(G),G++;continue}if(q==="<"&&Z[G+1]==="<"&&Z[G+2]!=="<"){let N=Z.slice(G+2).match(/^-?[ \t]*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/);if(!N){V=!1,G=U;continue}if($){let CZ=G+2+N[0].length;if(CZ<U&&!/[\s;&|()<>]/.test(Z[CZ])){V=!1,G=U;continue}j(G),K.push({delimiter:N[2],quoted:N[1]!=="",stripTabs:N[0].startsWith("-"),owner:B}),G=CZ;continue}let A=Z.indexOf(`
22
- `,G+2+N[0].length);if(A===-1){V=!1,G=U;continue}let h=Z.slice(A+1),w=n3(h,N[2]);if(w===-1){V=!1,G=U;continue}j(G),G=A+1+w+N[2].length;continue}if(q===">"||q==="<"){if(H>=0&&/^\d+$/.test(Z.slice(H,G)))H=-1;if(j(G),M=!0,G++,Z[G]===q||Z[G]==="&"||q===">"&&Z[G]==="|"||q==="<"&&Z[G]===">")G++;continue}if(q==="'"){if(H<0)H=G;let N=L(G);if(N<0)V=!1,G=U;else G=N;continue}if(q==='"'){if(H<0)H=G;let N=l(G),A=N<0||!$?[]:d3(Z,G,N);if(N<0||!A)V=!1,G=U;else Y.push(...A),G=N;continue}if(q==="`"){if(H<0)H=G;let N=y(G);if(N<0)V=!1,G=U;else{let A=Z.slice(G+1,N-1);Y.push($?E0(A,!1):A),G=N}continue}if(q==="$"&&Z[G+1]==="("){if(H<0)H=G;let N=E(G+1);if(N<0)V=!1,G=U;else Y.push(Z.slice(G+2,N-1)),G=N;continue}if(q==="\\"){if(H<0)H=G;if(G+1>=U)V=!1,G=U;else G+=2;continue}if(H<0)H=G;G++}if(F(U),K.length>0&&A1(Z,U,K,Y)<0)V=!1;return{segments:J,trustworthy:V,substitutions:Y}}function n3(Z,z){let $=0;while($<=Z.length){let J=Z.indexOf(z,$);if(J===-1)return-1;let Y=J===0||Z[J-1]===`
23
- `,X=J+z.length,Q=X===Z.length||Z[X]===`
24
- `||Z[X]==="\r";if(Y&&Q)return J;$=J+1}return-1}function R(Z){return h1(Z,!1)}function x(Z){let z=0,$=0;while(z<Z.words.length&&$++<32){if(Z.redirects.has(z)){z++;continue}let J=Z.words[z].text,Y=v(J);if(x1.test(Y)&&!Y.startsWith("-")){z++;continue}if(u3.has(Y)){z++;continue}let X=$0(Y);if(X==="command")for(let B of Z.words.filter((K,H)=>H>z&&!Z.redirects.has(H))){let K=v(B.text);if(K==="--"||!K.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(K))return-1}let Q=k3[X];if(Q){let B=z;z++;while(z<Z.words.length){if(Z.redirects.has(z)){z++;continue}let H=v(Z.words[z].text);if(!H.startsWith("-")||H==="-")break;if(H==="--"){z++;break}if(X==="env"&&(/^-[iv0]*S/.test(H)||/^--split-string(?:=|$)/.test(H)))return B;if(z++,Q.includes(H)||X==="exec"&&/^-[cl]*a$/.test(H)){while(Z.redirects.has(z))z++;z++}}let K=x3[X]??0;while(K>0&&z<Z.words.length){let H=v(Z.words[z].text);if(H.startsWith("-")&&H!=="-")break;z++,K--}continue}return z}return-1}function o3(Z,z){let $=[],J=!1;for(let Y=z+1;Y<Z.words.length;Y++){if(Z.redirects.has(Y))continue;let X=R(Z.words[Y].text);if(!J){if(X==="--"){J=!0;continue}if(X.startsWith("-")&&X!=="-")continue}$.push(Z.words[Y])}return $}function S0(Z){return E3.map((z)=>WZ(Z,...z.split("/")))}function a3(Z,z){if(Z==="~"||Z==="$HOME"||Z==="${HOME}")return z;if(Z.startsWith("~/"))return WZ(z,Z.slice(2));if(Z.startsWith("$HOME/"))return WZ(z,Z.slice(6));if(Z.startsWith("${HOME}/"))return WZ(z,Z.slice(8));return Z}function Z0(Z,z,$){let J=R(Z);if(!J)return null;if(J.includes("`"))return null;if(J==="$HOME"||J==="${HOME}"||J==="$HOME/"||J==="${HOME}/")return $;if(J.replace(/\$\{HOME\}/g,"").replace(/\$HOME/g,"").includes("$"))return null;if(/[*?[\]]/.test(J))return null;if(J.startsWith("~")){let B=a3(J,$);if(B===J)return null;J=B}let Q=(A3(J)?y3(J):R3(z,J)).replace(/\/+$/,"");return Q===""?"/":Q}function r(Z,z){return Z===z||Z.startsWith(`${z}${v0}`)}var r3=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/,t3=!1,e3=/^[A-Za-z0-9._@+-]{1,128}$/,Z4=512;function jZ(Z){return`'${Z.replace(/[\u0000-\u001f\u007f-\u009f]/g,"?").slice(0,Z4).replace(/'/g,"'\\''")}'`}function y1(Z){return e3.test(Z)?`\`${Z}\``:"a name that is not a plain identifier"}function $4(Z,z){let $=`${WZ(z,".hasna","scratchpad","scratch")}${v0}`;if(!Z.startsWith($))return null;let[J,Y]=Z.slice($.length).split(v0);if(!J)return{content:!1,reason:"the scratch root itself holds every session, not one session's content"};if(J.endsWith(".")||!r3.test(J))return{content:!1,reason:`${y1(J)} is not a session id this carve-out accepts (real ids are mixed case, e.g. \`ses_ebbb3f564ffe7PDf32UBmlNI3v\`)`};if(!Y)return t3?{content:!0}:{content:!1,reason:`${y1(J)} is a session root; removing it would also remove its \`meta.json\` and \`.lock\` control files, and whether the root itself is scratch is an open decision (Todos 264c4be0) \u2014 remove specific children instead`};let X=Y.normalize("NFKC").toLowerCase();if(X==="meta.json"||X===".lock")return{content:!1,reason:`\`${X}\` is session control state, not scratch`};return{content:!0}}function J4(Z,z){if(Z===z)return`${jZ(Z)} is the home directory itself, which is never deleted or trashed. Delete a specific file or directory inside it instead.`;for(let $ of D1){if(Z!==$&&!r($,Z))continue;return $==="/"?`${jZ(Z)} is the filesystem root, which is never deleted.`:`${jZ(Z)} is the system root \`${$}\` (or an ancestor of it), which is never deleted or trashed.`}for(let $ of S3){let J=WZ(z,$),Y=r(Z,J);if(!Y&&!r(J,Z))continue;if($===".hasna"&&Y){let X=$4(Z,z);if(X?.content===!0)continue;if(X&&X.content===!1)return`${jZ(Z)} is inside the protected \`~/${$}\` tree and is not sanctioned scratch, because ${X.reason}. Nothing under \`~/${$}\` is deleted or trashed outside that one carve-out.`}return Y?`${jZ(Z)} is inside the protected \`~/${$}\` tree, which is never deleted or trashed. Delete a specific file inside it, and only when you are sure.`:`${jZ(Z)} contains the protected \`~/${$}\` tree, which is never deleted or trashed. Delete a specific file or directory inside it instead.`}return null}function z4(Z,z,$){let J=S0($);if(J.some((Y)=>r(z,Y)))return!0;return Z.some((Y)=>Y!==null&&J.some((X)=>r(Y,X)))}var R1=new WeakMap;function Y4(Z){let z=R1.get(Z);if(z)return z;let $=Z.words.map((Q)=>v(Q.text)),J=$.findIndex((Q)=>Q==="-exec"||Q==="-execdir"||Q==="-ok"||Q==="-okdir"),Y=-1;Z.words.forEach((Q,B)=>{if(k1.has(R(Q.text)))Y=B});let X={findDelete:$.includes("-delete"),findExecDelete:J>=0&&$.slice(J).some((Q)=>b0.has($0(Q))),namesDelete:$.some((Q)=>b0.has($0(Q))),lastFlockCommand:Y,textMention:i(G4(Z)),envMention:i(uZ(Z.words.map((Q)=>R(Q.text)))),bodiesMention:i((Z.heredocs??[]).join(`
25
- `))};return R1.set(Z,X),X}var X4=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]);function Q4(Z,z){if(!X4.has(FZ(Z.words[z].text)))return!1;for(let $=z+1;$<Z.words.length;$++){if(Z.redirects.has($))continue;let J=R(Z.words[$].text);if(J==="--")return $+1>=Z.words.length;if(/^-[A-Za-z]*s/.test(J))return!0;if(/^-[A-Za-z]*c/.test(J))return!1;if(J==="-o"||J==="+o"||J==="-O"||J==="+O"){$++;continue}if(!/^[-+]/.test(J)||J==="-")return J==="-"}return!0}var y0=(Z)=>Z.kind==="rm"||Z.kind==="refuse",K4="This command's command word or wrapper arguments cannot be read before it runs (an expansion such as a variable, substitution, brace or glob pattern, an unknown or unsupported option, a working directory or a non-decimal duration), so this hook cannot tell which word runs, and one of its words could run a delete. Run the delete as a plain `rm -- <path>` command, which is redirected into trash.",B4="This delete's brace pattern names more paths than this hook will check. Run the delete on explicit paths with `rm -- <path> \u2026`, which is redirected into trash.",H4="This delete's brace pattern expands to a path under a protected repository checkout. Deletes there are refused; run them through the owning workflow, and write any other delete out as plain paths.",M4="This command's wrapper arguments can be read as running two different deletes, so no single rewrite is safe. Run the delete as a plain `rm -- <path>` command, which is redirected into trash.";function f0(Z){let z=[];Z.words.forEach((Y,X)=>{if(!Z.redirects.has(X))z.push(X)});let $=z.map((Y)=>{let X=Z.words[Y].text;return{text:v(X),opaque:J0(X)}}),J=zZ($,w3);if(J===null)return null;return J.index<0?-1:z[J.index]}function R0(Z,z,$,J){let Y=FZ(Z.words[z].text);if(Y==="cd"){let K=Z.words[z+1];if(!K)return{kind:"none"};return{kind:"cd",cwd:Z0(K.text,$,J.home)??J.cwd}}if(Object.hasOwn(A0,Y))return{kind:"refuse",reason:A0[Y]};let X=l1(Z,z,$,J);if(X)return X;if(Y==="rm"){let K=o3(Z,z);if(K.length===0)return{kind:"none"};let H={word:Z.words[z],operands:K},M=S0(J.home),V=(j)=>j!==null&&M.some((F)=>r(j,F)),G=[],U=[];for(let j of K){let F=Z0(j.text,$,J.home);if(G.push(F),!j.text.includes("{"))continue;let L=JZ(j.text);if(L===null)return{kind:"refuse",reason:B4};for(let y of L){let E=Z0(y,$,J.home);if(E===null)continue;if(V(E)&&!V(F))return{kind:"refuse",reason:H4};U.push(E)}}if(z4(G,$,J.home))return H.cwdOnly=G.every((j)=>j!==null&&!V(j)),{kind:"rm",hit:H,handoff:!0,protectedReason:null};for(let j of[...G,...U]){if(!j)continue;let F=J4(j,J.home);if(F)return{kind:"rm",hit:H,handoff:!1,protectedReason:F}}return{kind:"rm",hit:H,handoff:!1,protectedReason:null}}if(g3.has(Y)){let K=Z.words.findIndex((M,V)=>V>z&&!R(M.text).startsWith("-")),H=K>=0?FZ(Z.words[K].text):"";if(H==="rm"||Object.hasOwn(A0,H))return{kind:"refuse",reason:`\`${Y} ${H}\` runs the ${Y} applet, whose own \`rm\` is not GNU \`rm\` and cannot be rewritten in place. Run the delete as \`rm -- <path>\`, which is redirected into trash.`};return{kind:"none"}}if(Y==="git"){let K=k0(Z,z);if(K==="rm"||K==="clean"){if(!(K==="rm"?U4(Z,z):m1(Z,z)))return{kind:"refuse",reason:K==="rm"?"`git rm` is refused: without `--cached` it deletes the working-tree file, and its semantics are not `rm`'s. Use `rm -- <path>` (intercepted and redirected into trash) to remove the file, or `git rm --cached -- <path>` to unstage it without deleting.":"`git clean` deletes untracked files irrecoverably and is refused. Remove them explicitly with `rm -- <path>` (intercepted and redirected into trash), or preview with `git clean -n`."}}return{kind:"none"}}let Q=Y4(Z);if(Y==="find"){if(Q.findDelete)return{kind:"refuse",reason:"`find -delete` deletes files irrecoverably and is refused. List the paths first (`find \u2026 -print`), then remove them explicitly with `rm -- <path>` so the delete is redirected into trash."};if(Q.findExecDelete)return{kind:"refuse",reason:"`find -exec <delete>` is refused: the delete runs through find, not through `rm`, and cannot be redirected into trash. Remove the paths explicitly with `rm -- <path>`."};return{kind:"none"}}if(Y==="xargs"&&Q.namesDelete)return{kind:"refuse",reason:"`xargs rm` takes its targets from stdin, so this hook cannot verify what would be deleted. Pipe the paths into an explicit `rm -- <path> \u2026` instead, which is redirected into trash."};let B=Y==="flock"?Q.lastFlockCommand>z:k1.has(Y);if(f3.has(Y)||B){let K=Q4(Z,z)?J.bodiesMention:Q.bodiesMention;if((Y==="env"?Q.envMention:Q.textMention)||K)return{kind:"refuse",reason:`\`${B?"flock":Y}\` runs a command string this hook cannot rewrite in place. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or as a script that uses \`trash guard\` itself.`}}return{kind:"none"}}function l1(Z,z,$,J,Y={segment:Z,index:z},X=0){let Q=FZ(Z.words[z].text);for(let V of hZ(Z.words.map((G)=>v(G.text)),z,(G)=>Z.redirects.has(G))){if(X>=8)return gZ(Y.segment,Y.index,$,J.home)?{kind:"refuse",reason:V4}:null;let G={words:Z.words.slice(V.start,V.end),redirects:new Set([...Z.redirects].filter((j)=>j>=V.start&&j<V.end).map((j)=>j-V.start))},U=f0(G);for(let j of new Set([x(G),U??-1])){if(j<0)continue;let F=l1(G,j,$,J,Y,X+1);if(F)return F}}let B=Z.words.map((V,G)=>({word:V,at:G})).filter(({at:V})=>!Z.redirects.has(V)),K=B.findIndex(({at:V})=>V===z),H=K<0?null:xZ(B.map(({word:V})=>V.text),K,v);if(H&&!H.literal&&(gZ(Z,z,$,J.home)||gZ(Y.segment,Y.index,$,J.home)))return{kind:"refuse",reason:`\`${Q}\` runs a shell program that is not a plain literal (an expansion, a substitution, ANSI-C \`$'\u2026'\` quoting or several words), so this hook cannot read what it would delete under a protected repository checkout. Write the program out literally, or run it from outside the checkout.`};let M=wZ(Z.words.map((V)=>v(V.text)),z,(V)=>V>=0&&V<Z.words.length&&(Z.redirects.has(V)||J0(Z.words[V].text)));if(!M||!(gZ(Z,z,$,J.home)||gZ(Y.segment,Y.index,$,J.home)))return null;if(!M.unresolved&&!M.programs.some((V)=>i(V.text)))return null;return{kind:"refuse",reason:`\`${Q}\` runs a program locally (an interpreter's inline program or a command-running option) this hook cannot rewrite, and it could delete a file under a protected repository checkout. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or run the command from outside the checkout.`}}var V4="This command nests find/xargs launchers too deeply for this hook to read what they run under a protected repository checkout. Run the inner command directly.";function gZ(Z,z,$,J){let Y=S0(J),X=(Q)=>Q!==null&&Y.some((B)=>r(Q,B));if(Y.some((Q)=>r($,Q)))return!0;for(let Q=z+1;Q<Z.words.length;Q++){if(Z.redirects.has(Q))continue;if(X(Z0(Z.words[Q].text,$,J)))return!0}return!1}function NZ(Z,z){let $={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},J=b(Z,w1);$.trustworthy=J.trustworthy;let Y={cwd:z.cwd,home:z.home,depth:z.depth??0,bodiesMention:i(J.segments.flatMap((K)=>K.heredocs??[]).join(`
26
- `))};if(!J.trustworthy){let K=UZ(Z);return K===Z?$:{...NZ(K,z),trustworthy:!1}}let X=[],Q=(K,H=$.refusals)=>{if(K.kind==="refuse")H.push({reason:K.reason});else if(K.kind==="rm"&&K.handoff)$.handoffHits.push(K.hit);else if(K.kind==="rm"){if($.rmHits.push(K.hit),K.protectedReason)$.protectedHits.push({reason:K.protectedReason})}},B=Y.cwd;for(let K of J.segments){let H=x(K),M=f0(K),V=H<0?{kind:"none"}:R0(K,H,B,Y);if(V.kind!=="cd")Q(V);let G=(U)=>U!==null&&U>=0&&J0(K.words[U].text);if(M===null||G(H)||G(M)){if(K.words.some((U,j)=>!K.redirects.has(j)&&(y0(R0(K,j,B,Y))||i3(U.text))))X.push({reason:K4})}else if(M>=0&&M!==H){let U=R0(K,M,B,Y);if(y0(U))if(y0(V))X.push({reason:M4});else Q(U,X)}if(V.kind==="cd")B=V.cwd}if(Y.depth<3)for(let K of J.substitutions){let H=NZ(K,{cwd:B,home:Y.home,depth:Y.depth+1});if(H.rmHits.length>0||H.refusals.length>0||H.handoffHits.length>0||H.protectedHits.length>0||!H.trustworthy&&i(K)){$.refusals.push({reason:"This command runs a delete inside a command substitution `$(\u2026)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(J.substitutions.some((K)=>i(K)))$.refusals.push({reason:"This command nests a delete inside command substitutions deeper than this hook will follow. Run the delete as a separate `rm -- <path>` command."});return $.refusals.push(...X),$}function G4(Z){return Z.words.map((z)=>z.text).join(" ")}function k0(Z,z){let $=z+1;while($<Z.words.length){let J=R(Z.words[$].text);if(!J.startsWith("-"))return J;if($++,l3.has(J))$++}return null}function U4(Z,z){if(Z.words.slice(z+1).map((J)=>R(J.text)).includes("--cached"))return!0;return m1(Z,z)}function m1(Z,z){let $=Z.words.slice(z+1).map((J)=>R(J.text));return $.includes("-n")||$.includes("--dry-run")}function v1(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function j4(Z,z,$,J){let Y=J?["/usr/bin/env","-i",`HOME=${J.home}`,`PATH=${J.path}`,`HASNA_TRASH_AGENT=${J.agent}`,J.runtime,"--config=/dev/null","--no-env-file","--no-macros","--no-install",$,"guard"].map(v1).join(" "):`${v1($)} guard`,X=[...z].sort((B,K)=>K.word.start-B.word.start),Q=Z;for(let B of X)Q=`${Q.slice(0,B.word.start)}${Y}${Q.slice(B.word.end)}`;return Q}function W4(Z,z,$,J,Y){if(!z||z===Z)return!1;if($.length===0)return!1;let X=NZ(z,{cwd:J,home:Y});if(!X.trustworthy)return!1;if(X.rmHits.length>0||X.handoffHits.length>0)return!1;return X.refusals.length===0}function F4(Z,z){let $={};for(let[J,Y]of Object.entries(Z??{}))$[J]=Y;if($.command=z,typeof $.description!=="string"||$.description.trim()==="")$.description=b3;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=v3;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function N4(Z,z,$,J,Y){if(typeof Z.command!=="string"||Z.command.trim()==="")return!1;if(typeof Z.description!=="string"||Z.description.trim()==="")return!1;if(typeof Z.timeout!=="number"||!Number.isFinite(Z.timeout)||Z.timeout<=0)return!1;if(typeof Z.run_in_background!=="boolean")return!1;if("dangerouslyDisableSandbox"in Z&&typeof Z.dangerouslyDisableSandbox!=="boolean")return!1;return W4(z,Z.command,$,J,Y)}function D4(Z){let z=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return b(Z,w1).segments.some((J)=>{let Y=f0(J);return[x(J),...Y===null?[]:[Y]].some((X)=>{if(J.words.slice(0,X<0?J.words.length:X).some((K)=>x1.test(R(K.text))||z.has(FZ(K.text))))return!0;if(X<0)return!1;let B=J.words[X];return z.has(FZ(B.text))||/^\s*\(\s*\)\s*\{/.test(Z.slice(B.end))})})}function u(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function _4(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function I4(Z){try{if(Z.inspectTrash){let z=Z.inspectTrash();return z.ok?{path:z.path,error:null}:{path:null,error:`${z.code}: ${N1[z.code]}`}}return{path:Z.findTrash(),error:null}}catch(z){return{path:null,error:z instanceof Error?z.message:String(z)}}}var T4="[trash-guard] No verified @hasna/trash guard was found on PATH. This deletion is refused. Install the current @hasna/trash package with Bun and run its setup; the operating-system trash utility is not a compatible guard.",b1="[trash-guard] The rewrite of this command did not verify (the delete could not be redirected cleanly), so the command is refused rather than run unredirected. Re-run the delete as a plain `rm -- <path>` command.";function E1(Z,z){if(Z.refusals.length>0)return u(`[trash-guard] ${Z.refusals[0].reason}`);if(Z.protectedHits.length>0)return u(`[trash-guard] ${Z.protectedHits[0].reason}`);if(!Z.trustworthy)return i(z)?u("[trash-guard] This command could not be parsed to the end (unterminated quote, substitution or here-document), so a delete inside it cannot be redirected. Re-run the delete as a plain `rm -- <path>` command."):{continue:!0};if(Z.rmHits.length===0){if(Z.handoffHits.some(($)=>$.cwdOnly))return u("[trash-guard] This delete runs from inside a protected repository checkout but names only paths outside it. Run it from outside the checkout (`cd /tmp && rm -- <path>`), where it is redirected into trash.");return{continue:!0}}if(Z.handoffHits.length>0)return u("[trash-guard] This command mixes a delete under the protected repo-checkout roots (owned by workspace-repos-guard) with a delete outside them, and a partial rewrite would leave one of them unredirected. Re-run them as separate commands, so each delete is handled by the hook that owns it.");return null}function p1(Z,z){if(Z.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(Z.tool_name??"")){let j=Z.tool_input?.command;if(typeof j!=="string")return u("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(j))return u("[trash-guard] Delete File would bypass recoverable deletion. First use `trash put -- <path>` or the trash_put MCP tool, then submit any remaining edits without the deletion block.");return{continue:!0}}if(Z.tool_name!=="Bash")return{continue:!0};if(typeof Z.tool_input?.command!=="string")return u("[trash-guard] The Bash tool call carried no readable `command`, so this hook cannot verify what would run. Refusing a call it cannot verify. Re-run the delete explicitly as `rm -- <path>` so it can be redirected into trash.");let J=GZ(Z);if(!J.trim())return{continue:!0};let Y=()=>NZ(J,{cwd:z.cwd,home:z.home}),X=(j)=>j.rmHits.map((F)=>F.word.start).join(),Q=(j)=>j()||!!YZ(J,j),B=Y(),K=E1(B,J),H=YZ(J,()=>{let j=Y();return{result:j,verdict:E1(j,J)}});if(H){let{result:j,verdict:F}=H;if(F&&!("continue"in F))return F;if(!F&&(!K||("continue"in K))&&X(j)!==X(B))return u(b1)}if(K)return K;let M=I4(z);if(M.error!==null)return u(`[trash-guard] The guard could not resolve the \`trash\` binary (${M.error}), so this \`rm\` cannot be redirected into a recoverable delete \u2014 and an unrecoverable delete is never allowed, so the command is refused rather than run. Fix the environment (PATH, permissions) and re-run the same command.`);if(M.path===null)return u(T4);let V=M.path;if(z.execution&&Q(()=>D4(J)))return u("[trash-guard] A deletion combined with shell environment changes cannot use the verified native execution context. Run the deletion as a separate plain rm command.");let G=j4(J,B.rmHits,V,z.execution),U=F4(Z.tool_input,G);if(z.execution)U.hasna_execution="hasna.hooks.execution.v1";if(Q(()=>!N4(U,J,B.rmHits,z.cwd,z.home)))return u(b1);return _4(U)}import{closeSync as q4,constants as c1,fstatSync as C4,lstatSync as P4,openSync as O4,readFileSync as L4,statSync as A4}from"fs";import{homedir as Z2}from"os";import{dirname as x0,isAbsolute as $2,join as _Z,normalize as IZ,relative as y4,resolve as iZ,sep as l0}from"path";var R4=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),v4=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),b4=["hasna","hasnaxyz","hasna-products"],mZ="workspace-repos-guard";function E4(Z){return _Z(Z,".hasna","repos","clones")}function S4(Z){return _Z(Z,"workspace","repos")}function J2(Z){return[E4(Z),S4(Z)]}function f4(Z){return _Z(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var k4=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function h0(Z){let z=process.getuid?.();return z!==void 0&&(Z.uid===0||Z.uid===z)&&(Z.mode&18)===0}function x4(Z){let z=f4(Z),$;try{let Y=O4(z,c1.O_RDONLY|c1.O_NOFOLLOW);try{let Q=C4(Y);if(!Q.isFile()||!h0(Q)||Q.size>4096)return null;$=L4(Y,"utf8")}finally{q4(Y)}let X=IZ(Z);for(let Q=x0(z);Q!==X;Q=x0(Q)){let B=P4(Q);if(!B.isDirectory()||!h0(B)||Q===x0(Q))return null}if(!h0(A4(X)))return null}catch{return null}let J=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return J.length>0&&J.every((Y)=>k4.test(Y))?new Set(J):null}function h4(Z=process.env,z=Z2()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((J)=>J.trim()).filter(Boolean));return x4(z)??new Set(b4)}function w0(Z,z,$,J){if(J==="read")return{blocked:!1};let Y=y4(z,Z);if(Y===""){if(J==="delete")return{blocked:!0,reason:`[${mZ}] delete of the protected repo-checkout root is forbidden: ${z}`};return{blocked:!0,reason:`[${mZ}] writes directly to the protected repo-checkout root are forbidden: ${z}`}}if(Y.startsWith(`..${l0}`)||Y===".."||$2(Y))return{blocked:!1};let X=Y.split(l0).filter(Boolean);if(J==="delete")return{blocked:!0,reason:`[${mZ}] delete under the protected repo-checkout root (${z}) is forbidden at any depth: ${Z}`};if(X.length<=1)return{blocked:!0,reason:`[${mZ}] writing would create a top-level entry directly under the protected repo-checkout root (${z}); only GitHub-org folders belong there: ${Z}`};let Q=X[0];if(!$.has(Q))return{blocked:!0,reason:`[${mZ}] '${Q}' is not an allowed GitHub org under the protected repo-checkout root (${z}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var z2=/\b(?:-o|--output|-O|--output-document|-out)\b/,w4=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,g4=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function Y2(Z){return Z.replace(w4," ")}function u4(Z){let z=[],$=null,J=0,Y=0,X=!1,Q=0;for(let B=0;B<Z.length;B++){let K=Z[B];if($==="'"){if(K==="'")$=null;continue}if(K==="\\"){B++;continue}if(K==="("){J++;continue}if(K===")"){if(--J<0)return[Z];continue}if(K==="$"&&Z[B+1]==="{"){Y++,B++;continue}if(K==="}"&&Y>0){Y--;continue}if(K==="`"){X=!X;continue}if($==='"'){if(K==='"')$=null;continue}if(K==="'"||K==='"'){$=K;continue}if(K!=="|"||J>0||Y>0||X||Z[B-1]===">")continue;if(z.push(Z.slice(Q,B)),Z[B+1]==="&")B++;Q=B+1}if($||J!==0||Y!==0||X)return[Z];return z.push(Z.slice(Q)),z}function l4(Z){let z=[],$="",J="",Y=null,X=!1,Q=()=>{if(!X)return;let B=J.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),K=$.startsWith("~")&&!/^~(?:\/|$)/.test(J);z.push({text:K?`./${$}`:$,opaque:/[$\x60*?[]/.test(B)||/[()]/.test(B)||tZ(J)}),$="",J="",X=!1};for(let B=0;B<Z.length;B++){let K=Z[B];if(Y==="'"){if(K==="'")Y=null;else $+=K;J+=K;continue}if(K==="\\"&&B+1<Z.length){let H=Z[B+1];$+=Y==='"'&&!/[$\x60"\\\n]/.test(H)?K+H:Y==='"'&&H===`
27
- `&&!a.on?"":H,J+=K+H,X=!0,B++;continue}if(Y==='"'){if(K==='"')Y=null;else $+=K;J+=K;continue}if(/\s/.test(K)){Q();continue}if(X=!0,J+=K,K==="'"||K==='"')Y=K;else $+=K}if(Y)J+="$";return Q(),z}function g0(Z,z,$){let J=Z[z];return J==="--help"||J==="--version"||$&&(J==="-h"||J==="-V")}var i1={read:0,write:1,delete:2};function Y0(...Z){return Z.reduce((z,$)=>i1[$]>i1[z]?$:z,"read")}var m4=new Set(["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"]),X2=new Set(["put","rm","delete","remove"]),p4=new Set([...X2,"restore","restore-capsule","recover","release","locks","retention","hold","unhold","pin","unpin","retrieve","backup-retrieve"]),Q2=new Set(["-delete","-exec","-execdir","-ok","-okdir","-fls","-fprint","-fprint0","-fprintf"]);function p0(Z){let z=null;for(let $=0;$<Z.length;$++){let J=Z[$];if(z==="'"){if(J==="'")z=null;continue}if(J==="\\"){$++;continue}if(J==="$"||J==="`")return!0;if(z==='"'){if(J==='"')z=null;continue}if(J==="'"||J==='"')z=J;else if("*?[{".includes(J))return!0}return z!==null}function c0(Z){let z=Z.trim();if(!z)return"read";if(Q0(z))return"delete";let $=b(z);if(!$.trustworthy||$.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(z))return QZ(z);let J=$.segments.flatMap((Y)=>{let X=d1(Y),Q=Y.words.filter((H,M)=>!Y.redirects.has(M)).map((H)=>H.text),B=Q.map(JZ);if(B.every((H,M)=>H!==null&&H.length===1&&H[0]===Q[M]))return[X];if(B.some((H)=>H===null))return[X,QZ(Q.join(" "))];let K=b(B.flatMap((H)=>H??[]).join(" "));return[X,...K.trustworthy?K.segments.map(d1):[QZ(Q.join(" "))]]});return Y0(...J)}function d1(Z){let z=Z.words.map((X,Q)=>({word:X,at:Q})).filter(({at:X})=>!Z.redirects.has(X)),$=x(Z),J=$<0?"read":s1(Z,$),Y=zZ(z.map(({word:X})=>i0(X.text)));if(Y===null)return Y0(J,QZ(z.map(({word:X})=>R(X.text)).join(" ")));if(Y.index<0||z[Y.index].at===$)return J;return Y0(J,s1(Z,z[Y.index].at))}function K2(Z,z,$=0){if(z<0||$>8)return $>8;let J=Z.words.map((H,M)=>({word:H,at:M})).filter(({at:H})=>!Z.redirects.has(H)),Y=J.findIndex(({at:H})=>H===z),X=Y<0?null:xZ(J.map(({word:H})=>H.text),Y,v);if(X){if(!X.literal)return!0;let H=b(X.program);if(H.trustworthy&&H.segments.some((M)=>X0(M,$+1)))return!0}let Q=Z.words.map((H)=>v(H.text));for(let H of hZ(Q,z,(M)=>Z.redirects.has(M)))if(X0(B2(Z,H.start,H.end),$+1))return!0;let K=wZ(Q,z,(H)=>H>=0&&H<Z.words.length&&(Z.redirects.has(H)||p0(Z.words[H].text)));if(!K)return!1;if(K.unresolved)return!0;return K.programs.some((H)=>H.kind==="shell"?c0(H.text)!=="read":!P1(H))}function B2(Z,z,$){let J=new Set([...Z.redirects].filter((Y)=>Y>=z&&Y<$).map((Y)=>Y-z));return{words:Z.words.slice(z,$),redirects:J}}function X0(Z,z=0){return H2(Z).some(($)=>K2(Z,$,z))}function i0(Z){return{text:v(Z),opaque:/[$\x60]/.test(Z)&&!/^(?:[^$\x60"'\\]|\$'(?:[^'\\]|\\.)*')+$/.test(Z)}}function H2(Z){let z=new Set,$=x(Z);if($>=0)z.add($);let J=Z.words.map((X,Q)=>({word:X,at:Q})).filter(({at:X})=>!Z.redirects.has(X)),Y=zZ(J.map(({word:X})=>i0(X.text)));if(Y!==null&&Y.index>=0)z.add(J[Y.index].at);return[...z]}function pZ(Z,z=0){if(z>8)return[];let $=[];for(let J of Z.segments){let Y=J.words.map((B)=>v(B.text)),X=(B)=>B>=0&&B<J.words.length&&(J.redirects.has(B)||p0(J.words[B].text)),Q=J.words.filter((B,K)=>!J.redirects.has(K));for(let B of H2(J)){$.push(...(wZ(Y,B,X)?.writes??[]).map((M)=>M[0]==="/"?M:`./${M}`));let K=xZ(Q.map((M)=>M.text),Q.indexOf(J.words[B]),v),H=K?.literal?b(K.program):null;if(H?.trustworthy)$.push(...pZ(H,z+1));for(let M of hZ(Y,B,(V)=>J.redirects.has(V)))$.push(...pZ({segments:[B2(J,M.start,M.end)]},z+1))}}for(let J of Z.substitutions??[]){let Y=b(J);if(Y.trustworthy)$.push(...pZ(Y,z+1))}return $}function Q0(Z,z=0){if(z>4)return!1;let $=b(Z),J=$.trustworthy?Z:UZ(Z);if(J!==Z)return Q0(J,z+1);if($.trustworthy&&$.segments.some((X)=>X0(X)))return!0;return(G2(Z)??$.substitutions).some((X)=>Q0(X,z+1))}function s1(Z,z){if(K2(Z,z))return"delete";let $=Z.words.filter((X,Q)=>Q>=z&&!Z.redirects.has(Q)),J=$.map((X)=>v(X.text)),Y=J[0].split("/").pop();if(["rm","rmdir","shred"].includes(Y??""))return g0(J,1,!1)?"read":"delete";if(["unlink","rmtree","del"].includes(Y??""))return"delete";if(Y==="trash"){let X=1;while(X<J.length&&J[X].startsWith("-")){let Q=J[X++];if(["--help","-h","--version","-V","--identity"].includes(Q))return"read";if(["--agent","--spool","--files","--info","--config"].includes(Q))X++;else if(!["--json","--local"].includes(Q))return"delete"}if(X===J.length||m4.has(J[X]))return"read";if(p4.has(J[X])&&g0(J,X+1,!0))return"read";if(["restore","restore-capsule"].includes(J[X]))return"write";return"delete"}if(Y==="git"){let X=k0(Z,z);if(X==="clean"||X==="rm")return J[1]===X&&g0(J,2,!0)?"read":"delete";return X==="clone"||X==="init"?"write":"read"}if(Y==="find"&&!$.some((X)=>p0(X.text))&&!J.some((X)=>Q2.has(X)))return"read";if(Y==="env"&&i(uZ(J)))return"delete";if(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env","xargs","find","busybox","toybox"].includes(Y??""))return QZ(J.join(" "));if(["mkdir","mkfile","touch","mv","cp","ln","tee","install","dd","rsync","scp","truncate"].includes(Y??""))return"write";if(Y==="curl"||Y==="wget")return z2.test(J.join(" "))?"write":"read";if(Y==="sed"&&J.slice(1).some((X)=>/^-i|^--in-place(?:=|$)/.test(X)))return"write";if(["python","python3","node","bun"].includes(Y??"")&&J.some((X)=>X==="-c"||X==="-e"))return"write";return"read"}function QZ(Z){let z=Z.replace(/[{},]/g," ");return z===Z?u0(Z):Y0(u0(Z),u0(z))}function u0(Z){let z=Z.trim();if(!z)return"read";if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:rm|rmdir|unlink|shred|trash|rmtree|del)(?:\s|$)/.test(z))return"delete";if(/\bgit\b/.test(z)){if(/\bgit\b[^;&|]*\b(?:clean|rm)\b/.test(z))return"delete";if(/\bgit\b[^;&|]*\b(?:clone|init)\b/.test(z))return"write";return"read"}if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|mv|cp|ln|tee|install|dd)(?:\s|$)/.test(z))return"write";if(/\b(?:curl|wget)\b/.test(z)){if(z2.test(z))return"write";return"read"}if(/\bsed\b/.test(z)){if(/(?:^|\s)-i\S*(?:\s|$)|--in-place(?:\s|$)/.test(z))return"write"}else if(/\b(?:rsync|scp|truncate)\b/.test(z))return"write";else if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(z))return"write";if(/(?:^|[;&|])\s*echo\b/.test(z)||/>/.test(Y2(z)))return"write";return"read"}function cZ(Z,z){let $=Z.trim(),J=$.match(/^(['"])([\s\S]*)\1$/);if(J)$=J[2];if($=$.replace(/^"*\$HOME"*\//,"$HOME/"),$=$.replace(/^"*\$\{HOME\}"*\//,"${HOME}/"),$==="~")return z;if($.startsWith("~/"))return _Z(z,$.slice(2));if($==="$HOME"||$==="${HOME}")return z;if($.startsWith("$HOME/"))return _Z(z,$.slice(6));if($.startsWith("${HOME}/"))return _Z(z,$.slice(8));let Y=$.match(new RegExp(`^"*${m0(z)}"*/`));if(Y)return z+"/"+$.slice(Y[0].length);return Z}function c4(Z){let z=Z.trim();while(z.startsWith("(")||/^\{(?:\s|$)/.test(z))z=z.slice(1).trim();while(z.endsWith(")")||/(?:^|\s)\}$/.test(z))z=z.slice(0,-1).trim();return z}function m0(Z){return Z.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function n1(Z,z,$){if(Z===void 0)return[$];let J=cZ(Z,$),Y=J.match(/^(['"])(.*)\1$/);if(Y)J=Y[2];if(!J||J==="-"||/[$\x60*?[\]{}~\\'"]/.test(J))return null;return[...new Set(z.map((X)=>iZ(X,J)))]}var i4=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function d4(Z,z){let $=zZ(z);if(!$||$.index<=0||z[$.index].opaque)return 0;let J=b(Z);if(!J.trustworthy||J.substitutions.length>0||J.segments.length!==1)return 0;let[Y]=J.segments;if(Y.redirects.size>0||Y.words.length!==z.length)return 0;if(Y.words.some((X,Q)=>R(X.text)!==z[Q].text))return 0;return x(Y)===$.index?$.index:0}function s4(Z,z){let $=0;if(Z==="git")$=z.findIndex((Y)=>Y.text==="rm"||Y.text==="clean")+1;let J=!1;return z.slice($).filter((Y)=>{if(!J&&Y.text==="--")return J=!0,!1;if(!J&&Y.text.startsWith("-")&&!Y.opaque)return!1;return J=!0,!0})}var n4=new Set(["--agent","--spool","--files","--info","--config"]),o4=new Set(["--spool","--files","--info","--config"]),a4=new Set(["--json","--local","--help","-h","--version","--identity"]),o1={"--agent":/^[^-]/,"--retention":/^(?:\d+(?:\.\d+)?|never)$/},r4=new Set(["--to"]);function t4(Z){let z=[],$=0;for(;$<Z.length&&Z[$].text.startsWith("-");$++){let X=Z[$];if(X.opaque)return null;if(n4.has(X.text)){let Q=Z[++$];if(!Q||Q.opaque)return null;if(o4.has(X.text))z.push(Q)}else if(!a4.has(X.text))return null}let J=Z[$];if(!J||J.opaque||!X2.has(J.text))return null;let Y=!1;for($++;$<Z.length;$++){let X=Z[$];if(Y||X.opaque||X.text==="-"||!X.text.startsWith("-")){z.push(X);continue}if(X.text==="--"){Y=!0;continue}let Q=X.text.indexOf("="),B=Q<0?X.text:X.text.slice(0,Q);if(r4.has(B)){if(Q>=0)z.push({text:X.text.slice(Q+1),opaque:!1});else if(Z[$+1]&&!Z[$+1].text.startsWith("-"))z.push(Z[++$]);continue}let K=Z[$+1];if(Q<0&&Object.hasOwn(o1,B)&&K&&!K.opaque&&o1[B].test(K.text))$++}return z}function e4(Z){let z=Z.split(`
28
- `),$=[],J=[],Y=0;while(Y<z.length){let X=Y,Q=z[Y++].replace(/\r$/,""),B=[];for(let K=0;K<Q.length;K++){let H=Q[K],M=J[J.length-1];if(H==="\\"){K++;continue}if(H==="$"&&Q[K+1]==="("&&Q[K+2]==="("){let V=Q.indexOf("))",K+3);if(V<0)return null;K=V+1;continue}if(H==="$"&&Q[K+1]==="("){J.push(0),K++;continue}if(H==="$"&&Q[K+1]==="[")return null;if(H==="$"&&Q[K+1]==="{"){let V=Q.indexOf("}",K+2);if(V<0||/['"\x60$]|<</.test(Q.slice(K+2,V)))return null;K=V;continue}if(H==="`"){let V=Q.indexOf("`",K+1);if(V<0)return null;K=V;continue}if(M==='"'){if(H==='"')J.pop();continue}if(H==="'"){let V=Q.indexOf("'",K+1);if(V<0)return null;K=V;continue}if(H==='"'){J.push('"');continue}if(H==="#"&&(K===0||/[\s;&|()]/.test(Q[K-1])))break;if(H==="("&&Q[K+1]==="("&&(K===0||/[\s;&|(]/.test(Q[K-1]))){let V=Q.indexOf("))",K+2);if(V<0)return null;K=V+1;continue}if(typeof M==="number"&&(H==="("||H===")")){if(H==="(")J[J.length-1]=M+1;else if(M===0)J.pop();else J[J.length-1]=M-1;continue}if(H==="<"&&Q[K+1]==="<"){if(Q[K+2]==="<"){K+=2;continue}let V=DZ(Q,K);if(!V)return null;B.push({marker:V,from:K}),K=V.end-1}}for(let{marker:K,from:H}of B){let M=Y;for(;;){if(Y>=z.length)return null;let V=z[Y++].replace(/\r$/,"");if(K.stripTabs)V=V.replace(/^\t+/,"");if(V===K.delimiter)break}$.push({line:X,from:H,to:K.end,start:M,end:Y-1,quoted:K.quoted})}}return J.length===0?$:null}var Z5=new Set(["sh","bash","zsh","dash","ksh","mksh","ash","fish","csh","tcsh","nu","xonsh","elvish","busybox","toybox","ssh","su","runuser","sudo","doas","pkexec","xargs","parallel","expect","script","at","batch","crontab","watch","flock","chroot","nsenter","unshare","docker","podman","kubectl","lxc","python","pypy","node","nodejs","bun","deno","tsx","ts-node","zx","npx","bunx","pnpx","perl","ruby","irb","php","lua","luajit","osascript","pwsh","powershell","Rscript","R","julia","tclsh","wish","awk","gawk","mawk","nawk","sed","make","gmake","gdb","lldb","sqlite3","psql","mysql","sftp","ftp","lftp","vim","vi","nvim","ex","ed","emacs","chmod"]),$5=new Set([".","source","eval","env","alias","hash"]),J5=new Set(["tee","cp","mv","install","ln"]),M2=new Set(["cat","tac","tee","head","tail","wc","cut","tr","nl","rev","fold","fmt","paste","uniq","grep","egrep","fgrep","jq","diff","cmp","comm","iconv","od","xxd","hexdump","base64","base32","md5sum","sha1sum","sha224sum","sha256sum","sha384sum","sha512sum","b2sum","cksum","echo","printf","true","false",":","test","[","read","cd","pwd","ls","mkdir","touch","stat","sleep","cp","mv","ln","rm","rmdir","unlink","shred","trash","todos","conversations","mementos","knowledge","files","asks"]),z5=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),Y5=new Set(["pr","issue","api","release","gist"]);function X5(Z,z){let $=Z[z];if($==="gh")return Y5.has(Z[z+1]??"");if($!=="git")return M2.has($);for(let J=z+1;J<Z.length;J++){let Y=Z[J];if(Y==="-C")J++;else if(Y==="--no-pager"||Y==="-P")continue;else return!Y.startsWith("-")&&z5.has(Y)}return!1}function Q5(Z,z){for(let $=z+1;$<Z.length;$++){let J=Z[$];if(J==="\\")$++;else if(J==='"')return $;else if(J==="$"&&Z[$+1]==="("){if($=V2(Z,$+1),$<0)return-1}else if(J==="`"){if($=Z.indexOf("`",$+1),$<0)return-1}}return-1}function V2(Z,z){let $=0;for(let J=z;J<Z.length;J++){let Y=Z[J];if(Y==="\\")J++;else if(Y==="'"||Y==="`"){if(J=Z.indexOf(Y,J+1),J<0)return-1}else if(Y==='"'){if(J=Q5(Z,J),J<0)return-1}else if(Y==="(")$++;else if(Y===")"&&--$===0)return J}return-1}function G2(Z){let z=[],$=!1;for(let J=0;J<Z.length;J++){let Y=Z[J];if(Y==="\\")J++;else if(Y==="'"&&!$){let X=Z.indexOf("'",J+1);if(X<0)return null;J=X}else if(Y==='"')$=!$;else if(Y==="$"&&Z[J+1]==="("){let X=V2(Z,J+1);if(X<0)return null;let Q=Z.slice(J+2,X);if(Z[J+2]==="("){if(/\$\(|\x60/.test(Q))return null}else z.push(Q);J=X}else if(Y==="`"){let X=Z.indexOf("`",J+1);if(X<0)return null;z.push(Z.slice(J+1,X)),J=X}}return $?null:z}function K5(Z){if(/[<>]\(/.test(Z))return!0;let z=[],$=[Z];for(let Y=0;$.length>0;Y++){if(Y>64)return!0;let X=$.shift(),Q=b(X),B=G2(X);if(!Q.trustworthy||!B)return!0;z.push(...Q.segments),$.push(...new Set([...Q.substitutions,...B]))}let J=new Set;for(let Y of z){let X=Y.words.map((K)=>R(K.text));for(let K of Y.redirects)J.add(c(X[K]??""));let Q=x(Y);if(Q<0)continue;let B=c(X[Q]);if(J5.has(B)){for(let K of X.slice(Q+1))if(!K.startsWith("-"))J.add(c(K))}if(B==="dd"){for(let K of X)if(K.startsWith("of="))J.add(c(K.slice(3)))}}J.delete("");for(let Y of z){for(let H of Y.words){let M=c(R(H.text));if(Z5.has(M)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(M))return!0}let X=x(Y),Q=Y.words.map((H,M)=>({text:R(H.text),at:M})).filter(({at:H})=>!Y.redirects.has(H));if(Q.some(({text:H,at:M})=>(X<0||M<X)&&SZ.test(H)))return!0;if(X<0)continue;let B=Y.words[X].text,K=R(B);if(/[$\x60]/.test(B)||K.includes("/")||$5.has(K)||J.has(K))return!0;if(!X5(Q.filter(({at:H})=>H>=X).map(({text:H})=>H),0))return!0}return!1}function B5(Z){if(!Z.includes("<<"))return null;let z=e4(Z);if(!z||z.length===0)return null;let $=Z.split(`
29
- `),J=[...$],Y=[];for(let Q of z){let B=$.slice(Q.start,Q.end);if(!Q.quoted&&B.some((K)=>/\$\(|\x60/.test(K)))return null;Y.push(B.join(`
30
- `));for(let K=Q.start;K<=Q.end;K++)J[K]=""}let X=[...J];for(let Q of[...z].reverse()){let B=X[Q.line];X[Q.line]=B.slice(0,Q.from)+" ".repeat(Q.to-Q.from)+B.slice(Q.to)}return K5(X.join(`
31
- `))?null:{outer:J.join(`
32
- `),bodies:Y}}var H5="/";function K0(Z,z,$){if(!Z)return[];let J=b(Z).trustworthy?Z:UZ(Z),Y=B5(Z);return[...J===Z?[]:K0(J,z,$),...Y?[...e1(Y.outer,z,$),...Y.bodies.flatMap((X)=>K0(X,z,H5))]:e1(Z,z,$)]}var M5=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,V5=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function a1(Z,z,$=!1){let J=[],Y=0;for(let B of z)J.push(Y),Y+=B.length;let X=b(Z);if(!X.trustworthy||!$&&X.substitutions.length>0)return null;let Q=X.segments.flatMap((B)=>B.words).filter((B)=>z.some((K,H)=>H%2===1&&J[H]<B.end&&J[H]+K.length>B.start));return Q.length>0?{lexed:X,offsets:J,words:Q}:null}function r1(Z,z,$=[]){if(c0(z)!=="read")return!1;let J=x(Z),Y=Z.words.filter((M,V)=>!Z.redirects.has(V)),X=zZ(Y.map((M)=>i0(M.text)));if(X===null)return!1;let Q=[J<0?1/0:J,X.index<0?1/0:Z.words.indexOf(Y[X.index])];if(Z.words.some((M,V)=>V<Math.max(...Q)&&!Z.redirects.has(V)&&SZ.test(R(M.text))))return!1;if([J<0?null:Z.words[J].text,X.index<0?null:Y[X.index].text].every((M)=>M===null||M2.has(c(R(M)))))return!0;let K=Y.filter((M)=>!$.includes(M)),H=K.map((M)=>R(M.text));return QZ(K.map((M)=>M.text).join(" "))==="read"&&QZ(H.join(" "))==="read"&&!H.some((M)=>Q2.has(M))}function G5(Z,z,$,J){let Y=(X)=>X.start<J&&X.end>$;if(!z.words.some(Y))return!1;return z.lexed.segments.filter((X)=>X.words.some(Y)).some((X)=>X0(X))}var t1=(Z,z)=>Z.slice(z.words[0].start,z.words[z.words.length-1].end);function U5(Z,z,$,J){let Y=(Q)=>Q.start<J&&Q.end>$,X=z.words.filter(Y);if(X.length===0||X.some((Q)=>!V5.test(Q.text)))return!1;for(let Q of z.lexed.segments.filter((B)=>B.words.some(Y)))if(!r1(Q,t1(Z,Q),z.words))return!1;for(let Q of X){let B=Q.text.slice(1,-1);if(B.includes("<<"))return!1;let K=b(B);if(!K.trustworthy||K.substitutions.length>0)return!1;if(!K.segments.every((H)=>r1(H,t1(B,H))))return!1}return!0}function e1(Z,z,$){if(!Z)return[];let J=J2(z),Y=(U)=>J.some((j)=>U===j||U.startsWith(`${j}${l0}`)),X=Z.split(M5),Q=a1(Z,X),B=Q??a1(Z,X,!0),K=[],H=[$],M=new Set([$]),V=!0,G=[];for(let U=0;U<X.length;U+=2){let j=U===0?"":X[U-1].trim();if(j==="||")V=!1;else if(j!=="&&")V=!0;if(j!=="&&"||!V)H=[...M];let F=X[U],L=(F.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,y=(F.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let D=0;D<L;D++)G.push({current:[...H],reachable:new Set(M),certain:V});let E=c4(F),l=Q!==null&&U5(Z,Q,Q.offsets[U],Q.offsets[U]+F.length),q=!l&&(B!==null&&G5(Z,B,B.offsets[U],B.offsets[U]+F.length)||Q0(F.trim())),N=E.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),A=N?null:E.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(A){for(let D of n1(A[1],H,z)??[])M.add(D);V=!1,H=[...M]}let h=m0(z),w=J.map((D)=>m0(D.slice(z.length+1))).join("|"),CZ=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${h}"*)/(?:${w})`),G1=new RegExp(`(${CZ.source})([^\\s"';&|<>()\`]*|$)`,"g"),U1=(D)=>{let f=[],g;G1.lastIndex=0;while((g=G1.exec(D))!==null)f.push(IZ(cZ(g[0],z)).replace(/\/+$/,""));return f},j1=B===null?0:B.offsets[U],W1=(D)=>D.start<j1+F.length&&D.end>j1,f2=B!==null&&B.words.some(W1)?pZ({segments:B.lexed.segments.filter((D)=>D.words.some(W1))}):[F.trim(),E].flatMap((D)=>{let f=b(D);if(!f.trustworthy)f=b(UZ(D));return f.trustworthy?pZ(f):[]}),W0=u4(E).map((D,f)=>{let g=f===0?[...new Set(f2)]:[],PZ=!1,OZ=Y2(D).replace(g4,(N0,HZ)=>{if(!HZ||/[$\x60]/.test(HZ))PZ=!0;if(HZ)g.push(HZ);return" "}),LZ=l?"read":q?"delete":c0(OZ);return{commandPart:OZ,operands:g,op:PZ&&LZ==="read"?"write":LZ}}),k2=W0.some((D)=>D.op==="delete")?"delete":W0.some((D)=>D.op==="write")?"write":"read",F0=H.filter(Y);if(q)for(let D of F0)K.push({path:D,op:"delete"});for(let D of W0){let f=!1;for(let k of U1(D.commandPart))f=!0,K.push({path:k,op:k2});for(let k of D.operands){let n=U1(k);for(let p of n)K.push({path:p,op:"write"});if(n.length>0)continue;for(let p of F0)K.push({path:IZ(iZ(p,cZ(k,z))),op:"write"})}if(f||D.op==="read")continue;let g=l4(D.commandPart),PZ=d4(D.commandPart,g),OZ=c(g[PZ]?.text??""),LZ=g.slice(PZ+1),N0=((OZ==="trash"?t4(LZ):null)??s4(OZ,LZ)).map((k)=>k.opaque?".":k.text),HZ=D.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(D.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(D.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(D.commandPart),AZ=[];if(HZ)for(let k of N0.length>0?N0:["."])AZ.push({operand:k,op:D.op});else{let k=D.commandPart.match(i4),n=g.at(-1);if(AZ.push({operand:k?k[1]:!n||n.opaque?".":n.text,op:D.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(D.commandPart))g.forEach((p,F1)=>{let MZ,D0=p.text.match(/^-[A-Za-z]*?t(.*)$/),sZ=p.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(D0&&!p.text.startsWith("--"))MZ=D0[1]?{text:D0[1],opaque:p.opaque}:g[F1+1];else if(sZ&&"--target-directory".startsWith(sZ[1]))MZ=sZ[2]!==void 0?{text:sZ[2],opaque:p.opaque}:g[F1+1];if(MZ)AZ.push({operand:MZ.opaque||!MZ.text?".":MZ.text,op:D.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(D.commandPart))AZ.push({operand:".",op:D.op})}for(let k of F0)for(let{operand:n,op:p}of AZ)K.push({path:IZ(iZ(k,cZ(n,z))),op:p})}if(N){let D=n1(N[1],H,z);if(D){for(let f of D)M.add(f);if(V)H=D}else V=!1}for(let D=0;D<y&&G.length>0;D++)({current:H,reachable:M,certain:V}=G.pop())}return K}var j5=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function W5(Z,z){let $=[],J;while((J=j5.exec(Z))!==null){let Y=J[1]==="Delete File"?"delete":"write";$.push({path:IZ(iZ(z,J[2])),op:Y})}return $}function U2(Z,z={}){let $=[];if(Z.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:$};let J=typeof Z.tool_name==="string"?Z.tool_name:"",Y=z.home??Z2(),X=J2(Y),Q=h4(process.env,Y);if(J==="Bash"){let G=GZ(Z);if(!G)return{output:{continue:!0},warnings:$};let U=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd(),j=K0(G,Y,U);j.unshift(...YZ(G,()=>K0(G,Y,U))??[]);for(let F of j)for(let L of X){let y=w0(F.path,L,Q,F.op);if(y.blocked)return{output:{decision:"block",reason:y.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let B=Z.tool_input??{},K=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(v4.has(J)){let G=typeof B.patch==="string"?B.patch:"";if(!G)return{output:{continue:!0},warnings:$};let U=W5(G,K);for(let j of U)for(let F of X){let L=w0(j.path,F,Q,j.op);if(L.blocked)return{output:{decision:"block",reason:L.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!R4.has(J))return{output:{continue:!0},warnings:$};let H=typeof B.file_path==="string"?B.file_path:typeof B.path==="string"?B.path:typeof B.notebook_path==="string"?B.notebook_path:null;if(!H)return{output:{continue:!0},warnings:$};let M=cZ(H,Y),V=$2(M)?IZ(M):iZ(K,M);for(let G of X){let U=w0(V,G,Q,"write");if(U.blocked)return{output:{decision:"block",reason:U.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var F5=new Set(["id","node_id","databaseId","fullDatabaseId","number","state","state_reason","stateReason","status","conclusion","bucket","name","login","sha","oid","abbreviatedOid","ref","headRefName","baseRefName","headRefOid","baseRefOid","head_sha","headSha","head_branch","headBranch","merged","mergeable","mergeable_state","mergeStateStatus","draft","isDraft","locked","isLocked","title","displayTitle","display_title","created_at","updated_at","closed_at","merged_at","started_at","completed_at","submitted_at","pushed_at","published_at","createdAt","updatedAt","closedAt","mergedAt","startedAt","completedAt","submittedAt","pushedAt","publishedAt","tag_name","tagName","total_count","totalCount","count","additions","deletions","changes","changed_files","changedFiles","filename","path","event","workflow","workflowName","workflow_id","workflowDatabaseId","run_id","run_number","run_attempt","attempt","check_suite_id","default_branch","defaultBranch","full_name","fullName","nameWithOwner","private","isPrivate","visibility","archived","isArchived","fork","isFork","isRequired","is_required","required","context","type","__typename","role","permission","size","reviewDecision","author_association","authorAssociation","isCrossRepository","maintainerCanModify","maintainer_can_modify","commentsCount","language","digest","size_in_bytes","run_started_at","date","wait_timer","ahead_by","behind_by","total_commits","expired","current_user_can_approve","environment","html_url"]),N5=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),N2=new Set(["length","utf8bytelength","not","type","any","all","isempty","empty","test","startswith","endswith","contains","inside","has","in","index","rindex","indices","floor","ceil","round","fabs","sqrt","isinfinite","isnan","isnormal","infinite","nan","true","false","null"]),D2=new Set(["tostring","tojson","ascii_downcase","ascii_upcase","ltrimstr","rtrimstr","trim","ltrim","rtrim","sort","unique","reverse","first","last","min","max","add","flatten","join","split","values","nulls","strings","numbers","booleans","arrays","objects","iterables","scalars","sort_by","group_by","unique_by","min_by","max_by","select","limit","to_entries","from_entries"]),D5=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),_5=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class n0 extends Error{}var P=()=>{throw new n0};function d0(Z,z){let $=[],J="",Y=z+1;while(Y<Z.length){let X=Z[Y];if(X==='"'){if(J)$.push(J);return{end:Y+1,parts:$}}if(X==="\\"){let Q=Z[Y+1];if(Q==="("){let B=1,K=Y+2;while(K<Z.length&&B>0){let H=Z[K];if(H==='"'){K=d0(Z,K).end;continue}if(H==="(")B++;else if(H===")")B--;K++}if(B!==0)P();if(J)$.push(J),J="";$.push({src:Z.slice(Y+2,K-1)}),Y=K;continue}if(Q===void 0)P();J+=Q,Y+=2;continue}J+=X,Y++}return P()}function _2(Z){let z=[],$=0,J=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let Y=Z[$];if(/\s/.test(Y)){$++;continue}if(Y==="#")P();if(Y==='"'){let K=d0(Z,$);z.push({t:"str",parts:K.parts}),$=K.end;continue}if(Y==="."){if(Z[$+1]===".")P();let K=/^[A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($+1));if(K){z.push({t:"field",name:K[0]}),$+=1+K[0].length;continue}if(Z[$+1]==='"'){let H=d0(Z,$+1);if(H.parts.some((M)=>typeof M!=="string"))P();z.push({t:"field",name:H.parts.join("")}),$=H.end;continue}z.push({t:"dot"}),$++;continue}if(Y==="$"||Y==="@"){let K=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($));if(!K||Y==="$")P();z.push({t:"fmt",name:K[0]}),$+=K[0].length;continue}let X=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(Z.slice($));if(X){z.push({t:"num"}),$+=X[0].length;continue}let Q=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(Z.slice($));if(Q){z.push({t:"ident",name:Q[0]}),$+=Q[0].length;continue}let B=J.find((K)=>Z.startsWith(K,$));if(!B)P();z.push({t:"op",v:B}),$+=B.length}return z}var I5=new Set(["if","then","elif","else","end","as","def","reduce","foreach","try","catch","label","import","include","and","or","__loc__","error","input","inputs","debug","stderr","env","halt","halt_error","input_filename","input_line_number","recurse","paths","leaf_paths","getpath","setpath","delpaths","del","path","splits","sub","gsub","capture","match","scan","keys","keys_unsorted","map_values","with_entries","tostream","fromstream","truncate_stream","walk","tonumber","implode","explode","ascii","fromjson"]);class o0{tokens;at=0;constructor(Z){this.tokens=Z}parse(){if(this.tokens.length===0)P();let Z=this.pipe();if(this.at!==this.tokens.length)P();return Z}peek(){return this.tokens[this.at]}isOp(Z){let z=this.peek();return!!z&&z.t==="op"&&z.v===Z}isIdent(Z){let z=this.peek();return!!z&&z.t==="ident"&&z.name===Z}expectOp(Z){if(!this.isOp(Z))P();this.at++}pipe(){let Z=this.comma();if(this.isIdent("as"))P();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.pipe()};return Z}comma(){let Z=this.alt();while(this.isOp(","))this.at++,Z={k:"comma",a:Z,b:this.alt()};return Z}alt(){let Z=this.or();if(this.isOp("//"))return this.at++,{k:"alt",a:Z,b:this.alt()};return Z}or(){let Z=this.and();while(this.isIdent("or"))this.at++,Z={k:"bool",a:Z,b:this.and()};return Z}and(){let Z=this.cmp();while(this.isIdent("and"))this.at++,Z={k:"bool",a:Z,b:this.cmp()};return Z}cmp(){let Z=this.add();for(let z of["==","!=","<=",">=","<",">"])if(this.isOp(z))return this.at++,{k:"bool",a:Z,b:this.add()};for(let z of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(z))P();return Z}add(){let Z=this.mul();while(this.isOp("+")||this.isOp("-"))this.at++,Z={k:"arith",a:Z,b:this.mul()};return Z}mul(){let Z=this.unary();while(this.isOp("*")||this.isOp("/")||this.isOp("%"))this.at++,Z={k:"arith",a:Z,b:this.unary()};return Z}unary(){if(this.isOp("-"))return this.at++,{k:"neg",of:this.postfix()};return this.postfix()}objectValue(){let Z=this.unary();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.objectValue()};return Z}postfix(){let Z=this.primary();for(;;){let z=this.peek();if(!z)return Z;if(z.t==="field"){this.at++,Z={k:"field",name:z.name,of:Z};continue}if(z.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(z.t==="op"&&z.v==="?"){this.at++,Z={k:"opt",of:Z};continue}if(z.t==="op"&&z.v==="["){Z=this.bracket(Z);continue}return Z}}bracket(Z){if(this.expectOp("["),this.isOp("]"))return this.at++,{k:"iter",of:Z};if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}let z=this.pipe();if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}return this.expectOp("]"),{k:"index",of:Z,key:z}}primary(){let Z=this.peek();if(!Z)return P();switch(this.at++,Z.t){case"dot":return{k:"dot"};case"field":return{k:"field",name:Z.name};case"num":return{k:"lit"};case"str":return this.stringNode(Z.parts);case"fmt":{if(!_5.has(Z.name))P();let z=this.peek();if(z?.t==="str")return this.at++,{k:"fmt",name:Z.name,str:this.stringNode(z.parts)};return{k:"fmt",name:Z.name}}case"ident":{if(I5.has(Z.name))P();if(Z.name==="map"||N2.has(Z.name)||D2.has(Z.name)){let z=[];if(this.isOp("(")){this.at++,z.push(this.pipe());while(this.isOp(";"))this.at++,z.push(this.pipe());this.expectOp(")")}return{k:"call",name:Z.name,args:z}}return P()}case"op":{if(Z.v==="("){let z=this.pipe();return this.expectOp(")"),z}if(Z.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let z=this.pipe();return this.expectOp("]"),{k:"array",of:z}}if(Z.v==="{")return this.object();return P()}}return P()}stringNode(Z){let z=[];for(let $ of Z){if(typeof $==="string")continue;z.push(new o0(_2($.src)).parse())}return z.length===0?{k:"str",parts:z,text:Z.join("")}:{k:"str",parts:z}}object(){let Z=[];if(this.isOp("}"))return this.at++,{k:"object",entries:Z};for(;;){let z=this.peek();if(!z)P();this.at++;let $;if(z.t==="ident")$=z.name;else if(z.t==="str"){if(z.parts.some((J)=>typeof J!=="string"))P();$=z.parts.join("")}else P();if(this.isOp(":"))this.at++,Z.push({key:"static",value:this.objectValue()});else Z.push({key:"static",value:{k:"field",name:$}});if(this.isOp(",")){this.at++;continue}return this.expectOp("}"),{k:"object",entries:Z}}}}function a0(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(a0);return Z==="safe"||typeof Z==="object"&&F5.has(Z.leaf)}var dZ=(...Z)=>Z.every(a0)?"safe":"tainted";function s0(...Z){let z=[];for(let $ of Z)if(typeof $==="object"&&"union"in $)z.push(...$.union);else z.push($);return z.length===1?z[0]:{union:z}}function B0(Z,z){return typeof Z==="object"&&"union"in Z?s0(...Z.union.map(z)):z(Z)}var H0=(Z)=>typeof Z==="object"&&("leaf"in Z)&&N5.has(Z.leaf),t=(Z)=>B0(Z,(z)=>z==="safe"?"safe":z==="tainted"||H0(z)?"tainted":"unknown");function j2(Z){return Z.k==="lit"||Z.k==="str"&&Z.parts.length===0||Z.k==="call"&&["true","false","null"].includes(Z.name)&&Z.args.length===0}function W2(Z,z,$){return B0(Z,(J)=>{if(J==="safe"||J==="tainted")return J;if(H0(J))return"tainted";if(J==="root"&&$.rootScalars.has(z))return"safe";return{leaf:z}})}function O(Z,z,$){switch(Z.k){case"dot":return z;case"field":return W2(Z.of?O(Z.of,z,$):z,Z.name,$);case"iter":return t(O(Z.of,z,$));case"index":{let J=O(Z.of,z,$);if(Z.key.k==="str"&&Z.key.text!==void 0)return W2(J,Z.key.text,$);if(Z.key.k==="lit")return t(J);return O(Z.key,z,$),"tainted"}case"slice":return B0(O(Z.of,z,$),(J)=>J==="root"?"unknown":H0(J)?"tainted":J);case"opt":return O(Z.of,z,$);case"lit":return"safe";case"str":return dZ(...Z.parts.map((J)=>O(J,z,$)));case"fmt":return Z.str?O(Z.str,z,$):z;case"array":return Z.of?dZ(O(Z.of,z,$)):"safe";case"object":return dZ(...Z.entries.map((J)=>O(J.value,z,$)));case"pipe":return O(Z.b,O(Z.a,z,$),$);case"comma":return s0(O(Z.a,z,$),O(Z.b,z,$));case"alt":return s0(O(Z.a,z,$),O(Z.b,z,$));case"bool":return O(Z.a,z,$),O(Z.b,z,$),"safe";case"arith":return dZ(O(Z.a,z,$),O(Z.b,z,$));case"neg":return O(Z.of,z,$);case"call":return T5(Z,z,$)}}var F2=(Z)=>B0(Z,(z)=>z==="root"?"unknown":H0(z)?"tainted":z);function T5(Z,z,$){let{name:J,args:Y}=Z;if(D5.has(J)&&J!=="limit"&&!Y.every(j2))P();switch(J){case"map":if(Y.length!==1)P();return dZ(O(Y[0],t(z),$));case"select":if(Y.length!==1)P();return O(Y[0],z,$),z;case"limit":if(Y.length!==2||!j2(Y[0]))P();return O(Y[1],z,$);case"first":case"last":if(Y.length>1)P();return Y.length===1?O(Y[0],z,$):t(z);case"min":case"max":return t(z);case"sort_by":case"group_by":case"unique_by":if(Y.length!==1)P();return O(Y[0],t(z),$),F2(z);case"min_by":case"max_by":if(Y.length!==1)P();return O(Y[0],t(z),$),t(z);case"any":case"all":case"isempty":for(let X of Y)O(X,"unknown",$);return"safe"}if(N2.has(J))return"safe";if(D2.has(J))return F2(z);return P()}function I2(Z,z={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new o0(_2(Z)).parse();return a0(O($,"root",{rootScalars:z.rootScalars??new Set}))}catch($){if($ instanceof n0)return!1;return!1}}var X1="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",T={refused:!1},I=(Z)=>({refused:!0,rule:Z}),r0=new Set(["additions","assignees","author","baseRefName","baseRefOid","changedFiles","closed","closedAt","createdAt","deletions","files","fullDatabaseId","headRefName","headRefOid","headRepository","headRepositoryOwner","id","isCrossRepository","isDraft","labels","maintainerCanModify","mergeCommit","mergeStateStatus","mergeable","mergedAt","mergedBy","number","potentialMergeCommit","reactionGroups","reviewDecision","reviewRequests","state","title","updatedAt","url"]),t0=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),T2=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),q2=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),q5=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),C5=new Set(["author","committer","id","parents","repository","sha","url"]),P5=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function O2(Z){let z=[];for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="\\"){$++;continue}if(J==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return!1;$=Y;continue}if(J==='"'){$++;while($<Z.length&&Z[$]!=='"')$+=Z[$]==="\\"?2:1;continue}if(J==="{"){z.push({list:!1});continue}if(z.length===0)continue;if(J===","||J==="."&&Z[$+1]===".")z[z.length-1].list=!0;else if(J==="}"&&z.pop().list)return!0}return!1}function TZ(Z){let z="",$=!1,J=0,Y=(X)=>Z[X]==="`"||Z[X]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(Z[X+1]??"");while(J<Z.length){let X=Z[J];if(X==="\\"){z+=Z[J+1]??"",J+=2;continue}if(X==="$"&&Z[J+1]==="'"){$=!0,z+=X,J++;continue}if(X==="'"){let Q=Z.indexOf("'",J+1);if(Q<0){$=!0,z+=Z.slice(J+1);break}z+=Z.slice(J+1,Q),J=Q+1;continue}if(X==='"'){J++;while(J<Z.length&&Z[J]!=='"'){if(Z[J]==="\\"&&/[$`"\\\n]/.test(Z[J+1]??"")){z+=Z[J+1],J+=2;continue}if(Y(J))$=!0;z+=Z[J],J++}if(J>=Z.length)$=!0;J++;continue}if(Y(J)||X==="*"||X==="?"||X==="[")$=!0;z+=X,J++}if(!$&&Z.includes("{")&&O2(Z))$=!0;return{value:z,opaque:$,raw:Z}}var KZ=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function $1(Z,z="word"){let $=[],J=!1;for(let Y=0;Y<Z.length;Y++){let X=Z[Y];if(X==="\\"){Y++;continue}if(z==="word"&&X==="'"&&!J){let Q=Z.indexOf("'",Y+1);if(Q<0)return{bodies:$,complete:!1};Y=Q;continue}if(z==="word"&&X==='"'){J=!J;continue}if(X==="`"){let Q=Y+1;while(Q<Z.length&&Z[Q]!=="`")Q+=Z[Q]==="\\"?2:1;if(Q>=Z.length)return{bodies:$,complete:!1};$.push(Z.slice(Y+1,Q)),Y=Q;continue}if(X==="$"&&Z[Y+1]==="("){let Q=XZ(Z,Y+1);if(Q<0)return{bodies:$,complete:!1};$.push(Z.slice(Y+2,Q-1)),Y=Q-1}}return{bodies:$,complete:!0}}function qZ(Z,z){let $=new Set(z.values),J={flags:[],positionals:[]},Y=(X,Q)=>({value:X,opaque:Q.opaque,raw:Q.raw});for(let X=0;X<Z.length;X++){let Q=Z[X],B=Q.value;if(B==="--"){J.positionals.push(...Z.slice(X+1));break}if(B.startsWith("--")&&B.length>2){let K=B.indexOf("="),H=K>=0?B.slice(0,K):B;if(K>=0)J.flags.push({name:H,value:Y(B.slice(K+1),Q),inline:!0});else if($.has(H)){let M=Z[X+1];J.flags.push(M?{name:H,value:M}:{name:H,missing:!0}),X++}else J.flags.push({name:H});continue}if(B.startsWith("-")&&B.length>1){for(let K=1;K<B.length;K++){let H="-"+B[K],M=B.slice(K+1);if(M.startsWith("=")){J.flags.push({name:H,value:Y(M.slice(1),Q),inline:!0});break}if(!$.has(H)){J.flags.push({name:H});continue}if(M)J.flags.push({name:H,value:Y(M,Q),inline:!0});else{let V=Z[X+1];J.flags.push(V?{name:H,value:V}:{name:H,missing:!0}),X++}break}continue}J.positionals.push(Q)}return J}function S(Z,...z){let $=!1;for(let J of Z.flags){if(!z.includes(J.name))continue;if(!J.inline){$=!0;continue}let Y=J.value;$=!Y.opaque&&["1","t","T","TRUE","true","True"].includes(Y.value)}return $}var ZZ=(Z,...z)=>Z.flags.filter(($)=>z.includes($.name)),m=["-R","--repo","-q","--jq","-t","--template","--json"],BZ={"pr view":{values:m},"issue view":{values:m},"release view":{values:m},"discussion view":{values:[...m,"--after","-L","--limit","--order"]},"pr list":{values:[...m,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...m,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...m,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...m,"-L","--limit","-O","--order"]},"pr status":{values:m},"issue status":{values:m},"pr checks":{values:[...m,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...m,"--app","--assignee","--author","--author-date","--author-email","--author-name","--base","--checks","--closed","--commenter","--committer","--committer-date","--committer-email","--committer-name","--created","--hash","--head","--interactions","--involves","--label","--language","--limit","-L","--match","--mentions","--merged-at","--milestone","--no-assignee","--no-label","--no-milestone","--no-project","--order","--owner","--parent","--project","--reactions","--review","--review-requested","--reviewed-by","--sort","--state","--team-mentions","--tree","--updated","--visibility","--extension","--filename","--size","--forks","--good-first-issue","--help-wanted-issues","--number-topics","--stars","--topic","--followers","--include-forks","--license"]},"project item-list":{values:["--format","-L","--limit","--owner","-q","--jq","-t","--template","--query","--field","--field-id"]},api:{values:["-X","--method","-H","--header","-f","--raw-field","-F","--field","-q","--jq","-t","--template","-p","--preview","--input","--hostname","--cache"]},group:{values:["-R","--repo"]}},O5=new Set(["auth","browse","codespace","cs","gist","org","repo","skill","cache","run","workflow","co","agent-task","alias","attestation","completion","config","copilot","extension","ext","extensions","gpg-key","label","licenses","preview","ruleset","secret","ssh-key","variable","help","version","accessibility","actions","environment","exit-codes","formatting","mintty","reference","telemetry"]),L5=new Set(["pr","issue","release","discussion","search","project","api","status"]),A5=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),y5=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),R5=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),v5=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function U0(Z,z){let $=ZZ(Z,"--json"),J=[],Y=!1;for(let X of $){if(X.missing){if(z.appendsArgs)Y=!0;continue}if(!X.value)continue;if(X.value.opaque)Y=!0;J.push(...X.value.value.split(",").map((Q)=>Q.trim()).filter(Boolean))}return{present:$.length>0,opaque:Y,fields:J}}function Q1(Z,z){if(S(Z,"--verbose")||ZZ(Z,"-t","--template").length>0)return!1;let $=ZZ(Z,"-q","--jq");return $.length>0&&$.every((J)=>J.value!==void 0&&!J.value.opaque&&I2(J.value.value,{rootScalars:z}))}function K1(Z,z,$,J){let Y=U0(Z,$);if(Y.opaque)return I("unclassifiable");if(Y.fields.every((X)=>z.has(X)))return T;if($.debug)return I("debug-traffic");return Q1(Z)?T:I(J)}function M0(Z,z,$,J,Y){let X=qZ(Z,BZ[z]);if(S(X,"-h","--help"))return T;if(S(X,"-w","--web"))return J.debug?I("debug-traffic"):T;if(Y&&S(X,"-c","--comments"))return I("view-comments");if(!U0(X,J).present)return I(J.debug?"debug-traffic":"view-human");return K1(X,$,J,"json-composite")}function e(Z,z,$,J){let Y=qZ(Z,BZ[z]);if(S(Y,"-h","--help"))return T;if(J.debug&&(S(Y,"-w","--web")||!U0(Y,J).present))return I("debug-traffic");if(S(Y,"-w","--web"))return T;return K1(Y,$,J,"json-composite")}function b5(Z,z){let $=qZ(Z,BZ["pr checks"]);if(S($,"-h","--help"))return T;if(z.debug)return I("debug-traffic");if(S($,"-w","--web"))return T;if(!U0($,z).present)return I("checks-human");return K1($,P5,z,"checks-json")}function E5(Z){let z=new Set(BZ.group.values);for(let $=0;$<Z.length;$++){let J=Z[$].value;if(J==="--")return{sub:Z[$+1],rest:Z.slice($+2)};if(!J.startsWith("-")||J==="-")return{sub:Z[$],rest:[...Z.slice(0,$),...Z.slice($+1)]};if(z.has(J))$++}return{rest:Z}}function S5(Z,z,$){let{sub:J,rest:Y}=E5(z);if(!J)return $.appendsArgs?I("unclassifiable"):T;if(J.opaque)return I("unclassifiable");let X=J.value;if((Z==="pr"?A5:Z==="issue"?y5:Z==="release"?R5:Z==="discussion"?v5:new Set).has(X))return $.debug?I("debug-traffic"):T;if($.appendsArgs&&!(Z==="project"&&X!=="item-list"))return I("unclassifiable");switch(Z){case"pr":if(X==="view")return M0(Y,"pr view",r0,$,!0);if(X==="list"||X==="ls")return e(Y,"pr list",r0,$);if(X==="status")return e(Y,"pr status",r0,$);if(X==="checks")return b5(Y,$);if(X==="diff"){let B=qZ(Y,BZ["pr diff"]);if(S(B,"-h","--help"))return T;if($.debug)return I("debug-traffic");return S(B,"--patch")?I("composite-other"):T}return I("unclassifiable");case"issue":if(X==="view")return M0(Y,"issue view",t0,$,!0);if(X==="list"||X==="ls")return e(Y,"issue list",t0,$);if(X==="status")return e(Y,"issue status",t0,$);return I("unclassifiable");case"release":if(X==="view")return M0(Y,"release view",T2,$,!1);if(X==="list"||X==="ls")return e(Y,"release list",T2,$);return I("unclassifiable");case"discussion":if(X==="view")return M0(Y,"discussion view",q2,$,!0);if(X==="list"||X==="ls")return e(Y,"discussion list",q2,$);return I("unclassifiable");case"search":if(X==="prs"||X==="issues")return e(Y,"search",q5,$);if(X==="commits")return e(Y,"search",C5,$);if(X==="code"||X==="repos")return $.debug?I("debug-traffic"):T;return I("unclassifiable");case"project":{if($.debug)return I("debug-traffic");if(X!=="item-list")return T;let B=qZ(Y,BZ["project item-list"]);if(S(B,"-h","--help"))return T;let K=ZZ(B,"--format");if(K.some((H)=>!H.value||H.value.opaque))return I("unclassifiable");if(K.every((H)=>H.value.value!=="json"))return T;return Q1(B)?T:I("composite-other")}}return I("unclassifiable")}var L2=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function f5(Z){let z=Z.value.trim(),$=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(z);if($){let X=$[1].toLowerCase(),Q=$[2]??"/";if(X==="api.github.com"||/^api\./.test(X))z=Q;else if(/^\/api\/v3(?:\/|$)/i.test(Q))z=Q.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(Q))z="graphql";else return null}z=z.replace(/[?#].*$/,"");let J=[],Y=[];for(let X of z.split("/")){let Q;try{Q=decodeURIComponent(X)}catch{return null}for(let B of Q.split("/")){if(B===""||B===".")continue;if(B===".."){J.pop(),Y.pop();continue}J.push(B.toLowerCase()),Y.push(Z.opaque&&/[$`]/.test(B)||/[*?[]/.test(B)||O2(B))}}return{segments:J,opaque:Y}}function k5(Z){let z=f5(Z);if(!z)return{kind:"unclassifiable",segments:[]};let{segments:$,opaque:J}=z,Y=(K)=>({kind:K,segments:$});if($.length===1&&$[0]==="graphql")return Y("graphql");if($.length===0)return Y(Z.opaque?"unclassifiable":"other");if(J[0])return Y("unclassifiable");let X,Q=[];if($[0]==="repos")X=$.slice(3),Q=J.slice(3);else if($[0]==="repositories")X=$.slice(2),Q=J.slice(2);if(X){if(($[0]==="repos"?J.slice(1,3):J.slice(1,2)).some(Boolean)){let H=J.findIndex(Boolean),M=$.findIndex((V,G)=>G>H&&!J[G]&&x5.has(V));return Y(M<0?"unclassifiable":C2($.slice(M),J.slice(M)))}return Y(C2(X,Q))}let B=$[0];if(B==="issues")return Y("sensitive");if(B==="user"&&$[1]==="issues")return Y("sensitive");if(B==="orgs"&&$[2]==="issues")return Y("sensitive");if(B==="search")return Y($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&J[1]?"unclassifiable":"other");if(B==="events"||B==="networks")return Y("sensitive");if((B==="users"||B==="orgs")&&$.slice(2).some((K)=>K==="events"||K==="received_events"||K==="discussions"))return Y("sensitive");if((B==="users"||B==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return Y("sensitive");if(B==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||B==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return Y("sensitive");if(B==="teams"&&$.includes("discussions"))return Y("sensitive");if(B==="projects"&&$.includes("cards"))return Y("sensitive");if(J.some(Boolean))return Y($.some((K)=>K==="events"||K==="discussions"||K==="issues")?"sensitive":"unclassifiable");return Y("other")}var x5=new Set([...L2,"branches","git","actions","hooks","zipball","tarball"]);function C2(Z,z){let[$,J]=Z;if($===void 0)return"other";if(z[0])return"unclassifiable";if($==="issues"&&/^\d+$/.test(J??"")&&Z[2]==="labels")return"other";if(L2.has($))return"sensitive";if($==="branches"){if(Z.length===1||Z.slice(1).some((Y)=>Y==="protection")||Z[Z.length-1]==="rename")return"other";return z.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if($==="git")return J===void 0||J==="commits"||J==="tags"?"sensitive":z[1]?"unclassifiable":"other";if($==="actions"){if(J===void 0)return"sensitive";if(z[1])return"unclassifiable";if(J==="runs"||J==="jobs"){if(Z[Z.length-1]==="logs"&&Z.length>=4&&!z.some(Boolean))return"download";return"sensitive"}if(J==="workflows"&&Z[3]==="runs")return"sensitive";if(J==="artifacts"&&Z.length===4)return"download";return"other"}if($==="hooks"&&Z[2]==="deliveries"&&Z[3]!==void 0)return"sensitive";if($==="zipball"||$==="tarball")return"download";return"other"}function h5(Z,z){if(z[0]!=="repos"||z.length<5)return!1;let $=z.slice(3),J=(X)=>/^\d+$/.test($[X]??""),Y=(...X)=>$.length===X.length&&X.every((Q,B)=>typeof Q==="number"?J(B):$[B]===Q);if(Z==="DELETE")return Y("issues","comments",0)||Y("pulls","comments",0)||Y("comments",0)||Y("issues","comments",0,"reactions",0)||Y("pulls","comments",0,"reactions",0)||Y("issues",0,"reactions",0)||Y("issues",0,"labels")||$.length===4&&$[0]==="issues"&&J(1)&&$[2]==="labels"||Y("releases",0)||Y("releases","assets",0)||Y("actions","runs",0)||Y("actions","runs",0,"logs")||Y("deployments",0)||Y("milestones",0)||Y("issues",0,"lock");if(Z==="POST")return $.length===4&&$[0]==="actions"&&$[1]==="runs"&&J(2)&&["rerun","rerun-failed-jobs","cancel","force-cancel","approve"].includes($[3])||Y("actions","jobs",0,"rerun")||Y("issues",0,"labels");if(Z==="PUT")return Y("pulls",0,"merge")||Y("pulls",0,"update-branch")||Y("issues",0,"labels")||Y("issues",0,"lock");if(Z==="GET")return Y("pulls",0,"merge");return!1}function w5(Z){if(Z[0]!=="repos"||Z.length!==5||!/^\d+$/.test(Z[4]))return;if(Z[3]==="pulls")return new Set(["commits","comments","review_comments"]);if(Z[3]==="issues")return new Set(["comments"]);return}var g5=new Set(["body","bodyText","bodyHTML","bodyUrl","bodyResourcePath","comments","reviews","latestReviews","latestOpinionatedReviews","reviewThreads","url","permalink","summary","text","description","message","messageBody","messageHeadline","commitBody","commitHeadline","annotations","rawDetails","note","diff","readme","payload"]),u5=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function l5(Z){let z=[],$=0;while($<Z.length){let J=Z[$];if(/[\s,\uFEFF]/.test(J)){$++;continue}if(J==="#"){let Q=Z.indexOf(`
33
- `,$);$=Q<0?Z.length:Q+1;continue}if(Z.startsWith('"""',$)){let Q=$+3;for(;;){let B=Z.indexOf('"""',Q);if(B<0)return null;if(Z[B-1]==="\\"){Q=B+3;continue}$=B+3;break}continue}if(J==='"'){let Q=$+1;while(Q<Z.length&&Z[Q]!=='"'&&Z[Q]!==`
34
- `)Q+=Z[Q]==="\\"?2:1;if(Z[Q]!=='"')return null;$=Q+1;continue}let Y=/^[_A-Za-z][_0-9A-Za-z]*/.exec(Z.slice($,$+256));if(Y){z.push({kind:"name",text:Y[0]}),$+=Y[0].length;continue}let X=/^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(Z.slice($,$+64));if(X){$+=X[0].length;continue}if(Z.startsWith("...",$)){z.push({kind:"punct",text:"..."}),$+=3;continue}if("{}()[]:!$@=|&".includes(J)){z.push({kind:"punct",text:J}),$++;continue}return null}return z}function m5(Z){let z=l5(Z);if(!z)return!0;let $=[],J="",Y=0;for(let X=0;X<z.length;X++){let Q=z[X];if(Q.kind==="punct"){if(Q.text==="(")Y++;else if(Q.text===")"){if(Y--,Y<0)return!0}else if(Y===0&&Q.text==="{")$.push(J),J="";else if(Y===0&&Q.text==="}"){if($.pop()===void 0)return!0;J=""}continue}if(Y>0)continue;let B=z[X-1];if(B?.kind==="punct"&&(B.text==="@"||B.text==="$"))continue;if(z[X+1]?.kind==="punct"&&z[X+1].text===":")continue;if(Q.text==="on"&&B?.kind==="punct"&&B.text==="...")continue;if(B?.kind==="name"&&B.text==="on"){J=Q.text;continue}if($.length===0){J=Q.text;continue}if(g5.has(Q.text)||/(?:Url|URL|HTML|Html)$/.test(Q.text))return!0;if(Q.text==="title"&&$.some((K)=>u5.has(K)))return!0;J=Q.text}return Y!==0||$.length!==0}function p5(Z,z){let $=qZ(Z,BZ.api);if(S($,"-h","--help"))return T;let J=$.positionals[0];if(!J)return z.appendsArgs?I("unclassifiable"):T;let Y=k5(J),X=ZZ($,"-X","--method"),Q=X[X.length-1],B=ZZ($,"-f","--raw-field","-F","--field","--input"),K=Q?Q.value&&!Q.value.opaque?Q.value.value.toUpperCase():"?":B.length>0?"POST":"GET",H=h5(K,Y.segments),M=T;if(Y.kind==="unclassifiable")M=I("unclassifiable");else if(Y.kind==="sensitive"&&!H)M=I("api-rest");else if(Y.kind==="graphql")M=c5($);if(z.debug||S($,"--verbose")){if(Y.kind==="download"&&!M.refused)M=I("api-rest");if(M.refused)return z.debug?I("debug-traffic"):M;return T}if(z.appendsArgs&&Y.kind!=="other"&&Y.kind!=="download")return I("unclassifiable");if(!M.refused||S($,"--silent"))return T;if(Q1($,w5(Y.segments)))return T;return M}function c5(Z){if(ZZ(Z,"--input").length>0)return I("unclassifiable");let z=ZZ(Z,"-f","--raw-field","-F","--field"),$=z.filter((J)=>J.value&&/^query=/.test(J.value.value));if($.length===0||z.some((J)=>!J.value))return I("unclassifiable");for(let J of $){let Y=J.value.value.slice(6);if((J.name==="-F"||J.name==="--field")&&Y.startsWith("@")||J.value.opaque)return I("unclassifiable");if(m5(Y))return I("api-graphql")}return T}function G0(Z,z){let $=0;while($<Z.length&&Z[$].value.startsWith("-")&&!Z[$].opaque){if(["--help","-h","--version"].includes(Z[$].value))return T;$++}if($>=Z.length)return z.appendsArgs?I("unclassifiable"):T;let J=Z[$],Y=Z.slice($+1);if(J.opaque)return I("unclassifiable");switch(J.value){case"pr":case"issue":case"release":case"discussion":case"search":case"project":return S5(J.value,Y,z);case"api":return p5(Y,z);case"status":return Y.length>0&&Y.every((X)=>X.value==="-h"||X.value==="--help")?T:I("composite-other");case"help":case"version":return T;case"cs":case"codespace":{let X=Y.findIndex((Q)=>Q.value==="--");if(Y.some((Q)=>Q.value==="ssh")&&X>=0&&X+1<Y.length){let Q=d(Y.slice(X+1).map((B)=>B.value).join(" "),z.depth+1,z.debug);if(Q.refused)return Q}break}}if(!O5.has(J.value))return I("unclassifiable");if(z.debug)return I("debug-traffic");return T}var j0=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","fish"]),i5=new Set(["su","runuser","script","flock"]),d5=new Set(["secrets","op","unbuffer","caffeinate","chronic","strace","ltrace","firejail","bwrap","nsenter","unshare","chroot","sg","retry","parallel","doppler","aws-vault","dotenv","direnv","faketime","taskset","numactl","cgexec","systemd-run","docker","podman","kubectl","mise","asdf","rtx","devbox","gosu","su-exec","setpriv","pkexec","with-contenv","uv","poetry","pipenv","npx","bunx","pnpm","yarn","nix","nix-shell","infisical","chamber","envchain","dotenvx","teller","vault","chrt","coproc","prlimit","ionice","cpulimit","trickle","proxychains","proxychains4","torsocks","tsocks","catchsegv","valgrind"]),s5=new Map([["bun",["x","exec"]],["npm",["exec","x"]],["deno",["run"]]]),n5=new Set(["-I","-L","-l","-n","-P","-s","-d","-E","-e","-a","--arg-file","--delimiter","--max-args","--max-lines","--max-procs","--max-chars","--replace","--eof","--process-slot-var"]),o5=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),V0=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/,a5=/^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/,r5=6;function P2(Z,z){let $,J;for(let Y of Z){let X=a5.exec(Y.value);if(!X)continue;let Q={...Y,value:X[2]};if(X[1]==="GH_DEBUG")$=Q;else if(X[1]==="DEBUG")J=Q}if($)return $.opaque||!["","0","false","no"].includes($.value);if(J&&(J.opaque||["1","true","yes","api"].includes(J.value)))return!0;return z}function B1(Z){let z=b(Z),$=0;return{segments:z.segments.map((Y)=>{let X=Y.words[0],Q=Z.slice($,X.start);return $=Y.words[Y.words.length-1].end,{words:Y.words,redirects:Y.redirects,sepBefore:Q}}),trustworthy:z.trustworthy}}var A2=(Z)=>/(?:^|[^|])\|&?$/.test(Z.trim());function J1(Z,z){if(!j0.has(Z))return!1;if(H1(z))return!1;for(let $=0;$<z.length;$++){let J=z[$].value;if(J==="--")return $+1>=z.length;if(J==="-"||J==="-s")return!0;if(/^[-+][A-Za-z]*[oO]$/.test(J)){$++;continue}if(!J.startsWith("-")&&!J.startsWith("+"))return!1}return!0}function z1(Z){let{segments:z}=B1(Z.trim());if(z.length!==1)return null;let $=z[0],J=x($);if(J<0)return null;let Y=KZ(TZ($.words[J].text).value),X=$.words.slice(J+1).filter((Q,B)=>!$.redirects.has(B+J+1)).map((Q)=>TZ(Q.text));if(Y==="echo")return X.filter((Q,B)=>!(B===0&&/^-[neE]+$/.test(Q.value))).map((Q)=>Q.value).join(" ");if(Y==="printf"){let[Q,...B]=X.filter((H)=>H.value!=="--");if(!Q)return null;let K=0;return Q.value.replace(/\\n/g,`
35
- `).replace(/%s/g,()=>B[K++]?.value??"")+(K<B.length?" "+B.slice(K).map((H)=>H.value).join(" "):"")}if(Y==="cat"){let Q=Z.indexOf("<<");if(Q<0)return null;let B=DZ(Z,Q),K=Z.indexOf(`
36
- `,Q);if(!B||K<0)return null;let H=z0(Z,K,[B]);if(H<0)return null;let M=Z.slice(K+1,H);return M.slice(0,M.lastIndexOf(B.delimiter)).replace(/\n$/,"")}return null}function e0(Z,z,$){for(let J of $1(Z).bodies){let Y=z1(J);if(Y===null)continue;let X=d(Y,z+1,$.debug);if(X.refused)return X}return T}function d(Z,z=0,$=!1){if(typeof Z!=="string"||!Z.trim())return T;if(z>r5)return V0.test(Z)?I("unclassifiable"):T;let{segments:J,trustworthy:Y}=B1(Z);if(!Y)return V0.test(Z)?I("unclassifiable"):T;let X=$,Q=(B)=>d(B,z+1,X);for(let B of Z6(Z)){if(B.runsBody){let K=Q(B.body);if(K.refused)return K}if(!B.quoted){let K=$1(B.body,"heredoc");if(!K.complete&&V0.test(B.body))return I("unclassifiable");for(let H of K.bodies){let M=Q(H);if(M.refused)return M}}}for(let B=0;B<J.length;B++){let K=J[B];for(let N of K.words){let A=$1(N.text);if(!A.complete&&V0.test(N.text))return I("unclassifiable");for(let h of A.bodies){let w=Q(h);if(w.refused)return w}}let H=x(K),M=K.words.map((N,A)=>({word:TZ(N.text),redirect:K.redirects.has(A)})),V=M.slice(0,H<0?M.length:H).map((N)=>N.word),G=H>=0?KZ(M[H].word.value):"";if(H<0||["export","declare","typeset","readonly","local"].includes(G)){if(X=P2([...V,...M.slice(H+1).map((N)=>N.word)],X),H<0)continue}let U=P2(V,X),j=M.slice(H+1).filter((N)=>!N.redirect).map((N)=>N.word),F=M.slice(H+1).filter((N)=>N.redirect).map((N)=>N.word),L=M[H].word,y=KZ(L.value),E={depth:z,appendsArgs:!1,debug:U};if(H>0&&M[H-1].word.value==="function"){let N=j.filter((h)=>!["{","()","(",")"].includes(h.value)),A=Y1(N,E);if(A.refused)return A;continue}if(B>0&&A2(K.sepBefore)&&J1(y,j)){let N=J[B-1],A=t5(Z,N),h=A===null?null:z1(A);if(h!==null){let w=d(h,z+1,U);if(w.refused)return w}}let l=J[B+1];if(l&&/<\(\s*$/.test(l.sepBefore)&&(j0.has(y)||y==="source"||y===".")){let N=l.words[0].start-l.sepBefore.length+l.sepBefore.lastIndexOf("("),A=XZ(Z,N),h=A<0?null:z1(Z.slice(N+1,A-1));if(h!==null){let w=d(h,z+1,U);if(w.refused)return w}}let q=y2(y,L,j,F,K.words.slice(0,H+1),E);if(q.refused)return q}return T}function t5(Z,z){let $=z.words[0],J=z.words[z.words.length-1];return $&&J?Z.slice($.start,J.end):null}function e5(Z){let z=KZ(Z.value);return/[$`]/.test(z)||z===""?void 0:z}function y2(Z,z,$,J,Y,X){let Q=X.depth,B=(K)=>d(K,Q+1,X.debug);if(z.opaque){let K=e5(z);if(K===void 0){let H=$.find((V)=>!V.value.startsWith("-")),M=G0($,X);if(!M.refused)return T;return M.rule!=="unclassifiable"||H!==void 0&&!H.opaque&&L5.has(H.value)?M:T}Z=K}if(Z==="gh")return G0($,X);if(j0.has(Z)){let K=H1($);if(K){let H=B(K.value);if(H.refused||!K.opaque)return H;return e0(K.raw,Q,X)}for(let H of J){let M=B(H.value);if(M.refused)return M;if(H.opaque){let V=e0(H.raw,Q,X);if(V.refused)return V}}return T}if(i5.has(Z)){let K=$.findIndex((M)=>M.value==="-c"||M.value==="--command"||/^-[A-Za-z]*c$/.test(M.value)),H=K>=0?$[K+1]:void 0;return H?B(H.value):Z1($,X)}if(Z==="eval"||Z==="watch"){let K=$;if(Z==="watch"){let M=0;while(M<$.length&&$[M].value.startsWith("-")){if($[M].value==="--"){M++;break}if(["-n","--interval","-q","--equexit"].includes($[M].value))M++;M++}K=$.slice(M)}let H=B(K.map((M)=>M.value).join(" "));if(H.refused)return H;for(let M of K){let V=e0(M.raw,Q,X);if(V.refused)return V}return T}if(Z==="env")return B(uZ([...Y.map((K)=>TZ(K.text).value),...$.map((K)=>K.value)]));if(Z==="ssh"){let K=0;for(;K<$.length;K++){let V=$[K].value;if(!V.startsWith("-"))break;if(o5.has(V))K++}let H=$.slice(K+1);if(H[0]?.value==="--")H.shift();let M=H.map((V)=>V.value).join(" ");return M?B(M):T}if(Z==="xargs"){let K=0,H=!1;for(;K<$.length;K++){let M=$[K].value;if(M==="--"){K++;break}if(!M.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(M))H=!0;if(n5.has(M))K++}return Y1($.slice(K),{depth:Q,appendsArgs:!H,debug:X.debug})}if(Z==="find"){for(let K=0;K<$.length;K++){if(!["-exec","-execdir","-ok","-okdir"].includes($[K].value))continue;let H=K+1;while(H<$.length&&$[H].value!==";"&&$[H].value!=="+")H++;let M=Y1($.slice(K+1,H),X);if(M.refused)return M;K=H}return T}if(d5.has(Z))return Z1($,X);if(s5.get(Z)?.includes($[0]?.value??""))return Z1($.slice(1),X);return T}function Y1(Z,z){if(Z.length===0)return T;let $=KZ(Z[0].value);if($==="gh")return G0(Z.slice(1),z);if(j0.has($)){let J=H1(Z.slice(1));return J?d(J.value,z.depth+1,z.debug):T}return y2($,Z[0],Z.slice(1),[],[],z)}function Z1(Z,z){let $=Z.findIndex((J)=>!J.opaque&&KZ(J.value)==="gh"&&(J.value==="gh"||J.value.includes("/")));return $>=0?G0(Z.slice($+1),z):T}function H1(Z){for(let z=0;z<Z.length;z++){let $=Z[z].value;if($==="--")return;if(!$.startsWith("-")&&!$.startsWith("+"))return;if($==="-c"||/^-[A-Za-z]+$/.test($)&&$.includes("c"))return Z.slice(z+1).find((J)=>!J.value.startsWith("-")||J.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test($))z++}return}function Z6(Z){let z=[],$=0;for(;;){let J=Z.indexOf("<<",$);if(J<0)break;if($=J+2,Z[J+2]==="<"||J>0&&Z[J-1]==="<"){$=J+3;continue}let Y=DZ(Z,J);if(!Y)continue;let X=Z.lastIndexOf(`
37
- `,J)+1,Q=Z.indexOf(`
38
- `,J);if(Q<0)continue;let B=z0(Z,Q,[Y]),K=B<0?Z.slice(Q+1):Z.slice(Q+1,B),H=B<0?K:K.slice(0,Math.max(0,K.lastIndexOf(Y.delimiter))).replace(/\n$/,""),M=Z.slice(X,J)+" HEREDOC_OPERATOR "+Z.slice(Y.end,Q);z.push({body:H,runsBody:$6(M),quoted:Y.quoted})}return z}function $6(Z){let{segments:z}=B1(Z),$=z.findIndex((B)=>B.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(B)=>{let K=x(B);if(K<0)return{verb:"",args:[]};let H=B.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>TZ(M.text));return{verb:KZ(TZ(B.words[K].text).value),args:H}},{verb:Y,args:X}=J(z[$]);if(Y==="ssh"||J1(Y,X))return!0;if((Y==="source"||Y===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(X[0]?.value??""))return!0;let Q=z[$+1];if(Y==="cat"&&Q&&A2(Q.sepBefore)){let B=J(Q);return B.verb==="ssh"||J1(B.verb,B.args)}return!1}var J6=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function R2(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:X1}}}var z6=new Set(["Bash","Monitor"]);function v2(Z){if(Z?.hook_event_name!=="PreToolUse"||!z6.has(Z.tool_name??""))return{continue:!0};let z=GZ(Z);if(!z.trim())return{continue:!0};try{return d(z).refused?R2():{continue:!0}}catch{return J6.test(z)?R2():{continue:!0}}}function V1(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function E2(Z,z){V1(Z);let $=Z,J=JSON.parse(z);if(!J||Array.isArray(J)||J.hook_event_name!=="PreToolUse"||typeof J.tool_name!=="string"||!J.tool_input||typeof J.tool_input!=="object"||Array.isArray(J.tool_input)||typeof J.cwd!=="string"||!b2(J.cwd))throw Error("Invalid safety input");if(J.tool_name==="Bash"&&typeof J.tool_input.command!=="string")throw Error("Invalid shell input");if(J.tool_name==="Monitor"&&J.tool_input.command!==void 0&&typeof J.tool_input.command!=="string")throw Error("Invalid monitor input");let Y=J.hasna_execution;if(Y!==void 0&&(!Y||Object.keys(Y).sort().join()!=="agent,schema"||Y.schema!=="hasna.hooks.execution.v1"||typeof Y.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(Y.agent)))throw Error("Invalid execution capability");let X=Y===void 0?void 0:{runtime:process.execPath,home:M1(),path:process.env.PATH,agent:Y.agent};if(X&&(!b2(X.runtime)||!X.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(J.tool_name)){if(J.tool_input.command!==void 0&&J.tool_input.patch!==void 0&&J.tool_input.command!==J.tool_input.patch)throw Error("Conflicting patch aliases");let y=J.tool_input.command??J.tool_input.patch;if(typeof y!=="string")throw Error("Invalid patch input");J.tool_input={...J.tool_input,command:y,patch:y}}let Q=J.tool_name==="Monitor",B=J.tool_name==="Bash"||Q&&typeof J.tool_input.command==="string",K=Q&&B?{...J,tool_name:"Bash"}:J,H=(y)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:y}}),M=U2(K).output,V=v2(K),G=K.tool_input.command,U=()=>NZ(G,{home:M1(),cwd:J.cwd}).handoffHits.length>0,j=B&&(U()||!!YZ(G,U)),F=$==="trash-guard"&&(!Q||B)?p1(K,{home:M1(),cwd:J.cwd,findTrash:rZ,inspectTrash:bZ,execution:X}):{continue:!0};if(Q&&F.hookSpecificOutput?.permissionDecision==="allow")F=H("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let L=M.decision==="block"?H(M.reason):V.hookSpecificOutput?V:j?H("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):F;return JSON.stringify({verdict:"continue"in L?null:L})}var S2=process.argv[1];V1(S2);process.stdout.write(E2(S2,await Bun.stdin.text()));
2
+ import{homedir as dn}from"os";import{isAbsolute as Ir}from"path";import{isAbsolute as Ts,join as me,normalize as $s,resolve as Cs,sep as Ct}from"path";import{dirname as de,isAbsolute as Ye,join as yt,resolve as ne}from"path";import{accessSync as Hr,closeSync as Mr,constants as Ke,fstatSync as Fr,lstatSync as Te,openSync as Br,readFileSync as jr,readlinkSync as Gr,readSync as qr,realpathSync as xt,statSync as kt}from"fs";import{spawnSync as zr}from"child_process";var wn={missing:"No verified @hasna/trash guard was found on PATH.",unsafe_executable:"The Trash candidate is not an owned executable file or is writable by group or others.",unsafe_manifest:"The Trash package manifest is not a safe owned regular file.",unsafe_directory:"A Trash PATH or package directory is not owned safely or is writable by group or others.",unsafe_interpreter:"The Trash interpreter is missing, unsupported, or not a safe owned executable on its actual PATH.",unrecognized_package:"The candidate is not the registered @hasna/trash executable.",identity_failed:"The installed Trash identity probe failed or exceeded its deadline.",unsupported_protocol:"The installed Trash version does not expose the required guard protocol."};function $e(e){return e===0||e===process.getuid?.()}function Xe(e,r=!1){let t=e;for(let n=0;n<32;n++){if(!Ye(t)||t.length>4096||!Ce("/"))return!1;let s=t.split("/"),i=s.pop();if(!i||i==="."||i==="..")return!1;let o="/";for(let u of s){if(!u||u===".")continue;if(u===".."){o=de(o);continue}let c=yt(o,u),f=Te(c);if(r&&c==="/bin"&&f.isSymbolicLink()&&f.uid===0){let d=xt(c);if(!Ce(d))return!1;o=d;continue}if(!f.isDirectory()||!$e(f.uid)||f.mode&18)return!1;o=c}let a=yt(o,i),l=Te(a);if(!$e(l.uid))return!1;if(l.isSymbolicLink()){let u=Gr(a);t=Ye(u)?u:o+"/"+u;continue}return l.isFile()&&Boolean(l.mode&73)&&!(l.mode&18)}return!1}function Ur(e){if(!Ye(e)||ne(e)!==(e.replace(/\/+$/,"")||"/"))return!1;for(let r=ne(e);;r=de(r)){try{return Te(r),Ce(r)}catch(t){if(t.code!=="ENOENT")return!1}if(de(r)===r)return!1}}function Vr(e,r){let t=Br(e,Ke.O_RDONLY|Ke.O_NONBLOCK|Ke.O_NOFOLLOW),n;try{if(!Fr(t).isFile())return!1;let i=Buffer.alloc(256),o=qr(t,i,0,i.length,0);n=i.subarray(0,o).toString("utf8").split(`
3
+ `)[0]}finally{Mr(t)}let s=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(n);if(s&&s[1]!=="/usr/bin/env")return Xe(s[1],!0);if(n!=="#!/usr/bin/env bun"||!Xe("/usr/bin/env",!0))return!1;for(let i of r.split(":").slice(0,64)){if(!Ur(i))return!1;let o=ne(i,"bun");try{if(!kt(o).isFile())continue;Hr(o,Ke.X_OK)}catch{continue}return Xe(o,!0)}return!1}function Ce(e){let r=e;for(;;){let t=Te(r);if(!t.isDirectory()||!$e(t.uid)||(t.mode&18)!==0)return!1;let n=de(r);if(n===r)return!0;r=n}}function Pe(e=process.env){let r=e.PATH??"",t=Date.now()+2000,n="missing",s=(i)=>{if(n==="missing"||n==="unrecognized_package"||i.startsWith("unsafe_"))n=i};for(let i of r.split(":").slice(0,64)){if(!Ye(i)||Date.now()>=t)continue;let o=ne(i,"trash");try{let a=kt(o);if(!a.isFile()||!$e(a.uid)||(a.mode&73)===0||(a.mode&18)!==0){s("unsafe_executable");continue}let l=xt(o);if(!Ce(ne(i))||!Ce(de(l))){s("unsafe_directory");continue}if(!Xe(o)){s("unsafe_directory");continue}let u=ne(de(l),"../.."),c=yt(u,"package.json"),f=kt(c);if(!f.isFile()||!$e(f.uid)||f.size>16384||(f.mode&18)!==0||Te(c).isSymbolicLink()){s("unsafe_manifest");continue}let d=JSON.parse(jr(c,"utf8"));if(d.name!=="@hasna/trash"||typeof d.version!=="string"||typeof d.bin?.trash!=="string"||xt(ne(u,d.bin.trash))!==l){s("unrecognized_package");continue}try{if(!Vr(l,r)){s("unsafe_interpreter");continue}}catch{s("unsafe_interpreter");continue}let h=t-Date.now();if(h<=0){s("identity_failed");break}let p=zr(o,["--identity"],{encoding:"utf8",timeout:h,maxBuffer:2048,env:{PATH:r},stdio:["ignore","pipe","pipe"]});if(p.error||p.status!==0||Date.now()>=t){s("identity_failed");continue}let m=JSON.parse(p.stdout);if(m.name==="@hasna/trash"&&m.version===d.version&&m.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:o,version:d.version};s("unsupported_protocol")}catch{}}return{ok:!1,code:n}}function Qe(e=process.env){let r=Pe(e);return r.ok?r.path:null}function he(e){let r=e.tool_input?.command;return typeof r==="string"?r:""}var yn=["/","/bin","/boot","/dev","/etc","/home","/lib","/lib32","/lib64","/libx32","/opt","/proc","/root","/run","/sbin","/srv","/sys","/usr","/var","/Applications","/Library","/System","/Users","/Volumes","/private"];var We=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,z=(e)=>e.split("/").pop()??"";function Je(e){let r=e.startsWith("~")?e.slice(1).split("/",1)[0]:"";if(r&&!/['"\\]/.test(r))return!0;let t=null,n=0;for(let s=0;s<e.length;s++){let i=e[s];if(t==="'"){if(i==="'")t=null;continue}if(i==="\\"){s++;continue}if(t==='"'){if(i==='"')t=null;continue}if(i==="'"||i==='"')t=i;else if(i==="$"&&e[s+1]==="{")n++,s++;else if(i==="}"&&n>0)n--;else if(i==="{"||i==="}")return!0}return!1}var vt=64;function xn(e,r){let t=0;for(let n=r;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==="{")t++;else if(e[n]==="}"&&--t===0)return n;return e.length-1}function Zr(e){let r=e.match(/^([-+]?\d+)\.\.([-+]?\d+)(?:\.\.([-+]?\d+))?$/),t=r?null:e.match(/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([-+]?\d+))?$/),n=r??t;if(!n)return null;let s=r?Number(n[1]):n[1].charCodeAt(0),i=r?Number(n[2]):n[2].charCodeAt(0),o=Math.abs(Number(n[3]??1))||1;if(!Number.isSafeInteger(s)||!Number.isSafeInteger(i)||!Number.isSafeInteger(o))return"overflow";if(Math.floor(Math.abs(i-s)/o)+1>vt)return"overflow";let a=r&&(/^[-+]?0\d/.test(n[1])||/^[-+]?0\d/.test(n[2]))?Math.max(n[1].length,n[2].length):0,l=[];for(let u=s;s<=i?u<=i:u>=i;u+=s<=i?o:-o)if(!r)l.push(String.fromCharCode(u));else l.push(u<0?`-${String(-u).padStart(a-1,"0")}`:String(u).padStart(a,"0"));return l}function Kr(e){let r=null,t=0;for(let n=0;n<e.length;n++){let s=e[n];if(r==="'"){if(s==="'")r=null;continue}if(s==="\\"){n++;continue}if(r==='"'){if(s==='"')r=null;continue}if(s==="'"||s==='"')r=s;else if(s==="$"&&e[n+1]==="{")n=xn(e,n+1);else if(s==="{"){if(++t>vt)return"overflow";let i=null,o=0,a=!0,l=[];for(let u=n;u<e.length;u++){let c=e[u];if(i==="'"){if(c==="'")i=null;continue}if(c==="\\"){a=!1,u++;continue}if(i==='"'){if(c==='"')i=null;continue}if(c==="'"||c==='"')i=c,a=!1;else if(c==="$"&&e[u+1]==="{")u=xn(e,u+1),a=!1;else if(c==="{")o++;else if(c===","&&o===1)l.push(u);else if(c==="}"&&--o===0){if(l.length>0){let d=[n,...l,u];return{open:n,close:u,parts:d.slice(0,-1).map((h,p)=>e.slice(h+1,d[p+1]))}}let f=a?Zr(e.slice(n+1,u)):null;if(f==="overflow")return f;if(f)return{open:n,close:u,parts:f};break}}}}return null}function re(e){if(e.length>4096&&e.includes("{"))return null;let r=Kr(e);if(r===null)return[e];if(r==="overflow")return null;let t=[];for(let n of r.parts){let s=re(e.slice(0,r.open)+n+e.slice(r.close+1));if(s===null||t.push(...s)>vt)return null}return t}var g={arg:"none"},w={arg:"value"},Ie={arg:"optional"},Z={arg:"none",effect:"lookup"},v={arg:"none",effect:"refuse"},X={help:v,version:v},Xr=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,_t={timeout:{short:{k:w,s:w,v:g},long:{"kill-after":w,signal:w,verbose:g,foreground:g,"preserve-status":g,...X},positionals:[Xr]},env:{short:{i:g,"0":g,v:g,u:w,a:w,C:v,S:v},long:{"ignore-environment":g,null:g,debug:g,unset:w,argv0:w,chdir:v,"split-string":v,"block-signal":Ie,"default-signal":Ie,"ignore-signal":Ie,"list-signal-handling":v,...X},env:!0},nice:{short:{n:w},long:{adjustment:w,...X},numericOption:!0},nohup:{short:{},long:{...X}},command:{short:{p:g,v:Z,V:Z},long:{}},exec:{short:{c:g,l:g,a:w},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:w,o:w,e:w},long:{input:w,output:w,error:w,...X}},time:{short:{p:g,a:g,q:g,v:g,f:w,o:v,V:v},long:{portability:g,append:g,quiet:g,verbose:g,format:w,output:v,...X}},ionice:{short:{c:w,n:w,t:g,p:v,P:v,u:v,h:v,V:v},long:{class:w,classdata:w,ignore:g,pid:v,pgid:v,uid:v,...X}},setsid:{short:{c:g,f:g,w:g,h:v,V:v},long:{ctty:g,fork:g,wait:g,...X}}},Yr=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function Qr(e,r,t){let n=!1,s=(i)=>{if(!i||i.effect==="refuse")return!1;if(i.effect==="lookup")n=!0;return!0};while(t<r.length){let i=r[t];if(i.opaque)return null;let o=i.text;if(o==="--"){t++;break}if(o==="-"&&e.env){t++;continue}if(!o.startsWith("-")||o==="-")break;if(e.numericOption&&/^-[-+]?\d+$/.test(o)){t++;continue}if(o.startsWith("--")){let a=o.indexOf("="),l=a<0?o.slice(2):o.slice(2,a),u=Object.keys(e.long),c=u.includes(l)?[l]:u.filter((d)=>l&&d.startsWith(l));if(c.length!==1)return null;let f=e.long[c[0]];if(!s(f))return null;if(f.arg==="none"&&a>=0)return null;if(f.arg==="value"&&a<0){let d=r[++t];if(!d||d.opaque)return null}t++;continue}for(let a=1;a<o.length;a++){let l=e.short[o[a]];if(!s(l))return null;if(l.arg==="value"){if(a===o.length-1){let u=r[++t];if(!u||u.opaque)return null}break}}t++}if(n)return-1;for(let i of e.positionals??[]){let o=r[t];if(!o||o.opaque||!i.test(o.text))return null;t++}if(e.env||e.assignments){for(;t<r.length&&We.test(r[t].text);t++)if(r[t].opaque)return null}return t}function se(e,r=_t){let t=0;while(t<e.length&&(We.test(e[t].text)||Yr.has(e[t].text)))t++;for(let n=0;n<16;n++){if(t>=e.length)return{index:-1};if(e[t].opaque)return n===0?{index:t}:null;let s=Object.hasOwn(r,z(e[t].text))?r[z(e[t].text)]:void 0;if(!s)return{index:t};let i=Qr(s,e,t+1);if(i===null)return null;if(i<0)return{index:-1};t=i}return null}function Jr(e){return/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred|trash)(?![A-Za-z0-9_.-])/.test(e)}var Y={on:!1};function ie(e,r){if(!e.includes("\\")||!e.includes('"'))return;let t=Y.on;Y.on=!0;try{return r()}finally{Y.on=t}}var Rt=(e)=>e.split("/").pop()??"",Ot={perl:{letters:new Set(["e","E"]),long:new Set},python:{letters:new Set(["c"]),long:new Set},python2:{letters:new Set(["c"]),long:new Set},python3:{letters:new Set(["c"]),long:new Set},ruby:{letters:new Set(["e"]),long:new Set},node:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},nodejs:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},bun:{letters:new Set(["e"]),long:new Set(["--eval"])},deno:{letters:new Set(["e"]),long:new Set(["--eval"])},php:{letters:new Set(["r"]),long:new Set},lua:{letters:new Set(["e"]),long:new Set},luajit:{letters:new Set(["e"]),long:new Set},Rscript:{letters:new Set(["e"]),long:new Set}},En=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,es=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),ts=new Set(["ssh","scp","sftp"]),ns=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),kn=new Set(["proxycommand","localcommand","knownhostscommand"]),rs=/(?:`|\$\()|\b(?:system|exec|execve|execvp|popen|spawn|posix_spawn|fork|subprocess|Popen|check_output|check_call|shell_exec|passthru|proc_open|pcntl_exec|qx|open|fopen|sysopen|unlink|remove|delete|rmtree|rmdir|mkdir|rename|truncate|ftruncate|chmod|chown|symlink|writeFile|createWriteStream|appendFile|child_process|FileUtils|shutil|Kernel|require|import|load|eval|os|sys|io|fs|File|IO|Dir|Path|pathlib|Deno|Bun)|%x\W/,ss=/[|>]|\b(?:system|getline|close|fflush|print\w*\s*>>?)/;function On(e){if(Jr(e.text))return!1;if(e.kind==="awk")return!ss.test(e.text);if(e.kind==="c-interp")return!rs.test(e.text);return!1}function is(e,r,t,n){let s=Ot[e]??(En.test(e)?Ot[e.replace(/[0-9.]+$/,"")]:void 0);if(!s)return null;let i=[],o=!1,a=(l)=>{if(l+1>=r.length||n(l+1))return o=!0,l;return i.push({text:r[l+1],kind:"c-interp"}),l+1};for(let l=t+1;l<r.length;l++){let u=r[l];if(u==="--")break;if(!u.startsWith("-")||u==="-")break;if(u.startsWith("--")){let f=u.indexOf("="),d=f<0?u:u.slice(0,f);if(s.long.has(d))if(f>=0)i.push({text:u.slice(f+1),kind:"c-interp"});else l=a(l);continue}let c=u.slice(1);for(let f=0;f<c.length;f++){if(!s.letters.has(c[f]))continue;if(f<c.length-1)i.push({text:c.slice(f+1),kind:"c-interp"});else l=a(l);break}}if(i.length===0&&!o)return null;return{programs:i,unresolved:o}}function os(e,r,t){let n=r+1;for(;n<e.length&&e[n].startsWith("-");n++)if(e[n]==="-L"||e[n]==="--log-level")n++;if(e[n]!=="eval"||t(n))return null;let s=[],i=!1;for(n++;n<e.length;n++){if(t(n)){i=!0;continue}if(!e[n].startsWith("-"))s.push({text:e[n],kind:"c-interp"})}return s.length===0&&!i?null:{programs:s,unresolved:i}}function ls(e,r,t){let n=[],s=!1,i=r+1;for(;i<e.length;i++){let o=e[i];if(o==="--"){i++;break}if(!o.startsWith("-")||o==="-")break;if(o==="-e"||o.startsWith("-e")){let a=o==="-e"?null:o.slice(2);if(a!==null)n.push({text:a,kind:"awk"});else if(i+1<e.length&&!t(i+1))n.push({text:e[++i],kind:"awk"});else s=!0}else if(o==="-f"||o.startsWith("-f")){if(s=!0,o==="-f")i++}else if(o==="-v"||o.startsWith("-v")){if(o==="-v")i++}}if(n.length===0&&!s){if(i<e.length)if(t(i))s=!0;else n.push({text:e[i],kind:"awk"})}return{programs:n,unresolved:s}}function as(e,r,t){let n=e[r],s,i=r;if(n==="-o"){if(r+1>=e.length)return{value:null,next:r};if(t(r+1))return{value:null,next:r+1};s=e[r+1],i=r+1}else s=n.slice(2);return{value:s,next:i}}function us(e,r,t){let n=[],s=!1;for(let i=r+1;i<e.length;i++){let o=e[i];if(o==="--")break;if(!o.startsWith("-")||o==="-")break;if(o.startsWith("--"))continue;if(o==="-o"||o.startsWith("-o")){let{value:l,next:u}=as(e,i,t);if(i=u,l===null){s=!0;continue}let c=l.indexOf("="),f=c>=0?c:l.search(/\s/),d=(f>=0?l.slice(0,f):l).trim().toLowerCase(),h=f>=0?l.slice(f+1).trim():"";if(kn.has(d))n.push({text:h,kind:"shell"});continue}if(o==="-F"||o.startsWith("-F")){if(s=!0,o==="-F")i++;continue}if(o==="-S"||o.startsWith("-S")){let l=o==="-S"?i+1<e.length&&!t(i+1)?e[++i]:null:o.slice(2);if(l===null)s=!0;else n.push({text:l,kind:"shell"});continue}let a=o.slice(1);for(let l=0;l<a.length;l++){if(!ns.has(a[l]))continue;if(l<a.length-1)break;if(a[l]==="o"||a[l]==="F"||a[l]==="S"){if(i+1<e.length){let u=e[i+1];if(a[l]==="o")if(!t(i+1)){let c=u.indexOf("="),f=c>=0?c:u.search(/\s/),d=(f>=0?u.slice(0,f):u).trim().toLowerCase();if(kn.has(d))n.push({text:f>=0?u.slice(f+1).trim():"",kind:"shell"})}else s=!0;else if(a[l]==="F")s=!0;else if(!t(i+1))n.push({text:u,kind:"shell"});i++}}else if(i+1<e.length)i++}}return{programs:n,unresolved:s}}function cs(e,r,t){let n=[],s=!1,i=!1;for(let o=r+1;o<e.length;o++){let a=e[o];if(a==="--")break;if(a==="-e"||a==="--rsh")if(i=!0,o+1<e.length&&!t(o+1))n.push({text:e[++o],kind:"shell"});else s=!0;else if(a.startsWith("--rsh="))i=!0,n.push({text:a.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(a)&&a.length>2&&!a.startsWith("--"))i=!0,n.push({text:a.slice(a.indexOf("e")+1),kind:"shell"})}return i?{programs:n,unresolved:s}:null}var fs=/^(?:true|false|yes|no|on|off|1|0|)$/i,ds=[/^core\.(?:pager|editor|sshcommand|askpass|alternaterefscommand)$/,/^sequence\.editor$/,/^diff\.external$/,/^interactive\.difffilter$/,/^imap\.tunnel$/,/^gc\.recentobjectshook$/,/^gpg\.program$/,/^gpg\.ssh\.defaultkeycommand$/,/^uploadpack\.packobjectshook$/,/^instaweb\.(?:browser|httpd)$/,/^credential\.(?:.+\.)?helper$/,/^diff\..+\.(?:command|textconv)$/,/^(?:difftool|mergetool|man|browser)\..+\.(?:cmd|path)$/,/^guitool\..+\.cmd$/,/^merge\..+\.driver$/,/^gpg\..+\.program$/,/^remote\..+\.(?:uploadpack|receivepack)$/,/^filter\..+\.(?:clean|smudge|process)$/,/^tar\..+\.command$/,/^trailer\..+\.(?:cmd|command)$/,/^sendemail\.(?:.+\.)?(?:tocmd|cccmd|headercmd|sendmailcmd)$/];function Rn(e,r){let t=e.toLowerCase(),n=(s)=>s===void 0?{kind:"unresolved"}:{kind:"command",text:s};if(/^alias\./.test(t))return r!==void 0&&r.trimStart().startsWith("!")?n(r.trimStart().slice(1)):{kind:"unresolved"};if(/^pager\./.test(t)||t==="core.fsmonitor")return r!==void 0&&fs.test(r)?{kind:"harmless"}:n(r);if(t==="core.gitproxy")return r!==void 0&&/^none(?:\s+for\s+\S+)?$/.test(r)?{kind:"harmless"}:n(r?.replace(/\s+for\s+\S+$/,""));if(/^submodule\..+\.update$/.test(t))return r!==void 0&&r.trimStart().startsWith("!")?n(r.trimStart().slice(1)):r===void 0?{kind:"unresolved"}:{kind:"harmless"};if(/^sendemail\.(?:.+\.)?smtpserver$/.test(t))return r!==void 0&&!r.startsWith("/")?{kind:"harmless"}:n(r);if(/^credential\.(?:.+\.)?helper$/.test(t)){if(r==="")return{kind:"harmless"};if(r===void 0)return{kind:"unresolved"};let s=r.trimStart();return n(s.startsWith("!")?s.slice(1):s.startsWith("/")?s:`git credential-${s}`)}if(ds.some((s)=>s.test(t)))return n(r);if(t==="core.hookspath")return r==="/dev/null"?{kind:"harmless"}:{kind:"unresolved"};if(t==="include.path"||/^includeif\..+\.path$/.test(t))return{kind:"unresolved"};if(t==="protocol.allow")return r!==void 0&&/^(?:never|user)$/i.test(r)?{kind:"harmless"}:{kind:"unresolved"};if(t==="protocol.ext.allow")return r!==void 0&&/^never$/i.test(r)?{kind:"harmless"}:{kind:"unresolved"};return{kind:"harmless"}}function vn(e){return/[$\x60]/.test(e)||["","x","/x","!x"].some((r)=>Rn(e,r).kind!=="harmless")}var hs=new Set(["GIT_PAGER","GIT_EDITOR","GIT_SEQUENCE_EDITOR","GIT_EXTERNAL_DIFF","GIT_SSH","GIT_SSH_COMMAND","GIT_ASKPASS","SSH_ASKPASS","GIT_PROXY_COMMAND","PAGER","EDITOR","VISUAL"]),ps=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function gs(e){let r=/'((?:[^']|'\\'')*)'/y,t=(i)=>i.replace(/'\\''/g,"'"),n=[],s=0;while(s<e.length){if(/\s/.test(e[s])){s++;continue}r.lastIndex=s;let i=r.exec(e);if(!i)return null;if(s=r.lastIndex,e[s]==="="){r.lastIndex=s+1;let o=r.exec(e);if(!o)return null;s=r.lastIndex,n.push([t(i[1]),t(o[1])])}else{let o=t(i[1]),a=o.indexOf("=");n.push(a<0?[o,void 0]:[o.slice(0,a),o.slice(a+1)])}}return n}function ms(e,r,t){let n=[],s=!1,i=(u,c,f=!0)=>{if(!f||/[$\x60]/.test(u)){s=!0;return}let d=Rn(u,c);if(d.kind==="unresolved")s=!0;else if(d.kind==="command")n.push({text:d.text,kind:"shell"})},o=(u,c)=>{let f=u.indexOf("="),d=f<0?u:u.slice(0,f),h=f<0?"true":u.slice(f+1);if(!c)return i(d,h);if(vn(d))s=!0},a=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let u=r+1;u<e.length;u++){let c=e[u];if(!c.startsWith("-")||c==="-")break;if(c==="--")break;if(c==="-c"){if(u+1>=e.length)break;o(e[u+1],t(u+1)),u++}else if(c.startsWith("-c")&&!c.startsWith("--"))o(c.slice(2),t(u));else if(c==="--config-env"||c.startsWith("--config-env=")){let f=c==="--config-env"?e[++u]??"":c.slice(13),d=f.indexOf("="),h=d<0?f:f.slice(0,d);if(t(u)||vn(h))s=!0}else if(c.startsWith("--exec-path="))s=!0;else if(a.has(c))u++}let l=new Map;for(let u=0;u<r;u++){let c=e[u].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!c)continue;let[,f,d]=c,h=t(u);if(hs.has(f))if(h)s=!0;else n.push({text:d,kind:"shell"});else if(ps.has(f)){if(h||d!=="/dev/null"||f==="GIT_EXEC_PATH"||f==="GIT_TEMPLATE_DIR")s=!0}else if(f==="GIT_ALLOW_PROTOCOL"){if(h||d.split(":").includes("ext"))s=!0}else if(f==="GIT_CONFIG_PARAMETERS"){let p=h?null:gs(d);if(p===null)s=!0;else for(let[m,O]of p)i(m,O??"true")}else if(/^GIT_CONFIG_(?:KEY|VALUE)_\d+$/.test(f)){let p=f.replace(/^GIT_CONFIG_(?:KEY|VALUE)_/,""),m=l.get(p)??{};if(f.startsWith("GIT_CONFIG_KEY_"))m.key=d;else m.value=d;if(h)m.opaque=!0;l.set(p,m)}}for(let u of l.values()){if(u.key===void 0)continue;if(u.opaque)o(`${u.key}=`,!0);else i(u.key,u.value)}if(n.length===0&&!s)return null;return{programs:n,unresolved:s}}function Ne(e){if(/^~/.test(e))return null;let r="";for(let t=0;t<e.length;t++){let n=e[t];if(n==="'"){let s=e.indexOf("'",t+1);if(s<0)return null;r+=e.slice(t+1,s),t=s}else if(n==="$"||n==="`")return null;else if(n==='"'){let s=t+1;for(;s<e.length&&e[s]!=='"';s++){let i=e[s];if(i==="$"||i==="`")return null;if(i==="\\"&&s+1<e.length&&/[$\x60"\\\n]/.test(e[s+1])){if(e[++s]!==`
4
+ `||Y.on)r+=e[s];continue}r+=i}if(s>=e.length)return null;t=s}else if(n==="\\"){if(t+1>=e.length)return null;r+=e[++t]}else if("*?[{}".includes(n))return null;else r+=n}return r}function _n(e){let r=null;for(let t=0;t<e.length;t++){let n=e[t];if(r==="'"){if(n==="'")r=null;continue}if(n==="\\"){t++;continue}if(n==="$"||n==="`")return!1;if(r==='"'){if(n==='"')r=null;continue}if(n==="'"||n==='"'){r=n;continue}if(n==="<"&&e[t+1]==="<"&&e[t+2]!=="<")return!1}return r===null}var bs=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]),Ss=new Set(["--rcfile","--init-file"]),pe=(e)=>e.replace(/\$'(?:[^'\\]|\\[\s\S])*'/g,(r)=>r.replace(/\\[\s\S]/g,(t)=>t==="\\'"?"\\x27":t));function Le(e,r,t=Ne){if(r<0||r>=e.length)return null;let n=Rt(t(e[r])??"");if(n==="eval"){let a=r+1;if(Ne(e[a]??"")==="--")a++;let l=e.slice(a);if(l.length===0)return null;if(l.length>1)return{program:null,literal:!1};let u=Ne(l[0]);return u!==null&&_n(u)?{program:u,literal:!0}:{program:u,literal:!1}}if(!bs.has(n))return null;let s=!1,i=r+1;for(;i<e.length;i++){let a=Ne(e[i]);if(a===null){if(s)break;return/^"[^"]*"$/.test(e[i])?null:{program:null,literal:!1}}if(a==="--"){i++;break}if(!/^[-+]./.test(a))break;if(a.startsWith("--")){if(Ss.has(a))i++;continue}let l=a.slice(1);if(a[0]==="-"&&l.includes("c"))s=!0;if(/[oO]/.test(l))i++}if(!s||i>=e.length)return null;let o=Ne(e[i]);return o!==null&&_n(o)?{program:o,literal:!0}:{program:o,literal:!1}}function ws(e,r,t){let n=ys(e,r,t);if(n===null)return{programs:[],unresolved:!0};let s=new Set;for(let{scripts:i,mayFail:o}of n){let a=xs(i.join(`
5
+ `));if(a===null){if(o)continue;return{programs:[],unresolved:!0}}if(a.executes)return{programs:i.map((l)=>({text:l,kind:"shell"})),unresolved:!0};for(let l of a.writes)s.add(l)}if(s.size===0)return null;return{programs:[],unresolved:!1,writes:[...s]}}var Et="quiet silent debug follow-symlinks posix regexp-extended separate sandbox unbuffered null-data zero-terminated binary help version in-place file expression line-length".split(" ");function ys(e,r,t){let n=[],s=[],i=!1,o=-1,a=!1,l=!1;for(let f=r+1;f<e.length;f++){let d=e[f];if(l||!/^-./.test(d)){s.push(f);continue}if(t(f))return null;if(d==="--"){l=!0;continue}let h,p;if(d[1]==="-"){let m=d.indexOf("="),O=(m<0?d:d.slice(0,m)).slice(2),A=Et.filter((j)=>j.startsWith(O)),I=Et.includes(O)?O:A.length===1?A[0]:"";if(Et.indexOf(I)<15){if(!I)return null;continue}if(h=I[0],m>=0)p=d.slice(m+1)}else{let m=1;while("nrEsuzb".includes(d[m]??"_"))m++;if(h=d[m]??"",h==="i"||h==="I"){let O=m===d.length-1&&f+1<e.length&&!t(f+1)?e[f+1]:void 0;if(h==="I"){if(a=i=!0,m===d.length-1){if(O===void 0)return null;o=f+1}}else if(O===""||O?.startsWith("."))i=!0,o=f+1;continue}if(h==="")continue;if(!"efl".includes(h))return null;p=d.slice(m+1)||void 0}if(h==="f")return null;if(p===void 0){if(p=e[++f],p===void 0||t(f))return null}if(h==="e")n.push(p)}let u=(f)=>{if(n.length>0)return n;let d=s.find((h)=>h!==f);return d===void 0?[]:t(d)?null:[e[d]]},c=[];if(!a)c.push({scripts:u(-1),mayFail:o>=0&&n.length===0&&s[0]===o});if(i)c.push({scripts:u(o),mayFail:!1});return c.some((f)=>f.scripts===null)?null:c}function xs(e){let r=[],t=!1,n=0,s=e.length,i=()=>e[n]??"",o=()=>{while(i()===" "||i()==="\t")n++;let u=n,c=e.indexOf(`
6
+ `,n);return n=c<0?s:c,e.slice(u,n)},a=()=>{let u=o();if(u&&!/^\/dev\/std(?:out|err)$/.test(u))r.push(u)},l=(u,c)=>{for(;n<s;n++){let f=e[n];if(f===`
7
+ `)return!1;if(f==="\\"){if(++n>=s)return!1}else if(f===u)return n++,!0;else if(c&&f==="["){let d=n+1;if(e[d]==="^")d++;if(e[d]==="]")d++;for(;e[d]!=="]";d++){if(d>=s||e[d]===`
8
+ `)return!1;if(e[d]==="["&&":.=".includes(e[d+1]||`
9
+ `)){let h=e.indexOf(e[d+1]+"]",d+2);if(h<0||e.slice(d,h).includes(`
10
+ `))return!1;d=h+1}}n=d}}return!1};while(n<s){let u=e[n++];if(u==="/"||u==="\\"){let c=u==="\\"?e[n++]??"":"/";if(!c||c===`
11
+ `||!l(c,!0))return null}else if(u==="#")o();else if(":btTv".includes(u)){while(i()===" "||i()==="\t")n++;while(n<s&&!/[\s;]/.test(i()))n++}else if("aic".includes(u)){while(i()===" "||i()==="\t")n++;if(i()==="\\")n+=2;for(;n<s&&e[n]!==`
12
+ `;n++)if(e[n]==="\\")n++}else if(u==="e")t=!0,o();else if(u==="r"||u==="R")o();else if(u==="w"||u==="W")a();else if(u==="s"||u==="y"){let c=e[n++]??"";if(!c||c===`
13
+ `||c==="\\"||!l(c,u==="s")||!l(c,!1))return null;for(;u==="s"&&" \tgpiImMe0123456789w".includes(i()||"_");n++){if(i()==="e")t=!0;if(i()==="w"){n++,a();break}}}}return{writes:r,executes:t}}var ks=new Set(["-exec","-execdir","-ok","-okdir"]),vs=new Set(["-exec","-execdir"]),_s=new Set("0oprtx"),Es=new Set("adEILnPsJRS"),Os=new Set("eil"),et={"--null":"flag","--open-tty":"flag","--interactive":"flag","--no-run-if-empty":"flag","--verbose":"flag","--exit":"flag","--show-limits":"flag","--help":"flag","--version":"flag","--arg-file":"value","--delimiter":"value","--max-args":"value","--max-procs":"value","--max-chars":"value","--process-slot-var":"value","--max-lines":"value","--eof":"optional","--replace":"optional"};function Rs(e){if(Object.hasOwn(et,e))return et[e];let r=Object.keys(et).filter((t)=>t.startsWith(e));return r.length===1?et[r[0]]:null}function De(e,r,t,n=0){while(r<e.length){if(t(r)){r++;continue}let s=e[r];if(s==="--"){r++;break}if(!s.startsWith("-")||s==="-")break;if(s.startsWith("--")){let a=s.indexOf("="),l=Rs(a<0?s:s.slice(0,a));if(l===null){if(n>=4)return[];return[...De(e,r+1,t,n+1),...De(e,r+2,t,n+1)]}r+=l==="value"&&a<0?2:1;continue}let i=!1,o=!1;for(let a=1;a<s.length;a++){let l=s[a];if(_s.has(l))continue;if(Os.has(l))break;if(Es.has(l)){i=a===s.length-1;break}o=!0;break}if(o){if(n>=4)return[];return[...De(e,r+1,t,n+1),...De(e,r+2,t,n+1)]}r+=i?2:1}while(r<e.length&&t(r))r++;return r<e.length?[r]:[]}function He(e,r,t=()=>!1){if(r<0||r>=e.length)return[];let n=Rt(e[r]);if(n==="xargs")return[...new Set(De(e,r+1,t))].map((i)=>({start:i,end:e.length}));if(n!=="find")return[];let s=[];for(let i=r+1;i<e.length;i++){if(t(i)||!ks.has(e[i]))continue;let o=i+1,a=o;for(;a<e.length;a++){if(t(a))continue;if(e[a]===";")break;if(e[a]==="+"&&a>o&&e[a-1]==="{}"&&vs.has(e[i]))break}if(o<a)s.push({start:o,end:a});i=a}return s}function Me(e,r,t){if(r<0||r>=e.length)return null;let n=Rt(e[r]);if(n==="deno"){let s=os(e,r,t);if(s)return s}if(Object.hasOwn(Ot,n)||En.test(n))return is(n,e,r,t);if(es.has(n))return ls(e,r,t);if(ts.has(n))return us(e,r,t);if(n==="rsync")return cs(e,r,t);if(n==="git")return ms(e,r,t);if(n==="sed")return ws(e,r,t);return null}var Ps=600000,Is="Delete via trash guard (rm intercepted and made recoverable)",Ws=[".hasna/repos/clones","workspace/repos"],Ns=[".hasna",".ssh",".aws"],At={rmdir:"`rmdir` is a delete that trash-guard does not rewrite (it takes rmdir's flags, not rm's). Re-run it as `rm -d -- <path>` for an empty directory, or `rm -r -- <path>` for a non-empty one, and it is redirected into trash.",unlink:"`unlink` is a delete that trash-guard does not rewrite. Re-run it as `rm -- <path>` and it is redirected into trash.",shred:"`shred` destroys content irrecoverably and is never allowed. Re-run it as `rm -- <path>` and it is redirected into trash."},Ds=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env"]),Ls={sudo:["-u","--user","-g","--group","-p","--prompt","-C","--chdir","-h","--host","-r","--role","-t","--type","-U","--other-user"],doas:["-u","-C"],env:["-u","--unset","-C","--chdir","-S","--split-string"],nice:["-n","--adjustment"],ionice:["-c","--class","-n","--classdata","-p","--pid"],stdbuf:["-i","-o","-e","--input","--output","--error"],time:["-f","--format","-o","--output"],timeout:["-s","--signal","-k","--kill-after"],nohup:[],setsid:[],command:[],builtin:[],exec:["-a"]},Hs={timeout:1},Ms={sudo:{short:{A:g,B:g,b:g,E:g,H:g,i:g,k:g,N:g,n:g,P:g,S:g,s:g,C:w,g:w,p:w,r:w,T:w,t:w,U:w,u:w,e:Z,l:Z,v:Z,D:v,R:v,h:v,K:v,V:v},long:{askpass:g,bell:g,background:g,"close-from":w,chdir:v,"preserve-env":Ie,edit:Z,group:w,"set-home":g,help:v,host:v,login:g,"remove-timestamp":v,"reset-timestamp":g,list:Z,"no-update":g,"non-interactive":g,"preserve-groups":g,prompt:w,chroot:v,role:w,stdin:g,shell:g,type:w,"command-timeout":w,"other-user":w,user:w,version:v,validate:Z},assignments:!0},doas:{short:{n:g,s:g,u:w,C:v,L:v},long:{}},flock:{short:{s:g,x:g,e:g,n:g,u:g,o:g,F:g,w,E:w,h:v,V:v},long:{shared:g,exclusive:g,unlock:g,nonblock:g,nonblocking:g,nb:g,timeout:w,wait:w,"conflict-exit-code":w,close:g,"no-fork":g,fcntl:g,verbose:g,help:v,version:v},positionals:[/^[\s\S]+$/]}},Fs={..._t,...Ms},Ln=new Set(["-c","--command"]),Bs=new Set(["busybox","toybox"]),Pt=new Set(["rm","rmdir","unlink","shred"]),js=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]),Gs=new Set(["-C","-c","--git-dir","--work-tree","--namespace","--exec-path","--config-env"]),qs=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/;function U(e){return qs.test(T(e))}function Be(e){return e.map((r)=>r.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var Hn=/^[A-Za-z_][A-Za-z0-9_]*=/;function nt(e){let r=e.lastIndexOf("/");return r>=0?e.slice(r+1):e}var An={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
14
+ `,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function zs(e,r){let t="",n=r;while(n<e.length&&e[n]!=="'"){if(e[n]!=="\\"||n+1>=e.length){t+=e[n++];continue}let s=e[n+1],i=e.slice(n+1),o;if(Object.hasOwn(An,s))t+=An[s],n+=2;else if(o=i.match(/^[0-7]{1,3}/))t+=String.fromCharCode(parseInt(o[0],8)&255),n+=1+o[0].length;else if((o=i.match(/^x([0-9A-Fa-f]{1,2})/))||(o=i.match(/^u([0-9A-Fa-f]{1,4})/))||(o=i.match(/^U([0-9A-Fa-f]{1,8})/))){let a=parseInt(o[1],16);t+=a<=1114111?String.fromCodePoint(a):"",n+=1+o[0].length}else if(s==="c"&&n+2<e.length)t+=String.fromCharCode(e.charCodeAt(n+2)&31),n+=3;else t+=`\\${s}`,n+=2}return{text:t,end:Math.min(n+1,e.length)}}function C(e){return Mn(e,!0)}function Mn(e,r){let t="",n=0;while(n<e.length){let s=e[n];if(r&&s==="$"&&e[n+1]==="'"){let i=zs(e,n+2);t+=i.text,n=i.end;continue}if(r&&s==="$"&&e[n+1]==='"'){n++;continue}if(s==="\\"){if(n+1<e.length)t+=e[n+1];n+=2;continue}if(s==="'"){let i=e.indexOf("'",n+1);if(i===-1){t+=e.slice(n+1);break}t+=e.slice(n+1,i),n=i+1;continue}if(s==='"'){n++;while(n<e.length&&e[n]!=='"'){if(e[n]==="\\"&&n+1<e.length){let i=e[n+1];t+=Y.on||/[$`"\\]/.test(i)?i:i===`
15
+ `?"":`\\${i}`,n+=2;continue}t+=e[n],n++}n++;continue}t+=s,n++}return t}function rt(e){if(Je(e))return!0;let r=null;for(let t=0;t<e.length;t++){let n=e[t];if(r==="'"){if(n==="'")r=null;continue}if(n==="\\"){t++;continue}if(n==="`"||n==="$")return!0;if(n==='"'){r=r===null?'"':null;continue}if(r!==null)continue;if(n==="'")r="'";else if(n==="*"||n==="?")return!0;else if(n==="["&&Us(e,t+1,"]"))return!0}return!1}function Us(e,r,t){let n=null;for(let s=r;s<e.length;s++){let i=e[s];if(n!=="'"&&i==="\\")s++;else if(n===null&&i===t)return!0;else if(i==="'"&&n!=='"')n=n==="'"?null:"'";else if(i==='"'&&n!=="'")n=n==='"'?null:'"'}return!1}function Vs(e){if(!rt(e))return!1;let r=re(e);return r===null||r.some((t)=>C(t).split(/[^A-Za-z0-9_]+/).some((n)=>Pt.has(n)))}function be(e){return nt(C(e))}var Fn={deep:!0};function It(e,r){return e.replace(/\\([$`\\"])/g,(t,n)=>n==='"'&&!r?t:n)}function Zs(e,r,t){let n=[],s=r+1;while(s<t-1){let i=e[s];if(i==="\\"){s+=2;continue}if(i==="`"){let o=je(e,s);if(o<0)return null;n.push(It(e.slice(s+1,o-1),!0)),s=o;continue}if(i==="$"&&e[s+1]==="("){let o=oe(e,s+1);if(o<0)return null;n.push(e.slice(s+2,o-1)),s=o;continue}s++}return n}function Ks(e){let r=[],t=0;while(t<e.length){let n=e[t];if(n==="\\"){t+=2;continue}if(n==="`"){let s=je(e,t);if(s<0)return null;r.push(It(e.slice(t+1,s-1),!1)),t=s;continue}if(n==="$"&&e[t+1]==="("){let s=oe(e,t+1);if(s<0)return null;r.push(e.slice(t+2,s-1)),t=s;continue}t++}return r}function Tn(e,r,t,n){let s=r+1;for(let i of t){let o=Math.min(s,e.length);for(;;){if(s>e.length){s=e.length+1;break}let l=e.indexOf(`
16
+ `,s),u=l===-1?e.length:l,c=e.slice(s,u).replace(/\r$/,"");if(i.stripTabs)c=c.replace(/^\t+/,"");if(c===i.delimiter)break;s=u+1}let a=e.slice(o,Math.min(s,e.length));if(i.owner.push(a),!i.quoted){let l=Ks(a);if(!l)return-1;n.push(...l)}if(s<=e.length){let l=e.indexOf(`
17
+ `,s);s=(l===-1?e.length:l)+1}}return Math.min(s-1,e.length)}function Bn(e,r){let t=e.indexOf("'",r+1);return t===-1?-1:t+1}function je(e,r){let t=r+1;while(t<e.length){if(e[t]==="\\"){t+=2;continue}if(e[t]==="`")return t+1;t++}return-1}function jn(e,r){let t=r+1;while(t<e.length){let n=e[t];if(n==="\\"){t+=2;continue}if(n==='"')return t+1;if(n==="`"){let s=je(e,t);if(s<0)return-1;t=s;continue}if(n==="$"&&e[t+1]==="("){let s=oe(e,t+1);if(s<0)return-1;t=s;continue}t++}return-1}function we(e,r){if(e[r]!=="<"||e[r+1]!=="<"||e[r+2]==="<")return null;let t=r+2,n=e[t]==="-";if(n)t++;while(e[t]===" "||e[t]==="\t")t++;let s="",i=!1;while(t<e.length&&!/[\s;|&<>()]/.test(e[t])){let o=e[t];if(o==="'"||o==='"'){let a=e.indexOf(o,t+1);if(a<0)return null;s+=e.slice(t+1,a),i=!0,t=a+1;continue}if(o==="\\"){if(t+1>=e.length)return null;s+=e[t+1],i=!0,t+=2;continue}s+=o,t++}return s?{delimiter:s,stripTabs:n,quoted:i,end:t}:null}function st(e,r,t){let n=r+1;for(let s of t)for(;;){if(n>e.length)return-1;let i=e.indexOf(`
18
+ `,n),o=i===-1?e.length:i,a=e.slice(n,o);if(a.endsWith("\r"))a=a.slice(0,-1);let l=s.stripTabs?a.length-a.replace(/^\t+/,"").length:0;if(s.stripTabs)a=a.slice(l);if(a===s.delimiter){n=o+1;break}if(a.startsWith(s.delimiter)&&/^\s*\)/.test(a.slice(s.delimiter.length))){if(s===t[t.length-1])return n+l+s.delimiter.length;return-1}if(i===-1)return-1;n=i+1}return n-1}function oe(e,r){let t=e.length,n=e[r+1]==="(",s=0,i=r,o=[];while(i<t){let a=e[i];if(a==="\\"){i+=2;continue}if(a==="'"){let l=Bn(e,i);if(l<0)return-1;i=l;continue}if(a==='"'){let l=jn(e,i);if(l<0)return-1;i=l;continue}if(a==="`"){let l=je(e,i);if(l<0)return-1;i=l;continue}if(!n&&a==="<"&&e[i+1]==="<"){if(e[i+2]==="<"){i+=3;continue}let l=we(e,i);if(!l)return-1;o.push(l),i=l.end;continue}if(a===`
19
+ `&&o.length>0){let l=st(e,i,o);if(l<0)return-1;o=[],i=l;continue}if(!n&&a==="#"&&/[\s;&|(]/.test(e[i-1])){let l=e.indexOf(`
20
+ `,i);if(l<0)return-1;i=l;continue}if(a==="(")s++;else if(a===")"){if(s--,s===0)return o.length>0?-1:i+1}i++}return-1}function P(e,r={}){let t=r.deep===!0,n=[],s=[],i=[],o=new Set,a=[],l=[],u=-1,c=!1,f=!0,d=0,h=e.length,p=(k)=>{if(u>=0){let b=i.length;if(i.push({text:e.slice(u,k),start:u,end:k}),c)o.add(b);u=-1,c=!1}},m=(k)=>{if(p(k),i.length>0)n.push(t?{words:i,redirects:o,heredocs:a}:{words:i,redirects:o});if(i=[],o=new Set,t)a=[];c=!1},O=(k)=>Bn(e,k),A=(k)=>je(e,k),I=(k)=>oe(e,k),j=(k)=>jn(e,k);while(d<h){let k=e[d];if(k===" "||k==="\t"||k==="\r"){p(d),d++;continue}if(k===`
21
+ `){if(m(d),l.length>0){let b=Tn(e,d,l,s);if(l=[],b<0)f=!1,d=h;else d=b;continue}d++;continue}if(k===";"){m(d),d++;continue}if(k==="&"){m(d),d+=e[d+1]==="&"?2:1;continue}if(k==="|"){m(d),d+=e[d+1]==="|"?2:1;continue}if(t&&k==="("&&u>=0&&"?*+@!".includes(e[d-1])){f=!1,d=h;continue}if(k==="("||k===")"){m(d),d++;continue}if(k==="<"&&e[d+1]==="<"&&e[d+2]!=="<"){let b=e.slice(d+2).match(/^-?[ \t]*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/);if(!b){f=!1,d=h;continue}if(t){let _e=d+2+b[0].length;if(_e<h&&!/[\s;&|()<>]/.test(e[_e])){f=!1,d=h;continue}p(d),l.push({delimiter:b[2],quoted:b[1]!=="",stripTabs:b[0].startsWith("-"),owner:a}),d=_e;continue}let R=e.indexOf(`
22
+ `,d+2+b[0].length);if(R===-1){f=!1,d=h;continue}let H=e.slice(R+1),M=Xs(H,b[2]);if(M===-1){f=!1,d=h;continue}p(d),d=R+1+M+b[2].length;continue}if(k===">"||k==="<"){if(u>=0&&/^\d+$/.test(e.slice(u,d)))u=-1;if(p(d),c=!0,d++,e[d]===k||e[d]==="&"||k===">"&&e[d]==="|"||k==="<"&&e[d]===">")d++;continue}if(k==="'"){if(u<0)u=d;let b=O(d);if(b<0)f=!1,d=h;else d=b;continue}if(k==='"'){if(u<0)u=d;let b=j(d),R=b<0||!t?[]:Zs(e,d,b);if(b<0||!R)f=!1,d=h;else s.push(...R),d=b;continue}if(k==="`"){if(u<0)u=d;let b=A(d);if(b<0)f=!1,d=h;else{let R=e.slice(d+1,b-1);s.push(t?It(R,!1):R),d=b}continue}if(k==="$"&&e[d+1]==="("){if(u<0)u=d;let b=I(d+1);if(b<0)f=!1,d=h;else s.push(e.slice(d+2,b-1)),d=b;continue}if(k==="\\"){if(u<0)u=d;if(d+1>=h)f=!1,d=h;else d+=2;continue}if(u<0)u=d;d++}if(m(h),l.length>0&&Tn(e,h,l,s)<0)f=!1;return{segments:n,trustworthy:f,substitutions:s}}function Xs(e,r){let t=0;while(t<=e.length){let n=e.indexOf(r,t);if(n===-1)return-1;let s=n===0||e[n-1]===`
23
+ `,i=n+r.length,o=i===e.length||e[i]===`
24
+ `||e[i]==="\r";if(s&&o)return n;t=n+1}return-1}function T(e){return Mn(e,!1)}function L(e){let r=0,t=0;while(r<e.words.length&&t++<32){if(e.redirects.has(r)){r++;continue}let n=e.words[r].text,s=C(n);if(Hn.test(s)&&!s.startsWith("-")){r++;continue}if(js.has(s)){r++;continue}let i=nt(s);if(i==="command")for(let a of e.words.filter((l,u)=>u>r&&!e.redirects.has(u))){let l=C(a.text);if(l==="--"||!l.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(l))return-1}let o=Ls[i];if(o){let a=r;r++;while(r<e.words.length){if(e.redirects.has(r)){r++;continue}let u=C(e.words[r].text);if(!u.startsWith("-")||u==="-")break;if(u==="--"){r++;break}if(i==="env"&&(/^-[iv0]*S/.test(u)||/^--split-string(?:=|$)/.test(u)))return a;if(r++,o.includes(u)||i==="exec"&&/^-[cl]*a$/.test(u)){while(e.redirects.has(r))r++;r++}}let l=Hs[i]??0;while(l>0&&r<e.words.length){let u=C(e.words[r].text);if(u.startsWith("-")&&u!=="-")break;r++,l--}continue}return r}return-1}function Ys(e,r){let t=[],n=!1;for(let s=r+1;s<e.words.length;s++){if(e.redirects.has(s))continue;let i=T(e.words[s].text);if(!n){if(i==="--"){n=!0;continue}if(i.startsWith("-")&&i!=="-")continue}t.push(e.words[s])}return t}function Wt(e){return Ws.map((r)=>me(e,...r.split("/")))}function Qs(e,r){if(e==="~"||e==="$HOME"||e==="${HOME}")return r;if(e.startsWith("~/"))return me(r,e.slice(2));if(e.startsWith("$HOME/"))return me(r,e.slice(6));if(e.startsWith("${HOME}/"))return me(r,e.slice(8));return e}function tt(e,r,t){let n=T(e);if(!n)return null;if(n.includes("`"))return null;if(n==="$HOME"||n==="${HOME}"||n==="$HOME/"||n==="${HOME}/")return t;if(n.replace(/\$\{HOME\}/g,"").replace(/\$HOME/g,"").includes("$"))return null;if(/[*?[\]]/.test(n))return null;if(n.startsWith("~")){let a=Qs(n,t);if(a===n)return null;n=a}let o=(Ts(n)?$s(n):Cs(r,n)).replace(/\/+$/,"");return o===""?"/":o}function Q(e,r){return e===r||e.startsWith(`${r}${Ct}`)}var Js=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/,ei=!1,ti=/^[A-Za-z0-9._@+-]{1,128}$/,ni=512;function ge(e){return`'${e.replace(/[\u0000-\u001f\u007f-\u009f]/g,"?").slice(0,ni).replace(/'/g,"'\\''")}'`}function $n(e){return ti.test(e)?`\`${e}\``:"a name that is not a plain identifier"}function ri(e,r){let t=`${me(r,".hasna","scratchpad","scratch")}${Ct}`;if(!e.startsWith(t))return null;let[n,s]=e.slice(t.length).split(Ct);if(!n)return{content:!1,reason:"the scratch root itself holds every session, not one session's content"};if(n.endsWith(".")||!Js.test(n))return{content:!1,reason:`${$n(n)} is not a session id this carve-out accepts (real ids are mixed case, e.g. \`ses_ebbb3f564ffe7PDf32UBmlNI3v\`)`};if(!s)return ei?{content:!0}:{content:!1,reason:`${$n(n)} is a session root; removing it would also remove its \`meta.json\` and \`.lock\` control files, and whether the root itself is scratch is an open decision (Todos 264c4be0) \u2014 remove specific children instead`};let i=s.normalize("NFKC").toLowerCase();if(i==="meta.json"||i===".lock")return{content:!1,reason:`\`${i}\` is session control state, not scratch`};return{content:!0}}function si(e,r){if(e===r)return`${ge(e)} is the home directory itself, which is never deleted or trashed. Delete a specific file or directory inside it instead.`;for(let t of yn){if(e!==t&&!Q(t,e))continue;return t==="/"?`${ge(e)} is the filesystem root, which is never deleted.`:`${ge(e)} is the system root \`${t}\` (or an ancestor of it), which is never deleted or trashed.`}for(let t of Ns){let n=me(r,t),s=Q(e,n);if(!s&&!Q(n,e))continue;if(t===".hasna"&&s){let i=ri(e,r);if(i?.content===!0)continue;if(i&&i.content===!1)return`${ge(e)} is inside the protected \`~/${t}\` tree and is not sanctioned scratch, because ${i.reason}. Nothing under \`~/${t}\` is deleted or trashed outside that one carve-out.`}return s?`${ge(e)} is inside the protected \`~/${t}\` tree, which is never deleted or trashed. Delete a specific file inside it, and only when you are sure.`:`${ge(e)} contains the protected \`~/${t}\` tree, which is never deleted or trashed. Delete a specific file or directory inside it instead.`}return null}function ii(e,r,t){let n=Wt(t);if(n.some((s)=>Q(r,s)))return!0;return e.some((s)=>s!==null&&n.some((i)=>Q(s,i)))}var Cn=new WeakMap;function oi(e){let r=Cn.get(e);if(r)return r;let t=e.words.map((o)=>C(o.text)),n=t.findIndex((o)=>o==="-exec"||o==="-execdir"||o==="-ok"||o==="-okdir"),s=-1;e.words.forEach((o,a)=>{if(Ln.has(T(o.text)))s=a});let i={findDelete:t.includes("-delete"),findExecDelete:n>=0&&t.slice(n).some((o)=>Pt.has(nt(o))),namesDelete:t.some((o)=>Pt.has(nt(o))),lastFlockCommand:s,textMention:U(pi(e)),envMention:U(Be(e.words.map((o)=>T(o.text)))),bodiesMention:U((e.heredocs??[]).join(`
25
+ `))};return Cn.set(e,i),i}var li=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]);function ai(e,r){if(!li.has(be(e.words[r].text)))return!1;for(let t=r+1;t<e.words.length;t++){if(e.redirects.has(t))continue;let n=T(e.words[t].text);if(n==="--")return t+1>=e.words.length;if(/^-[A-Za-z]*s/.test(n))return!0;if(/^-[A-Za-z]*c/.test(n))return!1;if(n==="-o"||n==="+o"||n==="-O"||n==="+O"){t++;continue}if(!/^[-+]/.test(n)||n==="-")return n==="-"}return!0}var Tt=(e)=>e.kind==="rm"||e.kind==="refuse",ui="This command's command word or wrapper arguments cannot be read before it runs (an expansion such as a variable, substitution, brace or glob pattern, an unknown or unsupported option, a working directory or a non-decimal duration), so this hook cannot tell which word runs, and one of its words could run a delete. Run the delete as a plain `rm -- <path>` command, which is redirected into trash.",ci="This delete's brace pattern names more paths than this hook will check. Run the delete on explicit paths with `rm -- <path> \u2026`, which is redirected into trash.",fi="This delete's brace pattern expands to a path under a protected repository checkout. Deletes there are refused; run them through the owning workflow, and write any other delete out as plain paths.",di="This command's wrapper arguments can be read as running two different deletes, so no single rewrite is safe. Run the delete as a plain `rm -- <path>` command, which is redirected into trash.";function Nt(e){let r=[];e.words.forEach((s,i)=>{if(!e.redirects.has(i))r.push(i)});let t=r.map((s)=>{let i=e.words[s].text;return{text:C(i),opaque:rt(i)}}),n=se(t,Fs);if(n===null)return null;return n.index<0?-1:r[n.index]}function $t(e,r,t,n){let s=be(e.words[r].text);if(s==="cd"){let l=e.words[r+1];if(!l)return{kind:"none"};return{kind:"cd",cwd:tt(l.text,t,n.home)??n.cwd}}if(Object.hasOwn(At,s))return{kind:"refuse",reason:At[s]};let i=Gn(e,r,t,n);if(i)return i;if(s==="rm"){let l=Ys(e,r);if(l.length===0)return{kind:"none"};let u={word:e.words[r],operands:l},c=Wt(n.home),f=(p)=>p!==null&&c.some((m)=>Q(p,m)),d=[],h=[];for(let p of l){let m=tt(p.text,t,n.home);if(d.push(m),!p.text.includes("{"))continue;let O=re(p.text);if(O===null)return{kind:"refuse",reason:ci};for(let A of O){let I=tt(A,t,n.home);if(I===null)continue;if(f(I)&&!f(m))return{kind:"refuse",reason:fi};h.push(I)}}if(ii(d,t,n.home))return u.cwdOnly=d.every((p)=>p!==null&&!f(p)),{kind:"rm",hit:u,handoff:!0,protectedReason:null};for(let p of[...d,...h]){if(!p)continue;let m=si(p,n.home);if(m)return{kind:"rm",hit:u,handoff:!1,protectedReason:m}}return{kind:"rm",hit:u,handoff:!1,protectedReason:null}}if(Bs.has(s)){let l=e.words.findIndex((c,f)=>f>r&&!T(c.text).startsWith("-")),u=l>=0?be(e.words[l].text):"";if(u==="rm"||Object.hasOwn(At,u))return{kind:"refuse",reason:`\`${s} ${u}\` runs the ${s} applet, whose own \`rm\` is not GNU \`rm\` and cannot be rewritten in place. Run the delete as \`rm -- <path>\`, which is redirected into trash.`};return{kind:"none"}}if(s==="git"){let l=Dt(e,r);if(l==="rm"||l==="clean"){if(!(l==="rm"?gi(e,r):qn(e,r)))return{kind:"refuse",reason:l==="rm"?"`git rm` is refused: without `--cached` it deletes the working-tree file, and its semantics are not `rm`'s. Use `rm -- <path>` (intercepted and redirected into trash) to remove the file, or `git rm --cached -- <path>` to unstage it without deleting.":"`git clean` deletes untracked files irrecoverably and is refused. Remove them explicitly with `rm -- <path>` (intercepted and redirected into trash), or preview with `git clean -n`."}}return{kind:"none"}}let o=oi(e);if(s==="find"){if(o.findDelete)return{kind:"refuse",reason:"`find -delete` deletes files irrecoverably and is refused. List the paths first (`find \u2026 -print`), then remove them explicitly with `rm -- <path>` so the delete is redirected into trash."};if(o.findExecDelete)return{kind:"refuse",reason:"`find -exec <delete>` is refused: the delete runs through find, not through `rm`, and cannot be redirected into trash. Remove the paths explicitly with `rm -- <path>`."};return{kind:"none"}}if(s==="xargs"&&o.namesDelete)return{kind:"refuse",reason:"`xargs rm` takes its targets from stdin, so this hook cannot verify what would be deleted. Pipe the paths into an explicit `rm -- <path> \u2026` instead, which is redirected into trash."};let a=s==="flock"?o.lastFlockCommand>r:Ln.has(s);if(Ds.has(s)||a){let l=ai(e,r)?n.bodiesMention:o.bodiesMention;if((s==="env"?o.envMention:o.textMention)||l)return{kind:"refuse",reason:`\`${a?"flock":s}\` runs a command string this hook cannot rewrite in place. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or as a script that uses \`trash guard\` itself.`}}return{kind:"none"}}function Gn(e,r,t,n,s={segment:e,index:r},i=0){let o=be(e.words[r].text);for(let f of He(e.words.map((d)=>C(d.text)),r,(d)=>e.redirects.has(d))){if(i>=8)return Fe(s.segment,s.index,t,n.home)?{kind:"refuse",reason:hi}:null;let d={words:e.words.slice(f.start,f.end),redirects:new Set([...e.redirects].filter((p)=>p>=f.start&&p<f.end).map((p)=>p-f.start))},h=Nt(d);for(let p of new Set([L(d),h??-1])){if(p<0)continue;let m=Gn(d,p,t,n,s,i+1);if(m)return m}}let a=e.words.map((f,d)=>({word:f,at:d})).filter(({at:f})=>!e.redirects.has(f)),l=a.findIndex(({at:f})=>f===r),u=l<0?null:Le(a.map(({word:f})=>f.text),l,C);if(u&&!u.literal&&(Fe(e,r,t,n.home)||Fe(s.segment,s.index,t,n.home)))return{kind:"refuse",reason:`\`${o}\` runs a shell program that is not a plain literal (an expansion, a substitution, ANSI-C \`$'\u2026'\` quoting or several words), so this hook cannot read what it would delete under a protected repository checkout. Write the program out literally, or run it from outside the checkout.`};let c=Me(e.words.map((f)=>C(f.text)),r,(f)=>f>=0&&f<e.words.length&&(e.redirects.has(f)||rt(e.words[f].text)));if(!c||!(Fe(e,r,t,n.home)||Fe(s.segment,s.index,t,n.home)))return null;if(!c.unresolved&&!c.programs.some((f)=>U(f.text)))return null;return{kind:"refuse",reason:`\`${o}\` runs a program locally (an interpreter's inline program or a command-running option) this hook cannot rewrite, and it could delete a file under a protected repository checkout. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or run the command from outside the checkout.`}}var hi="This command nests find/xargs launchers too deeply for this hook to read what they run under a protected repository checkout. Run the inner command directly.";function Fe(e,r,t,n){let s=Wt(n),i=(o)=>o!==null&&s.some((a)=>Q(o,a));if(s.some((o)=>Q(t,o)))return!0;for(let o=r+1;o<e.words.length;o++){if(e.redirects.has(o))continue;if(i(tt(e.words[o].text,t,n)))return!0}return!1}function Se(e,r){let t={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},n=P(e,Fn);t.trustworthy=n.trustworthy;let s={cwd:r.cwd,home:r.home,depth:r.depth??0,bodiesMention:U(n.segments.flatMap((l)=>l.heredocs??[]).join(`
26
+ `))};if(!n.trustworthy){let l=pe(e);return l===e?t:{...Se(l,r),trustworthy:!1}}let i=[],o=(l,u=t.refusals)=>{if(l.kind==="refuse")u.push({reason:l.reason});else if(l.kind==="rm"&&l.handoff)t.handoffHits.push(l.hit);else if(l.kind==="rm"){if(t.rmHits.push(l.hit),l.protectedReason)t.protectedHits.push({reason:l.protectedReason})}},a=s.cwd;for(let l of n.segments){let u=L(l),c=Nt(l),f=u<0?{kind:"none"}:$t(l,u,a,s);if(f.kind!=="cd")o(f);let d=(h)=>h!==null&&h>=0&&rt(l.words[h].text);if(c===null||d(u)||d(c)){if(l.words.some((h,p)=>!l.redirects.has(p)&&(Tt($t(l,p,a,s))||Vs(h.text))))i.push({reason:ui})}else if(c>=0&&c!==u){let h=$t(l,c,a,s);if(Tt(h))if(Tt(f))i.push({reason:di});else o(h,i)}if(f.kind==="cd")a=f.cwd}if(s.depth<3)for(let l of n.substitutions){let u=Se(l,{cwd:a,home:s.home,depth:s.depth+1});if(u.rmHits.length>0||u.refusals.length>0||u.handoffHits.length>0||u.protectedHits.length>0||!u.trustworthy&&U(l)){t.refusals.push({reason:"This command runs a delete inside a command substitution `$(\u2026)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(n.substitutions.some((l)=>U(l)))t.refusals.push({reason:"This command nests a delete inside command substitutions deeper than this hook will follow. Run the delete as a separate `rm -- <path>` command."});return t.refusals.push(...i),t}function pi(e){return e.words.map((r)=>r.text).join(" ")}function Dt(e,r){let t=r+1;while(t<e.words.length){let n=T(e.words[t].text);if(!n.startsWith("-"))return n;if(t++,Gs.has(n))t++}return null}function gi(e,r){if(e.words.slice(r+1).map((n)=>T(n.text)).includes("--cached"))return!0;return qn(e,r)}function qn(e,r){let t=e.words.slice(r+1).map((n)=>T(n.text));return t.includes("-n")||t.includes("--dry-run")}function Pn(e){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(e))return e;return`'${e.replace(/'/g,"'\\''")}'`}function mi(e,r,t,n){let s=n?["/usr/bin/env","-i",`HOME=${n.home}`,`PATH=${n.path}`,`HASNA_TRASH_AGENT=${n.agent}`,n.runtime,"--config=/dev/null","--no-env-file","--no-macros","--no-install",t,"guard"].map(Pn).join(" "):`${Pn(t)} guard`,i=[...r].sort((a,l)=>l.word.start-a.word.start),o=e;for(let a of i)o=`${o.slice(0,a.word.start)}${s}${o.slice(a.word.end)}`;return o}function bi(e,r,t,n,s){if(!r||r===e)return!1;if(t.length===0)return!1;let i=Se(r,{cwd:n,home:s});if(!i.trustworthy)return!1;if(i.rmHits.length>0||i.handoffHits.length>0)return!1;return i.refusals.length===0}function Si(e,r){let t={};for(let[n,s]of Object.entries(e??{}))t[n]=s;if(t.command=r,typeof t.description!=="string"||t.description.trim()==="")t.description=Is;if(typeof t.timeout!=="number"||!Number.isFinite(t.timeout)||t.timeout<=0)t.timeout=Ps;if(typeof t.run_in_background!=="boolean")t.run_in_background=!1;if("dangerouslyDisableSandbox"in t&&typeof t.dangerouslyDisableSandbox!=="boolean")delete t.dangerouslyDisableSandbox;return t}function wi(e,r,t,n,s){if(typeof e.command!=="string"||e.command.trim()==="")return!1;if(typeof e.description!=="string"||e.description.trim()==="")return!1;if(typeof e.timeout!=="number"||!Number.isFinite(e.timeout)||e.timeout<=0)return!1;if(typeof e.run_in_background!=="boolean")return!1;if("dangerouslyDisableSandbox"in e&&typeof e.dangerouslyDisableSandbox!=="boolean")return!1;return bi(r,e.command,t,n,s)}function yi(e){let r=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return P(e,Fn).segments.some((n)=>{let s=Nt(n);return[L(n),...s===null?[]:[s]].some((i)=>{if(n.words.slice(0,i<0?n.words.length:i).some((l)=>Hn.test(T(l.text))||r.has(be(l.text))))return!0;if(i<0)return!1;let a=n.words[i];return r.has(be(a.text))||/^\s*\(\s*\)\s*\{/.test(e.slice(a.end))})})}function B(e){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e}}}function xi(e){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:e}}}function ki(e){try{if(e.inspectTrash){let r=e.inspectTrash();return r.ok?{path:r.path,error:null}:{path:null,error:`${r.code}: ${wn[r.code]}`}}return{path:e.findTrash(),error:null}}catch(r){return{path:null,error:r instanceof Error?r.message:String(r)}}}var vi="[trash-guard] No verified @hasna/trash guard was found on PATH. This deletion is refused. Install the current @hasna/trash package with Bun and run its setup; the operating-system trash utility is not a compatible guard.",In="[trash-guard] The rewrite of this command did not verify (the delete could not be redirected cleanly), so the command is refused rather than run unredirected. Re-run the delete as a plain `rm -- <path>` command.";function Wn(e,r){if(e.refusals.length>0)return B(`[trash-guard] ${e.refusals[0].reason}`);if(e.protectedHits.length>0)return B(`[trash-guard] ${e.protectedHits[0].reason}`);if(!e.trustworthy)return U(r)?B("[trash-guard] This command could not be parsed to the end (unterminated quote, substitution or here-document), so a delete inside it cannot be redirected. Re-run the delete as a plain `rm -- <path>` command."):{continue:!0};if(e.rmHits.length===0){if(e.handoffHits.some((t)=>t.cwdOnly))return B("[trash-guard] This delete runs from inside a protected repository checkout but names only paths outside it. Run it from outside the checkout (`cd /tmp && rm -- <path>`), where it is redirected into trash.");return{continue:!0}}if(e.handoffHits.length>0)return B("[trash-guard] This command mixes a delete under the protected repo-checkout roots (owned by workspace-repos-guard) with a delete outside them, and a partial rewrite would leave one of them unredirected. Re-run them as separate commands, so each delete is handled by the hook that owns it.");return null}function zn(e,r){if(e.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(e.tool_name??"")){let p=e.tool_input?.command;if(typeof p!=="string")return B("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(p))return B("[trash-guard] Delete File would bypass recoverable deletion. First use `trash put -- <path>` or the trash_put MCP tool, then submit any remaining edits without the deletion block.");return{continue:!0}}if(e.tool_name!=="Bash")return{continue:!0};if(typeof e.tool_input?.command!=="string")return B("[trash-guard] The Bash tool call carried no readable `command`, so this hook cannot verify what would run. Refusing a call it cannot verify. Re-run the delete explicitly as `rm -- <path>` so it can be redirected into trash.");let n=he(e);if(!n.trim())return{continue:!0};let s=()=>Se(n,{cwd:r.cwd,home:r.home}),i=(p)=>p.rmHits.map((m)=>m.word.start).join(),o=(p)=>p()||!!ie(n,p),a=s(),l=Wn(a,n),u=ie(n,()=>{let p=s();return{result:p,verdict:Wn(p,n)}});if(u){let{result:p,verdict:m}=u;if(m&&!("continue"in m))return m;if(!m&&(!l||("continue"in l))&&i(p)!==i(a))return B(In)}if(l)return l;let c=ki(r);if(c.error!==null)return B(`[trash-guard] The guard could not resolve the \`trash\` binary (${c.error}), so this \`rm\` cannot be redirected into a recoverable delete \u2014 and an unrecoverable delete is never allowed, so the command is refused rather than run. Fix the environment (PATH, permissions) and re-run the same command.`);if(c.path===null)return B(vi);let f=c.path;if(r.execution&&o(()=>yi(n)))return B("[trash-guard] A deletion combined with shell environment changes cannot use the verified native execution context. Run the deletion as a separate plain rm command.");let d=mi(n,a.rmHits,f,r.execution),h=Si(e.tool_input,d);if(r.execution)h.hasna_execution="hasna.hooks.execution.v1";if(o(()=>!wi(h,n,a.rmHits,r.cwd,r.home)))return B(In);return xi(h)}import{closeSync as _i,constants as Un,fstatSync as Ei,lstatSync as Oi,openSync as Ri,readFileSync as Ai,statSync as Ti}from"fs";import{homedir as nr}from"os";import{dirname as Lt,isAbsolute as rr,join as ye,normalize as xe,relative as $i,resolve as Ue,sep as jt}from"path";var Ci=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),Pi=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),Ii=["hasna","hasnaxyz","hasna-products"],Ge="workspace-repos-guard";function Wi(e){return ye(e,".hasna","repos","clones")}function Ni(e){return ye(e,"workspace","repos")}function sr(e){return[Wi(e),Ni(e)]}function Di(e){return ye(e,".hasna","hooks","config","workspace-repos-guard-orgs")}var Li=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function Ht(e){let r=process.getuid?.();return r!==void 0&&(e.uid===0||e.uid===r)&&(e.mode&18)===0}function Hi(e){let r=Di(e),t;try{let s=Ri(r,Un.O_RDONLY|Un.O_NOFOLLOW);try{let o=Ei(s);if(!o.isFile()||!Ht(o)||o.size>4096)return null;t=Ai(s,"utf8")}finally{_i(s)}let i=xe(e);for(let o=Lt(r);o!==i;o=Lt(o)){let a=Oi(o);if(!a.isDirectory()||!Ht(a)||o===Lt(o))return null}if(!Ht(Ti(i)))return null}catch{return null}let n=t.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return n.length>0&&n.every((s)=>Li.test(s))?new Set(n):null}function Mi(e=process.env,r=nr()){let t=e.WORKSPACE_REPOS_GUARD_ORGS;if(typeof t==="string"&&t.trim())return new Set(t.split(",").map((n)=>n.trim()).filter(Boolean));return Hi(r)??new Set(Ii)}function Mt(e,r,t,n){if(n==="read")return{blocked:!1};let s=$i(r,e);if(s===""){if(n==="delete")return{blocked:!0,reason:`[${Ge}] delete of the protected repo-checkout root is forbidden: ${r}`};return{blocked:!0,reason:`[${Ge}] writes directly to the protected repo-checkout root are forbidden: ${r}`}}if(s.startsWith(`..${jt}`)||s===".."||rr(s))return{blocked:!1};let i=s.split(jt).filter(Boolean);if(n==="delete")return{blocked:!0,reason:`[${Ge}] delete under the protected repo-checkout root (${r}) is forbidden at any depth: ${e}`};if(i.length<=1)return{blocked:!0,reason:`[${Ge}] writing would create a top-level entry directly under the protected repo-checkout root (${r}); only GitHub-org folders belong there: ${e}`};let o=i[0];if(!t.has(o))return{blocked:!0,reason:`[${Ge}] '${o}' is not an allowed GitHub org under the protected repo-checkout root (${r}); allowed: ${[...t].join(", ")}: ${e}`};return{blocked:!1}}var ir=/\b(?:-o|--output|-O|--output-document|-out)\b/,Fi=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,Bi=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function or(e){return e.replace(Fi," ")}function ji(e){let r=[],t=null,n=0,s=0,i=!1,o=0;for(let a=0;a<e.length;a++){let l=e[a];if(t==="'"){if(l==="'")t=null;continue}if(l==="\\"){a++;continue}if(l==="("){n++;continue}if(l===")"){if(--n<0)return[e];continue}if(l==="$"&&e[a+1]==="{"){s++,a++;continue}if(l==="}"&&s>0){s--;continue}if(l==="`"){i=!i;continue}if(t==='"'){if(l==='"')t=null;continue}if(l==="'"||l==='"'){t=l;continue}if(l!=="|"||n>0||s>0||i||e[a-1]===">")continue;if(r.push(e.slice(o,a)),e[a+1]==="&")a++;o=a+1}if(t||n!==0||s!==0||i)return[e];return r.push(e.slice(o)),r}function Gi(e){let r=[],t="",n="",s=null,i=!1,o=()=>{if(!i)return;let a=n.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),l=t.startsWith("~")&&!/^~(?:\/|$)/.test(n);r.push({text:l?`./${t}`:t,opaque:/[$\x60*?[]/.test(a)||/[()]/.test(a)||Je(n)}),t="",n="",i=!1};for(let a=0;a<e.length;a++){let l=e[a];if(s==="'"){if(l==="'")s=null;else t+=l;n+=l;continue}if(l==="\\"&&a+1<e.length){let u=e[a+1];t+=s==='"'&&!/[$\x60"\\\n]/.test(u)?l+u:s==='"'&&u===`
27
+ `&&!Y.on?"":u,n+=l+u,i=!0,a++;continue}if(s==='"'){if(l==='"')s=null;else t+=l;n+=l;continue}if(/\s/.test(l)){o();continue}if(i=!0,n+=l,l==="'"||l==='"')s=l;else t+=l}if(s)n+="$";return o(),r}function Ft(e,r,t){let n=e[r];return n==="--help"||n==="--version"||t&&(n==="-h"||n==="-V")}var Vn={read:0,write:1,delete:2};function it(...e){return e.reduce((r,t)=>Vn[t]>Vn[r]?t:r,"read")}var qi=new Set(["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"]),lr=new Set(["put","rm","delete","remove"]),zi=new Set([...lr,"restore","restore-capsule","recover","release","locks","retention","hold","unhold","pin","unpin","retrieve","backup-retrieve"]),ar=new Set(["-delete","-exec","-execdir","-ok","-okdir","-fls","-fprint","-fprint0","-fprintf"]);function qt(e){let r=null;for(let t=0;t<e.length;t++){let n=e[t];if(r==="'"){if(n==="'")r=null;continue}if(n==="\\"){t++;continue}if(n==="$"||n==="`")return!0;if(r==='"'){if(n==='"')r=null;continue}if(n==="'"||n==='"')r=n;else if("*?[{".includes(n))return!0}return r!==null}function zt(e){let r=e.trim();if(!r)return"read";if(lt(r))return"delete";let t=P(r);if(!t.trustworthy||t.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(r))return le(r);let n=t.segments.flatMap((s)=>{let i=Zn(s),o=s.words.filter((u,c)=>!s.redirects.has(c)).map((u)=>u.text),a=o.map(re);if(a.every((u,c)=>u!==null&&u.length===1&&u[0]===o[c]))return[i];if(a.some((u)=>u===null))return[i,le(o.join(" "))];let l=P(a.flatMap((u)=>u??[]).join(" "));return[i,...l.trustworthy?l.segments.map(Zn):[le(o.join(" "))]]});return it(...n)}function Zn(e){let r=e.words.map((i,o)=>({word:i,at:o})).filter(({at:i})=>!e.redirects.has(i)),t=L(e),n=t<0?"read":Kn(e,t),s=se(r.map(({word:i})=>Ut(i.text)));if(s===null)return it(n,le(r.map(({word:i})=>T(i.text)).join(" ")));if(s.index<0||r[s.index].at===t)return n;return it(n,Kn(e,r[s.index].at))}function ur(e,r,t=0){if(r<0||t>8)return t>8;let n=e.words.map((u,c)=>({word:u,at:c})).filter(({at:u})=>!e.redirects.has(u)),s=n.findIndex(({at:u})=>u===r),i=s<0?null:Le(n.map(({word:u})=>u.text),s,C);if(i){if(!i.literal)return!0;let u=P(i.program);if(u.trustworthy&&u.segments.some((c)=>ot(c,t+1)))return!0}let o=e.words.map((u)=>C(u.text));for(let u of He(o,r,(c)=>e.redirects.has(c)))if(ot(cr(e,u.start,u.end),t+1))return!0;let l=Me(o,r,(u)=>u>=0&&u<e.words.length&&(e.redirects.has(u)||qt(e.words[u].text)));if(!l)return!1;if(l.unresolved)return!0;return l.programs.some((u)=>u.kind==="shell"?zt(u.text)!=="read":!On(u))}function cr(e,r,t){let n=new Set([...e.redirects].filter((s)=>s>=r&&s<t).map((s)=>s-r));return{words:e.words.slice(r,t),redirects:n}}function ot(e,r=0){return fr(e).some((t)=>ur(e,t,r))}function Ut(e){return{text:C(e),opaque:/[$\x60]/.test(e)&&!/^(?:[^$\x60"'\\]|\$'(?:[^'\\]|\\.)*')+$/.test(e)}}function fr(e){let r=new Set,t=L(e);if(t>=0)r.add(t);let n=e.words.map((i,o)=>({word:i,at:o})).filter(({at:i})=>!e.redirects.has(i)),s=se(n.map(({word:i})=>Ut(i.text)));if(s!==null&&s.index>=0)r.add(n[s.index].at);return[...r]}function qe(e,r=0){if(r>8)return[];let t=[];for(let n of e.segments){let s=n.words.map((a)=>C(a.text)),i=(a)=>a>=0&&a<n.words.length&&(n.redirects.has(a)||qt(n.words[a].text)),o=n.words.filter((a,l)=>!n.redirects.has(l));for(let a of fr(n)){t.push(...(Me(s,a,i)?.writes??[]).map((c)=>c[0]==="/"?c:`./${c}`));let l=Le(o.map((c)=>c.text),o.indexOf(n.words[a]),C),u=l?.literal?P(l.program):null;if(u?.trustworthy)t.push(...qe(u,r+1));for(let c of He(s,a,(f)=>n.redirects.has(f)))t.push(...qe({segments:[cr(n,c.start,c.end)]},r+1))}}for(let n of e.substitutions??[]){let s=P(n);if(s.trustworthy)t.push(...qe(s,r+1))}return t}function lt(e,r=0){if(r>4)return!1;let t=P(e),n=t.trustworthy?e:pe(e);if(n!==e)return lt(n,r+1);if(t.trustworthy&&t.segments.some((i)=>ot(i)))return!0;return(pr(e)??t.substitutions).some((i)=>lt(i,r+1))}function Kn(e,r){if(ur(e,r))return"delete";let t=e.words.filter((i,o)=>o>=r&&!e.redirects.has(o)),n=t.map((i)=>C(i.text)),s=n[0].split("/").pop();if(["rm","rmdir","shred"].includes(s??""))return Ft(n,1,!1)?"read":"delete";if(["unlink","rmtree","del"].includes(s??""))return"delete";if(s==="trash"){let i=1;while(i<n.length&&n[i].startsWith("-")){let o=n[i++];if(["--help","-h","--version","-V","--identity"].includes(o))return"read";if(["--agent","--spool","--files","--info","--config"].includes(o))i++;else if(!["--json","--local"].includes(o))return"delete"}if(i===n.length||qi.has(n[i]))return"read";if(zi.has(n[i])&&Ft(n,i+1,!0))return"read";if(["restore","restore-capsule"].includes(n[i]))return"write";return"delete"}if(s==="git"){let i=Dt(e,r);if(i==="clean"||i==="rm")return n[1]===i&&Ft(n,2,!0)?"read":"delete";return i==="clone"||i==="init"?"write":"read"}if(s==="find"&&!t.some((i)=>qt(i.text))&&!n.some((i)=>ar.has(i)))return"read";if(s==="env"&&U(Be(n)))return"delete";if(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env","xargs","find","busybox","toybox"].includes(s??""))return le(n.join(" "));if(["mkdir","mkfile","touch","mv","cp","ln","tee","install","dd","rsync","scp","truncate"].includes(s??""))return"write";if(s==="curl"||s==="wget")return ir.test(n.join(" "))?"write":"read";if(s==="sed"&&n.slice(1).some((i)=>/^-i|^--in-place(?:=|$)/.test(i)))return"write";if(["python","python3","node","bun"].includes(s??"")&&n.some((i)=>i==="-c"||i==="-e"))return"write";return"read"}function le(e){let r=e.replace(/[{},]/g," ");return r===e?Bt(e):it(Bt(e),Bt(r))}function Bt(e){let r=e.trim();if(!r)return"read";if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:rm|rmdir|unlink|shred|trash|rmtree|del)(?:\s|$)/.test(r))return"delete";if(/\bgit\b/.test(r)){if(/\bgit\b[^;&|]*\b(?:clean|rm)\b/.test(r))return"delete";if(/\bgit\b[^;&|]*\b(?:clone|init)\b/.test(r))return"write";return"read"}if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|mv|cp|ln|tee|install|dd)(?:\s|$)/.test(r))return"write";if(/\b(?:curl|wget)\b/.test(r)){if(ir.test(r))return"write";return"read"}if(/\bsed\b/.test(r)){if(/(?:^|\s)-i\S*(?:\s|$)|--in-place(?:\s|$)/.test(r))return"write"}else if(/\b(?:rsync|scp|truncate)\b/.test(r))return"write";else if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(r))return"write";if(/(?:^|[;&|])\s*echo\b/.test(r)||/>/.test(or(r)))return"write";return"read"}function ze(e,r){let t=e.trim(),n=t.match(/^(['"])([\s\S]*)\1$/);if(n)t=n[2];if(t=t.replace(/^"*\$HOME"*\//,"$HOME/"),t=t.replace(/^"*\$\{HOME\}"*\//,"${HOME}/"),t==="~")return r;if(t.startsWith("~/"))return ye(r,t.slice(2));if(t==="$HOME"||t==="${HOME}")return r;if(t.startsWith("$HOME/"))return ye(r,t.slice(6));if(t.startsWith("${HOME}/"))return ye(r,t.slice(8));let s=t.match(new RegExp(`^"*${Gt(r)}"*/`));if(s)return r+"/"+t.slice(s[0].length);return e}function Ui(e){let r=e.trim();while(r.startsWith("(")||/^\{(?:\s|$)/.test(r))r=r.slice(1).trim();while(r.endsWith(")")||/(?:^|\s)\}$/.test(r))r=r.slice(0,-1).trim();return r}function Gt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Xn(e,r,t){if(e===void 0)return[t];let n=ze(e,t),s=n.match(/^(['"])(.*)\1$/);if(s)n=s[2];if(!n||n==="-"||/[$\x60*?[\]{}~\\'"]/.test(n))return null;return[...new Set(r.map((i)=>Ue(i,n)))]}var Vi=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function Zi(e,r){let t=se(r);if(!t||t.index<=0||r[t.index].opaque)return 0;let n=P(e);if(!n.trustworthy||n.substitutions.length>0||n.segments.length!==1)return 0;let[s]=n.segments;if(s.redirects.size>0||s.words.length!==r.length)return 0;if(s.words.some((i,o)=>T(i.text)!==r[o].text))return 0;return L(s)===t.index?t.index:0}function Ki(e,r){let t=0;if(e==="git")t=r.findIndex((s)=>s.text==="rm"||s.text==="clean")+1;let n=!1;return r.slice(t).filter((s)=>{if(!n&&s.text==="--")return n=!0,!1;if(!n&&s.text.startsWith("-")&&!s.opaque)return!1;return n=!0,!0})}var Xi=new Set(["--agent","--spool","--files","--info","--config"]),Yi=new Set(["--spool","--files","--info","--config"]),Qi=new Set(["--json","--local","--help","-h","--version","--identity"]),Yn={"--agent":/^[^-]/,"--retention":/^(?:\d+(?:\.\d+)?|never)$/},Ji=new Set(["--to"]);function eo(e){let r=[],t=0;for(;t<e.length&&e[t].text.startsWith("-");t++){let i=e[t];if(i.opaque)return null;if(Xi.has(i.text)){let o=e[++t];if(!o||o.opaque)return null;if(Yi.has(i.text))r.push(o)}else if(!Qi.has(i.text))return null}let n=e[t];if(!n||n.opaque||!lr.has(n.text))return null;let s=!1;for(t++;t<e.length;t++){let i=e[t];if(s||i.opaque||i.text==="-"||!i.text.startsWith("-")){r.push(i);continue}if(i.text==="--"){s=!0;continue}let o=i.text.indexOf("="),a=o<0?i.text:i.text.slice(0,o);if(Ji.has(a)){if(o>=0)r.push({text:i.text.slice(o+1),opaque:!1});else if(e[t+1]&&!e[t+1].text.startsWith("-"))r.push(e[++t]);continue}let l=e[t+1];if(o<0&&Object.hasOwn(Yn,a)&&l&&!l.opaque&&Yn[a].test(l.text))t++}return r}function to(e){let r=e.split(`
28
+ `),t=[],n=[],s=0;while(s<r.length){let i=s,o=r[s++].replace(/\r$/,""),a=[];for(let l=0;l<o.length;l++){let u=o[l],c=n[n.length-1];if(u==="\\"){l++;continue}if(u==="$"&&o[l+1]==="("&&o[l+2]==="("){let f=o.indexOf("))",l+3);if(f<0)return null;l=f+1;continue}if(u==="$"&&o[l+1]==="("){n.push(0),l++;continue}if(u==="$"&&o[l+1]==="[")return null;if(u==="$"&&o[l+1]==="{"){let f=o.indexOf("}",l+2);if(f<0||/['"\x60$]|<</.test(o.slice(l+2,f)))return null;l=f;continue}if(u==="`"){let f=o.indexOf("`",l+1);if(f<0)return null;l=f;continue}if(c==='"'){if(u==='"')n.pop();continue}if(u==="'"){let f=o.indexOf("'",l+1);if(f<0)return null;l=f;continue}if(u==='"'){n.push('"');continue}if(u==="#"&&(l===0||/[\s;&|()]/.test(o[l-1])))break;if(u==="("&&o[l+1]==="("&&(l===0||/[\s;&|(]/.test(o[l-1]))){let f=o.indexOf("))",l+2);if(f<0)return null;l=f+1;continue}if(typeof c==="number"&&(u==="("||u===")")){if(u==="(")n[n.length-1]=c+1;else if(c===0)n.pop();else n[n.length-1]=c-1;continue}if(u==="<"&&o[l+1]==="<"){if(o[l+2]==="<"){l+=2;continue}let f=we(o,l);if(!f)return null;a.push({marker:f,from:l}),l=f.end-1}}for(let{marker:l,from:u}of a){let c=s;for(;;){if(s>=r.length)return null;let f=r[s++].replace(/\r$/,"");if(l.stripTabs)f=f.replace(/^\t+/,"");if(f===l.delimiter)break}t.push({line:i,from:u,to:l.end,start:c,end:s-1,quoted:l.quoted})}}return n.length===0?t:null}var no=new Set(["sh","bash","zsh","dash","ksh","mksh","ash","fish","csh","tcsh","nu","xonsh","elvish","busybox","toybox","ssh","su","runuser","sudo","doas","pkexec","xargs","parallel","expect","script","at","batch","crontab","watch","flock","chroot","nsenter","unshare","docker","podman","kubectl","lxc","python","pypy","node","nodejs","bun","deno","tsx","ts-node","zx","npx","bunx","pnpx","perl","ruby","irb","php","lua","luajit","osascript","pwsh","powershell","Rscript","R","julia","tclsh","wish","awk","gawk","mawk","nawk","sed","make","gmake","gdb","lldb","sqlite3","psql","mysql","sftp","ftp","lftp","vim","vi","nvim","ex","ed","emacs","chmod"]),ro=new Set([".","source","eval","env","alias","hash"]),so=new Set(["tee","cp","mv","install","ln"]),dr=new Set(["cat","tac","tee","head","tail","wc","cut","tr","nl","rev","fold","fmt","paste","uniq","grep","egrep","fgrep","jq","diff","cmp","comm","iconv","od","xxd","hexdump","base64","base32","md5sum","sha1sum","sha224sum","sha256sum","sha384sum","sha512sum","b2sum","cksum","echo","printf","true","false",":","test","[","read","cd","pwd","ls","mkdir","touch","stat","sleep","cp","mv","ln","rm","rmdir","unlink","shred","trash","todos","conversations","mementos","knowledge","files","asks"]),io=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),oo=new Set(["pr","issue","api","release","gist"]);function lo(e,r){let t=e[r];if(t==="gh")return oo.has(e[r+1]??"");if(t!=="git")return dr.has(t);for(let n=r+1;n<e.length;n++){let s=e[n];if(s==="-C")n++;else if(s==="--no-pager"||s==="-P")continue;else return!s.startsWith("-")&&io.has(s)}return!1}function ao(e,r){for(let t=r+1;t<e.length;t++){let n=e[t];if(n==="\\")t++;else if(n==='"')return t;else if(n==="$"&&e[t+1]==="("){if(t=hr(e,t+1),t<0)return-1}else if(n==="`"){if(t=e.indexOf("`",t+1),t<0)return-1}}return-1}function hr(e,r){let t=0;for(let n=r;n<e.length;n++){let s=e[n];if(s==="\\")n++;else if(s==="'"||s==="`"){if(n=e.indexOf(s,n+1),n<0)return-1}else if(s==='"'){if(n=ao(e,n),n<0)return-1}else if(s==="(")t++;else if(s===")"&&--t===0)return n}return-1}function pr(e){let r=[],t=!1;for(let n=0;n<e.length;n++){let s=e[n];if(s==="\\")n++;else if(s==="'"&&!t){let i=e.indexOf("'",n+1);if(i<0)return null;n=i}else if(s==='"')t=!t;else if(s==="$"&&e[n+1]==="("){let i=hr(e,n+1);if(i<0)return null;let o=e.slice(n+2,i);if(e[n+2]==="("){if(/\$\(|\x60/.test(o))return null}else r.push(o);n=i}else if(s==="`"){let i=e.indexOf("`",n+1);if(i<0)return null;r.push(e.slice(n+1,i)),n=i}}return t?null:r}function uo(e){if(/[<>]\(/.test(e))return!0;let r=[],t=[e];for(let s=0;t.length>0;s++){if(s>64)return!0;let i=t.shift(),o=P(i),a=pr(i);if(!o.trustworthy||!a)return!0;r.push(...o.segments),t.push(...new Set([...o.substitutions,...a]))}let n=new Set;for(let s of r){let i=s.words.map((l)=>T(l.text));for(let l of s.redirects)n.add(z(i[l]??""));let o=L(s);if(o<0)continue;let a=z(i[o]);if(so.has(a)){for(let l of i.slice(o+1))if(!l.startsWith("-"))n.add(z(l))}if(a==="dd"){for(let l of i)if(l.startsWith("of="))n.add(z(l.slice(3)))}}n.delete("");for(let s of r){for(let u of s.words){let c=z(T(u.text));if(no.has(c)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(c))return!0}let i=L(s),o=s.words.map((u,c)=>({text:T(u.text),at:c})).filter(({at:u})=>!s.redirects.has(u));if(o.some(({text:u,at:c})=>(i<0||c<i)&&We.test(u)))return!0;if(i<0)continue;let a=s.words[i].text,l=T(a);if(/[$\x60]/.test(a)||l.includes("/")||ro.has(l)||n.has(l))return!0;if(!lo(o.filter(({at:u})=>u>=i).map(({text:u})=>u),0))return!0}return!1}function co(e){if(!e.includes("<<"))return null;let r=to(e);if(!r||r.length===0)return null;let t=e.split(`
29
+ `),n=[...t],s=[];for(let o of r){let a=t.slice(o.start,o.end);if(!o.quoted&&a.some((l)=>/\$\(|\x60/.test(l)))return null;s.push(a.join(`
30
+ `));for(let l=o.start;l<=o.end;l++)n[l]=""}let i=[...n];for(let o of[...r].reverse()){let a=i[o.line];i[o.line]=a.slice(0,o.from)+" ".repeat(o.to-o.from)+a.slice(o.to)}return uo(i.join(`
31
+ `))?null:{outer:n.join(`
32
+ `),bodies:s}}var fo="/";function at(e,r,t){if(!e)return[];let n=P(e).trustworthy?e:pe(e),s=co(e);return[...n===e?[]:at(n,r,t),...s?[...tr(s.outer,r,t),...s.bodies.flatMap((i)=>at(i,r,fo))]:tr(e,r,t)]}var ho=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,po=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function Qn(e,r,t=!1){let n=[],s=0;for(let a of r)n.push(s),s+=a.length;let i=P(e);if(!i.trustworthy||!t&&i.substitutions.length>0)return null;let o=i.segments.flatMap((a)=>a.words).filter((a)=>r.some((l,u)=>u%2===1&&n[u]<a.end&&n[u]+l.length>a.start));return o.length>0?{lexed:i,offsets:n,words:o}:null}function Jn(e,r,t=[]){if(zt(r)!=="read")return!1;let n=L(e),s=e.words.filter((c,f)=>!e.redirects.has(f)),i=se(s.map((c)=>Ut(c.text)));if(i===null)return!1;let o=[n<0?1/0:n,i.index<0?1/0:e.words.indexOf(s[i.index])];if(e.words.some((c,f)=>f<Math.max(...o)&&!e.redirects.has(f)&&We.test(T(c.text))))return!1;if([n<0?null:e.words[n].text,i.index<0?null:s[i.index].text].every((c)=>c===null||dr.has(z(T(c)))))return!0;let l=s.filter((c)=>!t.includes(c)),u=l.map((c)=>T(c.text));return le(l.map((c)=>c.text).join(" "))==="read"&&le(u.join(" "))==="read"&&!u.some((c)=>ar.has(c))}function go(e,r,t,n){let s=(i)=>i.start<n&&i.end>t;if(!r.words.some(s))return!1;return r.lexed.segments.filter((i)=>i.words.some(s)).some((i)=>ot(i))}var er=(e,r)=>e.slice(r.words[0].start,r.words[r.words.length-1].end);function mo(e,r,t,n){let s=(o)=>o.start<n&&o.end>t,i=r.words.filter(s);if(i.length===0||i.some((o)=>!po.test(o.text)))return!1;for(let o of r.lexed.segments.filter((a)=>a.words.some(s)))if(!Jn(o,er(e,o),r.words))return!1;for(let o of i){let a=o.text.slice(1,-1);if(a.includes("<<"))return!1;let l=P(a);if(!l.trustworthy||l.substitutions.length>0)return!1;if(!l.segments.every((u)=>Jn(u,er(a,u))))return!1}return!0}function tr(e,r,t){if(!e)return[];let n=sr(r),s=(h)=>n.some((p)=>h===p||h.startsWith(`${p}${jt}`)),i=e.split(ho),o=Qn(e,i),a=o??Qn(e,i,!0),l=[],u=[t],c=new Set([t]),f=!0,d=[];for(let h=0;h<i.length;h+=2){let p=h===0?"":i[h-1].trim();if(p==="||")f=!1;else if(p!=="&&")f=!0;if(p!=="&&"||!f)u=[...c];let m=i[h],O=(m.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,A=(m.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let S=0;S<O;S++)d.push({current:[...u],reachable:new Set(c),certain:f});let I=Ui(m),j=o!==null&&mo(e,o,o.offsets[h],o.offsets[h]+m.length),k=!j&&(a!==null&&go(e,a,a.offsets[h],a.offsets[h]+m.length)||lt(m.trim())),b=I.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),R=b?null:I.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(R){for(let S of Xn(R[1],u,r)??[])c.add(S);f=!1,u=[...c]}let H=Gt(r),M=n.map((S)=>Gt(S.slice(r.length+1))).join("|"),_e=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${H}"*)/(?:${M})`),pn=new RegExp(`(${_e.source})([^\\s"';&|<>()\`]*|$)`,"g"),gn=(S)=>{let N=[],F;pn.lastIndex=0;while((F=pn.exec(S))!==null)N.push(xe(ze(F[0],r)).replace(/\/+$/,""));return N},mn=a===null?0:a.offsets[h],bn=(S)=>S.start<mn+m.length&&S.end>mn,Dr=a!==null&&a.words.some(bn)?qe({segments:a.lexed.segments.filter((S)=>S.words.some(bn))}):[m.trim(),I].flatMap((S)=>{let N=P(S);if(!N.trustworthy)N=P(pe(S));return N.trustworthy?qe(N):[]}),mt=ji(I).map((S,N)=>{let F=N===0?[...new Set(Dr)]:[],Ee=!1,Oe=or(S).replace(Bi,(St,ce)=>{if(!ce||/[$\x60]/.test(ce))Ee=!0;if(ce)F.push(ce);return" "}),Re=j?"read":k?"delete":zt(Oe);return{commandPart:Oe,operands:F,op:Ee&&Re==="read"?"write":Re}}),Lr=mt.some((S)=>S.op==="delete")?"delete":mt.some((S)=>S.op==="write")?"write":"read",bt=u.filter(s);if(k)for(let S of bt)l.push({path:S,op:"delete"});for(let S of mt){let N=!1;for(let D of gn(S.commandPart))N=!0,l.push({path:D,op:Lr});for(let D of S.operands){let K=gn(D);for(let q of K)l.push({path:q,op:"write"});if(K.length>0)continue;for(let q of bt)l.push({path:xe(Ue(q,ze(D,r))),op:"write"})}if(N||S.op==="read")continue;let F=Gi(S.commandPart),Ee=Zi(S.commandPart,F),Oe=z(F[Ee]?.text??""),Re=F.slice(Ee+1),St=((Oe==="trash"?eo(Re):null)??Ki(Oe,Re)).map((D)=>D.opaque?".":D.text),ce=S.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(S.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(S.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(S.commandPart),Ae=[];if(ce)for(let D of St.length>0?St:["."])Ae.push({operand:D,op:S.op});else{let D=S.commandPart.match(Vi),K=F.at(-1);if(Ae.push({operand:D?D[1]:!K||K.opaque?".":K.text,op:S.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(S.commandPart))F.forEach((q,Sn)=>{let fe,wt=q.text.match(/^-[A-Za-z]*?t(.*)$/),Ze=q.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(wt&&!q.text.startsWith("--"))fe=wt[1]?{text:wt[1],opaque:q.opaque}:F[Sn+1];else if(Ze&&"--target-directory".startsWith(Ze[1]))fe=Ze[2]!==void 0?{text:Ze[2],opaque:q.opaque}:F[Sn+1];if(fe)Ae.push({operand:fe.opaque||!fe.text?".":fe.text,op:S.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(S.commandPart))Ae.push({operand:".",op:S.op})}for(let D of bt)for(let{operand:K,op:q}of Ae)l.push({path:xe(Ue(D,ze(K,r))),op:q})}if(b){let S=Xn(b[1],u,r);if(S){for(let N of S)c.add(N);if(f)u=S}else f=!1}for(let S=0;S<A&&d.length>0;S++)({current:u,reachable:c,certain:f}=d.pop())}return l}var bo=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function So(e,r){let t=[],n;while((n=bo.exec(e))!==null){let s=n[1]==="Delete File"?"delete":"write";t.push({path:xe(Ue(r,n[2])),op:s})}return t}function gr(e,r={}){let t=[];if(e.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:t};let n=typeof e.tool_name==="string"?e.tool_name:"",s=r.home??nr(),i=sr(s),o=Mi(process.env,s);if(n==="Bash"){let d=he(e);if(!d)return{output:{continue:!0},warnings:t};let h=typeof e.cwd==="string"&&e.cwd?e.cwd:process.cwd(),p=at(d,s,h);p.unshift(...ie(d,()=>at(d,s,h))??[]);for(let m of p)for(let O of i){let A=Mt(m.path,O,o,m.op);if(A.blocked)return{output:{decision:"block",reason:A.reason},warnings:t}}return{output:{continue:!0},warnings:t}}let a=e.tool_input??{},l=typeof e.cwd==="string"&&e.cwd?e.cwd:process.cwd();if(Pi.has(n)){let d=typeof a.patch==="string"?a.patch:"";if(!d)return{output:{continue:!0},warnings:t};let h=So(d,l);for(let p of h)for(let m of i){let O=Mt(p.path,m,o,p.op);if(O.blocked)return{output:{decision:"block",reason:O.reason},warnings:t}}return{output:{continue:!0},warnings:t}}if(!Ci.has(n))return{output:{continue:!0},warnings:t};let u=typeof a.file_path==="string"?a.file_path:typeof a.path==="string"?a.path:typeof a.notebook_path==="string"?a.notebook_path:null;if(!u)return{output:{continue:!0},warnings:t};let c=ze(u,s),f=rr(c)?xe(c):Ue(l,c);for(let d of i){let h=Mt(f,d,o,"write");if(h.blocked)return{output:{decision:"block",reason:h.reason},warnings:t}}return{output:{continue:!0},warnings:t}}var wo=new Set(["id","node_id","databaseId","fullDatabaseId","number","state","state_reason","stateReason","status","conclusion","bucket","name","login","sha","oid","abbreviatedOid","ref","headRefName","baseRefName","headRefOid","baseRefOid","head_sha","headSha","head_branch","headBranch","merged","mergeable","mergeable_state","mergeStateStatus","draft","isDraft","locked","isLocked","title","displayTitle","display_title","created_at","updated_at","closed_at","merged_at","started_at","completed_at","submitted_at","pushed_at","published_at","createdAt","updatedAt","closedAt","mergedAt","startedAt","completedAt","submittedAt","pushedAt","publishedAt","tag_name","tagName","total_count","totalCount","count","additions","deletions","changes","changed_files","changedFiles","filename","path","event","workflow","workflowName","workflow_id","workflowDatabaseId","run_id","run_number","run_attempt","attempt","check_suite_id","default_branch","defaultBranch","full_name","fullName","nameWithOwner","private","isPrivate","visibility","archived","isArchived","fork","isFork","isRequired","is_required","required","context","type","__typename","role","permission","size","reviewDecision","author_association","authorAssociation","isCrossRepository","maintainerCanModify","maintainer_can_modify","commentsCount","language","digest","size_in_bytes","run_started_at","date","wait_timer","ahead_by","behind_by","total_commits","expired","current_user_can_approve","environment","html_url"]),yo=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),wr=new Set(["length","utf8bytelength","not","type","any","all","isempty","empty","test","startswith","endswith","contains","inside","has","in","index","rindex","indices","floor","ceil","round","fabs","sqrt","isinfinite","isnan","isnormal","infinite","nan","true","false","null"]),yr=new Set(["tostring","tojson","ascii_downcase","ascii_upcase","ltrimstr","rtrimstr","trim","ltrim","rtrim","sort","unique","reverse","first","last","min","max","add","flatten","join","split","values","nulls","strings","numbers","booleans","arrays","objects","iterables","scalars","sort_by","group_by","unique_by","min_by","max_by","select","limit","to_entries","from_entries"]),xo=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),ko=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class Kt extends Error{}var _=()=>{throw new Kt};function Vt(e,r){let t=[],n="",s=r+1;while(s<e.length){let i=e[s];if(i==='"'){if(n)t.push(n);return{end:s+1,parts:t}}if(i==="\\"){let o=e[s+1];if(o==="("){let a=1,l=s+2;while(l<e.length&&a>0){let u=e[l];if(u==='"'){l=Vt(e,l).end;continue}if(u==="(")a++;else if(u===")")a--;l++}if(a!==0)_();if(n)t.push(n),n="";t.push({src:e.slice(s+2,l-1)}),s=l;continue}if(o===void 0)_();n+=o,s+=2;continue}n+=i,s++}return _()}function xr(e){let r=[],t=0,n=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while(t<e.length){let s=e[t];if(/\s/.test(s)){t++;continue}if(s==="#")_();if(s==='"'){let l=Vt(e,t);r.push({t:"str",parts:l.parts}),t=l.end;continue}if(s==="."){if(e[t+1]===".")_();let l=/^[A-Za-z_][A-Za-z0-9_]*/.exec(e.slice(t+1));if(l){r.push({t:"field",name:l[0]}),t+=1+l[0].length;continue}if(e[t+1]==='"'){let u=Vt(e,t+1);if(u.parts.some((c)=>typeof c!=="string"))_();r.push({t:"field",name:u.parts.join("")}),t=u.end;continue}r.push({t:"dot"}),t++;continue}if(s==="$"||s==="@"){let l=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(e.slice(t));if(!l||s==="$")_();r.push({t:"fmt",name:l[0]}),t+=l[0].length;continue}let i=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(e.slice(t));if(i){r.push({t:"num"}),t+=i[0].length;continue}let o=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(e.slice(t));if(o){r.push({t:"ident",name:o[0]}),t+=o[0].length;continue}let a=n.find((l)=>e.startsWith(l,t));if(!a)_();r.push({t:"op",v:a}),t+=a.length}return r}var vo=new Set(["if","then","elif","else","end","as","def","reduce","foreach","try","catch","label","import","include","and","or","__loc__","error","input","inputs","debug","stderr","env","halt","halt_error","input_filename","input_line_number","recurse","paths","leaf_paths","getpath","setpath","delpaths","del","path","splits","sub","gsub","capture","match","scan","keys","keys_unsorted","map_values","with_entries","tostream","fromstream","truncate_stream","walk","tonumber","implode","explode","ascii","fromjson"]);class Xt{tokens;at=0;constructor(e){this.tokens=e}parse(){if(this.tokens.length===0)_();let e=this.pipe();if(this.at!==this.tokens.length)_();return e}peek(){return this.tokens[this.at]}isOp(e){let r=this.peek();return!!r&&r.t==="op"&&r.v===e}isIdent(e){let r=this.peek();return!!r&&r.t==="ident"&&r.name===e}expectOp(e){if(!this.isOp(e))_();this.at++}pipe(){let e=this.comma();if(this.isIdent("as"))_();if(this.isOp("|"))this.at++,e={k:"pipe",a:e,b:this.pipe()};return e}comma(){let e=this.alt();while(this.isOp(","))this.at++,e={k:"comma",a:e,b:this.alt()};return e}alt(){let e=this.or();if(this.isOp("//"))return this.at++,{k:"alt",a:e,b:this.alt()};return e}or(){let e=this.and();while(this.isIdent("or"))this.at++,e={k:"bool",a:e,b:this.and()};return e}and(){let e=this.cmp();while(this.isIdent("and"))this.at++,e={k:"bool",a:e,b:this.cmp()};return e}cmp(){let e=this.add();for(let r of["==","!=","<=",">=","<",">"])if(this.isOp(r))return this.at++,{k:"bool",a:e,b:this.add()};for(let r of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(r))_();return e}add(){let e=this.mul();while(this.isOp("+")||this.isOp("-"))this.at++,e={k:"arith",a:e,b:this.mul()};return e}mul(){let e=this.unary();while(this.isOp("*")||this.isOp("/")||this.isOp("%"))this.at++,e={k:"arith",a:e,b:this.unary()};return e}unary(){if(this.isOp("-"))return this.at++,{k:"neg",of:this.postfix()};return this.postfix()}objectValue(){let e=this.unary();if(this.isOp("|"))this.at++,e={k:"pipe",a:e,b:this.objectValue()};return e}postfix(){let e=this.primary();for(;;){let r=this.peek();if(!r)return e;if(r.t==="field"){this.at++,e={k:"field",name:r.name,of:e};continue}if(r.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(r.t==="op"&&r.v==="?"){this.at++,e={k:"opt",of:e};continue}if(r.t==="op"&&r.v==="["){e=this.bracket(e);continue}return e}}bracket(e){if(this.expectOp("["),this.isOp("]"))return this.at++,{k:"iter",of:e};if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:e}}let r=this.pipe();if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:e}}return this.expectOp("]"),{k:"index",of:e,key:r}}primary(){let e=this.peek();if(!e)return _();switch(this.at++,e.t){case"dot":return{k:"dot"};case"field":return{k:"field",name:e.name};case"num":return{k:"lit"};case"str":return this.stringNode(e.parts);case"fmt":{if(!ko.has(e.name))_();let r=this.peek();if(r?.t==="str")return this.at++,{k:"fmt",name:e.name,str:this.stringNode(r.parts)};return{k:"fmt",name:e.name}}case"ident":{if(vo.has(e.name))_();if(e.name==="map"||wr.has(e.name)||yr.has(e.name)){let r=[];if(this.isOp("(")){this.at++,r.push(this.pipe());while(this.isOp(";"))this.at++,r.push(this.pipe());this.expectOp(")")}return{k:"call",name:e.name,args:r}}return _()}case"op":{if(e.v==="("){let r=this.pipe();return this.expectOp(")"),r}if(e.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let r=this.pipe();return this.expectOp("]"),{k:"array",of:r}}if(e.v==="{")return this.object();return _()}}return _()}stringNode(e){let r=[];for(let t of e){if(typeof t==="string")continue;r.push(new Xt(xr(t.src)).parse())}return r.length===0?{k:"str",parts:r,text:e.join("")}:{k:"str",parts:r}}object(){let e=[];if(this.isOp("}"))return this.at++,{k:"object",entries:e};for(;;){let r=this.peek();if(!r)_();this.at++;let t;if(r.t==="ident")t=r.name;else if(r.t==="str"){if(r.parts.some((n)=>typeof n!=="string"))_();t=r.parts.join("")}else _();if(this.isOp(":"))this.at++,e.push({key:"static",value:this.objectValue()});else e.push({key:"static",value:{k:"field",name:t}});if(this.isOp(",")){this.at++;continue}return this.expectOp("}"),{k:"object",entries:e}}}}function Yt(e){if(typeof e==="object"&&"union"in e)return e.union.every(Yt);return e==="safe"||typeof e==="object"&&wo.has(e.leaf)}var Ve=(...e)=>e.every(Yt)?"safe":"tainted";function Zt(...e){let r=[];for(let t of e)if(typeof t==="object"&&"union"in t)r.push(...t.union);else r.push(t);return r.length===1?r[0]:{union:r}}function ut(e,r){return typeof e==="object"&&"union"in e?Zt(...e.union.map(r)):r(e)}var ct=(e)=>typeof e==="object"&&("leaf"in e)&&yo.has(e.leaf),J=(e)=>ut(e,(r)=>r==="safe"?"safe":r==="tainted"||ct(r)?"tainted":"unknown");function mr(e){return e.k==="lit"||e.k==="str"&&e.parts.length===0||e.k==="call"&&["true","false","null"].includes(e.name)&&e.args.length===0}function br(e,r,t){return ut(e,(n)=>{if(n==="safe"||n==="tainted")return n;if(ct(n))return"tainted";if(n==="root"&&t.rootScalars.has(r))return"safe";return{leaf:r}})}function E(e,r,t){switch(e.k){case"dot":return r;case"field":return br(e.of?E(e.of,r,t):r,e.name,t);case"iter":return J(E(e.of,r,t));case"index":{let n=E(e.of,r,t);if(e.key.k==="str"&&e.key.text!==void 0)return br(n,e.key.text,t);if(e.key.k==="lit")return J(n);return E(e.key,r,t),"tainted"}case"slice":return ut(E(e.of,r,t),(n)=>n==="root"?"unknown":ct(n)?"tainted":n);case"opt":return E(e.of,r,t);case"lit":return"safe";case"str":return Ve(...e.parts.map((n)=>E(n,r,t)));case"fmt":return e.str?E(e.str,r,t):r;case"array":return e.of?Ve(E(e.of,r,t)):"safe";case"object":return Ve(...e.entries.map((n)=>E(n.value,r,t)));case"pipe":return E(e.b,E(e.a,r,t),t);case"comma":return Zt(E(e.a,r,t),E(e.b,r,t));case"alt":return Zt(E(e.a,r,t),E(e.b,r,t));case"bool":return E(e.a,r,t),E(e.b,r,t),"safe";case"arith":return Ve(E(e.a,r,t),E(e.b,r,t));case"neg":return E(e.of,r,t);case"call":return _o(e,r,t)}}var Sr=(e)=>ut(e,(r)=>r==="root"?"unknown":ct(r)?"tainted":r);function _o(e,r,t){let{name:n,args:s}=e;if(xo.has(n)&&n!=="limit"&&!s.every(mr))_();switch(n){case"map":if(s.length!==1)_();return Ve(E(s[0],J(r),t));case"select":if(s.length!==1)_();return E(s[0],r,t),r;case"limit":if(s.length!==2||!mr(s[0]))_();return E(s[1],r,t);case"first":case"last":if(s.length>1)_();return s.length===1?E(s[0],r,t):J(r);case"min":case"max":return J(r);case"sort_by":case"group_by":case"unique_by":if(s.length!==1)_();return E(s[0],J(r),t),Sr(r);case"min_by":case"max_by":if(s.length!==1)_();return E(s[0],J(r),t),J(r);case"any":case"all":case"isempty":for(let i of s)E(i,"unknown",t);return"safe"}if(wr.has(n))return"safe";if(yr.has(n))return Sr(r);return _()}function kr(e,r={}){if(typeof e!=="string"||!e.trim()||e.length>4096)return!1;try{let t=new Xt(xr(e)).parse();return Yt(E(t,"root",{rootScalars:r.rootScalars??new Set}))}catch(t){if(t instanceof Kt)return!1;return!1}}var ln="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",x={refused:!1},y=(e)=>({refused:!0,rule:e}),Qt=new Set(["additions","assignees","author","baseRefName","baseRefOid","changedFiles","closed","closedAt","createdAt","deletions","files","fullDatabaseId","headRefName","headRefOid","headRepository","headRepositoryOwner","id","isCrossRepository","isDraft","labels","maintainerCanModify","mergeCommit","mergeStateStatus","mergeable","mergedAt","mergedBy","number","potentialMergeCommit","reactionGroups","reviewDecision","reviewRequests","state","title","updatedAt","url"]),Jt=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),vr=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),_r=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),Eo=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),Oo=new Set(["author","committer","id","parents","repository","sha","url"]),Ro=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function Rr(e){let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(n==="\\"){t++;continue}if(n==="'"){let s=e.indexOf("'",t+1);if(s<0)return!1;t=s;continue}if(n==='"'){t++;while(t<e.length&&e[t]!=='"')t+=e[t]==="\\"?2:1;continue}if(n==="{"){r.push({list:!1});continue}if(r.length===0)continue;if(n===","||n==="."&&e[t+1]===".")r[r.length-1].list=!0;else if(n==="}"&&r.pop().list)return!0}return!1}function ke(e){let r="",t=!1,n=0,s=(i)=>e[i]==="`"||e[i]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(e[i+1]??"");while(n<e.length){let i=e[n];if(i==="\\"){r+=e[n+1]??"",n+=2;continue}if(i==="$"&&e[n+1]==="'"){t=!0,r+=i,n++;continue}if(i==="'"){let o=e.indexOf("'",n+1);if(o<0){t=!0,r+=e.slice(n+1);break}r+=e.slice(n+1,o),n=o+1;continue}if(i==='"'){n++;while(n<e.length&&e[n]!=='"'){if(e[n]==="\\"&&/[$`"\\\n]/.test(e[n+1]??"")){r+=e[n+1],n+=2;continue}if(s(n))t=!0;r+=e[n],n++}if(n>=e.length)t=!0;n++;continue}if(s(n)||i==="*"||i==="?"||i==="[")t=!0;r+=i,n++}if(!t&&e.includes("{")&&Rr(e))t=!0;return{value:r,opaque:t,raw:e}}var ae=(e)=>e.slice(e.lastIndexOf("/")+1);function nn(e,r="word"){let t=[],n=!1;for(let s=0;s<e.length;s++){let i=e[s];if(i==="\\"){s++;continue}if(r==="word"&&i==="'"&&!n){let o=e.indexOf("'",s+1);if(o<0)return{bodies:t,complete:!1};s=o;continue}if(r==="word"&&i==='"'){n=!n;continue}if(i==="`"){let o=s+1;while(o<e.length&&e[o]!=="`")o+=e[o]==="\\"?2:1;if(o>=e.length)return{bodies:t,complete:!1};t.push(e.slice(s+1,o)),s=o;continue}if(i==="$"&&e[s+1]==="("){let o=oe(e,s+1);if(o<0)return{bodies:t,complete:!1};t.push(e.slice(s+2,o-1)),s=o-1}}return{bodies:t,complete:!0}}function ve(e,r){let t=new Set(r.values),n={flags:[],positionals:[]},s=(i,o)=>({value:i,opaque:o.opaque,raw:o.raw});for(let i=0;i<e.length;i++){let o=e[i],a=o.value;if(a==="--"){n.positionals.push(...e.slice(i+1));break}if(a.startsWith("--")&&a.length>2){let l=a.indexOf("="),u=l>=0?a.slice(0,l):a;if(l>=0)n.flags.push({name:u,value:s(a.slice(l+1),o),inline:!0});else if(t.has(u)){let c=e[i+1];n.flags.push(c?{name:u,value:c}:{name:u,missing:!0}),i++}else n.flags.push({name:u});continue}if(a.startsWith("-")&&a.length>1){for(let l=1;l<a.length;l++){let u="-"+a[l],c=a.slice(l+1);if(c.startsWith("=")){n.flags.push({name:u,value:s(c.slice(1),o),inline:!0});break}if(!t.has(u)){n.flags.push({name:u});continue}if(c)n.flags.push({name:u,value:s(c,o),inline:!0});else{let f=e[i+1];n.flags.push(f?{name:u,value:f}:{name:u,missing:!0}),i++}break}continue}n.positionals.push(o)}return n}function W(e,...r){let t=!1;for(let n of e.flags){if(!r.includes(n.name))continue;if(!n.inline){t=!0;continue}let s=n.value;t=!s.opaque&&["1","t","T","TRUE","true","True"].includes(s.value)}return t}var te=(e,...r)=>e.flags.filter((t)=>r.includes(t.name)),G=["-R","--repo","-q","--jq","-t","--template","--json"],ue={"pr view":{values:G},"issue view":{values:G},"release view":{values:G},"discussion view":{values:[...G,"--after","-L","--limit","--order"]},"pr list":{values:[...G,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...G,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...G,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...G,"-L","--limit","-O","--order"]},"pr status":{values:G},"issue status":{values:G},"pr checks":{values:[...G,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...G,"--app","--assignee","--author","--author-date","--author-email","--author-name","--base","--checks","--closed","--commenter","--committer","--committer-date","--committer-email","--committer-name","--created","--hash","--head","--interactions","--involves","--label","--language","--limit","-L","--match","--mentions","--merged-at","--milestone","--no-assignee","--no-label","--no-milestone","--no-project","--order","--owner","--parent","--project","--reactions","--review","--review-requested","--reviewed-by","--sort","--state","--team-mentions","--tree","--updated","--visibility","--extension","--filename","--size","--forks","--good-first-issue","--help-wanted-issues","--number-topics","--stars","--topic","--followers","--include-forks","--license"]},"project item-list":{values:["--format","-L","--limit","--owner","-q","--jq","-t","--template","--query","--field","--field-id"]},api:{values:["-X","--method","-H","--header","-f","--raw-field","-F","--field","-q","--jq","-t","--template","-p","--preview","--input","--hostname","--cache"]},group:{values:["-R","--repo"]}},Ao=new Set(["auth","browse","codespace","cs","gist","org","repo","skill","cache","run","workflow","co","agent-task","alias","attestation","completion","config","copilot","extension","ext","extensions","gpg-key","label","licenses","preview","ruleset","secret","ssh-key","variable","help","version","accessibility","actions","environment","exit-codes","formatting","mintty","reference","telemetry"]),To=new Set(["pr","issue","release","discussion","search","project","api","status"]),$o=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),Co=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),Po=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),Io=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function pt(e,r){let t=te(e,"--json"),n=[],s=!1;for(let i of t){if(i.missing){if(r.appendsArgs)s=!0;continue}if(!i.value)continue;if(i.value.opaque)s=!0;n.push(...i.value.value.split(",").map((o)=>o.trim()).filter(Boolean))}return{present:t.length>0,opaque:s,fields:n}}function an(e,r){if(W(e,"--verbose")||te(e,"-t","--template").length>0)return!1;let t=te(e,"-q","--jq");return t.length>0&&t.every((n)=>n.value!==void 0&&!n.value.opaque&&kr(n.value.value,{rootScalars:r}))}function un(e,r,t,n){let s=pt(e,t);if(s.opaque)return y("unclassifiable");if(s.fields.every((i)=>r.has(i)))return x;if(t.debug)return y("debug-traffic");return an(e)?x:y(n)}function ft(e,r,t,n,s){let i=ve(e,ue[r]);if(W(i,"-h","--help"))return x;if(W(i,"-w","--web"))return n.debug?y("debug-traffic"):x;if(s&&W(i,"-c","--comments"))return y("view-comments");if(!pt(i,n).present)return y(n.debug?"debug-traffic":"view-human");return un(i,t,n,"json-composite")}function ee(e,r,t,n){let s=ve(e,ue[r]);if(W(s,"-h","--help"))return x;if(n.debug&&(W(s,"-w","--web")||!pt(s,n).present))return y("debug-traffic");if(W(s,"-w","--web"))return x;return un(s,t,n,"json-composite")}function Wo(e,r){let t=ve(e,ue["pr checks"]);if(W(t,"-h","--help"))return x;if(r.debug)return y("debug-traffic");if(W(t,"-w","--web"))return x;if(!pt(t,r).present)return y("checks-human");return un(t,Ro,r,"checks-json")}function No(e){let r=new Set(ue.group.values);for(let t=0;t<e.length;t++){let n=e[t].value;if(n==="--")return{sub:e[t+1],rest:e.slice(t+2)};if(!n.startsWith("-")||n==="-")return{sub:e[t],rest:[...e.slice(0,t),...e.slice(t+1)]};if(r.has(n))t++}return{rest:e}}function Do(e,r,t){let{sub:n,rest:s}=No(r);if(!n)return t.appendsArgs?y("unclassifiable"):x;if(n.opaque)return y("unclassifiable");let i=n.value;if((e==="pr"?$o:e==="issue"?Co:e==="release"?Po:e==="discussion"?Io:new Set).has(i))return t.debug?y("debug-traffic"):x;if(t.appendsArgs&&!(e==="project"&&i!=="item-list"))return y("unclassifiable");switch(e){case"pr":if(i==="view")return ft(s,"pr view",Qt,t,!0);if(i==="list"||i==="ls")return ee(s,"pr list",Qt,t);if(i==="status")return ee(s,"pr status",Qt,t);if(i==="checks")return Wo(s,t);if(i==="diff"){let a=ve(s,ue["pr diff"]);if(W(a,"-h","--help"))return x;if(t.debug)return y("debug-traffic");return W(a,"--patch")?y("composite-other"):x}return y("unclassifiable");case"issue":if(i==="view")return ft(s,"issue view",Jt,t,!0);if(i==="list"||i==="ls")return ee(s,"issue list",Jt,t);if(i==="status")return ee(s,"issue status",Jt,t);return y("unclassifiable");case"release":if(i==="view")return ft(s,"release view",vr,t,!1);if(i==="list"||i==="ls")return ee(s,"release list",vr,t);return y("unclassifiable");case"discussion":if(i==="view")return ft(s,"discussion view",_r,t,!0);if(i==="list"||i==="ls")return ee(s,"discussion list",_r,t);return y("unclassifiable");case"search":if(i==="prs"||i==="issues")return ee(s,"search",Eo,t);if(i==="commits")return ee(s,"search",Oo,t);if(i==="code"||i==="repos")return t.debug?y("debug-traffic"):x;return y("unclassifiable");case"project":{if(t.debug)return y("debug-traffic");if(i!=="item-list")return x;let a=ve(s,ue["project item-list"]);if(W(a,"-h","--help"))return x;let l=te(a,"--format");if(l.some((u)=>!u.value||u.value.opaque))return y("unclassifiable");if(l.every((u)=>u.value.value!=="json"))return x;return an(a)?x:y("composite-other")}}return y("unclassifiable")}var Ar=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function Lo(e){let r=e.value.trim(),t=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(r);if(t){let i=t[1].toLowerCase(),o=t[2]??"/";if(i==="api.github.com"||/^api\./.test(i))r=o;else if(/^\/api\/v3(?:\/|$)/i.test(o))r=o.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(o))r="graphql";else return null}r=r.replace(/[?#].*$/,"");let n=[],s=[];for(let i of r.split("/")){let o;try{o=decodeURIComponent(i)}catch{return null}for(let a of o.split("/")){if(a===""||a===".")continue;if(a===".."){n.pop(),s.pop();continue}n.push(a.toLowerCase()),s.push(e.opaque&&/[$`]/.test(a)||/[*?[]/.test(a)||Rr(a))}}return{segments:n,opaque:s}}function Ho(e){let r=Lo(e);if(!r)return{kind:"unclassifiable",segments:[]};let{segments:t,opaque:n}=r,s=(l)=>({kind:l,segments:t});if(t.length===1&&t[0]==="graphql")return s("graphql");if(t.length===0)return s(e.opaque?"unclassifiable":"other");if(n[0])return s("unclassifiable");let i,o=[];if(t[0]==="repos")i=t.slice(3),o=n.slice(3);else if(t[0]==="repositories")i=t.slice(2),o=n.slice(2);if(i){if((t[0]==="repos"?n.slice(1,3):n.slice(1,2)).some(Boolean)){let u=n.findIndex(Boolean),c=t.findIndex((f,d)=>d>u&&!n[d]&&Mo.has(f));return s(c<0?"unclassifiable":Er(t.slice(c),n.slice(c)))}return s(Er(i,o))}let a=t[0];if(a==="issues")return s("sensitive");if(a==="user"&&t[1]==="issues")return s("sensitive");if(a==="orgs"&&t[2]==="issues")return s("sensitive");if(a==="search")return s(t[1]==="issues"||t[1]==="commits"?"sensitive":t[1]!==void 0&&n[1]?"unclassifiable":"other");if(a==="events"||a==="networks")return s("sensitive");if((a==="users"||a==="orgs")&&t.slice(2).some((l)=>l==="events"||l==="received_events"||l==="discussions"))return s("sensitive");if((a==="users"||a==="orgs")&&t[2]==="projectsv2"&&t[4]==="items")return s("sensitive");if(a==="orgs"&&t[2]==="hooks"&&t[4]==="deliveries"&&t[5]!==void 0||a==="app"&&t[1]==="hook"&&t[2]==="deliveries"&&t[3]!==void 0)return s("sensitive");if(a==="teams"&&t.includes("discussions"))return s("sensitive");if(a==="projects"&&t.includes("cards"))return s("sensitive");if(n.some(Boolean))return s(t.some((l)=>l==="events"||l==="discussions"||l==="issues")?"sensitive":"unclassifiable");return s("other")}var Mo=new Set([...Ar,"branches","git","actions","hooks","zipball","tarball"]);function Er(e,r){let[t,n]=e;if(t===void 0)return"other";if(r[0])return"unclassifiable";if(t==="issues"&&/^\d+$/.test(n??"")&&e[2]==="labels")return"other";if(Ar.has(t))return"sensitive";if(t==="branches"){if(e.length===1||e.slice(1).some((s)=>s==="protection")||e[e.length-1]==="rename")return"other";return r.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if(t==="git")return n===void 0||n==="commits"||n==="tags"?"sensitive":r[1]?"unclassifiable":"other";if(t==="actions"){if(n===void 0)return"sensitive";if(r[1])return"unclassifiable";if(n==="runs"||n==="jobs"){if(e[e.length-1]==="logs"&&e.length>=4&&!r.some(Boolean))return"download";return"sensitive"}if(n==="workflows"&&e[3]==="runs")return"sensitive";if(n==="artifacts"&&e.length===4)return"download";return"other"}if(t==="hooks"&&e[2]==="deliveries"&&e[3]!==void 0)return"sensitive";if(t==="zipball"||t==="tarball")return"download";return"other"}function Fo(e,r){if(r[0]!=="repos"||r.length<5)return!1;let t=r.slice(3),n=(i)=>/^\d+$/.test(t[i]??""),s=(...i)=>t.length===i.length&&i.every((o,a)=>typeof o==="number"?n(a):t[a]===o);if(e==="DELETE")return s("issues","comments",0)||s("pulls","comments",0)||s("comments",0)||s("issues","comments",0,"reactions",0)||s("pulls","comments",0,"reactions",0)||s("issues",0,"reactions",0)||s("issues",0,"labels")||t.length===4&&t[0]==="issues"&&n(1)&&t[2]==="labels"||s("releases",0)||s("releases","assets",0)||s("actions","runs",0)||s("actions","runs",0,"logs")||s("deployments",0)||s("milestones",0)||s("issues",0,"lock");if(e==="POST")return t.length===4&&t[0]==="actions"&&t[1]==="runs"&&n(2)&&["rerun","rerun-failed-jobs","cancel","force-cancel","approve"].includes(t[3])||s("actions","jobs",0,"rerun")||s("issues",0,"labels");if(e==="PUT")return s("pulls",0,"merge")||s("pulls",0,"update-branch")||s("issues",0,"labels")||s("issues",0,"lock");if(e==="GET")return s("pulls",0,"merge");return!1}function Bo(e){if(e[0]!=="repos"||e.length!==5||!/^\d+$/.test(e[4]))return;if(e[3]==="pulls")return new Set(["commits","comments","review_comments"]);if(e[3]==="issues")return new Set(["comments"]);return}var jo=new Set(["body","bodyText","bodyHTML","bodyUrl","bodyResourcePath","comments","reviews","latestReviews","latestOpinionatedReviews","reviewThreads","url","permalink","summary","text","description","message","messageBody","messageHeadline","commitBody","commitHeadline","annotations","rawDetails","note","diff","readme","payload"]),Go=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function qo(e){let r=[],t=0;while(t<e.length){let n=e[t];if(/[\s,\uFEFF]/.test(n)){t++;continue}if(n==="#"){let o=e.indexOf(`
33
+ `,t);t=o<0?e.length:o+1;continue}if(e.startsWith('"""',t)){let o=t+3;for(;;){let a=e.indexOf('"""',o);if(a<0)return null;if(e[a-1]==="\\"){o=a+3;continue}t=a+3;break}continue}if(n==='"'){let o=t+1;while(o<e.length&&e[o]!=='"'&&e[o]!==`
34
+ `)o+=e[o]==="\\"?2:1;if(e[o]!=='"')return null;t=o+1;continue}let s=/^[_A-Za-z][_0-9A-Za-z]*/.exec(e.slice(t,t+256));if(s){r.push({kind:"name",text:s[0]}),t+=s[0].length;continue}let i=/^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(e.slice(t,t+64));if(i){t+=i[0].length;continue}if(e.startsWith("...",t)){r.push({kind:"punct",text:"..."}),t+=3;continue}if("{}()[]:!$@=|&".includes(n)){r.push({kind:"punct",text:n}),t++;continue}return null}return r}function zo(e){let r=qo(e);if(!r)return!0;let t=[],n="",s=0;for(let i=0;i<r.length;i++){let o=r[i];if(o.kind==="punct"){if(o.text==="(")s++;else if(o.text===")"){if(s--,s<0)return!0}else if(s===0&&o.text==="{")t.push(n),n="";else if(s===0&&o.text==="}"){if(t.pop()===void 0)return!0;n=""}continue}if(s>0)continue;let a=r[i-1];if(a?.kind==="punct"&&(a.text==="@"||a.text==="$"))continue;if(r[i+1]?.kind==="punct"&&r[i+1].text===":")continue;if(o.text==="on"&&a?.kind==="punct"&&a.text==="...")continue;if(a?.kind==="name"&&a.text==="on"){n=o.text;continue}if(t.length===0){n=o.text;continue}if(jo.has(o.text)||/(?:Url|URL|HTML|Html)$/.test(o.text))return!0;if(o.text==="title"&&t.some((l)=>Go.has(l)))return!0;n=o.text}return s!==0||t.length!==0}function Uo(e,r){let t=ve(e,ue.api);if(W(t,"-h","--help"))return x;let n=t.positionals[0];if(!n)return r.appendsArgs?y("unclassifiable"):x;let s=Ho(n),i=te(t,"-X","--method"),o=i[i.length-1],a=te(t,"-f","--raw-field","-F","--field","--input"),l=o?o.value&&!o.value.opaque?o.value.value.toUpperCase():"?":a.length>0?"POST":"GET",u=Fo(l,s.segments),c=x;if(s.kind==="unclassifiable")c=y("unclassifiable");else if(s.kind==="sensitive"&&!u)c=y("api-rest");else if(s.kind==="graphql")c=Vo(t);if(r.debug||W(t,"--verbose")){if(s.kind==="download"&&!c.refused)c=y("api-rest");if(c.refused)return r.debug?y("debug-traffic"):c;return x}if(r.appendsArgs&&s.kind!=="other"&&s.kind!=="download")return y("unclassifiable");if(!c.refused||W(t,"--silent"))return x;if(an(t,Bo(s.segments)))return x;return c}function Vo(e){if(te(e,"--input").length>0)return y("unclassifiable");let r=te(e,"-f","--raw-field","-F","--field"),t=r.filter((n)=>n.value&&/^query=/.test(n.value.value));if(t.length===0||r.some((n)=>!n.value))return y("unclassifiable");for(let n of t){let s=n.value.value.slice(6);if((n.name==="-F"||n.name==="--field")&&s.startsWith("@")||n.value.opaque)return y("unclassifiable");if(zo(s))return y("api-graphql")}return x}function ht(e,r){let t=0;while(t<e.length&&e[t].value.startsWith("-")&&!e[t].opaque){if(["--help","-h","--version"].includes(e[t].value))return x;t++}if(t>=e.length)return r.appendsArgs?y("unclassifiable"):x;let n=e[t],s=e.slice(t+1);if(n.opaque)return y("unclassifiable");switch(n.value){case"pr":case"issue":case"release":case"discussion":case"search":case"project":return Do(n.value,s,r);case"api":return Uo(s,r);case"status":return s.length>0&&s.every((i)=>i.value==="-h"||i.value==="--help")?x:y("composite-other");case"help":case"version":return x;case"cs":case"codespace":{let i=s.findIndex((o)=>o.value==="--");if(s.some((o)=>o.value==="ssh")&&i>=0&&i+1<s.length){let o=V(s.slice(i+1).map((a)=>a.value).join(" "),r.depth+1,r.debug);if(o.refused)return o}break}}if(!Ao.has(n.value))return y("unclassifiable");if(r.debug)return y("debug-traffic");return x}var gt=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","fish"]),Zo=new Set(["su","runuser","script","flock"]),Ko=new Set(["secrets","op","unbuffer","caffeinate","chronic","strace","ltrace","firejail","bwrap","nsenter","unshare","chroot","sg","retry","parallel","doppler","aws-vault","dotenv","direnv","faketime","taskset","numactl","cgexec","systemd-run","docker","podman","kubectl","mise","asdf","rtx","devbox","gosu","su-exec","setpriv","pkexec","with-contenv","uv","poetry","pipenv","npx","bunx","pnpm","yarn","nix","nix-shell","infisical","chamber","envchain","dotenvx","teller","vault","chrt","coproc","prlimit","ionice","cpulimit","trickle","proxychains","proxychains4","torsocks","tsocks","catchsegv","valgrind"]),Xo=new Map([["bun",["x","exec"]],["npm",["exec","x"]],["deno",["run"]]]),Yo=new Set(["-I","-L","-l","-n","-P","-s","-d","-E","-e","-a","--arg-file","--delimiter","--max-args","--max-lines","--max-procs","--max-chars","--replace","--eof","--process-slot-var"]),Qo=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),dt=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/,Jo=/^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/,el=6;function Or(e,r){let t,n;for(let s of e){let i=Jo.exec(s.value);if(!i)continue;let o={...s,value:i[2]};if(i[1]==="GH_DEBUG")t=o;else if(i[1]==="DEBUG")n=o}if(t)return t.opaque||!["","0","false","no"].includes(t.value);if(n&&(n.opaque||["1","true","yes","api"].includes(n.value)))return!0;return r}function cn(e){let r=P(e),t=0;return{segments:r.segments.map((s)=>{let i=s.words[0],o=e.slice(t,i.start);return t=s.words[s.words.length-1].end,{words:s.words,redirects:s.redirects,sepBefore:o}}),trustworthy:r.trustworthy}}var Tr=(e)=>/(?:^|[^|])\|&?$/.test(e.trim());function rn(e,r){if(!gt.has(e))return!1;if(fn(r))return!1;for(let t=0;t<r.length;t++){let n=r[t].value;if(n==="--")return t+1>=r.length;if(n==="-"||n==="-s")return!0;if(/^[-+][A-Za-z]*[oO]$/.test(n)){t++;continue}if(!n.startsWith("-")&&!n.startsWith("+"))return!1}return!0}function sn(e){let{segments:r}=cn(e.trim());if(r.length!==1)return null;let t=r[0],n=L(t);if(n<0)return null;let s=ae(ke(t.words[n].text).value),i=t.words.slice(n+1).filter((o,a)=>!t.redirects.has(a+n+1)).map((o)=>ke(o.text));if(s==="echo")return i.filter((o,a)=>!(a===0&&/^-[neE]+$/.test(o.value))).map((o)=>o.value).join(" ");if(s==="printf"){let[o,...a]=i.filter((u)=>u.value!=="--");if(!o)return null;let l=0;return o.value.replace(/\\n/g,`
35
+ `).replace(/%s/g,()=>a[l++]?.value??"")+(l<a.length?" "+a.slice(l).map((u)=>u.value).join(" "):"")}if(s==="cat"){let o=e.indexOf("<<");if(o<0)return null;let a=we(e,o),l=e.indexOf(`
36
+ `,o);if(!a||l<0)return null;let u=st(e,l,[a]);if(u<0)return null;let c=e.slice(l+1,u);return c.slice(0,c.lastIndexOf(a.delimiter)).replace(/\n$/,"")}return null}function en(e,r,t){for(let n of nn(e).bodies){let s=sn(n);if(s===null)continue;let i=V(s,r+1,t.debug);if(i.refused)return i}return x}function V(e,r=0,t=!1){if(typeof e!=="string"||!e.trim())return x;if(r>el)return dt.test(e)?y("unclassifiable"):x;let{segments:n,trustworthy:s}=cn(e);if(!s)return dt.test(e)?y("unclassifiable"):x;let i=t,o=(a)=>V(a,r+1,i);for(let a of rl(e)){if(a.runsBody){let l=o(a.body);if(l.refused)return l}if(!a.quoted){let l=nn(a.body,"heredoc");if(!l.complete&&dt.test(a.body))return y("unclassifiable");for(let u of l.bodies){let c=o(u);if(c.refused)return c}}}for(let a=0;a<n.length;a++){let l=n[a];for(let b of l.words){let R=nn(b.text);if(!R.complete&&dt.test(b.text))return y("unclassifiable");for(let H of R.bodies){let M=o(H);if(M.refused)return M}}let u=L(l),c=l.words.map((b,R)=>({word:ke(b.text),redirect:l.redirects.has(R)})),f=c.slice(0,u<0?c.length:u).map((b)=>b.word),d=u>=0?ae(c[u].word.value):"";if(u<0||["export","declare","typeset","readonly","local"].includes(d)){if(i=Or([...f,...c.slice(u+1).map((b)=>b.word)],i),u<0)continue}let h=Or(f,i),p=c.slice(u+1).filter((b)=>!b.redirect).map((b)=>b.word),m=c.slice(u+1).filter((b)=>b.redirect).map((b)=>b.word),O=c[u].word,A=ae(O.value),I={depth:r,appendsArgs:!1,debug:h};if(u>0&&c[u-1].word.value==="function"){let b=p.filter((H)=>!["{","()","(",")"].includes(H.value)),R=on(b,I);if(R.refused)return R;continue}if(a>0&&Tr(l.sepBefore)&&rn(A,p)){let b=n[a-1],R=tl(e,b),H=R===null?null:sn(R);if(H!==null){let M=V(H,r+1,h);if(M.refused)return M}}let j=n[a+1];if(j&&/<\(\s*$/.test(j.sepBefore)&&(gt.has(A)||A==="source"||A===".")){let b=j.words[0].start-j.sepBefore.length+j.sepBefore.lastIndexOf("("),R=oe(e,b),H=R<0?null:sn(e.slice(b+1,R-1));if(H!==null){let M=V(H,r+1,h);if(M.refused)return M}}let k=$r(A,O,p,m,l.words.slice(0,u+1),I);if(k.refused)return k}return x}function tl(e,r){let t=r.words[0],n=r.words[r.words.length-1];return t&&n?e.slice(t.start,n.end):null}function nl(e){let r=ae(e.value);return/[$`]/.test(r)||r===""?void 0:r}function $r(e,r,t,n,s,i){let o=i.depth,a=(l)=>V(l,o+1,i.debug);if(r.opaque){let l=nl(r);if(l===void 0){let u=t.find((f)=>!f.value.startsWith("-")),c=ht(t,i);if(!c.refused)return x;return c.rule!=="unclassifiable"||u!==void 0&&!u.opaque&&To.has(u.value)?c:x}e=l}if(e==="gh")return ht(t,i);if(gt.has(e)){let l=fn(t);if(l){let u=a(l.value);if(u.refused||!l.opaque)return u;return en(l.raw,o,i)}for(let u of n){let c=a(u.value);if(c.refused)return c;if(u.opaque){let f=en(u.raw,o,i);if(f.refused)return f}}return x}if(Zo.has(e)){let l=t.findIndex((c)=>c.value==="-c"||c.value==="--command"||/^-[A-Za-z]*c$/.test(c.value)),u=l>=0?t[l+1]:void 0;return u?a(u.value):tn(t,i)}if(e==="eval"||e==="watch"){let l=t;if(e==="watch"){let c=0;while(c<t.length&&t[c].value.startsWith("-")){if(t[c].value==="--"){c++;break}if(["-n","--interval","-q","--equexit"].includes(t[c].value))c++;c++}l=t.slice(c)}let u=a(l.map((c)=>c.value).join(" "));if(u.refused)return u;for(let c of l){let f=en(c.raw,o,i);if(f.refused)return f}return x}if(e==="env")return a(Be([...s.map((l)=>ke(l.text).value),...t.map((l)=>l.value)]));if(e==="ssh"){let l=0;for(;l<t.length;l++){let f=t[l].value;if(!f.startsWith("-"))break;if(Qo.has(f))l++}let u=t.slice(l+1);if(u[0]?.value==="--")u.shift();let c=u.map((f)=>f.value).join(" ");return c?a(c):x}if(e==="xargs"){let l=0,u=!1;for(;l<t.length;l++){let c=t[l].value;if(c==="--"){l++;break}if(!c.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(c))u=!0;if(Yo.has(c))l++}return on(t.slice(l),{depth:o,appendsArgs:!u,debug:i.debug})}if(e==="find"){for(let l=0;l<t.length;l++){if(!["-exec","-execdir","-ok","-okdir"].includes(t[l].value))continue;let u=l+1;while(u<t.length&&t[u].value!==";"&&t[u].value!=="+")u++;let c=on(t.slice(l+1,u),i);if(c.refused)return c;l=u}return x}if(Ko.has(e))return tn(t,i);if(Xo.get(e)?.includes(t[0]?.value??""))return tn(t.slice(1),i);return x}function on(e,r){if(e.length===0)return x;let t=ae(e[0].value);if(t==="gh")return ht(e.slice(1),r);if(gt.has(t)){let n=fn(e.slice(1));return n?V(n.value,r.depth+1,r.debug):x}return $r(t,e[0],e.slice(1),[],[],r)}function tn(e,r){let t=e.findIndex((n)=>!n.opaque&&ae(n.value)==="gh"&&(n.value==="gh"||n.value.includes("/")));return t>=0?ht(e.slice(t+1),r):x}function fn(e){for(let r=0;r<e.length;r++){let t=e[r].value;if(t==="--")return;if(!t.startsWith("-")&&!t.startsWith("+"))return;if(t==="-c"||/^-[A-Za-z]+$/.test(t)&&t.includes("c"))return e.slice(r+1).find((n)=>!n.value.startsWith("-")||n.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test(t))r++}return}function rl(e){let r=[],t=0;for(;;){let n=e.indexOf("<<",t);if(n<0)break;if(t=n+2,e[n+2]==="<"||n>0&&e[n-1]==="<"){t=n+3;continue}let s=we(e,n);if(!s)continue;let i=e.lastIndexOf(`
37
+ `,n)+1,o=e.indexOf(`
38
+ `,n);if(o<0)continue;let a=st(e,o,[s]),l=a<0?e.slice(o+1):e.slice(o+1,a),u=a<0?l:l.slice(0,Math.max(0,l.lastIndexOf(s.delimiter))).replace(/\n$/,""),c=e.slice(i,n)+" HEREDOC_OPERATOR "+e.slice(s.end,o);r.push({body:u,runsBody:sl(c),quoted:s.quoted})}return r}function sl(e){let{segments:r}=cn(e),t=r.findIndex((a)=>a.words.some((l)=>l.text==="HEREDOC_OPERATOR"));if(t<0)return!1;let n=(a)=>{let l=L(a);if(l<0)return{verb:"",args:[]};let u=a.words.slice(l+1).filter((c)=>c.text!=="HEREDOC_OPERATOR").map((c)=>ke(c.text));return{verb:ae(ke(a.words[l].text).value),args:u}},{verb:s,args:i}=n(r[t]);if(s==="ssh"||rn(s,i))return!0;if((s==="source"||s===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(i[0]?.value??""))return!0;let o=r[t+1];if(s==="cat"&&o&&Tr(o.sepBefore)){let a=n(o);return a.verb==="ssh"||rn(a.verb,a.args)}return!1}var il=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function Cr(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:ln}}}var ol=new Set(["Bash","Monitor"]);function Pr(e){if(e?.hook_event_name!=="PreToolUse"||!ol.has(e.tool_name??""))return{continue:!0};let r=he(e);if(!r.trim())return{continue:!0};try{return V(r).refused?Cr():{continue:!0}}catch{return il.test(r)?Cr():{continue:!0}}}function hn(e){if(e!=="trash-guard"&&e!=="workspace-repos-guard")throw Error("Invalid safety capability")}function Wr(e,r){hn(e);let t=e,n=JSON.parse(r);if(!n||Array.isArray(n)||n.hook_event_name!=="PreToolUse"||typeof n.tool_name!=="string"||!n.tool_input||typeof n.tool_input!=="object"||Array.isArray(n.tool_input)||typeof n.cwd!=="string"||!Ir(n.cwd))throw Error("Invalid safety input");if(n.tool_name==="Bash"&&typeof n.tool_input.command!=="string")throw Error("Invalid shell input");if(n.tool_name==="Monitor"&&n.tool_input.command!==void 0&&typeof n.tool_input.command!=="string")throw Error("Invalid monitor input");let s=n.hasna_execution;if(s!==void 0&&(!s||Object.keys(s).sort().join()!=="agent,schema"||s.schema!=="hasna.hooks.execution.v1"||typeof s.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(s.agent)))throw Error("Invalid execution capability");let i=s===void 0?void 0:{runtime:process.execPath,home:dn(),path:process.env.PATH,agent:s.agent};if(i&&(!Ir(i.runtime)||!i.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(n.tool_name)){if(n.tool_input.command!==void 0&&n.tool_input.patch!==void 0&&n.tool_input.command!==n.tool_input.patch)throw Error("Conflicting patch aliases");let A=n.tool_input.command??n.tool_input.patch;if(typeof A!=="string")throw Error("Invalid patch input");n.tool_input={...n.tool_input,command:A,patch:A}}let o=n.tool_name==="Monitor",a=n.tool_name==="Bash"||o&&typeof n.tool_input.command==="string",l=o&&a?{...n,tool_name:"Bash"}:n,u=(A)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:A}}),c=gr(l).output,f=Pr(l),d=l.tool_input.command,h=()=>Se(d,{home:dn(),cwd:n.cwd}).handoffHits.length>0,p=a&&(h()||!!ie(d,h)),m=t==="trash-guard"&&(!o||a)?zn(l,{home:dn(),cwd:n.cwd,findTrash:Qe,inspectTrash:Pe,execution:i}):{continue:!0};if(o&&m.hookSpecificOutput?.permissionDecision==="allow")m=u("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let O=c.decision==="block"?u(c.reason):f.hookSpecificOutput?f:p?u("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):m;return JSON.stringify({verdict:"continue"in O?null:O})}var Nr=process.argv[1];hn(Nr);process.stdout.write(Wr(Nr,await Bun.stdin.text()));