@hasna/hooks 0.12.17 → 0.12.19

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,28 +1,38 @@
1
1
  // @bun
2
- import{homedir as $1}from"os";import{isAbsolute as F2}from"path";import{isAbsolute as G3,join as MZ,normalize as U3,resolve as W3,sep as D0}from"path";import{dirname as HZ,isAbsolute as lZ,join as V0,resolve as ZZ}from"path";import{accessSync as C2,closeSync as q2,constants as wZ,fstatSync as P2,lstatSync as DZ,openSync as O2,readFileSync as L2,readlinkSync as y2,readSync as A2,realpathSync as G0,statSync as U0}from"fs";import{spawnSync as R2}from"child_process";var X1={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 CZ(Z){return Z===0||Z===process.getuid?.()}function gZ(Z,J=!1){let $=Z;for(let z=0;z<32;z++){if(!lZ($)||$.length>4096||!qZ("/"))return!1;let Y=$.split("/"),Q=Y.pop();if(!Q||Q==="."||Q==="..")return!1;let X="/";for(let B of Y){if(!B||B===".")continue;if(B===".."){X=HZ(X);continue}let M=V0(X,B),V=DZ(M);if(J&&M==="/bin"&&V.isSymbolicLink()&&V.uid===0){let G=G0(M);if(!qZ(G))return!1;X=G;continue}if(!V.isDirectory()||!CZ(V.uid)||V.mode&18)return!1;X=M}let H=V0(X,Q),K=DZ(H);if(!CZ(K.uid))return!1;if(K.isSymbolicLink()){let B=y2(H);$=lZ(B)?B:X+"/"+B;continue}return K.isFile()&&Boolean(K.mode&73)&&!(K.mode&18)}return!1}function v2(Z){if(!lZ(Z)||ZZ(Z)!==(Z.replace(/\/+$/,"")||"/"))return!1;for(let J=ZZ(Z);;J=HZ(J)){try{return DZ(J),qZ(J)}catch($){if($.code!=="ENOENT")return!1}if(HZ(J)===J)return!1}}function b2(Z,J){let $=O2(Z,wZ.O_RDONLY|wZ.O_NONBLOCK|wZ.O_NOFOLLOW),z;try{if(!P2($).isFile())return!1;let Q=Buffer.alloc(256),X=A2($,Q,0,Q.length,0);z=Q.subarray(0,X).toString("utf8").split(`
3
- `)[0]}finally{q2($)}let Y=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(z);if(Y&&Y[1]!=="/usr/bin/env")return gZ(Y[1],!0);if(z!=="#!/usr/bin/env bun"||!gZ("/usr/bin/env",!0))return!1;for(let Q of J.split(":").slice(0,64)){if(!v2(Q))return!1;let X=ZZ(Q,"bun");try{if(!U0(X).isFile())continue;C2(X,wZ.X_OK)}catch{continue}return gZ(X,!0)}return!1}function qZ(Z){let J=Z;for(;;){let $=DZ(J);if(!$.isDirectory()||!CZ($.uid)||($.mode&18)!==0)return!1;let z=HZ(J);if(z===J)return!0;J=z}}function PZ(Z=process.env){let J=Z.PATH??"",$=Date.now()+2000,z="missing",Y=(Q)=>{if(z==="missing"||z==="unrecognized_package"||Q.startsWith("unsafe_"))z=Q};for(let Q of J.split(":").slice(0,64)){if(!lZ(Q)||Date.now()>=$)continue;let X=ZZ(Q,"trash");try{let H=U0(X);if(!H.isFile()||!CZ(H.uid)||(H.mode&73)===0||(H.mode&18)!==0){Y("unsafe_executable");continue}let K=G0(X);if(!qZ(ZZ(Q))||!qZ(HZ(K))){Y("unsafe_directory");continue}if(!gZ(X)){Y("unsafe_directory");continue}let B=ZZ(HZ(K),"../.."),M=V0(B,"package.json"),V=U0(M);if(!V.isFile()||!CZ(V.uid)||V.size>16384||(V.mode&18)!==0||DZ(M).isSymbolicLink()){Y("unsafe_manifest");continue}let G=JSON.parse(L2(M,"utf8"));if(G.name!=="@hasna/trash"||typeof G.version!=="string"||typeof G.bin?.trash!=="string"||G0(ZZ(B,G.bin.trash))!==K){Y("unrecognized_package");continue}try{if(!b2(K,J)){Y("unsafe_interpreter");continue}}catch{Y("unsafe_interpreter");continue}let U=$-Date.now();if(U<=0){Y("identity_failed");break}let j=R2(X,["--identity"],{encoding:"utf8",timeout:U,maxBuffer:2048,env:{PATH:J},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:X,version:G.version};Y("unsupported_protocol")}catch{}}return{ok:!1,code:z}}function uZ(Z=process.env){let J=PZ(Z);return J.ok?J.path:null}function BZ(Z){let J=Z.tool_input?.command;return typeof J==="string"?J:""}var K1=["/","/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 LZ=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,p=(Z)=>Z.split("/").pop()??"";function mZ(Z){let J=Z.startsWith("~")?Z.slice(1).split("/",1)[0]:"";if(J&&!/['"\\]/.test(J))return!0;let $=null,z=0;for(let Y=0;Y<Z.length;Y++){let Q=Z[Y];if($==="'"){if(Q==="'")$=null;continue}if(Q==="\\"){Y++;continue}if($==='"'){if(Q==='"')$=null;continue}if(Q==="'"||Q==='"')$=Q;else if(Q==="$"&&Z[Y+1]==="{")z++,Y++;else if(Q==="}"&&z>0)z--;else if(Q==="{"||Q==="}")return!0}return!1}var W0=64;function H1(Z,J){let $=0;for(let z=J;z<Z.length;z++)if(Z[z]==="\\")z++;else if(Z[z]==="{")$++;else if(Z[z]==="}"&&--$===0)return z;return Z.length-1}function E2(Z){let J=Z.match(/^([-+]?\d+)\.\.([-+]?\d+)(?:\.\.([-+]?\d+))?$/),$=J?null:Z.match(/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([-+]?\d+))?$/),z=J??$;if(!z)return null;let Y=J?Number(z[1]):z[1].charCodeAt(0),Q=J?Number(z[2]):z[2].charCodeAt(0),X=Math.abs(Number(z[3]??1))||1;if(!Number.isSafeInteger(Y)||!Number.isSafeInteger(Q)||!Number.isSafeInteger(X))return"overflow";if(Math.floor(Math.abs(Q-Y)/X)+1>W0)return"overflow";let H=J&&(/^[-+]?0\d/.test(z[1])||/^[-+]?0\d/.test(z[2]))?Math.max(z[1].length,z[2].length):0,K=[];for(let B=Y;Y<=Q?B<=Q:B>=Q;B+=Y<=Q?X:-X)if(!J)K.push(String.fromCharCode(B));else K.push(B<0?`-${String(-B).padStart(H-1,"0")}`:String(B).padStart(H,"0"));return K}function S2(Z){let J=null,$=0;for(let z=0;z<Z.length;z++){let Y=Z[z];if(J==="'"){if(Y==="'")J=null;continue}if(Y==="\\"){z++;continue}if(J==='"'){if(Y==='"')J=null;continue}if(Y==="'"||Y==='"')J=Y;else if(Y==="$"&&Z[z+1]==="{")z=H1(Z,z+1);else if(Y==="{"){if(++$>W0)return"overflow";let Q=null,X=0,H=!0,K=[];for(let B=z;B<Z.length;B++){let M=Z[B];if(Q==="'"){if(M==="'")Q=null;continue}if(M==="\\"){H=!1,B++;continue}if(Q==='"'){if(M==='"')Q=null;continue}if(M==="'"||M==='"')Q=M,H=!1;else if(M==="$"&&Z[B+1]==="{")B=H1(Z,B+1),H=!1;else if(M==="{")X++;else if(M===","&&X===1)K.push(B);else if(M==="}"&&--X===0){if(K.length>0){let G=[z,...K,B];return{open:z,close:B,parts:G.slice(0,-1).map((U,j)=>Z.slice(U+1,G[j+1]))}}let V=H?E2(Z.slice(z+1,B)):null;if(V==="overflow")return V;if(V)return{open:z,close:B,parts:V};break}}}}return null}function $Z(Z){if(Z.length>4096&&Z.includes("{"))return null;let J=S2(Z);if(J===null)return[Z];if(J==="overflow")return null;let $=[];for(let z of J.parts){let Y=$Z(Z.slice(0,J.open)+z+Z.slice(J.close+1));if(Y===null||$.push(...Y)>W0)return null}return $}var W={arg:"none"},_={arg:"value"},OZ={arg:"optional"},d={arg:"none",effect:"lookup"},q={arg:"none",effect:"refuse"},n={help:q,version:q},f2=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,j0={timeout:{short:{k:_,s:_,v:W},long:{"kill-after":_,signal:_,verbose:W,foreground:W,"preserve-status":W,...n},positionals:[f2]},env:{short:{i:W,"0":W,v:W,u:_,a:_,C:q,S:q},long:{"ignore-environment":W,null:W,debug:W,unset:_,argv0:_,chdir:q,"split-string":q,"block-signal":OZ,"default-signal":OZ,"ignore-signal":OZ,"list-signal-handling":q,...n},env:!0},nice:{short:{n:_},long:{adjustment:_,...n},numericOption:!0},nohup:{short:{},long:{...n}},command:{short:{p:W,v:d,V:d},long:{}},exec:{short:{c:W,l:W,a:_},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:_,o:_,e:_},long:{input:_,output:_,error:_,...n}},time:{short:{p:W,a:W,q:W,v:W,f:_,o:q,V:q},long:{portability:W,append:W,quiet:W,verbose:W,format:_,output:q,...n}},ionice:{short:{c:_,n:_,t:W,p:q,P:q,u:q,h:q,V:q},long:{class:_,classdata:_,ignore:W,pid:q,pgid:q,uid:q,...n}},setsid:{short:{c:W,f:W,w:W,h:q,V:q},long:{ctty:W,fork:W,wait:W,...n}}},k2=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function x2(Z,J,$){let z=!1,Y=(Q)=>{if(!Q||Q.effect==="refuse")return!1;if(Q.effect==="lookup")z=!0;return!0};while($<J.length){let Q=J[$];if(Q.opaque)return null;let X=Q.text;if(X==="--"){$++;break}if(X==="-"&&Z.env){$++;continue}if(!X.startsWith("-")||X==="-")break;if(Z.numericOption&&/^-[-+]?\d+$/.test(X)){$++;continue}if(X.startsWith("--")){let H=X.indexOf("="),K=H<0?X.slice(2):X.slice(2,H),B=Object.keys(Z.long),M=B.includes(K)?[K]:B.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"&&H>=0)return null;if(V.arg==="value"&&H<0){let G=J[++$];if(!G||G.opaque)return null}$++;continue}for(let H=1;H<X.length;H++){let K=Z.short[X[H]];if(!Y(K))return null;if(K.arg==="value"){if(H===X.length-1){let B=J[++$];if(!B||B.opaque)return null}break}}$++}if(z)return-1;for(let Q of Z.positionals??[]){let X=J[$];if(!X||X.opaque||!Q.test(X.text))return null;$++}if(Z.env||Z.assignments){for(;$<J.length&&LZ.test(J[$].text);$++)if(J[$].opaque)return null}return $}function JZ(Z,J=j0){let $=0;while($<Z.length&&(LZ.test(Z[$].text)||k2.has(Z[$].text)))$++;for(let z=0;z<16;z++){if($>=Z.length)return{index:-1};if(Z[$].opaque)return z===0?{index:$}:null;let Y=Object.hasOwn(J,p(Z[$].text))?J[p(Z[$].text)]:void 0;if(!Y)return{index:$};let Q=x2(Y,Z,$+1);if(Q===null)return null;if(Q<0)return{index:-1};$=Q}return null}function h2(Z){return/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred|trash)(?![A-Za-z0-9_.-])/.test(Z)}var F0=(Z)=>Z.split("/").pop()??"",N0={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}},G1=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,w2=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),g2=new Set(["ssh","scp","sftp"]),l2=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),B1=new Set(["proxycommand","localcommand","knownhostscommand"]),u2=/(?:`|\$\()|\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)/,m2=/[|>]|\b(?:system|getline|close|fflush|print\w*\s*>>?)/;function U1(Z){if(h2(Z.text))return!1;if(Z.kind==="awk")return!m2.test(Z.text);if(Z.kind==="c-interp")return!u2.test(Z.text);return!1}function p2(Z,J,$,z){let Y=N0[Z]??(G1.test(Z)?N0[Z.replace(/[0-9.]+$/,"")]:void 0);if(!Y)return null;let Q=[],X=!1,H=(K)=>{if(K+1>=J.length||z(K+1))return X=!0,K;return Q.push({text:J[K+1],kind:"c-interp"}),K+1};for(let K=$+1;K<J.length;K++){let B=J[K];if(B==="--")break;if(!B.startsWith("-")||B==="-")break;if(B.startsWith("--")){let V=B.indexOf("="),G=V<0?B:B.slice(0,V);if(Y.long.has(G))if(V>=0)Q.push({text:B.slice(V+1),kind:"c-interp"});else K=H(K);continue}let M=B.slice(1);for(let V=0;V<M.length;V++){if(!Y.letters.has(M[V]))continue;if(V<M.length-1)Q.push({text:M.slice(V+1),kind:"c-interp"});else K=H(K);break}}if(Q.length===0&&!X)return null;return{programs:Q,unresolved:X}}function c2(Z,J,$){let z=[],Y=!1,Q=J+1;for(;Q<Z.length;Q++){let X=Z[Q];if(X==="--"){Q++;break}if(!X.startsWith("-")||X==="-")break;if(X==="-e"||X.startsWith("-e")){let H=X==="-e"?null:X.slice(2);if(H!==null)z.push({text:H,kind:"awk"});else if(Q+1<Z.length&&!$(Q+1))z.push({text:Z[++Q],kind:"awk"});else Y=!0}else if(X==="-f"||X.startsWith("-f")){if(Y=!0,X==="-f")Q++}else if(X==="-v"||X.startsWith("-v")){if(X==="-v")Q++}}if(z.length===0&&!Y){if(Q<Z.length)if($(Q))Y=!0;else z.push({text:Z[Q],kind:"awk"})}return{programs:z,unresolved:Y}}function i2(Z,J,$){let z=Z[J],Y,Q=J;if(z==="-o"){if(J+1>=Z.length)return{value:null,next:J};if($(J+1))return{value:null,next:J+1};Y=Z[J+1],Q=J+1}else Y=z.slice(2);return{value:Y,next:Q}}function d2(Z,J,$){let z=[],Y=!1;for(let Q=J+1;Q<Z.length;Q++){let X=Z[Q];if(X==="--")break;if(!X.startsWith("-")||X==="-")break;if(X.startsWith("--"))continue;if(X==="-o"||X.startsWith("-o")){let{value:K,next:B}=i2(Z,Q,$);if(Q=B,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(B1.has(G))z.push({text:U,kind:"shell"});continue}if(X==="-F"||X.startsWith("-F")){if(Y=!0,X==="-F")Q++;continue}if(X==="-S"||X.startsWith("-S")){let K=X==="-S"?Q+1<Z.length&&!$(Q+1)?Z[++Q]:null:X.slice(2);if(K===null)Y=!0;else z.push({text:K,kind:"shell"});continue}let H=X.slice(1);for(let K=0;K<H.length;K++){if(!l2.has(H[K]))continue;if(K<H.length-1)break;if(H[K]==="o"||H[K]==="F"||H[K]==="S"){if(Q+1<Z.length){let B=Z[Q+1];if(H[K]==="o")if(!$(Q+1)){let M=B.indexOf("="),V=M>=0?M:B.search(/\s/),G=(V>=0?B.slice(0,V):B).trim().toLowerCase();if(B1.has(G))z.push({text:V>=0?B.slice(V+1).trim():"",kind:"shell"})}else Y=!0;else if(H[K]==="F")Y=!0;else if(!$(Q+1))z.push({text:B,kind:"shell"});Q++}}else if(Q+1<Z.length)Q++}}return{programs:z,unresolved:Y}}function s2(Z,J,$){let z=[],Y=!1,Q=!1;for(let X=J+1;X<Z.length;X++){let H=Z[X];if(H==="--")break;if(H==="-e"||H==="--rsh")if(Q=!0,X+1<Z.length&&!$(X+1))z.push({text:Z[++X],kind:"shell"});else Y=!0;else if(H.startsWith("--rsh="))Q=!0,z.push({text:H.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(H)&&H.length>2&&!H.startsWith("--"))Q=!0,z.push({text:H.slice(H.indexOf("e")+1),kind:"shell"})}return Q?{programs:z,unresolved:Y}:null}var n2=/^(?:true|false|yes|no|on|off|1|0|)$/i,a2=[/^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 W1(Z,J){let $=Z.toLowerCase(),z=(Y)=>Y===void 0?{kind:"unresolved"}:{kind:"command",text:Y};if(/^alias\./.test($))return J!==void 0&&J.trimStart().startsWith("!")?z(J.trimStart().slice(1)):{kind:"unresolved"};if(/^pager\./.test($)||$==="core.fsmonitor")return J!==void 0&&n2.test(J)?{kind:"harmless"}:z(J);if($==="core.gitproxy")return J!==void 0&&/^none(?:\s+for\s+\S+)?$/.test(J)?{kind:"harmless"}:z(J?.replace(/\s+for\s+\S+$/,""));if(/^submodule\..+\.update$/.test($))return J!==void 0&&J.trimStart().startsWith("!")?z(J.trimStart().slice(1)):J===void 0?{kind:"unresolved"}:{kind:"harmless"};if(/^sendemail\.(?:.+\.)?smtpserver$/.test($))return J!==void 0&&!J.startsWith("/")?{kind:"harmless"}:z(J);if(/^credential\.(?:.+\.)?helper$/.test($)){if(J==="")return{kind:"harmless"};if(J===void 0)return{kind:"unresolved"};let Y=J.trimStart();return z(Y.startsWith("!")?Y.slice(1):Y.startsWith("/")?Y:`git credential-${Y}`)}if(a2.some((Y)=>Y.test($)))return z(J);if($==="core.hookspath")return J==="/dev/null"?{kind:"harmless"}:{kind:"unresolved"};if($==="include.path"||/^includeif\..+\.path$/.test($))return{kind:"unresolved"};if($==="protocol.allow")return J!==void 0&&/^(?:never|user)$/i.test(J)?{kind:"harmless"}:{kind:"unresolved"};if($==="protocol.ext.allow")return J!==void 0&&/^never$/i.test(J)?{kind:"harmless"}:{kind:"unresolved"};return{kind:"harmless"}}function M1(Z){return/[$\x60]/.test(Z)||["","x","/x","!x"].some((J)=>W1(Z,J).kind!=="harmless")}var o2=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"]),r2=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function t2(Z){let J=/'((?:[^']|'\\'')*)'/y,$=(Q)=>Q.replace(/'\\''/g,"'"),z=[],Y=0;while(Y<Z.length){if(/\s/.test(Z[Y])){Y++;continue}J.lastIndex=Y;let Q=J.exec(Z);if(!Q)return null;if(Y=J.lastIndex,Z[Y]==="="){J.lastIndex=Y+1;let X=J.exec(Z);if(!X)return null;Y=J.lastIndex,z.push([$(Q[1]),$(X[1])])}else{let X=$(Q[1]),H=X.indexOf("=");z.push(H<0?[X,void 0]:[X.slice(0,H),X.slice(H+1)])}}return z}function e2(Z,J,$){let z=[],Y=!1,Q=(B,M,V=!0)=>{if(!V||/[$\x60]/.test(B)){Y=!0;return}let G=W1(B,M);if(G.kind==="unresolved")Y=!0;else if(G.kind==="command")z.push({text:G.text,kind:"shell"})},X=(B,M)=>{let V=B.indexOf("="),G=V<0?B:B.slice(0,V),U=V<0?"true":B.slice(V+1);if(!M)return Q(G,U);if(M1(G))Y=!0},H=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let B=J+1;B<Z.length;B++){let M=Z[B];if(!M.startsWith("-")||M==="-")break;if(M==="--")break;if(M==="-c"){if(B+1>=Z.length)break;X(Z[B+1],$(B+1)),B++}else if(M.startsWith("-c")&&!M.startsWith("--"))X(M.slice(2),$(B));else if(M==="--config-env"||M.startsWith("--config-env=")){let V=M==="--config-env"?Z[++B]??"":M.slice(13),G=V.indexOf("="),U=G<0?V:V.slice(0,G);if($(B)||M1(U))Y=!0}else if(M.startsWith("--exec-path="))Y=!0;else if(H.has(M))B++}let K=new Map;for(let B=0;B<J;B++){let M=Z[B].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!M)continue;let[,V,G]=M,U=$(B);if(o2.has(V))if(U)Y=!0;else z.push({text:G,kind:"shell"});else if(r2.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:t2(G);if(j===null)Y=!0;else for(let[F,A]of j)Q(F,A??"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 B of K.values()){if(B.key===void 0)continue;if(B.opaque)X(`${B.key}=`,!0);else Q(B.key,B.value)}if(z.length===0&&!Y)return null;return{programs:z,unresolved:Y}}function yZ(Z){let J={n:`
4
- `,t:"\t",r:"\r",a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};if(/^~/.test(Z))return null;let $="";for(let z=0;z<Z.length;z++){let Y=Z[z];if(Y==="'"){let Q=Z.indexOf("'",z+1);if(Q<0)return null;$+=Z.slice(z+1,Q),z=Q}else if(Y==="$"&&Z[z+1]==="'"){let Q=z+2;for(;Q<Z.length&&Z[Q]!=="'";Q++){if(Z[Q]!=="\\"){$+=Z[Q];continue}let X=Z[Q+1],H;if(X!==void 0&&Object.hasOwn(J,X))$+=J[X],Q++;else if(H=Z.slice(Q+1).match(/^[0-7]{1,3}/))$+=String.fromCharCode(parseInt(H[0],8)&255),Q+=H[0].length;else if(H=Z.slice(Q+1).match(/^x([0-9A-Fa-f]{1,2})/))$+=String.fromCharCode(parseInt(H[1],16)),Q+=H[0].length;else return null}if(Q>=Z.length)return null;z=Q}else if(Y==="$"||Y==="`")return null;else if(Y==='"'){let Q=z+1;for(;Q<Z.length&&Z[Q]!=='"';Q++){let X=Z[Q];if(X==="$"||X==="`")return null;if(X==="\\"&&Q+1<Z.length&&/[$\x60"\\\n]/.test(Z[Q+1])){$+=Z[++Q];continue}$+=X}if(Q>=Z.length)return null;z=Q}else if(Y==="\\"){if(z+1>=Z.length)return null;$+=Z[++z]}else if("*?[{}".includes(Y))return null;else $+=Y}return $}function V1(Z){let J=null;for(let $=0;$<Z.length;$++){let z=Z[$];if(J==="'"){if(z==="'")J=null;continue}if(z==="\\"){$++;continue}if(z==="$"||z==="`")return!1;if(J==='"'){if(z==='"')J=null;continue}if(z==="'"||z==='"'){J=z;continue}if(z==="<"&&Z[$+1]==="<"&&Z[$+2]!=="<")return!1}return J===null}var Z3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]),$3=new Set(["--rcfile","--init-file"]);function cZ(Z,J){if(J<0||J>=Z.length)return null;let $=yZ(Z[J]),z=F0($??"");if(z==="eval"){let H=J+1;if(yZ(Z[H]??"")==="--")H++;let K=Z.slice(H);if(K.length===0)return null;if(K.length>1)return{program:null,literal:!1};let B=yZ(K[0]);return B!==null&&V1(B)?{program:B,literal:!0}:{program:B,literal:!1}}if(!Z3.has(z))return null;let Y=!1,Q=J+1;for(;Q<Z.length;Q++){let H=yZ(Z[Q]);if(H===null){if(Y)break;return/^"[^"]*"$/.test(Z[Q])?null:{program:null,literal:!1}}if(H==="--"){Q++;break}if(!/^[-+]./.test(H))break;if(H.startsWith("--")){if($3.has(H))Q++;continue}let K=H.slice(1);if(H[0]==="-"&&K.includes("c"))Y=!0;if(/[oO]/.test(K))Q++}if(!Y||Q>=Z.length)return null;let X=yZ(Z[Q]);return X!==null&&V1(X)?{program:X,literal:!0}:{program:X,literal:!1}}function J3(Z,J,$){let z=[],Y=!1,Q=!1,X=J+1,H=!1;for(;X<Z.length;X++){let V=Z[X];if(V==="--"){X++;break}if(V==="-i"||V.startsWith("-i")||V.startsWith("--in-place")){Q=!0;continue}if(V==="-e"||V==="--expression")if(H=!0,X+1<Z.length&&!$(X+1))z.push(Z[++X]);else Y=!0;else if(V.startsWith("-e"))H=!0,z.push(V.slice(2));else if(V.startsWith("--expression="))H=!0,z.push(V.slice(13));else if(V==="-f"||V==="--file"){if(H=!0,Y=!0,V==="-f")X++}else if(V.startsWith("-f")||V.startsWith("--file="))H=!0,Y=!0;else if(!V.startsWith("-")||V==="-")break}if(Q)return null;if(!H)if(X<Z.length)if($(X))Y=!0;else z.push(Z[X]);else return null;let K=z.join(`
5
- `),B=Y||z3(K),M=Y3(K);if(!B&&!M)return null;if(B)return{programs:z.map((V)=>({text:V,kind:"shell"})),unresolved:!0};return{programs:[],unresolved:!1}}var j1=String.raw`[\s0-9$,!]*(?:\/(?:\\.|[^\/\n])*\/[\s0-9$,!]*)?`;function z3(Z){if(new RegExp(`(?:^|[;{\\n])${j1}e(?:\\s|$|[^A-Za-z])`).test(Z))return!0;return N1(Z).some((J)=>J.includes("e"))}function Y3(Z){if(new RegExp(`(?:^|[;{\\n])${j1}[wW]\\s+\\S`).test(Z))return!0;return N1(Z).some((J)=>J.includes("w"))}function N1(Z){let J=[];for(let $=0;$<Z.length;$++){if(Z[$]!=="s")continue;if($>0&&/[A-Za-z0-9_]/.test(Z[$-1]))continue;let z=Z[$+1];if(!z||/[\sA-Za-z0-9\\]/.test(z))continue;let Y=0,Q=$+2;for(;Q<Z.length&&Y<2;Q++){if(Z[Q]==="\\"){Q++;continue}if(Z[Q]===z)Y++}if(Y<2)continue;let X=Z.slice(Q).match(/^[a-zA-Z0-9]*/);J.push(X?X[0]:""),$=Q}return J}var Q3=new Set(["-exec","-execdir","-ok","-okdir"]),X3=new Set(["-exec","-execdir"]),K3=new Set("0oprtx"),H3=new Set("adEILnPsJRS"),B3=new Set("eil"),pZ={"--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 M3(Z){if(Object.hasOwn(pZ,Z))return pZ[Z];let J=Object.keys(pZ).filter(($)=>$.startsWith(Z));return J.length===1?pZ[J[0]]:null}function AZ(Z,J,$,z=0){while(J<Z.length){if($(J)){J++;continue}let Y=Z[J];if(Y==="--"){J++;break}if(!Y.startsWith("-")||Y==="-")break;if(Y.startsWith("--")){let H=Y.indexOf("="),K=M3(H<0?Y:Y.slice(0,H));if(K===null){if(z>=4)return[];return[...AZ(Z,J+1,$,z+1),...AZ(Z,J+2,$,z+1)]}J+=K==="value"&&H<0?2:1;continue}let Q=!1,X=!1;for(let H=1;H<Y.length;H++){let K=Y[H];if(K3.has(K))continue;if(B3.has(K))break;if(H3.has(K)){Q=H===Y.length-1;break}X=!0;break}if(X){if(z>=4)return[];return[...AZ(Z,J+1,$,z+1),...AZ(Z,J+2,$,z+1)]}J+=Q?2:1}while(J<Z.length&&$(J))J++;return J<Z.length?[J]:[]}function iZ(Z,J,$=()=>!1){if(J<0||J>=Z.length)return[];let z=F0(Z[J]);if(z==="xargs")return[...new Set(AZ(Z,J+1,$))].map((Q)=>({start:Q,end:Z.length}));if(z!=="find")return[];let Y=[];for(let Q=J+1;Q<Z.length;Q++){if($(Q)||!Q3.has(Z[Q]))continue;let X=Q+1,H=X;for(;H<Z.length;H++){if($(H))continue;if(Z[H]===";")break;if(Z[H]==="+"&&H>X&&Z[H-1]==="{}"&&X3.has(Z[Q]))break}if(X<H)Y.push({start:X,end:H});Q=H}return Y}function dZ(Z,J,$){if(J<0||J>=Z.length)return null;let z=F0(Z[J]);if(Object.hasOwn(N0,z)||G1.test(z))return p2(z,Z,J,$);if(w2.has(z))return c2(Z,J,$);if(g2.has(z))return d2(Z,J,$);if(z==="rsync")return s2(Z,J,$);if(z==="git")return e2(Z,J,$);if(z==="sed")return J3(Z,J,$);return null}var j3=600000,N3="Delete via trash guard (rm intercepted and made recoverable)",F3=[".hasna/repos/clones","workspace/repos"],_3=[".hasna",".ssh",".aws"],_0={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."},T3=new Set(["sh","bash","zsh","dash","ksh","ash","eval","source",".","su","runuser","env"]),I3={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"]},D3={timeout:1},C3={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:d,l:d,v:d,D:q,R:q,h:q,K:q,V:q},long:{askpass:W,bell:W,background:W,"close-from":_,chdir:q,"preserve-env":OZ,edit:d,group:_,"set-home":W,help:q,host:q,login:W,"remove-timestamp":q,"reset-timestamp":W,list:d,"no-update":W,"non-interactive":W,"preserve-groups":W,prompt:_,chroot:q,role:_,stdin:W,shell:W,type:_,"command-timeout":_,"other-user":_,user:_,version:q,validate:d},assignments:!0},doas:{short:{n:W,s:W,u:_,C:q,L:q},long:{}},flock:{short:{s:W,x:W,e:W,n:W,u:W,o:W,F:W,w:_,E:_,h:q,V:q},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:q,version:q},positionals:[/^[\s\S]+$/]}},q3={...j0,...C3},q1=new Set(["-c","--command"]),P3=new Set(["busybox","toybox"]),C0=new Set(["rm","rmdir","unlink","shred"]),O3=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"]),y3=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/;function c(Z){return y3.test(P(Z))}function vZ(Z){return Z.map((J)=>J.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var P1=/^[A-Za-z_][A-Za-z0-9_]*=/;function nZ(Z){let J=Z.lastIndexOf("/");return J>=0?Z.slice(J+1):Z}var F1={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
6
- `,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function A3(Z,J){let $="",z=J;while(z<Z.length&&Z[z]!=="'"){if(Z[z]!=="\\"||z+1>=Z.length){$+=Z[z++];continue}let Y=Z[z+1],Q=Z.slice(z+1),X;if(Object.hasOwn(F1,Y))$+=F1[Y],z+=2;else if(X=Q.match(/^[0-7]{1,3}/))$+=String.fromCharCode(parseInt(X[0],8)&255),z+=1+X[0].length;else if((X=Q.match(/^x([0-9A-Fa-f]{1,2})/))||(X=Q.match(/^u([0-9A-Fa-f]{1,4})/))||(X=Q.match(/^U([0-9A-Fa-f]{1,8})/))){let H=parseInt(X[1],16);$+=H<=1114111?String.fromCodePoint(H):"",z+=1+X[0].length}else if(Y==="c"&&z+2<Z.length)$+=String.fromCharCode(Z.charCodeAt(z+2)&31),z+=3;else $+=`\\${Y}`,z+=2}return{text:$,end:Math.min(z+1,Z.length)}}function aZ(Z){let J="",$=0;while($<Z.length){let z=Z[$];if(z==="$"&&Z[$+1]==="'"){let Y=A3(Z,$+2);J+=Y.text,$=Y.end;continue}if(z==="$"&&Z[$+1]==='"'){$++;continue}if(z==="\\"){if($+1<Z.length)J+=Z[$+1];$+=2;continue}if(z==="'"){let Y=Z.indexOf("'",$+1);if(Y===-1){J+=Z.slice($+1);break}J+=Z.slice($+1,Y),$=Y+1;continue}if(z==='"'){$++;while($<Z.length&&Z[$]!=='"'){if(Z[$]==="\\"&&$+1<Z.length){J+=Z[$+1],$+=2;continue}J+=Z[$],$++}$++;continue}J+=z,$++}return J}function oZ(Z){if(mZ(Z))return!0;let J=null;for(let $=0;$<Z.length;$++){let z=Z[$];if(J==="'"){if(z==="'")J=null;continue}if(z==="\\"){$++;continue}if(z==="`"||z==="$")return!0;if(z==='"'){J=J===null?'"':null;continue}if(J!==null)continue;if(z==="'")J="'";else if(z==="*"||z==="?")return!0;else if(z==="["&&R3(Z,$+1,"]"))return!0}return!1}function R3(Z,J,$){let z=null;for(let Y=J;Y<Z.length;Y++){let Q=Z[Y];if(z!=="'"&&Q==="\\")Y++;else if(z===null&&Q===$)return!0;else if(Q==="'"&&z!=='"')z=z==="'"?null:"'";else if(Q==='"'&&z!=="'")z=z==='"'?null:'"'}return!1}function v3(Z){if(!oZ(Z))return!1;let J=$Z(Z);return J===null||J.some(($)=>aZ($).split(/[^A-Za-z0-9_]+/).some((z)=>C0.has(z)))}function VZ(Z){return nZ(aZ(Z))}var O1={deep:!0};function q0(Z,J){return Z.replace(/\\([$`\\"])/g,($,z)=>z==='"'&&!J?$:z)}function b3(Z,J,$){let z=[],Y=J+1;while(Y<$-1){let Q=Z[Y];if(Q==="\\"){Y+=2;continue}if(Q==="`"){let X=bZ(Z,Y);if(X<0)return null;z.push(q0(Z.slice(Y+1,X-1),!0)),Y=X;continue}if(Q==="$"&&Z[Y+1]==="("){let X=zZ(Z,Y+1);if(X<0)return null;z.push(Z.slice(Y+2,X-1)),Y=X;continue}Y++}return z}function E3(Z){let J=[],$=0;while($<Z.length){let z=Z[$];if(z==="\\"){$+=2;continue}if(z==="`"){let Y=bZ(Z,$);if(Y<0)return null;J.push(q0(Z.slice($+1,Y-1),!1)),$=Y;continue}if(z==="$"&&Z[$+1]==="("){let Y=zZ(Z,$+1);if(Y<0)return null;J.push(Z.slice($+2,Y-1)),$=Y;continue}$++}return J}function _1(Z,J,$,z){let Y=J+1;for(let Q of $){let X=Math.min(Y,Z.length);for(;;){if(Y>Z.length){Y=Z.length+1;break}let K=Z.indexOf(`
7
- `,Y),B=K===-1?Z.length:K,M=Z.slice(Y,B).replace(/\r$/,"");if(Q.stripTabs)M=M.replace(/^\t+/,"");if(M===Q.delimiter)break;Y=B+1}let H=Z.slice(X,Math.min(Y,Z.length));if(Q.owner.push(H),!Q.quoted){let K=E3(H);if(!K)return-1;z.push(...K)}if(Y<=Z.length){let K=Z.indexOf(`
8
- `,Y);Y=(K===-1?Z.length:K)+1}}return Math.min(Y-1,Z.length)}function L1(Z,J){let $=Z.indexOf("'",J+1);return $===-1?-1:$+1}function bZ(Z,J){let $=J+1;while($<Z.length){if(Z[$]==="\\"){$+=2;continue}if(Z[$]==="`")return $+1;$++}return-1}function y1(Z,J){let $=J+1;while($<Z.length){let z=Z[$];if(z==="\\"){$+=2;continue}if(z==='"')return $+1;if(z==="`"){let Y=bZ(Z,$);if(Y<0)return-1;$=Y;continue}if(z==="$"&&Z[$+1]==="("){let Y=zZ(Z,$+1);if(Y<0)return-1;$=Y;continue}$++}return-1}function GZ(Z,J){if(Z[J]!=="<"||Z[J+1]!=="<"||Z[J+2]==="<")return null;let $=J+2,z=Z[$]==="-";if(z)$++;while(Z[$]===" "||Z[$]==="\t")$++;let Y="",Q=!1;while($<Z.length&&!/[\s;|&<>()]/.test(Z[$])){let X=Z[$];if(X==="'"||X==='"'){let H=Z.indexOf(X,$+1);if(H<0)return null;Y+=Z.slice($+1,H),Q=!0,$=H+1;continue}if(X==="\\"){if($+1>=Z.length)return null;Y+=Z[$+1],Q=!0,$+=2;continue}Y+=X,$++}return Y?{delimiter:Y,stripTabs:z,quoted:Q,end:$}:null}function rZ(Z,J,$){let z=J+1;for(let Y of $)for(;;){if(z>Z.length)return-1;let Q=Z.indexOf(`
9
- `,z),X=Q===-1?Z.length:Q,H=Z.slice(z,X);if(H.endsWith("\r"))H=H.slice(0,-1);let K=Y.stripTabs?H.length-H.replace(/^\t+/,"").length:0;if(Y.stripTabs)H=H.slice(K);if(H===Y.delimiter){z=X+1;break}if(H.startsWith(Y.delimiter)&&/^\s*\)/.test(H.slice(Y.delimiter.length))){if(Y===$[$.length-1])return z+K+Y.delimiter.length;return-1}if(Q===-1)return-1;z=Q+1}return z-1}function zZ(Z,J){let $=Z.length,z=Z[J+1]==="(",Y=0,Q=J,X=[];while(Q<$){let H=Z[Q];if(H==="\\"){Q+=2;continue}if(H==="'"){let K=L1(Z,Q);if(K<0)return-1;Q=K;continue}if(H==='"'){let K=y1(Z,Q);if(K<0)return-1;Q=K;continue}if(H==="`"){let K=bZ(Z,Q);if(K<0)return-1;Q=K;continue}if(!z&&H==="<"&&Z[Q+1]==="<"){if(Z[Q+2]==="<"){Q+=3;continue}let K=GZ(Z,Q);if(!K)return-1;X.push(K),Q=K.end;continue}if(H===`
10
- `&&X.length>0){let K=rZ(Z,Q,X);if(K<0)return-1;X=[],Q=K;continue}if(!z&&H==="#"&&/[\s;&|(]/.test(Z[Q-1])){let K=Z.indexOf(`
11
- `,Q);if(K<0)return-1;Q=K;continue}if(H==="(")Y++;else if(H===")"){if(Y--,Y===0)return X.length>0?-1:Q+1}Q++}return-1}function x(Z,J={}){let $=J.deep===!0,z=[],Y=[],Q=[],X=new Set,H=[],K=[],B=-1,M=!1,V=!0,G=0,U=Z.length,j=(D)=>{if(B>=0){let N=Q.length;if(Q.push({text:Z.slice(B,D),start:B,end:D}),M)X.add(N);B=-1,M=!1}},F=(D)=>{if(j(D),Q.length>0)z.push($?{words:Q,redirects:X,heredocs:H}:{words:Q,redirects:X});if(Q=[],X=new Set,$)H=[];M=!1},A=(D)=>L1(Z,D),v=(D)=>bZ(Z,D),h=(D)=>zZ(Z,D),u=(D)=>y1(Z,D);while(G<U){let D=Z[G];if(D===" "||D==="\t"||D==="\r"){j(G),G++;continue}if(D===`
12
- `){if(F(G),K.length>0){let N=_1(Z,G,K,Y);if(K=[],N<0)V=!1,G=U;else G=N;continue}G++;continue}if(D===";"){F(G),G++;continue}if(D==="&"){F(G),G+=Z[G+1]==="&"?2:1;continue}if(D==="|"){F(G),G+=Z[G+1]==="|"?2:1;continue}if($&&D==="("&&B>=0&&"?*+@!".includes(Z[G-1])){V=!1,G=U;continue}if(D==="("||D===")"){F(G),G++;continue}if(D==="<"&&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 FZ=G+2+N[0].length;if(FZ<U&&!/[\s;&|()<>]/.test(Z[FZ])){V=!1,G=U;continue}j(G),K.push({delimiter:N[2],quoted:N[1]!=="",stripTabs:N[0].startsWith("-"),owner:H}),G=FZ;continue}let y=Z.indexOf(`
13
- `,G+2+N[0].length);if(y===-1){V=!1,G=U;continue}let S=Z.slice(y+1),f=S3(S,N[2]);if(f===-1){V=!1,G=U;continue}j(G),G=y+1+f+N[2].length;continue}if(D===">"||D==="<"){if(B>=0&&/^\d+$/.test(Z.slice(B,G)))B=-1;if(j(G),M=!0,G++,Z[G]===D||Z[G]==="&"||D===">"&&Z[G]==="|"||D==="<"&&Z[G]===">")G++;continue}if(D==="'"){if(B<0)B=G;let N=A(G);if(N<0)V=!1,G=U;else G=N;continue}if(D==='"'){if(B<0)B=G;let N=u(G),y=N<0||!$?[]:b3(Z,G,N);if(N<0||!y)V=!1,G=U;else Y.push(...y),G=N;continue}if(D==="`"){if(B<0)B=G;let N=v(G);if(N<0)V=!1,G=U;else{let y=Z.slice(G+1,N-1);Y.push($?q0(y,!1):y),G=N}continue}if(D==="$"&&Z[G+1]==="("){if(B<0)B=G;let N=h(G+1);if(N<0)V=!1,G=U;else Y.push(Z.slice(G+2,N-1)),G=N;continue}if(D==="\\"){if(B<0)B=G;if(G+1>=U)V=!1,G=U;else G+=2;continue}if(B<0)B=G;G++}if(F(U),K.length>0&&_1(Z,U,K,Y)<0)V=!1;return{segments:z,trustworthy:V,substitutions:Y}}function S3(Z,J){let $=0;while($<=Z.length){let z=Z.indexOf(J,$);if(z===-1)return-1;let Y=z===0||Z[z-1]===`
14
- `,Q=z+J.length,X=Q===Z.length||Z[Q]===`
15
- `||Z[Q]==="\r";if(Y&&X)return z;$=z+1}return-1}function P(Z){let J="",$=0;while($<Z.length){let z=Z[$];if(z==="\\"){if($+1<Z.length)J+=Z[$+1];$+=2;continue}if(z==="'"){let Y=Z.indexOf("'",$+1);if(Y===-1){J+=Z.slice($+1);break}J+=Z.slice($+1,Y),$=Y+1;continue}if(z==='"'){$++;while($<Z.length&&Z[$]!=='"'){if(Z[$]==="\\"&&$+1<Z.length){J+=Z[$+1],$+=2;continue}J+=Z[$],$++}$++;continue}J+=z,$++}return J}function E(Z){let J=0,$=0;while(J<Z.words.length&&$++<32){if(Z.redirects.has(J)){J++;continue}let z=Z.words[J].text,Y=P(z);if(P1.test(Y)&&!Y.startsWith("-")){J++;continue}if(O3.has(Y)){J++;continue}let Q=nZ(Y);if(Q==="command")for(let H of Z.words.filter((K,B)=>B>J&&!Z.redirects.has(B))){let K=P(H.text);if(K==="--"||!K.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(K))return-1}let X=I3[Q];if(X){let H=J;J++;while(J<Z.words.length){if(Z.redirects.has(J)){J++;continue}let B=P(Z.words[J].text);if(!B.startsWith("-")||B==="-")break;if(B==="--"){J++;break}if(Q==="env"&&(/^-[iv0]*S/.test(B)||/^--split-string(?:=|$)/.test(B)))return H;if(J++,X.includes(B)||Q==="exec"&&/^-[cl]*a$/.test(B)){while(Z.redirects.has(J))J++;J++}}let K=D3[Q]??0;while(K>0&&J<Z.words.length){let B=P(Z.words[J].text);if(B.startsWith("-")&&B!=="-")break;J++,K--}continue}return J}return-1}function f3(Z,J){let $=[],z=!1;for(let Y=J+1;Y<Z.words.length;Y++){if(Z.redirects.has(Y))continue;let Q=P(Z.words[Y].text);if(!z){if(Q==="--"){z=!0;continue}if(Q.startsWith("-")&&Q!=="-")continue}$.push(Z.words[Y])}return $}function P0(Z){return F3.map((J)=>MZ(Z,...J.split("/")))}function k3(Z,J){if(Z==="~"||Z==="$HOME"||Z==="${HOME}")return J;if(Z.startsWith("~/"))return MZ(J,Z.slice(2));if(Z.startsWith("$HOME/"))return MZ(J,Z.slice(6));if(Z.startsWith("${HOME}/"))return MZ(J,Z.slice(8));return Z}function sZ(Z,J,$){let z=P(Z);if(!z)return null;if(z.includes("`"))return null;if(z==="$HOME"||z==="${HOME}"||z==="$HOME/"||z==="${HOME}/")return $;if(z.replace(/\$\{HOME\}/g,"").replace(/\$HOME/g,"").includes("$"))return null;if(/[*?[\]]/.test(z))return null;if(z.startsWith("~")){let H=k3(z,$);if(H===z)return null;z=H}let X=(G3(z)?U3(z):W3(J,z)).replace(/\/+$/,"");return X===""?"/":X}function a(Z,J){return Z===J||Z.startsWith(`${J}${D0}`)}function x3(Z,J){let $=`${MZ(J,".hasna","scratchpad","scratch")}${D0}`;if(!Z.startsWith($))return!1;let[z,Y]=Z.slice($.length).split(D0);if(!z||!/^[a-z0-9][a-z0-9._-]{0,63}$/.test(z)||z.endsWith(".")||!Y)return!1;let Q=Y.normalize("NFKC").toLowerCase();return Q!=="meta.json"&&Q!==".lock"}function h3(Z,J){if(Z===J)return`\`${Z}\` is the home directory itself, which is never deleted or trashed. Delete a specific file or directory inside it instead.`;for(let $ of K1){if(Z!==$&&!a($,Z))continue;return $==="/"?`\`${Z}\` is the filesystem root, which is never deleted.`:`\`${Z}\` is the system root \`${$}\` (or an ancestor of it), which is never deleted or trashed.`}for(let $ of _3){let z=MZ(J,$);if($===".hasna"&&x3(Z,J))continue;if(!a(Z,z)&&!a(z,Z))continue;return`\`${Z}\` is the protected \`~/${$}\` path (or contains it), which is never deleted or trashed. Delete a specific file inside it, and only when you are sure.`}return null}function w3(Z,J,$){let z=P0($);if(z.some((Y)=>a(J,Y)))return!0;return Z.some((Y)=>Y!==null&&z.some((Q)=>a(Y,Q)))}var T1=new WeakMap;function g3(Z){let J=T1.get(Z);if(J)return J;let $=Z.words.map((X)=>aZ(X.text)),z=$.findIndex((X)=>X==="-exec"||X==="-execdir"||X==="-ok"||X==="-okdir"),Y=-1;Z.words.forEach((X,H)=>{if(q1.has(P(X.text)))Y=H});let Q={findDelete:$.includes("-delete"),findExecDelete:z>=0&&$.slice(z).some((X)=>C0.has(nZ(X))),namesDelete:$.some((X)=>C0.has(nZ(X))),lastFlockCommand:Y,textMention:c(s3(Z)),envMention:c(vZ(Z.words.map((X)=>P(X.text)))),bodiesMention:c((Z.heredocs??[]).join(`
16
- `))};return T1.set(Z,Q),Q}var l3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]);function u3(Z,J){if(!l3.has(VZ(Z.words[J].text)))return!1;for(let $=J+1;$<Z.words.length;$++){if(Z.redirects.has($))continue;let z=P(Z.words[$].text);if(z==="--")return $+1>=Z.words.length;if(/^-[A-Za-z]*s/.test(z))return!0;if(/^-[A-Za-z]*c/.test(z))return!1;if(z==="-o"||z==="+o"||z==="-O"||z==="+O"){$++;continue}if(!/^[-+]/.test(z)||z==="-")return z==="-"}return!0}var T0=(Z)=>Z.kind==="rm"||Z.kind==="refuse",m3="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.",p3="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.",c3="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.",i3="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 O0(Z){let J=[];Z.words.forEach((Y,Q)=>{if(!Z.redirects.has(Q))J.push(Q)});let $=J.map((Y)=>{let Q=Z.words[Y].text;return{text:aZ(Q),opaque:oZ(Q)}}),z=JZ($,q3);if(z===null)return null;return z.index<0?-1:J[z.index]}function I0(Z,J,$,z){let Y=VZ(Z.words[J].text);if(Y==="cd"){let K=Z.words[J+1];if(!K)return{kind:"none"};return{kind:"cd",cwd:sZ(K.text,$,z.home)??z.cwd}}if(Object.hasOwn(_0,Y))return{kind:"refuse",reason:_0[Y]};let Q=A1(Z,J,$,z);if(Q)return Q;if(Y==="rm"){let K=f3(Z,J);if(K.length===0)return{kind:"none"};let B={word:Z.words[J],operands:K},M=P0(z.home),V=(j)=>j!==null&&M.some((F)=>a(j,F)),G=[],U=[];for(let j of K){let F=sZ(j.text,$,z.home);if(G.push(F),!j.text.includes("{"))continue;let A=$Z(j.text);if(A===null)return{kind:"refuse",reason:p3};for(let v of A){let h=sZ(v,$,z.home);if(h===null)continue;if(V(h)&&!V(F))return{kind:"refuse",reason:c3};U.push(h)}}if(w3(G,$,z.home))return B.cwdOnly=G.every((j)=>j!==null&&!V(j)),{kind:"rm",hit:B,handoff:!0,protectedReason:null};for(let j of[...G,...U]){if(!j)continue;let F=h3(j,z.home);if(F)return{kind:"rm",hit:B,handoff:!1,protectedReason:F}}return{kind:"rm",hit:B,handoff:!1,protectedReason:null}}if(P3.has(Y)){let K=Z.words.findIndex((M,V)=>V>J&&!P(M.text).startsWith("-")),B=K>=0?VZ(Z.words[K].text):"";if(B==="rm"||Object.hasOwn(_0,B))return{kind:"refuse",reason:`\`${Y} ${B}\` 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=L0(Z,J);if(K==="rm"||K==="clean"){if(!(K==="rm"?n3(Z,J):R1(Z,J)))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 X=g3(Z);if(Y==="find"){if(X.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(X.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"&&X.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 H=Y==="flock"?X.lastFlockCommand>J:q1.has(Y);if(T3.has(Y)||H){let K=u3(Z,J)?z.bodiesMention:X.bodiesMention;if((Y==="env"?X.envMention:X.textMention)||K)return{kind:"refuse",reason:`\`${H?"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 A1(Z,J,$,z,Y={segment:Z,index:J},Q=0){let X=VZ(Z.words[J].text);for(let V of iZ(Z.words.map((G)=>P(G.text)),J,(G)=>Z.redirects.has(G))){if(Q>=8)return RZ(Y.segment,Y.index,$,z.home)?{kind:"refuse",reason:d3}: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=O0(G);for(let j of new Set([E(G),U??-1])){if(j<0)continue;let F=A1(G,j,$,z,Y,Q+1);if(F)return F}}let H=Z.words.map((V,G)=>({word:V,at:G})).filter(({at:V})=>!Z.redirects.has(V)),K=H.findIndex(({at:V})=>V===J),B=K<0?null:cZ(H.map(({word:V})=>V.text),K);if(B&&!B.literal&&(RZ(Z,J,$,z.home)||RZ(Y.segment,Y.index,$,z.home)))return{kind:"refuse",reason:`\`${X}\` runs a shell program that is not a plain literal (an expansion, a substitution 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=dZ(Z.words.map((V)=>P(V.text)),J,(V)=>V>=0&&V<Z.words.length&&(Z.redirects.has(V)||oZ(Z.words[V].text)));if(!M||!(RZ(Z,J,$,z.home)||RZ(Y.segment,Y.index,$,z.home)))return null;if(!M.unresolved&&!M.programs.some((V)=>c(V.text)))return null;return{kind:"refuse",reason:`\`${X}\` 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 d3="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 RZ(Z,J,$,z){let Y=P0(z),Q=(X)=>X!==null&&Y.some((H)=>a(X,H));if(Y.some((X)=>a($,X)))return!0;for(let X=J+1;X<Z.words.length;X++){if(Z.redirects.has(X))continue;if(Q(sZ(Z.words[X].text,$,z)))return!0}return!1}function EZ(Z,J){let $={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},z=x(Z,O1);$.trustworthy=z.trustworthy;let Y={cwd:J.cwd,home:J.home,depth:J.depth??0,bodiesMention:c(z.segments.flatMap((K)=>K.heredocs??[]).join(`
17
- `))};if(!z.trustworthy)return $;let Q=[],X=(K,B=$.refusals)=>{if(K.kind==="refuse")B.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})}},H=Y.cwd;for(let K of z.segments){let B=E(K),M=O0(K),V=B<0?{kind:"none"}:I0(K,B,H,Y);if(V.kind!=="cd")X(V);let G=(U)=>U!==null&&U>=0&&oZ(K.words[U].text);if(M===null||G(B)||G(M)){if(K.words.some((U,j)=>!K.redirects.has(j)&&(T0(I0(K,j,H,Y))||v3(U.text))))Q.push({reason:m3})}else if(M>=0&&M!==B){let U=I0(K,M,H,Y);if(T0(U))if(T0(V))Q.push({reason:i3});else X(U,Q)}if(V.kind==="cd")H=V.cwd}if(Y.depth<3)for(let K of z.substitutions){let B=EZ(K,{cwd:H,home:Y.home,depth:Y.depth+1});if(B.rmHits.length>0||B.refusals.length>0||B.handoffHits.length>0||B.protectedHits.length>0||!B.trustworthy&&c(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(z.substitutions.some((K)=>c(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(...Q),$}function s3(Z){return Z.words.map((J)=>J.text).join(" ")}function L0(Z,J){let $=J+1;while($<Z.words.length){let z=P(Z.words[$].text);if(!z.startsWith("-"))return z;if($++,L3.has(z))$++}return null}function n3(Z,J){if(Z.words.slice(J+1).map((z)=>P(z.text)).includes("--cached"))return!0;return R1(Z,J)}function R1(Z,J){let $=Z.words.slice(J+1).map((z)=>P(z.text));return $.includes("-n")||$.includes("--dry-run")}function I1(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function a3(Z,J,$,z){let Y=z?["/usr/bin/env","-i",`HOME=${z.home}`,`PATH=${z.path}`,`HASNA_TRASH_AGENT=${z.agent}`,z.runtime,"--config=/dev/null","--no-env-file","--no-macros","--no-install",$,"guard"].map(I1).join(" "):`${I1($)} guard`,Q=[...J].sort((H,K)=>K.word.start-H.word.start),X=Z;for(let H of Q)X=`${X.slice(0,H.word.start)}${Y}${X.slice(H.word.end)}`;return X}function o3(Z,J,$,z,Y){if(!J||J===Z)return!1;if($.length===0)return!1;let Q=EZ(J,{cwd:z,home:Y});if(!Q.trustworthy)return!1;if(Q.rmHits.length>0||Q.handoffHits.length>0)return!1;return Q.refusals.length===0}function r3(Z,J){let $={};for(let[z,Y]of Object.entries(Z??{}))$[z]=Y;if($.command=J,typeof $.description!=="string"||$.description.trim()==="")$.description=N3;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=j3;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function t3(Z,J,$,z,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 o3(J,Z.command,$,z,Y)}function e3(Z){let J=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return x(Z,O1).segments.some((z)=>{let Y=O0(z);return[E(z),...Y===null?[]:[Y]].some((Q)=>{if(z.words.slice(0,Q<0?z.words.length:Q).some((K)=>P1.test(P(K.text))||J.has(VZ(K.text))))return!0;if(Q<0)return!1;let H=z.words[Q];return J.has(VZ(H.text))||/^\s*\(\s*\)\s*\{/.test(Z.slice(H.end))})})}function w(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function Z4(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function $4(Z){try{if(Z.inspectTrash){let J=Z.inspectTrash();return J.ok?{path:J.path,error:null}:{path:null,error:`${J.code}: ${X1[J.code]}`}}return{path:Z.findTrash(),error:null}}catch(J){return{path:null,error:J instanceof Error?J.message:String(J)}}}var J4="[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.";function v1(Z,J){if(Z.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(Z.tool_name??"")){let B=Z.tool_input?.command;if(typeof B!=="string")return w("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(B))return w("[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 w("[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 z=BZ(Z);if(!z.trim())return{continue:!0};let Y=EZ(z,{cwd:J.cwd,home:J.home});if(Y.refusals.length>0)return w(`[trash-guard] ${Y.refusals[0].reason}`);if(Y.protectedHits.length>0)return w(`[trash-guard] ${Y.protectedHits[0].reason}`);if(!Y.trustworthy)return c(z)?w("[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(Y.rmHits.length===0){if(Y.handoffHits.some((B)=>B.cwdOnly))return w("[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.");if(Y.handoffHits.length>0)return{continue:!0};return{continue:!0}}if(Y.handoffHits.length>0)return w("[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.");let Q=$4(J);if(Q.error!==null)return w(`[trash-guard] The guard could not resolve the \`trash\` binary (${Q.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(Q.path===null)return w(J4);let X=Q.path;if(J.execution&&e3(z))return w("[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 H=a3(z,Y.rmHits,X,J.execution),K=r3(Z.tool_input,H);if(J.execution)K.hasna_execution="hasna.hooks.execution.v1";if(!t3(K,z,Y.rmHits,J.cwd,J.home))return w("[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.");return Z4(K)}import{closeSync as z4,constants as b1,fstatSync as Y4,lstatSync as Q4,openSync as X4,readFileSync as K4,statSync as H4}from"fs";import{homedir as u1}from"os";import{dirname as y0,isAbsolute as m1,join as UZ,normalize as WZ,relative as B4,resolve as kZ,sep as E0}from"path";var M4=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),V4=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),G4=["hasna","hasnaxyz","hasna-products"],SZ="workspace-repos-guard";function U4(Z){return UZ(Z,".hasna","repos","clones")}function W4(Z){return UZ(Z,"workspace","repos")}function p1(Z){return[U4(Z),W4(Z)]}function j4(Z){return UZ(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var N4=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function A0(Z){let J=process.getuid?.();return J!==void 0&&(Z.uid===0||Z.uid===J)&&(Z.mode&18)===0}function F4(Z){let J=j4(Z),$;try{let Y=X4(J,b1.O_RDONLY|b1.O_NOFOLLOW);try{let X=Y4(Y);if(!X.isFile()||!A0(X)||X.size>4096)return null;$=K4(Y,"utf8")}finally{z4(Y)}let Q=WZ(Z);for(let X=y0(J);X!==Q;X=y0(X)){let H=Q4(X);if(!H.isDirectory()||!A0(H)||X===y0(X))return null}if(!A0(H4(Q)))return null}catch{return null}let z=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return z.length>0&&z.every((Y)=>N4.test(Y))?new Set(z):null}function _4(Z=process.env,J=u1()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((z)=>z.trim()).filter(Boolean));return F4(J)??new Set(G4)}function R0(Z,J,$,z){if(z==="read")return{blocked:!1};let Y=B4(J,Z);if(Y===""){if(z==="delete")return{blocked:!0,reason:`[${SZ}] delete of the protected repo-checkout root is forbidden: ${J}`};return{blocked:!0,reason:`[${SZ}] writes directly to the protected repo-checkout root are forbidden: ${J}`}}if(Y.startsWith(`..${E0}`)||Y===".."||m1(Y))return{blocked:!1};let Q=Y.split(E0).filter(Boolean);if(z==="delete")return{blocked:!0,reason:`[${SZ}] delete under the protected repo-checkout root (${J}) is forbidden at any depth: ${Z}`};if(Q.length<=1)return{blocked:!0,reason:`[${SZ}] writing would create a top-level entry directly under the protected repo-checkout root (${J}); only GitHub-org folders belong there: ${Z}`};let X=Q[0];if(!$.has(X))return{blocked:!0,reason:`[${SZ}] '${X}' is not an allowed GitHub org under the protected repo-checkout root (${J}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var c1=/\b(?:-o|--output|-O|--output-document|-out)\b/,T4=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,I4=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function i1(Z){return Z.replace(T4," ")}function D4(Z){let J=[],$=null,z=0,Y=0,Q=!1,X=0;for(let H=0;H<Z.length;H++){let K=Z[H];if($==="'"){if(K==="'")$=null;continue}if(K==="\\"){H++;continue}if(K==="("){z++;continue}if(K===")"){if(--z<0)return[Z];continue}if(K==="$"&&Z[H+1]==="{"){Y++,H++;continue}if(K==="}"&&Y>0){Y--;continue}if(K==="`"){Q=!Q;continue}if($==='"'){if(K==='"')$=null;continue}if(K==="'"||K==='"'){$=K;continue}if(K!=="|"||z>0||Y>0||Q||Z[H-1]===">")continue;if(J.push(Z.slice(X,H)),Z[H+1]==="&")H++;X=H+1}if($||z!==0||Y!==0||Q)return[Z];return J.push(Z.slice(X)),J}function C4(Z){let J=[],$="",z="",Y=null,Q=!1,X=()=>{if(!Q)return;let H=z.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),K=$.startsWith("~")&&!/^~(?:\/|$)/.test(z);J.push({text:K?`./${$}`:$,opaque:/[$\x60*?[]/.test(H)||/[()]/.test(H)||mZ(z)}),$="",z="",Q=!1};for(let H=0;H<Z.length;H++){let K=Z[H];if(Y==="'"){if(K==="'")Y=null;else $+=K;z+=K;continue}if(K==="\\"&&H+1<Z.length){let B=Z[H+1];$+=Y==='"'&&!/[$\x60"\\\n]/.test(B)?K+B:B,z+=K+B,Q=!0,H++;continue}if(Y==='"'){if(K==='"')Y=null;else $+=K;z+=K;continue}if(/\s/.test(K)){X();continue}if(Q=!0,z+=K,K==="'"||K==='"')Y=K;else $+=K}if(Y)z+="$";return X(),J}function v0(Z,J,$){let z=Z[J];return z==="--help"||z==="--version"||$&&(z==="-h"||z==="-V")}var E1={read:0,write:1,delete:2};function tZ(...Z){return Z.reduce((J,$)=>E1[$]>E1[J]?$:J,"read")}var q4=new Set(["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"]),d1=new Set(["put","rm","delete","remove"]),P4=new Set([...d1,"restore","restore-capsule","recover","release","locks","retention","hold","unhold","pin","unpin","retrieve","backup-retrieve"]),s1=new Set(["-delete","-exec","-execdir","-ok","-okdir","-fls","-fprint","-fprint0","-fprintf"]);function n1(Z){let J=null;for(let $=0;$<Z.length;$++){let z=Z[$];if(J==="'"){if(z==="'")J=null;continue}if(z==="\\"){$++;continue}if(z==="$"||z==="`")return!0;if(J==='"'){if(z==='"')J=null;continue}if(z==="'"||z==='"')J=z;else if("*?[{".includes(z))return!0}return J!==null}function k0(Z){let J=Z.trim();if(!J)return"read";if(x0(J))return"delete";let $=x(J);if(!$.trustworthy||$.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(J))return YZ(J);let z=$.segments.flatMap((Y)=>{let Q=S1(Y),X=Y.words.filter((B,M)=>!Y.redirects.has(M)).map((B)=>B.text),H=X.map($Z);if(H.every((B,M)=>B!==null&&B.length===1&&B[0]===X[M]))return[Q];if(H.some((B)=>B===null))return[Q,YZ(X.join(" "))];let K=x(H.flatMap((B)=>B??[]).join(" "));return[Q,...K.trustworthy?K.segments.map(S1):[YZ(X.join(" "))]]});return tZ(...z)}function S1(Z){let J=Z.words.map((Q,X)=>({word:Q,at:X})).filter(({at:Q})=>!Z.redirects.has(Q)),$=E(Z),z=$<0?"read":f1(Z,$),Y=JZ(J.map(({word:Q})=>({text:P(Q.text),opaque:/[$\x60]/.test(Q.text)})));if(Y===null)return tZ(z,YZ(J.map(({word:Q})=>P(Q.text)).join(" ")));if(Y.index<0||J[Y.index].at===$)return z;return tZ(z,f1(Z,J[Y.index].at))}function S0(Z,J,$=0){if(J<0||$>8)return $>8;let z=Z.words.map((B,M)=>({word:B,at:M})).filter(({at:B})=>!Z.redirects.has(B)),Y=z.findIndex(({at:B})=>B===J),Q=Y<0?null:cZ(z.map(({word:B})=>B.text),Y);if(Q){if(!Q.literal)return!0;let B=x(Q.program);if(B.trustworthy&&B.segments.some((M)=>eZ(M,$+1)))return!0}let X=Z.words.map((B)=>P(B.text));for(let B of iZ(X,J,(M)=>Z.redirects.has(M)))if(eZ(O4(Z,B.start,B.end),$+1))return!0;let K=dZ(X,J,(B)=>B>=0&&B<Z.words.length&&(Z.redirects.has(B)||n1(Z.words[B].text)));if(!K)return!1;if(K.unresolved)return!0;return K.programs.some((B)=>B.kind==="shell"?k0(B.text)!=="read":!U1(B))}function O4(Z,J,$){let z=new Set([...Z.redirects].filter((Y)=>Y>=J&&Y<$).map((Y)=>Y-J));return{words:Z.words.slice(J,$),redirects:z}}function eZ(Z,J=0){let $=E(Z);if($>=0&&S0(Z,$,J))return!0;let z=Z.words.map((Q,X)=>({word:Q,at:X})).filter(({at:Q})=>!Z.redirects.has(Q)),Y=JZ(z.map(({word:Q})=>({text:P(Q.text),opaque:/[$\x60]/.test(Q.text)})));return Y!==null&&Y.index>=0&&z[Y.index].at!==$&&S0(Z,z[Y.index].at,J)}function x0(Z,J=0){if(J>4)return!1;let $=x(Z);if($.trustworthy&&$.segments.some((Y)=>eZ(Y)))return!0;return(r1(Z)??$.substitutions).some((Y)=>x0(Y,J+1))}function f1(Z,J){if(S0(Z,J))return"delete";let $=Z.words.filter((Q,X)=>X>=J&&!Z.redirects.has(X)),z=$.map((Q)=>P(Q.text)),Y=z[0].split("/").pop();if(["rm","rmdir","shred"].includes(Y??""))return v0(z,1,!1)?"read":"delete";if(["unlink","rmtree","del"].includes(Y??""))return"delete";if(Y==="trash"){let Q=1;while(Q<z.length&&z[Q].startsWith("-")){let X=z[Q++];if(["--help","-h","--version","-V","--identity"].includes(X))return"read";if(["--agent","--spool","--files","--info","--config"].includes(X))Q++;else if(!["--json","--local"].includes(X))return"delete"}if(Q===z.length||q4.has(z[Q]))return"read";if(P4.has(z[Q])&&v0(z,Q+1,!0))return"read";if(["restore","restore-capsule"].includes(z[Q]))return"write";return"delete"}if(Y==="git"){let Q=L0(Z,J);if(Q==="clean"||Q==="rm")return z[1]===Q&&v0(z,2,!0)?"read":"delete";return Q==="clone"||Q==="init"?"write":"read"}if(Y==="find"&&!$.some((Q)=>n1(Q.text))&&!z.some((Q)=>s1.has(Q)))return"read";if(Y==="env"&&c(vZ(z)))return"delete";if(["sh","bash","zsh","dash","ksh","ash","eval","source",".","su","runuser","env","xargs","find","busybox","toybox"].includes(Y??""))return YZ(z.join(" "));if(["mkdir","mkfile","touch","mv","cp","ln","tee","install","dd","rsync","scp","truncate"].includes(Y??""))return"write";if(Y==="curl"||Y==="wget")return c1.test(z.join(" "))?"write":"read";if(Y==="sed"&&z.slice(1).some((Q)=>/^-i|^--in-place(?:=|$)/.test(Q)))return"write";if(["python","python3","node","bun"].includes(Y??"")&&z.some((Q)=>Q==="-c"||Q==="-e"))return"write";return"read"}function YZ(Z){let J=Z.replace(/[{},]/g," ");return J===Z?b0(Z):tZ(b0(Z),b0(J))}function b0(Z){let J=Z.trim();if(!J)return"read";if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:rm|rmdir|unlink|shred|trash|rmtree|del)(?:\s|$)/.test(J))return"delete";if(/\bgit\b/.test(J)){if(/\bgit\b[^;&|]*\b(?:clean|rm)\b/.test(J))return"delete";if(/\bgit\b[^;&|]*\b(?:clone|init)\b/.test(J))return"write";return"read"}if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|mv|cp|ln|tee|install|dd)(?:\s|$)/.test(J))return"write";if(/\b(?:curl|wget)\b/.test(J)){if(c1.test(J))return"write";return"read"}if(/\bsed\b/.test(J)){if(/(?:^|\s)-i\S*(?:\s|$)|--in-place(?:\s|$)/.test(J))return"write"}else if(/\b(?:rsync|scp|truncate)\b/.test(J))return"write";else if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(J))return"write";if(/(?:^|[;&|])\s*echo\b/.test(J)||/>/.test(i1(J)))return"write";return"read"}function fZ(Z,J){let $=Z.trim(),z=$.match(/^(['"])([\s\S]*)\1$/);if(z)$=z[2];if($=$.replace(/^"*\$HOME"*\//,"$HOME/"),$=$.replace(/^"*\$\{HOME\}"*\//,"${HOME}/"),$==="~")return J;if($.startsWith("~/"))return UZ(J,$.slice(2));if($==="$HOME"||$==="${HOME}")return J;if($.startsWith("$HOME/"))return UZ(J,$.slice(6));if($.startsWith("${HOME}/"))return UZ(J,$.slice(8));let Y=$.match(new RegExp(`^"*${f0(J)}"*/`));if(Y)return J+"/"+$.slice(Y[0].length);return Z}function L4(Z){let J=Z.trim();while(J.startsWith("(")||/^\{(?:\s|$)/.test(J))J=J.slice(1).trim();while(J.endsWith(")")||/(?:^|\s)\}$/.test(J))J=J.slice(0,-1).trim();return J}function f0(Z){return Z.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function k1(Z,J,$){if(Z===void 0)return[$];let z=fZ(Z,$),Y=z.match(/^(['"])(.*)\1$/);if(Y)z=Y[2];if(!z||z==="-"||/[$\x60*?[\]{}~\\'"]/.test(z))return null;return[...new Set(J.map((Q)=>kZ(Q,z)))]}var y4=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function A4(Z,J){let $=JZ(J);if(!$||$.index<=0||J[$.index].opaque)return 0;let z=x(Z);if(!z.trustworthy||z.substitutions.length>0||z.segments.length!==1)return 0;let[Y]=z.segments;if(Y.redirects.size>0||Y.words.length!==J.length)return 0;if(Y.words.some((Q,X)=>P(Q.text)!==J[X].text))return 0;return E(Y)===$.index?$.index:0}function R4(Z,J){let $=0;if(Z==="git")$=J.findIndex((Y)=>Y.text==="rm"||Y.text==="clean")+1;let z=!1;return J.slice($).filter((Y)=>{if(!z&&Y.text==="--")return z=!0,!1;if(!z&&Y.text.startsWith("-")&&!Y.opaque)return!1;return z=!0,!0})}var v4=new Set(["--agent","--spool","--files","--info","--config"]),b4=new Set(["--spool","--files","--info","--config"]),E4=new Set(["--json","--local","--help","-h","--version","--identity"]),x1={"--agent":/^[^-]/,"--retention":/^(?:\d+(?:\.\d+)?|never)$/},S4=new Set(["--to"]);function f4(Z){let J=[],$=0;for(;$<Z.length&&Z[$].text.startsWith("-");$++){let Q=Z[$];if(Q.opaque)return null;if(v4.has(Q.text)){let X=Z[++$];if(!X||X.opaque)return null;if(b4.has(Q.text))J.push(X)}else if(!E4.has(Q.text))return null}let z=Z[$];if(!z||z.opaque||!d1.has(z.text))return null;let Y=!1;for($++;$<Z.length;$++){let Q=Z[$];if(Y||Q.opaque||Q.text==="-"||!Q.text.startsWith("-")){J.push(Q);continue}if(Q.text==="--"){Y=!0;continue}let X=Q.text.indexOf("="),H=X<0?Q.text:Q.text.slice(0,X);if(S4.has(H)){if(X>=0)J.push({text:Q.text.slice(X+1),opaque:!1});else if(Z[$+1]&&!Z[$+1].text.startsWith("-"))J.push(Z[++$]);continue}let K=Z[$+1];if(X<0&&Object.hasOwn(x1,H)&&K&&!K.opaque&&x1[H].test(K.text))$++}return J}function k4(Z){let J=Z.split(`
18
- `),$=[],z=[],Y=0;while(Y<J.length){let Q=Y,X=J[Y++].replace(/\r$/,""),H=[];for(let K=0;K<X.length;K++){let B=X[K],M=z[z.length-1];if(B==="\\"){K++;continue}if(B==="$"&&X[K+1]==="("&&X[K+2]==="("){let V=X.indexOf("))",K+3);if(V<0)return null;K=V+1;continue}if(B==="$"&&X[K+1]==="("){z.push(0),K++;continue}if(B==="$"&&X[K+1]==="[")return null;if(B==="$"&&X[K+1]==="{"){let V=X.indexOf("}",K+2);if(V<0||/['"\x60$]|<</.test(X.slice(K+2,V)))return null;K=V;continue}if(B==="`"){let V=X.indexOf("`",K+1);if(V<0)return null;K=V;continue}if(M==='"'){if(B==='"')z.pop();continue}if(B==="'"){let V=X.indexOf("'",K+1);if(V<0)return null;K=V;continue}if(B==='"'){z.push('"');continue}if(B==="#"&&(K===0||/[\s;&|()]/.test(X[K-1])))break;if(B==="("&&X[K+1]==="("&&(K===0||/[\s;&|(]/.test(X[K-1]))){let V=X.indexOf("))",K+2);if(V<0)return null;K=V+1;continue}if(typeof M==="number"&&(B==="("||B===")")){if(B==="(")z[z.length-1]=M+1;else if(M===0)z.pop();else z[z.length-1]=M-1;continue}if(B==="<"&&X[K+1]==="<"){if(X[K+2]==="<"){K+=2;continue}let V=GZ(X,K);if(!V)return null;H.push({marker:V,from:K}),K=V.end-1}}for(let{marker:K,from:B}of H){let M=Y;for(;;){if(Y>=J.length)return null;let V=J[Y++].replace(/\r$/,"");if(K.stripTabs)V=V.replace(/^\t+/,"");if(V===K.delimiter)break}$.push({line:Q,from:B,to:K.end,start:M,end:Y-1,quoted:K.quoted})}}return z.length===0?$:null}var x4=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"]),h4=new Set([".","source","eval","env","alias","hash"]),w4=new Set(["tee","cp","mv","install","ln"]),a1=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"]),g4=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),l4=new Set(["pr","issue","api","release","gist"]);function u4(Z,J){let $=Z[J];if($==="gh")return l4.has(Z[J+1]??"");if($!=="git")return a1.has($);for(let z=J+1;z<Z.length;z++){let Y=Z[z];if(Y==="-C")z++;else if(Y==="--no-pager"||Y==="-P")continue;else return!Y.startsWith("-")&&g4.has(Y)}return!1}function m4(Z,J){for(let $=J+1;$<Z.length;$++){let z=Z[$];if(z==="\\")$++;else if(z==='"')return $;else if(z==="$"&&Z[$+1]==="("){if($=o1(Z,$+1),$<0)return-1}else if(z==="`"){if($=Z.indexOf("`",$+1),$<0)return-1}}return-1}function o1(Z,J){let $=0;for(let z=J;z<Z.length;z++){let Y=Z[z];if(Y==="\\")z++;else if(Y==="'"||Y==="`"){if(z=Z.indexOf(Y,z+1),z<0)return-1}else if(Y==='"'){if(z=m4(Z,z),z<0)return-1}else if(Y==="(")$++;else if(Y===")"&&--$===0)return z}return-1}function r1(Z){let J=[],$=!1;for(let z=0;z<Z.length;z++){let Y=Z[z];if(Y==="\\")z++;else if(Y==="'"&&!$){let Q=Z.indexOf("'",z+1);if(Q<0)return null;z=Q}else if(Y==='"')$=!$;else if(Y==="$"&&Z[z+1]==="("){let Q=o1(Z,z+1);if(Q<0)return null;let X=Z.slice(z+2,Q);if(Z[z+2]==="("){if(/\$\(|\x60/.test(X))return null}else J.push(X);z=Q}else if(Y==="`"){let Q=Z.indexOf("`",z+1);if(Q<0)return null;J.push(Z.slice(z+1,Q)),z=Q}}return $?null:J}function p4(Z){if(/[<>]\(/.test(Z))return!0;let J=[],$=[Z];for(let Y=0;$.length>0;Y++){if(Y>64)return!0;let Q=$.shift(),X=x(Q),H=r1(Q);if(!X.trustworthy||!H)return!0;J.push(...X.segments),$.push(...new Set([...X.substitutions,...H]))}let z=new Set;for(let Y of J){let Q=Y.words.map((K)=>P(K.text));for(let K of Y.redirects)z.add(p(Q[K]??""));let X=E(Y);if(X<0)continue;let H=p(Q[X]);if(w4.has(H)){for(let K of Q.slice(X+1))if(!K.startsWith("-"))z.add(p(K))}if(H==="dd"){for(let K of Q)if(K.startsWith("of="))z.add(p(K.slice(3)))}}z.delete("");for(let Y of J){for(let B of Y.words){let M=p(P(B.text));if(x4.has(M)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(M))return!0}let Q=E(Y),X=Y.words.map((B,M)=>({text:P(B.text),at:M})).filter(({at:B})=>!Y.redirects.has(B));if(X.some(({text:B,at:M})=>(Q<0||M<Q)&&LZ.test(B)))return!0;if(Q<0)continue;let H=Y.words[Q].text,K=P(H);if(/[$\x60]/.test(H)||K.includes("/")||h4.has(K)||z.has(K))return!0;if(!u4(X.filter(({at:B})=>B>=Q).map(({text:B})=>B),0))return!0}return!1}function c4(Z){if(!Z.includes("<<"))return null;let J=k4(Z);if(!J||J.length===0)return null;let $=Z.split(`
19
- `),z=[...$],Y=[];for(let X of J){let H=$.slice(X.start,X.end);if(!X.quoted&&H.some((K)=>/\$\(|\x60/.test(K)))return null;Y.push(H.join(`
20
- `));for(let K=X.start;K<=X.end;K++)z[K]=""}let Q=[...z];for(let X of[...J].reverse()){let H=Q[X.line];Q[X.line]=H.slice(0,X.from)+" ".repeat(X.to-X.from)+H.slice(X.to)}return p4(Q.join(`
21
- `))?null:{outer:z.join(`
22
- `),bodies:Y}}var i4="/";function t1(Z,J,$){if(!Z)return[];let z=c4(Z);if(!z)return l1(Z,J,$);return[...l1(z.outer,J,$),...z.bodies.flatMap((Y)=>t1(Y,J,i4))]}var d4=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,s4=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function h1(Z,J,$=!1){let z=[],Y=0;for(let H of J)z.push(Y),Y+=H.length;let Q=x(Z);if(!Q.trustworthy||!$&&Q.substitutions.length>0)return null;let X=Q.segments.flatMap((H)=>H.words).filter((H)=>J.some((K,B)=>B%2===1&&z[B]<H.end&&z[B]+K.length>H.start));return X.length>0?{lexed:Q,offsets:z,words:X}:null}function w1(Z,J,$=[]){if(k0(J)!=="read")return!1;let z=E(Z),Y=Z.words.filter((M,V)=>!Z.redirects.has(V)),Q=JZ(Y.map((M)=>({text:P(M.text),opaque:/[$\x60]/.test(M.text)})));if(Q===null)return!1;let X=[z<0?1/0:z,Q.index<0?1/0:Z.words.indexOf(Y[Q.index])];if(Z.words.some((M,V)=>V<Math.max(...X)&&!Z.redirects.has(V)&&LZ.test(P(M.text))))return!1;if([z<0?null:Z.words[z].text,Q.index<0?null:Y[Q.index].text].every((M)=>M===null||a1.has(p(P(M)))))return!0;let K=Y.filter((M)=>!$.includes(M)),B=K.map((M)=>P(M.text));return YZ(K.map((M)=>M.text).join(" "))==="read"&&YZ(B.join(" "))==="read"&&!B.some((M)=>s1.has(M))}function n4(Z,J,$,z){let Y=(Q)=>Q.start<z&&Q.end>$;if(!J.words.some(Y))return!1;return J.lexed.segments.filter((Q)=>Q.words.some(Y)).some((Q)=>eZ(Q))}var g1=(Z,J)=>Z.slice(J.words[0].start,J.words[J.words.length-1].end);function a4(Z,J,$,z){let Y=(X)=>X.start<z&&X.end>$,Q=J.words.filter(Y);if(Q.length===0||Q.some((X)=>!s4.test(X.text)))return!1;for(let X of J.lexed.segments.filter((H)=>H.words.some(Y)))if(!w1(X,g1(Z,X),J.words))return!1;for(let X of Q){let H=X.text.slice(1,-1);if(H.includes("<<"))return!1;let K=x(H);if(!K.trustworthy||K.substitutions.length>0)return!1;if(!K.segments.every((B)=>w1(B,g1(H,B))))return!1}return!0}function l1(Z,J,$){if(!Z)return[];let z=p1(J),Y=(U)=>z.some((j)=>U===j||U.startsWith(`${j}${E0}`)),Q=Z.split(d4),X=h1(Z,Q),H=X??h1(Z,Q,!0),K=[],B=[$],M=new Set([$]),V=!0,G=[];for(let U=0;U<Q.length;U+=2){let j=U===0?"":Q[U-1].trim();if(j==="||")V=!1;else if(j!=="&&")V=!0;if(j!=="&&"||!V)B=[...M];let F=Q[U],A=(F.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,v=(F.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let C=0;C<A;C++)G.push({current:[...B],reachable:new Set(M),certain:V});let h=L4(F),u=X!==null&&a4(Z,X,X.offsets[U],X.offsets[U]+F.length),D=!u&&(H!==null&&n4(Z,H,H.offsets[U],H.offsets[U]+F.length)||x0(F.trim())),N=h.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),y=N?null:h.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(y){for(let C of k1(y[1],B,J)??[])M.add(C);V=!1,B=[...M]}let S=f0(J),f=z.map((C)=>f0(C.slice(J.length+1))).join("|"),FZ=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${S}"*)/(?:${f})`),z1=new RegExp(`(${FZ.source})([^\\s"';&|<>()\`]*|$)`,"g"),Y1=(C)=>{let m=[],k;z1.lastIndex=0;while((k=z1.exec(C))!==null)m.push(WZ(fZ(k[0],J)).replace(/\/+$/,""));return m},K0=D4(h).map((C)=>{let m=[],k=!1,_Z=i1(C).replace(I4,(B0,e)=>{if(!e||/[$\x60]/.test(e))k=!0;if(e)m.push(e);return" "}),TZ=u?"read":D?"delete":k0(_Z);return{commandPart:_Z,operands:m,op:k&&TZ==="read"?"write":TZ}}),I2=K0.some((C)=>C.op==="delete")?"delete":K0.some((C)=>C.op==="write")?"write":"read",H0=B.filter(Y);if(D)for(let C of H0)K.push({path:C,op:"delete"});for(let C of K0){let m=!1;for(let b of Y1(C.commandPart))m=!0,K.push({path:b,op:I2});for(let b of C.operands){let s=Y1(b);for(let l of s)K.push({path:l,op:"write"});if(s.length>0)continue;for(let l of H0)K.push({path:WZ(kZ(l,fZ(b,J))),op:"write"})}if(m||C.op==="read")continue;let k=C4(C.commandPart),_Z=A4(C.commandPart,k),TZ=p(k[_Z]?.text??""),B0=k.slice(_Z+1),e=((TZ==="trash"?f4(B0):null)??R4(TZ,B0)).map((b)=>b.opaque?".":b.text),D2=C.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(C.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(C.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(C.commandPart),IZ=[];if(D2)for(let b of e.length>0?e:["."])IZ.push({operand:b,op:C.op});else{let b=C.commandPart.match(y4),s=k.at(-1);if(IZ.push({operand:b?b[1]:!s||s.opaque?".":s.text,op:C.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(C.commandPart))k.forEach((l,Q1)=>{let KZ,M0=l.text.match(/^-[A-Za-z]*?t(.*)$/),hZ=l.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(M0&&!l.text.startsWith("--"))KZ=M0[1]?{text:M0[1],opaque:l.opaque}:k[Q1+1];else if(hZ&&"--target-directory".startsWith(hZ[1]))KZ=hZ[2]!==void 0?{text:hZ[2],opaque:l.opaque}:k[Q1+1];if(KZ)IZ.push({operand:KZ.opaque||!KZ.text?".":KZ.text,op:C.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(C.commandPart))IZ.push({operand:".",op:C.op})}for(let b of H0)for(let{operand:s,op:l}of IZ)K.push({path:WZ(kZ(b,fZ(s,J))),op:l})}if(N){let C=k1(N[1],B,J);if(C){for(let m of C)M.add(m);if(V)B=C}else V=!1}for(let C=0;C<v&&G.length>0;C++)({current:B,reachable:M,certain:V}=G.pop())}return K}var o4=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function r4(Z,J){let $=[],z;while((z=o4.exec(Z))!==null){let Y=z[1]==="Delete File"?"delete":"write";$.push({path:WZ(kZ(J,z[2])),op:Y})}return $}function e1(Z,J={}){let $=[];if(Z.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:$};let z=typeof Z.tool_name==="string"?Z.tool_name:"",Y=J.home??u1(),Q=p1(Y),X=_4(process.env,Y);if(z==="Bash"){let G=BZ(Z);if(!G)return{output:{continue:!0},warnings:$};let U=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd(),j=t1(G,Y,U);for(let F of j)for(let A of Q){let v=R0(F.path,A,X,F.op);if(v.blocked)return{output:{decision:"block",reason:v.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let H=Z.tool_input??{},K=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(V4.has(z)){let G=typeof H.patch==="string"?H.patch:"";if(!G)return{output:{continue:!0},warnings:$};let U=r4(G,K);for(let j of U)for(let F of Q){let A=R0(j.path,F,X,j.op);if(A.blocked)return{output:{decision:"block",reason:A.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!M4.has(z))return{output:{continue:!0},warnings:$};let B=typeof H.file_path==="string"?H.file_path:typeof H.path==="string"?H.path:typeof H.notebook_path==="string"?H.notebook_path:null;if(!B)return{output:{continue:!0},warnings:$};let M=fZ(B,Y),V=m1(M)?WZ(M):kZ(K,M);for(let G of Q){let U=R0(V,G,X,"write");if(U.blocked)return{output:{decision:"block",reason:U.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var t4=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"]),e4=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),z2=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"]),Y2=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"]),Z5=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 g0 extends Error{}var O=()=>{throw new g0};function h0(Z,J){let $=[],z="",Y=J+1;while(Y<Z.length){let Q=Z[Y];if(Q==='"'){if(z)$.push(z);return{end:Y+1,parts:$}}if(Q==="\\"){let X=Z[Y+1];if(X==="("){let H=1,K=Y+2;while(K<Z.length&&H>0){let B=Z[K];if(B==='"'){K=h0(Z,K).end;continue}if(B==="(")H++;else if(B===")")H--;K++}if(H!==0)O();if(z)$.push(z),z="";$.push({src:Z.slice(Y+2,K-1)}),Y=K;continue}if(X===void 0)O();z+=X,Y+=2;continue}z+=Q,Y++}return O()}function Q2(Z){let J=[],$=0,z=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let Y=Z[$];if(/\s/.test(Y)){$++;continue}if(Y==="#")O();if(Y==='"'){let K=h0(Z,$);J.push({t:"str",parts:K.parts}),$=K.end;continue}if(Y==="."){if(Z[$+1]===".")O();let K=/^[A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($+1));if(K){J.push({t:"field",name:K[0]}),$+=1+K[0].length;continue}if(Z[$+1]==='"'){let B=h0(Z,$+1);if(B.parts.some((M)=>typeof M!=="string"))O();J.push({t:"field",name:B.parts.join("")}),$=B.end;continue}J.push({t:"dot"}),$++;continue}if(Y==="$"||Y==="@"){let K=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($));if(!K||Y==="$")O();J.push({t:"fmt",name:K[0]}),$+=K[0].length;continue}let Q=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(Z.slice($));if(Q){J.push({t:"num"}),$+=Q[0].length;continue}let X=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(Z.slice($));if(X){J.push({t:"ident",name:X[0]}),$+=X[0].length;continue}let H=z.find((K)=>Z.startsWith(K,$));if(!H)O();J.push({t:"op",v:H}),$+=H.length}return J}var J5=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 l0{tokens;at=0;constructor(Z){this.tokens=Z}parse(){if(this.tokens.length===0)O();let Z=this.pipe();if(this.at!==this.tokens.length)O();return Z}peek(){return this.tokens[this.at]}isOp(Z){let J=this.peek();return!!J&&J.t==="op"&&J.v===Z}isIdent(Z){let J=this.peek();return!!J&&J.t==="ident"&&J.name===Z}expectOp(Z){if(!this.isOp(Z))O();this.at++}pipe(){let Z=this.comma();if(this.isIdent("as"))O();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 J of["==","!=","<=",">=","<",">"])if(this.isOp(J))return this.at++,{k:"bool",a:Z,b:this.add()};for(let J of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(J))O();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 J=this.peek();if(!J)return Z;if(J.t==="field"){this.at++,Z={k:"field",name:J.name,of:Z};continue}if(J.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(J.t==="op"&&J.v==="?"){this.at++,Z={k:"opt",of:Z};continue}if(J.t==="op"&&J.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 J=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:J}}primary(){let Z=this.peek();if(!Z)return O();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))O();let J=this.peek();if(J?.t==="str")return this.at++,{k:"fmt",name:Z.name,str:this.stringNode(J.parts)};return{k:"fmt",name:Z.name}}case"ident":{if(J5.has(Z.name))O();if(Z.name==="map"||z2.has(Z.name)||Y2.has(Z.name)){let J=[];if(this.isOp("(")){this.at++,J.push(this.pipe());while(this.isOp(";"))this.at++,J.push(this.pipe());this.expectOp(")")}return{k:"call",name:Z.name,args:J}}return O()}case"op":{if(Z.v==="("){let J=this.pipe();return this.expectOp(")"),J}if(Z.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let J=this.pipe();return this.expectOp("]"),{k:"array",of:J}}if(Z.v==="{")return this.object();return O()}}return O()}stringNode(Z){let J=[];for(let $ of Z){if(typeof $==="string")continue;J.push(new l0(Q2($.src)).parse())}return J.length===0?{k:"str",parts:J,text:Z.join("")}:{k:"str",parts:J}}object(){let Z=[];if(this.isOp("}"))return this.at++,{k:"object",entries:Z};for(;;){let J=this.peek();if(!J)O();this.at++;let $;if(J.t==="ident")$=J.name;else if(J.t==="str"){if(J.parts.some((z)=>typeof z!=="string"))O();$=J.parts.join("")}else O();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 u0(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(u0);return Z==="safe"||typeof Z==="object"&&t4.has(Z.leaf)}var xZ=(...Z)=>Z.every(u0)?"safe":"tainted";function w0(...Z){let J=[];for(let $ of Z)if(typeof $==="object"&&"union"in $)J.push(...$.union);else J.push($);return J.length===1?J[0]:{union:J}}function Z0(Z,J){return typeof Z==="object"&&"union"in Z?w0(...Z.union.map(J)):J(Z)}var $0=(Z)=>typeof Z==="object"&&("leaf"in Z)&&e4.has(Z.leaf),o=(Z)=>Z0(Z,(J)=>J==="safe"?"safe":J==="tainted"||$0(J)?"tainted":"unknown");function Z2(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 $2(Z,J,$){return Z0(Z,(z)=>{if(z==="safe"||z==="tainted")return z;if($0(z))return"tainted";if(z==="root"&&$.rootScalars.has(J))return"safe";return{leaf:J}})}function L(Z,J,$){switch(Z.k){case"dot":return J;case"field":return $2(Z.of?L(Z.of,J,$):J,Z.name,$);case"iter":return o(L(Z.of,J,$));case"index":{let z=L(Z.of,J,$);if(Z.key.k==="str"&&Z.key.text!==void 0)return $2(z,Z.key.text,$);if(Z.key.k==="lit")return o(z);return L(Z.key,J,$),"tainted"}case"slice":return Z0(L(Z.of,J,$),(z)=>z==="root"?"unknown":$0(z)?"tainted":z);case"opt":return L(Z.of,J,$);case"lit":return"safe";case"str":return xZ(...Z.parts.map((z)=>L(z,J,$)));case"fmt":return Z.str?L(Z.str,J,$):J;case"array":return Z.of?xZ(L(Z.of,J,$)):"safe";case"object":return xZ(...Z.entries.map((z)=>L(z.value,J,$)));case"pipe":return L(Z.b,L(Z.a,J,$),$);case"comma":return w0(L(Z.a,J,$),L(Z.b,J,$));case"alt":return w0(L(Z.a,J,$),L(Z.b,J,$));case"bool":return L(Z.a,J,$),L(Z.b,J,$),"safe";case"arith":return xZ(L(Z.a,J,$),L(Z.b,J,$));case"neg":return L(Z.of,J,$);case"call":return z5(Z,J,$)}}var J2=(Z)=>Z0(Z,(J)=>J==="root"?"unknown":$0(J)?"tainted":J);function z5(Z,J,$){let{name:z,args:Y}=Z;if(Z5.has(z)&&z!=="limit"&&!Y.every(Z2))O();switch(z){case"map":if(Y.length!==1)O();return xZ(L(Y[0],o(J),$));case"select":if(Y.length!==1)O();return L(Y[0],J,$),J;case"limit":if(Y.length!==2||!Z2(Y[0]))O();return L(Y[1],J,$);case"first":case"last":if(Y.length>1)O();return Y.length===1?L(Y[0],J,$):o(J);case"min":case"max":return o(J);case"sort_by":case"group_by":case"unique_by":if(Y.length!==1)O();return L(Y[0],o(J),$),J2(J);case"min_by":case"max_by":if(Y.length!==1)O();return L(Y[0],o(J),$),o(J);case"any":case"all":case"isempty":for(let Q of Y)L(Q,"unknown",$);return"safe"}if(z2.has(z))return"safe";if(Y2.has(z))return J2(J);return O()}function X2(Z,J={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new l0(Q2(Z)).parse();return u0(L($,"root",{rootScalars:J.rootScalars??new Set}))}catch($){if($ instanceof g0)return!1;return!1}}var o0="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",I={refused:!1},T=(Z)=>({refused:!0,rule:Z}),m0=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"]),p0=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),K2=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),H2=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),Y5=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),Q5=new Set(["author","committer","id","parents","repository","sha","url"]),X5=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function V2(Z){let J=[];for(let $=0;$<Z.length;$++){let z=Z[$];if(z==="\\"){$++;continue}if(z==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return!1;$=Y;continue}if(z==='"'){$++;while($<Z.length&&Z[$]!=='"')$+=Z[$]==="\\"?2:1;continue}if(z==="{"){J.push({list:!1});continue}if(J.length===0)continue;if(z===","||z==="."&&Z[$+1]===".")J[J.length-1].list=!0;else if(z==="}"&&J.pop().list)return!0}return!1}function jZ(Z){let J="",$=!1,z=0,Y=(Q)=>Z[Q]==="`"||Z[Q]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(Z[Q+1]??"");while(z<Z.length){let Q=Z[z];if(Q==="\\"){J+=Z[z+1]??"",z+=2;continue}if(Q==="$"&&Z[z+1]==="'"){$=!0,J+=Q,z++;continue}if(Q==="'"){let X=Z.indexOf("'",z+1);if(X<0){$=!0,J+=Z.slice(z+1);break}J+=Z.slice(z+1,X),z=X+1;continue}if(Q==='"'){z++;while(z<Z.length&&Z[z]!=='"'){if(Z[z]==="\\"&&/[$`"\\\n]/.test(Z[z+1]??"")){J+=Z[z+1],z+=2;continue}if(Y(z))$=!0;J+=Z[z],z++}if(z>=Z.length)$=!0;z++;continue}if(Y(z)||Q==="*"||Q==="?"||Q==="[")$=!0;J+=Q,z++}if(!$&&Z.includes("{")&&V2(Z))$=!0;return{value:J,opaque:$,raw:Z}}var QZ=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function d0(Z,J="word"){let $=[],z=!1;for(let Y=0;Y<Z.length;Y++){let Q=Z[Y];if(Q==="\\"){Y++;continue}if(J==="word"&&Q==="'"&&!z){let X=Z.indexOf("'",Y+1);if(X<0)return{bodies:$,complete:!1};Y=X;continue}if(J==="word"&&Q==='"'){z=!z;continue}if(Q==="`"){let X=Y+1;while(X<Z.length&&Z[X]!=="`")X+=Z[X]==="\\"?2:1;if(X>=Z.length)return{bodies:$,complete:!1};$.push(Z.slice(Y+1,X)),Y=X;continue}if(Q==="$"&&Z[Y+1]==="("){let X=zZ(Z,Y+1);if(X<0)return{bodies:$,complete:!1};$.push(Z.slice(Y+2,X-1)),Y=X-1}}return{bodies:$,complete:!0}}function NZ(Z,J){let $=new Set(J.values),z={flags:[],positionals:[]},Y=(Q,X)=>({value:Q,opaque:X.opaque,raw:X.raw});for(let Q=0;Q<Z.length;Q++){let X=Z[Q],H=X.value;if(H==="--"){z.positionals.push(...Z.slice(Q+1));break}if(H.startsWith("--")&&H.length>2){let K=H.indexOf("="),B=K>=0?H.slice(0,K):H;if(K>=0)z.flags.push({name:B,value:Y(H.slice(K+1),X),inline:!0});else if($.has(B)){let M=Z[Q+1];z.flags.push(M?{name:B,value:M}:{name:B,missing:!0}),Q++}else z.flags.push({name:B});continue}if(H.startsWith("-")&&H.length>1){for(let K=1;K<H.length;K++){let B="-"+H[K],M=H.slice(K+1);if(M.startsWith("=")){z.flags.push({name:B,value:Y(M.slice(1),X),inline:!0});break}if(!$.has(B)){z.flags.push({name:B});continue}if(M)z.flags.push({name:B,value:Y(M,X),inline:!0});else{let V=Z[Q+1];z.flags.push(V?{name:B,value:V}:{name:B,missing:!0}),Q++}break}continue}z.positionals.push(X)}return z}function R(Z,...J){let $=!1;for(let z of Z.flags){if(!J.includes(z.name))continue;if(!z.inline){$=!0;continue}let Y=z.value;$=!Y.opaque&&["1","t","T","TRUE","true","True"].includes(Y.value)}return $}var t=(Z,...J)=>Z.flags.filter(($)=>J.includes($.name)),g=["-R","--repo","-q","--jq","-t","--template","--json"],XZ={"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"]}},K5=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"]),H5=new Set(["pr","issue","release","discussion","search","project","api","status"]),B5=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),M5=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),V5=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),G5=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function Q0(Z,J){let $=t(Z,"--json"),z=[],Y=!1;for(let Q of $){if(Q.missing){if(J.appendsArgs)Y=!0;continue}if(!Q.value)continue;if(Q.value.opaque)Y=!0;z.push(...Q.value.value.split(",").map((X)=>X.trim()).filter(Boolean))}return{present:$.length>0,opaque:Y,fields:z}}function r0(Z,J){if(R(Z,"--verbose")||t(Z,"-t","--template").length>0)return!1;let $=t(Z,"-q","--jq");return $.length>0&&$.every((z)=>z.value!==void 0&&!z.value.opaque&&X2(z.value.value,{rootScalars:J}))}function t0(Z,J,$,z){let Y=Q0(Z,$);if(Y.opaque)return T("unclassifiable");if(Y.fields.every((Q)=>J.has(Q)))return I;if($.debug)return T("debug-traffic");return r0(Z)?I:T(z)}function J0(Z,J,$,z,Y){let Q=NZ(Z,XZ[J]);if(R(Q,"-h","--help"))return I;if(R(Q,"-w","--web"))return z.debug?T("debug-traffic"):I;if(Y&&R(Q,"-c","--comments"))return T("view-comments");if(!Q0(Q,z).present)return T(z.debug?"debug-traffic":"view-human");return t0(Q,$,z,"json-composite")}function r(Z,J,$,z){let Y=NZ(Z,XZ[J]);if(R(Y,"-h","--help"))return I;if(z.debug&&(R(Y,"-w","--web")||!Q0(Y,z).present))return T("debug-traffic");if(R(Y,"-w","--web"))return I;return t0(Y,$,z,"json-composite")}function U5(Z,J){let $=NZ(Z,XZ["pr checks"]);if(R($,"-h","--help"))return I;if(J.debug)return T("debug-traffic");if(R($,"-w","--web"))return I;if(!Q0($,J).present)return T("checks-human");return t0($,X5,J,"checks-json")}function W5(Z){let J=new Set(XZ.group.values);for(let $=0;$<Z.length;$++){let z=Z[$].value;if(z==="--")return{sub:Z[$+1],rest:Z.slice($+2)};if(!z.startsWith("-")||z==="-")return{sub:Z[$],rest:[...Z.slice(0,$),...Z.slice($+1)]};if(J.has(z))$++}return{rest:Z}}function j5(Z,J,$){let{sub:z,rest:Y}=W5(J);if(!z)return $.appendsArgs?T("unclassifiable"):I;if(z.opaque)return T("unclassifiable");let Q=z.value;if((Z==="pr"?B5:Z==="issue"?M5:Z==="release"?V5:Z==="discussion"?G5:new Set).has(Q))return $.debug?T("debug-traffic"):I;if($.appendsArgs&&!(Z==="project"&&Q!=="item-list"))return T("unclassifiable");switch(Z){case"pr":if(Q==="view")return J0(Y,"pr view",m0,$,!0);if(Q==="list"||Q==="ls")return r(Y,"pr list",m0,$);if(Q==="status")return r(Y,"pr status",m0,$);if(Q==="checks")return U5(Y,$);if(Q==="diff"){let H=NZ(Y,XZ["pr diff"]);if(R(H,"-h","--help"))return I;if($.debug)return T("debug-traffic");return R(H,"--patch")?T("composite-other"):I}return T("unclassifiable");case"issue":if(Q==="view")return J0(Y,"issue view",p0,$,!0);if(Q==="list"||Q==="ls")return r(Y,"issue list",p0,$);if(Q==="status")return r(Y,"issue status",p0,$);return T("unclassifiable");case"release":if(Q==="view")return J0(Y,"release view",K2,$,!1);if(Q==="list"||Q==="ls")return r(Y,"release list",K2,$);return T("unclassifiable");case"discussion":if(Q==="view")return J0(Y,"discussion view",H2,$,!0);if(Q==="list"||Q==="ls")return r(Y,"discussion list",H2,$);return T("unclassifiable");case"search":if(Q==="prs"||Q==="issues")return r(Y,"search",Y5,$);if(Q==="commits")return r(Y,"search",Q5,$);if(Q==="code"||Q==="repos")return $.debug?T("debug-traffic"):I;return T("unclassifiable");case"project":{if($.debug)return T("debug-traffic");if(Q!=="item-list")return I;let H=NZ(Y,XZ["project item-list"]);if(R(H,"-h","--help"))return I;let K=t(H,"--format");if(K.some((B)=>!B.value||B.value.opaque))return T("unclassifiable");if(K.every((B)=>B.value.value!=="json"))return I;return r0(H)?I:T("composite-other")}}return T("unclassifiable")}var G2=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function N5(Z){let J=Z.value.trim(),$=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(J);if($){let Q=$[1].toLowerCase(),X=$[2]??"/";if(Q==="api.github.com"||/^api\./.test(Q))J=X;else if(/^\/api\/v3(?:\/|$)/i.test(X))J=X.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(X))J="graphql";else return null}J=J.replace(/[?#].*$/,"");let z=[],Y=[];for(let Q of J.split("/")){let X;try{X=decodeURIComponent(Q)}catch{return null}for(let H of X.split("/")){if(H===""||H===".")continue;if(H===".."){z.pop(),Y.pop();continue}z.push(H.toLowerCase()),Y.push(Z.opaque&&/[$`]/.test(H)||/[*?[]/.test(H)||V2(H))}}return{segments:z,opaque:Y}}function F5(Z){let J=N5(Z);if(!J)return{kind:"unclassifiable",segments:[]};let{segments:$,opaque:z}=J,Y=(K)=>({kind:K,segments:$});if($.length===1&&$[0]==="graphql")return Y("graphql");if($.length===0)return Y(Z.opaque?"unclassifiable":"other");if(z[0])return Y("unclassifiable");let Q,X=[];if($[0]==="repos")Q=$.slice(3),X=z.slice(3);else if($[0]==="repositories")Q=$.slice(2),X=z.slice(2);if(Q){if(($[0]==="repos"?z.slice(1,3):z.slice(1,2)).some(Boolean)){let B=z.findIndex(Boolean),M=$.findIndex((V,G)=>G>B&&!z[G]&&_5.has(V));return Y(M<0?"unclassifiable":B2($.slice(M),z.slice(M)))}return Y(B2(Q,X))}let H=$[0];if(H==="issues")return Y("sensitive");if(H==="user"&&$[1]==="issues")return Y("sensitive");if(H==="orgs"&&$[2]==="issues")return Y("sensitive");if(H==="search")return Y($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&z[1]?"unclassifiable":"other");if(H==="events"||H==="networks")return Y("sensitive");if((H==="users"||H==="orgs")&&$.slice(2).some((K)=>K==="events"||K==="received_events"||K==="discussions"))return Y("sensitive");if((H==="users"||H==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return Y("sensitive");if(H==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||H==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return Y("sensitive");if(H==="teams"&&$.includes("discussions"))return Y("sensitive");if(H==="projects"&&$.includes("cards"))return Y("sensitive");if(z.some(Boolean))return Y($.some((K)=>K==="events"||K==="discussions"||K==="issues")?"sensitive":"unclassifiable");return Y("other")}var _5=new Set([...G2,"branches","git","actions","hooks","zipball","tarball"]);function B2(Z,J){let[$,z]=Z;if($===void 0)return"other";if(J[0])return"unclassifiable";if($==="issues"&&/^\d+$/.test(z??"")&&Z[2]==="labels")return"other";if(G2.has($))return"sensitive";if($==="branches"){if(Z.length===1||Z.slice(1).some((Y)=>Y==="protection")||Z[Z.length-1]==="rename")return"other";return J.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if($==="git")return z===void 0||z==="commits"||z==="tags"?"sensitive":J[1]?"unclassifiable":"other";if($==="actions"){if(z===void 0)return"sensitive";if(J[1])return"unclassifiable";if(z==="runs"||z==="jobs"){if(Z[Z.length-1]==="logs"&&Z.length>=4&&!J.some(Boolean))return"download";return"sensitive"}if(z==="workflows"&&Z[3]==="runs")return"sensitive";if(z==="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 T5(Z,J){if(J[0]!=="repos"||J.length<5)return!1;let $=J.slice(3),z=(Q)=>/^\d+$/.test($[Q]??""),Y=(...Q)=>$.length===Q.length&&Q.every((X,H)=>typeof X==="number"?z(H):$[H]===X);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"&&z(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"&&z(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 I5(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 D5=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"]),C5=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function q5(Z){let J=[],$=0;while($<Z.length){let z=Z[$];if(/[\s,\uFEFF]/.test(z)){$++;continue}if(z==="#"){let X=Z.indexOf(`
23
- `,$);$=X<0?Z.length:X+1;continue}if(Z.startsWith('"""',$)){let X=$+3;for(;;){let H=Z.indexOf('"""',X);if(H<0)return null;if(Z[H-1]==="\\"){X=H+3;continue}$=H+3;break}continue}if(z==='"'){let X=$+1;while(X<Z.length&&Z[X]!=='"'&&Z[X]!==`
24
- `)X+=Z[X]==="\\"?2:1;if(Z[X]!=='"')return null;$=X+1;continue}let Y=/^[_A-Za-z][_0-9A-Za-z]*/.exec(Z.slice($,$+256));if(Y){J.push({kind:"name",text:Y[0]}),$+=Y[0].length;continue}let Q=/^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(Z.slice($,$+64));if(Q){$+=Q[0].length;continue}if(Z.startsWith("...",$)){J.push({kind:"punct",text:"..."}),$+=3;continue}if("{}()[]:!$@=|&".includes(z)){J.push({kind:"punct",text:z}),$++;continue}return null}return J}function P5(Z){let J=q5(Z);if(!J)return!0;let $=[],z="",Y=0;for(let Q=0;Q<J.length;Q++){let X=J[Q];if(X.kind==="punct"){if(X.text==="(")Y++;else if(X.text===")"){if(Y--,Y<0)return!0}else if(Y===0&&X.text==="{")$.push(z),z="";else if(Y===0&&X.text==="}"){if($.pop()===void 0)return!0;z=""}continue}if(Y>0)continue;let H=J[Q-1];if(H?.kind==="punct"&&(H.text==="@"||H.text==="$"))continue;if(J[Q+1]?.kind==="punct"&&J[Q+1].text===":")continue;if(X.text==="on"&&H?.kind==="punct"&&H.text==="...")continue;if(H?.kind==="name"&&H.text==="on"){z=X.text;continue}if($.length===0){z=X.text;continue}if(D5.has(X.text)||/(?:Url|URL|HTML|Html)$/.test(X.text))return!0;if(X.text==="title"&&$.some((K)=>C5.has(K)))return!0;z=X.text}return Y!==0||$.length!==0}function O5(Z,J){let $=NZ(Z,XZ.api);if(R($,"-h","--help"))return I;let z=$.positionals[0];if(!z)return J.appendsArgs?T("unclassifiable"):I;let Y=F5(z),Q=t($,"-X","--method"),X=Q[Q.length-1],H=t($,"-f","--raw-field","-F","--field","--input"),K=X?X.value&&!X.value.opaque?X.value.value.toUpperCase():"?":H.length>0?"POST":"GET",B=T5(K,Y.segments),M=I;if(Y.kind==="unclassifiable")M=T("unclassifiable");else if(Y.kind==="sensitive"&&!B)M=T("api-rest");else if(Y.kind==="graphql")M=L5($);if(J.debug||R($,"--verbose")){if(Y.kind==="download"&&!M.refused)M=T("api-rest");if(M.refused)return J.debug?T("debug-traffic"):M;return I}if(J.appendsArgs&&Y.kind!=="other"&&Y.kind!=="download")return T("unclassifiable");if(!M.refused||R($,"--silent"))return I;if(r0($,I5(Y.segments)))return I;return M}function L5(Z){if(t(Z,"--input").length>0)return T("unclassifiable");let J=t(Z,"-f","--raw-field","-F","--field"),$=J.filter((z)=>z.value&&/^query=/.test(z.value.value));if($.length===0||J.some((z)=>!z.value))return T("unclassifiable");for(let z of $){let Y=z.value.value.slice(6);if((z.name==="-F"||z.name==="--field")&&Y.startsWith("@")||z.value.opaque)return T("unclassifiable");if(P5(Y))return T("api-graphql")}return I}function Y0(Z,J){let $=0;while($<Z.length&&Z[$].value.startsWith("-")&&!Z[$].opaque){if(["--help","-h","--version"].includes(Z[$].value))return I;$++}if($>=Z.length)return J.appendsArgs?T("unclassifiable"):I;let z=Z[$],Y=Z.slice($+1);if(z.opaque)return T("unclassifiable");switch(z.value){case"pr":case"issue":case"release":case"discussion":case"search":case"project":return j5(z.value,Y,J);case"api":return O5(Y,J);case"status":return Y.length>0&&Y.every((Q)=>Q.value==="-h"||Q.value==="--help")?I:T("composite-other");case"help":case"version":return I;case"cs":case"codespace":{let Q=Y.findIndex((X)=>X.value==="--");if(Y.some((X)=>X.value==="ssh")&&Q>=0&&Q+1<Y.length){let X=i(Y.slice(Q+1).map((H)=>H.value).join(" "),J.depth+1,J.debug);if(X.refused)return X}break}}if(!K5.has(z.value))return T("unclassifiable");if(J.debug)return T("debug-traffic");return I}var X0=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","fish"]),y5=new Set(["su","runuser","script","flock"]),A5=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"]),R5=new Map([["bun",["x","exec"]],["npm",["exec","x"]],["deno",["run"]]]),v5=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"]),b5=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),z0=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/,E5=/^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/,S5=6;function M2(Z,J){let $,z;for(let Y of Z){let Q=E5.exec(Y.value);if(!Q)continue;let X={...Y,value:Q[2]};if(Q[1]==="GH_DEBUG")$=X;else if(Q[1]==="DEBUG")z=X}if($)return $.opaque||!["","0","false","no"].includes($.value);if(z&&(z.opaque||["1","true","yes","api"].includes(z.value)))return!0;return J}function e0(Z){let J=x(Z),$=0;return{segments:J.segments.map((Y)=>{let Q=Y.words[0],X=Z.slice($,Q.start);return $=Y.words[Y.words.length-1].end,{words:Y.words,redirects:Y.redirects,sepBefore:X}}),trustworthy:J.trustworthy}}var U2=(Z)=>/(?:^|[^|])\|&?$/.test(Z.trim());function s0(Z,J){if(!X0.has(Z))return!1;if(Z1(J))return!1;for(let $=0;$<J.length;$++){let z=J[$].value;if(z==="--")return $+1>=J.length;if(z==="-"||z==="-s")return!0;if(/^[-+][A-Za-z]*[oO]$/.test(z)){$++;continue}if(!z.startsWith("-")&&!z.startsWith("+"))return!1}return!0}function n0(Z){let{segments:J}=e0(Z.trim());if(J.length!==1)return null;let $=J[0],z=E($);if(z<0)return null;let Y=QZ(jZ($.words[z].text).value),Q=$.words.slice(z+1).filter((X,H)=>!$.redirects.has(H+z+1)).map((X)=>jZ(X.text));if(Y==="echo")return Q.filter((X,H)=>!(H===0&&/^-[neE]+$/.test(X.value))).map((X)=>X.value).join(" ");if(Y==="printf"){let[X,...H]=Q.filter((B)=>B.value!=="--");if(!X)return null;let K=0;return X.value.replace(/\\n/g,`
25
- `).replace(/%s/g,()=>H[K++]?.value??"")+(K<H.length?" "+H.slice(K).map((B)=>B.value).join(" "):"")}if(Y==="cat"){let X=Z.indexOf("<<");if(X<0)return null;let H=GZ(Z,X),K=Z.indexOf(`
26
- `,X);if(!H||K<0)return null;let B=rZ(Z,K,[H]);if(B<0)return null;let M=Z.slice(K+1,B);return M.slice(0,M.lastIndexOf(H.delimiter)).replace(/\n$/,"")}return null}function c0(Z,J,$){for(let z of d0(Z).bodies){let Y=n0(z);if(Y===null)continue;let Q=i(Y,J+1,$.debug);if(Q.refused)return Q}return I}function i(Z,J=0,$=!1){if(typeof Z!=="string"||!Z.trim())return I;if(J>S5)return z0.test(Z)?T("unclassifiable"):I;let{segments:z,trustworthy:Y}=e0(Z);if(!Y)return z0.test(Z)?T("unclassifiable"):I;let Q=$,X=(H)=>i(H,J+1,Q);for(let H of x5(Z)){if(H.runsBody){let K=X(H.body);if(K.refused)return K}if(!H.quoted){let K=d0(H.body,"heredoc");if(!K.complete&&z0.test(H.body))return T("unclassifiable");for(let B of K.bodies){let M=X(B);if(M.refused)return M}}}for(let H=0;H<z.length;H++){let K=z[H];for(let N of K.words){let y=d0(N.text);if(!y.complete&&z0.test(N.text))return T("unclassifiable");for(let S of y.bodies){let f=X(S);if(f.refused)return f}}let B=E(K),M=K.words.map((N,y)=>({word:jZ(N.text),redirect:K.redirects.has(y)})),V=M.slice(0,B<0?M.length:B).map((N)=>N.word),G=B>=0?QZ(M[B].word.value):"";if(B<0||["export","declare","typeset","readonly","local"].includes(G)){if(Q=M2([...V,...M.slice(B+1).map((N)=>N.word)],Q),B<0)continue}let U=M2(V,Q),j=M.slice(B+1).filter((N)=>!N.redirect).map((N)=>N.word),F=M.slice(B+1).filter((N)=>N.redirect).map((N)=>N.word),A=M[B].word,v=QZ(A.value),h={depth:J,appendsArgs:!1,debug:U};if(B>0&&M[B-1].word.value==="function"){let N=j.filter((S)=>!["{","()","(",")"].includes(S.value)),y=a0(N,h);if(y.refused)return y;continue}if(H>0&&U2(K.sepBefore)&&s0(v,j)){let N=z[H-1],y=f5(Z,N),S=y===null?null:n0(y);if(S!==null){let f=i(S,J+1,U);if(f.refused)return f}}let u=z[H+1];if(u&&/<\(\s*$/.test(u.sepBefore)&&(X0.has(v)||v==="source"||v===".")){let N=u.words[0].start-u.sepBefore.length+u.sepBefore.lastIndexOf("("),y=zZ(Z,N),S=y<0?null:n0(Z.slice(N+1,y-1));if(S!==null){let f=i(S,J+1,U);if(f.refused)return f}}let D=W2(v,A,j,F,K.words.slice(0,B+1),h);if(D.refused)return D}return I}function f5(Z,J){let $=J.words[0],z=J.words[J.words.length-1];return $&&z?Z.slice($.start,z.end):null}function k5(Z){let J=QZ(Z.value);return/[$`]/.test(J)||J===""?void 0:J}function W2(Z,J,$,z,Y,Q){let X=Q.depth,H=(K)=>i(K,X+1,Q.debug);if(J.opaque){let K=k5(J);if(K===void 0){let B=$.find((V)=>!V.value.startsWith("-")),M=Y0($,Q);if(!M.refused)return I;return M.rule!=="unclassifiable"||B!==void 0&&!B.opaque&&H5.has(B.value)?M:I}Z=K}if(Z==="gh")return Y0($,Q);if(X0.has(Z)){let K=Z1($);if(K){let B=H(K.value);if(B.refused||!K.opaque)return B;return c0(K.raw,X,Q)}for(let B of z){let M=H(B.value);if(M.refused)return M;if(B.opaque){let V=c0(B.raw,X,Q);if(V.refused)return V}}return I}if(y5.has(Z)){let K=$.findIndex((M)=>M.value==="-c"||M.value==="--command"||/^-[A-Za-z]*c$/.test(M.value)),B=K>=0?$[K+1]:void 0;return B?H(B.value):i0($,Q)}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 B=H(K.map((M)=>M.value).join(" "));if(B.refused)return B;for(let M of K){let V=c0(M.raw,X,Q);if(V.refused)return V}return I}if(Z==="env")return H(vZ([...Y.map((K)=>jZ(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(b5.has(V))K++}let B=$.slice(K+1);if(B[0]?.value==="--")B.shift();let M=B.map((V)=>V.value).join(" ");return M?H(M):I}if(Z==="xargs"){let K=0,B=!1;for(;K<$.length;K++){let M=$[K].value;if(M==="--"){K++;break}if(!M.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(M))B=!0;if(v5.has(M))K++}return a0($.slice(K),{depth:X,appendsArgs:!B,debug:Q.debug})}if(Z==="find"){for(let K=0;K<$.length;K++){if(!["-exec","-execdir","-ok","-okdir"].includes($[K].value))continue;let B=K+1;while(B<$.length&&$[B].value!==";"&&$[B].value!=="+")B++;let M=a0($.slice(K+1,B),Q);if(M.refused)return M;K=B}return I}if(A5.has(Z))return i0($,Q);if(R5.get(Z)?.includes($[0]?.value??""))return i0($.slice(1),Q);return I}function a0(Z,J){if(Z.length===0)return I;let $=QZ(Z[0].value);if($==="gh")return Y0(Z.slice(1),J);if(X0.has($)){let z=Z1(Z.slice(1));return z?i(z.value,J.depth+1,J.debug):I}return W2($,Z[0],Z.slice(1),[],[],J)}function i0(Z,J){let $=Z.findIndex((z)=>!z.opaque&&QZ(z.value)==="gh"&&(z.value==="gh"||z.value.includes("/")));return $>=0?Y0(Z.slice($+1),J):I}function Z1(Z){for(let J=0;J<Z.length;J++){let $=Z[J].value;if($==="--")return;if(!$.startsWith("-")&&!$.startsWith("+"))return;if($==="-c"||/^-[A-Za-z]+$/.test($)&&$.includes("c"))return Z.slice(J+1).find((z)=>!z.value.startsWith("-")||z.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test($))J++}return}function x5(Z){let J=[],$=0;for(;;){let z=Z.indexOf("<<",$);if(z<0)break;if($=z+2,Z[z+2]==="<"||z>0&&Z[z-1]==="<"){$=z+3;continue}let Y=GZ(Z,z);if(!Y)continue;let Q=Z.lastIndexOf(`
27
- `,z)+1,X=Z.indexOf(`
28
- `,z);if(X<0)continue;let H=rZ(Z,X,[Y]),K=H<0?Z.slice(X+1):Z.slice(X+1,H),B=H<0?K:K.slice(0,Math.max(0,K.lastIndexOf(Y.delimiter))).replace(/\n$/,""),M=Z.slice(Q,z)+" HEREDOC_OPERATOR "+Z.slice(Y.end,X);J.push({body:B,runsBody:h5(M),quoted:Y.quoted})}return J}function h5(Z){let{segments:J}=e0(Z),$=J.findIndex((H)=>H.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let z=(H)=>{let K=E(H);if(K<0)return{verb:"",args:[]};let B=H.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>jZ(M.text));return{verb:QZ(jZ(H.words[K].text).value),args:B}},{verb:Y,args:Q}=z(J[$]);if(Y==="ssh"||s0(Y,Q))return!0;if((Y==="source"||Y===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(Q[0]?.value??""))return!0;let X=J[$+1];if(Y==="cat"&&X&&U2(X.sepBefore)){let H=z(X);return H.verb==="ssh"||s0(H.verb,H.args)}return!1}var w5=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function j2(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:o0}}}var g5=new Set(["Bash","Monitor"]);function N2(Z){if(Z?.hook_event_name!=="PreToolUse"||!g5.has(Z.tool_name??""))return{continue:!0};let J=BZ(Z);if(!J.trim())return{continue:!0};try{return i(J).refused?j2():{continue:!0}}catch{return w5.test(J)?j2():{continue:!0}}}function J1(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function _2(Z,J){J1(Z);let $=Z,z=JSON.parse(J);if(!z||Array.isArray(z)||z.hook_event_name!=="PreToolUse"||typeof z.tool_name!=="string"||!z.tool_input||typeof z.tool_input!=="object"||Array.isArray(z.tool_input)||typeof z.cwd!=="string"||!F2(z.cwd))throw Error("Invalid safety input");if(z.tool_name==="Bash"&&typeof z.tool_input.command!=="string")throw Error("Invalid shell input");if(z.tool_name==="Monitor"&&z.tool_input.command!==void 0&&typeof z.tool_input.command!=="string")throw Error("Invalid monitor input");let Y=z.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 Q=Y===void 0?void 0:{runtime:process.execPath,home:$1(),path:process.env.PATH,agent:Y.agent};if(Q&&(!F2(Q.runtime)||!Q.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(z.tool_name)){if(z.tool_input.command!==void 0&&z.tool_input.patch!==void 0&&z.tool_input.command!==z.tool_input.patch)throw Error("Conflicting patch aliases");let F=z.tool_input.command??z.tool_input.patch;if(typeof F!=="string")throw Error("Invalid patch input");z.tool_input={...z.tool_input,command:F,patch:F}}let X=z.tool_name==="Monitor",H=z.tool_name==="Bash"||X&&typeof z.tool_input.command==="string",K=X&&H?{...z,tool_name:"Bash"}:z,B=(F)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:F}}),M=e1(K).output,V=N2(K),G=H&&EZ(K.tool_input.command,{home:$1(),cwd:z.cwd}).handoffHits.length>0,U=$==="trash-guard"&&(!X||H)?v1(K,{home:$1(),cwd:z.cwd,findTrash:uZ,inspectTrash:PZ,execution:Q}):{continue:!0};if(X&&U.hookSpecificOutput?.permissionDecision==="allow")U=B("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let j=M.decision==="block"?B(M.reason):V.hookSpecificOutput?V:G?B("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):U;return JSON.stringify({verdict:"continue"in j?null:j})}var T2=process.argv[1];J1(T2);process.stdout.write(_2(T2,await Bun.stdin.text()));
2
+ import{homedir as B1}from"os";import{isAbsolute as R2}from"path";import{isAbsolute as O3,join as jZ,normalize as L3,resolve as A3,sep as R0}from"path";import{dirname as VZ,isAbsolute as oZ,join as _0,resolve as $Z}from"path";import{accessSync as f2,closeSync as k2,constants as sZ,fstatSync as x2,lstatSync as AZ,openSync as h2,readFileSync as w2,readlinkSync as g2,readSync as u2,realpathSync as D0,statSync as T0}from"fs";import{spawnSync as l2}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 yZ(Z){return Z===0||Z===process.getuid?.()}function nZ(Z,z=!1){let $=Z;for(let J=0;J<32;J++){if(!oZ($)||$.length>4096||!RZ("/"))return!1;let Y=$.split("/"),X=Y.pop();if(!X||X==="."||X==="..")return!1;let Q="/";for(let B of Y){if(!B||B===".")continue;if(B===".."){Q=VZ(Q);continue}let M=_0(Q,B),V=AZ(M);if(z&&M==="/bin"&&V.isSymbolicLink()&&V.uid===0){let G=D0(M);if(!RZ(G))return!1;Q=G;continue}if(!V.isDirectory()||!yZ(V.uid)||V.mode&18)return!1;Q=M}let H=_0(Q,X),K=AZ(H);if(!yZ(K.uid))return!1;if(K.isSymbolicLink()){let B=g2(H);$=oZ(B)?B:Q+"/"+B;continue}return K.isFile()&&Boolean(K.mode&73)&&!(K.mode&18)}return!1}function m2(Z){if(!oZ(Z)||$Z(Z)!==(Z.replace(/\/+$/,"")||"/"))return!1;for(let z=$Z(Z);;z=VZ(z)){try{return AZ(z),RZ(z)}catch($){if($.code!=="ENOENT")return!1}if(VZ(z)===z)return!1}}function p2(Z,z){let $=h2(Z,sZ.O_RDONLY|sZ.O_NONBLOCK|sZ.O_NOFOLLOW),J;try{if(!x2($).isFile())return!1;let X=Buffer.alloc(256),Q=u2($,X,0,X.length,0);J=X.subarray(0,Q).toString("utf8").split(`
3
+ `)[0]}finally{k2($)}let Y=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(J);if(Y&&Y[1]!=="/usr/bin/env")return nZ(Y[1],!0);if(J!=="#!/usr/bin/env bun"||!nZ("/usr/bin/env",!0))return!1;for(let X of z.split(":").slice(0,64)){if(!m2(X))return!1;let Q=$Z(X,"bun");try{if(!T0(Q).isFile())continue;f2(Q,sZ.X_OK)}catch{continue}return nZ(Q,!0)}return!1}function RZ(Z){let z=Z;for(;;){let $=AZ(z);if(!$.isDirectory()||!yZ($.uid)||($.mode&18)!==0)return!1;let J=VZ(z);if(J===z)return!0;z=J}}function vZ(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(!oZ(X)||Date.now()>=$)continue;let Q=$Z(X,"trash");try{let H=T0(Q);if(!H.isFile()||!yZ(H.uid)||(H.mode&73)===0||(H.mode&18)!==0){Y("unsafe_executable");continue}let K=D0(Q);if(!RZ($Z(X))||!RZ(VZ(K))){Y("unsafe_directory");continue}if(!nZ(Q)){Y("unsafe_directory");continue}let B=$Z(VZ(K),"../.."),M=_0(B,"package.json"),V=T0(M);if(!V.isFile()||!yZ(V.uid)||V.size>16384||(V.mode&18)!==0||AZ(M).isSymbolicLink()){Y("unsafe_manifest");continue}let G=JSON.parse(w2(M,"utf8"));if(G.name!=="@hasna/trash"||typeof G.version!=="string"||typeof G.bin?.trash!=="string"||D0($Z(B,G.bin.trash))!==K){Y("unrecognized_package");continue}try{if(!p2(K,z)){Y("unsafe_interpreter");continue}}catch{Y("unsafe_interpreter");continue}let U=$-Date.now();if(U<=0){Y("identity_failed");break}let j=l2(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 N=JSON.parse(j.stdout);if(N.name==="@hasna/trash"&&N.version===G.version&&N.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:Q,version:G.version};Y("unsupported_protocol")}catch{}}return{ok:!1,code:J}}function aZ(Z=process.env){let z=vZ(Z);return z.ok?z.path:null}function GZ(Z){let z=Z.tool_input?.command;return typeof z==="string"?z:""}var F1=["/","/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 EZ=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,c=(Z)=>Z.split("/").pop()??"";function rZ(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 I0=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 c2(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>I0)return"overflow";let H=z&&(/^[-+]?0\d/.test(J[1])||/^[-+]?0\d/.test(J[2]))?Math.max(J[1].length,J[2].length):0,K=[];for(let B=Y;Y<=X?B<=X:B>=X;B+=Y<=X?Q:-Q)if(!z)K.push(String.fromCharCode(B));else K.push(B<0?`-${String(-B).padStart(H-1,"0")}`:String(B).padStart(H,"0"));return K}function i2(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(++$>I0)return"overflow";let X=null,Q=0,H=!0,K=[];for(let B=J;B<Z.length;B++){let M=Z[B];if(X==="'"){if(M==="'")X=null;continue}if(M==="\\"){H=!1,B++;continue}if(X==='"'){if(M==='"')X=null;continue}if(M==="'"||M==='"')X=M,H=!1;else if(M==="$"&&Z[B+1]==="{")B=_1(Z,B+1),H=!1;else if(M==="{")Q++;else if(M===","&&Q===1)K.push(B);else if(M==="}"&&--Q===0){if(K.length>0){let G=[J,...K,B];return{open:J,close:B,parts:G.slice(0,-1).map((U,j)=>Z.slice(U+1,G[j+1]))}}let V=H?c2(Z.slice(J+1,B)):null;if(V==="overflow")return V;if(V)return{open:J,close:B,parts:V};break}}}}return null}function JZ(Z){if(Z.length>4096&&Z.includes("{"))return null;let z=i2(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)>I0)return null}return $}var W={arg:"none"},D={arg:"value"},bZ={arg:"optional"},s={arg:"none",effect:"lookup"},C={arg:"none",effect:"refuse"},o={help:C,version:C},d2=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,q0={timeout:{short:{k:D,s:D,v:W},long:{"kill-after":D,signal:D,verbose:W,foreground:W,"preserve-status":W,...o},positionals:[d2]},env:{short:{i:W,"0":W,v:W,u:D,a:D,C,S:C},long:{"ignore-environment":W,null:W,debug:W,unset:D,argv0:D,chdir:C,"split-string":C,"block-signal":bZ,"default-signal":bZ,"ignore-signal":bZ,"list-signal-handling":C,...o},env:!0},nice:{short:{n:D},long:{adjustment:D,...o},numericOption:!0},nohup:{short:{},long:{...o}},command:{short:{p:W,v:s,V:s},long:{}},exec:{short:{c:W,l:W,a:D},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:D,o:D,e:D},long:{input:D,output:D,error:D,...o}},time:{short:{p:W,a:W,q:W,v:W,f:D,o:C,V:C},long:{portability:W,append:W,quiet:W,verbose:W,format:D,output:C,...o}},ionice:{short:{c:D,n:D,t:W,p:C,P:C,u:C,h:C,V:C},long:{class:D,classdata:D,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}}},s2=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function n2(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 H=Q.indexOf("="),K=H<0?Q.slice(2):Q.slice(2,H),B=Object.keys(Z.long),M=B.includes(K)?[K]:B.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"&&H>=0)return null;if(V.arg==="value"&&H<0){let G=z[++$];if(!G||G.opaque)return null}$++;continue}for(let H=1;H<Q.length;H++){let K=Z.short[Q[H]];if(!Y(K))return null;if(K.arg==="value"){if(H===Q.length-1){let B=z[++$];if(!B||B.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&&EZ.test(z[$].text);$++)if(z[$].opaque)return null}return $}function zZ(Z,z=q0){let $=0;while($<Z.length&&(EZ.test(Z[$].text)||s2.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=n2(Y,Z,$+1);if(X===null)return null;if(X<0)return{index:-1};$=X}return null}function o2(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 O0=(Z)=>Z.split("/").pop()??"",P0={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}},q1=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,a2=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),r2=new Set(["ssh","scp","sftp"]),t2=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),D1=new Set(["proxycommand","localcommand","knownhostscommand"]),e2=/(?:`|\$\()|\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/,Z3=/[|>]|\b(?:system|getline|close|fflush|print\w*\s*>>?)/;function C1(Z){if(o2(Z.text))return!1;if(Z.kind==="awk")return!Z3.test(Z.text);if(Z.kind==="c-interp")return!e2.test(Z.text);return!1}function $3(Z,z,$,J){let Y=P0[Z]??(q1.test(Z)?P0[Z.replace(/[0-9.]+$/,"")]:void 0);if(!Y)return null;let X=[],Q=!1,H=(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 B=z[K];if(B==="--")break;if(!B.startsWith("-")||B==="-")break;if(B.startsWith("--")){let V=B.indexOf("="),G=V<0?B:B.slice(0,V);if(Y.long.has(G))if(V>=0)X.push({text:B.slice(V+1),kind:"c-interp"});else K=H(K);continue}let M=B.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=H(K);break}}if(X.length===0&&!Q)return null;return{programs:X,unresolved:Q}}function J3(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 z3(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 H=Q==="-e"?null:Q.slice(2);if(H!==null)J.push({text:H,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 Y3(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 X3(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:B}=Y3(Z,X,$);if(X=B,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(D1.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 H=Q.slice(1);for(let K=0;K<H.length;K++){if(!t2.has(H[K]))continue;if(K<H.length-1)break;if(H[K]==="o"||H[K]==="F"||H[K]==="S"){if(X+1<Z.length){let B=Z[X+1];if(H[K]==="o")if(!$(X+1)){let M=B.indexOf("="),V=M>=0?M:B.search(/\s/),G=(V>=0?B.slice(0,V):B).trim().toLowerCase();if(D1.has(G))J.push({text:V>=0?B.slice(V+1).trim():"",kind:"shell"})}else Y=!0;else if(H[K]==="F")Y=!0;else if(!$(X+1))J.push({text:B,kind:"shell"});X++}}else if(X+1<Z.length)X++}}return{programs:J,unresolved:Y}}function Q3(Z,z,$){let J=[],Y=!1,X=!1;for(let Q=z+1;Q<Z.length;Q++){let H=Z[Q];if(H==="--")break;if(H==="-e"||H==="--rsh")if(X=!0,Q+1<Z.length&&!$(Q+1))J.push({text:Z[++Q],kind:"shell"});else Y=!0;else if(H.startsWith("--rsh="))X=!0,J.push({text:H.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(H)&&H.length>2&&!H.startsWith("--"))X=!0,J.push({text:H.slice(H.indexOf("e")+1),kind:"shell"})}return X?{programs:J,unresolved:Y}:null}var K3=/^(?:true|false|yes|no|on|off|1|0|)$/i,H3=[/^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 P1(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&&K3.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(H3.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)=>P1(Z,z).kind!=="harmless")}var B3=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"]),M3=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function V3(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]),H=Q.indexOf("=");J.push(H<0?[Q,void 0]:[Q.slice(0,H),Q.slice(H+1)])}}return J}function G3(Z,z,$){let J=[],Y=!1,X=(B,M,V=!0)=>{if(!V||/[$\x60]/.test(B)){Y=!0;return}let G=P1(B,M);if(G.kind==="unresolved")Y=!0;else if(G.kind==="command")J.push({text:G.text,kind:"shell"})},Q=(B,M)=>{let V=B.indexOf("="),G=V<0?B:B.slice(0,V),U=V<0?"true":B.slice(V+1);if(!M)return X(G,U);if(T1(G))Y=!0},H=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let B=z+1;B<Z.length;B++){let M=Z[B];if(!M.startsWith("-")||M==="-")break;if(M==="--")break;if(M==="-c"){if(B+1>=Z.length)break;Q(Z[B+1],$(B+1)),B++}else if(M.startsWith("-c")&&!M.startsWith("--"))Q(M.slice(2),$(B));else if(M==="--config-env"||M.startsWith("--config-env=")){let V=M==="--config-env"?Z[++B]??"":M.slice(13),G=V.indexOf("="),U=G<0?V:V.slice(0,G);if($(B)||T1(U))Y=!0}else if(M.startsWith("--exec-path="))Y=!0;else if(H.has(M))B++}let K=new Map;for(let B=0;B<z;B++){let M=Z[B].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!M)continue;let[,V,G]=M,U=$(B);if(B3.has(V))if(U)Y=!0;else J.push({text:G,kind:"shell"});else if(M3.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:V3(G);if(j===null)Y=!0;else for(let[N,L]of j)X(N,L??"true")}else if(/^GIT_CONFIG_(?:KEY|VALUE)_\d+$/.test(V)){let j=V.replace(/^GIT_CONFIG_(?:KEY|VALUE)_/,""),N=K.get(j)??{};if(V.startsWith("GIT_CONFIG_KEY_"))N.key=G;else N.value=G;if(U)N.opaque=!0;K.set(j,N)}}for(let B of K.values()){if(B.key===void 0)continue;if(B.opaque)Q(`${B.key}=`,!0);else X(B.key,B.value)}if(J.length===0&&!Y)return null;return{programs:J,unresolved:Y}}function SZ(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 I1(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 U3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]),j3=new Set(["--rcfile","--init-file"]),UZ=(Z)=>Z.replace(/\$'(?:[^'\\]|\\[\s\S])*'/g,(z)=>z.replace(/\\[\s\S]/g,($)=>$==="\\'"?"\\x27":$));function kZ(Z,z,$=SZ){if(z<0||z>=Z.length)return null;let J=O0($(Z[z])??"");if(J==="eval"){let H=z+1;if(SZ(Z[H]??"")==="--")H++;let K=Z.slice(H);if(K.length===0)return null;if(K.length>1)return{program:null,literal:!1};let B=SZ(K[0]);return B!==null&&I1(B)?{program:B,literal:!0}:{program:B,literal:!1}}if(!U3.has(J))return null;let Y=!1,X=z+1;for(;X<Z.length;X++){let H=SZ(Z[X]);if(H===null){if(Y)break;return/^"[^"]*"$/.test(Z[X])?null:{program:null,literal:!1}}if(H==="--"){X++;break}if(!/^[-+]./.test(H))break;if(H.startsWith("--")){if(j3.has(H))X++;continue}let K=H.slice(1);if(H[0]==="-"&&K.includes("c"))Y=!0;if(/[oO]/.test(K))X++}if(!Y||X>=Z.length)return null;let Q=SZ(Z[X]);return Q!==null&&I1(Q)?{program:Q,literal:!0}:{program:Q,literal:!1}}function W3(Z,z,$){let J=N3(Z,z,$);if(J===null)return{programs:[],unresolved:!0};let Y=new Set;for(let{scripts:X,mayFail:Q}of J){let H=F3(X.join(`
5
+ `));if(H===null){if(Q)continue;return{programs:[],unresolved:!0}}if(H.executes)return{programs:X.map((K)=>({text:K,kind:"shell"})),unresolved:!0};for(let K of H.writes)Y.add(K)}if(Y.size===0)return null;return{programs:[],unresolved:!1,writes:[...Y]}}var C0="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 N3(Z,z,$){let J=[],Y=[],X=!1,Q=-1,H=!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 N=G.indexOf("="),L=(N<0?G:G.slice(0,N)).slice(2),y=C0.filter((l)=>l.startsWith(L)),E=C0.includes(L)?L:y.length===1?y[0]:"";if(C0.indexOf(E)<15){if(!E)return null;continue}if(U=E[0],N>=0)j=G.slice(N+1)}else{let N=1;while("nrEsuzb".includes(G[N]??"_"))N++;if(U=G[N]??"",U==="i"||U==="I"){let L=N===G.length-1&&V+1<Z.length&&!$(V+1)?Z[V+1]:void 0;if(U==="I"){if(H=X=!0,N===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(N+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 B=(V)=>{if(J.length>0)return J;let G=Y.find((U)=>U!==V);return G===void 0?[]:$(G)?null:[Z[G]]},M=[];if(!H)M.push({scripts:B(-1),mayFail:Q>=0&&J.length===0&&Y[0]===Q});if(X)M.push({scripts:B(Q),mayFail:!1});return M.some((V)=>V.scripts===null)?null:M}function F3(Z){let z=[],$=!1,J=0,Y=Z.length,X=()=>Z[J]??"",Q=()=>{while(X()===" "||X()==="\t")J++;let B=J,M=Z.indexOf(`
6
+ `,J);return J=M<0?Y:M,Z.slice(B,J)},H=()=>{let B=Q();if(B&&!/^\/dev\/std(?:out|err)$/.test(B))z.push(B)},K=(B,M)=>{for(;J<Y;J++){let V=Z[J];if(V===`
7
+ `)return!1;if(V==="\\"){if(++J>=Y)return!1}else if(V===B)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 B=Z[J++];if(B==="/"||B==="\\"){let M=B==="\\"?Z[J++]??"":"/";if(!M||M===`
11
+ `||!K(M,!0))return null}else if(B==="#")Q();else if(":btTv".includes(B)){while(X()===" "||X()==="\t")J++;while(J<Y&&!/[\s;]/.test(X()))J++}else if("aic".includes(B)){while(X()===" "||X()==="\t")J++;if(X()==="\\")J+=2;for(;J<Y&&Z[J]!==`
12
+ `;J++)if(Z[J]==="\\")J++}else if(B==="e")$=!0,Q();else if(B==="r"||B==="R")Q();else if(B==="w"||B==="W")H();else if(B==="s"||B==="y"){let M=Z[J++]??"";if(!M||M===`
13
+ `||M==="\\"||!K(M,B==="s")||!K(M,!1))return null;for(;B==="s"&&" \tgpiImMe0123456789w".includes(X()||"_");J++){if(X()==="e")$=!0;if(X()==="w"){J++,H();break}}}}return{writes:z,executes:$}}var _3=new Set(["-exec","-execdir","-ok","-okdir"]),D3=new Set(["-exec","-execdir"]),T3=new Set("0oprtx"),I3=new Set("adEILnPsJRS"),q3=new Set("eil"),tZ={"--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 C3(Z){if(Object.hasOwn(tZ,Z))return tZ[Z];let z=Object.keys(tZ).filter(($)=>$.startsWith(Z));return z.length===1?tZ[z[0]]:null}function fZ(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 H=Y.indexOf("="),K=C3(H<0?Y:Y.slice(0,H));if(K===null){if(J>=4)return[];return[...fZ(Z,z+1,$,J+1),...fZ(Z,z+2,$,J+1)]}z+=K==="value"&&H<0?2:1;continue}let X=!1,Q=!1;for(let H=1;H<Y.length;H++){let K=Y[H];if(T3.has(K))continue;if(q3.has(K))break;if(I3.has(K)){X=H===Y.length-1;break}Q=!0;break}if(Q){if(J>=4)return[];return[...fZ(Z,z+1,$,J+1),...fZ(Z,z+2,$,J+1)]}z+=X?2:1}while(z<Z.length&&$(z))z++;return z<Z.length?[z]:[]}function xZ(Z,z,$=()=>!1){if(z<0||z>=Z.length)return[];let J=O0(Z[z]);if(J==="xargs")return[...new Set(fZ(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)||!_3.has(Z[X]))continue;let Q=X+1,H=Q;for(;H<Z.length;H++){if($(H))continue;if(Z[H]===";")break;if(Z[H]==="+"&&H>Q&&Z[H-1]==="{}"&&D3.has(Z[X]))break}if(Q<H)Y.push({start:Q,end:H});X=H}return Y}function hZ(Z,z,$){if(z<0||z>=Z.length)return null;let J=O0(Z[z]);if(J==="deno"){let Y=J3(Z,z,$);if(Y)return Y}if(Object.hasOwn(P0,J)||q1.test(J))return $3(J,Z,z,$);if(a2.has(J))return z3(Z,z,$);if(r2.has(J))return X3(Z,z,$);if(J==="rsync")return Q3(Z,z,$);if(J==="git")return G3(Z,z,$);if(J==="sed")return W3(Z,z,$);return null}var y3=600000,R3="Delete via trash guard (rm intercepted and made recoverable)",v3=[".hasna/repos/clones","workspace/repos"],b3=[".hasna",".ssh",".aws"],L0={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."},E3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env"]),S3={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"]},f3={timeout:1},k3={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:D,g:D,p:D,r:D,T:D,t:D,U:D,u:D,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":D,chdir:C,"preserve-env":bZ,edit:s,group:D,"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:D,chroot:C,role:D,stdin:W,shell:W,type:D,"command-timeout":D,"other-user":D,user:D,version:C,validate:s},assignments:!0},doas:{short:{n:W,s:W,u:D,C,L:C},long:{}},flock:{short:{s:W,x:W,e:W,n:W,u:W,o:W,F:W,w:D,E:D,h:C,V:C},long:{shared:W,exclusive:W,unlock:W,nonblock:W,nonblocking:W,nb:W,timeout:D,wait:D,"conflict-exit-code":D,close:W,"no-fork":W,fcntl:W,verbose:W,help:C,version:C},positionals:[/^[\s\S]+$/]}},x3={...q0,...k3},S1=new Set(["-c","--command"]),h3=new Set(["busybox","toybox"]),v0=new Set(["rm","rmdir","unlink","shred"]),w3=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]),g3=new Set(["-C","-c","--git-dir","--work-tree","--namespace","--exec-path","--config-env"]),u3=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/;function i(Z){return u3.test(R(Z))}function gZ(Z){return Z.map((z)=>z.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var f1=/^[A-Za-z_][A-Za-z0-9_]*=/;function Z0(Z){let z=Z.lastIndexOf("/");return z>=0?Z.slice(z+1):Z}var O1={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
14
+ `,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function l3(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(O1,Y))$+=O1[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 H=parseInt(Q[1],16);$+=H<=1114111?String.fromCodePoint(H):"",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 k1(Z,!0)}function k1(Z,z){let $="",J=0;while(J<Z.length){let Y=Z[J];if(z&&Y==="$"&&Z[J+1]==="'"){let X=l3(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 $0(Z){if(rZ(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==="["&&m3(Z,$+1,"]"))return!0}return!1}function m3(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 p3(Z){if(!$0(Z))return!1;let z=JZ(Z);return z===null||z.some(($)=>v($).split(/[^A-Za-z0-9_]+/).some((J)=>v0.has(J)))}function WZ(Z){return Z0(v(Z))}var x1={deep:!0};function b0(Z,z){return Z.replace(/\\([$`\\"])/g,($,J)=>J==='"'&&!z?$:J)}function c3(Z,z,$){let J=[],Y=z+1;while(Y<$-1){let X=Z[Y];if(X==="\\"){Y+=2;continue}if(X==="`"){let Q=uZ(Z,Y);if(Q<0)return null;J.push(b0(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 i3(Z){let z=[],$=0;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==="`"){let Y=uZ(Z,$);if(Y<0)return null;z.push(b0(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 L1(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),B=K===-1?Z.length:K,M=Z.slice(Y,B).replace(/\r$/,"");if(X.stripTabs)M=M.replace(/^\t+/,"");if(M===X.delimiter)break;Y=B+1}let H=Z.slice(Q,Math.min(Y,Z.length));if(X.owner.push(H),!X.quoted){let K=i3(H);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 h1(Z,z){let $=Z.indexOf("'",z+1);return $===-1?-1:$+1}function uZ(Z,z){let $=z+1;while($<Z.length){if(Z[$]==="\\"){$+=2;continue}if(Z[$]==="`")return $+1;$++}return-1}function w1(Z,z){let $=z+1;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==='"')return $+1;if(J==="`"){let Y=uZ(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 FZ(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 H=Z.indexOf(Q,$+1);if(H<0)return null;Y+=Z.slice($+1,H),X=!0,$=H+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 J0(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,H=Z.slice(J,Q);if(H.endsWith("\r"))H=H.slice(0,-1);let K=Y.stripTabs?H.length-H.replace(/^\t+/,"").length:0;if(Y.stripTabs)H=H.slice(K);if(H===Y.delimiter){J=Q+1;break}if(H.startsWith(Y.delimiter)&&/^\s*\)/.test(H.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 H=Z[X];if(H==="\\"){X+=2;continue}if(H==="'"){let K=h1(Z,X);if(K<0)return-1;X=K;continue}if(H==='"'){let K=w1(Z,X);if(K<0)return-1;X=K;continue}if(H==="`"){let K=uZ(Z,X);if(K<0)return-1;X=K;continue}if(!J&&H==="<"&&Z[X+1]==="<"){if(Z[X+2]==="<"){X+=3;continue}let K=FZ(Z,X);if(!K)return-1;Q.push(K),X=K.end;continue}if(H===`
19
+ `&&Q.length>0){let K=J0(Z,X,Q);if(K<0)return-1;Q=[],X=K;continue}if(!J&&H==="#"&&/[\s;&|(]/.test(Z[X-1])){let K=Z.indexOf(`
20
+ `,X);if(K<0)return-1;X=K;continue}if(H==="(")Y++;else if(H===")"){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,H=[],K=[],B=-1,M=!1,V=!0,G=0,U=Z.length,j=(q)=>{if(B>=0){let F=X.length;if(X.push({text:Z.slice(B,q),start:B,end:q}),M)Q.add(F);B=-1,M=!1}},N=(q)=>{if(j(q),X.length>0)J.push($?{words:X,redirects:Q,heredocs:H}:{words:X,redirects:Q});if(X=[],Q=new Set,$)H=[];M=!1},L=(q)=>h1(Z,q),y=(q)=>uZ(Z,q),E=(q)=>XZ(Z,q),l=(q)=>w1(Z,q);while(G<U){let q=Z[G];if(q===" "||q==="\t"||q==="\r"){j(G),G++;continue}if(q===`
21
+ `){if(N(G),K.length>0){let F=L1(Z,G,K,Y);if(K=[],F<0)V=!1,G=U;else G=F;continue}G++;continue}if(q===";"){N(G),G++;continue}if(q==="&"){N(G),G+=Z[G+1]==="&"?2:1;continue}if(q==="|"){N(G),G+=Z[G+1]==="|"?2:1;continue}if($&&q==="("&&B>=0&&"?*+@!".includes(Z[G-1])){V=!1,G=U;continue}if(q==="("||q===")"){N(G),G++;continue}if(q==="<"&&Z[G+1]==="<"&&Z[G+2]!=="<"){let F=Z.slice(G+2).match(/^-?[ \t]*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/);if(!F){V=!1,G=U;continue}if($){let qZ=G+2+F[0].length;if(qZ<U&&!/[\s;&|()<>]/.test(Z[qZ])){V=!1,G=U;continue}j(G),K.push({delimiter:F[2],quoted:F[1]!=="",stripTabs:F[0].startsWith("-"),owner:H}),G=qZ;continue}let A=Z.indexOf(`
22
+ `,G+2+F[0].length);if(A===-1){V=!1,G=U;continue}let h=Z.slice(A+1),w=d3(h,F[2]);if(w===-1){V=!1,G=U;continue}j(G),G=A+1+w+F[2].length;continue}if(q===">"||q==="<"){if(B>=0&&/^\d+$/.test(Z.slice(B,G)))B=-1;if(j(G),M=!0,G++,Z[G]===q||Z[G]==="&"||q===">"&&Z[G]==="|"||q==="<"&&Z[G]===">")G++;continue}if(q==="'"){if(B<0)B=G;let F=L(G);if(F<0)V=!1,G=U;else G=F;continue}if(q==='"'){if(B<0)B=G;let F=l(G),A=F<0||!$?[]:c3(Z,G,F);if(F<0||!A)V=!1,G=U;else Y.push(...A),G=F;continue}if(q==="`"){if(B<0)B=G;let F=y(G);if(F<0)V=!1,G=U;else{let A=Z.slice(G+1,F-1);Y.push($?b0(A,!1):A),G=F}continue}if(q==="$"&&Z[G+1]==="("){if(B<0)B=G;let F=E(G+1);if(F<0)V=!1,G=U;else Y.push(Z.slice(G+2,F-1)),G=F;continue}if(q==="\\"){if(B<0)B=G;if(G+1>=U)V=!1,G=U;else G+=2;continue}if(B<0)B=G;G++}if(N(U),K.length>0&&L1(Z,U,K,Y)<0)V=!1;return{segments:J,trustworthy:V,substitutions:Y}}function d3(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 k1(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(f1.test(Y)&&!Y.startsWith("-")){z++;continue}if(w3.has(Y)){z++;continue}let X=Z0(Y);if(X==="command")for(let H of Z.words.filter((K,B)=>B>z&&!Z.redirects.has(B))){let K=v(H.text);if(K==="--"||!K.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(K))return-1}let Q=S3[X];if(Q){let H=z;z++;while(z<Z.words.length){if(Z.redirects.has(z)){z++;continue}let B=v(Z.words[z].text);if(!B.startsWith("-")||B==="-")break;if(B==="--"){z++;break}if(X==="env"&&(/^-[iv0]*S/.test(B)||/^--split-string(?:=|$)/.test(B)))return H;if(z++,Q.includes(B)||X==="exec"&&/^-[cl]*a$/.test(B)){while(Z.redirects.has(z))z++;z++}}let K=f3[X]??0;while(K>0&&z<Z.words.length){let B=v(Z.words[z].text);if(B.startsWith("-")&&B!=="-")break;z++,K--}continue}return z}return-1}function s3(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 E0(Z){return v3.map((z)=>jZ(Z,...z.split("/")))}function n3(Z,z){if(Z==="~"||Z==="$HOME"||Z==="${HOME}")return z;if(Z.startsWith("~/"))return jZ(z,Z.slice(2));if(Z.startsWith("$HOME/"))return jZ(z,Z.slice(6));if(Z.startsWith("${HOME}/"))return jZ(z,Z.slice(8));return Z}function eZ(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 H=n3(J,$);if(H===J)return null;J=H}let Q=(O3(J)?L3(J):A3(z,J)).replace(/\/+$/,"");return Q===""?"/":Q}function r(Z,z){return Z===z||Z.startsWith(`${z}${R0}`)}function o3(Z,z){let $=`${jZ(z,".hasna","scratchpad","scratch")}${R0}`;if(!Z.startsWith($))return!1;let[J,Y]=Z.slice($.length).split(R0);if(!J||!/^[a-z0-9][a-z0-9._-]{0,63}$/.test(J)||J.endsWith(".")||!Y)return!1;let X=Y.normalize("NFKC").toLowerCase();return X!=="meta.json"&&X!==".lock"}function a3(Z,z){if(Z===z)return`\`${Z}\` is the home directory itself, which is never deleted or trashed. Delete a specific file or directory inside it instead.`;for(let $ of F1){if(Z!==$&&!r($,Z))continue;return $==="/"?`\`${Z}\` is the filesystem root, which is never deleted.`:`\`${Z}\` is the system root \`${$}\` (or an ancestor of it), which is never deleted or trashed.`}for(let $ of b3){let J=jZ(z,$);if($===".hasna"&&o3(Z,z))continue;if(!r(Z,J)&&!r(J,Z))continue;return`\`${Z}\` is the protected \`~/${$}\` path (or contains it), which is never deleted or trashed. Delete a specific file inside it, and only when you are sure.`}return null}function r3(Z,z,$){let J=E0($);if(J.some((Y)=>r(z,Y)))return!0;return Z.some((Y)=>Y!==null&&J.some((X)=>r(Y,X)))}var A1=new WeakMap;function t3(Z){let z=A1.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,H)=>{if(S1.has(R(Q.text)))Y=H});let X={findDelete:$.includes("-delete"),findExecDelete:J>=0&&$.slice(J).some((Q)=>v0.has(Z0(Q))),namesDelete:$.some((Q)=>v0.has(Z0(Q))),lastFlockCommand:Y,textMention:i(Q4(Z)),envMention:i(gZ(Z.words.map((Q)=>R(Q.text)))),bodiesMention:i((Z.heredocs??[]).join(`
25
+ `))};return A1.set(Z,X),X}var e3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]);function Z4(Z,z){if(!e3.has(WZ(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 A0=(Z)=>Z.kind==="rm"||Z.kind==="refuse",$4="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.",J4="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.",z4="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.",Y4="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 S0(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:$0(X)}}),J=zZ($,x3);if(J===null)return null;return J.index<0?-1:z[J.index]}function y0(Z,z,$,J){let Y=WZ(Z.words[z].text);if(Y==="cd"){let K=Z.words[z+1];if(!K)return{kind:"none"};return{kind:"cd",cwd:eZ(K.text,$,J.home)??J.cwd}}if(Object.hasOwn(L0,Y))return{kind:"refuse",reason:L0[Y]};let X=g1(Z,z,$,J);if(X)return X;if(Y==="rm"){let K=s3(Z,z);if(K.length===0)return{kind:"none"};let B={word:Z.words[z],operands:K},M=E0(J.home),V=(j)=>j!==null&&M.some((N)=>r(j,N)),G=[],U=[];for(let j of K){let N=eZ(j.text,$,J.home);if(G.push(N),!j.text.includes("{"))continue;let L=JZ(j.text);if(L===null)return{kind:"refuse",reason:J4};for(let y of L){let E=eZ(y,$,J.home);if(E===null)continue;if(V(E)&&!V(N))return{kind:"refuse",reason:z4};U.push(E)}}if(r3(G,$,J.home))return B.cwdOnly=G.every((j)=>j!==null&&!V(j)),{kind:"rm",hit:B,handoff:!0,protectedReason:null};for(let j of[...G,...U]){if(!j)continue;let N=a3(j,J.home);if(N)return{kind:"rm",hit:B,handoff:!1,protectedReason:N}}return{kind:"rm",hit:B,handoff:!1,protectedReason:null}}if(h3.has(Y)){let K=Z.words.findIndex((M,V)=>V>z&&!R(M.text).startsWith("-")),B=K>=0?WZ(Z.words[K].text):"";if(B==="rm"||Object.hasOwn(L0,B))return{kind:"refuse",reason:`\`${Y} ${B}\` 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=f0(Z,z);if(K==="rm"||K==="clean"){if(!(K==="rm"?K4(Z,z):u1(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=t3(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 H=Y==="flock"?Q.lastFlockCommand>z:S1.has(Y);if(E3.has(Y)||H){let K=Z4(Z,z)?J.bodiesMention:Q.bodiesMention;if((Y==="env"?Q.envMention:Q.textMention)||K)return{kind:"refuse",reason:`\`${H?"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 g1(Z,z,$,J,Y={segment:Z,index:z},X=0){let Q=WZ(Z.words[z].text);for(let V of xZ(Z.words.map((G)=>v(G.text)),z,(G)=>Z.redirects.has(G))){if(X>=8)return wZ(Y.segment,Y.index,$,J.home)?{kind:"refuse",reason:X4}: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=S0(G);for(let j of new Set([x(G),U??-1])){if(j<0)continue;let N=g1(G,j,$,J,Y,X+1);if(N)return N}}let H=Z.words.map((V,G)=>({word:V,at:G})).filter(({at:V})=>!Z.redirects.has(V)),K=H.findIndex(({at:V})=>V===z),B=K<0?null:kZ(H.map(({word:V})=>V.text),K,v);if(B&&!B.literal&&(wZ(Z,z,$,J.home)||wZ(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=hZ(Z.words.map((V)=>v(V.text)),z,(V)=>V>=0&&V<Z.words.length&&(Z.redirects.has(V)||$0(Z.words[V].text)));if(!M||!(wZ(Z,z,$,J.home)||wZ(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 X4="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 wZ(Z,z,$,J){let Y=E0(J),X=(Q)=>Q!==null&&Y.some((H)=>r(Q,H));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(eZ(Z.words[Q].text,$,J)))return!0}return!1}function NZ(Z,z){let $={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},J=b(Z,x1);$.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,B=$.refusals)=>{if(K.kind==="refuse")B.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})}},H=Y.cwd;for(let K of J.segments){let B=x(K),M=S0(K),V=B<0?{kind:"none"}:y0(K,B,H,Y);if(V.kind!=="cd")Q(V);let G=(U)=>U!==null&&U>=0&&$0(K.words[U].text);if(M===null||G(B)||G(M)){if(K.words.some((U,j)=>!K.redirects.has(j)&&(A0(y0(K,j,H,Y))||p3(U.text))))X.push({reason:$4})}else if(M>=0&&M!==B){let U=y0(K,M,H,Y);if(A0(U))if(A0(V))X.push({reason:Y4});else Q(U,X)}if(V.kind==="cd")H=V.cwd}if(Y.depth<3)for(let K of J.substitutions){let B=NZ(K,{cwd:H,home:Y.home,depth:Y.depth+1});if(B.rmHits.length>0||B.refusals.length>0||B.handoffHits.length>0||B.protectedHits.length>0||!B.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 Q4(Z){return Z.words.map((z)=>z.text).join(" ")}function f0(Z,z){let $=z+1;while($<Z.words.length){let J=R(Z.words[$].text);if(!J.startsWith("-"))return J;if($++,g3.has(J))$++}return null}function K4(Z,z){if(Z.words.slice(z+1).map((J)=>R(J.text)).includes("--cached"))return!0;return u1(Z,z)}function u1(Z,z){let $=Z.words.slice(z+1).map((J)=>R(J.text));return $.includes("-n")||$.includes("--dry-run")}function y1(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function H4(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(y1).join(" "):`${y1($)} guard`,X=[...z].sort((H,K)=>K.word.start-H.word.start),Q=Z;for(let H of X)Q=`${Q.slice(0,H.word.start)}${Y}${Q.slice(H.word.end)}`;return Q}function B4(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 M4(Z,z){let $={};for(let[J,Y]of Object.entries(Z??{}))$[J]=Y;if($.command=z,typeof $.description!=="string"||$.description.trim()==="")$.description=R3;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=y3;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function V4(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 B4(z,Z.command,$,J,Y)}function G4(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,x1).segments.some((J)=>{let Y=S0(J);return[x(J),...Y===null?[]:[Y]].some((X)=>{if(J.words.slice(0,X<0?J.words.length:X).some((K)=>f1.test(R(K.text))||z.has(WZ(K.text))))return!0;if(X<0)return!1;let H=J.words[X];return z.has(WZ(H.text))||/^\s*\(\s*\)\s*\{/.test(Z.slice(H.end))})})}function u(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function U4(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function j4(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 W4="[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.",R1="[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 v1(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 l1(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((N)=>N.word.start).join(),Q=(j)=>j()||!!YZ(J,j),H=Y(),K=v1(H,J),B=YZ(J,()=>{let j=Y();return{result:j,verdict:v1(j,J)}});if(B){let{result:j,verdict:N}=B;if(N&&!("continue"in N))return N;if(!N&&(!K||("continue"in K))&&X(j)!==X(H))return u(R1)}if(K)return K;let M=j4(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(W4);let V=M.path;if(z.execution&&Q(()=>G4(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=H4(J,H.rmHits,V,z.execution),U=M4(Z.tool_input,G);if(z.execution)U.hasna_execution="hasna.hooks.execution.v1";if(Q(()=>!V4(U,J,H.rmHits,z.cwd,z.home)))return u(R1);return U4(U)}import{closeSync as N4,constants as m1,fstatSync as F4,lstatSync as _4,openSync as D4,readFileSync as T4,statSync as I4}from"fs";import{homedir as t1}from"os";import{dirname as k0,isAbsolute as e1,join as _Z,normalize as DZ,relative as q4,resolve as cZ,sep as u0}from"path";var C4=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),P4=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),O4=["hasna","hasnaxyz","hasna-products"],lZ="workspace-repos-guard";function L4(Z){return _Z(Z,".hasna","repos","clones")}function A4(Z){return _Z(Z,"workspace","repos")}function Z2(Z){return[L4(Z),A4(Z)]}function y4(Z){return _Z(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var R4=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function x0(Z){let z=process.getuid?.();return z!==void 0&&(Z.uid===0||Z.uid===z)&&(Z.mode&18)===0}function v4(Z){let z=y4(Z),$;try{let Y=D4(z,m1.O_RDONLY|m1.O_NOFOLLOW);try{let Q=F4(Y);if(!Q.isFile()||!x0(Q)||Q.size>4096)return null;$=T4(Y,"utf8")}finally{N4(Y)}let X=DZ(Z);for(let Q=k0(z);Q!==X;Q=k0(Q)){let H=_4(Q);if(!H.isDirectory()||!x0(H)||Q===k0(Q))return null}if(!x0(I4(X)))return null}catch{return null}let J=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return J.length>0&&J.every((Y)=>R4.test(Y))?new Set(J):null}function b4(Z=process.env,z=t1()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((J)=>J.trim()).filter(Boolean));return v4(z)??new Set(O4)}function h0(Z,z,$,J){if(J==="read")return{blocked:!1};let Y=q4(z,Z);if(Y===""){if(J==="delete")return{blocked:!0,reason:`[${lZ}] delete of the protected repo-checkout root is forbidden: ${z}`};return{blocked:!0,reason:`[${lZ}] writes directly to the protected repo-checkout root are forbidden: ${z}`}}if(Y.startsWith(`..${u0}`)||Y===".."||e1(Y))return{blocked:!1};let X=Y.split(u0).filter(Boolean);if(J==="delete")return{blocked:!0,reason:`[${lZ}] delete under the protected repo-checkout root (${z}) is forbidden at any depth: ${Z}`};if(X.length<=1)return{blocked:!0,reason:`[${lZ}] 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:`[${lZ}] '${Q}' is not an allowed GitHub org under the protected repo-checkout root (${z}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var $2=/\b(?:-o|--output|-O|--output-document|-out)\b/,E4=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,S4=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function J2(Z){return Z.replace(E4," ")}function f4(Z){let z=[],$=null,J=0,Y=0,X=!1,Q=0;for(let H=0;H<Z.length;H++){let K=Z[H];if($==="'"){if(K==="'")$=null;continue}if(K==="\\"){H++;continue}if(K==="("){J++;continue}if(K===")"){if(--J<0)return[Z];continue}if(K==="$"&&Z[H+1]==="{"){Y++,H++;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[H-1]===">")continue;if(z.push(Z.slice(Q,H)),Z[H+1]==="&")H++;Q=H+1}if($||J!==0||Y!==0||X)return[Z];return z.push(Z.slice(Q)),z}function k4(Z){let z=[],$="",J="",Y=null,X=!1,Q=()=>{if(!X)return;let H=J.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),K=$.startsWith("~")&&!/^~(?:\/|$)/.test(J);z.push({text:K?`./${$}`:$,opaque:/[$\x60*?[]/.test(H)||/[()]/.test(H)||rZ(J)}),$="",J="",X=!1};for(let H=0;H<Z.length;H++){let K=Z[H];if(Y==="'"){if(K==="'")Y=null;else $+=K;J+=K;continue}if(K==="\\"&&H+1<Z.length){let B=Z[H+1];$+=Y==='"'&&!/[$\x60"\\\n]/.test(B)?K+B:Y==='"'&&B===`
27
+ `&&!a.on?"":B,J+=K+B,X=!0,H++;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 w0(Z,z,$){let J=Z[z];return J==="--help"||J==="--version"||$&&(J==="-h"||J==="-V")}var p1={read:0,write:1,delete:2};function z0(...Z){return Z.reduce((z,$)=>p1[$]>p1[z]?$:z,"read")}var x4=new Set(["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"]),z2=new Set(["put","rm","delete","remove"]),h4=new Set([...z2,"restore","restore-capsule","recover","release","locks","retention","hold","unhold","pin","unpin","retrieve","backup-retrieve"]),Y2=new Set(["-delete","-exec","-execdir","-ok","-okdir","-fls","-fprint","-fprint0","-fprintf"]);function m0(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 p0(Z){let z=Z.trim();if(!z)return"read";if(X0(z))return"delete";let $=b(z);if(!$.trustworthy||$.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(z))return QZ(z);let J=$.segments.flatMap((Y)=>{let X=c1(Y),Q=Y.words.filter((B,M)=>!Y.redirects.has(M)).map((B)=>B.text),H=Q.map(JZ);if(H.every((B,M)=>B!==null&&B.length===1&&B[0]===Q[M]))return[X];if(H.some((B)=>B===null))return[X,QZ(Q.join(" "))];let K=b(H.flatMap((B)=>B??[]).join(" "));return[X,...K.trustworthy?K.segments.map(c1):[QZ(Q.join(" "))]]});return z0(...J)}function c1(Z){let z=Z.words.map((X,Q)=>({word:X,at:Q})).filter(({at:X})=>!Z.redirects.has(X)),$=x(Z),J=$<0?"read":i1(Z,$),Y=zZ(z.map(({word:X})=>c0(X.text)));if(Y===null)return z0(J,QZ(z.map(({word:X})=>R(X.text)).join(" ")));if(Y.index<0||z[Y.index].at===$)return J;return z0(J,i1(Z,z[Y.index].at))}function X2(Z,z,$=0){if(z<0||$>8)return $>8;let J=Z.words.map((B,M)=>({word:B,at:M})).filter(({at:B})=>!Z.redirects.has(B)),Y=J.findIndex(({at:B})=>B===z),X=Y<0?null:kZ(J.map(({word:B})=>B.text),Y,v);if(X){if(!X.literal)return!0;let B=b(X.program);if(B.trustworthy&&B.segments.some((M)=>Y0(M,$+1)))return!0}let Q=Z.words.map((B)=>v(B.text));for(let B of xZ(Q,z,(M)=>Z.redirects.has(M)))if(Y0(Q2(Z,B.start,B.end),$+1))return!0;let K=hZ(Q,z,(B)=>B>=0&&B<Z.words.length&&(Z.redirects.has(B)||m0(Z.words[B].text)));if(!K)return!1;if(K.unresolved)return!0;return K.programs.some((B)=>B.kind==="shell"?p0(B.text)!=="read":!C1(B))}function Q2(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 Y0(Z,z=0){return K2(Z).some(($)=>X2(Z,$,z))}function c0(Z){return{text:v(Z),opaque:/[$\x60]/.test(Z)&&!/^(?:[^$\x60"'\\]|\$'(?:[^'\\]|\\.)*')+$/.test(Z)}}function K2(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})=>c0(X.text)));if(Y!==null&&Y.index>=0)z.add(J[Y.index].at);return[...z]}function mZ(Z,z=0){if(z>8)return[];let $=[];for(let J of Z.segments){let Y=J.words.map((H)=>v(H.text)),X=(H)=>H>=0&&H<J.words.length&&(J.redirects.has(H)||m0(J.words[H].text)),Q=J.words.filter((H,K)=>!J.redirects.has(K));for(let H of K2(J)){$.push(...(hZ(Y,H,X)?.writes??[]).map((M)=>M[0]==="/"?M:`./${M}`));let K=kZ(Q.map((M)=>M.text),Q.indexOf(J.words[H]),v),B=K?.literal?b(K.program):null;if(B?.trustworthy)$.push(...mZ(B,z+1));for(let M of xZ(Y,H,(V)=>J.redirects.has(V)))$.push(...mZ({segments:[Q2(J,M.start,M.end)]},z+1))}}for(let J of Z.substitutions??[]){let Y=b(J);if(Y.trustworthy)$.push(...mZ(Y,z+1))}return $}function X0(Z,z=0){if(z>4)return!1;let $=b(Z),J=$.trustworthy?Z:UZ(Z);if(J!==Z)return X0(J,z+1);if($.trustworthy&&$.segments.some((X)=>Y0(X)))return!0;return(M2(Z)??$.substitutions).some((X)=>X0(X,z+1))}function i1(Z,z){if(X2(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 w0(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||x4.has(J[X]))return"read";if(h4.has(J[X])&&w0(J,X+1,!0))return"read";if(["restore","restore-capsule"].includes(J[X]))return"write";return"delete"}if(Y==="git"){let X=f0(Z,z);if(X==="clean"||X==="rm")return J[1]===X&&w0(J,2,!0)?"read":"delete";return X==="clone"||X==="init"?"write":"read"}if(Y==="find"&&!$.some((X)=>m0(X.text))&&!J.some((X)=>Y2.has(X)))return"read";if(Y==="env"&&i(gZ(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 $2.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?g0(Z):z0(g0(Z),g0(z))}function g0(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($2.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(J2(z)))return"write";return"read"}function pZ(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(`^"*${l0(z)}"*/`));if(Y)return z+"/"+$.slice(Y[0].length);return Z}function w4(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 l0(Z){return Z.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function d1(Z,z,$){if(Z===void 0)return[$];let J=pZ(Z,$),Y=J.match(/^(['"])(.*)\1$/);if(Y)J=Y[2];if(!J||J==="-"||/[$\x60*?[\]{}~\\'"]/.test(J))return null;return[...new Set(z.map((X)=>cZ(X,J)))]}var g4=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function u4(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 l4(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 m4=new Set(["--agent","--spool","--files","--info","--config"]),p4=new Set(["--spool","--files","--info","--config"]),c4=new Set(["--json","--local","--help","-h","--version","--identity"]),s1={"--agent":/^[^-]/,"--retention":/^(?:\d+(?:\.\d+)?|never)$/},i4=new Set(["--to"]);function d4(Z){let z=[],$=0;for(;$<Z.length&&Z[$].text.startsWith("-");$++){let X=Z[$];if(X.opaque)return null;if(m4.has(X.text)){let Q=Z[++$];if(!Q||Q.opaque)return null;if(p4.has(X.text))z.push(Q)}else if(!c4.has(X.text))return null}let J=Z[$];if(!J||J.opaque||!z2.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("="),H=Q<0?X.text:X.text.slice(0,Q);if(i4.has(H)){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(s1,H)&&K&&!K.opaque&&s1[H].test(K.text))$++}return z}function s4(Z){let z=Z.split(`
28
+ `),$=[],J=[],Y=0;while(Y<z.length){let X=Y,Q=z[Y++].replace(/\r$/,""),H=[];for(let K=0;K<Q.length;K++){let B=Q[K],M=J[J.length-1];if(B==="\\"){K++;continue}if(B==="$"&&Q[K+1]==="("&&Q[K+2]==="("){let V=Q.indexOf("))",K+3);if(V<0)return null;K=V+1;continue}if(B==="$"&&Q[K+1]==="("){J.push(0),K++;continue}if(B==="$"&&Q[K+1]==="[")return null;if(B==="$"&&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(B==="`"){let V=Q.indexOf("`",K+1);if(V<0)return null;K=V;continue}if(M==='"'){if(B==='"')J.pop();continue}if(B==="'"){let V=Q.indexOf("'",K+1);if(V<0)return null;K=V;continue}if(B==='"'){J.push('"');continue}if(B==="#"&&(K===0||/[\s;&|()]/.test(Q[K-1])))break;if(B==="("&&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"&&(B==="("||B===")")){if(B==="(")J[J.length-1]=M+1;else if(M===0)J.pop();else J[J.length-1]=M-1;continue}if(B==="<"&&Q[K+1]==="<"){if(Q[K+2]==="<"){K+=2;continue}let V=FZ(Q,K);if(!V)return null;H.push({marker:V,from:K}),K=V.end-1}}for(let{marker:K,from:B}of H){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:B,to:K.end,start:M,end:Y-1,quoted:K.quoted})}}return J.length===0?$:null}var n4=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"]),o4=new Set([".","source","eval","env","alias","hash"]),a4=new Set(["tee","cp","mv","install","ln"]),H2=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"]),r4=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),t4=new Set(["pr","issue","api","release","gist"]);function e4(Z,z){let $=Z[z];if($==="gh")return t4.has(Z[z+1]??"");if($!=="git")return H2.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("-")&&r4.has(Y)}return!1}function Z5(Z,z){for(let $=z+1;$<Z.length;$++){let J=Z[$];if(J==="\\")$++;else if(J==='"')return $;else if(J==="$"&&Z[$+1]==="("){if($=B2(Z,$+1),$<0)return-1}else if(J==="`"){if($=Z.indexOf("`",$+1),$<0)return-1}}return-1}function B2(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=Z5(Z,J),J<0)return-1}else if(Y==="(")$++;else if(Y===")"&&--$===0)return J}return-1}function M2(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=B2(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 $5(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),H=M2(X);if(!Q.trustworthy||!H)return!0;z.push(...Q.segments),$.push(...new Set([...Q.substitutions,...H]))}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 H=c(X[Q]);if(a4.has(H)){for(let K of X.slice(Q+1))if(!K.startsWith("-"))J.add(c(K))}if(H==="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 B of Y.words){let M=c(R(B.text));if(n4.has(M)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(M))return!0}let X=x(Y),Q=Y.words.map((B,M)=>({text:R(B.text),at:M})).filter(({at:B})=>!Y.redirects.has(B));if(Q.some(({text:B,at:M})=>(X<0||M<X)&&EZ.test(B)))return!0;if(X<0)continue;let H=Y.words[X].text,K=R(H);if(/[$\x60]/.test(H)||K.includes("/")||o4.has(K)||J.has(K))return!0;if(!e4(Q.filter(({at:B})=>B>=X).map(({text:B})=>B),0))return!0}return!1}function J5(Z){if(!Z.includes("<<"))return null;let z=s4(Z);if(!z||z.length===0)return null;let $=Z.split(`
29
+ `),J=[...$],Y=[];for(let Q of z){let H=$.slice(Q.start,Q.end);if(!Q.quoted&&H.some((K)=>/\$\(|\x60/.test(K)))return null;Y.push(H.join(`
30
+ `));for(let K=Q.start;K<=Q.end;K++)J[K]=""}let X=[...J];for(let Q of[...z].reverse()){let H=X[Q.line];X[Q.line]=H.slice(0,Q.from)+" ".repeat(Q.to-Q.from)+H.slice(Q.to)}return $5(X.join(`
31
+ `))?null:{outer:J.join(`
32
+ `),bodies:Y}}var z5="/";function Q0(Z,z,$){if(!Z)return[];let J=b(Z).trustworthy?Z:UZ(Z),Y=J5(Z);return[...J===Z?[]:Q0(J,z,$),...Y?[...r1(Y.outer,z,$),...Y.bodies.flatMap((X)=>Q0(X,z,z5))]:r1(Z,z,$)]}var Y5=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,X5=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function n1(Z,z,$=!1){let J=[],Y=0;for(let H of z)J.push(Y),Y+=H.length;let X=b(Z);if(!X.trustworthy||!$&&X.substitutions.length>0)return null;let Q=X.segments.flatMap((H)=>H.words).filter((H)=>z.some((K,B)=>B%2===1&&J[B]<H.end&&J[B]+K.length>H.start));return Q.length>0?{lexed:X,offsets:J,words:Q}:null}function o1(Z,z,$=[]){if(p0(z)!=="read")return!1;let J=x(Z),Y=Z.words.filter((M,V)=>!Z.redirects.has(V)),X=zZ(Y.map((M)=>c0(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)&&EZ.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||H2.has(c(R(M)))))return!0;let K=Y.filter((M)=>!$.includes(M)),B=K.map((M)=>R(M.text));return QZ(K.map((M)=>M.text).join(" "))==="read"&&QZ(B.join(" "))==="read"&&!B.some((M)=>Y2.has(M))}function Q5(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)=>Y0(X))}var a1=(Z,z)=>Z.slice(z.words[0].start,z.words[z.words.length-1].end);function K5(Z,z,$,J){let Y=(Q)=>Q.start<J&&Q.end>$,X=z.words.filter(Y);if(X.length===0||X.some((Q)=>!X5.test(Q.text)))return!1;for(let Q of z.lexed.segments.filter((H)=>H.words.some(Y)))if(!o1(Q,a1(Z,Q),z.words))return!1;for(let Q of X){let H=Q.text.slice(1,-1);if(H.includes("<<"))return!1;let K=b(H);if(!K.trustworthy||K.substitutions.length>0)return!1;if(!K.segments.every((B)=>o1(B,a1(H,B))))return!1}return!0}function r1(Z,z,$){if(!Z)return[];let J=Z2(z),Y=(U)=>J.some((j)=>U===j||U.startsWith(`${j}${u0}`)),X=Z.split(Y5),Q=n1(Z,X),H=Q??n1(Z,X,!0),K=[],B=[$],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)B=[...M];let N=X[U],L=(N.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,y=(N.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let _=0;_<L;_++)G.push({current:[...B],reachable:new Set(M),certain:V});let E=w4(N),l=Q!==null&&K5(Z,Q,Q.offsets[U],Q.offsets[U]+N.length),q=!l&&(H!==null&&Q5(Z,H,H.offsets[U],H.offsets[U]+N.length)||X0(N.trim())),F=E.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),A=F?null:E.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(A){for(let _ of d1(A[1],B,z)??[])M.add(_);V=!1,B=[...M]}let h=l0(z),w=J.map((_)=>l0(_.slice(z.length+1))).join("|"),qZ=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${h}"*)/(?:${w})`),V1=new RegExp(`(${qZ.source})([^\\s"';&|<>()\`]*|$)`,"g"),G1=(_)=>{let f=[],g;V1.lastIndex=0;while((g=V1.exec(_))!==null)f.push(DZ(pZ(g[0],z)).replace(/\/+$/,""));return f},U1=H===null?0:H.offsets[U],j1=(_)=>_.start<U1+N.length&&_.end>U1,E2=H!==null&&H.words.some(j1)?mZ({segments:H.lexed.segments.filter((_)=>_.words.some(j1))}):[N.trim(),E].flatMap((_)=>{let f=b(_);if(!f.trustworthy)f=b(UZ(_));return f.trustworthy?mZ(f):[]}),j0=f4(E).map((_,f)=>{let g=f===0?[...new Set(E2)]:[],CZ=!1,PZ=J2(_).replace(S4,(N0,BZ)=>{if(!BZ||/[$\x60]/.test(BZ))CZ=!0;if(BZ)g.push(BZ);return" "}),OZ=l?"read":q?"delete":p0(PZ);return{commandPart:PZ,operands:g,op:CZ&&OZ==="read"?"write":OZ}}),S2=j0.some((_)=>_.op==="delete")?"delete":j0.some((_)=>_.op==="write")?"write":"read",W0=B.filter(Y);if(q)for(let _ of W0)K.push({path:_,op:"delete"});for(let _ of j0){let f=!1;for(let k of G1(_.commandPart))f=!0,K.push({path:k,op:S2});for(let k of _.operands){let n=G1(k);for(let p of n)K.push({path:p,op:"write"});if(n.length>0)continue;for(let p of W0)K.push({path:DZ(cZ(p,pZ(k,z))),op:"write"})}if(f||_.op==="read")continue;let g=k4(_.commandPart),CZ=u4(_.commandPart,g),PZ=c(g[CZ]?.text??""),OZ=g.slice(CZ+1),N0=((PZ==="trash"?d4(OZ):null)??l4(PZ,OZ)).map((k)=>k.opaque?".":k.text),BZ=_.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(_.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(_.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(_.commandPart),LZ=[];if(BZ)for(let k of N0.length>0?N0:["."])LZ.push({operand:k,op:_.op});else{let k=_.commandPart.match(g4),n=g.at(-1);if(LZ.push({operand:k?k[1]:!n||n.opaque?".":n.text,op:_.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(_.commandPart))g.forEach((p,W1)=>{let MZ,F0=p.text.match(/^-[A-Za-z]*?t(.*)$/),dZ=p.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(F0&&!p.text.startsWith("--"))MZ=F0[1]?{text:F0[1],opaque:p.opaque}:g[W1+1];else if(dZ&&"--target-directory".startsWith(dZ[1]))MZ=dZ[2]!==void 0?{text:dZ[2],opaque:p.opaque}:g[W1+1];if(MZ)LZ.push({operand:MZ.opaque||!MZ.text?".":MZ.text,op:_.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(_.commandPart))LZ.push({operand:".",op:_.op})}for(let k of W0)for(let{operand:n,op:p}of LZ)K.push({path:DZ(cZ(k,pZ(n,z))),op:p})}if(F){let _=d1(F[1],B,z);if(_){for(let f of _)M.add(f);if(V)B=_}else V=!1}for(let _=0;_<y&&G.length>0;_++)({current:B,reachable:M,certain:V}=G.pop())}return K}var H5=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function B5(Z,z){let $=[],J;while((J=H5.exec(Z))!==null){let Y=J[1]==="Delete File"?"delete":"write";$.push({path:DZ(cZ(z,J[2])),op:Y})}return $}function V2(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??t1(),X=Z2(Y),Q=b4(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=Q0(G,Y,U);j.unshift(...YZ(G,()=>Q0(G,Y,U))??[]);for(let N of j)for(let L of X){let y=h0(N.path,L,Q,N.op);if(y.blocked)return{output:{decision:"block",reason:y.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let H=Z.tool_input??{},K=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(P4.has(J)){let G=typeof H.patch==="string"?H.patch:"";if(!G)return{output:{continue:!0},warnings:$};let U=B5(G,K);for(let j of U)for(let N of X){let L=h0(j.path,N,Q,j.op);if(L.blocked)return{output:{decision:"block",reason:L.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!C4.has(J))return{output:{continue:!0},warnings:$};let B=typeof H.file_path==="string"?H.file_path:typeof H.path==="string"?H.path:typeof H.notebook_path==="string"?H.notebook_path:null;if(!B)return{output:{continue:!0},warnings:$};let M=pZ(B,Y),V=e1(M)?DZ(M):cZ(K,M);for(let G of X){let U=h0(V,G,Q,"write");if(U.blocked)return{output:{decision:"block",reason:U.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var M5=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"]),V5=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),W2=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"]),N2=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"]),G5=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),U5=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class s0 extends Error{}var P=()=>{throw new s0};function i0(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 H=1,K=Y+2;while(K<Z.length&&H>0){let B=Z[K];if(B==='"'){K=i0(Z,K).end;continue}if(B==="(")H++;else if(B===")")H--;K++}if(H!==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 F2(Z){let z=[],$=0,J=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let Y=Z[$];if(/\s/.test(Y)){$++;continue}if(Y==="#")P();if(Y==='"'){let K=i0(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 B=i0(Z,$+1);if(B.parts.some((M)=>typeof M!=="string"))P();z.push({t:"field",name:B.parts.join("")}),$=B.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 H=J.find((K)=>Z.startsWith(K,$));if(!H)P();z.push({t:"op",v:H}),$+=H.length}return z}var j5=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 n0{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(!U5.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(j5.has(Z.name))P();if(Z.name==="map"||W2.has(Z.name)||N2.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 n0(F2($.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 o0(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(o0);return Z==="safe"||typeof Z==="object"&&M5.has(Z.leaf)}var iZ=(...Z)=>Z.every(o0)?"safe":"tainted";function d0(...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 K0(Z,z){return typeof Z==="object"&&"union"in Z?d0(...Z.union.map(z)):z(Z)}var H0=(Z)=>typeof Z==="object"&&("leaf"in Z)&&V5.has(Z.leaf),t=(Z)=>K0(Z,(z)=>z==="safe"?"safe":z==="tainted"||H0(z)?"tainted":"unknown");function G2(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 U2(Z,z,$){return K0(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 U2(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 U2(J,Z.key.text,$);if(Z.key.k==="lit")return t(J);return O(Z.key,z,$),"tainted"}case"slice":return K0(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 iZ(...Z.parts.map((J)=>O(J,z,$)));case"fmt":return Z.str?O(Z.str,z,$):z;case"array":return Z.of?iZ(O(Z.of,z,$)):"safe";case"object":return iZ(...Z.entries.map((J)=>O(J.value,z,$)));case"pipe":return O(Z.b,O(Z.a,z,$),$);case"comma":return d0(O(Z.a,z,$),O(Z.b,z,$));case"alt":return d0(O(Z.a,z,$),O(Z.b,z,$));case"bool":return O(Z.a,z,$),O(Z.b,z,$),"safe";case"arith":return iZ(O(Z.a,z,$),O(Z.b,z,$));case"neg":return O(Z.of,z,$);case"call":return W5(Z,z,$)}}var j2=(Z)=>K0(Z,(z)=>z==="root"?"unknown":H0(z)?"tainted":z);function W5(Z,z,$){let{name:J,args:Y}=Z;if(G5.has(J)&&J!=="limit"&&!Y.every(G2))P();switch(J){case"map":if(Y.length!==1)P();return iZ(O(Y[0],t(z),$));case"select":if(Y.length!==1)P();return O(Y[0],z,$),z;case"limit":if(Y.length!==2||!G2(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),$),j2(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(W2.has(J))return"safe";if(N2.has(J))return j2(z);return P()}function _2(Z,z={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new n0(F2(Z)).parse();return o0(O($,"root",{rootScalars:z.rootScalars??new Set}))}catch($){if($ instanceof s0)return!1;return!1}}var Y1="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",I={refused:!1},T=(Z)=>({refused:!0,rule:Z}),a0=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"]),r0=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),D2=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),T2=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),N5=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),F5=new Set(["author","committer","id","parents","repository","sha","url"]),_5=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function C2(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("{")&&C2(Z))$=!0;return{value:z,opaque:$,raw:Z}}var KZ=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function Z1(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 IZ(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],H=Q.value;if(H==="--"){J.positionals.push(...Z.slice(X+1));break}if(H.startsWith("--")&&H.length>2){let K=H.indexOf("="),B=K>=0?H.slice(0,K):H;if(K>=0)J.flags.push({name:B,value:Y(H.slice(K+1),Q),inline:!0});else if($.has(B)){let M=Z[X+1];J.flags.push(M?{name:B,value:M}:{name:B,missing:!0}),X++}else J.flags.push({name:B});continue}if(H.startsWith("-")&&H.length>1){for(let K=1;K<H.length;K++){let B="-"+H[K],M=H.slice(K+1);if(M.startsWith("=")){J.flags.push({name:B,value:Y(M.slice(1),Q),inline:!0});break}if(!$.has(B)){J.flags.push({name:B});continue}if(M)J.flags.push({name:B,value:Y(M,Q),inline:!0});else{let V=Z[X+1];J.flags.push(V?{name:B,value:V}:{name:B,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"],HZ={"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"]}},D5=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"]),T5=new Set(["pr","issue","release","discussion","search","project","api","status"]),I5=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),q5=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),C5=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),P5=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function G0(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 X1(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&&_2(J.value.value,{rootScalars:z}))}function Q1(Z,z,$,J){let Y=G0(Z,$);if(Y.opaque)return T("unclassifiable");if(Y.fields.every((X)=>z.has(X)))return I;if($.debug)return T("debug-traffic");return X1(Z)?I:T(J)}function B0(Z,z,$,J,Y){let X=IZ(Z,HZ[z]);if(S(X,"-h","--help"))return I;if(S(X,"-w","--web"))return J.debug?T("debug-traffic"):I;if(Y&&S(X,"-c","--comments"))return T("view-comments");if(!G0(X,J).present)return T(J.debug?"debug-traffic":"view-human");return Q1(X,$,J,"json-composite")}function e(Z,z,$,J){let Y=IZ(Z,HZ[z]);if(S(Y,"-h","--help"))return I;if(J.debug&&(S(Y,"-w","--web")||!G0(Y,J).present))return T("debug-traffic");if(S(Y,"-w","--web"))return I;return Q1(Y,$,J,"json-composite")}function O5(Z,z){let $=IZ(Z,HZ["pr checks"]);if(S($,"-h","--help"))return I;if(z.debug)return T("debug-traffic");if(S($,"-w","--web"))return I;if(!G0($,z).present)return T("checks-human");return Q1($,_5,z,"checks-json")}function L5(Z){let z=new Set(HZ.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 A5(Z,z,$){let{sub:J,rest:Y}=L5(z);if(!J)return $.appendsArgs?T("unclassifiable"):I;if(J.opaque)return T("unclassifiable");let X=J.value;if((Z==="pr"?I5:Z==="issue"?q5:Z==="release"?C5:Z==="discussion"?P5:new Set).has(X))return $.debug?T("debug-traffic"):I;if($.appendsArgs&&!(Z==="project"&&X!=="item-list"))return T("unclassifiable");switch(Z){case"pr":if(X==="view")return B0(Y,"pr view",a0,$,!0);if(X==="list"||X==="ls")return e(Y,"pr list",a0,$);if(X==="status")return e(Y,"pr status",a0,$);if(X==="checks")return O5(Y,$);if(X==="diff"){let H=IZ(Y,HZ["pr diff"]);if(S(H,"-h","--help"))return I;if($.debug)return T("debug-traffic");return S(H,"--patch")?T("composite-other"):I}return T("unclassifiable");case"issue":if(X==="view")return B0(Y,"issue view",r0,$,!0);if(X==="list"||X==="ls")return e(Y,"issue list",r0,$);if(X==="status")return e(Y,"issue status",r0,$);return T("unclassifiable");case"release":if(X==="view")return B0(Y,"release view",D2,$,!1);if(X==="list"||X==="ls")return e(Y,"release list",D2,$);return T("unclassifiable");case"discussion":if(X==="view")return B0(Y,"discussion view",T2,$,!0);if(X==="list"||X==="ls")return e(Y,"discussion list",T2,$);return T("unclassifiable");case"search":if(X==="prs"||X==="issues")return e(Y,"search",N5,$);if(X==="commits")return e(Y,"search",F5,$);if(X==="code"||X==="repos")return $.debug?T("debug-traffic"):I;return T("unclassifiable");case"project":{if($.debug)return T("debug-traffic");if(X!=="item-list")return I;let H=IZ(Y,HZ["project item-list"]);if(S(H,"-h","--help"))return I;let K=ZZ(H,"--format");if(K.some((B)=>!B.value||B.value.opaque))return T("unclassifiable");if(K.every((B)=>B.value.value!=="json"))return I;return X1(H)?I:T("composite-other")}}return T("unclassifiable")}var P2=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function y5(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 H of Q.split("/")){if(H===""||H===".")continue;if(H===".."){J.pop(),Y.pop();continue}J.push(H.toLowerCase()),Y.push(Z.opaque&&/[$`]/.test(H)||/[*?[]/.test(H)||C2(H))}}return{segments:J,opaque:Y}}function R5(Z){let z=y5(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 B=J.findIndex(Boolean),M=$.findIndex((V,G)=>G>B&&!J[G]&&v5.has(V));return Y(M<0?"unclassifiable":I2($.slice(M),J.slice(M)))}return Y(I2(X,Q))}let H=$[0];if(H==="issues")return Y("sensitive");if(H==="user"&&$[1]==="issues")return Y("sensitive");if(H==="orgs"&&$[2]==="issues")return Y("sensitive");if(H==="search")return Y($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&J[1]?"unclassifiable":"other");if(H==="events"||H==="networks")return Y("sensitive");if((H==="users"||H==="orgs")&&$.slice(2).some((K)=>K==="events"||K==="received_events"||K==="discussions"))return Y("sensitive");if((H==="users"||H==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return Y("sensitive");if(H==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||H==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return Y("sensitive");if(H==="teams"&&$.includes("discussions"))return Y("sensitive");if(H==="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 v5=new Set([...P2,"branches","git","actions","hooks","zipball","tarball"]);function I2(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(P2.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 b5(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,H)=>typeof Q==="number"?J(H):$[H]===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 E5(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 S5=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"]),f5=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function k5(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 H=Z.indexOf('"""',Q);if(H<0)return null;if(Z[H-1]==="\\"){Q=H+3;continue}$=H+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 x5(Z){let z=k5(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 H=z[X-1];if(H?.kind==="punct"&&(H.text==="@"||H.text==="$"))continue;if(z[X+1]?.kind==="punct"&&z[X+1].text===":")continue;if(Q.text==="on"&&H?.kind==="punct"&&H.text==="...")continue;if(H?.kind==="name"&&H.text==="on"){J=Q.text;continue}if($.length===0){J=Q.text;continue}if(S5.has(Q.text)||/(?:Url|URL|HTML|Html)$/.test(Q.text))return!0;if(Q.text==="title"&&$.some((K)=>f5.has(K)))return!0;J=Q.text}return Y!==0||$.length!==0}function h5(Z,z){let $=IZ(Z,HZ.api);if(S($,"-h","--help"))return I;let J=$.positionals[0];if(!J)return z.appendsArgs?T("unclassifiable"):I;let Y=R5(J),X=ZZ($,"-X","--method"),Q=X[X.length-1],H=ZZ($,"-f","--raw-field","-F","--field","--input"),K=Q?Q.value&&!Q.value.opaque?Q.value.value.toUpperCase():"?":H.length>0?"POST":"GET",B=b5(K,Y.segments),M=I;if(Y.kind==="unclassifiable")M=T("unclassifiable");else if(Y.kind==="sensitive"&&!B)M=T("api-rest");else if(Y.kind==="graphql")M=w5($);if(z.debug||S($,"--verbose")){if(Y.kind==="download"&&!M.refused)M=T("api-rest");if(M.refused)return z.debug?T("debug-traffic"):M;return I}if(z.appendsArgs&&Y.kind!=="other"&&Y.kind!=="download")return T("unclassifiable");if(!M.refused||S($,"--silent"))return I;if(X1($,E5(Y.segments)))return I;return M}function w5(Z){if(ZZ(Z,"--input").length>0)return T("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 T("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 T("unclassifiable");if(x5(Y))return T("api-graphql")}return I}function V0(Z,z){let $=0;while($<Z.length&&Z[$].value.startsWith("-")&&!Z[$].opaque){if(["--help","-h","--version"].includes(Z[$].value))return I;$++}if($>=Z.length)return z.appendsArgs?T("unclassifiable"):I;let J=Z[$],Y=Z.slice($+1);if(J.opaque)return T("unclassifiable");switch(J.value){case"pr":case"issue":case"release":case"discussion":case"search":case"project":return A5(J.value,Y,z);case"api":return h5(Y,z);case"status":return Y.length>0&&Y.every((X)=>X.value==="-h"||X.value==="--help")?I:T("composite-other");case"help":case"version":return I;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((H)=>H.value).join(" "),z.depth+1,z.debug);if(Q.refused)return Q}break}}if(!D5.has(J.value))return T("unclassifiable");if(z.debug)return T("debug-traffic");return I}var U0=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","fish"]),g5=new Set(["su","runuser","script","flock"]),u5=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"]),l5=new Map([["bun",["x","exec"]],["npm",["exec","x"]],["deno",["run"]]]),m5=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"]),p5=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),M0=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/,c5=/^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/,i5=6;function q2(Z,z){let $,J;for(let Y of Z){let X=c5.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 K1(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 O2=(Z)=>/(?:^|[^|])\|&?$/.test(Z.trim());function $1(Z,z){if(!U0.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 J1(Z){let{segments:z}=K1(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,H)=>!$.redirects.has(H+J+1)).map((Q)=>TZ(Q.text));if(Y==="echo")return X.filter((Q,H)=>!(H===0&&/^-[neE]+$/.test(Q.value))).map((Q)=>Q.value).join(" ");if(Y==="printf"){let[Q,...H]=X.filter((B)=>B.value!=="--");if(!Q)return null;let K=0;return Q.value.replace(/\\n/g,`
35
+ `).replace(/%s/g,()=>H[K++]?.value??"")+(K<H.length?" "+H.slice(K).map((B)=>B.value).join(" "):"")}if(Y==="cat"){let Q=Z.indexOf("<<");if(Q<0)return null;let H=FZ(Z,Q),K=Z.indexOf(`
36
+ `,Q);if(!H||K<0)return null;let B=J0(Z,K,[H]);if(B<0)return null;let M=Z.slice(K+1,B);return M.slice(0,M.lastIndexOf(H.delimiter)).replace(/\n$/,"")}return null}function t0(Z,z,$){for(let J of Z1(Z).bodies){let Y=J1(J);if(Y===null)continue;let X=d(Y,z+1,$.debug);if(X.refused)return X}return I}function d(Z,z=0,$=!1){if(typeof Z!=="string"||!Z.trim())return I;if(z>i5)return M0.test(Z)?T("unclassifiable"):I;let{segments:J,trustworthy:Y}=K1(Z);if(!Y)return M0.test(Z)?T("unclassifiable"):I;let X=$,Q=(H)=>d(H,z+1,X);for(let H of n5(Z)){if(H.runsBody){let K=Q(H.body);if(K.refused)return K}if(!H.quoted){let K=Z1(H.body,"heredoc");if(!K.complete&&M0.test(H.body))return T("unclassifiable");for(let B of K.bodies){let M=Q(B);if(M.refused)return M}}}for(let H=0;H<J.length;H++){let K=J[H];for(let F of K.words){let A=Z1(F.text);if(!A.complete&&M0.test(F.text))return T("unclassifiable");for(let h of A.bodies){let w=Q(h);if(w.refused)return w}}let B=x(K),M=K.words.map((F,A)=>({word:TZ(F.text),redirect:K.redirects.has(A)})),V=M.slice(0,B<0?M.length:B).map((F)=>F.word),G=B>=0?KZ(M[B].word.value):"";if(B<0||["export","declare","typeset","readonly","local"].includes(G)){if(X=q2([...V,...M.slice(B+1).map((F)=>F.word)],X),B<0)continue}let U=q2(V,X),j=M.slice(B+1).filter((F)=>!F.redirect).map((F)=>F.word),N=M.slice(B+1).filter((F)=>F.redirect).map((F)=>F.word),L=M[B].word,y=KZ(L.value),E={depth:z,appendsArgs:!1,debug:U};if(B>0&&M[B-1].word.value==="function"){let F=j.filter((h)=>!["{","()","(",")"].includes(h.value)),A=z1(F,E);if(A.refused)return A;continue}if(H>0&&O2(K.sepBefore)&&$1(y,j)){let F=J[H-1],A=d5(Z,F),h=A===null?null:J1(A);if(h!==null){let w=d(h,z+1,U);if(w.refused)return w}}let l=J[H+1];if(l&&/<\(\s*$/.test(l.sepBefore)&&(U0.has(y)||y==="source"||y===".")){let F=l.words[0].start-l.sepBefore.length+l.sepBefore.lastIndexOf("("),A=XZ(Z,F),h=A<0?null:J1(Z.slice(F+1,A-1));if(h!==null){let w=d(h,z+1,U);if(w.refused)return w}}let q=L2(y,L,j,N,K.words.slice(0,B+1),E);if(q.refused)return q}return I}function d5(Z,z){let $=z.words[0],J=z.words[z.words.length-1];return $&&J?Z.slice($.start,J.end):null}function s5(Z){let z=KZ(Z.value);return/[$`]/.test(z)||z===""?void 0:z}function L2(Z,z,$,J,Y,X){let Q=X.depth,H=(K)=>d(K,Q+1,X.debug);if(z.opaque){let K=s5(z);if(K===void 0){let B=$.find((V)=>!V.value.startsWith("-")),M=V0($,X);if(!M.refused)return I;return M.rule!=="unclassifiable"||B!==void 0&&!B.opaque&&T5.has(B.value)?M:I}Z=K}if(Z==="gh")return V0($,X);if(U0.has(Z)){let K=H1($);if(K){let B=H(K.value);if(B.refused||!K.opaque)return B;return t0(K.raw,Q,X)}for(let B of J){let M=H(B.value);if(M.refused)return M;if(B.opaque){let V=t0(B.raw,Q,X);if(V.refused)return V}}return I}if(g5.has(Z)){let K=$.findIndex((M)=>M.value==="-c"||M.value==="--command"||/^-[A-Za-z]*c$/.test(M.value)),B=K>=0?$[K+1]:void 0;return B?H(B.value):e0($,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 B=H(K.map((M)=>M.value).join(" "));if(B.refused)return B;for(let M of K){let V=t0(M.raw,Q,X);if(V.refused)return V}return I}if(Z==="env")return H(gZ([...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(p5.has(V))K++}let B=$.slice(K+1);if(B[0]?.value==="--")B.shift();let M=B.map((V)=>V.value).join(" ");return M?H(M):I}if(Z==="xargs"){let K=0,B=!1;for(;K<$.length;K++){let M=$[K].value;if(M==="--"){K++;break}if(!M.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(M))B=!0;if(m5.has(M))K++}return z1($.slice(K),{depth:Q,appendsArgs:!B,debug:X.debug})}if(Z==="find"){for(let K=0;K<$.length;K++){if(!["-exec","-execdir","-ok","-okdir"].includes($[K].value))continue;let B=K+1;while(B<$.length&&$[B].value!==";"&&$[B].value!=="+")B++;let M=z1($.slice(K+1,B),X);if(M.refused)return M;K=B}return I}if(u5.has(Z))return e0($,X);if(l5.get(Z)?.includes($[0]?.value??""))return e0($.slice(1),X);return I}function z1(Z,z){if(Z.length===0)return I;let $=KZ(Z[0].value);if($==="gh")return V0(Z.slice(1),z);if(U0.has($)){let J=H1(Z.slice(1));return J?d(J.value,z.depth+1,z.debug):I}return L2($,Z[0],Z.slice(1),[],[],z)}function e0(Z,z){let $=Z.findIndex((J)=>!J.opaque&&KZ(J.value)==="gh"&&(J.value==="gh"||J.value.includes("/")));return $>=0?V0(Z.slice($+1),z):I}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 n5(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=FZ(Z,J);if(!Y)continue;let X=Z.lastIndexOf(`
37
+ `,J)+1,Q=Z.indexOf(`
38
+ `,J);if(Q<0)continue;let H=J0(Z,Q,[Y]),K=H<0?Z.slice(Q+1):Z.slice(Q+1,H),B=H<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:B,runsBody:o5(M),quoted:Y.quoted})}return z}function o5(Z){let{segments:z}=K1(Z),$=z.findIndex((H)=>H.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(H)=>{let K=x(H);if(K<0)return{verb:"",args:[]};let B=H.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>TZ(M.text));return{verb:KZ(TZ(H.words[K].text).value),args:B}},{verb:Y,args:X}=J(z[$]);if(Y==="ssh"||$1(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&&O2(Q.sepBefore)){let H=J(Q);return H.verb==="ssh"||$1(H.verb,H.args)}return!1}var a5=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function A2(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Y1}}}var r5=new Set(["Bash","Monitor"]);function y2(Z){if(Z?.hook_event_name!=="PreToolUse"||!r5.has(Z.tool_name??""))return{continue:!0};let z=GZ(Z);if(!z.trim())return{continue:!0};try{return d(z).refused?A2():{continue:!0}}catch{return a5.test(z)?A2():{continue:!0}}}function M1(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function v2(Z,z){M1(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"||!R2(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:B1(),path:process.env.PATH,agent:Y.agent};if(X&&(!R2(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",H=J.tool_name==="Bash"||Q&&typeof J.tool_input.command==="string",K=Q&&H?{...J,tool_name:"Bash"}:J,B=(y)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:y}}),M=V2(K).output,V=y2(K),G=K.tool_input.command,U=()=>NZ(G,{home:B1(),cwd:J.cwd}).handoffHits.length>0,j=H&&(U()||!!YZ(G,U)),N=$==="trash-guard"&&(!Q||H)?l1(K,{home:B1(),cwd:J.cwd,findTrash:aZ,inspectTrash:vZ,execution:X}):{continue:!0};if(Q&&N.hookSpecificOutput?.permissionDecision==="allow")N=B("[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"?B(M.reason):V.hookSpecificOutput?V:j?B("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):N;return JSON.stringify({verdict:"continue"in L?null:L})}var b2=process.argv[1];M1(b2);process.stdout.write(v2(b2,await Bun.stdin.text()));