@hasna/hooks 0.13.2 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -15
- package/bin/hooks/stop-review.js +53 -17
- package/bin/hooks-mcp.js +4787 -1415
- package/bin/index.js +5250 -2337
- package/bin/native-safety-entry.js +15 -37
- package/bin/native-safety-worker.cjs +38 -36
- package/bin/serve.js +34 -11
- package/dist/index.js +4970 -1579
- package/dist/lib/claude-skills-coordination.d.ts +1 -1
- package/dist/lib/codex-safety-trust.d.ts +2 -2
- package/dist/lib/native-safety-registration.d.ts +2 -2
- package/dist/lib/native-safety.d.ts +1 -1
- package/dist/lib/registry.d.ts +3 -1
- package/dist/native-safety.d.ts +4 -2
- package/dist/native-safety.js +21 -2
- package/dist/sdk/index.js +9 -53
- package/hooks/hook-job-folder-guard/README.md +61 -0
- package/hooks/hook-job-folder-guard/package.json +12 -0
- package/hooks/hook-job-folder-guard/src/classify.ts +398 -0
- package/hooks/hook-job-folder-guard/src/hook.ts +96 -0
- package/hooks/hook-protected-delete-guard/README.md +114 -0
- package/hooks/hook-protected-delete-guard/package.json +12 -0
- package/hooks/hook-protected-delete-guard/src/hook.ts +539 -0
- package/hooks/hook-signed-link-guard/src/classify.ts +41 -2
- package/hooks/hook-stop-review/README.md +16 -0
- package/hooks/hook-stop-review/manifest.json +1 -1
- package/hooks/hook-stop-review/package.json +1 -1
- package/hooks/hook-stop-review/src/hook.ts +1 -1
- package/hooks/hook-stop-review/src/native.ts +44 -8
- package/hooks/hook-stop-review/src/policy.ts +20 -8
- package/hooks/hook-stop-review/src/runtime.ts +16 -13
- package/hooks/hook-stop-review/src/types.ts +12 -2
- package/hooks/hook-trash-guard/README.md +130 -13
- package/hooks/hook-trash-guard/src/hook.ts +518 -71
- package/hooks/local-executors.ts +33 -0
- package/hooks/native-safety-composite.ts +19 -8
- package/package.json +3 -3
- package/scripts/build-native-entry.ts +123 -0
- package/scripts/build-native-worker.ts +11 -4
- package/scripts/validate-package.ts +8 -2
- package/hooks/native-safety-entry.ts +0 -11
|
@@ -1,37 +1,39 @@
|
|
|
1
|
-
var{defineProperty:
|
|
2
|
-
`)[0]}finally{P.closeSync($)}let Y=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(J);if(Y&&Y[1]!=="/usr/bin/env")return dZ(Y[1],!0);if(J!=="#!/usr/bin/env bun"||!dZ("/usr/bin/env",!0))return!1;for(let X of z.split(":").slice(0,64)){if(!f3(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 dZ(Q,!0)}return!1}function RZ(Z){let z=Z;for(;;){let $=P.lstatSync(z);if(!$.isDirectory()||!yZ($.uid)||($.mode&18)!==0)return!1;let J=v.dirname(z);if(J===z)return!0;z=J}}function vZ(Z=process.env){let z=Z.PATH??"",$=Date.now()+2000,J="missing",Y=(X)=>{if(J==="missing"||J==="unrecognized_package"||X.startsWith("unsafe_"))J=X};for(let X of z.split(":").slice(0,64)){if(!v.isAbsolute(X)||Date.now()>=$)continue;let Q=v.resolve(X,"trash");try{let B=P.statSync(Q);if(!B.isFile()||!yZ(B.uid)||(B.mode&73)===0||(B.mode&18)!==0){Y("unsafe_executable");continue}let K=P.realpathSync(Q);if(!RZ(v.resolve(X))||!RZ(v.dirname(K))){Y("unsafe_directory");continue}if(!dZ(Q)){Y("unsafe_directory");continue}let H=v.resolve(v.dirname(K),"../.."),M=v.join(H,"package.json"),V=P.statSync(M);if(!V.isFile()||!yZ(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(H,G.bin.trash))!==K){Y("unrecognized_package");continue}try{if(!k3(K,z)){Y("unsafe_interpreter");continue}}catch{Y("unsafe_interpreter");continue}let U=$-Date.now();if(U<=0){Y("identity_failed");break}let j=M2.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 F=JSON.parse(j.stdout);if(F.name==="@hasna/trash"&&F.version===G.version&&F.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:Q,version:G.version};Y("unsupported_protocol")}catch{}}return{ok:!1,code:J}}function sZ(Z=process.env){let z=vZ(Z);return z.ok?z.path:null}function WZ(Z){let z=Z.tool_input?.command;return typeof z==="string"?z:""}var G2=["/","/bin","/boot","/dev","/etc","/home","/lib","/lib32","/lib64","/libx32","/opt","/proc","/root","/run","/sbin","/srv","/sys","/usr","/var","/Applications","/Library","/System","/Users","/Volumes","/private"];var EZ=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,o=(Z)=>Z.split("/").pop()??"";function nZ(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 U2(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 x3(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 B=z&&(/^[-+]?0\d/.test(J[1])||/^[-+]?0\d/.test(J[2]))?Math.max(J[1].length,J[2].length):0,K=[];for(let H=Y;Y<=X?H<=X:H>=X;H+=Y<=X?Q:-Q)if(!z)K.push(String.fromCharCode(H));else K.push(H<0?`-${String(-H).padStart(B-1,"0")}`:String(H).padStart(B,"0"));return K}function h3(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=U2(Z,J+1);else if(Y==="{"){if(++$>N0)return"overflow";let X=null,Q=0,B=!0,K=[];for(let H=J;H<Z.length;H++){let M=Z[H];if(X==="'"){if(M==="'")X=null;continue}if(M==="\\"){B=!1,H++;continue}if(X==='"'){if(M==='"')X=null;continue}if(M==="'"||M==='"')X=M,B=!1;else if(M==="$"&&Z[H+1]==="{")H=U2(Z,H+1),B=!1;else if(M==="{")Q++;else if(M===","&&Q===1)K.push(H);else if(M==="}"&&--Q===0){if(K.length>0){let G=[J,...K,H];return{open:J,close:H,parts:G.slice(0,-1).map((U,j)=>Z.slice(U+1,G[j+1]))}}let V=B?x3(Z.slice(J+1,H)):null;if(V==="overflow")return V;if(V)return{open:J,close:H,parts:V};break}}}}return null}function QZ(Z){if(Z.length>4096&&Z.includes("{"))return null;let z=h3(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"},_={arg:"value"},bZ={arg:"optional"},t={arg:"none",effect:"lookup"},C={arg:"none",effect:"refuse"},ZZ={help:C,version:C},w3=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,D0={timeout:{short:{k:_,s:_,v:W},long:{"kill-after":_,signal:_,verbose:W,foreground:W,"preserve-status":W,...ZZ},positionals:[w3]},env:{short:{i:W,"0":W,v:W,u:_,a:_,C,S:C},long:{"ignore-environment":W,null:W,debug:W,unset:_,argv0:_,chdir:C,"split-string":C,"block-signal":bZ,"default-signal":bZ,"ignore-signal":bZ,"list-signal-handling":C,...ZZ},env:!0},nice:{short:{n:_},long:{adjustment:_,...ZZ},numericOption:!0},nohup:{short:{},long:{...ZZ}},command:{short:{p:W,v:t,V:t},long:{}},exec:{short:{c:W,l:W,a:_},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:_,o:_,e:_},long:{input:_,output:_,error:_,...ZZ}},time:{short:{p:W,a:W,q:W,v:W,f:_,o:C,V:C},long:{portability:W,append:W,quiet:W,verbose:W,format:_,output:C,...ZZ}},ionice:{short:{c:_,n:_,t:W,p:C,P:C,u:C,h:C,V:C},long:{class:_,classdata:_,ignore:W,pid:C,pgid:C,uid:C,...ZZ}},setsid:{short:{c:W,f:W,w:W,h:C,V:C},long:{ctty:W,fork:W,wait:W,...ZZ}}},g3=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function u3(Z,z,$){let J=!1,Y=(X)=>{if(!X||X.effect==="refuse")return!1;if(X.effect==="lookup")J=!0;return!0};while($<z.length){let X=z[$];if(X.opaque)return null;let Q=X.text;if(Q==="--"){$++;break}if(Q==="-"&&Z.env){$++;continue}if(!Q.startsWith("-")||Q==="-")break;if(Z.numericOption&&/^-[-+]?\d+$/.test(Q)){$++;continue}if(Q.startsWith("--")){let B=Q.indexOf("="),K=B<0?Q.slice(2):Q.slice(2,B),H=Object.keys(Z.long),M=H.includes(K)?[K]:H.filter((G)=>K&&G.startsWith(K));if(M.length!==1)return null;let V=Z.long[M[0]];if(!Y(V))return null;if(V.arg==="none"&&B>=0)return null;if(V.arg==="value"&&B<0){let G=z[++$];if(!G||G.opaque)return null}$++;continue}for(let B=1;B<Q.length;B++){let K=Z.short[Q[B]];if(!Y(K))return null;if(K.arg==="value"){if(B===Q.length-1){let H=z[++$];if(!H||H.opaque)return null}break}}$++}if(J)return-1;for(let X of Z.positionals??[]){let Q=z[$];if(!Q||Q.opaque||!X.test(Q.text))return null;$++}if(Z.env||Z.assignments){for(;$<z.length&&EZ.test(z[$].text);$++)if(z[$].opaque)return null}return $}function KZ(Z,z=D0){let $=0;while($<Z.length&&(EZ.test(Z[$].text)||g3.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=u3(Y,Z,$+1);if(X===null)return null;if(X<0)return{index:-1};$=X}return null}function l3(Z){return/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred|trash)(?![A-Za-z0-9_.-])/.test(Z)}var $Z={on:!1};function BZ(Z,z){if(!Z.includes("\\")||!Z.includes('"'))return;let $=$Z.on;$Z.on=!0;try{return z()}finally{$Z.on=$}}var T0=(Z)=>Z.split("/").pop()??"",I0={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.]+$/,m3=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),p3=new Set(["ssh","scp","sftp"]),c3=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),j2=new Set(["proxycommand","localcommand","knownhostscommand"]),i3=/(?:`|\$\()|\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/,d3=/system|getline|close|fflush|@(?![@/])/;function s3(Z){if(d3.test(Z))return!1;if(!/[|>]/.test(Z))return!0;if(/\\\r?\n/.test(Z))return!1;let z=Z.search(/print/);return z<0||!/[|>]/.test(Z.slice(z))}var n3=/\.\s*(?!(?:argv|std(?:in|out|err)|exit|write|loads?|dumps?|strip|split(?:lines)?|join|replace|(?:start|end)swith|lower|find|count|get|items|keys|values|append|sort|read)\b)[a-zA-Z_]/,o3=/(?<![\w.])(?:breakpoint|case|compile|\w*attr|eval|exec|globals|help|locals|type|vars)\b|(?<!\w)_/;function D2(Z){return Z.replace(/#.*|\\[^]|([rRbBuUfFtT]{0,2})("""|'''|(["'])(?!\3\3))((?:\\[^]|(?!\2)[^\\])*)\2|\w+/g,(z,$,J,Y,X)=>{if(!J)return z[0]==="#"?"":z;if(!/[ft]/i.test($))return/^[rbt]+$/.test(X)?"~":"%";let Q="",B=X.replace(/\{\{|\}\}|\{([^{}#]*)\}/g,(K,H="")=>(Q+=`${D2(H)},`,""));return/[{}]/.test(B)?"'":`(${Q})`})}function a3(Z){if(Z.length>8192||/`|\$\(/.test(Z))return!1;let z=D2(Z);if(/['"\\]|[^\0-\x7f]/.test(z)||o3.test(z))return!1;if(/\b(?:import|from)\b/.test(z.replace(/\bimport\s+(?:json|sys)(?:\s*,\s*(?:json|sys))*(?=\s*(?:;|$))/gm,"")))return!1;if(/\bopen\b/.test(z.replace(/\bopen\([\w.[\]%]+(?:,\s*(?:mode=)?~)?(?:,\s*encoding=%)?\)/g,"")))return!1;return!n3.test(z)}function _2(Z){if(l3(Z.text))return!1;if(Z.kind==="awk")return s3(Z.text);if(Z.kind==="c-interp")return Z.language==="python"?a3(Z.text):!i3.test(Z.text);return!1}function r3(Z,z,$,J){let Y=I0[Z]??(N2.test(Z)?I0[Z.replace(/[0-9.]+$/,"")]:void 0);if(!Y)return null;let X=(H)=>Z.startsWith("python3")?{text:H,kind:"c-interp",language:"python"}:{text:H,kind:"c-interp"},Q=[],B=!1,K=(H)=>{if(H+1>=z.length||J(H+1))return B=!0,H;return Q.push(X(z[H+1])),H+1};for(let H=$+1;H<z.length;H++){let M=z[H];if(M==="--")break;if(!M.startsWith("-")||M==="-")break;if(M.startsWith("--")){let G=M.indexOf("="),U=G<0?M:M.slice(0,G);if(Y.long.has(U))if(G>=0)Q.push(X(M.slice(G+1)));else H=K(H);continue}let V=M.slice(1);for(let G=0;G<V.length;G++){if(!Y.letters.has(V[G]))continue;if(G<V.length-1)Q.push(X(V.slice(G+1)));else H=K(H);break}}if(Q.length===0&&!B)return null;return{programs:Q,unresolved:B}}function t3(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 e3(Z,z,$){let J=[],Y=!1,X=z+1;for(;X<Z.length;X++){let Q=Z[X];if(Q==="--"){X++;break}if(!Q.startsWith("-")||Q==="-")break;if(Q==="-e"||Q.startsWith("-e")){let B=Q==="-e"?null:Q.slice(2);if(B!==null)J.push({text:B,kind:"awk"});else if(X+1<Z.length&&!$(X+1))J.push({text:Z[++X],kind:"awk"});else Y=!0}else if(Q==="-f"||Q.startsWith("-f")){if(Y=!0,Q==="-f")X++}else if(Q==="-v"||Q.startsWith("-v")){if(Q==="-v")X++}}if(J.length===0&&!Y){if(X<Z.length)if($(X))Y=!0;else J.push({text:Z[X],kind:"awk"})}return{programs:J,unresolved:Y}}function Z4(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 $4(Z,z,$){let J=[],Y=!1;for(let X=z+1;X<Z.length;X++){let Q=Z[X];if(Q==="--")break;if(!Q.startsWith("-")||Q==="-")break;if(Q.startsWith("--"))continue;if(Q==="-o"||Q.startsWith("-o")){let{value:K,next:H}=Z4(Z,X,$);if(X=H,K===null){Y=!0;continue}let M=K.indexOf("="),V=M>=0?M:K.search(/\s/),G=(V>=0?K.slice(0,V):K).trim().toLowerCase(),U=V>=0?K.slice(V+1).trim():"";if(j2.has(G))J.push({text:U,kind:"shell"});continue}if(Q==="-F"||Q.startsWith("-F")){if(Y=!0,Q==="-F")X++;continue}if(Q==="-S"||Q.startsWith("-S")){let K=Q==="-S"?X+1<Z.length&&!$(X+1)?Z[++X]:null:Q.slice(2);if(K===null)Y=!0;else J.push({text:K,kind:"shell"});continue}let B=Q.slice(1);for(let K=0;K<B.length;K++){if(!c3.has(B[K]))continue;if(K<B.length-1)break;if(B[K]==="o"||B[K]==="F"||B[K]==="S"){if(X+1<Z.length){let H=Z[X+1];if(B[K]==="o")if(!$(X+1)){let M=H.indexOf("="),V=M>=0?M:H.search(/\s/),G=(V>=0?H.slice(0,V):H).trim().toLowerCase();if(j2.has(G))J.push({text:V>=0?H.slice(V+1).trim():"",kind:"shell"})}else Y=!0;else if(B[K]==="F")Y=!0;else if(!$(X+1))J.push({text:H,kind:"shell"});X++}}else if(X+1<Z.length)X++}}return{programs:J,unresolved:Y}}function J4(Z,z,$){let J=[],Y=!1,X=!1;for(let Q=z+1;Q<Z.length;Q++){let B=Z[Q];if(B==="--")break;if(B==="-e"||B==="--rsh")if(X=!0,Q+1<Z.length&&!$(Q+1))J.push({text:Z[++Q],kind:"shell"});else Y=!0;else if(B.startsWith("--rsh="))X=!0,J.push({text:B.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(B)&&B.length>2&&!B.startsWith("--"))X=!0,J.push({text:B.slice(B.indexOf("e")+1),kind:"shell"})}return X?{programs:J,unresolved:Y}:null}var z4=/^(?:true|false|yes|no|on|off|1|0|)$/i,Y4=[/^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 I2(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&&z4.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(Y4.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 W2(Z){return/[$\x60]/.test(Z)||["","x","/x","!x"].some((z)=>I2(Z,z).kind!=="harmless")}var X4=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"]),Q4=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function K4(Z){let z=/'((?:[^']|'\\'')*)'/y,$=(X)=>X.replace(/'\\''/g,"'"),J=[],Y=0;while(Y<Z.length){if(/\s/.test(Z[Y])){Y++;continue}z.lastIndex=Y;let X=z.exec(Z);if(!X)return null;if(Y=z.lastIndex,Z[Y]==="="){z.lastIndex=Y+1;let Q=z.exec(Z);if(!Q)return null;Y=z.lastIndex,J.push([$(X[1]),$(Q[1])])}else{let Q=$(X[1]),B=Q.indexOf("=");J.push(B<0?[Q,void 0]:[Q.slice(0,B),Q.slice(B+1)])}}return J}function B4(Z,z,$){let J=[],Y=!1,X=(H,M,V=!0)=>{if(!V||/[$\x60]/.test(H)){Y=!0;return}let G=I2(H,M);if(G.kind==="unresolved")Y=!0;else if(G.kind==="command")J.push({text:G.text,kind:"shell"})},Q=(H,M)=>{let V=H.indexOf("="),G=V<0?H:H.slice(0,V),U=V<0?"true":H.slice(V+1);if(!M)return X(G,U);if(W2(G))Y=!0},B=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let H=z+1;H<Z.length;H++){let M=Z[H];if(!M.startsWith("-")||M==="-")break;if(M==="--")break;if(M==="-c"){if(H+1>=Z.length)break;Q(Z[H+1],$(H+1)),H++}else if(M.startsWith("-c")&&!M.startsWith("--"))Q(M.slice(2),$(H));else if(M==="--config-env"||M.startsWith("--config-env=")){let V=M==="--config-env"?Z[++H]??"":M.slice(13),G=V.indexOf("="),U=G<0?V:V.slice(0,G);if($(H)||W2(U))Y=!0}else if(M.startsWith("--exec-path="))Y=!0;else if(B.has(M))H++}let K=new Map;for(let H=0;H<z;H++){let M=Z[H].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!M)continue;let[,V,G]=M,U=$(H);if(X4.has(V))if(U)Y=!0;else J.push({text:G,kind:"shell"});else if(Q4.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:K4(G);if(j===null)Y=!0;else for(let[F,y]of j)X(F,y??"true")}else if(/^GIT_CONFIG_(?:KEY|VALUE)_\d+$/.test(V)){let j=V.replace(/^GIT_CONFIG_(?:KEY|VALUE)_/,""),F=K.get(j)??{};if(V.startsWith("GIT_CONFIG_KEY_"))F.key=G;else F.value=G;if(U)F.opaque=!0;K.set(j,F)}}for(let H of K.values()){if(H.key===void 0)continue;if(H.opaque)Q(`${H.key}=`,!0);else X(H.key,H.value)}if(J.length===0&&!Y)return null;return{programs:J,unresolved:Y}}function SZ(Z){if(/^~/.test(Z))return null;let z="";for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return null;z+=Z.slice($+1,Y),$=Y}else if(J==="$"||J==="`")return null;else if(J==='"'){let Y=$+1;for(;Y<Z.length&&Z[Y]!=='"';Y++){let X=Z[Y];if(X==="$"||X==="`")return null;if(X==="\\"&&Y+1<Z.length&&/[$\x60"\\\n]/.test(Z[Y+1])){if(Z[++Y]!==`
|
|
3
|
-
|
|
4
|
-
`));if(B===null){if(
|
|
5
|
-
`,J);return J=M<0?Y:M,Z.slice(H,J)},B=()=>{let H=
|
|
6
|
-
`)return!1;if(
|
|
7
|
-
`)return!1;if(Z[
|
|
8
|
-
`)){let
|
|
9
|
-
`))return!1;
|
|
10
|
-
`||!
|
|
11
|
-
`;J++)if(Z[J]==="\\")J++}else if(H==="e")$=!0,
|
|
12
|
-
`||M==="\\"||!
|
|
13
|
-
`,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function
|
|
14
|
-
`?"":`\\${X}`,J+=2;continue}$+=Z[J],J++}J++;continue}$+=Y,J++}return $}function
|
|
15
|
-
`,Y),H=
|
|
16
|
-
`,Y);Y=(
|
|
17
|
-
`,J),
|
|
18
|
-
`&&
|
|
19
|
-
`,X);if(
|
|
20
|
-
`){if(
|
|
21
|
-
|
|
22
|
-
`,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
`))};if(!J.trustworthy){let K=FZ(Z);return K===Z?$:{..._Z(K,z),trustworthy:!1}}let X=[],Q=(K,H=$.refusals)=>{if(K.kind==="refuse")H.push({reason:K.reason});else if(K.kind==="rm"&&K.handoff)$.handoffHits.push(K.hit);else if(K.kind==="rm"){if($.rmHits.push(K.hit),K.protectedReason)$.protectedHits.push({reason:K.protectedReason})}},B=Y.cwd;for(let K of J.segments){let H=l(K),M=y0(K),V=H<0?{kind:"none"}:P0(K,H,B,Y);if(V.kind!=="cd")Q(V);let G=(U)=>U!==null&&U>=0&&tZ(K.words[U].text);if(M===null||G(H)||G(M)){if(K.words.some((U,j)=>!K.redirects.has(j)&&(C0(P0(K,j,B,Y))||x4(U.text))))X.push({reason:t4})}else if(M>=0&&M!==H){let U=P0(K,M,B,Y);if(C0(U))if(C0(V))X.push({reason:$5});else Q(U,X)}if(V.kind==="cd")B=V.cwd}if(Y.depth<3)for(let K of J.substitutions){let H=_Z(K,{cwd:B,home:Y.home,depth:Y.depth+1});if(H.rmHits.length>0||H.refusals.length>0||H.handoffHits.length>0||H.protectedHits.length>0||!H.trustworthy&&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 z5(Z){return Z.words.map((z)=>z.text).join(" ")}function R0(Z,z){let $=z+1;while($<Z.words.length){let J=E(Z.words[$].text);if(!J.startsWith("-"))return J;if($++,E4.has(J))$++}return null}function Y5(Z,z){if(Z.words.slice(z+1).map((J)=>E(J.text)).includes("--cached"))return!0;return h2(Z,z)}function h2(Z,z){let $=Z.words.slice(z+1).map((J)=>E(J.text));return $.includes("-n")||$.includes("--dry-run")}function O2(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function X5(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(O2).join(" "):`${O2($)} guard`,X=[...z].sort((B,K)=>K.word.start-B.word.start),Q=Z;for(let B of X)Q=`${Q.slice(0,B.word.start)}${Y}${Q.slice(B.word.end)}`;return Q}function Q5(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 K5(Z,z){let $={};for(let[J,Y]of Object.entries(Z??{}))$[J]=Y;if($.command=z,typeof $.description!=="string"||$.description.trim()==="")$.description=q4;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=T4;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function B5(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 Q5(z,Z.command,$,J,Y)}function H5(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,S2).segments.some((J)=>{let Y=y0(J);return[l(J),...Y===null?[]:[Y]].some((X)=>{if(J.words.slice(0,X<0?J.words.length:X).some((K)=>b2.test(E(K.text))||z.has(DZ(K.text))))return!0;if(X<0)return!1;let B=J.words[X];return z.has(DZ(B.text))||/^\s*\(\s*\)\s*\{/.test(Z.slice(B.end))})})}function i(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function M5(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function V5(Z){try{if(Z.inspectTrash){let z=Z.inspectTrash();return z.ok?{path:z.path,error:null}:{path:null,error:`${z.code}: ${V2[z.code]}`}}return{path:Z.findTrash(),error:null}}catch(z){return{path:null,error:z instanceof Error?z.message:String(z)}}}var G5="[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.",L2="[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 A2(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 w2(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((F)=>F.word.start).join(),Q=(j)=>j()||!!BZ(J,j),B=Y(),K=A2(B,J),H=BZ(J,()=>{let j=Y();return{result:j,verdict:A2(j,J)}});if(H){let{result:j,verdict:F}=H;if(F&&!("continue"in F))return F;if(!F&&(!K||("continue"in K))&&X(j)!==X(B))return i(L2)}if(K)return K;let M=V5(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(G5);let V=M.path;if(z.execution&&Q(()=>H5(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=X5(J,B.rmHits,V,z.execution),U=K5(Z.tool_input,G);if(z.execution)U.hasna_execution="hasna.hooks.execution.v1";if(Q(()=>!B5(U,J,B.rmHits,z.cwd,z.home)))return i(L2);return M5(U)}var h=require("node:fs"),k0=require("node:os"),O=require("node:path");var U5=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),j5=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),W5=["hasna","hasnaxyz","hasna-products"],lZ="workspace-repos-guard";function F5(Z){return O.join(Z,".hasna","repos","clones")}function N5(Z){return O.join(Z,"workspace","repos")}function n2(Z){return[F5(Z),N5(Z)]}function D5(Z){return O.join(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var _5=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function v0(Z){let z=process.getuid?.();return z!==void 0&&(Z.uid===0||Z.uid===z)&&(Z.mode&18)===0}function I5(Z){let z=D5(Z),$;try{let Y=h.openSync(z,h.constants.O_RDONLY|h.constants.O_NOFOLLOW);try{let Q=h.fstatSync(Y);if(!Q.isFile()||!v0(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 B=h.lstatSync(Q);if(!B.isDirectory()||!v0(B)||Q===O.dirname(Q))return null}if(!v0(h.statSync(X)))return null}catch{return null}let J=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return J.length>0&&J.every((Y)=>_5.test(Y))?new Set(J):null}function T5(Z=process.env,z=k0.homedir()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((J)=>J.trim()).filter(Boolean));return I5(z)??new Set(W5)}function b0(Z,z,$,J){if(J==="read")return{blocked:!1};let Y=O.relative(z,Z);if(Y===""){if(J==="delete")return{blocked:!0,reason:`[${lZ}] delete of the protected repo-checkout root is forbidden: ${z}`};return{blocked:!0,reason:`[${lZ}] writes directly to the protected repo-checkout root are forbidden: ${z}`}}if(Y.startsWith(`..${O.sep}`)||Y===".."||O.isAbsolute(Y))return{blocked:!1};let X=Y.split(O.sep).filter(Boolean);if(J==="delete")return{blocked:!0,reason:`[${lZ}] delete under the protected repo-checkout root (${z}) is forbidden at any depth: ${Z}`};if(X.length<=1)return{blocked:!0,reason:`[${lZ}] writing would create a top-level entry directly under the protected repo-checkout root (${z}); only GitHub-org folders belong there: ${Z}`};let Q=X[0];if(!$.has(Q))return{blocked:!0,reason:`[${lZ}] '${Q}' is not an allowed GitHub org under the protected repo-checkout root (${z}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var o2=/\b(?:-o|--output|-O|--output-document|-out)\b/,q5=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,C5=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function a2(Z){return Z.replace(q5," ")}function P5(Z){let z=[],$=null,J=0,Y=0,X=!1,Q=0;for(let B=0;B<Z.length;B++){let K=Z[B];if($==="'"){if(K==="'")$=null;continue}if(K==="\\"){B++;continue}if(K==="("){J++;continue}if(K===")"){if(--J<0)return[Z];continue}if(K==="$"&&Z[B+1]==="{"){Y++,B++;continue}if(K==="}"&&Y>0){Y--;continue}if(K==="`"){X=!X;continue}if($==='"'){if(K==='"')$=null;continue}if(K==="'"||K==='"'){$=K;continue}if(K!=="|"||J>0||Y>0||X||Z[B-1]===">")continue;if(z.push(Z.slice(Q,B)),Z[B+1]==="&")B++;Q=B+1}if($||J!==0||Y!==0||X)return[Z];return z.push(Z.slice(Q)),z}function O5(Z){let z=[],$="",J="",Y=null,X=!1,Q=()=>{if(!X)return;let B=J.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),K=$.startsWith("~")&&!/^~(?:\/|$)/.test(J);z.push({text:K?`./${$}`:$,opaque:/[$\x60*?[]/.test(B)||/[()]/.test(B)||nZ(J)}),$="",J="",X=!1};for(let B=0;B<Z.length;B++){let K=Z[B];if(Y==="'"){if(K==="'")Y=null;else $+=K;J+=K;continue}if(K==="\\"&&B+1<Z.length){let H=Z[B+1];$+=Y==='"'&&!/[$\x60"\\\n]/.test(H)?K+H:Y==='"'&&H===`
|
|
26
|
-
|
|
27
|
-
`),$=[],J=[],Y=0;while(Y<z.length){let X=Y,Q=z[Y++].replace(/\r$/,""),B=[];for(let K=0;K<Q.length;K++){let H=Q[K],M=J[J.length-1];if(H==="\\"){K++;continue}if(H==="$"&&Q[K+1]==="("&&Q[K+2]==="("){let V=Q.indexOf("))",K+3);if(V<0)return null;K=V+1;continue}if(H==="$"&&Q[K+1]==="("){J.push(0),K++;continue}if(H==="$"&&Q[K+1]==="[")return null;if(H==="$"&&Q[K+1]==="{"){let V=Q.indexOf("}",K+2);if(V<0||/['"\x60$]|<</.test(Q.slice(K+2,V)))return null;K=V;continue}if(H==="`"){let V=Q.indexOf("`",K+1);if(V<0)return null;K=V;continue}if(M==='"'){if(H==='"')J.pop();continue}if(H==="'"){let V=Q.indexOf("'",K+1);if(V<0)return null;K=V;continue}if(H==='"'){J.push('"');continue}if(H==="#"&&(K===0||/[\s;&|()]/.test(Q[K-1])))break;if(H==="("&&Q[K+1]==="("&&(K===0||/[\s;&|(]/.test(Q[K-1]))){let V=Q.indexOf("))",K+2);if(V<0)return null;K=V+1;continue}if(typeof M==="number"&&(H==="("||H===")")){if(H==="(")J[J.length-1]=M+1;else if(M===0)J.pop();else J[J.length-1]=M-1;continue}if(H==="<"&&Q[K+1]==="<"){if(Q[K+2]==="<"){K+=2;continue}let V=IZ(Q,K);if(!V)return null;B.push({marker:V,from:K}),K=V.end-1}}for(let{marker:K,from:H}of B){let M=Y;for(;;){if(Y>=z.length)return null;let V=z[Y++].replace(/\r$/,"");if(K.stripTabs)V=V.replace(/^\t+/,"");if(V===K.delimiter)break}$.push({line:X,from:H,to:K.end,start:M,end:Y-1,quoted:K.quoted})}}return J.length===0?$:null}var w5=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"]),g5=new Set([".","source","eval","env","alias","hash"]),u5=new Set(["tee","cp","mv","install","ln"]),J3=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"]),l5=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),m5=new Set(["pr","issue","api","release","gist"]);function p5(Z,z){let $=Z[z];if($==="gh")return m5.has(Z[z+1]??"");if($!=="git")return J3.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("-")&&l5.has(Y)}return!1}function c5(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=c5(Z,J),J<0)return-1}else if(Y==="(")$++;else if(Y===")"&&--$===0)return J}return-1}function Y3(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 i5(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),B=Y3(X);if(!Q.trustworthy||!B)return!0;z.push(...Q.segments),$.push(...new Set([...Q.substitutions,...B]))}let J=new Set;for(let Y of z){let X=Y.words.map((K)=>E(K.text));for(let K of Y.redirects)J.add(o(X[K]??""));let Q=l(Y);if(Q<0)continue;let B=o(X[Q]);if(u5.has(B)){for(let K of X.slice(Q+1))if(!K.startsWith("-"))J.add(o(K))}if(B==="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 H of Y.words){let M=o(E(H.text));if(w5.has(M)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(M))return!0}let X=l(Y),Q=Y.words.map((H,M)=>({text:E(H.text),at:M})).filter(({at:H})=>!Y.redirects.has(H));if(Q.some(({text:H,at:M})=>(X<0||M<X)&&EZ.test(H)))return!0;if(X<0)continue;let B=Y.words[X].text,K=E(B);if(/[$\x60]/.test(B)||K.includes("/")||g5.has(K)||J.has(K))return!0;if(!p5(Q.filter(({at:H})=>H>=X).map(({text:H})=>H),0))return!0}return!1}function d5(Z){if(!Z.includes("<<"))return null;let z=h5(Z);if(!z||z.length===0)return null;let $=Z.split(`
|
|
28
|
-
|
|
29
|
-
`));for(let K=Q.
|
|
1
|
+
var{defineProperty:v0,getOwnPropertyNames:G4,getOwnPropertyDescriptor:V4}=Object,U4=Object.prototype.hasOwnProperty;function j4(Z){return this[Z]}var W4=(Z)=>{var z=(v2??=new WeakMap).get(Z),$;if(z)return z;if(z=v0({},"__esModule",{value:!0}),Z&&typeof Z==="object"||typeof Z==="function"){for(var J of G4(Z))if(!U4.call(z,J))v0(z,J,{get:j4.bind(Z,J),enumerable:!($=V4(Z,J))||$.enumerable})}return v2.set(Z,z),z},v2;var F4=(Z)=>Z;function N4(Z,z){this[Z]=F4.bind(null,z)}var q4=(Z,z)=>{for(var $ in z)v0(Z,$,{get:z[$],enumerable:!0,configurable:!0,set:N4.bind(z,$)})};var r7={};q4(r7,{version:()=>o7,evaluate:()=>a7,abi:()=>n7});module.exports=W4(r7);var z0=require("node:os"),A2=require("node:path");var u=require("node:path");var h=require("node:path"),b=require("node:fs"),S2=require("node:child_process"),E2={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 uZ(Z){return Z===0||Z===process.getuid?.()}function X0(Z,z=!1){let $=Z;for(let J=0;J<32;J++){if(!h.isAbsolute($)||$.length>4096||!lZ("/"))return!1;let Y=$.split("/"),X=Y.pop();if(!X||X==="."||X==="..")return!1;let K="/";for(let H of Y){if(!H||H===".")continue;if(H===".."){K=h.dirname(K);continue}let M=h.join(K,H),G=b.lstatSync(M);if(z&&M==="/bin"&&G.isSymbolicLink()&&G.uid===0){let U=b.realpathSync(M);if(!lZ(U))return!1;K=U;continue}if(!G.isDirectory()||!uZ(G.uid)||G.mode&18)return!1;K=M}let B=h.join(K,X),Q=b.lstatSync(B);if(!uZ(Q.uid))return!1;if(Q.isSymbolicLink()){let H=b.readlinkSync(B);$=h.isAbsolute(H)?H:K+"/"+H;continue}return Q.isFile()&&Boolean(Q.mode&73)&&!(Q.mode&18)}return!1}function I4(Z){if(!h.isAbsolute(Z)||h.resolve(Z)!==(Z.replace(/\/+$/,"")||"/"))return!1;for(let z=h.resolve(Z);;z=h.dirname(z)){try{return b.lstatSync(z),lZ(z)}catch($){if($.code!=="ENOENT")return!1}if(h.dirname(z)===z)return!1}}function T4(Z,z){let $=b.openSync(Z,b.constants.O_RDONLY|b.constants.O_NONBLOCK|b.constants.O_NOFOLLOW),J;try{if(!b.fstatSync($).isFile())return!1;let X=Buffer.alloc(256),K=b.readSync($,X,0,X.length,0);J=X.subarray(0,K).toString("utf8").split(`
|
|
2
|
+
`)[0]}finally{b.closeSync($)}let Y=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(J);if(Y&&Y[1]!=="/usr/bin/env")return X0(Y[1],!0);if(J!=="#!/usr/bin/env bun"||!X0("/usr/bin/env",!0))return!1;for(let X of z.split(":").slice(0,64)){if(!I4(X))return!1;let K=h.resolve(X,"bun");try{if(!b.statSync(K).isFile())continue;b.accessSync(K,b.constants.X_OK)}catch{continue}return X0(K,!0)}return!1}function lZ(Z){let z=Z;for(;;){let $=b.lstatSync(z);if(!$.isDirectory()||!uZ($.uid)||($.mode&18)!==0)return!1;let J=h.dirname(z);if(J===z)return!0;z=J}}function pZ(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(!h.isAbsolute(X)||Date.now()>=$)continue;let K=h.resolve(X,"trash");try{let B=b.statSync(K);if(!B.isFile()||!uZ(B.uid)||(B.mode&73)===0||(B.mode&18)!==0){Y("unsafe_executable");continue}let Q=b.realpathSync(K);if(!lZ(h.resolve(X))||!lZ(h.dirname(Q))){Y("unsafe_directory");continue}if(!X0(K)){Y("unsafe_directory");continue}let H=h.resolve(h.dirname(Q),"../.."),M=h.join(H,"package.json"),G=b.statSync(M);if(!G.isFile()||!uZ(G.uid)||G.size>16384||(G.mode&18)!==0||b.lstatSync(M).isSymbolicLink()){Y("unsafe_manifest");continue}let U=JSON.parse(b.readFileSync(M,"utf8"));if(U.name!=="@hasna/trash"||typeof U.version!=="string"||typeof U.bin?.trash!=="string"||b.realpathSync(h.resolve(H,U.bin.trash))!==Q){Y("unrecognized_package");continue}try{if(!T4(Q,z)){Y("unsafe_interpreter");continue}}catch{Y("unsafe_interpreter");continue}let V=$-Date.now();if(V<=0){Y("identity_failed");break}let j=S2.spawnSync(K,["--identity"],{encoding:"utf8",timeout:V,maxBuffer:2048,env:{PATH:z},stdio:["ignore","pipe","pipe"]});if(j.error||j.status!==0||Date.now()>=$){Y("identity_failed");continue}let W=JSON.parse(j.stdout);if(W.name==="@hasna/trash"&&W.version===U.version&&W.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:K,version:U.version};Y("unsupported_protocol")}catch{}}return{ok:!1,code:J}}function K0(Z=process.env){let z=pZ(Z);return z.ok?z.path:null}function zZ(Z){let z=Z.tool_input?.command;return typeof z==="string"?z:""}var mZ=["/","/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 _4=/^(?:\*|\*\*|\.\*|\.\[!\.\]\*)$/;function D4(Z,z){let $=z+1;if(Z[$]==="!"||Z[$]==="^")$+=1;if(Z[$]==="]")$+=1;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==="["&&(Z[$+1]===":"||Z[$+1]==="="||Z[$+1]===".")){let Y=Z[$+1],X=Z.indexOf(`${Y}]`,$+2),K=Z.indexOf("]",$+2);if(X===-1||K!==-1&&K<X)return K;$=X+2;continue}if(J==="]")return $;$+=1}return-1}function C4(Z,z,$,J){let Y=Z.slice(z+1,$),X=Y.startsWith("!")||Y.startsWith("^"),K=X?Y.slice(1):Y;if(/\\|\[[:=.]/.test(K))return!0;let B=!1,Q=!0;for(let H=0;H<K.length;H+=1){let M=K[H];if(M==="]"&&!Q)break;if(K[H+1]==="-"&&H+2<K.length&&K[H+2]!=="]"){if(J>=M&&J<=K[H+2])B=!0;H+=2}else if(J===M)B=!0;Q=!1}return X?!B:B}function P4(Z,z){let $=0,J=0,Y=-1,X=0;while(J<z.length){let K=Z[$];if($<Z.length&&K==="*"){Y=$,X=J,$+=1;continue}if($<Z.length&&K==="?"){$+=1,J+=1;continue}if($<Z.length&&K==="["){let B=D4(Z,$);if(B===-1)return!0;if(C4(Z,$,B,z[J])){$=B+1,J+=1;continue}}else if($<Z.length){let B=K==="\\"&&$+1<Z.length?Z[$+1]:K,Q=K==="\\"&&$+1<Z.length?2:1;if(B===z[J]){$+=Q,J+=1;continue}}if(Y===-1)return!1;X+=1,J=X,$=Y+1}while(Z[$]==="*")$+=1;return $>=Z.length}function S0(Z,z){if(!/[*?[]/.test(Z))return Z===z;if(!Z.includes("]")&&!/[*?]/.test(Z))return Z===z;if(/\[[:=.]/.test(Z))return!0;if(_4.test(Z))return!0;return P4(Z,z)}var iZ=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,$Z=(Z)=>Z.split("/").pop()??"";function Q0(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 E0=64;function f2(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 O4(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),K=Math.abs(Number(J[3]??1))||1;if(!Number.isSafeInteger(Y)||!Number.isSafeInteger(X)||!Number.isSafeInteger(K))return"overflow";if(Math.floor(Math.abs(X-Y)/K)+1>E0)return"overflow";let B=z&&(/^[-+]?0\d/.test(J[1])||/^[-+]?0\d/.test(J[2]))?Math.max(J[1].length,J[2].length):0,Q=[];for(let H=Y;Y<=X?H<=X:H>=X;H+=Y<=X?K:-K)if(!z)Q.push(String.fromCharCode(H));else Q.push(H<0?`-${String(-H).padStart(B-1,"0")}`:String(H).padStart(B,"0"));return Q}function L4(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=f2(Z,J+1);else if(Y==="{"){if(++$>E0)return"overflow";let X=null,K=0,B=!0,Q=[];for(let H=J;H<Z.length;H++){let M=Z[H];if(X==="'"){if(M==="'")X=null;continue}if(M==="\\"){B=!1,H++;continue}if(X==='"'){if(M==='"')X=null;continue}if(M==="'"||M==='"')X=M,B=!1;else if(M==="$"&&Z[H+1]==="{")H=f2(Z,H+1),B=!1;else if(M==="{")K++;else if(M===","&&K===1)Q.push(H);else if(M==="}"&&--K===0){if(Q.length>0){let U=[J,...Q,H];return{open:J,close:H,parts:U.slice(0,-1).map((V,j)=>Z.slice(V+1,U[j+1]))}}let G=B?O4(Z.slice(J+1,H)):null;if(G==="overflow")return G;if(G)return{open:J,close:H,parts:G};break}}}}return null}function JZ(Z){if(Z.length>4096&&Z.includes("{"))return null;let z=L4(Z);if(z===null)return[Z];if(z==="overflow")return null;let $=[];for(let J of z.parts){let Y=JZ(Z.slice(0,z.open)+J+Z.slice(z.close+1));if(Y===null||$.push(...Y)>E0)return null}return $}var N={arg:"none"},D={arg:"value"},cZ={arg:"optional"},YZ={arg:"none",effect:"lookup"},A={arg:"none",effect:"refuse"},GZ={help:A,version:A},A4=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,f0={timeout:{short:{k:D,s:D,v:N},long:{"kill-after":D,signal:D,verbose:N,foreground:N,"preserve-status":N,...GZ},positionals:[A4]},env:{short:{i:N,"0":N,v:N,u:D,a:D,C:A,S:A},long:{"ignore-environment":N,null:N,debug:N,unset:D,argv0:D,chdir:A,"split-string":A,"block-signal":cZ,"default-signal":cZ,"ignore-signal":cZ,"list-signal-handling":A,...GZ},env:!0},nice:{short:{n:D},long:{adjustment:D,...GZ},numericOption:!0},nohup:{short:{},long:{...GZ}},command:{short:{p:N,v:YZ,V:YZ},long:{}},exec:{short:{c:N,l:N,a:D},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:D,o:D,e:D},long:{input:D,output:D,error:D,...GZ}},time:{short:{p:N,a:N,q:N,v:N,f:D,o:A,V:A},long:{portability:N,append:N,quiet:N,verbose:N,format:D,output:A,...GZ}},ionice:{short:{c:D,n:D,t:N,p:A,P:A,u:A,h:A,V:A},long:{class:D,classdata:D,ignore:N,pid:A,pgid:A,uid:A,...GZ}},setsid:{short:{c:N,f:N,w:N,h:A,V:A},long:{ctty:N,fork:N,wait:N,...GZ}}},y4=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function R4(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 K=X.text;if(K==="--"){$++;break}if(K==="-"&&Z.env){$++;continue}if(!K.startsWith("-")||K==="-")break;if(Z.numericOption&&/^-[-+]?\d+$/.test(K)){$++;continue}if(K.startsWith("--")){let B=K.indexOf("="),Q=B<0?K.slice(2):K.slice(2,B),H=Object.keys(Z.long),M=H.includes(Q)?[Q]:H.filter((U)=>Q&&U.startsWith(Q));if(M.length!==1)return null;let G=Z.long[M[0]];if(!Y(G))return null;if(G.arg==="none"&&B>=0)return null;if(G.arg==="value"&&B<0){let U=z[++$];if(!U||U.opaque)return null}$++;continue}for(let B=1;B<K.length;B++){let Q=Z.short[K[B]];if(!Y(Q))return null;if(Q.arg==="value"){if(B===K.length-1){let H=z[++$];if(!H||H.opaque)return null}break}}$++}if(J)return-1;for(let X of Z.positionals??[]){let K=z[$];if(!K||K.opaque||!X.test(K.text))return null;$++}if(Z.env||Z.assignments){for(;$<z.length&&iZ.test(z[$].text);$++)if(z[$].opaque)return null}return $}function IZ(Z,z=f0){let $=0;while($<Z.length&&(iZ.test(Z[$].text)||y4.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,$Z(Z[$].text))?z[$Z(Z[$].text)]:void 0;if(!Y)return{index:$};let X=R4(Y,Z,$+1);if(X===null)return null;if(X<0)return{index:-1};$=X}return null}function b4(Z){return/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred|trash)(?![A-Za-z0-9_.-])/.test(Z)}var VZ={on:!1};function XZ(Z,z){if(!Z.includes("\\")||!Z.includes('"'))return;let $=VZ.on;VZ.on=!0;try{return z()}finally{VZ.on=$}}var h0=(Z)=>Z.split("/").pop()??"",x0={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}},w2=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,v4=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),S4=new Set(["ssh","scp","sftp"]),E4=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),k2=new Set(["proxycommand","localcommand","knownhostscommand"]),f4=/(?:`|\$\()|\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/,k4=/system|getline|close|fflush|@(?![@/])/;function x4(Z){if(k4.test(Z))return!1;if(!/[|>]/.test(Z))return!0;if(/\\\r?\n/.test(Z))return!1;let z=Z.search(/print/);return z<0||!/[|>]/.test(Z.slice(z))}var h4=/\.\s*(?!(?:argv|std(?:in|out|err)|exit|write|loads?|dumps?|strip|split(?:lines)?|join|replace|(?:start|end)swith|lower|find|count|get|items|keys|values|append|sort|read)\b)[a-zA-Z_]/,w4=/(?<![\w.])(?:breakpoint|case|compile|\w*attr|eval|exec|globals|help|locals|type|vars)\b|(?<!\w)_/;function g2(Z){return Z.replace(/#.*|\\[^]|([rRbBuUfFtT]{0,2})("""|'''|(["'])(?!\3\3))((?:\\[^]|(?!\2)[^\\])*)\2|\w+/g,(z,$,J,Y,X)=>{if(!J)return z[0]==="#"?"":z;if(!/[ft]/i.test($))return/^[rbt]+$/.test(X)?"~":"%";let K="",B=X.replace(/\{\{|\}\}|\{([^{}#]*)\}/g,(Q,H="")=>(K+=`${g2(H)},`,""));return/[{}]/.test(B)?"'":`(${K})`})}function g4(Z){if(Z.length>8192||/`|\$\(/.test(Z))return!1;let z=g2(Z);if(/['"\\]|[^\0-\x7f]/.test(z)||w4.test(z))return!1;if(/\b(?:import|from)\b/.test(z.replace(/\bimport\s+(?:json|sys)(?:\s*,\s*(?:json|sys))*(?=\s*(?:;|$))/gm,"")))return!1;if(/\bopen\b/.test(z.replace(/\bopen\([\w.[\]%]+(?:,\s*(?:mode=)?~)?(?:,\s*encoding=%)?\)/g,"")))return!1;return!h4.test(z)}function u2(Z){if(b4(Z.text))return!1;if(Z.kind==="awk")return x4(Z.text);if(Z.kind==="c-interp")return Z.language==="python"?g4(Z.text):!f4.test(Z.text);return!1}function u4(Z,z,$,J){let Y=x0[Z]??(w2.test(Z)?x0[Z.replace(/[0-9.]+$/,"")]:void 0);if(!Y)return null;let X=(H)=>Z.startsWith("python3")?{text:H,kind:"c-interp",language:"python"}:{text:H,kind:"c-interp"},K=[],B=!1,Q=(H)=>{if(H+1>=z.length||J(H+1))return B=!0,H;return K.push(X(z[H+1])),H+1};for(let H=$+1;H<z.length;H++){let M=z[H];if(M==="--")break;if(!M.startsWith("-")||M==="-")break;if(M.startsWith("--")){let U=M.indexOf("="),V=U<0?M:M.slice(0,U);if(Y.long.has(V))if(U>=0)K.push(X(M.slice(U+1)));else H=Q(H);continue}let G=M.slice(1);for(let U=0;U<G.length;U++){if(!Y.letters.has(G[U]))continue;if(U<G.length-1)K.push(X(G.slice(U+1)));else H=Q(H);break}}if(K.length===0&&!B)return null;return{programs:K,unresolved:B}}function l4(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 p4(Z,z,$){let J=[],Y=!1,X=z+1;for(;X<Z.length;X++){let K=Z[X];if(K==="--"){X++;break}if(!K.startsWith("-")||K==="-")break;if(K==="-e"||K.startsWith("-e")){let B=K==="-e"?null:K.slice(2);if(B!==null)J.push({text:B,kind:"awk"});else if(X+1<Z.length&&!$(X+1))J.push({text:Z[++X],kind:"awk"});else Y=!0}else if(K==="-f"||K.startsWith("-f")){if(Y=!0,K==="-f")X++}else if(K==="-v"||K.startsWith("-v")){if(K==="-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 m4(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 c4(Z,z,$){let J=[],Y=!1;for(let X=z+1;X<Z.length;X++){let K=Z[X];if(K==="--")break;if(!K.startsWith("-")||K==="-")break;if(K.startsWith("--"))continue;if(K==="-o"||K.startsWith("-o")){let{value:Q,next:H}=m4(Z,X,$);if(X=H,Q===null){Y=!0;continue}let M=Q.indexOf("="),G=M>=0?M:Q.search(/\s/),U=(G>=0?Q.slice(0,G):Q).trim().toLowerCase(),V=G>=0?Q.slice(G+1).trim():"";if(k2.has(U))J.push({text:V,kind:"shell"});continue}if(K==="-F"||K.startsWith("-F")){if(Y=!0,K==="-F")X++;continue}if(K==="-S"||K.startsWith("-S")){let Q=K==="-S"?X+1<Z.length&&!$(X+1)?Z[++X]:null:K.slice(2);if(Q===null)Y=!0;else J.push({text:Q,kind:"shell"});continue}let B=K.slice(1);for(let Q=0;Q<B.length;Q++){if(!E4.has(B[Q]))continue;if(Q<B.length-1)break;if(B[Q]==="o"||B[Q]==="F"||B[Q]==="S"){if(X+1<Z.length){let H=Z[X+1];if(B[Q]==="o")if(!$(X+1)){let M=H.indexOf("="),G=M>=0?M:H.search(/\s/),U=(G>=0?H.slice(0,G):H).trim().toLowerCase();if(k2.has(U))J.push({text:G>=0?H.slice(G+1).trim():"",kind:"shell"})}else Y=!0;else if(B[Q]==="F")Y=!0;else if(!$(X+1))J.push({text:H,kind:"shell"});X++}}else if(X+1<Z.length)X++}}return{programs:J,unresolved:Y}}function i4(Z,z,$){let J=[],Y=!1,X=!1;for(let K=z+1;K<Z.length;K++){let B=Z[K];if(B==="--")break;if(B==="-e"||B==="--rsh")if(X=!0,K+1<Z.length&&!$(K+1))J.push({text:Z[++K],kind:"shell"});else Y=!0;else if(B.startsWith("--rsh="))X=!0,J.push({text:B.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(B)&&B.length>2&&!B.startsWith("--"))X=!0,J.push({text:B.slice(B.indexOf("e")+1),kind:"shell"})}return X?{programs:J,unresolved:Y}:null}var d4=/^(?:true|false|yes|no|on|off|1|0|)$/i,s4=[/^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 l2(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&&d4.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(s4.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 x2(Z){return/[$\x60]/.test(Z)||["","x","/x","!x"].some((z)=>l2(Z,z).kind!=="harmless")}var n4=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"]),o4=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function a4(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 K=z.exec(Z);if(!K)return null;Y=z.lastIndex,J.push([$(X[1]),$(K[1])])}else{let K=$(X[1]),B=K.indexOf("=");J.push(B<0?[K,void 0]:[K.slice(0,B),K.slice(B+1)])}}return J}function r4(Z,z,$){let J=[],Y=!1,X=(H,M,G=!0)=>{if(!G||/[$\x60]/.test(H)){Y=!0;return}let U=l2(H,M);if(U.kind==="unresolved")Y=!0;else if(U.kind==="command")J.push({text:U.text,kind:"shell"})},K=(H,M)=>{let G=H.indexOf("="),U=G<0?H:H.slice(0,G),V=G<0?"true":H.slice(G+1);if(!M)return X(U,V);if(x2(U))Y=!0},B=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let H=z+1;H<Z.length;H++){let M=Z[H];if(!M.startsWith("-")||M==="-")break;if(M==="--")break;if(M==="-c"){if(H+1>=Z.length)break;K(Z[H+1],$(H+1)),H++}else if(M.startsWith("-c")&&!M.startsWith("--"))K(M.slice(2),$(H));else if(M==="--config-env"||M.startsWith("--config-env=")){let G=M==="--config-env"?Z[++H]??"":M.slice(13),U=G.indexOf("="),V=U<0?G:G.slice(0,U);if($(H)||x2(V))Y=!0}else if(M.startsWith("--exec-path="))Y=!0;else if(B.has(M))H++}let Q=new Map;for(let H=0;H<z;H++){let M=Z[H].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!M)continue;let[,G,U]=M,V=$(H);if(n4.has(G))if(V)Y=!0;else J.push({text:U,kind:"shell"});else if(o4.has(G)){if(V||U!=="/dev/null"||G==="GIT_EXEC_PATH"||G==="GIT_TEMPLATE_DIR")Y=!0}else if(G==="GIT_ALLOW_PROTOCOL"){if(V||U.split(":").includes("ext"))Y=!0}else if(G==="GIT_CONFIG_PARAMETERS"){let j=V?null:a4(U);if(j===null)Y=!0;else for(let[W,_]of j)X(W,_??"true")}else if(/^GIT_CONFIG_(?:KEY|VALUE)_\d+$/.test(G)){let j=G.replace(/^GIT_CONFIG_(?:KEY|VALUE)_/,""),W=Q.get(j)??{};if(G.startsWith("GIT_CONFIG_KEY_"))W.key=U;else W.value=U;if(V)W.opaque=!0;Q.set(j,W)}}for(let H of Q.values()){if(H.key===void 0)continue;if(H.opaque)K(`${H.key}=`,!0);else X(H.key,H.value)}if(J.length===0&&!Y)return null;return{programs:J,unresolved:Y}}function dZ(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
|
+
`||VZ.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 h2(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 t4=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]),e4=new Set(["--rcfile","--init-file"]),KZ=(Z)=>Z.replace(/\$'(?:[^'\\]|\\[\s\S])*'/g,(z)=>z.replace(/\\[\s\S]/g,($)=>$==="\\'"?"\\x27":$));function H0(Z){let z=/\$'(?:[^'\\]|\\[\s\S])*'/y,$=new Set;for(let X=Z.indexOf("$'");X>=0;X=Z.indexOf("$'",X+1)){z.lastIndex=X;let K=z.exec(Z);if(!K)continue;let B=X+K[0].length-1;for(let Q=X+2;Q<B;Q++){if(Z[Q]!=="\\")continue;if(Z[Q+1]==="'")$.add(Q);Q++}}if($.size===0)return Z;let J="",Y=0;for(let X of[...$].sort((K,B)=>K-B))J+=`${Z.slice(Y,X)}\\x27`,Y=X+2;return J+Z.slice(Y)}function nZ(Z,z,$=dZ){if(z<0||z>=Z.length)return null;let J=h0($(Z[z])??"");if(J==="eval"){let B=z+1;if(dZ(Z[B]??"")==="--")B++;let Q=Z.slice(B);if(Q.length===0)return null;if(Q.length>1)return{program:null,literal:!1};let H=dZ(Q[0]);return H!==null&&h2(H)?{program:H,literal:!0}:{program:H,literal:!1}}if(!t4.has(J))return null;let Y=!1,X=z+1;for(;X<Z.length;X++){let B=dZ(Z[X]);if(B===null){if(Y)break;return/^"[^"]*"$/.test(Z[X])?null:{program:null,literal:!1}}if(B==="--"){X++;break}if(!/^[-+]./.test(B))break;if(B.startsWith("--")){if(e4.has(B))X++;continue}let Q=B.slice(1);if(B[0]==="-"&&Q.includes("c"))Y=!0;if(/[oO]/.test(Q))X++}if(!Y||X>=Z.length)return null;let K=dZ(Z[X]);return K!==null&&h2(K)?{program:K,literal:!0}:{program:K,literal:!1}}function Z5(Z,z,$){let J=$5(Z,z,$);if(J===null)return{programs:[],unresolved:!0};let Y=new Set;for(let{scripts:X,mayFail:K}of J){let B=J5(X.join(`
|
|
4
|
+
`));if(B===null){if(K)continue;return{programs:[],unresolved:!0}}if(B.executes)return{programs:X.map((Q)=>({text:Q,kind:"shell"})),unresolved:!0};for(let Q of B.writes)Y.add(Q)}if(Y.size===0)return null;return{programs:[],unresolved:!1,writes:[...Y]}}var k0="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 $5(Z,z,$){let J=[],Y=[],X=!1,K=-1,B=!1,Q=!1;for(let G=z+1;G<Z.length;G++){let U=Z[G];if(Q||!/^-./.test(U)){Y.push(G);continue}if($(G))return null;if(U==="--"){Q=!0;continue}let V,j;if(U[1]==="-"){let W=U.indexOf("="),_=(W<0?U:U.slice(0,W)).slice(2),L=k0.filter((g)=>g.startsWith(_)),x=k0.includes(_)?_:L.length===1?L[0]:"";if(k0.indexOf(x)<15){if(!x)return null;continue}if(V=x[0],W>=0)j=U.slice(W+1)}else{let W=1;while("nrEsuzb".includes(U[W]??"_"))W++;if(V=U[W]??"",V==="i"||V==="I"){let _=W===U.length-1&&G+1<Z.length&&!$(G+1)?Z[G+1]:void 0;if(V==="I"){if(B=X=!0,W===U.length-1){if(_===void 0)return null;K=G+1}}else if(_===""||_?.startsWith("."))X=!0,K=G+1;continue}if(V==="")continue;if(!"efl".includes(V))return null;j=U.slice(W+1)||void 0}if(V==="f")return null;if(j===void 0){if(j=Z[++G],j===void 0||$(G))return null}if(V==="e")J.push(j)}let H=(G)=>{if(J.length>0)return J;let U=Y.find((V)=>V!==G);return U===void 0?[]:$(U)?null:[Z[U]]},M=[];if(!B)M.push({scripts:H(-1),mayFail:K>=0&&J.length===0&&Y[0]===K});if(X)M.push({scripts:H(K),mayFail:!1});return M.some((G)=>G.scripts===null)?null:M}function J5(Z){let z=[],$=!1,J=0,Y=Z.length,X=()=>Z[J]??"",K=()=>{while(X()===" "||X()==="\t")J++;let H=J,M=Z.indexOf(`
|
|
5
|
+
`,J);return J=M<0?Y:M,Z.slice(H,J)},B=()=>{let H=K();if(H&&!/^\/dev\/std(?:out|err)$/.test(H))z.push(H)},Q=(H,M)=>{for(;J<Y;J++){let G=Z[J];if(G===`
|
|
6
|
+
`)return!1;if(G==="\\"){if(++J>=Y)return!1}else if(G===H)return J++,!0;else if(M&&G==="["){let U=J+1;if(Z[U]==="^")U++;if(Z[U]==="]")U++;for(;Z[U]!=="]";U++){if(U>=Y||Z[U]===`
|
|
7
|
+
`)return!1;if(Z[U]==="["&&":.=".includes(Z[U+1]||`
|
|
8
|
+
`)){let V=Z.indexOf(Z[U+1]+"]",U+2);if(V<0||Z.slice(U,V).includes(`
|
|
9
|
+
`))return!1;U=V+1}}J=U}}return!1};while(J<Y){let H=Z[J++];if(H==="/"||H==="\\"){let M=H==="\\"?Z[J++]??"":"/";if(!M||M===`
|
|
10
|
+
`||!Q(M,!0))return null}else if(H==="#")K();else if(":btTv".includes(H)){while(X()===" "||X()==="\t")J++;while(J<Y&&!/[\s;]/.test(X()))J++}else if("aic".includes(H)){while(X()===" "||X()==="\t")J++;if(X()==="\\")J+=2;for(;J<Y&&Z[J]!==`
|
|
11
|
+
`;J++)if(Z[J]==="\\")J++}else if(H==="e")$=!0,K();else if(H==="r"||H==="R")K();else if(H==="w"||H==="W")B();else if(H==="s"||H==="y"){let M=Z[J++]??"";if(!M||M===`
|
|
12
|
+
`||M==="\\"||!Q(M,H==="s")||!Q(M,!1))return null;for(;H==="s"&&" \tgpiImMe0123456789w".includes(X()||"_");J++){if(X()==="e")$=!0;if(X()==="w"){J++,B();break}}}}return{writes:z,executes:$}}var z5=new Set(["-exec","-execdir","-ok","-okdir"]),Y5=new Set(["-exec","-execdir"]),X5=new Set("0oprtx"),K5=new Set("adEILnPsJRS"),Q5=new Set("eil"),B0={"--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 B5(Z){if(Object.hasOwn(B0,Z))return B0[Z];let z=Object.keys(B0).filter(($)=>$.startsWith(Z));return z.length===1?B0[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 B=Y.indexOf("="),Q=B5(B<0?Y:Y.slice(0,B));if(Q===null){if(J>=4)return[];return[...sZ(Z,z+1,$,J+1),...sZ(Z,z+2,$,J+1)]}z+=Q==="value"&&B<0?2:1;continue}let X=!1,K=!1;for(let B=1;B<Y.length;B++){let Q=Y[B];if(X5.has(Q))continue;if(Q5.has(Q))break;if(K5.has(Q)){X=B===Y.length-1;break}K=!0;break}if(K){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 OZ(Z,z,$=()=>!1){if(z<0||z>=Z.length)return[];let J=h0(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)||!z5.has(Z[X]))continue;let K=X+1,B=K;for(;B<Z.length;B++){if($(B))continue;if(Z[B]===";")break;if(Z[B]==="+"&&B>K&&Z[B-1]==="{}"&&Y5.has(Z[X]))break}if(K<B)Y.push({start:K,end:B});X=B}return Y}function oZ(Z,z,$){if(z<0||z>=Z.length)return null;let J=h0(Z[z]);if(J==="deno"){let Y=l4(Z,z,$);if(Y)return Y}if(Object.hasOwn(x0,J)||w2.test(J))return u4(J,Z,z,$);if(v4.has(J))return p4(Z,z,$);if(S4.has(J))return c4(Z,z,$);if(J==="rsync")return i4(Z,z,$);if(J==="git")return r4(Z,z,$);if(J==="sed")return Z5(Z,z,$);return null}var H5=600000,M5="Delete via trash guard (rm intercepted and made recoverable)",m0="[workspace-repos-guard] Deletion under a protected repository checkout is refused.",G5=[".hasna/repos/clones","workspace/repos"],V5=[".hasna",".ssh",".aws"],M0={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."},e2="`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.",Z3="`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>`.",$3=new Set([...Object.values(M0),e2,Z3]),U5=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env"]),j5={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"]},W5={timeout:1},F5={sudo:{short:{A:N,B:N,b:N,E:N,H:N,i:N,k:N,N,n:N,P:N,S:N,s:N,C:D,g:D,p:D,r:D,T:D,t:D,U:D,u:D,e:YZ,l:YZ,v:YZ,D:A,R:A,h:A,K:A,V:A},long:{askpass:N,bell:N,background:N,"close-from":D,chdir:A,"preserve-env":cZ,edit:YZ,group:D,"set-home":N,help:A,host:A,login:N,"remove-timestamp":A,"reset-timestamp":N,list:YZ,"no-update":N,"non-interactive":N,"preserve-groups":N,prompt:D,chroot:A,role:D,stdin:N,shell:N,type:D,"command-timeout":D,"other-user":D,user:D,version:A,validate:YZ},assignments:!0},doas:{short:{n:N,s:N,u:D,C:A,L:A},long:{}},flock:{short:{s:N,x:N,e:N,n:N,u:N,o:N,F:N,w:D,E:D,h:A,V:A},long:{shared:N,exclusive:N,unlock:N,nonblock:N,nonblocking:N,nb:N,timeout:D,wait:D,"conflict-exit-code":D,close:N,"no-fork":N,fcntl:N,verbose:N,help:A,version:A},positionals:[/^[\s\S]+$/]}},N5={...f0,...F5},J3=new Set(["-c","--command"]),q5=new Set(["busybox","toybox"]),w0=new Set(["rm","rmdir","unlink","shred"]),I5=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]),T5=new Set(["-C","-c","--git-dir","--work-tree","--namespace","--exec-path","--config-env"]),_5=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/i;function z3(Z){let z=k(Z),$=f(Z);return $===z?[z]:[z,$]}function n(Z){return z3(Z).some((z)=>_5.test(z))}var D5=/(^|[^A-Za-z0-9_.-])-delete(?![A-Za-z0-9_.-])/,C5=/(^|[^A-Za-z0-9_.-])git(?![A-Za-z0-9_.-])/i,P5=/(^|[^A-Za-z0-9_.-])clean(?![A-Za-z0-9_.-])/;function yZ(Z){return z3(Z).some((z)=>{if(D5.test(z))return!0;for(let $ of z.split(/[\n;&|]/)){let J=C5.exec($);if(J&&P5.test($.slice(J.index+J[0].length)))return!0}return!1})}function tZ(Z){return Z.map((z)=>z.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var c0=/^[A-Za-z_][A-Za-z0-9_]*=/;function G0(Z){let z=Z.lastIndexOf("/");return z>=0?Z.slice(z+1):Z}var p2={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
|
|
13
|
+
`,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function O5(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),K;if(Object.hasOwn(p2,Y))$+=p2[Y],J+=2;else if(K=X.match(/^[0-7]{1,3}/))$+=String.fromCharCode(parseInt(K[0],8)&255),J+=1+K[0].length;else if((K=X.match(/^x([0-9A-Fa-f]{1,2})/))||(K=X.match(/^u([0-9A-Fa-f]{1,4})/))||(K=X.match(/^U([0-9A-Fa-f]{1,8})/))){let B=parseInt(K[1],16);$+=B<=1114111?String.fromCodePoint(B):"",J+=1+K[0].length}else if(Y==="c"&&J+2<Z.length&&Z[J+2]!=="'")$+=String.fromCharCode(Z.charCodeAt(J+2)&31),J+=3;else $+=`\\${Y}`,J+=2}return{text:$,end:Math.min(J+1,Z.length)}}function f(Z){return Y3(Z,!0)}function Y3(Z,z){let $="",J=0;while(J<Z.length){let Y=Z[J];if(z&&Y==="$"&&Z[J+1]==="'"){let X=O5(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];$+=VZ.on||/[$`"\\]/.test(X)?X:X===`
|
|
14
|
+
`?"":`\\${X}`,J+=2;continue}$+=Z[J],J++}J++;continue}$+=Y,J++}return $}function RZ(Z){if(Q0(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==="["&&L5(Z,$+1,"]"))return!0}return!1}function L5(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 A5(Z,z){if(!RZ(Z))return!1;let $=JZ(Z);return $===null||$.some((J)=>X3(J,z).some((Y)=>w0.has(Y)))}function jZ(Z){return G0(f(Z))}var i0={deep:!0};function d0(Z,z){return Z.replace(/\\([$`\\"])/g,($,J)=>J==='"'&&!z?$:J)}function y5(Z,z,$){let J=[],Y=z+1;while(Y<$-1){let X=Z[Y];if(X==="\\"){Y+=2;continue}if(X==="`"){let K=bZ(Z,Y);if(K<0)return null;J.push(d0(Z.slice(Y+1,K-1),!0)),Y=K;continue}if(X==="$"&&Z[Y+1]==="("){let K=BZ(Z,Y+1);if(K<0)return null;J.push(Z.slice(Y+2,K-1)),Y=K;continue}Y++}return J}function R5(Z){let z=[],$=0;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==="`"){let Y=bZ(Z,$);if(Y<0)return null;z.push(d0(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 m2(Z,z,$,J){let Y=z+1;for(let X of $){let K=Math.min(Y,Z.length);for(;;){if(Y>Z.length){Y=Z.length+1;break}let Q=Z.indexOf(`
|
|
15
|
+
`,Y),H=Q===-1?Z.length:Q,M=Z.slice(Y,H).replace(/\r$/,"");if(X.stripTabs)M=M.replace(/^\t+/,"");if(M===X.delimiter)break;Y=H+1}let B=Z.slice(K,Math.min(Y,Z.length));if(X.owner.push(B),!X.quoted){let Q=R5(B);if(!Q)return-1;J.push(...Q)}if(Y<=Z.length){let Q=Z.indexOf(`
|
|
16
|
+
`,Y);Y=(Q===-1?Z.length:Q)+1}}return Math.min(Y-1,Z.length)}function s0(Z,z){let $=Z.indexOf("'",z+1);return $===-1?-1:$+1}function b5(Z,z){let $=1,J=z+1;while(J<Z.length){let Y=Z[J],X=Y==="\\"?J+2:Y==="'"?s0(Z,J):Y==='"'?n0(Z,J):Y==="`"?bZ(Z,J):Y==="$"&&Z[J+1]==="("?BZ(Z,J+1):0;if(X<0)return-1;if(X>0)J=X;else if(Y==="$"&&Z[J+1]==="{")$++,J+=2;else if(Y==="}"&&--$===0)return J+1;else J++}return-1}function bZ(Z,z){let $=z+1;while($<Z.length){if(Z[$]==="\\"){$+=2;continue}if(Z[$]==="`")return $+1;$++}return-1}function n0(Z,z){let $=z+1;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==='"')return $+1;if(J==="`"){let Y=bZ(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 vZ(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 K=Z[$];if(K==="'"||K==='"'){let B=Z.indexOf(K,$+1);if(B<0)return null;Y+=Z.slice($+1,B),X=!0,$=B+1;continue}if(K==="\\"){if($+1>=Z.length)return null;Y+=Z[$+1],X=!0,$+=2;continue}Y+=K,$++}return Y?{delimiter:Y,stripTabs:J,quoted:X,end:$}:null}function V0(Z,z,$){let J=z+1;for(let Y of $)for(;;){if(J>Z.length)return-1;let X=Z.indexOf(`
|
|
17
|
+
`,J),K=X===-1?Z.length:X,B=Z.slice(J,K);if(B.endsWith("\r"))B=B.slice(0,-1);let Q=Y.stripTabs?B.length-B.replace(/^\t+/,"").length:0;if(Y.stripTabs)B=B.slice(Q);if(B===Y.delimiter){J=K+1;break}if(B.startsWith(Y.delimiter)&&/^\s*\)/.test(B.slice(Y.delimiter.length))){if(Y===$[$.length-1])return J+Q+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,K=[];while(X<$){let B=Z[X];if(B==="\\"){X+=2;continue}if(B==="'"){let Q=s0(Z,X);if(Q<0)return-1;X=Q;continue}if(B==='"'){let Q=n0(Z,X);if(Q<0)return-1;X=Q;continue}if(B==="`"){let Q=bZ(Z,X);if(Q<0)return-1;X=Q;continue}if(!J&&B==="<"&&Z[X+1]==="<"){if(Z[X+2]==="<"){X+=3;continue}let Q=vZ(Z,X);if(!Q)return-1;K.push(Q),X=Q.end;continue}if(B===`
|
|
18
|
+
`&&K.length>0){let Q=V0(Z,X,K);if(Q<0)return-1;K=[],X=Q;continue}if(!J&&B==="#"&&/[\s;&|(]/.test(Z[X-1])){let Q=Z.indexOf(`
|
|
19
|
+
`,X);if(Q<0)return-1;X=Q;continue}if(B==="(")Y++;else if(B===")"){if(Y--,Y===0)return K.length>0?-1:X+1}X++}return-1}function w(Z,z={}){let $=z.deep===!0,J=z.comments,Y=[],X=[],K=[],B=new Set,Q=[],H=[],M=-1,G=!1,U=!0,V=0,j=Z.length,W=(q)=>{if(M>=0){let F=K.length;if(K.push({text:Z.slice(M,q),start:M,end:q}),G)B.add(F);M=-1,G=!1}},_="",L=(q,F)=>{if(W(q),K.length>0)Y.push($?{words:K,redirects:B,heredocs:Q,position:{before:_,after:F}}:{words:K,redirects:B});if(_=F,K=[],B=new Set,$)Q=[];G=!1},x=(q)=>s0(Z,q),g=(q)=>bZ(Z,q),y=(q)=>BZ(Z,q),O=(q)=>n0(Z,q);while(V<j){let q=Z[V];if(q===" "||q==="\t"||q==="\r"){W(V),V++;continue}if(q===`
|
|
20
|
+
`){if(L(V,`
|
|
21
|
+
`),H.length>0){let F=m2(Z,V,H,X);if(H=[],F<0)U=!1,V=j;else V=F;continue}V++;continue}if(q===";"){L(V,";"),V++;continue}if(q==="&"){L(V,Z[V+1]==="&"?"&&":Z[V+1]===">"?"&>":"&"),V+=Z[V+1]==="&"?2:1;continue}if(q==="|"){L(V,Z[V+1]==="|"?"||":"|"),V+=/[|&]/.test(Z[V+1])?2:1;continue}if(J&&M<0&&(q==="#"||q==="("&&Z[V+1]==="(")){let F=Z.indexOf(`
|
|
22
|
+
`,V),R=q==="("?BZ(Z,V):F<0?j:F;if(q==="#")J.push([V,R]);if(R<0)U=!1,V=j;else V=R;continue}if(J&&q==="$"&&Z[V+1]==="{"){if(M<0)M=V;let F=b5(Z,V+1);if(F<0)U=!1,V=j;else V=F;continue}if($&&q==="("&&M>=0&&"?*+@!".includes(Z[V-1])){U=!1,V=j;continue}if(q==="("||q===")"){L(V,q),V++;continue}if(q==="<"&&Z[V+1]==="<"&&Z[V+2]!=="<"){let F=Z.slice(V+2).match(/^-?[ \t]*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/);if(!F){U=!1,V=j;continue}if($){let ZZ=V+2+F[0].length;if(ZZ<j&&!/[\s;&|()<>]/.test(Z[ZZ])){U=!1,V=j;continue}W(V),H.push({delimiter:F[2],quoted:F[1]!=="",stripTabs:F[0].startsWith("-"),owner:Q}),V=ZZ;continue}let R=Z.indexOf(`
|
|
23
|
+
`,V+2+F[0].length);if(R===-1){U=!1,V=j;continue}let e=Z.slice(R+1),o=v5(e,F[2]);if(o===-1){U=!1,V=j;continue}W(V),V=R+1+o+F[2].length;continue}if(q===">"||q==="<"){if(M>=0&&/^\d+$/.test(Z.slice(M,V)))M=-1;if(W(V),G=!0,V++,Z[V]===q||Z[V]==="&"||q===">"&&Z[V]==="|"||q==="<"&&Z[V]===">")V++;continue}if(q==="'"){if(M<0)M=V;let F=x(V);if(F<0)U=!1,V=j;else V=F;continue}if(q==='"'){if(M<0)M=V;let F=O(V),R=F<0||!$?[]:y5(Z,V,F);if(F<0||!R)U=!1,V=j;else X.push(...R),V=F;continue}if(q==="`"){if(M<0)M=V;let F=g(V);if(F<0)U=!1,V=j;else{let R=Z.slice(V+1,F-1);X.push($?d0(R,!1):R),V=F}continue}if(q==="$"&&Z[V+1]==="("){if(M<0)M=V;let F=y(V+1);if(F<0)U=!1,V=j;else X.push(Z.slice(V+2,F-1)),V=F;continue}if(q==="\\"){if(M<0)M=V;if(V+1>=j)U=!1,V=j;else V+=2;continue}if(M<0)M=V;V++}if(L(j,""),H.length>0&&m2(Z,j,H,X)<0)U=!1;return{segments:Y,trustworthy:U,substitutions:X}}function v5(Z,z){let $=0;while($<=Z.length){let J=Z.indexOf(z,$);if(J===-1)return-1;let Y=J===0||Z[J-1]===`
|
|
24
|
+
`,X=J+z.length,K=X===Z.length||Z[X]===`
|
|
25
|
+
`||Z[X]==="\r";if(Y&&K)return J;$=J+1}return-1}function k(Z){return Y3(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=f(J);if(c0.test(Y)&&!Y.startsWith("-")){z++;continue}if(I5.has(Y)){z++;continue}let X=G0(Y);if(X==="command")for(let B of Z.words.filter((Q,H)=>H>z&&!Z.redirects.has(H))){let Q=f(B.text);if(Q==="--"||!Q.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(Q))return-1}let K=j5[X];if(K){let B=z;z++;while(z<Z.words.length){if(Z.redirects.has(z)){z++;continue}let H=f(Z.words[z].text);if(!H.startsWith("-")||H==="-")break;if(H==="--"){z++;break}if(X==="env"&&(/^-[iv0]*S/.test(H)||/^--split-string(?:=|$)/.test(H)))return B;if(z++,K.includes(H)||X==="exec"&&/^-[cl]*a$/.test(H)){while(Z.redirects.has(z))z++;z++}}let Q=W5[X]??0;while(Q>0&&z<Z.words.length){let H=f(Z.words[z].text);if(H.startsWith("-")&&H!=="-")break;z++,Q--}continue}return z}return-1}function c2(Z,z){let $=[],J=!1;for(let Y=z+1;Y<Z.words.length;Y++){if(Z.redirects.has(Y))continue;let X=k(Z.words[Y].text);if(!J){if(X==="--"){J=!0;continue}if(X.startsWith("-")&&X!=="-")continue}$.push(Z.words[Y])}return $}function o0(Z){return G5.map((z)=>u.join(Z,...z.split("/")))}function U0(Z,z){if(Z==="~"||Z==="$HOME"||Z==="${HOME}")return z;if(Z.startsWith("~/"))return u.join(z,Z.slice(2));if(Z.startsWith("$HOME/"))return u.join(z,Z.slice(6));if(Z.startsWith("${HOME}/"))return u.join(z,Z.slice(8));return Z}function WZ(Z,z,$){let J=k(Z);if(!J)return null;if(J.includes("`"))return null;if(J==="$HOME"||J==="${HOME}"||J==="$HOME/"||J==="${HOME}/")return $;if(J.replace(/\$\{HOME\}/g,"").replace(/\$HOME/g,"").includes("$"))return null;if(/[*?[\]]/.test(J))return null;if(J.startsWith("~")){let B=U0(J,$);if(B===J)return null;J=B}let K=(u.isAbsolute(J)?u.normalize(J):u.resolve(z,J)).replace(/\/+$/,"");return K===""?"/":K}function UZ(Z,z){return Z===z||Z.startsWith(`${z}${u.sep}`)}var S5=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/,E5=!1,f5=/^[A-Za-z0-9._@+-]{1,128}$/,k5=512;function LZ(Z){return`'${Z.replace(/[\u0000-\u001f\u007f-\u009f]/g,"?").slice(0,k5).replace(/'/g,"'\\''")}'`}function i2(Z){return f5.test(Z)?`\`${Z}\``:"a name that is not a plain identifier"}function x5(Z,z){let $=`${u.join(z,".hasna","scratchpad","scratch")}${u.sep}`;if(!Z.startsWith($))return null;let[J,Y]=Z.slice($.length).split(u.sep);if(!J)return{content:!1,reason:"the scratch root itself holds every session, not one session's content"};if(J.endsWith(".")||!S5.test(J))return{content:!1,reason:`${i2(J)} is not a session id this carve-out accepts (real ids are mixed case, e.g. \`ses_ebbb3f564ffe7PDf32UBmlNI3v\`)`};if(!Y)return E5?{content:!0}:{content:!1,reason:`${i2(J)} is a session root; removing it would also remove its \`meta.json\` and \`.lock\` control files, and whether the root itself is scratch is an open decision (Todos 264c4be0) — remove specific children instead`};let X=Y.normalize("NFKC").toLowerCase();if(X==="meta.json"||X===".lock")return{content:!1,reason:`\`${X}\` is session control state, not scratch`};return{content:!0}}function a0(Z,z){if(Z===z)return`${LZ(Z)} is the home directory itself, which is never deleted or trashed. Delete a specific file or directory inside it instead.`;for(let $ of mZ){if(Z!==$&&!UZ($,Z))continue;return $==="/"?`${LZ(Z)} is the filesystem root, which is never deleted.`:`${LZ(Z)} is the system root \`${$}\` (or an ancestor of it), which is never deleted or trashed.`}for(let $ of V5){let J=u.join(z,$),Y=UZ(Z,J);if(!Y&&!UZ(J,Z))continue;if($===".hasna"&&Y){let X=x5(Z,z);if(X?.content===!0)continue;if(X&&X.content===!1)return`${LZ(Z)} is inside the protected \`~/${$}\` tree and is not sanctioned scratch, because ${X.reason}. Nothing under \`~/${$}\` is deleted or trashed outside that one carve-out.`}return Y?`${LZ(Z)} is inside the protected \`~/${$}\` tree, which is never deleted or trashed. Delete a specific file inside it, and only when you are sure.`:`${LZ(Z)} contains the protected \`~/${$}\` tree, which is never deleted or trashed. Delete a specific file or directory inside it instead.`}return null}function h5(Z,z,$){let J=o0($);if(J.some((Y)=>UZ(z,Y)))return!0;return Z.some((Y)=>Y!==null&&J.some((X)=>UZ(Y,X)))}var g0=/[^A-Za-z0-9_]+/;function w5(Z){let z=new Map;for(let $ of Z.flatMap((J)=>J.words)){let J=c0.exec($.text)?.[0].slice(0,-1);if(!J)continue;let Y=f($.text.slice(J.length+1)),X=z.get(J)??{values:[],names:new Set};X.values.push(Y);for(let K of Y.split(g0))X.names.add(K);z.set(J,X)}return z}function X3(Z,z){let $=f(Z).split(g0),J=[];for(let Y of new Set(Array.from(Z.matchAll(/\$\{?([A-Za-z_]\w*)/g),(X)=>X[1]))){let X=z.assigned.get(Y);if(!X)continue;for(let B of X.names)$.push(B);let K=new RegExp(`\\$(?:\\{${Y}\\}|${Y}(?!\\w))`,"g");J=(J.length>0?J:[Z]).flatMap((B)=>X.values.slice(0,16).map((Q)=>B.replace(K,()=>Q))).slice(0,16)}for(let Y of J)for(let X of f(Y).split(g0))$.push(X);return $}var d2=new WeakMap;function g5(Z){let z=d2.get(Z);if(z)return z;let $=Z.words.map((K)=>f(K.text)),J=$.findIndex((K)=>K==="-exec"||K==="-execdir"||K==="-ok"||K==="-okdir"),Y=-1;Z.words.forEach((K,B)=>{if(J3.has(k(K.text)))Y=B});let X={findDelete:$.includes("-delete"),findExecDelete:J>=0&&$.slice(J).some((K)=>w0.has(G0(K))),namesDelete:$.some((K)=>w0.has(G0(K))),lastFlockCommand:Y,textMention:t5(B3(Z),$.join(" ")),envMention:n(tZ(Z.words.map((K)=>k(K.text)))),bodiesMention:n((Z.heredocs??[]).join(`
|
|
26
|
+
`))};return d2.set(Z,X),X}var u5=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]);function l5(Z,z){if(!u5.has(jZ(Z.words[z].text)))return!1;for(let $=z+1;$<Z.words.length;$++){if(Z.redirects.has($))continue;let J=k(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 AZ=(Z)=>Z.kind==="rm"||Z.kind==="refuse",K3="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.",p5="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.",m5="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.",c5="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.",i5="This command deletes after a `cd` this hook cannot follow, and where that cd leads the delete is in a protected repository checkout (owned by workspace-repos-guard). Write the cd with its directory alone, or run the delete as its own `rm -- <path>` command.";function rZ(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:f(X),opaque:RZ(X)}}),J=IZ($,N5);if(J===null)return null;return J.index<0?-1:z[J.index]}function d5(Z,z,$,J){let Y={kind:"cd",cwd:J.cwd,kept:!0},X=()=>{let G=Z.words[z+1];if(!G)return{kind:"none"};return{kind:"cd",cwd:WZ(G.text,$,J.home)??J.cwd}},K=Z.position;if(K&&(K.before==="|"||K.after==="|"||K.after==="&"))return{kind:"none"};if(z!==0&&!(z===1&&Z.words[0].text==="{"))return X();let B=null,Q=!0;for(let G=z+1;G<Z.words.length;G++){if(Z.redirects.has(G)){if(B===null)return X();continue}let U=Z.words[G].text,V=RZ(U)?U:k(U);if(Q&&(V==="--"||V.startsWith("-")&&V!=="-")&&U!==V)return X();if(Q&&V==="--"){Q=!1;continue}if(Q&&V.startsWith("-")&&V!=="-"){if(/^-[LPe]+$/.test(V))continue;return Y}if(Q=!1,B!==null)return Y;B=U}if(B===null)return K?.after==="&>"?X():{kind:"cd",cwd:J.home};let H=k(B);if(H==="-")return Y;if(J.setsCdpath&&!/^(?:\/|\.|~|\$HOME|\$\{HOME\})/.test(H))return Y;let M=WZ(B,$,J.home);return M===null?Y:{kind:"cd",cwd:M}}function QZ(Z,z,$,J){let Y=jZ(Z.words[z].text);if(Y==="cd")return d5(Z,z,$,J);if(Object.hasOwn(M0,Y))return J.observe?.({verb:Y,operands:c2(Z,z).map((Q)=>Q.text),cwd:$}),{kind:"refuse",reason:M0[Y]};let X=J.launched?null:Q3(Z,z,$,J);if(X)return X;if(Y==="rm"){let Q=c2(Z,z);if(Q.length===0)return{kind:"none"};J.observe?.({verb:"rm",operands:Q.map((j)=>j.text),cwd:$});let H={word:Z.words[z],operands:Q},M=o0(J.home),G=(j)=>j!==null&&M.some((W)=>UZ(j,W)),U=[],V=[];for(let j of Q){let W=WZ(j.text,$,J.home);if(U.push(W),!j.text.includes("{"))continue;let _=JZ(j.text);if(_===null)return{kind:"refuse",reason:p5};for(let L of _){let x=WZ(L,$,J.home);if(x===null)continue;if(G(x)&&!G(W))return{kind:"refuse",reason:m5};V.push(x)}}if(h5(U,$,J.home))return H.cwdOnly=U.every((j)=>j!==null&&!G(j)),{kind:"rm",hit:H,handoff:!0,protectedReason:null};for(let j of[...U,...V]){if(!j)continue;let W=a0(j,J.home);if(W)return{kind:"rm",hit:H,handoff:!1,protectedReason:W}}return{kind:"rm",hit:H,handoff:!1,protectedReason:null}}if(q5.has(Y)){let Q=Z.words.findIndex((M,G)=>G>z&&!k(M.text).startsWith("-")),H=Q>=0?jZ(Z.words[Q].text):"";if(H==="rm"||Object.hasOwn(M0,H))return{kind:"refuse",reason:`\`${Y} ${H}\` runs the ${Y} applet, whose own \`rm\` is not GNU \`rm\` and cannot be rewritten in place. Run the delete as \`rm -- <path>\`, which is redirected into trash.`};return{kind:"none"}}if(Y==="git"){for(let[Q,H]of[[k,!1],[f,!1],[f,!0]]){let M=H3(Z,z,Q,H);if(M<0)continue;let G=Z.words[M].text,U=RZ(G)?[Q(G),...X3(G,J)]:[Q(G)];for(let V of["rm","clean"].filter((j)=>U.includes(j))){if(V==="rm"?e5(Z,z):G3(Z,z))continue;return{kind:"refuse",reason:V==="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 K=g5(Z);if(Y==="find"){if(K.findDelete||K.findExecDelete)J.observe?.({verb:"find",cwd:$});if(K.findDelete)return{kind:"refuse",reason:e2};if(K.findExecDelete)return{kind:"refuse",reason:Z3};return s2(Z,z,$,J)??{kind:"none"}}if(Y==="xargs"&&K.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."};if(Y==="xargs")return s2(Z,z,$,J)??{kind:"none"};let B=Y==="flock"?K.lastFlockCommand>z:J3.has(Y);if(U5.has(Y)||B){let Q=l5(Z,z)?J.bodiesMention:K.bodiesMention;if((Y==="env"?K.envMention:K.textMention)||Q)return{kind:"refuse",reason:`\`${B?"flock":Y}\` runs a command string this hook cannot rewrite in place. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or as a script that uses \`trash guard\` itself.`}}return{kind:"none"}}function Q3(Z,z,$,J,Y={segment:Z,index:z},X=0){let K=jZ(Z.words[z].text);for(let G of OZ(Z.words.map((U)=>f(U.text)),z,(U)=>Z.redirects.has(U))){if(X>=8)return aZ(Y.segment,Y.index,$,J.home)?{kind:"refuse",reason:s5}:null;let U={words:Z.words.slice(G.start,G.end),redirects:new Set([...Z.redirects].filter((j)=>j>=G.start&&j<G.end).map((j)=>j-G.start))},V=rZ(U);for(let j of new Set([l(U),V??-1])){if(j<0)continue;let W=Q3(U,j,$,J,Y,X+1);if(W)return W}}let B=Z.words.map((G,U)=>({word:G,at:U})).filter(({at:G})=>!Z.redirects.has(G)),Q=B.findIndex(({at:G})=>G===z),H=Q<0?null:nZ(B.map(({word:G})=>G.text),Q,f);if(H&&!H.literal&&(aZ(Z,z,$,J.home)||aZ(Y.segment,Y.index,$,J.home)))return{kind:"refuse",reason:`\`${K}\` 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=oZ(Z.words.map((G)=>f(G.text)),z,(G)=>G>=0&&G<Z.words.length&&(Z.redirects.has(G)||RZ(Z.words[G].text)));if(!M||!(aZ(Z,z,$,J.home)||aZ(Y.segment,Y.index,$,J.home)))return null;if(!M.unresolved&&!M.programs.some((G)=>n(G.text)))return null;return{kind:"refuse",reason:`\`${K}\` 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 s5="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 s2(Z,z,$,J){if(J.launched)return null;let Y=Z.words.map((H)=>f(H.text)),X=(H)=>Z.redirects.has(H),K={...J,launched:!0},B=[{at:z,end:Z.words.length}],Q=new Set;for(let H=0;H<B.length;H++){let{at:M,end:G}=B[H];for(let U of OZ(Y.slice(0,G),M,X)){let V=`${U.start}:${U.end}`;if(Q.has(V))continue;if(Q.add(V),Q.size>64)return yZ(B3(Z))?{kind:"refuse",reason:K3}:null;let j={words:Z.words.slice(U.start,U.end),redirects:new Set([...Z.redirects].filter((W)=>W>=U.start&&W<U.end).map((W)=>W-U.start))};for(let W of new Set([l(j),rZ(j)??-1])){if(W<0)continue;let _=QZ(j,W,$,K);if(_.kind==="refuse")return _;B.push({at:U.start+W,end:U.end})}}}return null}function aZ(Z,z,$,J){let Y=o0(J),X=(K)=>K!==null&&Y.some((B)=>UZ(K,B));if(Y.some((K)=>UZ($,K)))return!0;for(let K=z+1;K<Z.words.length;K++){if(Z.redirects.has(K))continue;if(X(WZ(Z.words[K].text,$,J)))return!0}return!1}var n5=/(^|[^A-Za-z0-9_.-])(case|esac)(?![A-Za-z0-9_.-])/;function r0(Z){if(!Z.includes("#"))return Z;let z=[];w(Z,{...i0,comments:z});let $=Z;for(let[J,Y]of z)$=$.slice(0,J)+" ".repeat(Y-J)+$.slice(Y);return $}function HZ(Z,z){let $=o2(Z,z),J=r0(Z),Y=J===Z?$:n2($,o2(J,z));for(let X of o5(Z)){let K=HZ(X,z);if(K.rmHits.length+K.handoffHits.length+K.refusals.length+K.protectedHits.length>0)Y={...n2(Y,K),trustworthy:!1}}return Y}function o5(Z){let z=KZ(Z),$=H0(Z);return[z,$].filter((J,Y,X)=>J!==Z&&X.indexOf(J)===Y)}function n2(Z,z){let $=(J,Y)=>[...J,...Y.filter((X)=>!J.some((K)=>K.word.start===X.word.start&&K.word.end===X.word.end))];return{rmHits:$(Z.rmHits,z.rmHits),handoffHits:$(Z.handoffHits,z.handoffHits),refusals:[...Z.refusals,...z.refusals.filter((J)=>!Z.refusals.some((Y)=>Y.reason===J.reason))],protectedHits:[...Z.protectedHits,...z.protectedHits],trustworthy:Z.trustworthy&&z.trustworthy}}function o2(Z,z){let $={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},J=w(Z,i0);$.trustworthy=J.trustworthy;let Y={cwd:z.cwd,home:z.home,depth:z.depth??0,setsCdpath:/\bCDPATH\b/.test(Z),bodiesMention:n(J.segments.flatMap((M)=>M.heredocs??[]).join(`
|
|
27
|
+
`)),assigned:w5(J.segments),observe:z.observe};if(!J.trustworthy){let M=KZ(Z);return M===Z?$:{...HZ(M,z),trustworthy:!1}}let X=[],K=(M,G=$.refusals)=>{if(M.kind==="refuse")G.push({reason:M.reason});else if(M.kind==="rm"&&M.handoff)$.handoffHits.push(M.hit);else if(M.kind==="rm"){if($.rmHits.push(M.hit),M.protectedReason)$.protectedHits.push({reason:M.protectedReason})}},B=Y.cwd,Q=Y.cwd,H=!1;for(let M of J.segments){let G=l(M),U=rZ(M),V=G<0?{kind:"none"}:QZ(M,G,B,Y),j=Q!==B,W=(y)=>{if(y.kind==="refuse")X.push({reason:y.reason});else if(y.kind==="rm"&&y.protectedReason)$.protectedHits.push({reason:y.protectedReason});else if(y.kind==="rm"&&y.handoff&&H)$.handoffHits.push(y.hit),X.push({reason:i5})};if(G>=0&&j)W(QZ(M,G,Q,Y));if(G>=0&&jZ(M.words[G].text)==="cd"&&M.words[G+1])Q=WZ(M.words[G+1].text,Q,Y.home)??Y.cwd;if(V.kind!=="cd")K(V);let _=(y)=>y!==null&&y>=0&&RZ(M.words[y].text);if(U===null||_(G)||_(U)){let y=(O)=>AZ(QZ(M,O,B,Y))||j&&AZ(QZ(M,O,Q,Y));if(M.words.some((O,q)=>!M.redirects.has(q)&&(y(q)||A5(O.text,Y))))X.push({reason:K3})}else if(U>=0&&U!==G){let y=QZ(M,U,B,Y);if(AZ(y))if(AZ(V))X.push({reason:c5});else K(y,X);if(j)W(QZ(M,U,Q,Y))}let L=r5(M),x=new Set([G,U??-1]);if(L&&[l(L),rZ(L)??-1].some((y)=>y>=0&&AZ(QZ(L,y,B,Y))&&!(x.has(y)&&AZ(QZ(M,y,B,Y)))))X.push({reason:a5});if(V.kind==="cd")B=V.cwd;if((V.kind==="cd"&&V.kept===!0||V.kind==="none"&&G>=0&&jZ(M.words[G].text)==="cd")&&Q!==B)H=!0}if(Y.depth<3){let M=(G,U)=>{let V=HZ(G,{cwd:U,home:Y.home,depth:Y.depth+1,observe:Y.observe});return V.rmHits.length>0||V.refusals.length>0||V.handoffHits.length>0||V.protectedHits.length>0||!V.trustworthy&&n(G)};for(let G of J.substitutions)if(M(G,B)||Q!==B&&M(G,Q)){$.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((M)=>n(M)))$.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."});if($.refusals.push(...X),J.substitutions.some((M)=>n5.test(M)))$.trustworthy=!1;return $}function B3(Z){return Z.words.map((z)=>z.text).join(" ")}var a5="A command name in capitals, such as `RM`, runs the lower-case command on a case-insensitive filesystem (the macOS default), and in lower case this command deletes or is refused. Write it in lower case.";function r5(Z){let z=!1,$=Z.words.map((J)=>{let Y=f(J.text);if(!/[A-Z]/.test(Y)||!/^[A-Za-z0-9_./+][A-Za-z0-9_./+-]*$/.test(Y))return J;return z=!0,{...J,text:u0(Y.toLowerCase())}});return z?{...Z,words:$}:null}function t5(Z,z){return[Z,z,f(z)].some(($)=>n($)||yZ($))}function H3(Z,z,$,J=!1){let Y=z+1;while(Y<Z.words.length){if(J&&Z.redirects.has(Y)){Y++;continue}let X=$(Z.words[Y].text);if(!X.startsWith("-"))return Y;if(Y++,T5.has(X))Y++}return-1}function M3(Z,z){let $=H3(Z,z,k);return $<0?null:k(Z.words[$].text)}function e5(Z,z){if(Z.words.slice(z+1).map((J)=>k(J.text)).includes("--cached"))return!0;return G3(Z,z)}function G3(Z,z){let $=Z.words.slice(z+1).map((J)=>k(J.text));return $.includes("-n")||$.includes("--dry-run")}function u0(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function Z6(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(u0).join(" "):`${u0($)} guard`,X=[...z].sort((B,Q)=>Q.word.start-B.word.start);if(X.some((B,Q)=>Q>0&&B.word.end>X[Q-1].word.start))return Z;let K=Z;for(let B of X)K=`${K.slice(0,B.word.start)}${Y}${K.slice(B.word.end)}`;return K}function $6(Z,z,$,J,Y){if(!z||z===Z)return!1;if($.length===0)return!1;let X=HZ(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 J6(Z,z){let $={};for(let[J,Y]of Object.entries(Z??{}))$[J]=Y;if($.command=z,typeof $.description!=="string"||$.description.trim()==="")$.description=M5;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=H5;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function z6(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 $6(z,Z.command,$,J,Y)}function Y6(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 w(Z,i0).segments.some((J)=>{let Y=rZ(J);return[l(J),...Y===null?[]:[Y]].some((X)=>{if(J.words.slice(0,X<0?J.words.length:X).some((Q)=>c0.test(k(Q.text))||z.has(jZ(Q.text))))return!0;if(X<0)return!1;let B=J.words[X];return z.has(jZ(B.text))||/^\s*\(\s*\)\s*\{/.test(Z.slice(B.end))})})}function s(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function X6(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function K6(Z){try{if(Z.inspectTrash){let z=Z.inspectTrash();return z.ok?{path:z.path,error:null}:{path:null,error:`${z.code}: ${E2[z.code]}`}}return{path:Z.findTrash(),error:null}}catch(z){return{path:null,error:z instanceof Error?z.message:String(z)}}}var Q6="[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.",a2="[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 r2(Z,z){if(Z.refusals.length>0)return s(`[trash-guard] ${Z.refusals[0].reason}`);if(Z.protectedHits.length>0)return s(`[trash-guard] ${Z.protectedHits[0].reason}`);if(!Z.trustworthy)return Z.rmHits.length>0||Z.handoffHits.length>0||n(z)||yZ(z)?s("[trash-guard] This hook could not follow this command to its end (an unclosed quote, substitution or here-document, or a construct it does not read, such as `case` inside a substitution), 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)return Z.handoffHits.length>0?s(m0):{continue:!0};if(Z.handoffHits.length>0)return s("[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 V3(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 s("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(j))return s("[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 s("[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=zZ(Z);if(!J.trim())return{continue:!0};let Y=()=>HZ(J,{cwd:z.cwd,home:z.home}),X=(j)=>j.rmHits.map((W)=>W.word.start).join(),K=(j)=>j()||!!XZ(J,j),B=Y(),Q=r2(B,J),H=XZ(J,()=>{let j=Y();return{result:j,verdict:r2(j,J)}});if(H){let{result:j,verdict:W}=H;if(W&&!("continue"in W))return W;if(!W&&(!Q||("continue"in Q))&&X(j)!==X(B))return s(a2)}if(Q)return Q;let M=K6(z);if(M.error!==null)return s(`[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 s(Q6);let G=M.path;if(z.execution&&K(()=>Y6(J)))return s("[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 U=Z6(J,B.rmHits,G,z.execution),V=J6(Z.tool_input,U);if(z.execution)V.hasna_execution="hasna.hooks.execution.v1";if(K(()=>!z6(V,J,B.rmHits,z.cwd,z.home)))return s(a2);return X6(V)}var p=require("node:fs"),z2=require("node:os"),v=require("node:path");var B6=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),H6=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),M6=["hasna","hasnaxyz","hasna-products"],eZ="workspace-repos-guard";function G6(Z){return v.join(Z,".hasna","repos","clones")}function V6(Z){return v.join(Z,"workspace","repos")}function D3(Z){return[G6(Z),V6(Z)]}function U6(Z){return v.join(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var j6=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function t0(Z){let z=process.getuid?.();return z!==void 0&&(Z.uid===0||Z.uid===z)&&(Z.mode&18)===0}function W6(Z){let z=U6(Z),$;try{let Y=p.openSync(z,p.constants.O_RDONLY|p.constants.O_NOFOLLOW);try{let K=p.fstatSync(Y);if(!K.isFile()||!t0(K)||K.size>4096)return null;$=p.readFileSync(Y,"utf8")}finally{p.closeSync(Y)}let X=v.normalize(Z);for(let K=v.dirname(z);K!==X;K=v.dirname(K)){let B=p.lstatSync(K);if(!B.isDirectory()||!t0(B)||K===v.dirname(K))return null}if(!t0(p.statSync(X)))return null}catch{return null}let J=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return J.length>0&&J.every((Y)=>j6.test(Y))?new Set(J):null}function F6(Z=process.env,z=z2.homedir()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((J)=>J.trim()).filter(Boolean));return W6(z)??new Set(M6)}function e0(Z,z,$,J){if(J==="read")return{blocked:!1};let Y=v.relative(z,Z);if(Y===""){if(J==="delete")return{blocked:!0,reason:`[${eZ}] delete of the protected repo-checkout root is forbidden: ${z}`};return{blocked:!0,reason:`[${eZ}] writes directly to the protected repo-checkout root are forbidden: ${z}`}}if(Y.startsWith(`..${v.sep}`)||Y===".."||v.isAbsolute(Y))return{blocked:!1};let X=Y.split(v.sep).filter(Boolean);if(J==="delete")return{blocked:!0,reason:`[${eZ}] delete under the protected repo-checkout root (${z}) is forbidden at any depth: ${Z}`};if(X.length<=1)return{blocked:!0,reason:`[${eZ}] writing would create a top-level entry directly under the protected repo-checkout root (${z}); only GitHub-org folders belong there: ${Z}`};let K=X[0];if(!$.has(K))return{blocked:!0,reason:`[${eZ}] '${K}' is not an allowed GitHub org under the protected repo-checkout root (${z}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var C3=/\b(?:-o|--output|-O|--output-document|-out)\b/,N6=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,q6=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function P3(Z){return Z.replace(N6," ")}function I6(Z){let z=[],$=null,J=0,Y=0,X=!1,K=0;for(let B=0;B<Z.length;B++){let Q=Z[B];if($==="'"){if(Q==="'")$=null;continue}if(Q==="\\"){B++;continue}if(Q==="("){J++;continue}if(Q===")"){if(--J<0)return[Z];continue}if(Q==="$"&&Z[B+1]==="{"){Y++,B++;continue}if(Q==="}"&&Y>0){Y--;continue}if(Q==="`"){X=!X;continue}if($==='"'){if(Q==='"')$=null;continue}if(Q==="'"||Q==='"'){$=Q;continue}if(Q!=="|"||J>0||Y>0||X||Z[B-1]===">")continue;if(z.push(Z.slice(K,B)),Z[B+1]==="&")B++;K=B+1}if($||J!==0||Y!==0||X)return[Z];return z.push(Z.slice(K)),z}function T6(Z){let z=[],$="",J="",Y=null,X=!1,K=()=>{if(!X)return;let B=J.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),Q=$.startsWith("~")&&!/^~(?:\/|$)/.test(J);z.push({text:Q?`./${$}`:$,opaque:/[$\x60*?[]/.test(B)||/[()]/.test(B)||Q0(J)}),$="",J="",X=!1};for(let B=0;B<Z.length;B++){let Q=Z[B];if(Y==="'"){if(Q==="'")Y=null;else $+=Q;J+=Q;continue}if(Q==="\\"&&B+1<Z.length){let H=Z[B+1];$+=Y==='"'&&!/[$\x60"\\\n]/.test(H)?Q+H:Y==='"'&&H===`
|
|
28
|
+
`&&!VZ.on?"":H,J+=Q+H,X=!0,B++;continue}if(Y==='"'){if(Q==='"')Y=null;else $+=Q;J+=Q;continue}if(/\s/.test(Q)){K();continue}if(X=!0,J+=Q,Q==="'"||Q==='"')Y=Q;else $+=Q}if(Y)J+="$";return K(),z}function Z2(Z,z,$){let J=Z[z];return J==="--help"||J==="--version"||$&&(J==="-h"||J==="-V")}var U3={read:0,write:1,delete:2};function j0(...Z){return Z.reduce((z,$)=>U3[$]>U3[z]?$:z,"read")}var _6=new Set(["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"]),O3=new Set(["put","rm","delete","remove"]),D6=new Set([...O3,"restore","restore-capsule","recover","release","locks","retention","hold","unhold","pin","unpin","retrieve","backup-retrieve"]),L3=new Set(["-delete","-exec","-execdir","-ok","-okdir","-fls","-fprint","-fprint0","-fprintf"]);function Y2(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 X2(Z){let z=Z.trim();if(!z)return"read";if(F0(z))return"delete";let $=w(z);if(!$.trustworthy||$.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(z))return TZ(z);let J=$.segments.flatMap((Y)=>{let X=j3(Y),K=Y.words.filter((H,M)=>!Y.redirects.has(M)).map((H)=>H.text),B=K.map(JZ);if(B.every((H,M)=>H!==null&&H.length===1&&H[0]===K[M]))return[X];if(B.some((H)=>H===null))return[X,TZ(K.join(" "))];let Q=w(B.flatMap((H)=>H??[]).join(" "));return[X,...Q.trustworthy?Q.segments.map(j3):[TZ(K.join(" "))]]});return j0(...J)}function j3(Z){let z=Z.words.map((X,K)=>({word:X,at:K})).filter(({at:X})=>!Z.redirects.has(X)),$=l(Z),J=$<0?"read":W3(Z,$),Y=IZ(z.map(({word:X})=>K2(X.text)));if(Y===null)return j0(J,TZ(z.map(({word:X})=>k(X.text)).join(" ")));if(Y.index<0||z[Y.index].at===$)return J;return j0(J,W3(Z,z[Y.index].at))}function A3(Z,z,$=0){if(z<0||$>8)return $>8;let J=Z.words.map((H,M)=>({word:H,at:M})).filter(({at:H})=>!Z.redirects.has(H)),Y=J.findIndex(({at:H})=>H===z),X=Y<0?null:nZ(J.map(({word:H})=>H.text),Y,f);if(X){if(!X.literal)return!0;let H=w(X.program);if(H.trustworthy&&H.segments.some((M)=>W0(M,$+1)))return!0}let K=Z.words.map((H)=>f(H.text));for(let H of OZ(K,z,(M)=>Z.redirects.has(M)))if(W0(y3(Z,H.start,H.end),$+1))return!0;let Q=oZ(K,z,(H)=>H>=0&&H<Z.words.length&&(Z.redirects.has(H)||Y2(Z.words[H].text)));if(!Q)return!1;if(Q.unresolved)return!0;return Q.programs.some((H)=>H.kind==="shell"?X2(H.text)!=="read":!u2(H))}function y3(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 W0(Z,z=0){return R3(Z).some(($)=>A3(Z,$,z))}function K2(Z){return{text:f(Z),opaque:/[$\x60]/.test(Z)&&!/^(?:[^$\x60"'\\]|\$'(?:[^'\\]|\\.)*')+$/.test(Z)}}function R3(Z){let z=new Set,$=l(Z);if($>=0)z.add($);let J=Z.words.map((X,K)=>({word:X,at:K})).filter(({at:X})=>!Z.redirects.has(X)),Y=IZ(J.map(({word:X})=>K2(X.text)));if(Y!==null&&Y.index>=0)z.add(J[Y.index].at);return[...z]}function Z0(Z,z=0){if(z>8)return[];let $=[];for(let J of Z.segments){let Y=J.words.map((B)=>f(B.text)),X=(B)=>B>=0&&B<J.words.length&&(J.redirects.has(B)||Y2(J.words[B].text)),K=J.words.filter((B,Q)=>!J.redirects.has(Q));for(let B of R3(J)){$.push(...(oZ(Y,B,X)?.writes??[]).map((M)=>M[0]==="/"?M:`./${M}`));let Q=nZ(K.map((M)=>M.text),K.indexOf(J.words[B]),f),H=Q?.literal?w(Q.program):null;if(H?.trustworthy)$.push(...Z0(H,z+1));for(let M of OZ(Y,B,(G)=>J.redirects.has(G)))$.push(...Z0({segments:[y3(J,M.start,M.end)]},z+1))}}for(let J of Z.substitutions??[]){let Y=w(J);if(Y.trustworthy)$.push(...Z0(Y,z+1))}return $}function F0(Z,z=0){if(z>4)return!1;let $=w(Z),J=$.trustworthy?Z:KZ(Z);if(J!==Z)return F0(J,z+1);if($.trustworthy&&$.segments.some((X)=>W0(X)))return!0;return(S3(Z)??$.substitutions).some((X)=>F0(X,z+1))}function W3(Z,z){if(A3(Z,z))return"delete";let $=Z.words.filter((X,K)=>K>=z&&!Z.redirects.has(K)),J=$.map((X)=>f(X.text)),Y=J[0].split("/").pop();if(["rm","rmdir","shred"].includes(Y??""))return Z2(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 K=J[X++];if(["--help","-h","--version","-V","--identity"].includes(K))return"read";if(["--agent","--spool","--files","--info","--config"].includes(K))X++;else if(!["--json","--local"].includes(K))return"delete"}if(X===J.length||_6.has(J[X]))return"read";if(D6.has(J[X])&&Z2(J,X+1,!0))return"read";if(["restore","restore-capsule"].includes(J[X]))return"write";return"delete"}if(Y==="git"){let X=M3(Z,z);if(X==="clean"||X==="rm")return J[1]===X&&Z2(J,2,!0)?"read":"delete";return X==="clone"||X==="init"?"write":"read"}if(Y==="find"&&!$.some((X)=>Y2(X.text))&&!J.some((X)=>L3.has(X)))return"read";if(Y==="env"&&n(tZ(J)))return"delete";if(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env","xargs","find","busybox","toybox"].includes(Y??""))return TZ(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 C3.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 TZ(Z){let z=Z.replace(/[{},]/g," ");return z===Z?$2(Z):j0($2(Z),$2(z))}function $2(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(C3.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(P3(z)))return"write";return"read"}function $0(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 v.join(z,$.slice(2));if($==="$HOME"||$==="${HOME}")return z;if($.startsWith("$HOME/"))return v.join(z,$.slice(6));if($.startsWith("${HOME}/"))return v.join(z,$.slice(8));let Y=$.match(new RegExp(`^"*${J2(z)}"*/`));if(Y)return z+"/"+$.slice(Y[0].length);return Z}function C6(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 J2(Z){return Z.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function F3(Z,z,$){if(Z===void 0)return[$];let J=$0(Z,$),Y=J.match(/^(['"])(.*)\1$/);if(Y)J=Y[2];if(!J||J==="-"||/[$\x60*?[\]{}~\\'"]/.test(J))return null;return[...new Set(z.map((X)=>v.resolve(X,J)))]}var P6=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function O6(Z,z){let $=IZ(z);if(!$||$.index<=0||z[$.index].opaque)return 0;let J=w(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,K)=>k(X.text)!==z[K].text))return 0;return l(Y)===$.index?$.index:0}function L6(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 A6=new Set(["--agent","--spool","--files","--info","--config"]),y6=new Set(["--spool","--files","--info","--config"]),R6=new Set(["--json","--local","--help","-h","--version","--identity"]),N3={"--agent":/^[^-]/,"--retention":/^(?:\d+(?:\.\d+)?|never)$/},b6=new Set(["--to"]);function v6(Z){let z=[],$=0;for(;$<Z.length&&Z[$].text.startsWith("-");$++){let X=Z[$];if(X.opaque)return null;if(A6.has(X.text)){let K=Z[++$];if(!K||K.opaque)return null;if(y6.has(X.text))z.push(K)}else if(!R6.has(X.text))return null}let J=Z[$];if(!J||J.opaque||!O3.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 K=X.text.indexOf("="),B=K<0?X.text:X.text.slice(0,K);if(b6.has(B)){if(K>=0)z.push({text:X.text.slice(K+1),opaque:!1});else if(Z[$+1]&&!Z[$+1].text.startsWith("-"))z.push(Z[++$]);continue}let Q=Z[$+1];if(K<0&&Object.hasOwn(N3,B)&&Q&&!Q.opaque&&N3[B].test(Q.text))$++}return z}function S6(Z){let z=Z.split(`
|
|
29
|
+
`),$=[],J=[],Y=0;while(Y<z.length){let X=Y,K=z[Y++].replace(/\r$/,""),B=[];for(let Q=0;Q<K.length;Q++){let H=K[Q],M=J[J.length-1];if(H==="\\"){Q++;continue}if(H==="$"&&K[Q+1]==="("&&K[Q+2]==="("){let G=K.indexOf("))",Q+3);if(G<0)return null;Q=G+1;continue}if(H==="$"&&K[Q+1]==="("){J.push(0),Q++;continue}if(H==="$"&&K[Q+1]==="[")return null;if(H==="$"&&K[Q+1]==="{"){let G=K.indexOf("}",Q+2);if(G<0||/['"\x60$]|<</.test(K.slice(Q+2,G)))return null;Q=G;continue}if(H==="`"){let G=K.indexOf("`",Q+1);if(G<0)return null;Q=G;continue}if(M==='"'){if(H==='"')J.pop();continue}if(H==="'"){let G=K.indexOf("'",Q+1);if(G<0)return null;Q=G;continue}if(H==='"'){J.push('"');continue}if(H==="#"&&(Q===0||/[\s;&|()]/.test(K[Q-1])))break;if(H==="("&&K[Q+1]==="("&&(Q===0||/[\s;&|(]/.test(K[Q-1]))){let G=K.indexOf("))",Q+2);if(G<0)return null;Q=G+1;continue}if(typeof M==="number"&&(H==="("||H===")")){if(H==="(")J[J.length-1]=M+1;else if(M===0)J.pop();else J[J.length-1]=M-1;continue}if(H==="<"&&K[Q+1]==="<"){if(K[Q+2]==="<"){Q+=2;continue}let G=vZ(K,Q);if(!G)return null;B.push({marker:G,from:Q}),Q=G.end-1}}for(let{marker:Q,from:H}of B){let M=Y;for(;;){if(Y>=z.length)return null;let G=z[Y++].replace(/\r$/,"");if(Q.stripTabs)G=G.replace(/^\t+/,"");if(G===Q.delimiter)break}$.push({line:X,from:H,to:Q.end,start:M,end:Y-1,quoted:Q.quoted})}}return J.length===0?$:null}var E6=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"]),f6=new Set([".","source","eval","env","alias","hash"]),k6=new Set(["tee","cp","mv","install","ln"]),b3=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"]),x6=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),h6=new Set(["pr","issue","api","release","gist"]);function w6(Z,z){let $=Z[z];if($==="gh")return h6.has(Z[z+1]??"");if($!=="git")return b3.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("-")&&x6.has(Y)}return!1}function g6(Z,z){for(let $=z+1;$<Z.length;$++){let J=Z[$];if(J==="\\")$++;else if(J==='"')return $;else if(J==="$"&&Z[$+1]==="("){if($=v3(Z,$+1),$<0)return-1}else if(J==="`"){if($=Z.indexOf("`",$+1),$<0)return-1}}return-1}function v3(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=g6(Z,J),J<0)return-1}else if(Y==="(")$++;else if(Y===")"&&--$===0)return J}return-1}function S3(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=v3(Z,J+1);if(X<0)return null;let K=Z.slice(J+2,X);if(Z[J+2]==="("){if(/\$\(|\x60/.test(K))return null}else z.push(K);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 u6(Z){if(/[<>]\(/.test(Z))return!0;let z=[],$=[Z];for(let Y=0;$.length>0;Y++){if(Y>64)return!0;let X=$.shift(),K=w(X),B=S3(X);if(!K.trustworthy||!B)return!0;z.push(...K.segments),$.push(...new Set([...K.substitutions,...B]))}let J=new Set;for(let Y of z){let X=Y.words.map((Q)=>k(Q.text));for(let Q of Y.redirects)J.add($Z(X[Q]??""));let K=l(Y);if(K<0)continue;let B=$Z(X[K]);if(k6.has(B)){for(let Q of X.slice(K+1))if(!Q.startsWith("-"))J.add($Z(Q))}if(B==="dd"){for(let Q of X)if(Q.startsWith("of="))J.add($Z(Q.slice(3)))}}J.delete("");for(let Y of z){for(let H of Y.words){let M=$Z(k(H.text));if(E6.has(M)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(M))return!0}let X=l(Y),K=Y.words.map((H,M)=>({text:k(H.text),at:M})).filter(({at:H})=>!Y.redirects.has(H));if(K.some(({text:H,at:M})=>(X<0||M<X)&&iZ.test(H)))return!0;if(X<0)continue;let B=Y.words[X].text,Q=k(B);if(/[$\x60]/.test(B)||Q.includes("/")||f6.has(Q)||J.has(Q))return!0;if(!w6(K.filter(({at:H})=>H>=X).map(({text:H})=>H),0))return!0}return!1}function l6(Z){if(!Z.includes("<<"))return null;let z=S6(Z);if(!z||z.length===0)return null;let $=Z.split(`
|
|
30
|
+
`),J=[...$],Y=[];for(let K of z){let B=$.slice(K.start,K.end);if(!K.quoted&&B.some((Q)=>/\$\(|\x60/.test(Q)))return null;Y.push(B.join(`
|
|
31
|
+
`));for(let Q=K.start;Q<=K.end;Q++)J[Q]=""}let X=[...J];for(let K of[...z].reverse()){let B=X[K.line];X[K.line]=B.slice(0,K.from)+" ".repeat(K.to-K.from)+B.slice(K.to)}return u6(X.join(`
|
|
30
32
|
`))?null:{outer:J.join(`
|
|
31
|
-
`),bodies:Y}}var s5="/";function z0(Z,z,$){if(!Z)return[];let J=f(Z).trustworthy?Z:FZ(Z),Y=d5(Z);return[...J===Z?[]:z0(J,z,$),...Y?[...s2(Y.outer,z,$),...Y.bodies.flatMap((X)=>z0(X,z,s5))]:s2(Z,z,$)]}var n5=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,o5=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function c2(Z,z,$=!1){let J=[],Y=0;for(let B of z)J.push(Y),Y+=B.length;let X=f(Z);if(!X.trustworthy||!$&&X.substitutions.length>0)return null;let Q=X.segments.flatMap((B)=>B.words).filter((B)=>z.some((K,H)=>H%2===1&&J[H]<B.end&&J[H]+K.length>B.start));return Q.length>0?{lexed:X,offsets:J,words:Q}:null}function i2(Z,z,$=[]){if(h0(z)!=="read")return!1;let J=l(Z),Y=Z.words.filter((M,V)=>!Z.redirects.has(V)),X=KZ(Y.map((M)=>w0(M.text)));if(X===null)return!1;let Q=[J<0?1/0:J,X.index<0?1/0:Z.words.indexOf(Y[X.index])];if(Z.words.some((M,V)=>V<Math.max(...Q)&&!Z.redirects.has(V)&&EZ.test(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||J3.has(o(E(M)))))return!0;let K=Y.filter((M)=>!$.includes(M)),H=K.map((M)=>E(M.text));return MZ(K.map((M)=>M.text).join(" "))==="read"&&MZ(H.join(" "))==="read"&&!H.some((M)=>t2.has(M))}function a5(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)=>$0(X))}var d2=(Z,z)=>Z.slice(z.words[0].start,z.words[z.words.length-1].end);function r5(Z,z,$,J){let Y=(Q)=>Q.start<J&&Q.end>$,X=z.words.filter(Y);if(X.length===0||X.some((Q)=>!o5.test(Q.text)))return!1;for(let Q of z.lexed.segments.filter((B)=>B.words.some(Y)))if(!i2(Q,d2(Z,Q),z.words))return!1;for(let Q of X){let B=Q.text.slice(1,-1);if(B.includes("<<"))return!1;let K=f(B);if(!K.trustworthy||K.substitutions.length>0)return!1;if(!K.segments.every((H)=>i2(H,d2(B,H))))return!1}return!0}function s2(Z,z,$){if(!Z)return[];let J=n2(z),Y=(U)=>J.some((j)=>U===j||U.startsWith(`${j}${O.sep}`)),X=Z.split(n5),Q=c2(Z,X),B=Q??c2(Z,X,!0),K=[],H=[$],M=new Set([$]),V=!0,G=[];for(let U=0;U<X.length;U+=2){let j=U===0?"":X[U-1].trim();if(j==="||")V=!1;else if(j!=="&&")V=!0;if(j!=="&&"||!V)H=[...M];let F=X[U],y=(F.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,b=(F.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let D=0;D<y;D++)G.push({current:[...H],reachable:new Set(M),certain:V});let k=y5(F),d=Q!==null&&r5(Z,Q,Q.offsets[U],Q.offsets[U]+F.length),q=!d&&(B!==null&&a5(Z,B,B.offsets[U],B.offsets[U]+F.length)||J0(F.trim())),N=k.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),R=N?null:k.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(R){for(let D of m2(R[1],H,z)??[])M.add(D);V=!1,H=[...M]}let m=f0(z),p=J.map((D)=>f0(D.slice(z.length+1))).join("|"),CZ=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${m}"*)/(?:${p})`),Y2=new RegExp(`(${CZ.source})([^\\s"';&|<>()\`]*|$)`,"g"),X2=(D)=>{let g=[],c;Y2.lastIndex=0;while((c=Y2.exec(D))!==null)g.push(O.normalize(pZ(c[0],z)).replace(/\/+$/,""));return g},Q2=B===null?0:B.offsets[U],K2=(D)=>D.start<Q2+F.length&&D.end>Q2,P3=B!==null&&B.words.some(K2)?mZ({segments:B.lexed.segments.filter((D)=>D.words.some(K2))}):[F.trim(),k].flatMap((D)=>{let g=f(D);if(!g.trustworthy)g=f(FZ(D));return g.trustworthy?mZ(g):[]}),G0=P5(k).map((D,g)=>{let c=g===0?[...new Set(P3)]:[],PZ=!1,OZ=a2(D).replace(C5,(j0,UZ)=>{if(!UZ||/[$\x60]/.test(UZ))PZ=!0;if(UZ)c.push(UZ);return" "}),LZ=d?"read":q?"delete":h0(OZ);return{commandPart:OZ,operands:c,op:PZ&&LZ==="read"?"write":LZ}}),O3=G0.some((D)=>D.op==="delete")?"delete":G0.some((D)=>D.op==="write")?"write":"read",U0=H.filter(Y);if(q)for(let D of U0)K.push({path:D,op:"delete"});for(let D of G0){let g=!1;for(let u of X2(D.commandPart))g=!0,K.push({path:u,op:O3});for(let u of D.operands){let e=X2(u);for(let n of e)K.push({path:n,op:"write"});if(e.length>0)continue;for(let n of U0)K.push({path:O.normalize(O.resolve(n,pZ(u,z))),op:"write"})}if(g||D.op==="read")continue;let c=O5(D.commandPart),PZ=v5(D.commandPart,c),OZ=o(c[PZ]?.text??""),LZ=c.slice(PZ+1),j0=((OZ==="trash"?x5(LZ):null)??b5(OZ,LZ)).map((u)=>u.opaque?".":u.text),UZ=D.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(D.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(D.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(D.commandPart),AZ=[];if(UZ)for(let u of j0.length>0?j0:["."])AZ.push({operand:u,op:D.op});else{let u=D.commandPart.match(R5),e=c.at(-1);if(AZ.push({operand:u?u[1]:!e||e.opaque?".":e.text,op:D.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(D.commandPart))c.forEach((n,B2)=>{let jZ,W0=n.text.match(/^-[A-Za-z]*?t(.*)$/),iZ=n.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(W0&&!n.text.startsWith("--"))jZ=W0[1]?{text:W0[1],opaque:n.opaque}:c[B2+1];else if(iZ&&"--target-directory".startsWith(iZ[1]))jZ=iZ[2]!==void 0?{text:iZ[2],opaque:n.opaque}:c[B2+1];if(jZ)AZ.push({operand:jZ.opaque||!jZ.text?".":jZ.text,op:D.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(D.commandPart))AZ.push({operand:".",op:D.op})}for(let u of U0)for(let{operand:e,op:n}of AZ)K.push({path:O.normalize(O.resolve(u,pZ(e,z))),op:n})}if(N){let D=m2(N[1],H,z);if(D){for(let g of D)M.add(g);if(V)H=D}else V=!1}for(let D=0;D<b&&G.length>0;D++)({current:H,reachable:M,certain:V}=G.pop())}return K}var t5=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function e5(Z,z){let $=[],J;while((J=t5.exec(Z))!==null){let Y=J[1]==="Delete File"?"delete":"write";$.push({path:O.normalize(O.resolve(z,J[2])),op:Y})}return $}function X3(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??k0.homedir(),X=n2(Y),Q=T5(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=z0(G,Y,U);j.unshift(...BZ(G,()=>z0(G,Y,U))??[]);for(let F of j)for(let y of X){let b=b0(F.path,y,Q,F.op);if(b.blocked)return{output:{decision:"block",reason:b.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let B=Z.tool_input??{},K=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(j5.has(J)){let G=typeof B.patch==="string"?B.patch:"";if(!G)return{output:{continue:!0},warnings:$};let U=e5(G,K);for(let j of U)for(let F of X){let y=b0(j.path,F,Q,j.op);if(y.blocked)return{output:{decision:"block",reason:y.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!U5.has(J))return{output:{continue:!0},warnings:$};let H=typeof B.file_path==="string"?B.file_path:typeof B.path==="string"?B.path:typeof B.notebook_path==="string"?B.notebook_path:null;if(!H)return{output:{continue:!0},warnings:$};let M=pZ(H,Y),V=O.isAbsolute(M)?O.normalize(M):O.resolve(K,M);for(let G of X){let U=b0(V,G,Q,"write");if(U.blocked)return{output:{decision:"block",reason:U.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var Z6=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"]),$6=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),H3=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"]),M3=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"]),J6=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),z6=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class l0 extends Error{}var L=()=>{throw new l0};function g0(Z,z){let $=[],J="",Y=z+1;while(Y<Z.length){let X=Z[Y];if(X==='"'){if(J)$.push(J);return{end:Y+1,parts:$}}if(X==="\\"){let Q=Z[Y+1];if(Q==="("){let B=1,K=Y+2;while(K<Z.length&&B>0){let H=Z[K];if(H==='"'){K=g0(Z,K).end;continue}if(H==="(")B++;else if(H===")")B--;K++}if(B!==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 V3(Z){let z=[],$=0,J=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let Y=Z[$];if(/\s/.test(Y)){$++;continue}if(Y==="#")L();if(Y==='"'){let K=g0(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 H=g0(Z,$+1);if(H.parts.some((M)=>typeof M!=="string"))L();z.push({t:"field",name:H.parts.join("")}),$=H.end;continue}z.push({t:"dot"}),$++;continue}if(Y==="$"||Y==="@"){let K=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($));if(!K||Y==="$")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 B=J.find((K)=>Z.startsWith(K,$));if(!B)L();z.push({t:"op",v:B}),$+=B.length}return z}var Y6=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 m0{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(!z6.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(Y6.has(Z.name))L();if(Z.name==="map"||H3.has(Z.name)||M3.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 m0(V3($.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 p0(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(p0);return Z==="safe"||typeof Z==="object"&&Z6.has(Z.leaf)}var cZ=(...Z)=>Z.every(p0)?"safe":"tainted";function u0(...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 Y0(Z,z){return typeof Z==="object"&&"union"in Z?u0(...Z.union.map(z)):z(Z)}var X0=(Z)=>typeof Z==="object"&&("leaf"in Z)&&$6.has(Z.leaf),zZ=(Z)=>Y0(Z,(z)=>z==="safe"?"safe":z==="tainted"||X0(z)?"tainted":"unknown");function Q3(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 K3(Z,z,$){return Y0(Z,(J)=>{if(J==="safe"||J==="tainted")return J;if(X0(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 K3(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 K3(J,Z.key.text,$);if(Z.key.k==="lit")return zZ(J);return A(Z.key,z,$),"tainted"}case"slice":return Y0(A(Z.of,z,$),(J)=>J==="root"?"unknown":X0(J)?"tainted":J);case"opt":return A(Z.of,z,$);case"lit":return"safe";case"str":return cZ(...Z.parts.map((J)=>A(J,z,$)));case"fmt":return Z.str?A(Z.str,z,$):z;case"array":return Z.of?cZ(A(Z.of,z,$)):"safe";case"object":return cZ(...Z.entries.map((J)=>A(J.value,z,$)));case"pipe":return A(Z.b,A(Z.a,z,$),$);case"comma":return u0(A(Z.a,z,$),A(Z.b,z,$));case"alt":return u0(A(Z.a,z,$),A(Z.b,z,$));case"bool":return A(Z.a,z,$),A(Z.b,z,$),"safe";case"arith":return cZ(A(Z.a,z,$),A(Z.b,z,$));case"neg":return A(Z.of,z,$);case"call":return X6(Z,z,$)}}var B3=(Z)=>Y0(Z,(z)=>z==="root"?"unknown":X0(z)?"tainted":z);function X6(Z,z,$){let{name:J,args:Y}=Z;if(J6.has(J)&&J!=="limit"&&!Y.every(Q3))L();switch(J){case"map":if(Y.length!==1)L();return cZ(A(Y[0],zZ(z),$));case"select":if(Y.length!==1)L();return A(Y[0],z,$),z;case"limit":if(Y.length!==2||!Q3(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),$),B3(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(H3.has(J))return"safe";if(M3.has(J))return B3(z);return L()}function G3(Z,z={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new m0(V3(Z)).parse();return p0(A($,"root",{rootScalars:z.rootScalars??new Set}))}catch($){if($ instanceof l0)return!1;return!1}}var t0="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",T={refused:!1},I=(Z)=>({refused:!0,rule:Z}),c0=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"]),i0=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),U3=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),j3=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),Q6=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),K6=new Set(["author","committer","id","parents","repository","sha","url"]),B6=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function N3(Z){let z=[];for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="\\"){$++;continue}if(J==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return!1;$=Y;continue}if(J==='"'){$++;while($<Z.length&&Z[$]!=='"')$+=Z[$]==="\\"?2:1;continue}if(J==="{"){z.push({list:!1});continue}if(z.length===0)continue;if(J===","||J==="."&&Z[$+1]===".")z[z.length-1].list=!0;else if(J==="}"&&z.pop().list)return!0}return!1}function TZ(Z){let z="",$=!1,J=0,Y=(X)=>Z[X]==="`"||Z[X]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(Z[X+1]??"");while(J<Z.length){let X=Z[J];if(X==="\\"){z+=Z[J+1]??"",J+=2;continue}if(X==="$"&&Z[J+1]==="'"){$=!0,z+=X,J++;continue}if(X==="'"){let Q=Z.indexOf("'",J+1);if(Q<0){$=!0,z+=Z.slice(J+1);break}z+=Z.slice(J+1,Q),J=Q+1;continue}if(X==='"'){J++;while(J<Z.length&&Z[J]!=='"'){if(Z[J]==="\\"&&/[$`"\\\n]/.test(Z[J+1]??"")){z+=Z[J+1],J+=2;continue}if(Y(J))$=!0;z+=Z[J],J++}if(J>=Z.length)$=!0;J++;continue}if(Y(J)||X==="*"||X==="?"||X==="[")$=!0;z+=X,J++}if(!$&&Z.includes("{")&&N3(Z))$=!0;return{value:z,opaque:$,raw:Z}}var VZ=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function n0(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=HZ(Z,Y+1);if(Q<0)return{bodies:$,complete:!1};$.push(Z.slice(Y+2,Q-1)),Y=Q-1}}return{bodies:$,complete:!0}}function qZ(Z,z){let $=new Set(z.values),J={flags:[],positionals:[]},Y=(X,Q)=>({value:X,opaque:Q.opaque,raw:Q.raw});for(let X=0;X<Z.length;X++){let Q=Z[X],B=Q.value;if(B==="--"){J.positionals.push(...Z.slice(X+1));break}if(B.startsWith("--")&&B.length>2){let K=B.indexOf("="),H=K>=0?B.slice(0,K):B;if(K>=0)J.flags.push({name:H,value:Y(B.slice(K+1),Q),inline:!0});else if($.has(H)){let M=Z[X+1];J.flags.push(M?{name:H,value:M}:{name:H,missing:!0}),X++}else J.flags.push({name:H});continue}if(B.startsWith("-")&&B.length>1){for(let K=1;K<B.length;K++){let H="-"+B[K],M=B.slice(K+1);if(M.startsWith("=")){J.flags.push({name:H,value:Y(M.slice(1),Q),inline:!0});break}if(!$.has(H)){J.flags.push({name:H});continue}if(M)J.flags.push({name:H,value:Y(M,Q),inline:!0});else{let V=Z[X+1];J.flags.push(V?{name:H,value:V}:{name:H,missing:!0}),X++}break}continue}J.positionals.push(Q)}return J}function 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"]}},H6=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"]),M6=new Set(["pr","issue","release","discussion","search","project","api","status"]),V6=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),G6=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),U6=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),j6=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 e0(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&&G3(J.value.value,{rootScalars:z}))}function Z2(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 e0(Z)?T:I(J)}function Q0(Z,z,$,J,Y){let X=qZ(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 Z2(X,$,J,"json-composite")}function YZ(Z,z,$,J){let Y=qZ(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 Z2(Y,$,J,"json-composite")}function W6(Z,z){let $=qZ(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 Z2($,B6,z,"checks-json")}function F6(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 N6(Z,z,$){let{sub:J,rest:Y}=F6(z);if(!J)return $.appendsArgs?I("unclassifiable"):T;if(J.opaque)return I("unclassifiable");let X=J.value;if((Z==="pr"?V6:Z==="issue"?G6:Z==="release"?U6:Z==="discussion"?j6: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 Q0(Y,"pr view",c0,$,!0);if(X==="list"||X==="ls")return YZ(Y,"pr list",c0,$);if(X==="status")return YZ(Y,"pr status",c0,$);if(X==="checks")return W6(Y,$);if(X==="diff"){let B=qZ(Y,GZ["pr diff"]);if(w(B,"-h","--help"))return T;if($.debug)return I("debug-traffic");return w(B,"--patch")?I("composite-other"):T}return I("unclassifiable");case"issue":if(X==="view")return Q0(Y,"issue view",i0,$,!0);if(X==="list"||X==="ls")return YZ(Y,"issue list",i0,$);if(X==="status")return YZ(Y,"issue status",i0,$);return I("unclassifiable");case"release":if(X==="view")return Q0(Y,"release view",U3,$,!1);if(X==="list"||X==="ls")return YZ(Y,"release list",U3,$);return I("unclassifiable");case"discussion":if(X==="view")return Q0(Y,"discussion view",j3,$,!0);if(X==="list"||X==="ls")return YZ(Y,"discussion list",j3,$);return I("unclassifiable");case"search":if(X==="prs"||X==="issues")return YZ(Y,"search",Q6,$);if(X==="commits")return YZ(Y,"search",K6,$);if(X==="code"||X==="repos")return $.debug?I("debug-traffic"):T;return I("unclassifiable");case"project":{if($.debug)return I("debug-traffic");if(X!=="item-list")return T;let B=qZ(Y,GZ["project item-list"]);if(w(B,"-h","--help"))return T;let K=XZ(B,"--format");if(K.some((H)=>!H.value||H.value.opaque))return I("unclassifiable");if(K.every((H)=>H.value.value!=="json"))return T;return e0(B)?T:I("composite-other")}}return I("unclassifiable")}var D3=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function D6(Z){let z=Z.value.trim(),$=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(z);if($){let X=$[1].toLowerCase(),Q=$[2]??"/";if(X==="api.github.com"||/^api\./.test(X))z=Q;else if(/^\/api\/v3(?:\/|$)/i.test(Q))z=Q.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(Q))z="graphql";else return null}z=z.replace(/[?#].*$/,"");let J=[],Y=[];for(let X of z.split("/")){let Q;try{Q=decodeURIComponent(X)}catch{return null}for(let B of Q.split("/")){if(B===""||B===".")continue;if(B===".."){J.pop(),Y.pop();continue}J.push(B.toLowerCase()),Y.push(Z.opaque&&/[$`]/.test(B)||/[*?[]/.test(B)||N3(B))}}return{segments:J,opaque:Y}}function _6(Z){let z=D6(Z);if(!z)return{kind:"unclassifiable",segments:[]};let{segments:$,opaque:J}=z,Y=(K)=>({kind:K,segments:$});if($.length===1&&$[0]==="graphql")return Y("graphql");if($.length===0)return Y(Z.opaque?"unclassifiable":"other");if(J[0])return Y("unclassifiable");let X,Q=[];if($[0]==="repos")X=$.slice(3),Q=J.slice(3);else if($[0]==="repositories")X=$.slice(2),Q=J.slice(2);if(X){if(($[0]==="repos"?J.slice(1,3):J.slice(1,2)).some(Boolean)){let H=J.findIndex(Boolean),M=$.findIndex((V,G)=>G>H&&!J[G]&&I6.has(V));return Y(M<0?"unclassifiable":W3($.slice(M),J.slice(M)))}return Y(W3(X,Q))}let B=$[0];if(B==="issues")return Y("sensitive");if(B==="user"&&$[1]==="issues")return Y("sensitive");if(B==="orgs"&&$[2]==="issues")return Y("sensitive");if(B==="search")return Y($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&J[1]?"unclassifiable":"other");if(B==="events"||B==="networks")return Y("sensitive");if((B==="users"||B==="orgs")&&$.slice(2).some((K)=>K==="events"||K==="received_events"||K==="discussions"))return Y("sensitive");if((B==="users"||B==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return Y("sensitive");if(B==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||B==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return Y("sensitive");if(B==="teams"&&$.includes("discussions"))return Y("sensitive");if(B==="projects"&&$.includes("cards"))return Y("sensitive");if(J.some(Boolean))return Y($.some((K)=>K==="events"||K==="discussions"||K==="issues")?"sensitive":"unclassifiable");return Y("other")}var I6=new Set([...D3,"branches","git","actions","hooks","zipball","tarball"]);function W3(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(D3.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 T6(Z,z){if(z[0]!=="repos"||z.length<5)return!1;let $=z.slice(3),J=(X)=>/^\d+$/.test($[X]??""),Y=(...X)=>$.length===X.length&&X.every((Q,B)=>typeof Q==="number"?J(B):$[B]===Q);if(Z==="DELETE")return Y("issues","comments",0)||Y("pulls","comments",0)||Y("comments",0)||Y("issues","comments",0,"reactions",0)||Y("pulls","comments",0,"reactions",0)||Y("issues",0,"reactions",0)||Y("issues",0,"labels")||$.length===4&&$[0]==="issues"&&J(1)&&$[2]==="labels"||Y("releases",0)||Y("releases","assets",0)||Y("actions","runs",0)||Y("actions","runs",0,"logs")||Y("deployments",0)||Y("milestones",0)||Y("issues",0,"lock");if(Z==="POST")return $.length===4&&$[0]==="actions"&&$[1]==="runs"&&J(2)&&["rerun","rerun-failed-jobs","cancel","force-cancel","approve"].includes($[3])||Y("actions","jobs",0,"rerun")||Y("issues",0,"labels");if(Z==="PUT")return Y("pulls",0,"merge")||Y("pulls",0,"update-branch")||Y("issues",0,"labels")||Y("issues",0,"lock");if(Z==="GET")return Y("pulls",0,"merge");return!1}function q6(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 C6=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"]),P6=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function O6(Z){let z=[],$=0;while($<Z.length){let J=Z[$];if(/[\s,]/.test(J)){$++;continue}if(J==="#"){let Q=Z.indexOf(`
|
|
32
|
-
`,$);$=
|
|
33
|
-
`)
|
|
34
|
-
`).replace(/%s/g,()=>B[
|
|
35
|
-
`,
|
|
36
|
-
`,J)+1,
|
|
37
|
-
`,J);if(
|
|
33
|
+
`),bodies:Y}}var p6="/";function N0(Z,z,$){if(!Z)return[];let J=w(Z).trustworthy?Z:KZ(Z),Y=l6(Z);return[...J===Z?[]:N0(J,z,$),...Y?[..._3(Y.outer,z,$),...Y.bodies.flatMap((X)=>N0(X,z,p6))]:_3(Z,z,$)]}var m6=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,c6=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function q3(Z,z,$=!1){let J=[],Y=0;for(let B of z)J.push(Y),Y+=B.length;let X=w(Z);if(!X.trustworthy||!$&&X.substitutions.length>0)return null;let K=X.segments.flatMap((B)=>B.words).filter((B)=>z.some((Q,H)=>H%2===1&&J[H]<B.end&&J[H]+Q.length>B.start));return K.length>0?{lexed:X,offsets:J,words:K}:null}function I3(Z,z,$=[]){if(X2(z)!=="read")return!1;let J=l(Z),Y=Z.words.filter((M,G)=>!Z.redirects.has(G)),X=IZ(Y.map((M)=>K2(M.text)));if(X===null)return!1;let K=[J<0?1/0:J,X.index<0?1/0:Z.words.indexOf(Y[X.index])];if(Z.words.some((M,G)=>G<Math.max(...K)&&!Z.redirects.has(G)&&iZ.test(k(M.text))))return!1;if([J<0?null:Z.words[J].text,X.index<0?null:Y[X.index].text].every((M)=>M===null||b3.has($Z(k(M)))))return!0;let Q=Y.filter((M)=>!$.includes(M)),H=Q.map((M)=>k(M.text));return TZ(Q.map((M)=>M.text).join(" "))==="read"&&TZ(H.join(" "))==="read"&&!H.some((M)=>L3.has(M))}function i6(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)=>W0(X))}var T3=(Z,z)=>Z.slice(z.words[0].start,z.words[z.words.length-1].end);function d6(Z,z,$,J){let Y=(K)=>K.start<J&&K.end>$,X=z.words.filter(Y);if(X.length===0||X.some((K)=>!c6.test(K.text)))return!1;for(let K of z.lexed.segments.filter((B)=>B.words.some(Y)))if(!I3(K,T3(Z,K),z.words))return!1;for(let K of X){let B=K.text.slice(1,-1);if(B.includes("<<"))return!1;let Q=w(B);if(!Q.trustworthy||Q.substitutions.length>0)return!1;if(!Q.segments.every((H)=>I3(H,T3(B,H))))return!1}return!0}function _3(Z,z,$){if(!Z)return[];let J=D3(z),Y=(V)=>J.some((j)=>V===j||V.startsWith(`${j}${v.sep}`)),X=Z.split(m6),K=q3(Z,X),B=K??q3(Z,X,!0),Q=[],H=[$],M=new Set([$]),G=!0,U=[];for(let V=0;V<X.length;V+=2){let j=V===0?"":X[V-1].trim();if(j==="||")G=!1;else if(j!=="&&")G=!0;if(j!=="&&"||!G)H=[...M];let W=X[V],_=(W.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,L=(W.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let T=0;T<_;T++)U.push({current:[...H],reachable:new Set(M),certain:G});let x=C6(W),g=K!==null&&d6(Z,K,K.offsets[V],K.offsets[V]+W.length),y=!g&&(B!==null&&i6(Z,B,B.offsets[V],B.offsets[V]+W.length)||F0(W.trim())),O=x.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),q=O?null:x.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(q){for(let T of F3(q[1],H,z)??[])M.add(T);G=!1,H=[...M]}let F=J2(z),R=J.map((T)=>J2(T.slice(z.length+1))).join("|"),e=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${F}"*)/(?:${R})`),o=new RegExp(`(${e.source})([^\\s"';&|<>()\`]*|$)`,"g"),ZZ=(T)=>{let c=[],d;o.lastIndex=0;while((d=o.exec(T))!==null)c.push(v.normalize($0(d[0],z)).replace(/\/+$/,""));return c},y2=B===null?0:B.offsets[V],R2=(T)=>T.start<y2+W.length&&T.end>y2,H4=B!==null&&B.words.some(R2)?Z0({segments:B.lexed.segments.filter((T)=>T.words.some(R2))}):[W.trim(),x].flatMap((T)=>{let c=w(T);if(!c.trustworthy)c=w(KZ(T));return c.trustworthy?Z0(c):[]}),A0=I6(x).map((T,c)=>{let d=c===0?[...new Set(H4)]:[],xZ=!1,hZ=P3(T).replace(q6,(R0,CZ)=>{if(!CZ||/[$\x60]/.test(CZ))xZ=!0;if(CZ)d.push(CZ);return" "}),wZ=g?"read":y?"delete":X2(hZ);return{commandPart:hZ,operands:d,op:xZ&&wZ==="read"?"write":wZ}}),M4=A0.some((T)=>T.op==="delete")?"delete":A0.some((T)=>T.op==="write")?"write":"read",y0=H.filter(Y);if(y)for(let T of y0)Q.push({path:T,op:"delete"});for(let T of A0){let c=!1;for(let i of ZZ(T.commandPart))c=!0,Q.push({path:i,op:M4});for(let i of T.operands){let MZ=ZZ(i);for(let t of MZ)Q.push({path:t,op:"write"});if(MZ.length>0)continue;for(let t of y0)Q.push({path:v.normalize(v.resolve(t,$0(i,z))),op:"write"})}if(c||T.op==="read")continue;let d=T6(T.commandPart),xZ=O6(T.commandPart,d),hZ=$Z(d[xZ]?.text??""),wZ=d.slice(xZ+1),R0=((hZ==="trash"?v6(wZ):null)??L6(hZ,wZ)).map((i)=>i.opaque?".":i.text),CZ=T.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(T.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(T.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(T.commandPart),gZ=[];if(CZ)for(let i of R0.length>0?R0:["."])gZ.push({operand:i,op:T.op});else{let i=T.commandPart.match(P6),MZ=d.at(-1);if(gZ.push({operand:i?i[1]:!MZ||MZ.opaque?".":MZ.text,op:T.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(T.commandPart))d.forEach((t,b2)=>{let PZ,b0=t.text.match(/^-[A-Za-z]*?t(.*)$/),Y0=t.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(b0&&!t.text.startsWith("--"))PZ=b0[1]?{text:b0[1],opaque:t.opaque}:d[b2+1];else if(Y0&&"--target-directory".startsWith(Y0[1]))PZ=Y0[2]!==void 0?{text:Y0[2],opaque:t.opaque}:d[b2+1];if(PZ)gZ.push({operand:PZ.opaque||!PZ.text?".":PZ.text,op:T.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(T.commandPart))gZ.push({operand:".",op:T.op})}for(let i of y0)for(let{operand:MZ,op:t}of gZ)Q.push({path:v.normalize(v.resolve(i,$0(MZ,z))),op:t})}if(O){let T=F3(O[1],H,z);if(T){for(let c of T)M.add(c);if(G)H=T}else G=!1}for(let T=0;T<L&&U.length>0;T++)({current:H,reachable:M,certain:G}=U.pop())}return Q}var s6=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function n6(Z,z){let $=[],J;while((J=s6.exec(Z))!==null){let Y=J[1]==="Delete File"?"delete":"write";$.push({path:v.normalize(v.resolve(z,J[2])),op:Y})}return $}function E3(Z,z={}){let $=[];if(Z.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:$};let J=typeof Z.tool_name==="string"?Z.tool_name:"",Y=z.home??z2.homedir(),X=D3(Y),K=F6(process.env,Y);if(J==="Bash"){let U=zZ(Z);if(!U)return{output:{continue:!0},warnings:$};let V=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd(),j=N0(U,Y,V);j.unshift(...XZ(U,()=>N0(U,Y,V))??[]);for(let W of j)for(let _ of X){let L=e0(W.path,_,K,W.op);if(L.blocked)return{output:{decision:"block",reason:L.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let B=Z.tool_input??{},Q=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(H6.has(J)){let U=typeof B.patch==="string"?B.patch:"";if(!U)return{output:{continue:!0},warnings:$};let V=n6(U,Q);for(let j of V)for(let W of X){let _=e0(j.path,W,K,j.op);if(_.blocked)return{output:{decision:"block",reason:_.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!B6.has(J))return{output:{continue:!0},warnings:$};let H=typeof B.file_path==="string"?B.file_path:typeof B.path==="string"?B.path:typeof B.notebook_path==="string"?B.notebook_path:null;if(!H)return{output:{continue:!0},warnings:$};let M=$0(H,Y),G=v.isAbsolute(M)?v.normalize(M):v.resolve(Q,M);for(let U of X){let V=e0(G,U,K,"write");if(V.blocked)return{output:{decision:"block",reason:V.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var EZ=require("node:fs");var I=require("node:path");var o6="protected-delete-guard",h3=(Z)=>EZ.readdirSync(Z),w3=(Z)=>EZ.realpathSync(Z),g3=(Z)=>EZ.lstatSync(Z,{throwIfNoEntry:!1})!==void 0,a6=/^(?:history\.jsonl|session_index\.jsonl|(?:state|thread_history)_\d+\.sqlite(?:-shm|-wal)?)$/;function r6(Z,z,$=h3){let J=(H)=>z[H]?[I.resolve(z[H])]:[],Y=(H,M)=>z[H]?I.resolve(z[H]):I.join(Z,M),X=Y("XDG_DATA_HOME",".local/share"),K=Y("XDG_STATE_HOME",".local/state"),B=Y("XDG_CONFIG_HOME",".config"),Q=[];for(let H of[I.join(Z,".claude"),I.join(Z,".claude.json"),...J("CLAUDE_CONFIG_DIR")])Q.push({tool:"Claude Code",path:H});for(let H of[I.join(Z,".codex"),...J("CODEX_HOME")]){for(let G of["sessions","archived_sessions"])Q.push({tool:"Codex",path:I.join(H,G)});let M=[];try{M=$(H)}catch(G){let U=G?.code;if(U!=="ENOENT"&&U!=="ENOTDIR")Q.push({tool:"Codex",path:H})}for(let G of M)if(a6.test(G))Q.push({tool:"Codex",path:I.join(H,G)})}for(let[H,M]of[["opencode","OpenCode"],["sumi","Sumi"],["devin","Devin"]])for(let G of[X,K])Q.push({tool:M,path:I.join(G,H)});for(let H of[I.join(Z,".cursor"),I.join(Z,"Library","Application Support","Cursor"),I.join(B,"Cursor")])Q.push({tool:"Cursor",path:H});for(let H of[I.resolve(z.DSH_HOME??I.join(Z,".dsh")),I.join(Z,".dsh-tui"),...J("DSH_TUI_SESSION_ROOT")])Q.push({tool:"DSH",path:H});Q.push({tool:"antigravity",path:I.join(Z,".gemini","antigravity-cli")}),Q.push({tool:"Cline",path:I.join(Z,".cline")});for(let H of[I.join(Z,".gemini","tmp"),I.join(Z,".gemini","history")])Q.push({tool:"Gemini CLI",path:H});Q.push({tool:"Qwen Code",path:I.join(Z,".qwen")}),Q.push({tool:"GitHub Copilot CLI",path:I.join(Z,".copilot")}),Q.push({tool:"Codewith",path:I.join(Z,".codewith")});for(let H of(z.HASNA_TRASH_SESSION_ROOTS??"").split(I.delimiter).filter(Boolean))Q.push({tool:"configured coding-agent",path:I.resolve(H)});return Q}function Q2(Z,z=w3){let $=[];for(let J=Z;;J=I.dirname(J))try{return I.join(z(J),...$)}catch{if(I.dirname(J)===J)return Z;$.unshift(I.basename(J))}}function SZ(Z,z){return z==="darwin"||z==="win32"?Z.normalize("NFC").toLowerCase():Z}function f3(Z,z,$){let J=SZ(Z,$),Y=SZ(z,$);return J===Y||J.startsWith(Y.endsWith(I.sep)?Y:`${Y}${I.sep}`)}function t6(Z,z,$=process.platform){for(let J of z)for(let Y of Z)if(f3(J,Y.path,$)||f3(Y.path,J,$))return Y;return null}function e6(Z,z,$=g3){let J=I.join(z,".hasna","repos","worktrees");if(!Z.startsWith(`${J}${I.sep}`))return!1;let Y=Z.slice(J.length+1).split(I.sep);if(Y.some((X)=>X===""||X==="."||X===".."))return!1;return[2,3].some((X)=>Y.length>X&&$(I.join(J,...Y.slice(0,X),".git")))}function B2(Z){return Z.replace(/\$\{HOME(?::?[-?=][^}]*|%%?\/)\}/g,"${HOME}")}function k3(Z,z,$){let J=B2(k(Z));if(!/^\$(?:HOME|\{HOME\})\//.test(J))return WZ(Z,z,$);let Y=U0(J,$);if(Y===J||/[$`*?[\]]/.test(Y))return null;let X=I.resolve(Y).replace(/\/+$/,"");return X===""?I.sep:X}function q0(Z){return`'${Z.replace(/[\u0000-\u001f\u007f-\u009f]/g,"?").slice(0,512).replace(/'/g,"'\\''")}'`}function u3(Z){let z=Z.platform??process.platform,$=Z.realpath??w3,{home:J}=Z,Y=null,X=()=>{if(Y===null)Y=r6(J,Z.env??{},Z.list??h3).flatMap((U)=>{let V=Q2(U.path,$);return V===U.path?[U]:[U,{...U,path:V}]});return Y},K=(G)=>{if(z!=="darwin"&&z!=="win32")return[];let U=[];for(let V of[J,...mZ.filter((j)=>j!==I.sep)]){let j=G.slice(0,V.length),W=G.slice(V.length);if(SZ(j,z)!==SZ(V,z)||W!==""&&!W.startsWith(I.sep))continue;let _=V===J?`${J}${SZ(W,z)}`:`${V}${W}`;if(_!==G)U.push(_)}return U},B=(G)=>{let U=I.join(Q2(I.dirname(G),$),I.basename(G)),V=U===G?[G]:[G,U];for(let _ of[...V,...V.flatMap(K)]){if(e6(_,J,Z.exists??g3))continue;let L=a0(_,J);if(L)return L}let j=Q2(G,$),W=t6(X(),V.includes(j)?V:[...V,j],z);if(W)return`${q0(G)} is, contains or lies inside ${W.tool} session history (${q0(W.path)}). Coding-agent sessions and their history are never deleted, including inactive and archived ones, because agents need them to resume.`;return null},Q=(G,U)=>{let V=B2(k(G));if(!V||V.includes("`")||!/[*?[]/.test(V))return;if(V.replace(/\$\{HOME\}/g,"").replace(/\$HOME/g,"").includes("$"))return;let j=V.startsWith("~")||V.startsWith("$")?U0(V,J):V;if(j.startsWith("~")||j.startsWith("$"))return;let W=(I.isAbsolute(j)?I.resolve(j):I.resolve(U,j)).split(I.sep).filter(Boolean),_=W.findIndex((F)=>/[*?[]/.test(F));if(_<0)return;let L=(F)=>F,x=(F,R=L)=>{let e=F.split(I.sep).filter(Boolean);return W.length<=e.length&&W.every((o,ZZ)=>S0(R(o),R(e[ZZ])))},g=(F,R=L)=>{let e=F.split(I.sep).filter(Boolean);return W.length>e.length&&e.every((o,ZZ)=>S0(R(W[ZZ]),R(o)))},y=(F)=>`The pattern ${q0(V)} can name ${F}, which is never deleted. Write the delete out as plain paths.`,O=(F)=>SZ(F,z);for(let F of mZ)if(F!==I.sep&&x(F,O))return y(`the system root \`${F}\``);if(x(J,O))return y("the home directory");for(let F of[".ssh",".aws"]){let R=I.join(J,F);if(x(R,O)||g(R,O))return y(`\`~/${F}\` or a path inside it`)}let q=I.join(J,".hasna");if(x(q,O))return y("`~/.hasna`");if(g(q,O)){let F=q.split(I.sep).filter(Boolean).length,R=`${I.sep}${W.map((o)=>/[*?[]/.test(o)?"x":o).join(I.sep)}`;if((_>=F?B(R):"a pattern")!==null)return y("a path inside `~/.hasna` outside worktree and scratch content")}for(let F of X())if(x(F.path,O)||g(F.path,O))return y(`${F.tool} session history (${q0(F.path)})`);return null};return{path:B,pattern:Q,operand:(G,U)=>{let V=G.includes("{")?JZ(G):[];if(V===null)return"This delete's brace pattern names more paths than this guard will check. Write the delete out as plain paths.";for(let j of[G,...V]){let W=k3(j,U,J),_=W!==null?B(W):Q(j,U);if(_)return _}return null},expands:(G,U)=>[G,...(G.includes("{")?JZ(G):[])??[]].some((V)=>k3(V,U,J)===null&&Q(V,U)===void 0)}}var Z7="`find` with a delete action (`-delete`, or `-exec` running a delete) removes whatever its walk matches, which this guard cannot read before it runs. List the paths first (`find … -print`), then remove them with `rm -- <path>`.";function I0(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:`[${o6}] ${Z}`}}}function l3(Z,z,$){for(let J of new Set(Z.split(/[\s;|&()<>"'`=]+/))){if(!J||J.startsWith("-")||!/^(?:[/~.]|\$HOME|\$\{HOME\})|\//.test(J))continue;let Y=$.operand(J,z);if(Y)return Y}return null}function x3(Z,z,$){let J=[],Y=HZ(Z,{cwd:z.cwd,home:z.home,observe:(Q)=>J.push(Q)}),X=!1;for(let Q of J){if(Q.verb==="find")continue;for(let H of Q.operands){let M=$.operand(H,Q.cwd);if(M)return M;X||=$.expands(H,Q.cwd)}}if(J.some((Q)=>Q.verb==="find"))return Z7;if(!(X||Y.refusals.some((Q)=>!$3.has(Q.reason))||!Y.trustworthy&&(Y.rmHits.length>0||Y.handoffHits.length>0||n(Z)||yZ(Z))))return null;let B=l3(Z,z.cwd,$);return B===null?null:`This command runs a delete this guard cannot read exactly (an operand the shell expands, a shell string, a launcher, an expansion in command position or an unclosed quote), and it names a protected path: ${B} Run the delete as a plain \`rm -- <path>\` command on its own.`}var $7=["apply_patch","ApplyPatch","functions.apply_patch"];function J7(Z,z,$){for(let J of Z.matchAll(/^\s*\*\*\* Delete File:[ \t]*(.*)$/gm)){let Y=J[1].trim();if(!Y)continue;let X=I.isAbsolute(Y)?I.resolve(Y):I.resolve(z.cwd,Y.startsWith("~/")?I.join(z.home,Y.slice(2)):Y),K=$.path(X);if(K)return`Delete File is refused: ${K}`}return null}function z7(Z,z){if(Z.hook_event_name!=="PreToolUse")return{continue:!0};let $=u3(z);if($7.includes(Z.tool_name??"")){let X=Z.tool_input?.command??Z.tool_input?.patch;if(typeof X!=="string")return{continue:!0};let K=J7(X,z,$);return K===null?{continue:!0}:I0(K)}if(Z.tool_name!=="Bash")return{continue:!0};let J=zZ(Z);if(!J.trim())return{continue:!0};let Y=/^[A-Za-z0-9._/-]+$/.test(z.home)?B2(J).replace(/\$\{HOME\}|\$HOME(?![A-Za-z0-9_])/g,z.home):J;for(let X of Y===J?[J]:[J,Y]){let K=x3(X,z,$)??XZ(X,()=>x3(X,z,$))??null;if(K!==null)return I0(K)}return{continue:!0}}function Y7(Z,z){let $=zZ(Z);if(!(n($)||yZ($)||/^\s*\*\*\* Delete File:/m.test($)))return{continue:!0};let J="The guard failed while reading this command, so it cannot show that the delete in it spares the protected paths.";try{return l3($,z.cwd,u3(z))===null?{continue:!0}:I0(`${J} Run the delete as a plain \`rm -- <path>\` command on its own.`)}catch{return I0(`${J} Report it, and run the delete as a plain \`rm -- <path>\` command on its own.`)}}function p3(Z,z){try{return z7(Z,z)}catch{return Y7(Z,z)}}var X7=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"]),K7=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),d3=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"]),s3=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"]),Q7=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),B7=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class G2 extends Error{}var S=()=>{throw new G2};function H2(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 K=Z[Y+1];if(K==="("){let B=1,Q=Y+2;while(Q<Z.length&&B>0){let H=Z[Q];if(H==='"'){Q=H2(Z,Q).end;continue}if(H==="(")B++;else if(H===")")B--;Q++}if(B!==0)S();if(J)$.push(J),J="";$.push({src:Z.slice(Y+2,Q-1)}),Y=Q;continue}if(K===void 0)S();J+=K,Y+=2;continue}J+=X,Y++}return S()}function n3(Z){let z=[],$=0,J=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let Y=Z[$];if(/\s/.test(Y)){$++;continue}if(Y==="#")S();if(Y==='"'){let Q=H2(Z,$);z.push({t:"str",parts:Q.parts}),$=Q.end;continue}if(Y==="."){if(Z[$+1]===".")S();let Q=/^[A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($+1));if(Q){z.push({t:"field",name:Q[0]}),$+=1+Q[0].length;continue}if(Z[$+1]==='"'){let H=H2(Z,$+1);if(H.parts.some((M)=>typeof M!=="string"))S();z.push({t:"field",name:H.parts.join("")}),$=H.end;continue}z.push({t:"dot"}),$++;continue}if(Y==="$"||Y==="@"){let Q=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($));if(!Q||Y==="$")S();z.push({t:"fmt",name:Q[0]}),$+=Q[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 K=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(Z.slice($));if(K){z.push({t:"ident",name:K[0]}),$+=K[0].length;continue}let B=J.find((Q)=>Z.startsWith(Q,$));if(!B)S();z.push({t:"op",v:B}),$+=B.length}return z}var H7=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 V2{tokens;at=0;constructor(Z){this.tokens=Z}parse(){if(this.tokens.length===0)S();let Z=this.pipe();if(this.at!==this.tokens.length)S();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))S();this.at++}pipe(){let Z=this.comma();if(this.isIdent("as"))S();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))S();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 S();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(!B7.has(Z.name))S();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(H7.has(Z.name))S();if(Z.name==="map"||d3.has(Z.name)||s3.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 S()}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 S()}}return S()}stringNode(Z){let z=[];for(let $ of Z){if(typeof $==="string")continue;z.push(new V2(n3($.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)S();this.at++;let $;if(z.t==="ident")$=z.name;else if(z.t==="str"){if(z.parts.some((J)=>typeof J!=="string"))S();$=z.parts.join("")}else S();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 U2(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(U2);return Z==="safe"||typeof Z==="object"&&X7.has(Z.leaf)}var J0=(...Z)=>Z.every(U2)?"safe":"tainted";function M2(...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 T0(Z,z){return typeof Z==="object"&&"union"in Z?M2(...Z.union.map(z)):z(Z)}var _0=(Z)=>typeof Z==="object"&&("leaf"in Z)&&K7.has(Z.leaf),FZ=(Z)=>T0(Z,(z)=>z==="safe"?"safe":z==="tainted"||_0(z)?"tainted":"unknown");function m3(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 c3(Z,z,$){return T0(Z,(J)=>{if(J==="safe"||J==="tainted")return J;if(_0(J))return"tainted";if(J==="root"&&$.rootScalars.has(z))return"safe";return{leaf:z}})}function E(Z,z,$){switch(Z.k){case"dot":return z;case"field":return c3(Z.of?E(Z.of,z,$):z,Z.name,$);case"iter":return FZ(E(Z.of,z,$));case"index":{let J=E(Z.of,z,$);if(Z.key.k==="str"&&Z.key.text!==void 0)return c3(J,Z.key.text,$);if(Z.key.k==="lit")return FZ(J);return E(Z.key,z,$),"tainted"}case"slice":return T0(E(Z.of,z,$),(J)=>J==="root"?"unknown":_0(J)?"tainted":J);case"opt":return E(Z.of,z,$);case"lit":return"safe";case"str":return J0(...Z.parts.map((J)=>E(J,z,$)));case"fmt":return Z.str?E(Z.str,z,$):z;case"array":return Z.of?J0(E(Z.of,z,$)):"safe";case"object":return J0(...Z.entries.map((J)=>E(J.value,z,$)));case"pipe":return E(Z.b,E(Z.a,z,$),$);case"comma":return M2(E(Z.a,z,$),E(Z.b,z,$));case"alt":return M2(E(Z.a,z,$),E(Z.b,z,$));case"bool":return E(Z.a,z,$),E(Z.b,z,$),"safe";case"arith":return J0(E(Z.a,z,$),E(Z.b,z,$));case"neg":return E(Z.of,z,$);case"call":return M7(Z,z,$)}}var i3=(Z)=>T0(Z,(z)=>z==="root"?"unknown":_0(z)?"tainted":z);function M7(Z,z,$){let{name:J,args:Y}=Z;if(Q7.has(J)&&J!=="limit"&&!Y.every(m3))S();switch(J){case"map":if(Y.length!==1)S();return J0(E(Y[0],FZ(z),$));case"select":if(Y.length!==1)S();return E(Y[0],z,$),z;case"limit":if(Y.length!==2||!m3(Y[0]))S();return E(Y[1],z,$);case"first":case"last":if(Y.length>1)S();return Y.length===1?E(Y[0],z,$):FZ(z);case"min":case"max":return FZ(z);case"sort_by":case"group_by":case"unique_by":if(Y.length!==1)S();return E(Y[0],FZ(z),$),i3(z);case"min_by":case"max_by":if(Y.length!==1)S();return E(Y[0],FZ(z),$),FZ(z);case"any":case"all":case"isempty":for(let X of Y)E(X,"unknown",$);return"safe"}if(d3.has(J))return"safe";if(s3.has(J))return i3(z);return S()}function o3(Z,z={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new V2(n3(Z)).parse();return U2(E($,"root",{rootScalars:z.rootScalars??new Set}))}catch($){if($ instanceof G2)return!1;return!1}}var D2="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",C={refused:!1},P=(Z)=>({refused:!0,rule:Z}),j2=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"]),W2=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),a3=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),r3=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),G7=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),V7=new Set(["author","committer","id","parents","repository","sha","url"]),U7=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function J4(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 fZ(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 K=Z.indexOf("'",J+1);if(K<0){$=!0,z+=Z.slice(J+1);break}z+=Z.slice(J+1,K),J=K+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("{")&&J4(Z))$=!0;return{value:z,opaque:$,raw:Z}}var _Z=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function q2(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 K=Z.indexOf("'",Y+1);if(K<0)return{bodies:$,complete:!1};Y=K;continue}if(z==="word"&&X==='"'){J=!J;continue}if(X==="`"){let K=Y+1;while(K<Z.length&&Z[K]!=="`")K+=Z[K]==="\\"?2:1;if(K>=Z.length)return{bodies:$,complete:!1};$.push(Z.slice(Y+1,K)),Y=K;continue}if(X==="$"&&Z[Y+1]==="("){let K=BZ(Z,Y+1);if(K<0)return{bodies:$,complete:!1};$.push(Z.slice(Y+2,K-1)),Y=K-1}}return{bodies:$,complete:!0}}function kZ(Z,z){let $=new Set(z.values),J={flags:[],positionals:[]},Y=(X,K)=>({value:X,opaque:K.opaque,raw:K.raw});for(let X=0;X<Z.length;X++){let K=Z[X],B=K.value;if(B==="--"){J.positionals.push(...Z.slice(X+1));break}if(B.startsWith("--")&&B.length>2){let Q=B.indexOf("="),H=Q>=0?B.slice(0,Q):B;if(Q>=0)J.flags.push({name:H,value:Y(B.slice(Q+1),K),inline:!0});else if($.has(H)){let M=Z[X+1];J.flags.push(M?{name:H,value:M}:{name:H,missing:!0}),X++}else J.flags.push({name:H});continue}if(B.startsWith("-")&&B.length>1){for(let Q=1;Q<B.length;Q++){let H="-"+B[Q],M=B.slice(Q+1);if(M.startsWith("=")){J.flags.push({name:H,value:Y(M.slice(1),K),inline:!0});break}if(!$.has(H)){J.flags.push({name:H});continue}if(M)J.flags.push({name:H,value:Y(M,K),inline:!0});else{let G=Z[X+1];J.flags.push(G?{name:H,value:G}:{name:H,missing:!0}),X++}break}continue}J.positionals.push(K)}return J}function m(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 qZ=(Z,...z)=>Z.flags.filter(($)=>z.includes($.name)),a=["-R","--repo","-q","--jq","-t","--template","--json"],DZ={"pr view":{values:a},"issue view":{values:a},"release view":{values:a},"discussion view":{values:[...a,"--after","-L","--limit","--order"]},"pr list":{values:[...a,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...a,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...a,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...a,"-L","--limit","-O","--order"]},"pr status":{values:a},"issue status":{values:a},"pr checks":{values:[...a,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...a,"--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"]}},j7=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"]),W7=new Set(["pr","issue","release","discussion","search","project","api","status"]),F7=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),N7=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),q7=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),I7=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function O0(Z,z){let $=qZ(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((K)=>K.trim()).filter(Boolean))}return{present:$.length>0,opaque:Y,fields:J}}function C2(Z,z){if(m(Z,"--verbose")||qZ(Z,"-t","--template").length>0)return!1;let $=qZ(Z,"-q","--jq");return $.length>0&&$.every((J)=>J.value!==void 0&&!J.value.opaque&&o3(J.value.value,{rootScalars:z}))}function P2(Z,z,$,J){let Y=O0(Z,$);if(Y.opaque)return P("unclassifiable");if(Y.fields.every((X)=>z.has(X)))return C;if($.debug)return P("debug-traffic");return C2(Z)?C:P(J)}function D0(Z,z,$,J,Y){let X=kZ(Z,DZ[z]);if(m(X,"-h","--help"))return C;if(m(X,"-w","--web"))return J.debug?P("debug-traffic"):C;if(Y&&m(X,"-c","--comments"))return P("view-comments");if(!O0(X,J).present)return P(J.debug?"debug-traffic":"view-human");return P2(X,$,J,"json-composite")}function NZ(Z,z,$,J){let Y=kZ(Z,DZ[z]);if(m(Y,"-h","--help"))return C;if(J.debug&&(m(Y,"-w","--web")||!O0(Y,J).present))return P("debug-traffic");if(m(Y,"-w","--web"))return C;return P2(Y,$,J,"json-composite")}function T7(Z,z){let $=kZ(Z,DZ["pr checks"]);if(m($,"-h","--help"))return C;if(z.debug)return P("debug-traffic");if(m($,"-w","--web"))return C;if(!O0($,z).present)return P("checks-human");return P2($,U7,z,"checks-json")}function _7(Z){let z=new Set(DZ.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 D7(Z,z,$){let{sub:J,rest:Y}=_7(z);if(!J)return $.appendsArgs?P("unclassifiable"):C;if(J.opaque)return P("unclassifiable");let X=J.value;if((Z==="pr"?F7:Z==="issue"?N7:Z==="release"?q7:Z==="discussion"?I7:new Set).has(X))return $.debug?P("debug-traffic"):C;if($.appendsArgs&&!(Z==="project"&&X!=="item-list"))return P("unclassifiable");switch(Z){case"pr":if(X==="view")return D0(Y,"pr view",j2,$,!0);if(X==="list"||X==="ls")return NZ(Y,"pr list",j2,$);if(X==="status")return NZ(Y,"pr status",j2,$);if(X==="checks")return T7(Y,$);if(X==="diff"){let B=kZ(Y,DZ["pr diff"]);if(m(B,"-h","--help"))return C;if($.debug)return P("debug-traffic");return m(B,"--patch")?P("composite-other"):C}return P("unclassifiable");case"issue":if(X==="view")return D0(Y,"issue view",W2,$,!0);if(X==="list"||X==="ls")return NZ(Y,"issue list",W2,$);if(X==="status")return NZ(Y,"issue status",W2,$);return P("unclassifiable");case"release":if(X==="view")return D0(Y,"release view",a3,$,!1);if(X==="list"||X==="ls")return NZ(Y,"release list",a3,$);return P("unclassifiable");case"discussion":if(X==="view")return D0(Y,"discussion view",r3,$,!0);if(X==="list"||X==="ls")return NZ(Y,"discussion list",r3,$);return P("unclassifiable");case"search":if(X==="prs"||X==="issues")return NZ(Y,"search",G7,$);if(X==="commits")return NZ(Y,"search",V7,$);if(X==="code"||X==="repos")return $.debug?P("debug-traffic"):C;return P("unclassifiable");case"project":{if($.debug)return P("debug-traffic");if(X!=="item-list")return C;let B=kZ(Y,DZ["project item-list"]);if(m(B,"-h","--help"))return C;let Q=qZ(B,"--format");if(Q.some((H)=>!H.value||H.value.opaque))return P("unclassifiable");if(Q.every((H)=>H.value.value!=="json"))return C;return C2(B)?C:P("composite-other")}}return P("unclassifiable")}var z4=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function C7(Z){let z=Z.value.trim(),$=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(z);if($){let X=$[1].toLowerCase(),K=$[2]??"/";if(X==="api.github.com"||/^api\./.test(X))z=K;else if(/^\/api\/v3(?:\/|$)/i.test(K))z=K.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(K))z="graphql";else return null}z=z.replace(/[?#].*$/,"");let J=[],Y=[];for(let X of z.split("/")){let K;try{K=decodeURIComponent(X)}catch{return null}for(let B of K.split("/")){if(B===""||B===".")continue;if(B===".."){J.pop(),Y.pop();continue}J.push(B.toLowerCase()),Y.push(Z.opaque&&/[$`]/.test(B)||/[*?[]/.test(B)||J4(B))}}return{segments:J,opaque:Y}}function P7(Z){let z=C7(Z);if(!z)return{kind:"unclassifiable",segments:[]};let{segments:$,opaque:J}=z,Y=(Q)=>({kind:Q,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,K=[];if($[0]==="repos")X=$.slice(3),K=J.slice(3);else if($[0]==="repositories")X=$.slice(2),K=J.slice(2);if(X){if(($[0]==="repos"?J.slice(1,3):J.slice(1,2)).some(Boolean)){let H=J.findIndex(Boolean),M=$.findIndex((G,U)=>U>H&&!J[U]&&O7.has(G));return Y(M<0?"unclassifiable":t3($.slice(M),J.slice(M)))}return Y(t3(X,K))}let B=$[0];if(B==="issues")return Y("sensitive");if(B==="user"&&$[1]==="issues")return Y("sensitive");if(B==="orgs"&&$[2]==="issues")return Y("sensitive");if(B==="search")return Y($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&J[1]?"unclassifiable":"other");if(B==="events"||B==="networks")return Y("sensitive");if((B==="users"||B==="orgs")&&$.slice(2).some((Q)=>Q==="events"||Q==="received_events"||Q==="discussions"))return Y("sensitive");if((B==="users"||B==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return Y("sensitive");if(B==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||B==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return Y("sensitive");if(B==="teams"&&$.includes("discussions"))return Y("sensitive");if(B==="projects"&&$.includes("cards"))return Y("sensitive");if(J.some(Boolean))return Y($.some((Q)=>Q==="events"||Q==="discussions"||Q==="issues")?"sensitive":"unclassifiable");return Y("other")}var O7=new Set([...z4,"branches","git","actions","hooks","zipball","tarball"]);function t3(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(z4.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 L7(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((K,B)=>typeof K==="number"?J(B):$[B]===K);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 A7(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 y7=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"]),R7=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function b7(Z){let z=[],$=0;while($<Z.length){let J=Z[$];if(/[\s,]/.test(J)){$++;continue}if(J==="#"){let K=Z.indexOf(`
|
|
34
|
+
`,$);$=K<0?Z.length:K+1;continue}if(Z.startsWith('"""',$)){let K=$+3;for(;;){let B=Z.indexOf('"""',K);if(B<0)return null;if(Z[B-1]==="\\"){K=B+3;continue}$=B+3;break}continue}if(J==='"'){let K=$+1;while(K<Z.length&&Z[K]!=='"'&&Z[K]!==`
|
|
35
|
+
`)K+=Z[K]==="\\"?2:1;if(Z[K]!=='"')return null;$=K+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 v7(Z){let z=b7(Z);if(!z)return!0;let $=[],J="",Y=0;for(let X=0;X<z.length;X++){let K=z[X];if(K.kind==="punct"){if(K.text==="(")Y++;else if(K.text===")"){if(Y--,Y<0)return!0}else if(Y===0&&K.text==="{")$.push(J),J="";else if(Y===0&&K.text==="}"){if($.pop()===void 0)return!0;J=""}continue}if(Y>0)continue;let B=z[X-1];if(B?.kind==="punct"&&(B.text==="@"||B.text==="$"))continue;if(z[X+1]?.kind==="punct"&&z[X+1].text===":")continue;if(K.text==="on"&&B?.kind==="punct"&&B.text==="...")continue;if(B?.kind==="name"&&B.text==="on"){J=K.text;continue}if($.length===0){J=K.text;continue}if(y7.has(K.text)||/(?:Url|URL|HTML|Html)$/.test(K.text))return!0;if(K.text==="title"&&$.some((Q)=>R7.has(Q)))return!0;J=K.text}return Y!==0||$.length!==0}function S7(Z,z){let $=kZ(Z,DZ.api);if(m($,"-h","--help"))return C;let J=$.positionals[0];if(!J)return z.appendsArgs?P("unclassifiable"):C;let Y=P7(J),X=qZ($,"-X","--method"),K=X[X.length-1],B=qZ($,"-f","--raw-field","-F","--field","--input"),Q=K?K.value&&!K.value.opaque?K.value.value.toUpperCase():"?":B.length>0?"POST":"GET",H=L7(Q,Y.segments),M=C;if(Y.kind==="unclassifiable")M=P("unclassifiable");else if(Y.kind==="sensitive"&&!H)M=P("api-rest");else if(Y.kind==="graphql")M=E7($);if(z.debug||m($,"--verbose")){if(Y.kind==="download"&&!M.refused)M=P("api-rest");if(M.refused)return z.debug?P("debug-traffic"):M;return C}if(z.appendsArgs&&Y.kind!=="other"&&Y.kind!=="download")return P("unclassifiable");if(!M.refused||m($,"--silent"))return C;if(C2($,A7(Y.segments)))return C;return M}function E7(Z){if(qZ(Z,"--input").length>0)return P("unclassifiable");let z=qZ(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 P("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 P("unclassifiable");if(v7(Y))return P("api-graphql")}return C}function P0(Z,z){let $=0;while($<Z.length&&Z[$].value.startsWith("-")&&!Z[$].opaque){if(["--help","-h","--version"].includes(Z[$].value))return C;$++}if($>=Z.length)return z.appendsArgs?P("unclassifiable"):C;let J=Z[$],Y=Z.slice($+1);if(J.opaque)return P("unclassifiable");switch(J.value){case"pr":case"issue":case"release":case"discussion":case"search":case"project":return D7(J.value,Y,z);case"api":return S7(Y,z);case"status":return Y.length>0&&Y.every((X)=>X.value==="-h"||X.value==="--help")?C:P("composite-other");case"help":case"version":return C;case"cs":case"codespace":{let X=Y.findIndex((K)=>K.value==="--");if(Y.some((K)=>K.value==="ssh")&&X>=0&&X+1<Y.length){let K=r(Y.slice(X+1).map((B)=>B.value).join(" "),z.depth+1,z.debug);if(K.refused)return K}break}}if(!j7.has(J.value))return P("unclassifiable");if(z.debug)return P("debug-traffic");return C}var L0=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","fish"]),f7=new Set(["su","runuser","script","flock"]),k7=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"]),x7=new Map([["bun",["x","exec"]],["npm",["exec","x"]],["deno",["run"]]]),h7=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"]),w7=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),C0=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/,g7=/^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/,u7=6;function e3(Z,z){let $,J;for(let Y of Z){let X=g7.exec(Y.value);if(!X)continue;let K={...Y,value:X[2]};if(X[1]==="GH_DEBUG")$=K;else if(X[1]==="DEBUG")J=K}if($)return $.opaque||!["","0","false","no"].includes($.value);if(J&&(J.opaque||["1","true","yes","api"].includes(J.value)))return!0;return z}function O2(Z){let z=w(Z),$=0;return{segments:z.segments.map((Y)=>{let X=Y.words[0],K=Z.slice($,X.start);return $=Y.words[Y.words.length-1].end,{words:Y.words,redirects:Y.redirects,sepBefore:K}}),trustworthy:z.trustworthy}}var Y4=(Z)=>/(?:^|[^|])\|&?$/.test(Z.trim());function I2(Z,z){if(!L0.has(Z))return!1;if(L2(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 T2(Z){let{segments:z}=O2(Z.trim());if(z.length!==1)return null;let $=z[0],J=l($);if(J<0)return null;let Y=_Z(fZ($.words[J].text).value),X=$.words.slice(J+1).filter((K,B)=>!$.redirects.has(B+J+1)).map((K)=>fZ(K.text));if(Y==="echo")return X.filter((K,B)=>!(B===0&&/^-[neE]+$/.test(K.value))).map((K)=>K.value).join(" ");if(Y==="printf"){let[K,...B]=X.filter((H)=>H.value!=="--");if(!K)return null;let Q=0;return K.value.replace(/\\n/g,`
|
|
36
|
+
`).replace(/%s/g,()=>B[Q++]?.value??"")+(Q<B.length?" "+B.slice(Q).map((H)=>H.value).join(" "):"")}if(Y==="cat"){let K=Z.indexOf("<<");if(K<0)return null;let B=vZ(Z,K),Q=Z.indexOf(`
|
|
37
|
+
`,K);if(!B||Q<0)return null;let H=V0(Z,Q,[B]);if(H<0)return null;let M=Z.slice(Q+1,H);return M.slice(0,M.lastIndexOf(B.delimiter)).replace(/\n$/,"")}return null}function F2(Z,z,$){for(let J of q2(Z).bodies){let Y=T2(J);if(Y===null)continue;let X=r(Y,z+1,$.debug);if(X.refused)return X}return C}function r(Z,z=0,$=!1){let J=Z4(Z,z,$);if(J.refused||typeof Z!=="string")return J;let Y=r0(Z),X=Y===Z?J:Z4(Y,z,$);if(X.refused)return X;let K=KZ(Z),B=K===Z?X:r(K,z,$);if(B.refused)return B;let Q=H0(Z);return Q===Z||Q===K?B:r(Q,z,$)}function Z4(Z,z,$){if(typeof Z!=="string"||!Z.trim())return C;if(z>u7)return C0.test(Z)?P("unclassifiable"):C;let{segments:J,trustworthy:Y}=O2(Z);if(!Y)return C0.test(Z)?P("unclassifiable"):C;let X=$,K=(B)=>r(B,z+1,X);for(let B of m7(Z)){if(B.runsBody){let Q=K(B.body);if(Q.refused)return Q}if(!B.quoted){let Q=q2(B.body,"heredoc");if(!Q.complete&&C0.test(B.body))return P("unclassifiable");for(let H of Q.bodies){let M=K(H);if(M.refused)return M}}}for(let B=0;B<J.length;B++){let Q=J[B];for(let O of Q.words){let q=q2(O.text);if(!q.complete&&C0.test(O.text))return P("unclassifiable");for(let F of q.bodies){let R=K(F);if(R.refused)return R}}let H=l(Q),M=Q.words.map((O,q)=>({word:fZ(O.text),redirect:Q.redirects.has(q)})),G=M.slice(0,H<0?M.length:H).map((O)=>O.word),U=H>=0?_Z(M[H].word.value):"";if(H<0||["export","declare","typeset","readonly","local"].includes(U)){if(X=e3([...G,...M.slice(H+1).map((O)=>O.word)],X),H<0)continue}let V=e3(G,X),j=M.slice(H+1).filter((O)=>!O.redirect).map((O)=>O.word),W=M.slice(H+1).filter((O)=>O.redirect).map((O)=>O.word),_=M[H].word,L=_Z(_.value),x={depth:z,appendsArgs:!1,debug:V};if(H>0&&M[H-1].word.value==="function"){let O=j.filter((F)=>!["{","()","(",")"].includes(F.value)),q=_2(O,x);if(q.refused)return q;continue}if(B>0&&Y4(Q.sepBefore)&&I2(L,j)){let O=J[B-1],q=l7(Z,O),F=q===null?null:T2(q);if(F!==null){let R=r(F,z+1,V);if(R.refused)return R}}let g=J[B+1];if(g&&/<\(\s*$/.test(g.sepBefore)&&(L0.has(L)||L==="source"||L===".")){let O=g.words[0].start-g.sepBefore.length+g.sepBefore.lastIndexOf("("),q=BZ(Z,O),F=q<0?null:T2(Z.slice(O+1,q-1));if(F!==null){let R=r(F,z+1,V);if(R.refused)return R}}let y=X4(L,_,j,W,Q.words.slice(0,H+1),x);if(y.refused)return y}return C}function l7(Z,z){let $=z.words[0],J=z.words[z.words.length-1];return $&&J?Z.slice($.start,J.end):null}function p7(Z){let z=_Z(Z.value);return/[$`]/.test(z)||z===""?void 0:z}function X4(Z,z,$,J,Y,X){let K=X.depth,B=(Q)=>r(Q,K+1,X.debug);if(z.opaque){let Q=p7(z);if(Q===void 0){let H=$.find((G)=>!G.value.startsWith("-")),M=P0($,X);if(!M.refused)return C;return M.rule!=="unclassifiable"||H!==void 0&&!H.opaque&&W7.has(H.value)?M:C}Z=Q}if(Z==="gh")return P0($,X);if(L0.has(Z)){let Q=L2($);if(Q){let H=B(Q.value);if(H.refused||!Q.opaque)return H;let M=$4(Q.raw,B);if(M.refused)return M;return F2(Q.raw,K,X)}for(let H of J){let M=B(H.value);if(M.refused)return M;if(H.opaque){let G=F2(H.raw,K,X);if(G.refused)return G}}return C}if(f7.has(Z)){let Q=$.findIndex((M)=>M.value==="-c"||M.value==="--command"||/^-[A-Za-z]*c$/.test(M.value)),H=Q>=0?$[Q+1]:void 0;return H?B(H.value):N2($,X)}if(Z==="eval"||Z==="watch"){let Q=$;if(Z==="watch"){let G=0;while(G<$.length&&$[G].value.startsWith("-")){if($[G].value==="--"){G++;break}if(["-n","--interval","-q","--equexit"].includes($[G].value))G++;G++}Q=$.slice(G)}let H=B(Q.map((G)=>G.value).join(" "));if(H.refused)return H;let M=$4(Q.map((G)=>G.raw).join(" "),B);if(M.refused)return M;for(let G of Q){let U=F2(G.raw,K,X);if(U.refused)return U}return C}if(Z==="env")return B(tZ([...Y.map((Q)=>fZ(Q.text).value),...$.map((Q)=>Q.value)]));if(Z==="ssh"){let Q=0;for(;Q<$.length;Q++){let G=$[Q].value;if(!G.startsWith("-"))break;if(w7.has(G))Q++}let H=$.slice(Q+1);if(H[0]?.value==="--")H.shift();let M=H.map((G)=>G.value).join(" ");return M?B(M):C}if(Z==="xargs"){let Q=0,H=!1;for(;Q<$.length;Q++){let M=$[Q].value;if(M==="--"){Q++;break}if(!M.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(M))H=!0;if(h7.has(M))Q++}return _2($.slice(Q),{depth:K,appendsArgs:!H,debug:X.debug})}if(Z==="find"){for(let Q=0;Q<$.length;Q++){if(!["-exec","-execdir","-ok","-okdir"].includes($[Q].value))continue;let H=Q+1;while(H<$.length&&$[H].value!==";"&&$[H].value!=="+")H++;let M=_2($.slice(Q+1,H),X);if(M.refused)return M;Q=H}return C}if(k7.has(Z))return N2($,X);if(x7.get(Z)?.includes($[0]?.value??""))return N2($.slice(1),X);return C}function _2(Z,z){if(Z.length===0)return C;let $=_Z(Z[0].value);if($==="gh")return P0(Z.slice(1),z);if(L0.has($)){let J=L2(Z.slice(1));return J?r(J.value,z.depth+1,z.debug):C}return X4($,Z[0],Z.slice(1),[],[],z)}function N2(Z,z){let $=Z.findIndex((J)=>!J.opaque&&_Z(J.value)==="gh"&&(J.value==="gh"||J.value.includes("/")));return $>=0?P0(Z.slice($+1),z):C}function $4(Z,z){return Z.includes("$'")?z(f(Z)):C}function L2(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 m7(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=vZ(Z,J);if(!Y)continue;let X=Z.lastIndexOf(`
|
|
38
|
+
`,J)+1,K=Z.indexOf(`
|
|
39
|
+
`,J);if(K<0)continue;let B=V0(Z,K,[Y]),Q=B<0?Z.slice(K+1):Z.slice(K+1,B),H=B<0?Q:Q.slice(0,Math.max(0,Q.lastIndexOf(Y.delimiter))).replace(/\n$/,""),M=Z.slice(X,J)+" HEREDOC_OPERATOR "+Z.slice(Y.end,K);z.push({body:H,runsBody:c7(M),quoted:Y.quoted})}return z}function c7(Z){let{segments:z}=O2(Z),$=z.findIndex((B)=>B.words.some((Q)=>Q.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(B)=>{let Q=l(B);if(Q<0)return{verb:"",args:[]};let H=B.words.slice(Q+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>fZ(M.text));return{verb:_Z(fZ(B.words[Q].text).value),args:H}},{verb:Y,args:X}=J(z[$]);if(Y==="ssh"||I2(Y,X))return!0;if((Y==="source"||Y===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(X[0]?.value??""))return!0;let K=z[$+1];if(Y==="cat"&&K&&Y4(K.sepBefore)){let B=J(K);return B.verb==="ssh"||I2(B.verb,B.args)}return!1}var i7=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function K4(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:D2}}}var d7=new Set(["Bash","Monitor"]);function Q4(Z){if(Z?.hook_event_name!=="PreToolUse"||!d7.has(Z.tool_name??""))return{continue:!0};let z=zZ(Z);if(!z.trim())return{continue:!0};try{return r(z).refused?K4():{continue:!0}}catch{return i7.test(z)?K4():{continue:!0}}}function s7(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard"&&Z!=="protected-delete-guard")throw Error("Invalid safety capability")}function B4(Z,z){s7(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"||!A2.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:z0.homedir(),path:process.env.PATH,agent:Y.agent};if(X&&(!A2.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 L=J.tool_input.command??J.tool_input.patch;if(typeof L!=="string")throw Error("Invalid patch input");J.tool_input={...J.tool_input,command:L,patch:L}}let K=J.tool_name==="Monitor",B=J.tool_name==="Bash"||K&&typeof J.tool_input.command==="string",Q=K&&B?{...J,tool_name:"Bash"}:J,H=(L)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:L}});if($==="protected-delete-guard"){let L=p3(Q,{home:z0.homedir(),cwd:J.cwd,env:process.env});return JSON.stringify({verdict:L.hookSpecificOutput?.permissionDecision==="deny"?L:null})}let M=E3(Q).output,G=Q4(Q),U=Q.tool_input.command,V=()=>HZ(U,{home:z0.homedir(),cwd:J.cwd}).handoffHits.length>0,j=B&&(V()||!!XZ(U,V)),W=$==="trash-guard"&&(!K||B)?V3(Q,{home:z0.homedir(),cwd:J.cwd,findTrash:K0,inspectTrash:pZ,execution:X}):{continue:!0};if(K&&W.hookSpecificOutput?.permissionDecision==="allow")W=H("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let _=M.decision==="block"?H(M.reason):G.hookSpecificOutput?G:j?H(m0):W;return JSON.stringify({verdict:"continue"in _?null:_})}var n7=2,o7="0.14.0";function a7(Z,z){return B4(Z,z)}
|