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