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