@hasna/hooks 0.12.22 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -0
- package/bin/hooks/scratch-lifecycle.js +5 -5
- package/bin/hooks/stop-review.js +23 -8
- package/bin/hooks-mcp.js +1901 -1213
- package/bin/index.js +3355 -1978
- package/bin/native-safety-entry.js +37 -37
- package/bin/native-safety-worker.cjs +37 -37
- package/bin/serve.js +125 -121
- package/dist/index.js +2304 -1548
- package/dist/lib/claude-skills-coordination.d.ts +1 -1
- package/dist/lib/installer.d.ts +44 -5
- package/dist/lib/manifest.d.ts +21 -0
- package/dist/lib/native-safety.d.ts +24 -0
- package/dist/lib/native-target.d.ts +11 -2
- package/dist/lib/registry.d.ts +12 -0
- package/dist/lib/sumi-stop-plugin.d.ts +4 -0
- package/dist/lib/target-adapters.d.ts +151 -0
- package/dist/lib/targets.d.ts +99 -0
- package/dist/native-readiness.js +11 -11
- package/dist/native-safety.js +183 -24
- package/dist/opencode-stop-plugin.js +17 -7
- package/dist/sdk/index.js +60 -16
- package/dist/storage.js +34 -34
- package/dist/sumi-stop-plugin.js +29 -10
- package/hooks/hook-announce-stop/src/hook.ts +91 -15
- package/hooks/hook-stop-review/README.md +7 -0
- package/hooks/hook-stop-review/src/policy.ts +21 -4
- package/hooks/hook-stop-review/src/runtime.ts +4 -3
- package/hooks/hook-stop-review/src/types.ts +6 -0
- package/hooks/hook-trash-guard/src/hook.ts +108 -12
- package/package.json +2 -2
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{homedir as
|
|
3
|
-
`)[0]}finally{k2($)}let Y=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(J);if(Y&&Y[1]!=="/usr/bin/env")return nZ(Y[1],!0);if(J!=="#!/usr/bin/env bun"||!nZ("/usr/bin/env",!0))return!1;for(let X of z.split(":").slice(0,64)){if(!m2(X))return!1;let Q=$Z(X,"bun");try{if(!T0(Q).isFile())continue;f2(Q,sZ.X_OK)}catch{continue}return nZ(Q,!0)}return!1}function RZ(Z){let z=Z;for(;;){let $=AZ(z);if(!$.isDirectory()||!yZ($.uid)||($.mode&18)!==0)return!1;let J=VZ(z);if(J===z)return!0;z=J}}function vZ(Z=process.env){let z=Z.PATH??"",$=Date.now()+2000,J="missing",Y=(X)=>{if(J==="missing"||J==="unrecognized_package"||X.startsWith("unsafe_"))J=X};for(let X of z.split(":").slice(0,64)){if(!oZ(X)||Date.now()>=$)continue;let Q=$Z(X,"trash");try{let H=T0(Q);if(!H.isFile()||!yZ(H.uid)||(H.mode&73)===0||(H.mode&18)!==0){Y("unsafe_executable");continue}let K=D0(Q);if(!RZ($Z(X))||!RZ(VZ(K))){Y("unsafe_directory");continue}if(!nZ(Q)){Y("unsafe_directory");continue}let B=$Z(VZ(K),"../.."),M=_0(B,"package.json"),V=T0(M);if(!V.isFile()||!yZ(V.uid)||V.size>16384||(V.mode&18)!==0||AZ(M).isSymbolicLink()){Y("unsafe_manifest");continue}let G=JSON.parse(w2(M,"utf8"));if(G.name!=="@hasna/trash"||typeof G.version!=="string"||typeof G.bin?.trash!=="string"||D0($Z(B,G.bin.trash))!==K){Y("unrecognized_package");continue}try{if(!p2(K,z)){Y("unsafe_interpreter");continue}}catch{Y("unsafe_interpreter");continue}let U=$-Date.now();if(U<=0){Y("identity_failed");break}let j=l2(Q,["--identity"],{encoding:"utf8",timeout:U,maxBuffer:2048,env:{PATH:z},stdio:["ignore","pipe","pipe"]});if(j.error||j.status!==0||Date.now()>=$){Y("identity_failed");continue}let N=JSON.parse(j.stdout);if(N.name==="@hasna/trash"&&N.version===G.version&&N.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:Q,version:G.version};Y("unsupported_protocol")}catch{}}return{ok:!1,code:J}}function aZ(Z=process.env){let z=vZ(Z);return z.ok?z.path:null}function GZ(Z){let z=Z.tool_input?.command;return typeof z==="string"?z:""}var F1=["/","/bin","/boot","/dev","/etc","/home","/lib","/lib32","/lib64","/libx32","/opt","/proc","/root","/run","/sbin","/srv","/sys","/usr","/var","/Applications","/Library","/System","/Users","/Volumes","/private"];var EZ=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,c=(Z)=>Z.split("/").pop()??"";function rZ(Z){let z=Z.startsWith("~")?Z.slice(1).split("/",1)[0]:"";if(z&&!/['"\\]/.test(z))return!0;let $=null,J=0;for(let Y=0;Y<Z.length;Y++){let X=Z[Y];if($==="'"){if(X==="'")$=null;continue}if(X==="\\"){Y++;continue}if($==='"'){if(X==='"')$=null;continue}if(X==="'"||X==='"')$=X;else if(X==="$"&&Z[Y+1]==="{")J++,Y++;else if(X==="}"&&J>0)J--;else if(X==="{"||X==="}")return!0}return!1}var I0=64;function _1(Z,z){let $=0;for(let J=z;J<Z.length;J++)if(Z[J]==="\\")J++;else if(Z[J]==="{")$++;else if(Z[J]==="}"&&--$===0)return J;return Z.length-1}function c2(Z){let z=Z.match(/^([-+]?\d+)\.\.([-+]?\d+)(?:\.\.([-+]?\d+))?$/),$=z?null:Z.match(/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([-+]?\d+))?$/),J=z??$;if(!J)return null;let Y=z?Number(J[1]):J[1].charCodeAt(0),X=z?Number(J[2]):J[2].charCodeAt(0),Q=Math.abs(Number(J[3]??1))||1;if(!Number.isSafeInteger(Y)||!Number.isSafeInteger(X)||!Number.isSafeInteger(Q))return"overflow";if(Math.floor(Math.abs(X-Y)/Q)+1>I0)return"overflow";let H=z&&(/^[-+]?0\d/.test(J[1])||/^[-+]?0\d/.test(J[2]))?Math.max(J[1].length,J[2].length):0,K=[];for(let B=Y;Y<=X?B<=X:B>=X;B+=Y<=X?Q:-Q)if(!z)K.push(String.fromCharCode(B));else K.push(B<0?`-${String(-B).padStart(H-1,"0")}`:String(B).padStart(H,"0"));return K}function i2(Z){let z=null,$=0;for(let J=0;J<Z.length;J++){let Y=Z[J];if(z==="'"){if(Y==="'")z=null;continue}if(Y==="\\"){J++;continue}if(z==='"'){if(Y==='"')z=null;continue}if(Y==="'"||Y==='"')z=Y;else if(Y==="$"&&Z[J+1]==="{")J=_1(Z,J+1);else if(Y==="{"){if(++$>I0)return"overflow";let X=null,Q=0,H=!0,K=[];for(let B=J;B<Z.length;B++){let M=Z[B];if(X==="'"){if(M==="'")X=null;continue}if(M==="\\"){H=!1,B++;continue}if(X==='"'){if(M==='"')X=null;continue}if(M==="'"||M==='"')X=M,H=!1;else if(M==="$"&&Z[B+1]==="{")B=_1(Z,B+1),H=!1;else if(M==="{")Q++;else if(M===","&&Q===1)K.push(B);else if(M==="}"&&--Q===0){if(K.length>0){let G=[J,...K,B];return{open:J,close:B,parts:G.slice(0,-1).map((U,j)=>Z.slice(U+1,G[j+1]))}}let V=H?c2(Z.slice(J+1,B)):null;if(V==="overflow")return V;if(V)return{open:J,close:B,parts:V};break}}}}return null}function JZ(Z){if(Z.length>4096&&Z.includes("{"))return null;let z=i2(Z);if(z===null)return[Z];if(z==="overflow")return null;let $=[];for(let J of z.parts){let Y=JZ(Z.slice(0,z.open)+J+Z.slice(z.close+1));if(Y===null||$.push(...Y)>I0)return null}return $}var W={arg:"none"},D={arg:"value"},bZ={arg:"optional"},s={arg:"none",effect:"lookup"},C={arg:"none",effect:"refuse"},o={help:C,version:C},d2=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,q0={timeout:{short:{k:D,s:D,v:W},long:{"kill-after":D,signal:D,verbose:W,foreground:W,"preserve-status":W,...o},positionals:[d2]},env:{short:{i:W,"0":W,v:W,u:D,a:D,C,S:C},long:{"ignore-environment":W,null:W,debug:W,unset:D,argv0:D,chdir:C,"split-string":C,"block-signal":bZ,"default-signal":bZ,"ignore-signal":bZ,"list-signal-handling":C,...o},env:!0},nice:{short:{n:D},long:{adjustment:D,...o},numericOption:!0},nohup:{short:{},long:{...o}},command:{short:{p:W,v:s,V:s},long:{}},exec:{short:{c:W,l:W,a:D},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:D,o:D,e:D},long:{input:D,output:D,error:D,...o}},time:{short:{p:W,a:W,q:W,v:W,f:D,o:C,V:C},long:{portability:W,append:W,quiet:W,verbose:W,format:D,output:C,...o}},ionice:{short:{c:D,n:D,t:W,p:C,P:C,u:C,h:C,V:C},long:{class:D,classdata:D,ignore:W,pid:C,pgid:C,uid:C,...o}},setsid:{short:{c:W,f:W,w:W,h:C,V:C},long:{ctty:W,fork:W,wait:W,...o}}},s2=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function n2(Z,z,$){let J=!1,Y=(X)=>{if(!X||X.effect==="refuse")return!1;if(X.effect==="lookup")J=!0;return!0};while($<z.length){let X=z[$];if(X.opaque)return null;let Q=X.text;if(Q==="--"){$++;break}if(Q==="-"&&Z.env){$++;continue}if(!Q.startsWith("-")||Q==="-")break;if(Z.numericOption&&/^-[-+]?\d+$/.test(Q)){$++;continue}if(Q.startsWith("--")){let H=Q.indexOf("="),K=H<0?Q.slice(2):Q.slice(2,H),B=Object.keys(Z.long),M=B.includes(K)?[K]:B.filter((G)=>K&&G.startsWith(K));if(M.length!==1)return null;let V=Z.long[M[0]];if(!Y(V))return null;if(V.arg==="none"&&H>=0)return null;if(V.arg==="value"&&H<0){let G=z[++$];if(!G||G.opaque)return null}$++;continue}for(let H=1;H<Q.length;H++){let K=Z.short[Q[H]];if(!Y(K))return null;if(K.arg==="value"){if(H===Q.length-1){let B=z[++$];if(!B||B.opaque)return null}break}}$++}if(J)return-1;for(let X of Z.positionals??[]){let Q=z[$];if(!Q||Q.opaque||!X.test(Q.text))return null;$++}if(Z.env||Z.assignments){for(;$<z.length&&EZ.test(z[$].text);$++)if(z[$].opaque)return null}return $}function zZ(Z,z=q0){let $=0;while($<Z.length&&(EZ.test(Z[$].text)||s2.has(Z[$].text)))$++;for(let J=0;J<16;J++){if($>=Z.length)return{index:-1};if(Z[$].opaque)return J===0?{index:$}:null;let Y=Object.hasOwn(z,c(Z[$].text))?z[c(Z[$].text)]:void 0;if(!Y)return{index:$};let X=n2(Y,Z,$+1);if(X===null)return null;if(X<0)return{index:-1};$=X}return null}function o2(Z){return/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred|trash)(?![A-Za-z0-9_.-])/.test(Z)}var a={on:!1};function YZ(Z,z){if(!Z.includes("\\")||!Z.includes('"'))return;let $=a.on;a.on=!0;try{return z()}finally{a.on=$}}var O0=(Z)=>Z.split("/").pop()??"",P0={perl:{letters:new Set(["e","E"]),long:new Set},python:{letters:new Set(["c"]),long:new Set},python2:{letters:new Set(["c"]),long:new Set},python3:{letters:new Set(["c"]),long:new Set},ruby:{letters:new Set(["e"]),long:new Set},node:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},nodejs:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},bun:{letters:new Set(["e"]),long:new Set(["--eval"])},deno:{letters:new Set(["e"]),long:new Set(["--eval"])},php:{letters:new Set(["r"]),long:new Set},lua:{letters:new Set(["e"]),long:new Set},luajit:{letters:new Set(["e"]),long:new Set},Rscript:{letters:new Set(["e"]),long:new Set}},q1=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,a2=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),r2=new Set(["ssh","scp","sftp"]),t2=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),D1=new Set(["proxycommand","localcommand","knownhostscommand"]),e2=/(?:`|\$\()|\b(?:system|exec|execve|execvp|popen|spawn|posix_spawn|fork|subprocess|Popen|check_output|check_call|shell_exec|passthru|proc_open|pcntl_exec|qx|open|fopen|sysopen|unlink|remove|delete|rmtree|rmdir|mkdir|rename|truncate|ftruncate|chmod|chown|symlink|writeFile|createWriteStream|appendFile|child_process|FileUtils|shutil|Kernel|require|import|load|eval|os|sys|io|fs|File|IO|Dir|Path|pathlib|Deno|Bun)|%x\W/,Z3=/[|>]|\b(?:system|getline|close|fflush|print\w*\s*>>?)/;function C1(Z){if(o2(Z.text))return!1;if(Z.kind==="awk")return!Z3.test(Z.text);if(Z.kind==="c-interp")return!e2.test(Z.text);return!1}function $3(Z,z,$,J){let Y=P0[Z]??(q1.test(Z)?P0[Z.replace(/[0-9.]+$/,"")]:void 0);if(!Y)return null;let X=[],Q=!1,H=(K)=>{if(K+1>=z.length||J(K+1))return Q=!0,K;return X.push({text:z[K+1],kind:"c-interp"}),K+1};for(let K=$+1;K<z.length;K++){let B=z[K];if(B==="--")break;if(!B.startsWith("-")||B==="-")break;if(B.startsWith("--")){let V=B.indexOf("="),G=V<0?B:B.slice(0,V);if(Y.long.has(G))if(V>=0)X.push({text:B.slice(V+1),kind:"c-interp"});else K=H(K);continue}let M=B.slice(1);for(let V=0;V<M.length;V++){if(!Y.letters.has(M[V]))continue;if(V<M.length-1)X.push({text:M.slice(V+1),kind:"c-interp"});else K=H(K);break}}if(X.length===0&&!Q)return null;return{programs:X,unresolved:Q}}function J3(Z,z,$){let J=z+1;for(;J<Z.length&&Z[J].startsWith("-");J++)if(Z[J]==="-L"||Z[J]==="--log-level")J++;if(Z[J]!=="eval"||$(J))return null;let Y=[],X=!1;for(J++;J<Z.length;J++){if($(J)){X=!0;continue}if(!Z[J].startsWith("-"))Y.push({text:Z[J],kind:"c-interp"})}return Y.length===0&&!X?null:{programs:Y,unresolved:X}}function z3(Z,z,$){let J=[],Y=!1,X=z+1;for(;X<Z.length;X++){let Q=Z[X];if(Q==="--"){X++;break}if(!Q.startsWith("-")||Q==="-")break;if(Q==="-e"||Q.startsWith("-e")){let H=Q==="-e"?null:Q.slice(2);if(H!==null)J.push({text:H,kind:"awk"});else if(X+1<Z.length&&!$(X+1))J.push({text:Z[++X],kind:"awk"});else Y=!0}else if(Q==="-f"||Q.startsWith("-f")){if(Y=!0,Q==="-f")X++}else if(Q==="-v"||Q.startsWith("-v")){if(Q==="-v")X++}}if(J.length===0&&!Y){if(X<Z.length)if($(X))Y=!0;else J.push({text:Z[X],kind:"awk"})}return{programs:J,unresolved:Y}}function Y3(Z,z,$){let J=Z[z],Y,X=z;if(J==="-o"){if(z+1>=Z.length)return{value:null,next:z};if($(z+1))return{value:null,next:z+1};Y=Z[z+1],X=z+1}else Y=J.slice(2);return{value:Y,next:X}}function X3(Z,z,$){let J=[],Y=!1;for(let X=z+1;X<Z.length;X++){let Q=Z[X];if(Q==="--")break;if(!Q.startsWith("-")||Q==="-")break;if(Q.startsWith("--"))continue;if(Q==="-o"||Q.startsWith("-o")){let{value:K,next:B}=Y3(Z,X,$);if(X=B,K===null){Y=!0;continue}let M=K.indexOf("="),V=M>=0?M:K.search(/\s/),G=(V>=0?K.slice(0,V):K).trim().toLowerCase(),U=V>=0?K.slice(V+1).trim():"";if(D1.has(G))J.push({text:U,kind:"shell"});continue}if(Q==="-F"||Q.startsWith("-F")){if(Y=!0,Q==="-F")X++;continue}if(Q==="-S"||Q.startsWith("-S")){let K=Q==="-S"?X+1<Z.length&&!$(X+1)?Z[++X]:null:Q.slice(2);if(K===null)Y=!0;else J.push({text:K,kind:"shell"});continue}let H=Q.slice(1);for(let K=0;K<H.length;K++){if(!t2.has(H[K]))continue;if(K<H.length-1)break;if(H[K]==="o"||H[K]==="F"||H[K]==="S"){if(X+1<Z.length){let B=Z[X+1];if(H[K]==="o")if(!$(X+1)){let M=B.indexOf("="),V=M>=0?M:B.search(/\s/),G=(V>=0?B.slice(0,V):B).trim().toLowerCase();if(D1.has(G))J.push({text:V>=0?B.slice(V+1).trim():"",kind:"shell"})}else Y=!0;else if(H[K]==="F")Y=!0;else if(!$(X+1))J.push({text:B,kind:"shell"});X++}}else if(X+1<Z.length)X++}}return{programs:J,unresolved:Y}}function Q3(Z,z,$){let J=[],Y=!1,X=!1;for(let Q=z+1;Q<Z.length;Q++){let H=Z[Q];if(H==="--")break;if(H==="-e"||H==="--rsh")if(X=!0,Q+1<Z.length&&!$(Q+1))J.push({text:Z[++Q],kind:"shell"});else Y=!0;else if(H.startsWith("--rsh="))X=!0,J.push({text:H.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(H)&&H.length>2&&!H.startsWith("--"))X=!0,J.push({text:H.slice(H.indexOf("e")+1),kind:"shell"})}return X?{programs:J,unresolved:Y}:null}var K3=/^(?:true|false|yes|no|on|off|1|0|)$/i,H3=[/^core\.(?:pager|editor|sshcommand|askpass|alternaterefscommand)$/,/^sequence\.editor$/,/^diff\.external$/,/^interactive\.difffilter$/,/^imap\.tunnel$/,/^gc\.recentobjectshook$/,/^gpg\.program$/,/^gpg\.ssh\.defaultkeycommand$/,/^uploadpack\.packobjectshook$/,/^instaweb\.(?:browser|httpd)$/,/^credential\.(?:.+\.)?helper$/,/^diff\..+\.(?:command|textconv)$/,/^(?:difftool|mergetool|man|browser)\..+\.(?:cmd|path)$/,/^guitool\..+\.cmd$/,/^merge\..+\.driver$/,/^gpg\..+\.program$/,/^remote\..+\.(?:uploadpack|receivepack)$/,/^filter\..+\.(?:clean|smudge|process)$/,/^tar\..+\.command$/,/^trailer\..+\.(?:cmd|command)$/,/^sendemail\.(?:.+\.)?(?:tocmd|cccmd|headercmd|sendmailcmd)$/];function P1(Z,z){let $=Z.toLowerCase(),J=(Y)=>Y===void 0?{kind:"unresolved"}:{kind:"command",text:Y};if(/^alias\./.test($))return z!==void 0&&z.trimStart().startsWith("!")?J(z.trimStart().slice(1)):{kind:"unresolved"};if(/^pager\./.test($)||$==="core.fsmonitor")return z!==void 0&&K3.test(z)?{kind:"harmless"}:J(z);if($==="core.gitproxy")return z!==void 0&&/^none(?:\s+for\s+\S+)?$/.test(z)?{kind:"harmless"}:J(z?.replace(/\s+for\s+\S+$/,""));if(/^submodule\..+\.update$/.test($))return z!==void 0&&z.trimStart().startsWith("!")?J(z.trimStart().slice(1)):z===void 0?{kind:"unresolved"}:{kind:"harmless"};if(/^sendemail\.(?:.+\.)?smtpserver$/.test($))return z!==void 0&&!z.startsWith("/")?{kind:"harmless"}:J(z);if(/^credential\.(?:.+\.)?helper$/.test($)){if(z==="")return{kind:"harmless"};if(z===void 0)return{kind:"unresolved"};let Y=z.trimStart();return J(Y.startsWith("!")?Y.slice(1):Y.startsWith("/")?Y:`git credential-${Y}`)}if(H3.some((Y)=>Y.test($)))return J(z);if($==="core.hookspath")return z==="/dev/null"?{kind:"harmless"}:{kind:"unresolved"};if($==="include.path"||/^includeif\..+\.path$/.test($))return{kind:"unresolved"};if($==="protocol.allow")return z!==void 0&&/^(?:never|user)$/i.test(z)?{kind:"harmless"}:{kind:"unresolved"};if($==="protocol.ext.allow")return z!==void 0&&/^never$/i.test(z)?{kind:"harmless"}:{kind:"unresolved"};return{kind:"harmless"}}function T1(Z){return/[$\x60]/.test(Z)||["","x","/x","!x"].some((z)=>P1(Z,z).kind!=="harmless")}var B3=new Set(["GIT_PAGER","GIT_EDITOR","GIT_SEQUENCE_EDITOR","GIT_EXTERNAL_DIFF","GIT_SSH","GIT_SSH_COMMAND","GIT_ASKPASS","SSH_ASKPASS","GIT_PROXY_COMMAND","PAGER","EDITOR","VISUAL"]),M3=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function V3(Z){let z=/'((?:[^']|'\\'')*)'/y,$=(X)=>X.replace(/'\\''/g,"'"),J=[],Y=0;while(Y<Z.length){if(/\s/.test(Z[Y])){Y++;continue}z.lastIndex=Y;let X=z.exec(Z);if(!X)return null;if(Y=z.lastIndex,Z[Y]==="="){z.lastIndex=Y+1;let Q=z.exec(Z);if(!Q)return null;Y=z.lastIndex,J.push([$(X[1]),$(Q[1])])}else{let Q=$(X[1]),H=Q.indexOf("=");J.push(H<0?[Q,void 0]:[Q.slice(0,H),Q.slice(H+1)])}}return J}function G3(Z,z,$){let J=[],Y=!1,X=(B,M,V=!0)=>{if(!V||/[$\x60]/.test(B)){Y=!0;return}let G=P1(B,M);if(G.kind==="unresolved")Y=!0;else if(G.kind==="command")J.push({text:G.text,kind:"shell"})},Q=(B,M)=>{let V=B.indexOf("="),G=V<0?B:B.slice(0,V),U=V<0?"true":B.slice(V+1);if(!M)return X(G,U);if(T1(G))Y=!0},H=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let B=z+1;B<Z.length;B++){let M=Z[B];if(!M.startsWith("-")||M==="-")break;if(M==="--")break;if(M==="-c"){if(B+1>=Z.length)break;Q(Z[B+1],$(B+1)),B++}else if(M.startsWith("-c")&&!M.startsWith("--"))Q(M.slice(2),$(B));else if(M==="--config-env"||M.startsWith("--config-env=")){let V=M==="--config-env"?Z[++B]??"":M.slice(13),G=V.indexOf("="),U=G<0?V:V.slice(0,G);if($(B)||T1(U))Y=!0}else if(M.startsWith("--exec-path="))Y=!0;else if(H.has(M))B++}let K=new Map;for(let B=0;B<z;B++){let M=Z[B].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!M)continue;let[,V,G]=M,U=$(B);if(B3.has(V))if(U)Y=!0;else J.push({text:G,kind:"shell"});else if(M3.has(V)){if(U||G!=="/dev/null"||V==="GIT_EXEC_PATH"||V==="GIT_TEMPLATE_DIR")Y=!0}else if(V==="GIT_ALLOW_PROTOCOL"){if(U||G.split(":").includes("ext"))Y=!0}else if(V==="GIT_CONFIG_PARAMETERS"){let j=U?null:V3(G);if(j===null)Y=!0;else for(let[N,L]of j)X(N,L??"true")}else if(/^GIT_CONFIG_(?:KEY|VALUE)_\d+$/.test(V)){let j=V.replace(/^GIT_CONFIG_(?:KEY|VALUE)_/,""),N=K.get(j)??{};if(V.startsWith("GIT_CONFIG_KEY_"))N.key=G;else N.value=G;if(U)N.opaque=!0;K.set(j,N)}}for(let B of K.values()){if(B.key===void 0)continue;if(B.opaque)Q(`${B.key}=`,!0);else X(B.key,B.value)}if(J.length===0&&!Y)return null;return{programs:J,unresolved:Y}}function SZ(Z){if(/^~/.test(Z))return null;let z="";for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return null;z+=Z.slice($+1,Y),$=Y}else if(J==="$"||J==="`")return null;else if(J==='"'){let Y=$+1;for(;Y<Z.length&&Z[Y]!=='"';Y++){let X=Z[Y];if(X==="$"||X==="`")return null;if(X==="\\"&&Y+1<Z.length&&/[$\x60"\\\n]/.test(Z[Y+1])){if(Z[++Y]!==`
|
|
4
|
-
`||
|
|
5
|
-
`));if(
|
|
6
|
-
`,
|
|
7
|
-
`)return!1;if(
|
|
8
|
-
`)return!1;if(
|
|
9
|
-
`)){let
|
|
10
|
-
`))return!1;
|
|
11
|
-
`||!
|
|
12
|
-
`;
|
|
13
|
-
`||
|
|
14
|
-
`,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function
|
|
15
|
-
`?"":`\\${
|
|
16
|
-
`,
|
|
17
|
-
`,
|
|
18
|
-
`,
|
|
19
|
-
`&&
|
|
20
|
-
`,
|
|
21
|
-
`){if(
|
|
22
|
-
`,
|
|
23
|
-
`,
|
|
24
|
-
`||
|
|
25
|
-
`))};return
|
|
26
|
-
`))};if(!J.trustworthy){let K=UZ(Z);return K===Z?$:{...NZ(K,z),trustworthy:!1}}let X=[],Q=(K,B=$.refusals)=>{if(K.kind==="refuse")B.push({reason:K.reason});else if(K.kind==="rm"&&K.handoff)$.handoffHits.push(K.hit);else if(K.kind==="rm"){if($.rmHits.push(K.hit),K.protectedReason)$.protectedHits.push({reason:K.protectedReason})}},H=Y.cwd;for(let K of J.segments){let B=x(K),M=S0(K),V=B<0?{kind:"none"}:y0(K,B,H,Y);if(V.kind!=="cd")Q(V);let G=(U)=>U!==null&&U>=0&&$0(K.words[U].text);if(M===null||G(B)||G(M)){if(K.words.some((U,j)=>!K.redirects.has(j)&&(A0(y0(K,j,H,Y))||p3(U.text))))X.push({reason:$4})}else if(M>=0&&M!==B){let U=y0(K,M,H,Y);if(A0(U))if(A0(V))X.push({reason:Y4});else Q(U,X)}if(V.kind==="cd")H=V.cwd}if(Y.depth<3)for(let K of J.substitutions){let B=NZ(K,{cwd:H,home:Y.home,depth:Y.depth+1});if(B.rmHits.length>0||B.refusals.length>0||B.handoffHits.length>0||B.protectedHits.length>0||!B.trustworthy&&i(K)){$.refusals.push({reason:"This command runs a delete inside a command substitution `$(\u2026)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(J.substitutions.some((K)=>i(K)))$.refusals.push({reason:"This command nests a delete inside command substitutions deeper than this hook will follow. Run the delete as a separate `rm -- <path>` command."});return $.refusals.push(...X),$}function Q4(Z){return Z.words.map((z)=>z.text).join(" ")}function f0(Z,z){let $=z+1;while($<Z.words.length){let J=R(Z.words[$].text);if(!J.startsWith("-"))return J;if($++,g3.has(J))$++}return null}function K4(Z,z){if(Z.words.slice(z+1).map((J)=>R(J.text)).includes("--cached"))return!0;return u1(Z,z)}function u1(Z,z){let $=Z.words.slice(z+1).map((J)=>R(J.text));return $.includes("-n")||$.includes("--dry-run")}function y1(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function H4(Z,z,$,J){let Y=J?["/usr/bin/env","-i",`HOME=${J.home}`,`PATH=${J.path}`,`HASNA_TRASH_AGENT=${J.agent}`,J.runtime,"--config=/dev/null","--no-env-file","--no-macros","--no-install",$,"guard"].map(y1).join(" "):`${y1($)} guard`,X=[...z].sort((H,K)=>K.word.start-H.word.start),Q=Z;for(let H of X)Q=`${Q.slice(0,H.word.start)}${Y}${Q.slice(H.word.end)}`;return Q}function B4(Z,z,$,J,Y){if(!z||z===Z)return!1;if($.length===0)return!1;let X=NZ(z,{cwd:J,home:Y});if(!X.trustworthy)return!1;if(X.rmHits.length>0||X.handoffHits.length>0)return!1;return X.refusals.length===0}function M4(Z,z){let $={};for(let[J,Y]of Object.entries(Z??{}))$[J]=Y;if($.command=z,typeof $.description!=="string"||$.description.trim()==="")$.description=R3;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=y3;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function V4(Z,z,$,J,Y){if(typeof Z.command!=="string"||Z.command.trim()==="")return!1;if(typeof Z.description!=="string"||Z.description.trim()==="")return!1;if(typeof Z.timeout!=="number"||!Number.isFinite(Z.timeout)||Z.timeout<=0)return!1;if(typeof Z.run_in_background!=="boolean")return!1;if("dangerouslyDisableSandbox"in Z&&typeof Z.dangerouslyDisableSandbox!=="boolean")return!1;return B4(z,Z.command,$,J,Y)}function G4(Z){let z=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return b(Z,x1).segments.some((J)=>{let Y=S0(J);return[x(J),...Y===null?[]:[Y]].some((X)=>{if(J.words.slice(0,X<0?J.words.length:X).some((K)=>f1.test(R(K.text))||z.has(WZ(K.text))))return!0;if(X<0)return!1;let H=J.words[X];return z.has(WZ(H.text))||/^\s*\(\s*\)\s*\{/.test(Z.slice(H.end))})})}function u(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function U4(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function j4(Z){try{if(Z.inspectTrash){let z=Z.inspectTrash();return z.ok?{path:z.path,error:null}:{path:null,error:`${z.code}: ${N1[z.code]}`}}return{path:Z.findTrash(),error:null}}catch(z){return{path:null,error:z instanceof Error?z.message:String(z)}}}var W4="[trash-guard] No verified @hasna/trash guard was found on PATH. This deletion is refused. Install the current @hasna/trash package with Bun and run its setup; the operating-system trash utility is not a compatible guard.",R1="[trash-guard] The rewrite of this command did not verify (the delete could not be redirected cleanly), so the command is refused rather than run unredirected. Re-run the delete as a plain `rm -- <path>` command.";function v1(Z,z){if(Z.refusals.length>0)return u(`[trash-guard] ${Z.refusals[0].reason}`);if(Z.protectedHits.length>0)return u(`[trash-guard] ${Z.protectedHits[0].reason}`);if(!Z.trustworthy)return i(z)?u("[trash-guard] This command could not be parsed to the end (unterminated quote, substitution or here-document), so a delete inside it cannot be redirected. Re-run the delete as a plain `rm -- <path>` command."):{continue:!0};if(Z.rmHits.length===0){if(Z.handoffHits.some(($)=>$.cwdOnly))return u("[trash-guard] This delete runs from inside a protected repository checkout but names only paths outside it. Run it from outside the checkout (`cd /tmp && rm -- <path>`), where it is redirected into trash.");return{continue:!0}}if(Z.handoffHits.length>0)return u("[trash-guard] This command mixes a delete under the protected repo-checkout roots (owned by workspace-repos-guard) with a delete outside them, and a partial rewrite would leave one of them unredirected. Re-run them as separate commands, so each delete is handled by the hook that owns it.");return null}function l1(Z,z){if(Z.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(Z.tool_name??"")){let j=Z.tool_input?.command;if(typeof j!=="string")return u("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(j))return u("[trash-guard] Delete File would bypass recoverable deletion. First use `trash put -- <path>` or the trash_put MCP tool, then submit any remaining edits without the deletion block.");return{continue:!0}}if(Z.tool_name!=="Bash")return{continue:!0};if(typeof Z.tool_input?.command!=="string")return u("[trash-guard] The Bash tool call carried no readable `command`, so this hook cannot verify what would run. Refusing a call it cannot verify. Re-run the delete explicitly as `rm -- <path>` so it can be redirected into trash.");let J=GZ(Z);if(!J.trim())return{continue:!0};let Y=()=>NZ(J,{cwd:z.cwd,home:z.home}),X=(j)=>j.rmHits.map((N)=>N.word.start).join(),Q=(j)=>j()||!!YZ(J,j),H=Y(),K=v1(H,J),B=YZ(J,()=>{let j=Y();return{result:j,verdict:v1(j,J)}});if(B){let{result:j,verdict:N}=B;if(N&&!("continue"in N))return N;if(!N&&(!K||("continue"in K))&&X(j)!==X(H))return u(R1)}if(K)return K;let M=j4(z);if(M.error!==null)return u(`[trash-guard] The guard could not resolve the \`trash\` binary (${M.error}), so this \`rm\` cannot be redirected into a recoverable delete \u2014 and an unrecoverable delete is never allowed, so the command is refused rather than run. Fix the environment (PATH, permissions) and re-run the same command.`);if(M.path===null)return u(W4);let V=M.path;if(z.execution&&Q(()=>G4(J)))return u("[trash-guard] A deletion combined with shell environment changes cannot use the verified native execution context. Run the deletion as a separate plain rm command.");let G=H4(J,H.rmHits,V,z.execution),U=M4(Z.tool_input,G);if(z.execution)U.hasna_execution="hasna.hooks.execution.v1";if(Q(()=>!V4(U,J,H.rmHits,z.cwd,z.home)))return u(R1);return U4(U)}import{closeSync as N4,constants as m1,fstatSync as F4,lstatSync as _4,openSync as D4,readFileSync as T4,statSync as I4}from"fs";import{homedir as t1}from"os";import{dirname as k0,isAbsolute as e1,join as _Z,normalize as DZ,relative as q4,resolve as cZ,sep as u0}from"path";var C4=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),P4=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),O4=["hasna","hasnaxyz","hasna-products"],lZ="workspace-repos-guard";function L4(Z){return _Z(Z,".hasna","repos","clones")}function A4(Z){return _Z(Z,"workspace","repos")}function Z2(Z){return[L4(Z),A4(Z)]}function y4(Z){return _Z(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var R4=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function x0(Z){let z=process.getuid?.();return z!==void 0&&(Z.uid===0||Z.uid===z)&&(Z.mode&18)===0}function v4(Z){let z=y4(Z),$;try{let Y=D4(z,m1.O_RDONLY|m1.O_NOFOLLOW);try{let Q=F4(Y);if(!Q.isFile()||!x0(Q)||Q.size>4096)return null;$=T4(Y,"utf8")}finally{N4(Y)}let X=DZ(Z);for(let Q=k0(z);Q!==X;Q=k0(Q)){let H=_4(Q);if(!H.isDirectory()||!x0(H)||Q===k0(Q))return null}if(!x0(I4(X)))return null}catch{return null}let J=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return J.length>0&&J.every((Y)=>R4.test(Y))?new Set(J):null}function b4(Z=process.env,z=t1()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((J)=>J.trim()).filter(Boolean));return v4(z)??new Set(O4)}function h0(Z,z,$,J){if(J==="read")return{blocked:!1};let Y=q4(z,Z);if(Y===""){if(J==="delete")return{blocked:!0,reason:`[${lZ}] delete of the protected repo-checkout root is forbidden: ${z}`};return{blocked:!0,reason:`[${lZ}] writes directly to the protected repo-checkout root are forbidden: ${z}`}}if(Y.startsWith(`..${u0}`)||Y===".."||e1(Y))return{blocked:!1};let X=Y.split(u0).filter(Boolean);if(J==="delete")return{blocked:!0,reason:`[${lZ}] delete under the protected repo-checkout root (${z}) is forbidden at any depth: ${Z}`};if(X.length<=1)return{blocked:!0,reason:`[${lZ}] writing would create a top-level entry directly under the protected repo-checkout root (${z}); only GitHub-org folders belong there: ${Z}`};let Q=X[0];if(!$.has(Q))return{blocked:!0,reason:`[${lZ}] '${Q}' is not an allowed GitHub org under the protected repo-checkout root (${z}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var $2=/\b(?:-o|--output|-O|--output-document|-out)\b/,E4=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,S4=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function J2(Z){return Z.replace(E4," ")}function f4(Z){let z=[],$=null,J=0,Y=0,X=!1,Q=0;for(let H=0;H<Z.length;H++){let K=Z[H];if($==="'"){if(K==="'")$=null;continue}if(K==="\\"){H++;continue}if(K==="("){J++;continue}if(K===")"){if(--J<0)return[Z];continue}if(K==="$"&&Z[H+1]==="{"){Y++,H++;continue}if(K==="}"&&Y>0){Y--;continue}if(K==="`"){X=!X;continue}if($==='"'){if(K==='"')$=null;continue}if(K==="'"||K==='"'){$=K;continue}if(K!=="|"||J>0||Y>0||X||Z[H-1]===">")continue;if(z.push(Z.slice(Q,H)),Z[H+1]==="&")H++;Q=H+1}if($||J!==0||Y!==0||X)return[Z];return z.push(Z.slice(Q)),z}function k4(Z){let z=[],$="",J="",Y=null,X=!1,Q=()=>{if(!X)return;let H=J.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),K=$.startsWith("~")&&!/^~(?:\/|$)/.test(J);z.push({text:K?`./${$}`:$,opaque:/[$\x60*?[]/.test(H)||/[()]/.test(H)||rZ(J)}),$="",J="",X=!1};for(let H=0;H<Z.length;H++){let K=Z[H];if(Y==="'"){if(K==="'")Y=null;else $+=K;J+=K;continue}if(K==="\\"&&H+1<Z.length){let B=Z[H+1];$+=Y==='"'&&!/[$\x60"\\\n]/.test(B)?K+B:Y==='"'&&B===`
|
|
27
|
-
`&&!
|
|
28
|
-
`)
|
|
29
|
-
`),
|
|
30
|
-
`));for(let
|
|
31
|
-
`))?null:{outer:
|
|
32
|
-
`),bodies:Y}}var z5="/";function Q0(Z,z,$){if(!Z)return[];let J=b(Z).trustworthy?Z:UZ(Z),Y=J5(Z);return[...J===Z?[]:Q0(J,z,$),...Y?[...r1(Y.outer,z,$),...Y.bodies.flatMap((X)=>Q0(X,z,z5))]:r1(Z,z,$)]}var Y5=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,X5=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function n1(Z,z,$=!1){let J=[],Y=0;for(let H of z)J.push(Y),Y+=H.length;let X=b(Z);if(!X.trustworthy||!$&&X.substitutions.length>0)return null;let Q=X.segments.flatMap((H)=>H.words).filter((H)=>z.some((K,B)=>B%2===1&&J[B]<H.end&&J[B]+K.length>H.start));return Q.length>0?{lexed:X,offsets:J,words:Q}:null}function o1(Z,z,$=[]){if(p0(z)!=="read")return!1;let J=x(Z),Y=Z.words.filter((M,V)=>!Z.redirects.has(V)),X=zZ(Y.map((M)=>c0(M.text)));if(X===null)return!1;let Q=[J<0?1/0:J,X.index<0?1/0:Z.words.indexOf(Y[X.index])];if(Z.words.some((M,V)=>V<Math.max(...Q)&&!Z.redirects.has(V)&&EZ.test(R(M.text))))return!1;if([J<0?null:Z.words[J].text,X.index<0?null:Y[X.index].text].every((M)=>M===null||H2.has(c(R(M)))))return!0;let K=Y.filter((M)=>!$.includes(M)),B=K.map((M)=>R(M.text));return QZ(K.map((M)=>M.text).join(" "))==="read"&&QZ(B.join(" "))==="read"&&!B.some((M)=>Y2.has(M))}function Q5(Z,z,$,J){let Y=(X)=>X.start<J&&X.end>$;if(!z.words.some(Y))return!1;return z.lexed.segments.filter((X)=>X.words.some(Y)).some((X)=>Y0(X))}var a1=(Z,z)=>Z.slice(z.words[0].start,z.words[z.words.length-1].end);function K5(Z,z,$,J){let Y=(Q)=>Q.start<J&&Q.end>$,X=z.words.filter(Y);if(X.length===0||X.some((Q)=>!X5.test(Q.text)))return!1;for(let Q of z.lexed.segments.filter((H)=>H.words.some(Y)))if(!o1(Q,a1(Z,Q),z.words))return!1;for(let Q of X){let H=Q.text.slice(1,-1);if(H.includes("<<"))return!1;let K=b(H);if(!K.trustworthy||K.substitutions.length>0)return!1;if(!K.segments.every((B)=>o1(B,a1(H,B))))return!1}return!0}function r1(Z,z,$){if(!Z)return[];let J=Z2(z),Y=(U)=>J.some((j)=>U===j||U.startsWith(`${j}${u0}`)),X=Z.split(Y5),Q=n1(Z,X),H=Q??n1(Z,X,!0),K=[],B=[$],M=new Set([$]),V=!0,G=[];for(let U=0;U<X.length;U+=2){let j=U===0?"":X[U-1].trim();if(j==="||")V=!1;else if(j!=="&&")V=!0;if(j!=="&&"||!V)B=[...M];let N=X[U],L=(N.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,y=(N.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let _=0;_<L;_++)G.push({current:[...B],reachable:new Set(M),certain:V});let E=w4(N),l=Q!==null&&K5(Z,Q,Q.offsets[U],Q.offsets[U]+N.length),q=!l&&(H!==null&&Q5(Z,H,H.offsets[U],H.offsets[U]+N.length)||X0(N.trim())),F=E.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),A=F?null:E.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(A){for(let _ of d1(A[1],B,z)??[])M.add(_);V=!1,B=[...M]}let h=l0(z),w=J.map((_)=>l0(_.slice(z.length+1))).join("|"),qZ=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${h}"*)/(?:${w})`),V1=new RegExp(`(${qZ.source})([^\\s"';&|<>()\`]*|$)`,"g"),G1=(_)=>{let f=[],g;V1.lastIndex=0;while((g=V1.exec(_))!==null)f.push(DZ(pZ(g[0],z)).replace(/\/+$/,""));return f},U1=H===null?0:H.offsets[U],j1=(_)=>_.start<U1+N.length&&_.end>U1,E2=H!==null&&H.words.some(j1)?mZ({segments:H.lexed.segments.filter((_)=>_.words.some(j1))}):[N.trim(),E].flatMap((_)=>{let f=b(_);if(!f.trustworthy)f=b(UZ(_));return f.trustworthy?mZ(f):[]}),j0=f4(E).map((_,f)=>{let g=f===0?[...new Set(E2)]:[],CZ=!1,PZ=J2(_).replace(S4,(N0,BZ)=>{if(!BZ||/[$\x60]/.test(BZ))CZ=!0;if(BZ)g.push(BZ);return" "}),OZ=l?"read":q?"delete":p0(PZ);return{commandPart:PZ,operands:g,op:CZ&&OZ==="read"?"write":OZ}}),S2=j0.some((_)=>_.op==="delete")?"delete":j0.some((_)=>_.op==="write")?"write":"read",W0=B.filter(Y);if(q)for(let _ of W0)K.push({path:_,op:"delete"});for(let _ of j0){let f=!1;for(let k of G1(_.commandPart))f=!0,K.push({path:k,op:S2});for(let k of _.operands){let n=G1(k);for(let p of n)K.push({path:p,op:"write"});if(n.length>0)continue;for(let p of W0)K.push({path:DZ(cZ(p,pZ(k,z))),op:"write"})}if(f||_.op==="read")continue;let g=k4(_.commandPart),CZ=u4(_.commandPart,g),PZ=c(g[CZ]?.text??""),OZ=g.slice(CZ+1),N0=((PZ==="trash"?d4(OZ):null)??l4(PZ,OZ)).map((k)=>k.opaque?".":k.text),BZ=_.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(_.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(_.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(_.commandPart),LZ=[];if(BZ)for(let k of N0.length>0?N0:["."])LZ.push({operand:k,op:_.op});else{let k=_.commandPart.match(g4),n=g.at(-1);if(LZ.push({operand:k?k[1]:!n||n.opaque?".":n.text,op:_.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(_.commandPart))g.forEach((p,W1)=>{let MZ,F0=p.text.match(/^-[A-Za-z]*?t(.*)$/),dZ=p.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(F0&&!p.text.startsWith("--"))MZ=F0[1]?{text:F0[1],opaque:p.opaque}:g[W1+1];else if(dZ&&"--target-directory".startsWith(dZ[1]))MZ=dZ[2]!==void 0?{text:dZ[2],opaque:p.opaque}:g[W1+1];if(MZ)LZ.push({operand:MZ.opaque||!MZ.text?".":MZ.text,op:_.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(_.commandPart))LZ.push({operand:".",op:_.op})}for(let k of W0)for(let{operand:n,op:p}of LZ)K.push({path:DZ(cZ(k,pZ(n,z))),op:p})}if(F){let _=d1(F[1],B,z);if(_){for(let f of _)M.add(f);if(V)B=_}else V=!1}for(let _=0;_<y&&G.length>0;_++)({current:B,reachable:M,certain:V}=G.pop())}return K}var H5=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function B5(Z,z){let $=[],J;while((J=H5.exec(Z))!==null){let Y=J[1]==="Delete File"?"delete":"write";$.push({path:DZ(cZ(z,J[2])),op:Y})}return $}function V2(Z,z={}){let $=[];if(Z.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:$};let J=typeof Z.tool_name==="string"?Z.tool_name:"",Y=z.home??t1(),X=Z2(Y),Q=b4(process.env,Y);if(J==="Bash"){let G=GZ(Z);if(!G)return{output:{continue:!0},warnings:$};let U=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd(),j=Q0(G,Y,U);j.unshift(...YZ(G,()=>Q0(G,Y,U))??[]);for(let N of j)for(let L of X){let y=h0(N.path,L,Q,N.op);if(y.blocked)return{output:{decision:"block",reason:y.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let H=Z.tool_input??{},K=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(P4.has(J)){let G=typeof H.patch==="string"?H.patch:"";if(!G)return{output:{continue:!0},warnings:$};let U=B5(G,K);for(let j of U)for(let N of X){let L=h0(j.path,N,Q,j.op);if(L.blocked)return{output:{decision:"block",reason:L.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!C4.has(J))return{output:{continue:!0},warnings:$};let B=typeof H.file_path==="string"?H.file_path:typeof H.path==="string"?H.path:typeof H.notebook_path==="string"?H.notebook_path:null;if(!B)return{output:{continue:!0},warnings:$};let M=pZ(B,Y),V=e1(M)?DZ(M):cZ(K,M);for(let G of X){let U=h0(V,G,Q,"write");if(U.blocked)return{output:{decision:"block",reason:U.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var M5=new Set(["id","node_id","databaseId","fullDatabaseId","number","state","state_reason","stateReason","status","conclusion","bucket","name","login","sha","oid","abbreviatedOid","ref","headRefName","baseRefName","headRefOid","baseRefOid","head_sha","headSha","head_branch","headBranch","merged","mergeable","mergeable_state","mergeStateStatus","draft","isDraft","locked","isLocked","title","displayTitle","display_title","created_at","updated_at","closed_at","merged_at","started_at","completed_at","submitted_at","pushed_at","published_at","createdAt","updatedAt","closedAt","mergedAt","startedAt","completedAt","submittedAt","pushedAt","publishedAt","tag_name","tagName","total_count","totalCount","count","additions","deletions","changes","changed_files","changedFiles","filename","path","event","workflow","workflowName","workflow_id","workflowDatabaseId","run_id","run_number","run_attempt","attempt","check_suite_id","default_branch","defaultBranch","full_name","fullName","nameWithOwner","private","isPrivate","visibility","archived","isArchived","fork","isFork","isRequired","is_required","required","context","type","__typename","role","permission","size","reviewDecision","author_association","authorAssociation","isCrossRepository","maintainerCanModify","maintainer_can_modify","commentsCount","language","digest","size_in_bytes","run_started_at","date","wait_timer","ahead_by","behind_by","total_commits","expired","current_user_can_approve","environment","html_url"]),V5=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),W2=new Set(["length","utf8bytelength","not","type","any","all","isempty","empty","test","startswith","endswith","contains","inside","has","in","index","rindex","indices","floor","ceil","round","fabs","sqrt","isinfinite","isnan","isnormal","infinite","nan","true","false","null"]),N2=new Set(["tostring","tojson","ascii_downcase","ascii_upcase","ltrimstr","rtrimstr","trim","ltrim","rtrim","sort","unique","reverse","first","last","min","max","add","flatten","join","split","values","nulls","strings","numbers","booleans","arrays","objects","iterables","scalars","sort_by","group_by","unique_by","min_by","max_by","select","limit","to_entries","from_entries"]),G5=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),U5=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class s0 extends Error{}var P=()=>{throw new s0};function i0(Z,z){let $=[],J="",Y=z+1;while(Y<Z.length){let X=Z[Y];if(X==='"'){if(J)$.push(J);return{end:Y+1,parts:$}}if(X==="\\"){let Q=Z[Y+1];if(Q==="("){let H=1,K=Y+2;while(K<Z.length&&H>0){let B=Z[K];if(B==='"'){K=i0(Z,K).end;continue}if(B==="(")H++;else if(B===")")H--;K++}if(H!==0)P();if(J)$.push(J),J="";$.push({src:Z.slice(Y+2,K-1)}),Y=K;continue}if(Q===void 0)P();J+=Q,Y+=2;continue}J+=X,Y++}return P()}function F2(Z){let z=[],$=0,J=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let Y=Z[$];if(/\s/.test(Y)){$++;continue}if(Y==="#")P();if(Y==='"'){let K=i0(Z,$);z.push({t:"str",parts:K.parts}),$=K.end;continue}if(Y==="."){if(Z[$+1]===".")P();let K=/^[A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($+1));if(K){z.push({t:"field",name:K[0]}),$+=1+K[0].length;continue}if(Z[$+1]==='"'){let B=i0(Z,$+1);if(B.parts.some((M)=>typeof M!=="string"))P();z.push({t:"field",name:B.parts.join("")}),$=B.end;continue}z.push({t:"dot"}),$++;continue}if(Y==="$"||Y==="@"){let K=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($));if(!K||Y==="$")P();z.push({t:"fmt",name:K[0]}),$+=K[0].length;continue}let X=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(Z.slice($));if(X){z.push({t:"num"}),$+=X[0].length;continue}let Q=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(Z.slice($));if(Q){z.push({t:"ident",name:Q[0]}),$+=Q[0].length;continue}let H=J.find((K)=>Z.startsWith(K,$));if(!H)P();z.push({t:"op",v:H}),$+=H.length}return z}var j5=new Set(["if","then","elif","else","end","as","def","reduce","foreach","try","catch","label","import","include","and","or","__loc__","error","input","inputs","debug","stderr","env","halt","halt_error","input_filename","input_line_number","recurse","paths","leaf_paths","getpath","setpath","delpaths","del","path","splits","sub","gsub","capture","match","scan","keys","keys_unsorted","map_values","with_entries","tostream","fromstream","truncate_stream","walk","tonumber","implode","explode","ascii","fromjson"]);class n0{tokens;at=0;constructor(Z){this.tokens=Z}parse(){if(this.tokens.length===0)P();let Z=this.pipe();if(this.at!==this.tokens.length)P();return Z}peek(){return this.tokens[this.at]}isOp(Z){let z=this.peek();return!!z&&z.t==="op"&&z.v===Z}isIdent(Z){let z=this.peek();return!!z&&z.t==="ident"&&z.name===Z}expectOp(Z){if(!this.isOp(Z))P();this.at++}pipe(){let Z=this.comma();if(this.isIdent("as"))P();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.pipe()};return Z}comma(){let Z=this.alt();while(this.isOp(","))this.at++,Z={k:"comma",a:Z,b:this.alt()};return Z}alt(){let Z=this.or();if(this.isOp("//"))return this.at++,{k:"alt",a:Z,b:this.alt()};return Z}or(){let Z=this.and();while(this.isIdent("or"))this.at++,Z={k:"bool",a:Z,b:this.and()};return Z}and(){let Z=this.cmp();while(this.isIdent("and"))this.at++,Z={k:"bool",a:Z,b:this.cmp()};return Z}cmp(){let Z=this.add();for(let z of["==","!=","<=",">=","<",">"])if(this.isOp(z))return this.at++,{k:"bool",a:Z,b:this.add()};for(let z of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(z))P();return Z}add(){let Z=this.mul();while(this.isOp("+")||this.isOp("-"))this.at++,Z={k:"arith",a:Z,b:this.mul()};return Z}mul(){let Z=this.unary();while(this.isOp("*")||this.isOp("/")||this.isOp("%"))this.at++,Z={k:"arith",a:Z,b:this.unary()};return Z}unary(){if(this.isOp("-"))return this.at++,{k:"neg",of:this.postfix()};return this.postfix()}objectValue(){let Z=this.unary();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.objectValue()};return Z}postfix(){let Z=this.primary();for(;;){let z=this.peek();if(!z)return Z;if(z.t==="field"){this.at++,Z={k:"field",name:z.name,of:Z};continue}if(z.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(z.t==="op"&&z.v==="?"){this.at++,Z={k:"opt",of:Z};continue}if(z.t==="op"&&z.v==="["){Z=this.bracket(Z);continue}return Z}}bracket(Z){if(this.expectOp("["),this.isOp("]"))return this.at++,{k:"iter",of:Z};if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}let z=this.pipe();if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}return this.expectOp("]"),{k:"index",of:Z,key:z}}primary(){let Z=this.peek();if(!Z)return P();switch(this.at++,Z.t){case"dot":return{k:"dot"};case"field":return{k:"field",name:Z.name};case"num":return{k:"lit"};case"str":return this.stringNode(Z.parts);case"fmt":{if(!U5.has(Z.name))P();let z=this.peek();if(z?.t==="str")return this.at++,{k:"fmt",name:Z.name,str:this.stringNode(z.parts)};return{k:"fmt",name:Z.name}}case"ident":{if(j5.has(Z.name))P();if(Z.name==="map"||W2.has(Z.name)||N2.has(Z.name)){let z=[];if(this.isOp("(")){this.at++,z.push(this.pipe());while(this.isOp(";"))this.at++,z.push(this.pipe());this.expectOp(")")}return{k:"call",name:Z.name,args:z}}return P()}case"op":{if(Z.v==="("){let z=this.pipe();return this.expectOp(")"),z}if(Z.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let z=this.pipe();return this.expectOp("]"),{k:"array",of:z}}if(Z.v==="{")return this.object();return P()}}return P()}stringNode(Z){let z=[];for(let $ of Z){if(typeof $==="string")continue;z.push(new n0(F2($.src)).parse())}return z.length===0?{k:"str",parts:z,text:Z.join("")}:{k:"str",parts:z}}object(){let Z=[];if(this.isOp("}"))return this.at++,{k:"object",entries:Z};for(;;){let z=this.peek();if(!z)P();this.at++;let $;if(z.t==="ident")$=z.name;else if(z.t==="str"){if(z.parts.some((J)=>typeof J!=="string"))P();$=z.parts.join("")}else P();if(this.isOp(":"))this.at++,Z.push({key:"static",value:this.objectValue()});else Z.push({key:"static",value:{k:"field",name:$}});if(this.isOp(",")){this.at++;continue}return this.expectOp("}"),{k:"object",entries:Z}}}}function o0(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(o0);return Z==="safe"||typeof Z==="object"&&M5.has(Z.leaf)}var iZ=(...Z)=>Z.every(o0)?"safe":"tainted";function d0(...Z){let z=[];for(let $ of Z)if(typeof $==="object"&&"union"in $)z.push(...$.union);else z.push($);return z.length===1?z[0]:{union:z}}function K0(Z,z){return typeof Z==="object"&&"union"in Z?d0(...Z.union.map(z)):z(Z)}var H0=(Z)=>typeof Z==="object"&&("leaf"in Z)&&V5.has(Z.leaf),t=(Z)=>K0(Z,(z)=>z==="safe"?"safe":z==="tainted"||H0(z)?"tainted":"unknown");function G2(Z){return Z.k==="lit"||Z.k==="str"&&Z.parts.length===0||Z.k==="call"&&["true","false","null"].includes(Z.name)&&Z.args.length===0}function U2(Z,z,$){return K0(Z,(J)=>{if(J==="safe"||J==="tainted")return J;if(H0(J))return"tainted";if(J==="root"&&$.rootScalars.has(z))return"safe";return{leaf:z}})}function O(Z,z,$){switch(Z.k){case"dot":return z;case"field":return U2(Z.of?O(Z.of,z,$):z,Z.name,$);case"iter":return t(O(Z.of,z,$));case"index":{let J=O(Z.of,z,$);if(Z.key.k==="str"&&Z.key.text!==void 0)return U2(J,Z.key.text,$);if(Z.key.k==="lit")return t(J);return O(Z.key,z,$),"tainted"}case"slice":return K0(O(Z.of,z,$),(J)=>J==="root"?"unknown":H0(J)?"tainted":J);case"opt":return O(Z.of,z,$);case"lit":return"safe";case"str":return iZ(...Z.parts.map((J)=>O(J,z,$)));case"fmt":return Z.str?O(Z.str,z,$):z;case"array":return Z.of?iZ(O(Z.of,z,$)):"safe";case"object":return iZ(...Z.entries.map((J)=>O(J.value,z,$)));case"pipe":return O(Z.b,O(Z.a,z,$),$);case"comma":return d0(O(Z.a,z,$),O(Z.b,z,$));case"alt":return d0(O(Z.a,z,$),O(Z.b,z,$));case"bool":return O(Z.a,z,$),O(Z.b,z,$),"safe";case"arith":return iZ(O(Z.a,z,$),O(Z.b,z,$));case"neg":return O(Z.of,z,$);case"call":return W5(Z,z,$)}}var j2=(Z)=>K0(Z,(z)=>z==="root"?"unknown":H0(z)?"tainted":z);function W5(Z,z,$){let{name:J,args:Y}=Z;if(G5.has(J)&&J!=="limit"&&!Y.every(G2))P();switch(J){case"map":if(Y.length!==1)P();return iZ(O(Y[0],t(z),$));case"select":if(Y.length!==1)P();return O(Y[0],z,$),z;case"limit":if(Y.length!==2||!G2(Y[0]))P();return O(Y[1],z,$);case"first":case"last":if(Y.length>1)P();return Y.length===1?O(Y[0],z,$):t(z);case"min":case"max":return t(z);case"sort_by":case"group_by":case"unique_by":if(Y.length!==1)P();return O(Y[0],t(z),$),j2(z);case"min_by":case"max_by":if(Y.length!==1)P();return O(Y[0],t(z),$),t(z);case"any":case"all":case"isempty":for(let X of Y)O(X,"unknown",$);return"safe"}if(W2.has(J))return"safe";if(N2.has(J))return j2(z);return P()}function _2(Z,z={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new n0(F2(Z)).parse();return o0(O($,"root",{rootScalars:z.rootScalars??new Set}))}catch($){if($ instanceof s0)return!1;return!1}}var Y1="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",I={refused:!1},T=(Z)=>({refused:!0,rule:Z}),a0=new Set(["additions","assignees","author","baseRefName","baseRefOid","changedFiles","closed","closedAt","createdAt","deletions","files","fullDatabaseId","headRefName","headRefOid","headRepository","headRepositoryOwner","id","isCrossRepository","isDraft","labels","maintainerCanModify","mergeCommit","mergeStateStatus","mergeable","mergedAt","mergedBy","number","potentialMergeCommit","reactionGroups","reviewDecision","reviewRequests","state","title","updatedAt","url"]),r0=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),D2=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),T2=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),N5=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),F5=new Set(["author","committer","id","parents","repository","sha","url"]),_5=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function C2(Z){let z=[];for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="\\"){$++;continue}if(J==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return!1;$=Y;continue}if(J==='"'){$++;while($<Z.length&&Z[$]!=='"')$+=Z[$]==="\\"?2:1;continue}if(J==="{"){z.push({list:!1});continue}if(z.length===0)continue;if(J===","||J==="."&&Z[$+1]===".")z[z.length-1].list=!0;else if(J==="}"&&z.pop().list)return!0}return!1}function TZ(Z){let z="",$=!1,J=0,Y=(X)=>Z[X]==="`"||Z[X]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(Z[X+1]??"");while(J<Z.length){let X=Z[J];if(X==="\\"){z+=Z[J+1]??"",J+=2;continue}if(X==="$"&&Z[J+1]==="'"){$=!0,z+=X,J++;continue}if(X==="'"){let Q=Z.indexOf("'",J+1);if(Q<0){$=!0,z+=Z.slice(J+1);break}z+=Z.slice(J+1,Q),J=Q+1;continue}if(X==='"'){J++;while(J<Z.length&&Z[J]!=='"'){if(Z[J]==="\\"&&/[$`"\\\n]/.test(Z[J+1]??"")){z+=Z[J+1],J+=2;continue}if(Y(J))$=!0;z+=Z[J],J++}if(J>=Z.length)$=!0;J++;continue}if(Y(J)||X==="*"||X==="?"||X==="[")$=!0;z+=X,J++}if(!$&&Z.includes("{")&&C2(Z))$=!0;return{value:z,opaque:$,raw:Z}}var KZ=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function Z1(Z,z="word"){let $=[],J=!1;for(let Y=0;Y<Z.length;Y++){let X=Z[Y];if(X==="\\"){Y++;continue}if(z==="word"&&X==="'"&&!J){let Q=Z.indexOf("'",Y+1);if(Q<0)return{bodies:$,complete:!1};Y=Q;continue}if(z==="word"&&X==='"'){J=!J;continue}if(X==="`"){let Q=Y+1;while(Q<Z.length&&Z[Q]!=="`")Q+=Z[Q]==="\\"?2:1;if(Q>=Z.length)return{bodies:$,complete:!1};$.push(Z.slice(Y+1,Q)),Y=Q;continue}if(X==="$"&&Z[Y+1]==="("){let Q=XZ(Z,Y+1);if(Q<0)return{bodies:$,complete:!1};$.push(Z.slice(Y+2,Q-1)),Y=Q-1}}return{bodies:$,complete:!0}}function IZ(Z,z){let $=new Set(z.values),J={flags:[],positionals:[]},Y=(X,Q)=>({value:X,opaque:Q.opaque,raw:Q.raw});for(let X=0;X<Z.length;X++){let Q=Z[X],H=Q.value;if(H==="--"){J.positionals.push(...Z.slice(X+1));break}if(H.startsWith("--")&&H.length>2){let K=H.indexOf("="),B=K>=0?H.slice(0,K):H;if(K>=0)J.flags.push({name:B,value:Y(H.slice(K+1),Q),inline:!0});else if($.has(B)){let M=Z[X+1];J.flags.push(M?{name:B,value:M}:{name:B,missing:!0}),X++}else J.flags.push({name:B});continue}if(H.startsWith("-")&&H.length>1){for(let K=1;K<H.length;K++){let B="-"+H[K],M=H.slice(K+1);if(M.startsWith("=")){J.flags.push({name:B,value:Y(M.slice(1),Q),inline:!0});break}if(!$.has(B)){J.flags.push({name:B});continue}if(M)J.flags.push({name:B,value:Y(M,Q),inline:!0});else{let V=Z[X+1];J.flags.push(V?{name:B,value:V}:{name:B,missing:!0}),X++}break}continue}J.positionals.push(Q)}return J}function S(Z,...z){let $=!1;for(let J of Z.flags){if(!z.includes(J.name))continue;if(!J.inline){$=!0;continue}let Y=J.value;$=!Y.opaque&&["1","t","T","TRUE","true","True"].includes(Y.value)}return $}var ZZ=(Z,...z)=>Z.flags.filter(($)=>z.includes($.name)),m=["-R","--repo","-q","--jq","-t","--template","--json"],HZ={"pr view":{values:m},"issue view":{values:m},"release view":{values:m},"discussion view":{values:[...m,"--after","-L","--limit","--order"]},"pr list":{values:[...m,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...m,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...m,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...m,"-L","--limit","-O","--order"]},"pr status":{values:m},"issue status":{values:m},"pr checks":{values:[...m,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...m,"--app","--assignee","--author","--author-date","--author-email","--author-name","--base","--checks","--closed","--commenter","--committer","--committer-date","--committer-email","--committer-name","--created","--hash","--head","--interactions","--involves","--label","--language","--limit","-L","--match","--mentions","--merged-at","--milestone","--no-assignee","--no-label","--no-milestone","--no-project","--order","--owner","--parent","--project","--reactions","--review","--review-requested","--reviewed-by","--sort","--state","--team-mentions","--tree","--updated","--visibility","--extension","--filename","--size","--forks","--good-first-issue","--help-wanted-issues","--number-topics","--stars","--topic","--followers","--include-forks","--license"]},"project item-list":{values:["--format","-L","--limit","--owner","-q","--jq","-t","--template","--query","--field","--field-id"]},api:{values:["-X","--method","-H","--header","-f","--raw-field","-F","--field","-q","--jq","-t","--template","-p","--preview","--input","--hostname","--cache"]},group:{values:["-R","--repo"]}},D5=new Set(["auth","browse","codespace","cs","gist","org","repo","skill","cache","run","workflow","co","agent-task","alias","attestation","completion","config","copilot","extension","ext","extensions","gpg-key","label","licenses","preview","ruleset","secret","ssh-key","variable","help","version","accessibility","actions","environment","exit-codes","formatting","mintty","reference","telemetry"]),T5=new Set(["pr","issue","release","discussion","search","project","api","status"]),I5=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),q5=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),C5=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),P5=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function G0(Z,z){let $=ZZ(Z,"--json"),J=[],Y=!1;for(let X of $){if(X.missing){if(z.appendsArgs)Y=!0;continue}if(!X.value)continue;if(X.value.opaque)Y=!0;J.push(...X.value.value.split(",").map((Q)=>Q.trim()).filter(Boolean))}return{present:$.length>0,opaque:Y,fields:J}}function X1(Z,z){if(S(Z,"--verbose")||ZZ(Z,"-t","--template").length>0)return!1;let $=ZZ(Z,"-q","--jq");return $.length>0&&$.every((J)=>J.value!==void 0&&!J.value.opaque&&_2(J.value.value,{rootScalars:z}))}function Q1(Z,z,$,J){let Y=G0(Z,$);if(Y.opaque)return T("unclassifiable");if(Y.fields.every((X)=>z.has(X)))return I;if($.debug)return T("debug-traffic");return X1(Z)?I:T(J)}function B0(Z,z,$,J,Y){let X=IZ(Z,HZ[z]);if(S(X,"-h","--help"))return I;if(S(X,"-w","--web"))return J.debug?T("debug-traffic"):I;if(Y&&S(X,"-c","--comments"))return T("view-comments");if(!G0(X,J).present)return T(J.debug?"debug-traffic":"view-human");return Q1(X,$,J,"json-composite")}function e(Z,z,$,J){let Y=IZ(Z,HZ[z]);if(S(Y,"-h","--help"))return I;if(J.debug&&(S(Y,"-w","--web")||!G0(Y,J).present))return T("debug-traffic");if(S(Y,"-w","--web"))return I;return Q1(Y,$,J,"json-composite")}function O5(Z,z){let $=IZ(Z,HZ["pr checks"]);if(S($,"-h","--help"))return I;if(z.debug)return T("debug-traffic");if(S($,"-w","--web"))return I;if(!G0($,z).present)return T("checks-human");return Q1($,_5,z,"checks-json")}function L5(Z){let z=new Set(HZ.group.values);for(let $=0;$<Z.length;$++){let J=Z[$].value;if(J==="--")return{sub:Z[$+1],rest:Z.slice($+2)};if(!J.startsWith("-")||J==="-")return{sub:Z[$],rest:[...Z.slice(0,$),...Z.slice($+1)]};if(z.has(J))$++}return{rest:Z}}function A5(Z,z,$){let{sub:J,rest:Y}=L5(z);if(!J)return $.appendsArgs?T("unclassifiable"):I;if(J.opaque)return T("unclassifiable");let X=J.value;if((Z==="pr"?I5:Z==="issue"?q5:Z==="release"?C5:Z==="discussion"?P5:new Set).has(X))return $.debug?T("debug-traffic"):I;if($.appendsArgs&&!(Z==="project"&&X!=="item-list"))return T("unclassifiable");switch(Z){case"pr":if(X==="view")return B0(Y,"pr view",a0,$,!0);if(X==="list"||X==="ls")return e(Y,"pr list",a0,$);if(X==="status")return e(Y,"pr status",a0,$);if(X==="checks")return O5(Y,$);if(X==="diff"){let H=IZ(Y,HZ["pr diff"]);if(S(H,"-h","--help"))return I;if($.debug)return T("debug-traffic");return S(H,"--patch")?T("composite-other"):I}return T("unclassifiable");case"issue":if(X==="view")return B0(Y,"issue view",r0,$,!0);if(X==="list"||X==="ls")return e(Y,"issue list",r0,$);if(X==="status")return e(Y,"issue status",r0,$);return T("unclassifiable");case"release":if(X==="view")return B0(Y,"release view",D2,$,!1);if(X==="list"||X==="ls")return e(Y,"release list",D2,$);return T("unclassifiable");case"discussion":if(X==="view")return B0(Y,"discussion view",T2,$,!0);if(X==="list"||X==="ls")return e(Y,"discussion list",T2,$);return T("unclassifiable");case"search":if(X==="prs"||X==="issues")return e(Y,"search",N5,$);if(X==="commits")return e(Y,"search",F5,$);if(X==="code"||X==="repos")return $.debug?T("debug-traffic"):I;return T("unclassifiable");case"project":{if($.debug)return T("debug-traffic");if(X!=="item-list")return I;let H=IZ(Y,HZ["project item-list"]);if(S(H,"-h","--help"))return I;let K=ZZ(H,"--format");if(K.some((B)=>!B.value||B.value.opaque))return T("unclassifiable");if(K.every((B)=>B.value.value!=="json"))return I;return X1(H)?I:T("composite-other")}}return T("unclassifiable")}var P2=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function y5(Z){let z=Z.value.trim(),$=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(z);if($){let X=$[1].toLowerCase(),Q=$[2]??"/";if(X==="api.github.com"||/^api\./.test(X))z=Q;else if(/^\/api\/v3(?:\/|$)/i.test(Q))z=Q.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(Q))z="graphql";else return null}z=z.replace(/[?#].*$/,"");let J=[],Y=[];for(let X of z.split("/")){let Q;try{Q=decodeURIComponent(X)}catch{return null}for(let H of Q.split("/")){if(H===""||H===".")continue;if(H===".."){J.pop(),Y.pop();continue}J.push(H.toLowerCase()),Y.push(Z.opaque&&/[$`]/.test(H)||/[*?[]/.test(H)||C2(H))}}return{segments:J,opaque:Y}}function R5(Z){let z=y5(Z);if(!z)return{kind:"unclassifiable",segments:[]};let{segments:$,opaque:J}=z,Y=(K)=>({kind:K,segments:$});if($.length===1&&$[0]==="graphql")return Y("graphql");if($.length===0)return Y(Z.opaque?"unclassifiable":"other");if(J[0])return Y("unclassifiable");let X,Q=[];if($[0]==="repos")X=$.slice(3),Q=J.slice(3);else if($[0]==="repositories")X=$.slice(2),Q=J.slice(2);if(X){if(($[0]==="repos"?J.slice(1,3):J.slice(1,2)).some(Boolean)){let B=J.findIndex(Boolean),M=$.findIndex((V,G)=>G>B&&!J[G]&&v5.has(V));return Y(M<0?"unclassifiable":I2($.slice(M),J.slice(M)))}return Y(I2(X,Q))}let H=$[0];if(H==="issues")return Y("sensitive");if(H==="user"&&$[1]==="issues")return Y("sensitive");if(H==="orgs"&&$[2]==="issues")return Y("sensitive");if(H==="search")return Y($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&J[1]?"unclassifiable":"other");if(H==="events"||H==="networks")return Y("sensitive");if((H==="users"||H==="orgs")&&$.slice(2).some((K)=>K==="events"||K==="received_events"||K==="discussions"))return Y("sensitive");if((H==="users"||H==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return Y("sensitive");if(H==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||H==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return Y("sensitive");if(H==="teams"&&$.includes("discussions"))return Y("sensitive");if(H==="projects"&&$.includes("cards"))return Y("sensitive");if(J.some(Boolean))return Y($.some((K)=>K==="events"||K==="discussions"||K==="issues")?"sensitive":"unclassifiable");return Y("other")}var v5=new Set([...P2,"branches","git","actions","hooks","zipball","tarball"]);function I2(Z,z){let[$,J]=Z;if($===void 0)return"other";if(z[0])return"unclassifiable";if($==="issues"&&/^\d+$/.test(J??"")&&Z[2]==="labels")return"other";if(P2.has($))return"sensitive";if($==="branches"){if(Z.length===1||Z.slice(1).some((Y)=>Y==="protection")||Z[Z.length-1]==="rename")return"other";return z.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if($==="git")return J===void 0||J==="commits"||J==="tags"?"sensitive":z[1]?"unclassifiable":"other";if($==="actions"){if(J===void 0)return"sensitive";if(z[1])return"unclassifiable";if(J==="runs"||J==="jobs"){if(Z[Z.length-1]==="logs"&&Z.length>=4&&!z.some(Boolean))return"download";return"sensitive"}if(J==="workflows"&&Z[3]==="runs")return"sensitive";if(J==="artifacts"&&Z.length===4)return"download";return"other"}if($==="hooks"&&Z[2]==="deliveries"&&Z[3]!==void 0)return"sensitive";if($==="zipball"||$==="tarball")return"download";return"other"}function b5(Z,z){if(z[0]!=="repos"||z.length<5)return!1;let $=z.slice(3),J=(X)=>/^\d+$/.test($[X]??""),Y=(...X)=>$.length===X.length&&X.every((Q,H)=>typeof Q==="number"?J(H):$[H]===Q);if(Z==="DELETE")return Y("issues","comments",0)||Y("pulls","comments",0)||Y("comments",0)||Y("issues","comments",0,"reactions",0)||Y("pulls","comments",0,"reactions",0)||Y("issues",0,"reactions",0)||Y("issues",0,"labels")||$.length===4&&$[0]==="issues"&&J(1)&&$[2]==="labels"||Y("releases",0)||Y("releases","assets",0)||Y("actions","runs",0)||Y("actions","runs",0,"logs")||Y("deployments",0)||Y("milestones",0)||Y("issues",0,"lock");if(Z==="POST")return $.length===4&&$[0]==="actions"&&$[1]==="runs"&&J(2)&&["rerun","rerun-failed-jobs","cancel","force-cancel","approve"].includes($[3])||Y("actions","jobs",0,"rerun")||Y("issues",0,"labels");if(Z==="PUT")return Y("pulls",0,"merge")||Y("pulls",0,"update-branch")||Y("issues",0,"labels")||Y("issues",0,"lock");if(Z==="GET")return Y("pulls",0,"merge");return!1}function E5(Z){if(Z[0]!=="repos"||Z.length!==5||!/^\d+$/.test(Z[4]))return;if(Z[3]==="pulls")return new Set(["commits","comments","review_comments"]);if(Z[3]==="issues")return new Set(["comments"]);return}var S5=new Set(["body","bodyText","bodyHTML","bodyUrl","bodyResourcePath","comments","reviews","latestReviews","latestOpinionatedReviews","reviewThreads","url","permalink","summary","text","description","message","messageBody","messageHeadline","commitBody","commitHeadline","annotations","rawDetails","note","diff","readme","payload"]),f5=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function k5(Z){let z=[],$=0;while($<Z.length){let J=Z[$];if(/[\s,\uFEFF]/.test(J)){$++;continue}if(J==="#"){let Q=Z.indexOf(`
|
|
33
|
-
|
|
34
|
-
`)
|
|
35
|
-
`).replace(/%s/g,()=>
|
|
36
|
-
`,
|
|
37
|
-
`,
|
|
38
|
-
`,
|
|
2
|
+
import{homedir as dn}from"os";import{isAbsolute as Ir}from"path";import{isAbsolute as Ts,join as me,normalize as $s,resolve as Cs,sep as Ct}from"path";import{dirname as de,isAbsolute as Ye,join as yt,resolve as ne}from"path";import{accessSync as Hr,closeSync as Mr,constants as Ke,fstatSync as Fr,lstatSync as Te,openSync as Br,readFileSync as jr,readlinkSync as Gr,readSync as qr,realpathSync as xt,statSync as kt}from"fs";import{spawnSync as zr}from"child_process";var wn={missing:"No verified @hasna/trash guard was found on PATH.",unsafe_executable:"The Trash candidate is not an owned executable file or is writable by group or others.",unsafe_manifest:"The Trash package manifest is not a safe owned regular file.",unsafe_directory:"A Trash PATH or package directory is not owned safely or is writable by group or others.",unsafe_interpreter:"The Trash interpreter is missing, unsupported, or not a safe owned executable on its actual PATH.",unrecognized_package:"The candidate is not the registered @hasna/trash executable.",identity_failed:"The installed Trash identity probe failed or exceeded its deadline.",unsupported_protocol:"The installed Trash version does not expose the required guard protocol."};function $e(e){return e===0||e===process.getuid?.()}function Xe(e,r=!1){let t=e;for(let n=0;n<32;n++){if(!Ye(t)||t.length>4096||!Ce("/"))return!1;let s=t.split("/"),i=s.pop();if(!i||i==="."||i==="..")return!1;let o="/";for(let u of s){if(!u||u===".")continue;if(u===".."){o=de(o);continue}let c=yt(o,u),f=Te(c);if(r&&c==="/bin"&&f.isSymbolicLink()&&f.uid===0){let d=xt(c);if(!Ce(d))return!1;o=d;continue}if(!f.isDirectory()||!$e(f.uid)||f.mode&18)return!1;o=c}let a=yt(o,i),l=Te(a);if(!$e(l.uid))return!1;if(l.isSymbolicLink()){let u=Gr(a);t=Ye(u)?u:o+"/"+u;continue}return l.isFile()&&Boolean(l.mode&73)&&!(l.mode&18)}return!1}function Ur(e){if(!Ye(e)||ne(e)!==(e.replace(/\/+$/,"")||"/"))return!1;for(let r=ne(e);;r=de(r)){try{return Te(r),Ce(r)}catch(t){if(t.code!=="ENOENT")return!1}if(de(r)===r)return!1}}function Vr(e,r){let t=Br(e,Ke.O_RDONLY|Ke.O_NONBLOCK|Ke.O_NOFOLLOW),n;try{if(!Fr(t).isFile())return!1;let i=Buffer.alloc(256),o=qr(t,i,0,i.length,0);n=i.subarray(0,o).toString("utf8").split(`
|
|
3
|
+
`)[0]}finally{Mr(t)}let s=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(n);if(s&&s[1]!=="/usr/bin/env")return Xe(s[1],!0);if(n!=="#!/usr/bin/env bun"||!Xe("/usr/bin/env",!0))return!1;for(let i of r.split(":").slice(0,64)){if(!Ur(i))return!1;let o=ne(i,"bun");try{if(!kt(o).isFile())continue;Hr(o,Ke.X_OK)}catch{continue}return Xe(o,!0)}return!1}function Ce(e){let r=e;for(;;){let t=Te(r);if(!t.isDirectory()||!$e(t.uid)||(t.mode&18)!==0)return!1;let n=de(r);if(n===r)return!0;r=n}}function Pe(e=process.env){let r=e.PATH??"",t=Date.now()+2000,n="missing",s=(i)=>{if(n==="missing"||n==="unrecognized_package"||i.startsWith("unsafe_"))n=i};for(let i of r.split(":").slice(0,64)){if(!Ye(i)||Date.now()>=t)continue;let o=ne(i,"trash");try{let a=kt(o);if(!a.isFile()||!$e(a.uid)||(a.mode&73)===0||(a.mode&18)!==0){s("unsafe_executable");continue}let l=xt(o);if(!Ce(ne(i))||!Ce(de(l))){s("unsafe_directory");continue}if(!Xe(o)){s("unsafe_directory");continue}let u=ne(de(l),"../.."),c=yt(u,"package.json"),f=kt(c);if(!f.isFile()||!$e(f.uid)||f.size>16384||(f.mode&18)!==0||Te(c).isSymbolicLink()){s("unsafe_manifest");continue}let d=JSON.parse(jr(c,"utf8"));if(d.name!=="@hasna/trash"||typeof d.version!=="string"||typeof d.bin?.trash!=="string"||xt(ne(u,d.bin.trash))!==l){s("unrecognized_package");continue}try{if(!Vr(l,r)){s("unsafe_interpreter");continue}}catch{s("unsafe_interpreter");continue}let h=t-Date.now();if(h<=0){s("identity_failed");break}let p=zr(o,["--identity"],{encoding:"utf8",timeout:h,maxBuffer:2048,env:{PATH:r},stdio:["ignore","pipe","pipe"]});if(p.error||p.status!==0||Date.now()>=t){s("identity_failed");continue}let m=JSON.parse(p.stdout);if(m.name==="@hasna/trash"&&m.version===d.version&&m.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:o,version:d.version};s("unsupported_protocol")}catch{}}return{ok:!1,code:n}}function Qe(e=process.env){let r=Pe(e);return r.ok?r.path:null}function he(e){let r=e.tool_input?.command;return typeof r==="string"?r:""}var yn=["/","/bin","/boot","/dev","/etc","/home","/lib","/lib32","/lib64","/libx32","/opt","/proc","/root","/run","/sbin","/srv","/sys","/usr","/var","/Applications","/Library","/System","/Users","/Volumes","/private"];var We=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,z=(e)=>e.split("/").pop()??"";function Je(e){let r=e.startsWith("~")?e.slice(1).split("/",1)[0]:"";if(r&&!/['"\\]/.test(r))return!0;let t=null,n=0;for(let s=0;s<e.length;s++){let i=e[s];if(t==="'"){if(i==="'")t=null;continue}if(i==="\\"){s++;continue}if(t==='"'){if(i==='"')t=null;continue}if(i==="'"||i==='"')t=i;else if(i==="$"&&e[s+1]==="{")n++,s++;else if(i==="}"&&n>0)n--;else if(i==="{"||i==="}")return!0}return!1}var vt=64;function xn(e,r){let t=0;for(let n=r;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==="{")t++;else if(e[n]==="}"&&--t===0)return n;return e.length-1}function Zr(e){let r=e.match(/^([-+]?\d+)\.\.([-+]?\d+)(?:\.\.([-+]?\d+))?$/),t=r?null:e.match(/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([-+]?\d+))?$/),n=r??t;if(!n)return null;let s=r?Number(n[1]):n[1].charCodeAt(0),i=r?Number(n[2]):n[2].charCodeAt(0),o=Math.abs(Number(n[3]??1))||1;if(!Number.isSafeInteger(s)||!Number.isSafeInteger(i)||!Number.isSafeInteger(o))return"overflow";if(Math.floor(Math.abs(i-s)/o)+1>vt)return"overflow";let a=r&&(/^[-+]?0\d/.test(n[1])||/^[-+]?0\d/.test(n[2]))?Math.max(n[1].length,n[2].length):0,l=[];for(let u=s;s<=i?u<=i:u>=i;u+=s<=i?o:-o)if(!r)l.push(String.fromCharCode(u));else l.push(u<0?`-${String(-u).padStart(a-1,"0")}`:String(u).padStart(a,"0"));return l}function Kr(e){let r=null,t=0;for(let n=0;n<e.length;n++){let s=e[n];if(r==="'"){if(s==="'")r=null;continue}if(s==="\\"){n++;continue}if(r==='"'){if(s==='"')r=null;continue}if(s==="'"||s==='"')r=s;else if(s==="$"&&e[n+1]==="{")n=xn(e,n+1);else if(s==="{"){if(++t>vt)return"overflow";let i=null,o=0,a=!0,l=[];for(let u=n;u<e.length;u++){let c=e[u];if(i==="'"){if(c==="'")i=null;continue}if(c==="\\"){a=!1,u++;continue}if(i==='"'){if(c==='"')i=null;continue}if(c==="'"||c==='"')i=c,a=!1;else if(c==="$"&&e[u+1]==="{")u=xn(e,u+1),a=!1;else if(c==="{")o++;else if(c===","&&o===1)l.push(u);else if(c==="}"&&--o===0){if(l.length>0){let d=[n,...l,u];return{open:n,close:u,parts:d.slice(0,-1).map((h,p)=>e.slice(h+1,d[p+1]))}}let f=a?Zr(e.slice(n+1,u)):null;if(f==="overflow")return f;if(f)return{open:n,close:u,parts:f};break}}}}return null}function re(e){if(e.length>4096&&e.includes("{"))return null;let r=Kr(e);if(r===null)return[e];if(r==="overflow")return null;let t=[];for(let n of r.parts){let s=re(e.slice(0,r.open)+n+e.slice(r.close+1));if(s===null||t.push(...s)>vt)return null}return t}var g={arg:"none"},w={arg:"value"},Ie={arg:"optional"},Z={arg:"none",effect:"lookup"},v={arg:"none",effect:"refuse"},X={help:v,version:v},Xr=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,_t={timeout:{short:{k:w,s:w,v:g},long:{"kill-after":w,signal:w,verbose:g,foreground:g,"preserve-status":g,...X},positionals:[Xr]},env:{short:{i:g,"0":g,v:g,u:w,a:w,C:v,S:v},long:{"ignore-environment":g,null:g,debug:g,unset:w,argv0:w,chdir:v,"split-string":v,"block-signal":Ie,"default-signal":Ie,"ignore-signal":Ie,"list-signal-handling":v,...X},env:!0},nice:{short:{n:w},long:{adjustment:w,...X},numericOption:!0},nohup:{short:{},long:{...X}},command:{short:{p:g,v:Z,V:Z},long:{}},exec:{short:{c:g,l:g,a:w},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:w,o:w,e:w},long:{input:w,output:w,error:w,...X}},time:{short:{p:g,a:g,q:g,v:g,f:w,o:v,V:v},long:{portability:g,append:g,quiet:g,verbose:g,format:w,output:v,...X}},ionice:{short:{c:w,n:w,t:g,p:v,P:v,u:v,h:v,V:v},long:{class:w,classdata:w,ignore:g,pid:v,pgid:v,uid:v,...X}},setsid:{short:{c:g,f:g,w:g,h:v,V:v},long:{ctty:g,fork:g,wait:g,...X}}},Yr=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function Qr(e,r,t){let n=!1,s=(i)=>{if(!i||i.effect==="refuse")return!1;if(i.effect==="lookup")n=!0;return!0};while(t<r.length){let i=r[t];if(i.opaque)return null;let o=i.text;if(o==="--"){t++;break}if(o==="-"&&e.env){t++;continue}if(!o.startsWith("-")||o==="-")break;if(e.numericOption&&/^-[-+]?\d+$/.test(o)){t++;continue}if(o.startsWith("--")){let a=o.indexOf("="),l=a<0?o.slice(2):o.slice(2,a),u=Object.keys(e.long),c=u.includes(l)?[l]:u.filter((d)=>l&&d.startsWith(l));if(c.length!==1)return null;let f=e.long[c[0]];if(!s(f))return null;if(f.arg==="none"&&a>=0)return null;if(f.arg==="value"&&a<0){let d=r[++t];if(!d||d.opaque)return null}t++;continue}for(let a=1;a<o.length;a++){let l=e.short[o[a]];if(!s(l))return null;if(l.arg==="value"){if(a===o.length-1){let u=r[++t];if(!u||u.opaque)return null}break}}t++}if(n)return-1;for(let i of e.positionals??[]){let o=r[t];if(!o||o.opaque||!i.test(o.text))return null;t++}if(e.env||e.assignments){for(;t<r.length&&We.test(r[t].text);t++)if(r[t].opaque)return null}return t}function se(e,r=_t){let t=0;while(t<e.length&&(We.test(e[t].text)||Yr.has(e[t].text)))t++;for(let n=0;n<16;n++){if(t>=e.length)return{index:-1};if(e[t].opaque)return n===0?{index:t}:null;let s=Object.hasOwn(r,z(e[t].text))?r[z(e[t].text)]:void 0;if(!s)return{index:t};let i=Qr(s,e,t+1);if(i===null)return null;if(i<0)return{index:-1};t=i}return null}function Jr(e){return/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred|trash)(?![A-Za-z0-9_.-])/.test(e)}var Y={on:!1};function ie(e,r){if(!e.includes("\\")||!e.includes('"'))return;let t=Y.on;Y.on=!0;try{return r()}finally{Y.on=t}}var Rt=(e)=>e.split("/").pop()??"",Ot={perl:{letters:new Set(["e","E"]),long:new Set},python:{letters:new Set(["c"]),long:new Set},python2:{letters:new Set(["c"]),long:new Set},python3:{letters:new Set(["c"]),long:new Set},ruby:{letters:new Set(["e"]),long:new Set},node:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},nodejs:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},bun:{letters:new Set(["e"]),long:new Set(["--eval"])},deno:{letters:new Set(["e"]),long:new Set(["--eval"])},php:{letters:new Set(["r"]),long:new Set},lua:{letters:new Set(["e"]),long:new Set},luajit:{letters:new Set(["e"]),long:new Set},Rscript:{letters:new Set(["e"]),long:new Set}},En=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,es=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),ts=new Set(["ssh","scp","sftp"]),ns=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),kn=new Set(["proxycommand","localcommand","knownhostscommand"]),rs=/(?:`|\$\()|\b(?:system|exec|execve|execvp|popen|spawn|posix_spawn|fork|subprocess|Popen|check_output|check_call|shell_exec|passthru|proc_open|pcntl_exec|qx|open|fopen|sysopen|unlink|remove|delete|rmtree|rmdir|mkdir|rename|truncate|ftruncate|chmod|chown|symlink|writeFile|createWriteStream|appendFile|child_process|FileUtils|shutil|Kernel|require|import|load|eval|os|sys|io|fs|File|IO|Dir|Path|pathlib|Deno|Bun)|%x\W/,ss=/[|>]|\b(?:system|getline|close|fflush|print\w*\s*>>?)/;function On(e){if(Jr(e.text))return!1;if(e.kind==="awk")return!ss.test(e.text);if(e.kind==="c-interp")return!rs.test(e.text);return!1}function is(e,r,t,n){let s=Ot[e]??(En.test(e)?Ot[e.replace(/[0-9.]+$/,"")]:void 0);if(!s)return null;let i=[],o=!1,a=(l)=>{if(l+1>=r.length||n(l+1))return o=!0,l;return i.push({text:r[l+1],kind:"c-interp"}),l+1};for(let l=t+1;l<r.length;l++){let u=r[l];if(u==="--")break;if(!u.startsWith("-")||u==="-")break;if(u.startsWith("--")){let f=u.indexOf("="),d=f<0?u:u.slice(0,f);if(s.long.has(d))if(f>=0)i.push({text:u.slice(f+1),kind:"c-interp"});else l=a(l);continue}let c=u.slice(1);for(let f=0;f<c.length;f++){if(!s.letters.has(c[f]))continue;if(f<c.length-1)i.push({text:c.slice(f+1),kind:"c-interp"});else l=a(l);break}}if(i.length===0&&!o)return null;return{programs:i,unresolved:o}}function os(e,r,t){let n=r+1;for(;n<e.length&&e[n].startsWith("-");n++)if(e[n]==="-L"||e[n]==="--log-level")n++;if(e[n]!=="eval"||t(n))return null;let s=[],i=!1;for(n++;n<e.length;n++){if(t(n)){i=!0;continue}if(!e[n].startsWith("-"))s.push({text:e[n],kind:"c-interp"})}return s.length===0&&!i?null:{programs:s,unresolved:i}}function ls(e,r,t){let n=[],s=!1,i=r+1;for(;i<e.length;i++){let o=e[i];if(o==="--"){i++;break}if(!o.startsWith("-")||o==="-")break;if(o==="-e"||o.startsWith("-e")){let a=o==="-e"?null:o.slice(2);if(a!==null)n.push({text:a,kind:"awk"});else if(i+1<e.length&&!t(i+1))n.push({text:e[++i],kind:"awk"});else s=!0}else if(o==="-f"||o.startsWith("-f")){if(s=!0,o==="-f")i++}else if(o==="-v"||o.startsWith("-v")){if(o==="-v")i++}}if(n.length===0&&!s){if(i<e.length)if(t(i))s=!0;else n.push({text:e[i],kind:"awk"})}return{programs:n,unresolved:s}}function as(e,r,t){let n=e[r],s,i=r;if(n==="-o"){if(r+1>=e.length)return{value:null,next:r};if(t(r+1))return{value:null,next:r+1};s=e[r+1],i=r+1}else s=n.slice(2);return{value:s,next:i}}function us(e,r,t){let n=[],s=!1;for(let i=r+1;i<e.length;i++){let o=e[i];if(o==="--")break;if(!o.startsWith("-")||o==="-")break;if(o.startsWith("--"))continue;if(o==="-o"||o.startsWith("-o")){let{value:l,next:u}=as(e,i,t);if(i=u,l===null){s=!0;continue}let c=l.indexOf("="),f=c>=0?c:l.search(/\s/),d=(f>=0?l.slice(0,f):l).trim().toLowerCase(),h=f>=0?l.slice(f+1).trim():"";if(kn.has(d))n.push({text:h,kind:"shell"});continue}if(o==="-F"||o.startsWith("-F")){if(s=!0,o==="-F")i++;continue}if(o==="-S"||o.startsWith("-S")){let l=o==="-S"?i+1<e.length&&!t(i+1)?e[++i]:null:o.slice(2);if(l===null)s=!0;else n.push({text:l,kind:"shell"});continue}let a=o.slice(1);for(let l=0;l<a.length;l++){if(!ns.has(a[l]))continue;if(l<a.length-1)break;if(a[l]==="o"||a[l]==="F"||a[l]==="S"){if(i+1<e.length){let u=e[i+1];if(a[l]==="o")if(!t(i+1)){let c=u.indexOf("="),f=c>=0?c:u.search(/\s/),d=(f>=0?u.slice(0,f):u).trim().toLowerCase();if(kn.has(d))n.push({text:f>=0?u.slice(f+1).trim():"",kind:"shell"})}else s=!0;else if(a[l]==="F")s=!0;else if(!t(i+1))n.push({text:u,kind:"shell"});i++}}else if(i+1<e.length)i++}}return{programs:n,unresolved:s}}function cs(e,r,t){let n=[],s=!1,i=!1;for(let o=r+1;o<e.length;o++){let a=e[o];if(a==="--")break;if(a==="-e"||a==="--rsh")if(i=!0,o+1<e.length&&!t(o+1))n.push({text:e[++o],kind:"shell"});else s=!0;else if(a.startsWith("--rsh="))i=!0,n.push({text:a.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(a)&&a.length>2&&!a.startsWith("--"))i=!0,n.push({text:a.slice(a.indexOf("e")+1),kind:"shell"})}return i?{programs:n,unresolved:s}:null}var fs=/^(?:true|false|yes|no|on|off|1|0|)$/i,ds=[/^core\.(?:pager|editor|sshcommand|askpass|alternaterefscommand)$/,/^sequence\.editor$/,/^diff\.external$/,/^interactive\.difffilter$/,/^imap\.tunnel$/,/^gc\.recentobjectshook$/,/^gpg\.program$/,/^gpg\.ssh\.defaultkeycommand$/,/^uploadpack\.packobjectshook$/,/^instaweb\.(?:browser|httpd)$/,/^credential\.(?:.+\.)?helper$/,/^diff\..+\.(?:command|textconv)$/,/^(?:difftool|mergetool|man|browser)\..+\.(?:cmd|path)$/,/^guitool\..+\.cmd$/,/^merge\..+\.driver$/,/^gpg\..+\.program$/,/^remote\..+\.(?:uploadpack|receivepack)$/,/^filter\..+\.(?:clean|smudge|process)$/,/^tar\..+\.command$/,/^trailer\..+\.(?:cmd|command)$/,/^sendemail\.(?:.+\.)?(?:tocmd|cccmd|headercmd|sendmailcmd)$/];function Rn(e,r){let t=e.toLowerCase(),n=(s)=>s===void 0?{kind:"unresolved"}:{kind:"command",text:s};if(/^alias\./.test(t))return r!==void 0&&r.trimStart().startsWith("!")?n(r.trimStart().slice(1)):{kind:"unresolved"};if(/^pager\./.test(t)||t==="core.fsmonitor")return r!==void 0&&fs.test(r)?{kind:"harmless"}:n(r);if(t==="core.gitproxy")return r!==void 0&&/^none(?:\s+for\s+\S+)?$/.test(r)?{kind:"harmless"}:n(r?.replace(/\s+for\s+\S+$/,""));if(/^submodule\..+\.update$/.test(t))return r!==void 0&&r.trimStart().startsWith("!")?n(r.trimStart().slice(1)):r===void 0?{kind:"unresolved"}:{kind:"harmless"};if(/^sendemail\.(?:.+\.)?smtpserver$/.test(t))return r!==void 0&&!r.startsWith("/")?{kind:"harmless"}:n(r);if(/^credential\.(?:.+\.)?helper$/.test(t)){if(r==="")return{kind:"harmless"};if(r===void 0)return{kind:"unresolved"};let s=r.trimStart();return n(s.startsWith("!")?s.slice(1):s.startsWith("/")?s:`git credential-${s}`)}if(ds.some((s)=>s.test(t)))return n(r);if(t==="core.hookspath")return r==="/dev/null"?{kind:"harmless"}:{kind:"unresolved"};if(t==="include.path"||/^includeif\..+\.path$/.test(t))return{kind:"unresolved"};if(t==="protocol.allow")return r!==void 0&&/^(?:never|user)$/i.test(r)?{kind:"harmless"}:{kind:"unresolved"};if(t==="protocol.ext.allow")return r!==void 0&&/^never$/i.test(r)?{kind:"harmless"}:{kind:"unresolved"};return{kind:"harmless"}}function vn(e){return/[$\x60]/.test(e)||["","x","/x","!x"].some((r)=>Rn(e,r).kind!=="harmless")}var hs=new Set(["GIT_PAGER","GIT_EDITOR","GIT_SEQUENCE_EDITOR","GIT_EXTERNAL_DIFF","GIT_SSH","GIT_SSH_COMMAND","GIT_ASKPASS","SSH_ASKPASS","GIT_PROXY_COMMAND","PAGER","EDITOR","VISUAL"]),ps=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function gs(e){let r=/'((?:[^']|'\\'')*)'/y,t=(i)=>i.replace(/'\\''/g,"'"),n=[],s=0;while(s<e.length){if(/\s/.test(e[s])){s++;continue}r.lastIndex=s;let i=r.exec(e);if(!i)return null;if(s=r.lastIndex,e[s]==="="){r.lastIndex=s+1;let o=r.exec(e);if(!o)return null;s=r.lastIndex,n.push([t(i[1]),t(o[1])])}else{let o=t(i[1]),a=o.indexOf("=");n.push(a<0?[o,void 0]:[o.slice(0,a),o.slice(a+1)])}}return n}function ms(e,r,t){let n=[],s=!1,i=(u,c,f=!0)=>{if(!f||/[$\x60]/.test(u)){s=!0;return}let d=Rn(u,c);if(d.kind==="unresolved")s=!0;else if(d.kind==="command")n.push({text:d.text,kind:"shell"})},o=(u,c)=>{let f=u.indexOf("="),d=f<0?u:u.slice(0,f),h=f<0?"true":u.slice(f+1);if(!c)return i(d,h);if(vn(d))s=!0},a=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let u=r+1;u<e.length;u++){let c=e[u];if(!c.startsWith("-")||c==="-")break;if(c==="--")break;if(c==="-c"){if(u+1>=e.length)break;o(e[u+1],t(u+1)),u++}else if(c.startsWith("-c")&&!c.startsWith("--"))o(c.slice(2),t(u));else if(c==="--config-env"||c.startsWith("--config-env=")){let f=c==="--config-env"?e[++u]??"":c.slice(13),d=f.indexOf("="),h=d<0?f:f.slice(0,d);if(t(u)||vn(h))s=!0}else if(c.startsWith("--exec-path="))s=!0;else if(a.has(c))u++}let l=new Map;for(let u=0;u<r;u++){let c=e[u].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!c)continue;let[,f,d]=c,h=t(u);if(hs.has(f))if(h)s=!0;else n.push({text:d,kind:"shell"});else if(ps.has(f)){if(h||d!=="/dev/null"||f==="GIT_EXEC_PATH"||f==="GIT_TEMPLATE_DIR")s=!0}else if(f==="GIT_ALLOW_PROTOCOL"){if(h||d.split(":").includes("ext"))s=!0}else if(f==="GIT_CONFIG_PARAMETERS"){let p=h?null:gs(d);if(p===null)s=!0;else for(let[m,O]of p)i(m,O??"true")}else if(/^GIT_CONFIG_(?:KEY|VALUE)_\d+$/.test(f)){let p=f.replace(/^GIT_CONFIG_(?:KEY|VALUE)_/,""),m=l.get(p)??{};if(f.startsWith("GIT_CONFIG_KEY_"))m.key=d;else m.value=d;if(h)m.opaque=!0;l.set(p,m)}}for(let u of l.values()){if(u.key===void 0)continue;if(u.opaque)o(`${u.key}=`,!0);else i(u.key,u.value)}if(n.length===0&&!s)return null;return{programs:n,unresolved:s}}function Ne(e){if(/^~/.test(e))return null;let r="";for(let t=0;t<e.length;t++){let n=e[t];if(n==="'"){let s=e.indexOf("'",t+1);if(s<0)return null;r+=e.slice(t+1,s),t=s}else if(n==="$"||n==="`")return null;else if(n==='"'){let s=t+1;for(;s<e.length&&e[s]!=='"';s++){let i=e[s];if(i==="$"||i==="`")return null;if(i==="\\"&&s+1<e.length&&/[$\x60"\\\n]/.test(e[s+1])){if(e[++s]!==`
|
|
4
|
+
`||Y.on)r+=e[s];continue}r+=i}if(s>=e.length)return null;t=s}else if(n==="\\"){if(t+1>=e.length)return null;r+=e[++t]}else if("*?[{}".includes(n))return null;else r+=n}return r}function _n(e){let r=null;for(let t=0;t<e.length;t++){let n=e[t];if(r==="'"){if(n==="'")r=null;continue}if(n==="\\"){t++;continue}if(n==="$"||n==="`")return!1;if(r==='"'){if(n==='"')r=null;continue}if(n==="'"||n==='"'){r=n;continue}if(n==="<"&&e[t+1]==="<"&&e[t+2]!=="<")return!1}return r===null}var bs=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]),Ss=new Set(["--rcfile","--init-file"]),pe=(e)=>e.replace(/\$'(?:[^'\\]|\\[\s\S])*'/g,(r)=>r.replace(/\\[\s\S]/g,(t)=>t==="\\'"?"\\x27":t));function Le(e,r,t=Ne){if(r<0||r>=e.length)return null;let n=Rt(t(e[r])??"");if(n==="eval"){let a=r+1;if(Ne(e[a]??"")==="--")a++;let l=e.slice(a);if(l.length===0)return null;if(l.length>1)return{program:null,literal:!1};let u=Ne(l[0]);return u!==null&&_n(u)?{program:u,literal:!0}:{program:u,literal:!1}}if(!bs.has(n))return null;let s=!1,i=r+1;for(;i<e.length;i++){let a=Ne(e[i]);if(a===null){if(s)break;return/^"[^"]*"$/.test(e[i])?null:{program:null,literal:!1}}if(a==="--"){i++;break}if(!/^[-+]./.test(a))break;if(a.startsWith("--")){if(Ss.has(a))i++;continue}let l=a.slice(1);if(a[0]==="-"&&l.includes("c"))s=!0;if(/[oO]/.test(l))i++}if(!s||i>=e.length)return null;let o=Ne(e[i]);return o!==null&&_n(o)?{program:o,literal:!0}:{program:o,literal:!1}}function ws(e,r,t){let n=ys(e,r,t);if(n===null)return{programs:[],unresolved:!0};let s=new Set;for(let{scripts:i,mayFail:o}of n){let a=xs(i.join(`
|
|
5
|
+
`));if(a===null){if(o)continue;return{programs:[],unresolved:!0}}if(a.executes)return{programs:i.map((l)=>({text:l,kind:"shell"})),unresolved:!0};for(let l of a.writes)s.add(l)}if(s.size===0)return null;return{programs:[],unresolved:!1,writes:[...s]}}var Et="quiet silent debug follow-symlinks posix regexp-extended separate sandbox unbuffered null-data zero-terminated binary help version in-place file expression line-length".split(" ");function ys(e,r,t){let n=[],s=[],i=!1,o=-1,a=!1,l=!1;for(let f=r+1;f<e.length;f++){let d=e[f];if(l||!/^-./.test(d)){s.push(f);continue}if(t(f))return null;if(d==="--"){l=!0;continue}let h,p;if(d[1]==="-"){let m=d.indexOf("="),O=(m<0?d:d.slice(0,m)).slice(2),A=Et.filter((j)=>j.startsWith(O)),I=Et.includes(O)?O:A.length===1?A[0]:"";if(Et.indexOf(I)<15){if(!I)return null;continue}if(h=I[0],m>=0)p=d.slice(m+1)}else{let m=1;while("nrEsuzb".includes(d[m]??"_"))m++;if(h=d[m]??"",h==="i"||h==="I"){let O=m===d.length-1&&f+1<e.length&&!t(f+1)?e[f+1]:void 0;if(h==="I"){if(a=i=!0,m===d.length-1){if(O===void 0)return null;o=f+1}}else if(O===""||O?.startsWith("."))i=!0,o=f+1;continue}if(h==="")continue;if(!"efl".includes(h))return null;p=d.slice(m+1)||void 0}if(h==="f")return null;if(p===void 0){if(p=e[++f],p===void 0||t(f))return null}if(h==="e")n.push(p)}let u=(f)=>{if(n.length>0)return n;let d=s.find((h)=>h!==f);return d===void 0?[]:t(d)?null:[e[d]]},c=[];if(!a)c.push({scripts:u(-1),mayFail:o>=0&&n.length===0&&s[0]===o});if(i)c.push({scripts:u(o),mayFail:!1});return c.some((f)=>f.scripts===null)?null:c}function xs(e){let r=[],t=!1,n=0,s=e.length,i=()=>e[n]??"",o=()=>{while(i()===" "||i()==="\t")n++;let u=n,c=e.indexOf(`
|
|
6
|
+
`,n);return n=c<0?s:c,e.slice(u,n)},a=()=>{let u=o();if(u&&!/^\/dev\/std(?:out|err)$/.test(u))r.push(u)},l=(u,c)=>{for(;n<s;n++){let f=e[n];if(f===`
|
|
7
|
+
`)return!1;if(f==="\\"){if(++n>=s)return!1}else if(f===u)return n++,!0;else if(c&&f==="["){let d=n+1;if(e[d]==="^")d++;if(e[d]==="]")d++;for(;e[d]!=="]";d++){if(d>=s||e[d]===`
|
|
8
|
+
`)return!1;if(e[d]==="["&&":.=".includes(e[d+1]||`
|
|
9
|
+
`)){let h=e.indexOf(e[d+1]+"]",d+2);if(h<0||e.slice(d,h).includes(`
|
|
10
|
+
`))return!1;d=h+1}}n=d}}return!1};while(n<s){let u=e[n++];if(u==="/"||u==="\\"){let c=u==="\\"?e[n++]??"":"/";if(!c||c===`
|
|
11
|
+
`||!l(c,!0))return null}else if(u==="#")o();else if(":btTv".includes(u)){while(i()===" "||i()==="\t")n++;while(n<s&&!/[\s;]/.test(i()))n++}else if("aic".includes(u)){while(i()===" "||i()==="\t")n++;if(i()==="\\")n+=2;for(;n<s&&e[n]!==`
|
|
12
|
+
`;n++)if(e[n]==="\\")n++}else if(u==="e")t=!0,o();else if(u==="r"||u==="R")o();else if(u==="w"||u==="W")a();else if(u==="s"||u==="y"){let c=e[n++]??"";if(!c||c===`
|
|
13
|
+
`||c==="\\"||!l(c,u==="s")||!l(c,!1))return null;for(;u==="s"&&" \tgpiImMe0123456789w".includes(i()||"_");n++){if(i()==="e")t=!0;if(i()==="w"){n++,a();break}}}}return{writes:r,executes:t}}var ks=new Set(["-exec","-execdir","-ok","-okdir"]),vs=new Set(["-exec","-execdir"]),_s=new Set("0oprtx"),Es=new Set("adEILnPsJRS"),Os=new Set("eil"),et={"--null":"flag","--open-tty":"flag","--interactive":"flag","--no-run-if-empty":"flag","--verbose":"flag","--exit":"flag","--show-limits":"flag","--help":"flag","--version":"flag","--arg-file":"value","--delimiter":"value","--max-args":"value","--max-procs":"value","--max-chars":"value","--process-slot-var":"value","--max-lines":"value","--eof":"optional","--replace":"optional"};function Rs(e){if(Object.hasOwn(et,e))return et[e];let r=Object.keys(et).filter((t)=>t.startsWith(e));return r.length===1?et[r[0]]:null}function De(e,r,t,n=0){while(r<e.length){if(t(r)){r++;continue}let s=e[r];if(s==="--"){r++;break}if(!s.startsWith("-")||s==="-")break;if(s.startsWith("--")){let a=s.indexOf("="),l=Rs(a<0?s:s.slice(0,a));if(l===null){if(n>=4)return[];return[...De(e,r+1,t,n+1),...De(e,r+2,t,n+1)]}r+=l==="value"&&a<0?2:1;continue}let i=!1,o=!1;for(let a=1;a<s.length;a++){let l=s[a];if(_s.has(l))continue;if(Os.has(l))break;if(Es.has(l)){i=a===s.length-1;break}o=!0;break}if(o){if(n>=4)return[];return[...De(e,r+1,t,n+1),...De(e,r+2,t,n+1)]}r+=i?2:1}while(r<e.length&&t(r))r++;return r<e.length?[r]:[]}function He(e,r,t=()=>!1){if(r<0||r>=e.length)return[];let n=Rt(e[r]);if(n==="xargs")return[...new Set(De(e,r+1,t))].map((i)=>({start:i,end:e.length}));if(n!=="find")return[];let s=[];for(let i=r+1;i<e.length;i++){if(t(i)||!ks.has(e[i]))continue;let o=i+1,a=o;for(;a<e.length;a++){if(t(a))continue;if(e[a]===";")break;if(e[a]==="+"&&a>o&&e[a-1]==="{}"&&vs.has(e[i]))break}if(o<a)s.push({start:o,end:a});i=a}return s}function Me(e,r,t){if(r<0||r>=e.length)return null;let n=Rt(e[r]);if(n==="deno"){let s=os(e,r,t);if(s)return s}if(Object.hasOwn(Ot,n)||En.test(n))return is(n,e,r,t);if(es.has(n))return ls(e,r,t);if(ts.has(n))return us(e,r,t);if(n==="rsync")return cs(e,r,t);if(n==="git")return ms(e,r,t);if(n==="sed")return ws(e,r,t);return null}var Ps=600000,Is="Delete via trash guard (rm intercepted and made recoverable)",Ws=[".hasna/repos/clones","workspace/repos"],Ns=[".hasna",".ssh",".aws"],At={rmdir:"`rmdir` is a delete that trash-guard does not rewrite (it takes rmdir's flags, not rm's). Re-run it as `rm -d -- <path>` for an empty directory, or `rm -r -- <path>` for a non-empty one, and it is redirected into trash.",unlink:"`unlink` is a delete that trash-guard does not rewrite. Re-run it as `rm -- <path>` and it is redirected into trash.",shred:"`shred` destroys content irrecoverably and is never allowed. Re-run it as `rm -- <path>` and it is redirected into trash."},Ds=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env"]),Ls={sudo:["-u","--user","-g","--group","-p","--prompt","-C","--chdir","-h","--host","-r","--role","-t","--type","-U","--other-user"],doas:["-u","-C"],env:["-u","--unset","-C","--chdir","-S","--split-string"],nice:["-n","--adjustment"],ionice:["-c","--class","-n","--classdata","-p","--pid"],stdbuf:["-i","-o","-e","--input","--output","--error"],time:["-f","--format","-o","--output"],timeout:["-s","--signal","-k","--kill-after"],nohup:[],setsid:[],command:[],builtin:[],exec:["-a"]},Hs={timeout:1},Ms={sudo:{short:{A:g,B:g,b:g,E:g,H:g,i:g,k:g,N:g,n:g,P:g,S:g,s:g,C:w,g:w,p:w,r:w,T:w,t:w,U:w,u:w,e:Z,l:Z,v:Z,D:v,R:v,h:v,K:v,V:v},long:{askpass:g,bell:g,background:g,"close-from":w,chdir:v,"preserve-env":Ie,edit:Z,group:w,"set-home":g,help:v,host:v,login:g,"remove-timestamp":v,"reset-timestamp":g,list:Z,"no-update":g,"non-interactive":g,"preserve-groups":g,prompt:w,chroot:v,role:w,stdin:g,shell:g,type:w,"command-timeout":w,"other-user":w,user:w,version:v,validate:Z},assignments:!0},doas:{short:{n:g,s:g,u:w,C:v,L:v},long:{}},flock:{short:{s:g,x:g,e:g,n:g,u:g,o:g,F:g,w,E:w,h:v,V:v},long:{shared:g,exclusive:g,unlock:g,nonblock:g,nonblocking:g,nb:g,timeout:w,wait:w,"conflict-exit-code":w,close:g,"no-fork":g,fcntl:g,verbose:g,help:v,version:v},positionals:[/^[\s\S]+$/]}},Fs={..._t,...Ms},Ln=new Set(["-c","--command"]),Bs=new Set(["busybox","toybox"]),Pt=new Set(["rm","rmdir","unlink","shred"]),js=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]),Gs=new Set(["-C","-c","--git-dir","--work-tree","--namespace","--exec-path","--config-env"]),qs=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/;function U(e){return qs.test(T(e))}function Be(e){return e.map((r)=>r.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var Hn=/^[A-Za-z_][A-Za-z0-9_]*=/;function nt(e){let r=e.lastIndexOf("/");return r>=0?e.slice(r+1):e}var An={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
|
|
14
|
+
`,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function zs(e,r){let t="",n=r;while(n<e.length&&e[n]!=="'"){if(e[n]!=="\\"||n+1>=e.length){t+=e[n++];continue}let s=e[n+1],i=e.slice(n+1),o;if(Object.hasOwn(An,s))t+=An[s],n+=2;else if(o=i.match(/^[0-7]{1,3}/))t+=String.fromCharCode(parseInt(o[0],8)&255),n+=1+o[0].length;else if((o=i.match(/^x([0-9A-Fa-f]{1,2})/))||(o=i.match(/^u([0-9A-Fa-f]{1,4})/))||(o=i.match(/^U([0-9A-Fa-f]{1,8})/))){let a=parseInt(o[1],16);t+=a<=1114111?String.fromCodePoint(a):"",n+=1+o[0].length}else if(s==="c"&&n+2<e.length)t+=String.fromCharCode(e.charCodeAt(n+2)&31),n+=3;else t+=`\\${s}`,n+=2}return{text:t,end:Math.min(n+1,e.length)}}function C(e){return Mn(e,!0)}function Mn(e,r){let t="",n=0;while(n<e.length){let s=e[n];if(r&&s==="$"&&e[n+1]==="'"){let i=zs(e,n+2);t+=i.text,n=i.end;continue}if(r&&s==="$"&&e[n+1]==='"'){n++;continue}if(s==="\\"){if(n+1<e.length)t+=e[n+1];n+=2;continue}if(s==="'"){let i=e.indexOf("'",n+1);if(i===-1){t+=e.slice(n+1);break}t+=e.slice(n+1,i),n=i+1;continue}if(s==='"'){n++;while(n<e.length&&e[n]!=='"'){if(e[n]==="\\"&&n+1<e.length){let i=e[n+1];t+=Y.on||/[$`"\\]/.test(i)?i:i===`
|
|
15
|
+
`?"":`\\${i}`,n+=2;continue}t+=e[n],n++}n++;continue}t+=s,n++}return t}function rt(e){if(Je(e))return!0;let r=null;for(let t=0;t<e.length;t++){let n=e[t];if(r==="'"){if(n==="'")r=null;continue}if(n==="\\"){t++;continue}if(n==="`"||n==="$")return!0;if(n==='"'){r=r===null?'"':null;continue}if(r!==null)continue;if(n==="'")r="'";else if(n==="*"||n==="?")return!0;else if(n==="["&&Us(e,t+1,"]"))return!0}return!1}function Us(e,r,t){let n=null;for(let s=r;s<e.length;s++){let i=e[s];if(n!=="'"&&i==="\\")s++;else if(n===null&&i===t)return!0;else if(i==="'"&&n!=='"')n=n==="'"?null:"'";else if(i==='"'&&n!=="'")n=n==='"'?null:'"'}return!1}function Vs(e){if(!rt(e))return!1;let r=re(e);return r===null||r.some((t)=>C(t).split(/[^A-Za-z0-9_]+/).some((n)=>Pt.has(n)))}function be(e){return nt(C(e))}var Fn={deep:!0};function It(e,r){return e.replace(/\\([$`\\"])/g,(t,n)=>n==='"'&&!r?t:n)}function Zs(e,r,t){let n=[],s=r+1;while(s<t-1){let i=e[s];if(i==="\\"){s+=2;continue}if(i==="`"){let o=je(e,s);if(o<0)return null;n.push(It(e.slice(s+1,o-1),!0)),s=o;continue}if(i==="$"&&e[s+1]==="("){let o=oe(e,s+1);if(o<0)return null;n.push(e.slice(s+2,o-1)),s=o;continue}s++}return n}function Ks(e){let r=[],t=0;while(t<e.length){let n=e[t];if(n==="\\"){t+=2;continue}if(n==="`"){let s=je(e,t);if(s<0)return null;r.push(It(e.slice(t+1,s-1),!1)),t=s;continue}if(n==="$"&&e[t+1]==="("){let s=oe(e,t+1);if(s<0)return null;r.push(e.slice(t+2,s-1)),t=s;continue}t++}return r}function Tn(e,r,t,n){let s=r+1;for(let i of t){let o=Math.min(s,e.length);for(;;){if(s>e.length){s=e.length+1;break}let l=e.indexOf(`
|
|
16
|
+
`,s),u=l===-1?e.length:l,c=e.slice(s,u).replace(/\r$/,"");if(i.stripTabs)c=c.replace(/^\t+/,"");if(c===i.delimiter)break;s=u+1}let a=e.slice(o,Math.min(s,e.length));if(i.owner.push(a),!i.quoted){let l=Ks(a);if(!l)return-1;n.push(...l)}if(s<=e.length){let l=e.indexOf(`
|
|
17
|
+
`,s);s=(l===-1?e.length:l)+1}}return Math.min(s-1,e.length)}function Bn(e,r){let t=e.indexOf("'",r+1);return t===-1?-1:t+1}function je(e,r){let t=r+1;while(t<e.length){if(e[t]==="\\"){t+=2;continue}if(e[t]==="`")return t+1;t++}return-1}function jn(e,r){let t=r+1;while(t<e.length){let n=e[t];if(n==="\\"){t+=2;continue}if(n==='"')return t+1;if(n==="`"){let s=je(e,t);if(s<0)return-1;t=s;continue}if(n==="$"&&e[t+1]==="("){let s=oe(e,t+1);if(s<0)return-1;t=s;continue}t++}return-1}function we(e,r){if(e[r]!=="<"||e[r+1]!=="<"||e[r+2]==="<")return null;let t=r+2,n=e[t]==="-";if(n)t++;while(e[t]===" "||e[t]==="\t")t++;let s="",i=!1;while(t<e.length&&!/[\s;|&<>()]/.test(e[t])){let o=e[t];if(o==="'"||o==='"'){let a=e.indexOf(o,t+1);if(a<0)return null;s+=e.slice(t+1,a),i=!0,t=a+1;continue}if(o==="\\"){if(t+1>=e.length)return null;s+=e[t+1],i=!0,t+=2;continue}s+=o,t++}return s?{delimiter:s,stripTabs:n,quoted:i,end:t}:null}function st(e,r,t){let n=r+1;for(let s of t)for(;;){if(n>e.length)return-1;let i=e.indexOf(`
|
|
18
|
+
`,n),o=i===-1?e.length:i,a=e.slice(n,o);if(a.endsWith("\r"))a=a.slice(0,-1);let l=s.stripTabs?a.length-a.replace(/^\t+/,"").length:0;if(s.stripTabs)a=a.slice(l);if(a===s.delimiter){n=o+1;break}if(a.startsWith(s.delimiter)&&/^\s*\)/.test(a.slice(s.delimiter.length))){if(s===t[t.length-1])return n+l+s.delimiter.length;return-1}if(i===-1)return-1;n=i+1}return n-1}function oe(e,r){let t=e.length,n=e[r+1]==="(",s=0,i=r,o=[];while(i<t){let a=e[i];if(a==="\\"){i+=2;continue}if(a==="'"){let l=Bn(e,i);if(l<0)return-1;i=l;continue}if(a==='"'){let l=jn(e,i);if(l<0)return-1;i=l;continue}if(a==="`"){let l=je(e,i);if(l<0)return-1;i=l;continue}if(!n&&a==="<"&&e[i+1]==="<"){if(e[i+2]==="<"){i+=3;continue}let l=we(e,i);if(!l)return-1;o.push(l),i=l.end;continue}if(a===`
|
|
19
|
+
`&&o.length>0){let l=st(e,i,o);if(l<0)return-1;o=[],i=l;continue}if(!n&&a==="#"&&/[\s;&|(]/.test(e[i-1])){let l=e.indexOf(`
|
|
20
|
+
`,i);if(l<0)return-1;i=l;continue}if(a==="(")s++;else if(a===")"){if(s--,s===0)return o.length>0?-1:i+1}i++}return-1}function P(e,r={}){let t=r.deep===!0,n=[],s=[],i=[],o=new Set,a=[],l=[],u=-1,c=!1,f=!0,d=0,h=e.length,p=(k)=>{if(u>=0){let b=i.length;if(i.push({text:e.slice(u,k),start:u,end:k}),c)o.add(b);u=-1,c=!1}},m=(k)=>{if(p(k),i.length>0)n.push(t?{words:i,redirects:o,heredocs:a}:{words:i,redirects:o});if(i=[],o=new Set,t)a=[];c=!1},O=(k)=>Bn(e,k),A=(k)=>je(e,k),I=(k)=>oe(e,k),j=(k)=>jn(e,k);while(d<h){let k=e[d];if(k===" "||k==="\t"||k==="\r"){p(d),d++;continue}if(k===`
|
|
21
|
+
`){if(m(d),l.length>0){let b=Tn(e,d,l,s);if(l=[],b<0)f=!1,d=h;else d=b;continue}d++;continue}if(k===";"){m(d),d++;continue}if(k==="&"){m(d),d+=e[d+1]==="&"?2:1;continue}if(k==="|"){m(d),d+=e[d+1]==="|"?2:1;continue}if(t&&k==="("&&u>=0&&"?*+@!".includes(e[d-1])){f=!1,d=h;continue}if(k==="("||k===")"){m(d),d++;continue}if(k==="<"&&e[d+1]==="<"&&e[d+2]!=="<"){let b=e.slice(d+2).match(/^-?[ \t]*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/);if(!b){f=!1,d=h;continue}if(t){let _e=d+2+b[0].length;if(_e<h&&!/[\s;&|()<>]/.test(e[_e])){f=!1,d=h;continue}p(d),l.push({delimiter:b[2],quoted:b[1]!=="",stripTabs:b[0].startsWith("-"),owner:a}),d=_e;continue}let R=e.indexOf(`
|
|
22
|
+
`,d+2+b[0].length);if(R===-1){f=!1,d=h;continue}let H=e.slice(R+1),M=Xs(H,b[2]);if(M===-1){f=!1,d=h;continue}p(d),d=R+1+M+b[2].length;continue}if(k===">"||k==="<"){if(u>=0&&/^\d+$/.test(e.slice(u,d)))u=-1;if(p(d),c=!0,d++,e[d]===k||e[d]==="&"||k===">"&&e[d]==="|"||k==="<"&&e[d]===">")d++;continue}if(k==="'"){if(u<0)u=d;let b=O(d);if(b<0)f=!1,d=h;else d=b;continue}if(k==='"'){if(u<0)u=d;let b=j(d),R=b<0||!t?[]:Zs(e,d,b);if(b<0||!R)f=!1,d=h;else s.push(...R),d=b;continue}if(k==="`"){if(u<0)u=d;let b=A(d);if(b<0)f=!1,d=h;else{let R=e.slice(d+1,b-1);s.push(t?It(R,!1):R),d=b}continue}if(k==="$"&&e[d+1]==="("){if(u<0)u=d;let b=I(d+1);if(b<0)f=!1,d=h;else s.push(e.slice(d+2,b-1)),d=b;continue}if(k==="\\"){if(u<0)u=d;if(d+1>=h)f=!1,d=h;else d+=2;continue}if(u<0)u=d;d++}if(m(h),l.length>0&&Tn(e,h,l,s)<0)f=!1;return{segments:n,trustworthy:f,substitutions:s}}function Xs(e,r){let t=0;while(t<=e.length){let n=e.indexOf(r,t);if(n===-1)return-1;let s=n===0||e[n-1]===`
|
|
23
|
+
`,i=n+r.length,o=i===e.length||e[i]===`
|
|
24
|
+
`||e[i]==="\r";if(s&&o)return n;t=n+1}return-1}function T(e){return Mn(e,!1)}function L(e){let r=0,t=0;while(r<e.words.length&&t++<32){if(e.redirects.has(r)){r++;continue}let n=e.words[r].text,s=C(n);if(Hn.test(s)&&!s.startsWith("-")){r++;continue}if(js.has(s)){r++;continue}let i=nt(s);if(i==="command")for(let a of e.words.filter((l,u)=>u>r&&!e.redirects.has(u))){let l=C(a.text);if(l==="--"||!l.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(l))return-1}let o=Ls[i];if(o){let a=r;r++;while(r<e.words.length){if(e.redirects.has(r)){r++;continue}let u=C(e.words[r].text);if(!u.startsWith("-")||u==="-")break;if(u==="--"){r++;break}if(i==="env"&&(/^-[iv0]*S/.test(u)||/^--split-string(?:=|$)/.test(u)))return a;if(r++,o.includes(u)||i==="exec"&&/^-[cl]*a$/.test(u)){while(e.redirects.has(r))r++;r++}}let l=Hs[i]??0;while(l>0&&r<e.words.length){let u=C(e.words[r].text);if(u.startsWith("-")&&u!=="-")break;r++,l--}continue}return r}return-1}function Ys(e,r){let t=[],n=!1;for(let s=r+1;s<e.words.length;s++){if(e.redirects.has(s))continue;let i=T(e.words[s].text);if(!n){if(i==="--"){n=!0;continue}if(i.startsWith("-")&&i!=="-")continue}t.push(e.words[s])}return t}function Wt(e){return Ws.map((r)=>me(e,...r.split("/")))}function Qs(e,r){if(e==="~"||e==="$HOME"||e==="${HOME}")return r;if(e.startsWith("~/"))return me(r,e.slice(2));if(e.startsWith("$HOME/"))return me(r,e.slice(6));if(e.startsWith("${HOME}/"))return me(r,e.slice(8));return e}function tt(e,r,t){let n=T(e);if(!n)return null;if(n.includes("`"))return null;if(n==="$HOME"||n==="${HOME}"||n==="$HOME/"||n==="${HOME}/")return t;if(n.replace(/\$\{HOME\}/g,"").replace(/\$HOME/g,"").includes("$"))return null;if(/[*?[\]]/.test(n))return null;if(n.startsWith("~")){let a=Qs(n,t);if(a===n)return null;n=a}let o=(Ts(n)?$s(n):Cs(r,n)).replace(/\/+$/,"");return o===""?"/":o}function Q(e,r){return e===r||e.startsWith(`${r}${Ct}`)}var Js=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/,ei=!1,ti=/^[A-Za-z0-9._@+-]{1,128}$/,ni=512;function ge(e){return`'${e.replace(/[\u0000-\u001f\u007f-\u009f]/g,"?").slice(0,ni).replace(/'/g,"'\\''")}'`}function $n(e){return ti.test(e)?`\`${e}\``:"a name that is not a plain identifier"}function ri(e,r){let t=`${me(r,".hasna","scratchpad","scratch")}${Ct}`;if(!e.startsWith(t))return null;let[n,s]=e.slice(t.length).split(Ct);if(!n)return{content:!1,reason:"the scratch root itself holds every session, not one session's content"};if(n.endsWith(".")||!Js.test(n))return{content:!1,reason:`${$n(n)} is not a session id this carve-out accepts (real ids are mixed case, e.g. \`ses_ebbb3f564ffe7PDf32UBmlNI3v\`)`};if(!s)return ei?{content:!0}:{content:!1,reason:`${$n(n)} is a session root; removing it would also remove its \`meta.json\` and \`.lock\` control files, and whether the root itself is scratch is an open decision (Todos 264c4be0) \u2014 remove specific children instead`};let i=s.normalize("NFKC").toLowerCase();if(i==="meta.json"||i===".lock")return{content:!1,reason:`\`${i}\` is session control state, not scratch`};return{content:!0}}function si(e,r){if(e===r)return`${ge(e)} is the home directory itself, which is never deleted or trashed. Delete a specific file or directory inside it instead.`;for(let t of yn){if(e!==t&&!Q(t,e))continue;return t==="/"?`${ge(e)} is the filesystem root, which is never deleted.`:`${ge(e)} is the system root \`${t}\` (or an ancestor of it), which is never deleted or trashed.`}for(let t of Ns){let n=me(r,t),s=Q(e,n);if(!s&&!Q(n,e))continue;if(t===".hasna"&&s){let i=ri(e,r);if(i?.content===!0)continue;if(i&&i.content===!1)return`${ge(e)} is inside the protected \`~/${t}\` tree and is not sanctioned scratch, because ${i.reason}. Nothing under \`~/${t}\` is deleted or trashed outside that one carve-out.`}return s?`${ge(e)} is inside the protected \`~/${t}\` tree, which is never deleted or trashed. Delete a specific file inside it, and only when you are sure.`:`${ge(e)} contains the protected \`~/${t}\` tree, which is never deleted or trashed. Delete a specific file or directory inside it instead.`}return null}function ii(e,r,t){let n=Wt(t);if(n.some((s)=>Q(r,s)))return!0;return e.some((s)=>s!==null&&n.some((i)=>Q(s,i)))}var Cn=new WeakMap;function oi(e){let r=Cn.get(e);if(r)return r;let t=e.words.map((o)=>C(o.text)),n=t.findIndex((o)=>o==="-exec"||o==="-execdir"||o==="-ok"||o==="-okdir"),s=-1;e.words.forEach((o,a)=>{if(Ln.has(T(o.text)))s=a});let i={findDelete:t.includes("-delete"),findExecDelete:n>=0&&t.slice(n).some((o)=>Pt.has(nt(o))),namesDelete:t.some((o)=>Pt.has(nt(o))),lastFlockCommand:s,textMention:U(pi(e)),envMention:U(Be(e.words.map((o)=>T(o.text)))),bodiesMention:U((e.heredocs??[]).join(`
|
|
25
|
+
`))};return Cn.set(e,i),i}var li=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]);function ai(e,r){if(!li.has(be(e.words[r].text)))return!1;for(let t=r+1;t<e.words.length;t++){if(e.redirects.has(t))continue;let n=T(e.words[t].text);if(n==="--")return t+1>=e.words.length;if(/^-[A-Za-z]*s/.test(n))return!0;if(/^-[A-Za-z]*c/.test(n))return!1;if(n==="-o"||n==="+o"||n==="-O"||n==="+O"){t++;continue}if(!/^[-+]/.test(n)||n==="-")return n==="-"}return!0}var Tt=(e)=>e.kind==="rm"||e.kind==="refuse",ui="This command's command word or wrapper arguments cannot be read before it runs (an expansion such as a variable, substitution, brace or glob pattern, an unknown or unsupported option, a working directory or a non-decimal duration), so this hook cannot tell which word runs, and one of its words could run a delete. Run the delete as a plain `rm -- <path>` command, which is redirected into trash.",ci="This delete's brace pattern names more paths than this hook will check. Run the delete on explicit paths with `rm -- <path> \u2026`, which is redirected into trash.",fi="This delete's brace pattern expands to a path under a protected repository checkout. Deletes there are refused; run them through the owning workflow, and write any other delete out as plain paths.",di="This command's wrapper arguments can be read as running two different deletes, so no single rewrite is safe. Run the delete as a plain `rm -- <path>` command, which is redirected into trash.";function Nt(e){let r=[];e.words.forEach((s,i)=>{if(!e.redirects.has(i))r.push(i)});let t=r.map((s)=>{let i=e.words[s].text;return{text:C(i),opaque:rt(i)}}),n=se(t,Fs);if(n===null)return null;return n.index<0?-1:r[n.index]}function $t(e,r,t,n){let s=be(e.words[r].text);if(s==="cd"){let l=e.words[r+1];if(!l)return{kind:"none"};return{kind:"cd",cwd:tt(l.text,t,n.home)??n.cwd}}if(Object.hasOwn(At,s))return{kind:"refuse",reason:At[s]};let i=Gn(e,r,t,n);if(i)return i;if(s==="rm"){let l=Ys(e,r);if(l.length===0)return{kind:"none"};let u={word:e.words[r],operands:l},c=Wt(n.home),f=(p)=>p!==null&&c.some((m)=>Q(p,m)),d=[],h=[];for(let p of l){let m=tt(p.text,t,n.home);if(d.push(m),!p.text.includes("{"))continue;let O=re(p.text);if(O===null)return{kind:"refuse",reason:ci};for(let A of O){let I=tt(A,t,n.home);if(I===null)continue;if(f(I)&&!f(m))return{kind:"refuse",reason:fi};h.push(I)}}if(ii(d,t,n.home))return u.cwdOnly=d.every((p)=>p!==null&&!f(p)),{kind:"rm",hit:u,handoff:!0,protectedReason:null};for(let p of[...d,...h]){if(!p)continue;let m=si(p,n.home);if(m)return{kind:"rm",hit:u,handoff:!1,protectedReason:m}}return{kind:"rm",hit:u,handoff:!1,protectedReason:null}}if(Bs.has(s)){let l=e.words.findIndex((c,f)=>f>r&&!T(c.text).startsWith("-")),u=l>=0?be(e.words[l].text):"";if(u==="rm"||Object.hasOwn(At,u))return{kind:"refuse",reason:`\`${s} ${u}\` runs the ${s} applet, whose own \`rm\` is not GNU \`rm\` and cannot be rewritten in place. Run the delete as \`rm -- <path>\`, which is redirected into trash.`};return{kind:"none"}}if(s==="git"){let l=Dt(e,r);if(l==="rm"||l==="clean"){if(!(l==="rm"?gi(e,r):qn(e,r)))return{kind:"refuse",reason:l==="rm"?"`git rm` is refused: without `--cached` it deletes the working-tree file, and its semantics are not `rm`'s. Use `rm -- <path>` (intercepted and redirected into trash) to remove the file, or `git rm --cached -- <path>` to unstage it without deleting.":"`git clean` deletes untracked files irrecoverably and is refused. Remove them explicitly with `rm -- <path>` (intercepted and redirected into trash), or preview with `git clean -n`."}}return{kind:"none"}}let o=oi(e);if(s==="find"){if(o.findDelete)return{kind:"refuse",reason:"`find -delete` deletes files irrecoverably and is refused. List the paths first (`find \u2026 -print`), then remove them explicitly with `rm -- <path>` so the delete is redirected into trash."};if(o.findExecDelete)return{kind:"refuse",reason:"`find -exec <delete>` is refused: the delete runs through find, not through `rm`, and cannot be redirected into trash. Remove the paths explicitly with `rm -- <path>`."};return{kind:"none"}}if(s==="xargs"&&o.namesDelete)return{kind:"refuse",reason:"`xargs rm` takes its targets from stdin, so this hook cannot verify what would be deleted. Pipe the paths into an explicit `rm -- <path> \u2026` instead, which is redirected into trash."};let a=s==="flock"?o.lastFlockCommand>r:Ln.has(s);if(Ds.has(s)||a){let l=ai(e,r)?n.bodiesMention:o.bodiesMention;if((s==="env"?o.envMention:o.textMention)||l)return{kind:"refuse",reason:`\`${a?"flock":s}\` runs a command string this hook cannot rewrite in place. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or as a script that uses \`trash guard\` itself.`}}return{kind:"none"}}function Gn(e,r,t,n,s={segment:e,index:r},i=0){let o=be(e.words[r].text);for(let f of He(e.words.map((d)=>C(d.text)),r,(d)=>e.redirects.has(d))){if(i>=8)return Fe(s.segment,s.index,t,n.home)?{kind:"refuse",reason:hi}:null;let d={words:e.words.slice(f.start,f.end),redirects:new Set([...e.redirects].filter((p)=>p>=f.start&&p<f.end).map((p)=>p-f.start))},h=Nt(d);for(let p of new Set([L(d),h??-1])){if(p<0)continue;let m=Gn(d,p,t,n,s,i+1);if(m)return m}}let a=e.words.map((f,d)=>({word:f,at:d})).filter(({at:f})=>!e.redirects.has(f)),l=a.findIndex(({at:f})=>f===r),u=l<0?null:Le(a.map(({word:f})=>f.text),l,C);if(u&&!u.literal&&(Fe(e,r,t,n.home)||Fe(s.segment,s.index,t,n.home)))return{kind:"refuse",reason:`\`${o}\` runs a shell program that is not a plain literal (an expansion, a substitution, ANSI-C \`$'\u2026'\` quoting or several words), so this hook cannot read what it would delete under a protected repository checkout. Write the program out literally, or run it from outside the checkout.`};let c=Me(e.words.map((f)=>C(f.text)),r,(f)=>f>=0&&f<e.words.length&&(e.redirects.has(f)||rt(e.words[f].text)));if(!c||!(Fe(e,r,t,n.home)||Fe(s.segment,s.index,t,n.home)))return null;if(!c.unresolved&&!c.programs.some((f)=>U(f.text)))return null;return{kind:"refuse",reason:`\`${o}\` runs a program locally (an interpreter's inline program or a command-running option) this hook cannot rewrite, and it could delete a file under a protected repository checkout. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or run the command from outside the checkout.`}}var hi="This command nests find/xargs launchers too deeply for this hook to read what they run under a protected repository checkout. Run the inner command directly.";function Fe(e,r,t,n){let s=Wt(n),i=(o)=>o!==null&&s.some((a)=>Q(o,a));if(s.some((o)=>Q(t,o)))return!0;for(let o=r+1;o<e.words.length;o++){if(e.redirects.has(o))continue;if(i(tt(e.words[o].text,t,n)))return!0}return!1}function Se(e,r){let t={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},n=P(e,Fn);t.trustworthy=n.trustworthy;let s={cwd:r.cwd,home:r.home,depth:r.depth??0,bodiesMention:U(n.segments.flatMap((l)=>l.heredocs??[]).join(`
|
|
26
|
+
`))};if(!n.trustworthy){let l=pe(e);return l===e?t:{...Se(l,r),trustworthy:!1}}let i=[],o=(l,u=t.refusals)=>{if(l.kind==="refuse")u.push({reason:l.reason});else if(l.kind==="rm"&&l.handoff)t.handoffHits.push(l.hit);else if(l.kind==="rm"){if(t.rmHits.push(l.hit),l.protectedReason)t.protectedHits.push({reason:l.protectedReason})}},a=s.cwd;for(let l of n.segments){let u=L(l),c=Nt(l),f=u<0?{kind:"none"}:$t(l,u,a,s);if(f.kind!=="cd")o(f);let d=(h)=>h!==null&&h>=0&&rt(l.words[h].text);if(c===null||d(u)||d(c)){if(l.words.some((h,p)=>!l.redirects.has(p)&&(Tt($t(l,p,a,s))||Vs(h.text))))i.push({reason:ui})}else if(c>=0&&c!==u){let h=$t(l,c,a,s);if(Tt(h))if(Tt(f))i.push({reason:di});else o(h,i)}if(f.kind==="cd")a=f.cwd}if(s.depth<3)for(let l of n.substitutions){let u=Se(l,{cwd:a,home:s.home,depth:s.depth+1});if(u.rmHits.length>0||u.refusals.length>0||u.handoffHits.length>0||u.protectedHits.length>0||!u.trustworthy&&U(l)){t.refusals.push({reason:"This command runs a delete inside a command substitution `$(\u2026)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(n.substitutions.some((l)=>U(l)))t.refusals.push({reason:"This command nests a delete inside command substitutions deeper than this hook will follow. Run the delete as a separate `rm -- <path>` command."});return t.refusals.push(...i),t}function pi(e){return e.words.map((r)=>r.text).join(" ")}function Dt(e,r){let t=r+1;while(t<e.words.length){let n=T(e.words[t].text);if(!n.startsWith("-"))return n;if(t++,Gs.has(n))t++}return null}function gi(e,r){if(e.words.slice(r+1).map((n)=>T(n.text)).includes("--cached"))return!0;return qn(e,r)}function qn(e,r){let t=e.words.slice(r+1).map((n)=>T(n.text));return t.includes("-n")||t.includes("--dry-run")}function Pn(e){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(e))return e;return`'${e.replace(/'/g,"'\\''")}'`}function mi(e,r,t,n){let s=n?["/usr/bin/env","-i",`HOME=${n.home}`,`PATH=${n.path}`,`HASNA_TRASH_AGENT=${n.agent}`,n.runtime,"--config=/dev/null","--no-env-file","--no-macros","--no-install",t,"guard"].map(Pn).join(" "):`${Pn(t)} guard`,i=[...r].sort((a,l)=>l.word.start-a.word.start),o=e;for(let a of i)o=`${o.slice(0,a.word.start)}${s}${o.slice(a.word.end)}`;return o}function bi(e,r,t,n,s){if(!r||r===e)return!1;if(t.length===0)return!1;let i=Se(r,{cwd:n,home:s});if(!i.trustworthy)return!1;if(i.rmHits.length>0||i.handoffHits.length>0)return!1;return i.refusals.length===0}function Si(e,r){let t={};for(let[n,s]of Object.entries(e??{}))t[n]=s;if(t.command=r,typeof t.description!=="string"||t.description.trim()==="")t.description=Is;if(typeof t.timeout!=="number"||!Number.isFinite(t.timeout)||t.timeout<=0)t.timeout=Ps;if(typeof t.run_in_background!=="boolean")t.run_in_background=!1;if("dangerouslyDisableSandbox"in t&&typeof t.dangerouslyDisableSandbox!=="boolean")delete t.dangerouslyDisableSandbox;return t}function wi(e,r,t,n,s){if(typeof e.command!=="string"||e.command.trim()==="")return!1;if(typeof e.description!=="string"||e.description.trim()==="")return!1;if(typeof e.timeout!=="number"||!Number.isFinite(e.timeout)||e.timeout<=0)return!1;if(typeof e.run_in_background!=="boolean")return!1;if("dangerouslyDisableSandbox"in e&&typeof e.dangerouslyDisableSandbox!=="boolean")return!1;return bi(r,e.command,t,n,s)}function yi(e){let r=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return P(e,Fn).segments.some((n)=>{let s=Nt(n);return[L(n),...s===null?[]:[s]].some((i)=>{if(n.words.slice(0,i<0?n.words.length:i).some((l)=>Hn.test(T(l.text))||r.has(be(l.text))))return!0;if(i<0)return!1;let a=n.words[i];return r.has(be(a.text))||/^\s*\(\s*\)\s*\{/.test(e.slice(a.end))})})}function B(e){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e}}}function xi(e){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:e}}}function ki(e){try{if(e.inspectTrash){let r=e.inspectTrash();return r.ok?{path:r.path,error:null}:{path:null,error:`${r.code}: ${wn[r.code]}`}}return{path:e.findTrash(),error:null}}catch(r){return{path:null,error:r instanceof Error?r.message:String(r)}}}var vi="[trash-guard] No verified @hasna/trash guard was found on PATH. This deletion is refused. Install the current @hasna/trash package with Bun and run its setup; the operating-system trash utility is not a compatible guard.",In="[trash-guard] The rewrite of this command did not verify (the delete could not be redirected cleanly), so the command is refused rather than run unredirected. Re-run the delete as a plain `rm -- <path>` command.";function Wn(e,r){if(e.refusals.length>0)return B(`[trash-guard] ${e.refusals[0].reason}`);if(e.protectedHits.length>0)return B(`[trash-guard] ${e.protectedHits[0].reason}`);if(!e.trustworthy)return U(r)?B("[trash-guard] This command could not be parsed to the end (unterminated quote, substitution or here-document), so a delete inside it cannot be redirected. Re-run the delete as a plain `rm -- <path>` command."):{continue:!0};if(e.rmHits.length===0){if(e.handoffHits.some((t)=>t.cwdOnly))return B("[trash-guard] This delete runs from inside a protected repository checkout but names only paths outside it. Run it from outside the checkout (`cd /tmp && rm -- <path>`), where it is redirected into trash.");return{continue:!0}}if(e.handoffHits.length>0)return B("[trash-guard] This command mixes a delete under the protected repo-checkout roots (owned by workspace-repos-guard) with a delete outside them, and a partial rewrite would leave one of them unredirected. Re-run them as separate commands, so each delete is handled by the hook that owns it.");return null}function zn(e,r){if(e.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(e.tool_name??"")){let p=e.tool_input?.command;if(typeof p!=="string")return B("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(p))return B("[trash-guard] Delete File would bypass recoverable deletion. First use `trash put -- <path>` or the trash_put MCP tool, then submit any remaining edits without the deletion block.");return{continue:!0}}if(e.tool_name!=="Bash")return{continue:!0};if(typeof e.tool_input?.command!=="string")return B("[trash-guard] The Bash tool call carried no readable `command`, so this hook cannot verify what would run. Refusing a call it cannot verify. Re-run the delete explicitly as `rm -- <path>` so it can be redirected into trash.");let n=he(e);if(!n.trim())return{continue:!0};let s=()=>Se(n,{cwd:r.cwd,home:r.home}),i=(p)=>p.rmHits.map((m)=>m.word.start).join(),o=(p)=>p()||!!ie(n,p),a=s(),l=Wn(a,n),u=ie(n,()=>{let p=s();return{result:p,verdict:Wn(p,n)}});if(u){let{result:p,verdict:m}=u;if(m&&!("continue"in m))return m;if(!m&&(!l||("continue"in l))&&i(p)!==i(a))return B(In)}if(l)return l;let c=ki(r);if(c.error!==null)return B(`[trash-guard] The guard could not resolve the \`trash\` binary (${c.error}), so this \`rm\` cannot be redirected into a recoverable delete \u2014 and an unrecoverable delete is never allowed, so the command is refused rather than run. Fix the environment (PATH, permissions) and re-run the same command.`);if(c.path===null)return B(vi);let f=c.path;if(r.execution&&o(()=>yi(n)))return B("[trash-guard] A deletion combined with shell environment changes cannot use the verified native execution context. Run the deletion as a separate plain rm command.");let d=mi(n,a.rmHits,f,r.execution),h=Si(e.tool_input,d);if(r.execution)h.hasna_execution="hasna.hooks.execution.v1";if(o(()=>!wi(h,n,a.rmHits,r.cwd,r.home)))return B(In);return xi(h)}import{closeSync as _i,constants as Un,fstatSync as Ei,lstatSync as Oi,openSync as Ri,readFileSync as Ai,statSync as Ti}from"fs";import{homedir as nr}from"os";import{dirname as Lt,isAbsolute as rr,join as ye,normalize as xe,relative as $i,resolve as Ue,sep as jt}from"path";var Ci=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),Pi=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),Ii=["hasna","hasnaxyz","hasna-products"],Ge="workspace-repos-guard";function Wi(e){return ye(e,".hasna","repos","clones")}function Ni(e){return ye(e,"workspace","repos")}function sr(e){return[Wi(e),Ni(e)]}function Di(e){return ye(e,".hasna","hooks","config","workspace-repos-guard-orgs")}var Li=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function Ht(e){let r=process.getuid?.();return r!==void 0&&(e.uid===0||e.uid===r)&&(e.mode&18)===0}function Hi(e){let r=Di(e),t;try{let s=Ri(r,Un.O_RDONLY|Un.O_NOFOLLOW);try{let o=Ei(s);if(!o.isFile()||!Ht(o)||o.size>4096)return null;t=Ai(s,"utf8")}finally{_i(s)}let i=xe(e);for(let o=Lt(r);o!==i;o=Lt(o)){let a=Oi(o);if(!a.isDirectory()||!Ht(a)||o===Lt(o))return null}if(!Ht(Ti(i)))return null}catch{return null}let n=t.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return n.length>0&&n.every((s)=>Li.test(s))?new Set(n):null}function Mi(e=process.env,r=nr()){let t=e.WORKSPACE_REPOS_GUARD_ORGS;if(typeof t==="string"&&t.trim())return new Set(t.split(",").map((n)=>n.trim()).filter(Boolean));return Hi(r)??new Set(Ii)}function Mt(e,r,t,n){if(n==="read")return{blocked:!1};let s=$i(r,e);if(s===""){if(n==="delete")return{blocked:!0,reason:`[${Ge}] delete of the protected repo-checkout root is forbidden: ${r}`};return{blocked:!0,reason:`[${Ge}] writes directly to the protected repo-checkout root are forbidden: ${r}`}}if(s.startsWith(`..${jt}`)||s===".."||rr(s))return{blocked:!1};let i=s.split(jt).filter(Boolean);if(n==="delete")return{blocked:!0,reason:`[${Ge}] delete under the protected repo-checkout root (${r}) is forbidden at any depth: ${e}`};if(i.length<=1)return{blocked:!0,reason:`[${Ge}] writing would create a top-level entry directly under the protected repo-checkout root (${r}); only GitHub-org folders belong there: ${e}`};let o=i[0];if(!t.has(o))return{blocked:!0,reason:`[${Ge}] '${o}' is not an allowed GitHub org under the protected repo-checkout root (${r}); allowed: ${[...t].join(", ")}: ${e}`};return{blocked:!1}}var ir=/\b(?:-o|--output|-O|--output-document|-out)\b/,Fi=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,Bi=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function or(e){return e.replace(Fi," ")}function ji(e){let r=[],t=null,n=0,s=0,i=!1,o=0;for(let a=0;a<e.length;a++){let l=e[a];if(t==="'"){if(l==="'")t=null;continue}if(l==="\\"){a++;continue}if(l==="("){n++;continue}if(l===")"){if(--n<0)return[e];continue}if(l==="$"&&e[a+1]==="{"){s++,a++;continue}if(l==="}"&&s>0){s--;continue}if(l==="`"){i=!i;continue}if(t==='"'){if(l==='"')t=null;continue}if(l==="'"||l==='"'){t=l;continue}if(l!=="|"||n>0||s>0||i||e[a-1]===">")continue;if(r.push(e.slice(o,a)),e[a+1]==="&")a++;o=a+1}if(t||n!==0||s!==0||i)return[e];return r.push(e.slice(o)),r}function Gi(e){let r=[],t="",n="",s=null,i=!1,o=()=>{if(!i)return;let a=n.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),l=t.startsWith("~")&&!/^~(?:\/|$)/.test(n);r.push({text:l?`./${t}`:t,opaque:/[$\x60*?[]/.test(a)||/[()]/.test(a)||Je(n)}),t="",n="",i=!1};for(let a=0;a<e.length;a++){let l=e[a];if(s==="'"){if(l==="'")s=null;else t+=l;n+=l;continue}if(l==="\\"&&a+1<e.length){let u=e[a+1];t+=s==='"'&&!/[$\x60"\\\n]/.test(u)?l+u:s==='"'&&u===`
|
|
27
|
+
`&&!Y.on?"":u,n+=l+u,i=!0,a++;continue}if(s==='"'){if(l==='"')s=null;else t+=l;n+=l;continue}if(/\s/.test(l)){o();continue}if(i=!0,n+=l,l==="'"||l==='"')s=l;else t+=l}if(s)n+="$";return o(),r}function Ft(e,r,t){let n=e[r];return n==="--help"||n==="--version"||t&&(n==="-h"||n==="-V")}var Vn={read:0,write:1,delete:2};function it(...e){return e.reduce((r,t)=>Vn[t]>Vn[r]?t:r,"read")}var qi=new Set(["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"]),lr=new Set(["put","rm","delete","remove"]),zi=new Set([...lr,"restore","restore-capsule","recover","release","locks","retention","hold","unhold","pin","unpin","retrieve","backup-retrieve"]),ar=new Set(["-delete","-exec","-execdir","-ok","-okdir","-fls","-fprint","-fprint0","-fprintf"]);function qt(e){let r=null;for(let t=0;t<e.length;t++){let n=e[t];if(r==="'"){if(n==="'")r=null;continue}if(n==="\\"){t++;continue}if(n==="$"||n==="`")return!0;if(r==='"'){if(n==='"')r=null;continue}if(n==="'"||n==='"')r=n;else if("*?[{".includes(n))return!0}return r!==null}function zt(e){let r=e.trim();if(!r)return"read";if(lt(r))return"delete";let t=P(r);if(!t.trustworthy||t.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(r))return le(r);let n=t.segments.flatMap((s)=>{let i=Zn(s),o=s.words.filter((u,c)=>!s.redirects.has(c)).map((u)=>u.text),a=o.map(re);if(a.every((u,c)=>u!==null&&u.length===1&&u[0]===o[c]))return[i];if(a.some((u)=>u===null))return[i,le(o.join(" "))];let l=P(a.flatMap((u)=>u??[]).join(" "));return[i,...l.trustworthy?l.segments.map(Zn):[le(o.join(" "))]]});return it(...n)}function Zn(e){let r=e.words.map((i,o)=>({word:i,at:o})).filter(({at:i})=>!e.redirects.has(i)),t=L(e),n=t<0?"read":Kn(e,t),s=se(r.map(({word:i})=>Ut(i.text)));if(s===null)return it(n,le(r.map(({word:i})=>T(i.text)).join(" ")));if(s.index<0||r[s.index].at===t)return n;return it(n,Kn(e,r[s.index].at))}function ur(e,r,t=0){if(r<0||t>8)return t>8;let n=e.words.map((u,c)=>({word:u,at:c})).filter(({at:u})=>!e.redirects.has(u)),s=n.findIndex(({at:u})=>u===r),i=s<0?null:Le(n.map(({word:u})=>u.text),s,C);if(i){if(!i.literal)return!0;let u=P(i.program);if(u.trustworthy&&u.segments.some((c)=>ot(c,t+1)))return!0}let o=e.words.map((u)=>C(u.text));for(let u of He(o,r,(c)=>e.redirects.has(c)))if(ot(cr(e,u.start,u.end),t+1))return!0;let l=Me(o,r,(u)=>u>=0&&u<e.words.length&&(e.redirects.has(u)||qt(e.words[u].text)));if(!l)return!1;if(l.unresolved)return!0;return l.programs.some((u)=>u.kind==="shell"?zt(u.text)!=="read":!On(u))}function cr(e,r,t){let n=new Set([...e.redirects].filter((s)=>s>=r&&s<t).map((s)=>s-r));return{words:e.words.slice(r,t),redirects:n}}function ot(e,r=0){return fr(e).some((t)=>ur(e,t,r))}function Ut(e){return{text:C(e),opaque:/[$\x60]/.test(e)&&!/^(?:[^$\x60"'\\]|\$'(?:[^'\\]|\\.)*')+$/.test(e)}}function fr(e){let r=new Set,t=L(e);if(t>=0)r.add(t);let n=e.words.map((i,o)=>({word:i,at:o})).filter(({at:i})=>!e.redirects.has(i)),s=se(n.map(({word:i})=>Ut(i.text)));if(s!==null&&s.index>=0)r.add(n[s.index].at);return[...r]}function qe(e,r=0){if(r>8)return[];let t=[];for(let n of e.segments){let s=n.words.map((a)=>C(a.text)),i=(a)=>a>=0&&a<n.words.length&&(n.redirects.has(a)||qt(n.words[a].text)),o=n.words.filter((a,l)=>!n.redirects.has(l));for(let a of fr(n)){t.push(...(Me(s,a,i)?.writes??[]).map((c)=>c[0]==="/"?c:`./${c}`));let l=Le(o.map((c)=>c.text),o.indexOf(n.words[a]),C),u=l?.literal?P(l.program):null;if(u?.trustworthy)t.push(...qe(u,r+1));for(let c of He(s,a,(f)=>n.redirects.has(f)))t.push(...qe({segments:[cr(n,c.start,c.end)]},r+1))}}for(let n of e.substitutions??[]){let s=P(n);if(s.trustworthy)t.push(...qe(s,r+1))}return t}function lt(e,r=0){if(r>4)return!1;let t=P(e),n=t.trustworthy?e:pe(e);if(n!==e)return lt(n,r+1);if(t.trustworthy&&t.segments.some((i)=>ot(i)))return!0;return(pr(e)??t.substitutions).some((i)=>lt(i,r+1))}function Kn(e,r){if(ur(e,r))return"delete";let t=e.words.filter((i,o)=>o>=r&&!e.redirects.has(o)),n=t.map((i)=>C(i.text)),s=n[0].split("/").pop();if(["rm","rmdir","shred"].includes(s??""))return Ft(n,1,!1)?"read":"delete";if(["unlink","rmtree","del"].includes(s??""))return"delete";if(s==="trash"){let i=1;while(i<n.length&&n[i].startsWith("-")){let o=n[i++];if(["--help","-h","--version","-V","--identity"].includes(o))return"read";if(["--agent","--spool","--files","--info","--config"].includes(o))i++;else if(!["--json","--local"].includes(o))return"delete"}if(i===n.length||qi.has(n[i]))return"read";if(zi.has(n[i])&&Ft(n,i+1,!0))return"read";if(["restore","restore-capsule"].includes(n[i]))return"write";return"delete"}if(s==="git"){let i=Dt(e,r);if(i==="clean"||i==="rm")return n[1]===i&&Ft(n,2,!0)?"read":"delete";return i==="clone"||i==="init"?"write":"read"}if(s==="find"&&!t.some((i)=>qt(i.text))&&!n.some((i)=>ar.has(i)))return"read";if(s==="env"&&U(Be(n)))return"delete";if(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env","xargs","find","busybox","toybox"].includes(s??""))return le(n.join(" "));if(["mkdir","mkfile","touch","mv","cp","ln","tee","install","dd","rsync","scp","truncate"].includes(s??""))return"write";if(s==="curl"||s==="wget")return ir.test(n.join(" "))?"write":"read";if(s==="sed"&&n.slice(1).some((i)=>/^-i|^--in-place(?:=|$)/.test(i)))return"write";if(["python","python3","node","bun"].includes(s??"")&&n.some((i)=>i==="-c"||i==="-e"))return"write";return"read"}function le(e){let r=e.replace(/[{},]/g," ");return r===e?Bt(e):it(Bt(e),Bt(r))}function Bt(e){let r=e.trim();if(!r)return"read";if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:rm|rmdir|unlink|shred|trash|rmtree|del)(?:\s|$)/.test(r))return"delete";if(/\bgit\b/.test(r)){if(/\bgit\b[^;&|]*\b(?:clean|rm)\b/.test(r))return"delete";if(/\bgit\b[^;&|]*\b(?:clone|init)\b/.test(r))return"write";return"read"}if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|mv|cp|ln|tee|install|dd)(?:\s|$)/.test(r))return"write";if(/\b(?:curl|wget)\b/.test(r)){if(ir.test(r))return"write";return"read"}if(/\bsed\b/.test(r)){if(/(?:^|\s)-i\S*(?:\s|$)|--in-place(?:\s|$)/.test(r))return"write"}else if(/\b(?:rsync|scp|truncate)\b/.test(r))return"write";else if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(r))return"write";if(/(?:^|[;&|])\s*echo\b/.test(r)||/>/.test(or(r)))return"write";return"read"}function ze(e,r){let t=e.trim(),n=t.match(/^(['"])([\s\S]*)\1$/);if(n)t=n[2];if(t=t.replace(/^"*\$HOME"*\//,"$HOME/"),t=t.replace(/^"*\$\{HOME\}"*\//,"${HOME}/"),t==="~")return r;if(t.startsWith("~/"))return ye(r,t.slice(2));if(t==="$HOME"||t==="${HOME}")return r;if(t.startsWith("$HOME/"))return ye(r,t.slice(6));if(t.startsWith("${HOME}/"))return ye(r,t.slice(8));let s=t.match(new RegExp(`^"*${Gt(r)}"*/`));if(s)return r+"/"+t.slice(s[0].length);return e}function Ui(e){let r=e.trim();while(r.startsWith("(")||/^\{(?:\s|$)/.test(r))r=r.slice(1).trim();while(r.endsWith(")")||/(?:^|\s)\}$/.test(r))r=r.slice(0,-1).trim();return r}function Gt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Xn(e,r,t){if(e===void 0)return[t];let n=ze(e,t),s=n.match(/^(['"])(.*)\1$/);if(s)n=s[2];if(!n||n==="-"||/[$\x60*?[\]{}~\\'"]/.test(n))return null;return[...new Set(r.map((i)=>Ue(i,n)))]}var Vi=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function Zi(e,r){let t=se(r);if(!t||t.index<=0||r[t.index].opaque)return 0;let n=P(e);if(!n.trustworthy||n.substitutions.length>0||n.segments.length!==1)return 0;let[s]=n.segments;if(s.redirects.size>0||s.words.length!==r.length)return 0;if(s.words.some((i,o)=>T(i.text)!==r[o].text))return 0;return L(s)===t.index?t.index:0}function Ki(e,r){let t=0;if(e==="git")t=r.findIndex((s)=>s.text==="rm"||s.text==="clean")+1;let n=!1;return r.slice(t).filter((s)=>{if(!n&&s.text==="--")return n=!0,!1;if(!n&&s.text.startsWith("-")&&!s.opaque)return!1;return n=!0,!0})}var Xi=new Set(["--agent","--spool","--files","--info","--config"]),Yi=new Set(["--spool","--files","--info","--config"]),Qi=new Set(["--json","--local","--help","-h","--version","--identity"]),Yn={"--agent":/^[^-]/,"--retention":/^(?:\d+(?:\.\d+)?|never)$/},Ji=new Set(["--to"]);function eo(e){let r=[],t=0;for(;t<e.length&&e[t].text.startsWith("-");t++){let i=e[t];if(i.opaque)return null;if(Xi.has(i.text)){let o=e[++t];if(!o||o.opaque)return null;if(Yi.has(i.text))r.push(o)}else if(!Qi.has(i.text))return null}let n=e[t];if(!n||n.opaque||!lr.has(n.text))return null;let s=!1;for(t++;t<e.length;t++){let i=e[t];if(s||i.opaque||i.text==="-"||!i.text.startsWith("-")){r.push(i);continue}if(i.text==="--"){s=!0;continue}let o=i.text.indexOf("="),a=o<0?i.text:i.text.slice(0,o);if(Ji.has(a)){if(o>=0)r.push({text:i.text.slice(o+1),opaque:!1});else if(e[t+1]&&!e[t+1].text.startsWith("-"))r.push(e[++t]);continue}let l=e[t+1];if(o<0&&Object.hasOwn(Yn,a)&&l&&!l.opaque&&Yn[a].test(l.text))t++}return r}function to(e){let r=e.split(`
|
|
28
|
+
`),t=[],n=[],s=0;while(s<r.length){let i=s,o=r[s++].replace(/\r$/,""),a=[];for(let l=0;l<o.length;l++){let u=o[l],c=n[n.length-1];if(u==="\\"){l++;continue}if(u==="$"&&o[l+1]==="("&&o[l+2]==="("){let f=o.indexOf("))",l+3);if(f<0)return null;l=f+1;continue}if(u==="$"&&o[l+1]==="("){n.push(0),l++;continue}if(u==="$"&&o[l+1]==="[")return null;if(u==="$"&&o[l+1]==="{"){let f=o.indexOf("}",l+2);if(f<0||/['"\x60$]|<</.test(o.slice(l+2,f)))return null;l=f;continue}if(u==="`"){let f=o.indexOf("`",l+1);if(f<0)return null;l=f;continue}if(c==='"'){if(u==='"')n.pop();continue}if(u==="'"){let f=o.indexOf("'",l+1);if(f<0)return null;l=f;continue}if(u==='"'){n.push('"');continue}if(u==="#"&&(l===0||/[\s;&|()]/.test(o[l-1])))break;if(u==="("&&o[l+1]==="("&&(l===0||/[\s;&|(]/.test(o[l-1]))){let f=o.indexOf("))",l+2);if(f<0)return null;l=f+1;continue}if(typeof c==="number"&&(u==="("||u===")")){if(u==="(")n[n.length-1]=c+1;else if(c===0)n.pop();else n[n.length-1]=c-1;continue}if(u==="<"&&o[l+1]==="<"){if(o[l+2]==="<"){l+=2;continue}let f=we(o,l);if(!f)return null;a.push({marker:f,from:l}),l=f.end-1}}for(let{marker:l,from:u}of a){let c=s;for(;;){if(s>=r.length)return null;let f=r[s++].replace(/\r$/,"");if(l.stripTabs)f=f.replace(/^\t+/,"");if(f===l.delimiter)break}t.push({line:i,from:u,to:l.end,start:c,end:s-1,quoted:l.quoted})}}return n.length===0?t:null}var no=new Set(["sh","bash","zsh","dash","ksh","mksh","ash","fish","csh","tcsh","nu","xonsh","elvish","busybox","toybox","ssh","su","runuser","sudo","doas","pkexec","xargs","parallel","expect","script","at","batch","crontab","watch","flock","chroot","nsenter","unshare","docker","podman","kubectl","lxc","python","pypy","node","nodejs","bun","deno","tsx","ts-node","zx","npx","bunx","pnpx","perl","ruby","irb","php","lua","luajit","osascript","pwsh","powershell","Rscript","R","julia","tclsh","wish","awk","gawk","mawk","nawk","sed","make","gmake","gdb","lldb","sqlite3","psql","mysql","sftp","ftp","lftp","vim","vi","nvim","ex","ed","emacs","chmod"]),ro=new Set([".","source","eval","env","alias","hash"]),so=new Set(["tee","cp","mv","install","ln"]),dr=new Set(["cat","tac","tee","head","tail","wc","cut","tr","nl","rev","fold","fmt","paste","uniq","grep","egrep","fgrep","jq","diff","cmp","comm","iconv","od","xxd","hexdump","base64","base32","md5sum","sha1sum","sha224sum","sha256sum","sha384sum","sha512sum","b2sum","cksum","echo","printf","true","false",":","test","[","read","cd","pwd","ls","mkdir","touch","stat","sleep","cp","mv","ln","rm","rmdir","unlink","shred","trash","todos","conversations","mementos","knowledge","files","asks"]),io=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),oo=new Set(["pr","issue","api","release","gist"]);function lo(e,r){let t=e[r];if(t==="gh")return oo.has(e[r+1]??"");if(t!=="git")return dr.has(t);for(let n=r+1;n<e.length;n++){let s=e[n];if(s==="-C")n++;else if(s==="--no-pager"||s==="-P")continue;else return!s.startsWith("-")&&io.has(s)}return!1}function ao(e,r){for(let t=r+1;t<e.length;t++){let n=e[t];if(n==="\\")t++;else if(n==='"')return t;else if(n==="$"&&e[t+1]==="("){if(t=hr(e,t+1),t<0)return-1}else if(n==="`"){if(t=e.indexOf("`",t+1),t<0)return-1}}return-1}function hr(e,r){let t=0;for(let n=r;n<e.length;n++){let s=e[n];if(s==="\\")n++;else if(s==="'"||s==="`"){if(n=e.indexOf(s,n+1),n<0)return-1}else if(s==='"'){if(n=ao(e,n),n<0)return-1}else if(s==="(")t++;else if(s===")"&&--t===0)return n}return-1}function pr(e){let r=[],t=!1;for(let n=0;n<e.length;n++){let s=e[n];if(s==="\\")n++;else if(s==="'"&&!t){let i=e.indexOf("'",n+1);if(i<0)return null;n=i}else if(s==='"')t=!t;else if(s==="$"&&e[n+1]==="("){let i=hr(e,n+1);if(i<0)return null;let o=e.slice(n+2,i);if(e[n+2]==="("){if(/\$\(|\x60/.test(o))return null}else r.push(o);n=i}else if(s==="`"){let i=e.indexOf("`",n+1);if(i<0)return null;r.push(e.slice(n+1,i)),n=i}}return t?null:r}function uo(e){if(/[<>]\(/.test(e))return!0;let r=[],t=[e];for(let s=0;t.length>0;s++){if(s>64)return!0;let i=t.shift(),o=P(i),a=pr(i);if(!o.trustworthy||!a)return!0;r.push(...o.segments),t.push(...new Set([...o.substitutions,...a]))}let n=new Set;for(let s of r){let i=s.words.map((l)=>T(l.text));for(let l of s.redirects)n.add(z(i[l]??""));let o=L(s);if(o<0)continue;let a=z(i[o]);if(so.has(a)){for(let l of i.slice(o+1))if(!l.startsWith("-"))n.add(z(l))}if(a==="dd"){for(let l of i)if(l.startsWith("of="))n.add(z(l.slice(3)))}}n.delete("");for(let s of r){for(let u of s.words){let c=z(T(u.text));if(no.has(c)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(c))return!0}let i=L(s),o=s.words.map((u,c)=>({text:T(u.text),at:c})).filter(({at:u})=>!s.redirects.has(u));if(o.some(({text:u,at:c})=>(i<0||c<i)&&We.test(u)))return!0;if(i<0)continue;let a=s.words[i].text,l=T(a);if(/[$\x60]/.test(a)||l.includes("/")||ro.has(l)||n.has(l))return!0;if(!lo(o.filter(({at:u})=>u>=i).map(({text:u})=>u),0))return!0}return!1}function co(e){if(!e.includes("<<"))return null;let r=to(e);if(!r||r.length===0)return null;let t=e.split(`
|
|
29
|
+
`),n=[...t],s=[];for(let o of r){let a=t.slice(o.start,o.end);if(!o.quoted&&a.some((l)=>/\$\(|\x60/.test(l)))return null;s.push(a.join(`
|
|
30
|
+
`));for(let l=o.start;l<=o.end;l++)n[l]=""}let i=[...n];for(let o of[...r].reverse()){let a=i[o.line];i[o.line]=a.slice(0,o.from)+" ".repeat(o.to-o.from)+a.slice(o.to)}return uo(i.join(`
|
|
31
|
+
`))?null:{outer:n.join(`
|
|
32
|
+
`),bodies:s}}var fo="/";function at(e,r,t){if(!e)return[];let n=P(e).trustworthy?e:pe(e),s=co(e);return[...n===e?[]:at(n,r,t),...s?[...tr(s.outer,r,t),...s.bodies.flatMap((i)=>at(i,r,fo))]:tr(e,r,t)]}var ho=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,po=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function Qn(e,r,t=!1){let n=[],s=0;for(let a of r)n.push(s),s+=a.length;let i=P(e);if(!i.trustworthy||!t&&i.substitutions.length>0)return null;let o=i.segments.flatMap((a)=>a.words).filter((a)=>r.some((l,u)=>u%2===1&&n[u]<a.end&&n[u]+l.length>a.start));return o.length>0?{lexed:i,offsets:n,words:o}:null}function Jn(e,r,t=[]){if(zt(r)!=="read")return!1;let n=L(e),s=e.words.filter((c,f)=>!e.redirects.has(f)),i=se(s.map((c)=>Ut(c.text)));if(i===null)return!1;let o=[n<0?1/0:n,i.index<0?1/0:e.words.indexOf(s[i.index])];if(e.words.some((c,f)=>f<Math.max(...o)&&!e.redirects.has(f)&&We.test(T(c.text))))return!1;if([n<0?null:e.words[n].text,i.index<0?null:s[i.index].text].every((c)=>c===null||dr.has(z(T(c)))))return!0;let l=s.filter((c)=>!t.includes(c)),u=l.map((c)=>T(c.text));return le(l.map((c)=>c.text).join(" "))==="read"&&le(u.join(" "))==="read"&&!u.some((c)=>ar.has(c))}function go(e,r,t,n){let s=(i)=>i.start<n&&i.end>t;if(!r.words.some(s))return!1;return r.lexed.segments.filter((i)=>i.words.some(s)).some((i)=>ot(i))}var er=(e,r)=>e.slice(r.words[0].start,r.words[r.words.length-1].end);function mo(e,r,t,n){let s=(o)=>o.start<n&&o.end>t,i=r.words.filter(s);if(i.length===0||i.some((o)=>!po.test(o.text)))return!1;for(let o of r.lexed.segments.filter((a)=>a.words.some(s)))if(!Jn(o,er(e,o),r.words))return!1;for(let o of i){let a=o.text.slice(1,-1);if(a.includes("<<"))return!1;let l=P(a);if(!l.trustworthy||l.substitutions.length>0)return!1;if(!l.segments.every((u)=>Jn(u,er(a,u))))return!1}return!0}function tr(e,r,t){if(!e)return[];let n=sr(r),s=(h)=>n.some((p)=>h===p||h.startsWith(`${p}${jt}`)),i=e.split(ho),o=Qn(e,i),a=o??Qn(e,i,!0),l=[],u=[t],c=new Set([t]),f=!0,d=[];for(let h=0;h<i.length;h+=2){let p=h===0?"":i[h-1].trim();if(p==="||")f=!1;else if(p!=="&&")f=!0;if(p!=="&&"||!f)u=[...c];let m=i[h],O=(m.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,A=(m.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let S=0;S<O;S++)d.push({current:[...u],reachable:new Set(c),certain:f});let I=Ui(m),j=o!==null&&mo(e,o,o.offsets[h],o.offsets[h]+m.length),k=!j&&(a!==null&&go(e,a,a.offsets[h],a.offsets[h]+m.length)||lt(m.trim())),b=I.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),R=b?null:I.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(R){for(let S of Xn(R[1],u,r)??[])c.add(S);f=!1,u=[...c]}let H=Gt(r),M=n.map((S)=>Gt(S.slice(r.length+1))).join("|"),_e=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${H}"*)/(?:${M})`),pn=new RegExp(`(${_e.source})([^\\s"';&|<>()\`]*|$)`,"g"),gn=(S)=>{let N=[],F;pn.lastIndex=0;while((F=pn.exec(S))!==null)N.push(xe(ze(F[0],r)).replace(/\/+$/,""));return N},mn=a===null?0:a.offsets[h],bn=(S)=>S.start<mn+m.length&&S.end>mn,Dr=a!==null&&a.words.some(bn)?qe({segments:a.lexed.segments.filter((S)=>S.words.some(bn))}):[m.trim(),I].flatMap((S)=>{let N=P(S);if(!N.trustworthy)N=P(pe(S));return N.trustworthy?qe(N):[]}),mt=ji(I).map((S,N)=>{let F=N===0?[...new Set(Dr)]:[],Ee=!1,Oe=or(S).replace(Bi,(St,ce)=>{if(!ce||/[$\x60]/.test(ce))Ee=!0;if(ce)F.push(ce);return" "}),Re=j?"read":k?"delete":zt(Oe);return{commandPart:Oe,operands:F,op:Ee&&Re==="read"?"write":Re}}),Lr=mt.some((S)=>S.op==="delete")?"delete":mt.some((S)=>S.op==="write")?"write":"read",bt=u.filter(s);if(k)for(let S of bt)l.push({path:S,op:"delete"});for(let S of mt){let N=!1;for(let D of gn(S.commandPart))N=!0,l.push({path:D,op:Lr});for(let D of S.operands){let K=gn(D);for(let q of K)l.push({path:q,op:"write"});if(K.length>0)continue;for(let q of bt)l.push({path:xe(Ue(q,ze(D,r))),op:"write"})}if(N||S.op==="read")continue;let F=Gi(S.commandPart),Ee=Zi(S.commandPart,F),Oe=z(F[Ee]?.text??""),Re=F.slice(Ee+1),St=((Oe==="trash"?eo(Re):null)??Ki(Oe,Re)).map((D)=>D.opaque?".":D.text),ce=S.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(S.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(S.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(S.commandPart),Ae=[];if(ce)for(let D of St.length>0?St:["."])Ae.push({operand:D,op:S.op});else{let D=S.commandPart.match(Vi),K=F.at(-1);if(Ae.push({operand:D?D[1]:!K||K.opaque?".":K.text,op:S.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(S.commandPart))F.forEach((q,Sn)=>{let fe,wt=q.text.match(/^-[A-Za-z]*?t(.*)$/),Ze=q.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(wt&&!q.text.startsWith("--"))fe=wt[1]?{text:wt[1],opaque:q.opaque}:F[Sn+1];else if(Ze&&"--target-directory".startsWith(Ze[1]))fe=Ze[2]!==void 0?{text:Ze[2],opaque:q.opaque}:F[Sn+1];if(fe)Ae.push({operand:fe.opaque||!fe.text?".":fe.text,op:S.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(S.commandPart))Ae.push({operand:".",op:S.op})}for(let D of bt)for(let{operand:K,op:q}of Ae)l.push({path:xe(Ue(D,ze(K,r))),op:q})}if(b){let S=Xn(b[1],u,r);if(S){for(let N of S)c.add(N);if(f)u=S}else f=!1}for(let S=0;S<A&&d.length>0;S++)({current:u,reachable:c,certain:f}=d.pop())}return l}var bo=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function So(e,r){let t=[],n;while((n=bo.exec(e))!==null){let s=n[1]==="Delete File"?"delete":"write";t.push({path:xe(Ue(r,n[2])),op:s})}return t}function gr(e,r={}){let t=[];if(e.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:t};let n=typeof e.tool_name==="string"?e.tool_name:"",s=r.home??nr(),i=sr(s),o=Mi(process.env,s);if(n==="Bash"){let d=he(e);if(!d)return{output:{continue:!0},warnings:t};let h=typeof e.cwd==="string"&&e.cwd?e.cwd:process.cwd(),p=at(d,s,h);p.unshift(...ie(d,()=>at(d,s,h))??[]);for(let m of p)for(let O of i){let A=Mt(m.path,O,o,m.op);if(A.blocked)return{output:{decision:"block",reason:A.reason},warnings:t}}return{output:{continue:!0},warnings:t}}let a=e.tool_input??{},l=typeof e.cwd==="string"&&e.cwd?e.cwd:process.cwd();if(Pi.has(n)){let d=typeof a.patch==="string"?a.patch:"";if(!d)return{output:{continue:!0},warnings:t};let h=So(d,l);for(let p of h)for(let m of i){let O=Mt(p.path,m,o,p.op);if(O.blocked)return{output:{decision:"block",reason:O.reason},warnings:t}}return{output:{continue:!0},warnings:t}}if(!Ci.has(n))return{output:{continue:!0},warnings:t};let u=typeof a.file_path==="string"?a.file_path:typeof a.path==="string"?a.path:typeof a.notebook_path==="string"?a.notebook_path:null;if(!u)return{output:{continue:!0},warnings:t};let c=ze(u,s),f=rr(c)?xe(c):Ue(l,c);for(let d of i){let h=Mt(f,d,o,"write");if(h.blocked)return{output:{decision:"block",reason:h.reason},warnings:t}}return{output:{continue:!0},warnings:t}}var wo=new Set(["id","node_id","databaseId","fullDatabaseId","number","state","state_reason","stateReason","status","conclusion","bucket","name","login","sha","oid","abbreviatedOid","ref","headRefName","baseRefName","headRefOid","baseRefOid","head_sha","headSha","head_branch","headBranch","merged","mergeable","mergeable_state","mergeStateStatus","draft","isDraft","locked","isLocked","title","displayTitle","display_title","created_at","updated_at","closed_at","merged_at","started_at","completed_at","submitted_at","pushed_at","published_at","createdAt","updatedAt","closedAt","mergedAt","startedAt","completedAt","submittedAt","pushedAt","publishedAt","tag_name","tagName","total_count","totalCount","count","additions","deletions","changes","changed_files","changedFiles","filename","path","event","workflow","workflowName","workflow_id","workflowDatabaseId","run_id","run_number","run_attempt","attempt","check_suite_id","default_branch","defaultBranch","full_name","fullName","nameWithOwner","private","isPrivate","visibility","archived","isArchived","fork","isFork","isRequired","is_required","required","context","type","__typename","role","permission","size","reviewDecision","author_association","authorAssociation","isCrossRepository","maintainerCanModify","maintainer_can_modify","commentsCount","language","digest","size_in_bytes","run_started_at","date","wait_timer","ahead_by","behind_by","total_commits","expired","current_user_can_approve","environment","html_url"]),yo=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),wr=new Set(["length","utf8bytelength","not","type","any","all","isempty","empty","test","startswith","endswith","contains","inside","has","in","index","rindex","indices","floor","ceil","round","fabs","sqrt","isinfinite","isnan","isnormal","infinite","nan","true","false","null"]),yr=new Set(["tostring","tojson","ascii_downcase","ascii_upcase","ltrimstr","rtrimstr","trim","ltrim","rtrim","sort","unique","reverse","first","last","min","max","add","flatten","join","split","values","nulls","strings","numbers","booleans","arrays","objects","iterables","scalars","sort_by","group_by","unique_by","min_by","max_by","select","limit","to_entries","from_entries"]),xo=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),ko=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class Kt extends Error{}var _=()=>{throw new Kt};function Vt(e,r){let t=[],n="",s=r+1;while(s<e.length){let i=e[s];if(i==='"'){if(n)t.push(n);return{end:s+1,parts:t}}if(i==="\\"){let o=e[s+1];if(o==="("){let a=1,l=s+2;while(l<e.length&&a>0){let u=e[l];if(u==='"'){l=Vt(e,l).end;continue}if(u==="(")a++;else if(u===")")a--;l++}if(a!==0)_();if(n)t.push(n),n="";t.push({src:e.slice(s+2,l-1)}),s=l;continue}if(o===void 0)_();n+=o,s+=2;continue}n+=i,s++}return _()}function xr(e){let r=[],t=0,n=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while(t<e.length){let s=e[t];if(/\s/.test(s)){t++;continue}if(s==="#")_();if(s==='"'){let l=Vt(e,t);r.push({t:"str",parts:l.parts}),t=l.end;continue}if(s==="."){if(e[t+1]===".")_();let l=/^[A-Za-z_][A-Za-z0-9_]*/.exec(e.slice(t+1));if(l){r.push({t:"field",name:l[0]}),t+=1+l[0].length;continue}if(e[t+1]==='"'){let u=Vt(e,t+1);if(u.parts.some((c)=>typeof c!=="string"))_();r.push({t:"field",name:u.parts.join("")}),t=u.end;continue}r.push({t:"dot"}),t++;continue}if(s==="$"||s==="@"){let l=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(e.slice(t));if(!l||s==="$")_();r.push({t:"fmt",name:l[0]}),t+=l[0].length;continue}let i=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(e.slice(t));if(i){r.push({t:"num"}),t+=i[0].length;continue}let o=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(e.slice(t));if(o){r.push({t:"ident",name:o[0]}),t+=o[0].length;continue}let a=n.find((l)=>e.startsWith(l,t));if(!a)_();r.push({t:"op",v:a}),t+=a.length}return r}var vo=new Set(["if","then","elif","else","end","as","def","reduce","foreach","try","catch","label","import","include","and","or","__loc__","error","input","inputs","debug","stderr","env","halt","halt_error","input_filename","input_line_number","recurse","paths","leaf_paths","getpath","setpath","delpaths","del","path","splits","sub","gsub","capture","match","scan","keys","keys_unsorted","map_values","with_entries","tostream","fromstream","truncate_stream","walk","tonumber","implode","explode","ascii","fromjson"]);class Xt{tokens;at=0;constructor(e){this.tokens=e}parse(){if(this.tokens.length===0)_();let e=this.pipe();if(this.at!==this.tokens.length)_();return e}peek(){return this.tokens[this.at]}isOp(e){let r=this.peek();return!!r&&r.t==="op"&&r.v===e}isIdent(e){let r=this.peek();return!!r&&r.t==="ident"&&r.name===e}expectOp(e){if(!this.isOp(e))_();this.at++}pipe(){let e=this.comma();if(this.isIdent("as"))_();if(this.isOp("|"))this.at++,e={k:"pipe",a:e,b:this.pipe()};return e}comma(){let e=this.alt();while(this.isOp(","))this.at++,e={k:"comma",a:e,b:this.alt()};return e}alt(){let e=this.or();if(this.isOp("//"))return this.at++,{k:"alt",a:e,b:this.alt()};return e}or(){let e=this.and();while(this.isIdent("or"))this.at++,e={k:"bool",a:e,b:this.and()};return e}and(){let e=this.cmp();while(this.isIdent("and"))this.at++,e={k:"bool",a:e,b:this.cmp()};return e}cmp(){let e=this.add();for(let r of["==","!=","<=",">=","<",">"])if(this.isOp(r))return this.at++,{k:"bool",a:e,b:this.add()};for(let r of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(r))_();return e}add(){let e=this.mul();while(this.isOp("+")||this.isOp("-"))this.at++,e={k:"arith",a:e,b:this.mul()};return e}mul(){let e=this.unary();while(this.isOp("*")||this.isOp("/")||this.isOp("%"))this.at++,e={k:"arith",a:e,b:this.unary()};return e}unary(){if(this.isOp("-"))return this.at++,{k:"neg",of:this.postfix()};return this.postfix()}objectValue(){let e=this.unary();if(this.isOp("|"))this.at++,e={k:"pipe",a:e,b:this.objectValue()};return e}postfix(){let e=this.primary();for(;;){let r=this.peek();if(!r)return e;if(r.t==="field"){this.at++,e={k:"field",name:r.name,of:e};continue}if(r.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(r.t==="op"&&r.v==="?"){this.at++,e={k:"opt",of:e};continue}if(r.t==="op"&&r.v==="["){e=this.bracket(e);continue}return e}}bracket(e){if(this.expectOp("["),this.isOp("]"))return this.at++,{k:"iter",of:e};if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:e}}let r=this.pipe();if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:e}}return this.expectOp("]"),{k:"index",of:e,key:r}}primary(){let e=this.peek();if(!e)return _();switch(this.at++,e.t){case"dot":return{k:"dot"};case"field":return{k:"field",name:e.name};case"num":return{k:"lit"};case"str":return this.stringNode(e.parts);case"fmt":{if(!ko.has(e.name))_();let r=this.peek();if(r?.t==="str")return this.at++,{k:"fmt",name:e.name,str:this.stringNode(r.parts)};return{k:"fmt",name:e.name}}case"ident":{if(vo.has(e.name))_();if(e.name==="map"||wr.has(e.name)||yr.has(e.name)){let r=[];if(this.isOp("(")){this.at++,r.push(this.pipe());while(this.isOp(";"))this.at++,r.push(this.pipe());this.expectOp(")")}return{k:"call",name:e.name,args:r}}return _()}case"op":{if(e.v==="("){let r=this.pipe();return this.expectOp(")"),r}if(e.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let r=this.pipe();return this.expectOp("]"),{k:"array",of:r}}if(e.v==="{")return this.object();return _()}}return _()}stringNode(e){let r=[];for(let t of e){if(typeof t==="string")continue;r.push(new Xt(xr(t.src)).parse())}return r.length===0?{k:"str",parts:r,text:e.join("")}:{k:"str",parts:r}}object(){let e=[];if(this.isOp("}"))return this.at++,{k:"object",entries:e};for(;;){let r=this.peek();if(!r)_();this.at++;let t;if(r.t==="ident")t=r.name;else if(r.t==="str"){if(r.parts.some((n)=>typeof n!=="string"))_();t=r.parts.join("")}else _();if(this.isOp(":"))this.at++,e.push({key:"static",value:this.objectValue()});else e.push({key:"static",value:{k:"field",name:t}});if(this.isOp(",")){this.at++;continue}return this.expectOp("}"),{k:"object",entries:e}}}}function Yt(e){if(typeof e==="object"&&"union"in e)return e.union.every(Yt);return e==="safe"||typeof e==="object"&&wo.has(e.leaf)}var Ve=(...e)=>e.every(Yt)?"safe":"tainted";function Zt(...e){let r=[];for(let t of e)if(typeof t==="object"&&"union"in t)r.push(...t.union);else r.push(t);return r.length===1?r[0]:{union:r}}function ut(e,r){return typeof e==="object"&&"union"in e?Zt(...e.union.map(r)):r(e)}var ct=(e)=>typeof e==="object"&&("leaf"in e)&&yo.has(e.leaf),J=(e)=>ut(e,(r)=>r==="safe"?"safe":r==="tainted"||ct(r)?"tainted":"unknown");function mr(e){return e.k==="lit"||e.k==="str"&&e.parts.length===0||e.k==="call"&&["true","false","null"].includes(e.name)&&e.args.length===0}function br(e,r,t){return ut(e,(n)=>{if(n==="safe"||n==="tainted")return n;if(ct(n))return"tainted";if(n==="root"&&t.rootScalars.has(r))return"safe";return{leaf:r}})}function E(e,r,t){switch(e.k){case"dot":return r;case"field":return br(e.of?E(e.of,r,t):r,e.name,t);case"iter":return J(E(e.of,r,t));case"index":{let n=E(e.of,r,t);if(e.key.k==="str"&&e.key.text!==void 0)return br(n,e.key.text,t);if(e.key.k==="lit")return J(n);return E(e.key,r,t),"tainted"}case"slice":return ut(E(e.of,r,t),(n)=>n==="root"?"unknown":ct(n)?"tainted":n);case"opt":return E(e.of,r,t);case"lit":return"safe";case"str":return Ve(...e.parts.map((n)=>E(n,r,t)));case"fmt":return e.str?E(e.str,r,t):r;case"array":return e.of?Ve(E(e.of,r,t)):"safe";case"object":return Ve(...e.entries.map((n)=>E(n.value,r,t)));case"pipe":return E(e.b,E(e.a,r,t),t);case"comma":return Zt(E(e.a,r,t),E(e.b,r,t));case"alt":return Zt(E(e.a,r,t),E(e.b,r,t));case"bool":return E(e.a,r,t),E(e.b,r,t),"safe";case"arith":return Ve(E(e.a,r,t),E(e.b,r,t));case"neg":return E(e.of,r,t);case"call":return _o(e,r,t)}}var Sr=(e)=>ut(e,(r)=>r==="root"?"unknown":ct(r)?"tainted":r);function _o(e,r,t){let{name:n,args:s}=e;if(xo.has(n)&&n!=="limit"&&!s.every(mr))_();switch(n){case"map":if(s.length!==1)_();return Ve(E(s[0],J(r),t));case"select":if(s.length!==1)_();return E(s[0],r,t),r;case"limit":if(s.length!==2||!mr(s[0]))_();return E(s[1],r,t);case"first":case"last":if(s.length>1)_();return s.length===1?E(s[0],r,t):J(r);case"min":case"max":return J(r);case"sort_by":case"group_by":case"unique_by":if(s.length!==1)_();return E(s[0],J(r),t),Sr(r);case"min_by":case"max_by":if(s.length!==1)_();return E(s[0],J(r),t),J(r);case"any":case"all":case"isempty":for(let i of s)E(i,"unknown",t);return"safe"}if(wr.has(n))return"safe";if(yr.has(n))return Sr(r);return _()}function kr(e,r={}){if(typeof e!=="string"||!e.trim()||e.length>4096)return!1;try{let t=new Xt(xr(e)).parse();return Yt(E(t,"root",{rootScalars:r.rootScalars??new Set}))}catch(t){if(t instanceof Kt)return!1;return!1}}var ln="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",x={refused:!1},y=(e)=>({refused:!0,rule:e}),Qt=new Set(["additions","assignees","author","baseRefName","baseRefOid","changedFiles","closed","closedAt","createdAt","deletions","files","fullDatabaseId","headRefName","headRefOid","headRepository","headRepositoryOwner","id","isCrossRepository","isDraft","labels","maintainerCanModify","mergeCommit","mergeStateStatus","mergeable","mergedAt","mergedBy","number","potentialMergeCommit","reactionGroups","reviewDecision","reviewRequests","state","title","updatedAt","url"]),Jt=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),vr=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),_r=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),Eo=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),Oo=new Set(["author","committer","id","parents","repository","sha","url"]),Ro=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function Rr(e){let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(n==="\\"){t++;continue}if(n==="'"){let s=e.indexOf("'",t+1);if(s<0)return!1;t=s;continue}if(n==='"'){t++;while(t<e.length&&e[t]!=='"')t+=e[t]==="\\"?2:1;continue}if(n==="{"){r.push({list:!1});continue}if(r.length===0)continue;if(n===","||n==="."&&e[t+1]===".")r[r.length-1].list=!0;else if(n==="}"&&r.pop().list)return!0}return!1}function ke(e){let r="",t=!1,n=0,s=(i)=>e[i]==="`"||e[i]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(e[i+1]??"");while(n<e.length){let i=e[n];if(i==="\\"){r+=e[n+1]??"",n+=2;continue}if(i==="$"&&e[n+1]==="'"){t=!0,r+=i,n++;continue}if(i==="'"){let o=e.indexOf("'",n+1);if(o<0){t=!0,r+=e.slice(n+1);break}r+=e.slice(n+1,o),n=o+1;continue}if(i==='"'){n++;while(n<e.length&&e[n]!=='"'){if(e[n]==="\\"&&/[$`"\\\n]/.test(e[n+1]??"")){r+=e[n+1],n+=2;continue}if(s(n))t=!0;r+=e[n],n++}if(n>=e.length)t=!0;n++;continue}if(s(n)||i==="*"||i==="?"||i==="[")t=!0;r+=i,n++}if(!t&&e.includes("{")&&Rr(e))t=!0;return{value:r,opaque:t,raw:e}}var ae=(e)=>e.slice(e.lastIndexOf("/")+1);function nn(e,r="word"){let t=[],n=!1;for(let s=0;s<e.length;s++){let i=e[s];if(i==="\\"){s++;continue}if(r==="word"&&i==="'"&&!n){let o=e.indexOf("'",s+1);if(o<0)return{bodies:t,complete:!1};s=o;continue}if(r==="word"&&i==='"'){n=!n;continue}if(i==="`"){let o=s+1;while(o<e.length&&e[o]!=="`")o+=e[o]==="\\"?2:1;if(o>=e.length)return{bodies:t,complete:!1};t.push(e.slice(s+1,o)),s=o;continue}if(i==="$"&&e[s+1]==="("){let o=oe(e,s+1);if(o<0)return{bodies:t,complete:!1};t.push(e.slice(s+2,o-1)),s=o-1}}return{bodies:t,complete:!0}}function ve(e,r){let t=new Set(r.values),n={flags:[],positionals:[]},s=(i,o)=>({value:i,opaque:o.opaque,raw:o.raw});for(let i=0;i<e.length;i++){let o=e[i],a=o.value;if(a==="--"){n.positionals.push(...e.slice(i+1));break}if(a.startsWith("--")&&a.length>2){let l=a.indexOf("="),u=l>=0?a.slice(0,l):a;if(l>=0)n.flags.push({name:u,value:s(a.slice(l+1),o),inline:!0});else if(t.has(u)){let c=e[i+1];n.flags.push(c?{name:u,value:c}:{name:u,missing:!0}),i++}else n.flags.push({name:u});continue}if(a.startsWith("-")&&a.length>1){for(let l=1;l<a.length;l++){let u="-"+a[l],c=a.slice(l+1);if(c.startsWith("=")){n.flags.push({name:u,value:s(c.slice(1),o),inline:!0});break}if(!t.has(u)){n.flags.push({name:u});continue}if(c)n.flags.push({name:u,value:s(c,o),inline:!0});else{let f=e[i+1];n.flags.push(f?{name:u,value:f}:{name:u,missing:!0}),i++}break}continue}n.positionals.push(o)}return n}function W(e,...r){let t=!1;for(let n of e.flags){if(!r.includes(n.name))continue;if(!n.inline){t=!0;continue}let s=n.value;t=!s.opaque&&["1","t","T","TRUE","true","True"].includes(s.value)}return t}var te=(e,...r)=>e.flags.filter((t)=>r.includes(t.name)),G=["-R","--repo","-q","--jq","-t","--template","--json"],ue={"pr view":{values:G},"issue view":{values:G},"release view":{values:G},"discussion view":{values:[...G,"--after","-L","--limit","--order"]},"pr list":{values:[...G,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...G,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...G,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...G,"-L","--limit","-O","--order"]},"pr status":{values:G},"issue status":{values:G},"pr checks":{values:[...G,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...G,"--app","--assignee","--author","--author-date","--author-email","--author-name","--base","--checks","--closed","--commenter","--committer","--committer-date","--committer-email","--committer-name","--created","--hash","--head","--interactions","--involves","--label","--language","--limit","-L","--match","--mentions","--merged-at","--milestone","--no-assignee","--no-label","--no-milestone","--no-project","--order","--owner","--parent","--project","--reactions","--review","--review-requested","--reviewed-by","--sort","--state","--team-mentions","--tree","--updated","--visibility","--extension","--filename","--size","--forks","--good-first-issue","--help-wanted-issues","--number-topics","--stars","--topic","--followers","--include-forks","--license"]},"project item-list":{values:["--format","-L","--limit","--owner","-q","--jq","-t","--template","--query","--field","--field-id"]},api:{values:["-X","--method","-H","--header","-f","--raw-field","-F","--field","-q","--jq","-t","--template","-p","--preview","--input","--hostname","--cache"]},group:{values:["-R","--repo"]}},Ao=new Set(["auth","browse","codespace","cs","gist","org","repo","skill","cache","run","workflow","co","agent-task","alias","attestation","completion","config","copilot","extension","ext","extensions","gpg-key","label","licenses","preview","ruleset","secret","ssh-key","variable","help","version","accessibility","actions","environment","exit-codes","formatting","mintty","reference","telemetry"]),To=new Set(["pr","issue","release","discussion","search","project","api","status"]),$o=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),Co=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),Po=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),Io=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function pt(e,r){let t=te(e,"--json"),n=[],s=!1;for(let i of t){if(i.missing){if(r.appendsArgs)s=!0;continue}if(!i.value)continue;if(i.value.opaque)s=!0;n.push(...i.value.value.split(",").map((o)=>o.trim()).filter(Boolean))}return{present:t.length>0,opaque:s,fields:n}}function an(e,r){if(W(e,"--verbose")||te(e,"-t","--template").length>0)return!1;let t=te(e,"-q","--jq");return t.length>0&&t.every((n)=>n.value!==void 0&&!n.value.opaque&&kr(n.value.value,{rootScalars:r}))}function un(e,r,t,n){let s=pt(e,t);if(s.opaque)return y("unclassifiable");if(s.fields.every((i)=>r.has(i)))return x;if(t.debug)return y("debug-traffic");return an(e)?x:y(n)}function ft(e,r,t,n,s){let i=ve(e,ue[r]);if(W(i,"-h","--help"))return x;if(W(i,"-w","--web"))return n.debug?y("debug-traffic"):x;if(s&&W(i,"-c","--comments"))return y("view-comments");if(!pt(i,n).present)return y(n.debug?"debug-traffic":"view-human");return un(i,t,n,"json-composite")}function ee(e,r,t,n){let s=ve(e,ue[r]);if(W(s,"-h","--help"))return x;if(n.debug&&(W(s,"-w","--web")||!pt(s,n).present))return y("debug-traffic");if(W(s,"-w","--web"))return x;return un(s,t,n,"json-composite")}function Wo(e,r){let t=ve(e,ue["pr checks"]);if(W(t,"-h","--help"))return x;if(r.debug)return y("debug-traffic");if(W(t,"-w","--web"))return x;if(!pt(t,r).present)return y("checks-human");return un(t,Ro,r,"checks-json")}function No(e){let r=new Set(ue.group.values);for(let t=0;t<e.length;t++){let n=e[t].value;if(n==="--")return{sub:e[t+1],rest:e.slice(t+2)};if(!n.startsWith("-")||n==="-")return{sub:e[t],rest:[...e.slice(0,t),...e.slice(t+1)]};if(r.has(n))t++}return{rest:e}}function Do(e,r,t){let{sub:n,rest:s}=No(r);if(!n)return t.appendsArgs?y("unclassifiable"):x;if(n.opaque)return y("unclassifiable");let i=n.value;if((e==="pr"?$o:e==="issue"?Co:e==="release"?Po:e==="discussion"?Io:new Set).has(i))return t.debug?y("debug-traffic"):x;if(t.appendsArgs&&!(e==="project"&&i!=="item-list"))return y("unclassifiable");switch(e){case"pr":if(i==="view")return ft(s,"pr view",Qt,t,!0);if(i==="list"||i==="ls")return ee(s,"pr list",Qt,t);if(i==="status")return ee(s,"pr status",Qt,t);if(i==="checks")return Wo(s,t);if(i==="diff"){let a=ve(s,ue["pr diff"]);if(W(a,"-h","--help"))return x;if(t.debug)return y("debug-traffic");return W(a,"--patch")?y("composite-other"):x}return y("unclassifiable");case"issue":if(i==="view")return ft(s,"issue view",Jt,t,!0);if(i==="list"||i==="ls")return ee(s,"issue list",Jt,t);if(i==="status")return ee(s,"issue status",Jt,t);return y("unclassifiable");case"release":if(i==="view")return ft(s,"release view",vr,t,!1);if(i==="list"||i==="ls")return ee(s,"release list",vr,t);return y("unclassifiable");case"discussion":if(i==="view")return ft(s,"discussion view",_r,t,!0);if(i==="list"||i==="ls")return ee(s,"discussion list",_r,t);return y("unclassifiable");case"search":if(i==="prs"||i==="issues")return ee(s,"search",Eo,t);if(i==="commits")return ee(s,"search",Oo,t);if(i==="code"||i==="repos")return t.debug?y("debug-traffic"):x;return y("unclassifiable");case"project":{if(t.debug)return y("debug-traffic");if(i!=="item-list")return x;let a=ve(s,ue["project item-list"]);if(W(a,"-h","--help"))return x;let l=te(a,"--format");if(l.some((u)=>!u.value||u.value.opaque))return y("unclassifiable");if(l.every((u)=>u.value.value!=="json"))return x;return an(a)?x:y("composite-other")}}return y("unclassifiable")}var Ar=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function Lo(e){let r=e.value.trim(),t=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(r);if(t){let i=t[1].toLowerCase(),o=t[2]??"/";if(i==="api.github.com"||/^api\./.test(i))r=o;else if(/^\/api\/v3(?:\/|$)/i.test(o))r=o.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(o))r="graphql";else return null}r=r.replace(/[?#].*$/,"");let n=[],s=[];for(let i of r.split("/")){let o;try{o=decodeURIComponent(i)}catch{return null}for(let a of o.split("/")){if(a===""||a===".")continue;if(a===".."){n.pop(),s.pop();continue}n.push(a.toLowerCase()),s.push(e.opaque&&/[$`]/.test(a)||/[*?[]/.test(a)||Rr(a))}}return{segments:n,opaque:s}}function Ho(e){let r=Lo(e);if(!r)return{kind:"unclassifiable",segments:[]};let{segments:t,opaque:n}=r,s=(l)=>({kind:l,segments:t});if(t.length===1&&t[0]==="graphql")return s("graphql");if(t.length===0)return s(e.opaque?"unclassifiable":"other");if(n[0])return s("unclassifiable");let i,o=[];if(t[0]==="repos")i=t.slice(3),o=n.slice(3);else if(t[0]==="repositories")i=t.slice(2),o=n.slice(2);if(i){if((t[0]==="repos"?n.slice(1,3):n.slice(1,2)).some(Boolean)){let u=n.findIndex(Boolean),c=t.findIndex((f,d)=>d>u&&!n[d]&&Mo.has(f));return s(c<0?"unclassifiable":Er(t.slice(c),n.slice(c)))}return s(Er(i,o))}let a=t[0];if(a==="issues")return s("sensitive");if(a==="user"&&t[1]==="issues")return s("sensitive");if(a==="orgs"&&t[2]==="issues")return s("sensitive");if(a==="search")return s(t[1]==="issues"||t[1]==="commits"?"sensitive":t[1]!==void 0&&n[1]?"unclassifiable":"other");if(a==="events"||a==="networks")return s("sensitive");if((a==="users"||a==="orgs")&&t.slice(2).some((l)=>l==="events"||l==="received_events"||l==="discussions"))return s("sensitive");if((a==="users"||a==="orgs")&&t[2]==="projectsv2"&&t[4]==="items")return s("sensitive");if(a==="orgs"&&t[2]==="hooks"&&t[4]==="deliveries"&&t[5]!==void 0||a==="app"&&t[1]==="hook"&&t[2]==="deliveries"&&t[3]!==void 0)return s("sensitive");if(a==="teams"&&t.includes("discussions"))return s("sensitive");if(a==="projects"&&t.includes("cards"))return s("sensitive");if(n.some(Boolean))return s(t.some((l)=>l==="events"||l==="discussions"||l==="issues")?"sensitive":"unclassifiable");return s("other")}var Mo=new Set([...Ar,"branches","git","actions","hooks","zipball","tarball"]);function Er(e,r){let[t,n]=e;if(t===void 0)return"other";if(r[0])return"unclassifiable";if(t==="issues"&&/^\d+$/.test(n??"")&&e[2]==="labels")return"other";if(Ar.has(t))return"sensitive";if(t==="branches"){if(e.length===1||e.slice(1).some((s)=>s==="protection")||e[e.length-1]==="rename")return"other";return r.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if(t==="git")return n===void 0||n==="commits"||n==="tags"?"sensitive":r[1]?"unclassifiable":"other";if(t==="actions"){if(n===void 0)return"sensitive";if(r[1])return"unclassifiable";if(n==="runs"||n==="jobs"){if(e[e.length-1]==="logs"&&e.length>=4&&!r.some(Boolean))return"download";return"sensitive"}if(n==="workflows"&&e[3]==="runs")return"sensitive";if(n==="artifacts"&&e.length===4)return"download";return"other"}if(t==="hooks"&&e[2]==="deliveries"&&e[3]!==void 0)return"sensitive";if(t==="zipball"||t==="tarball")return"download";return"other"}function Fo(e,r){if(r[0]!=="repos"||r.length<5)return!1;let t=r.slice(3),n=(i)=>/^\d+$/.test(t[i]??""),s=(...i)=>t.length===i.length&&i.every((o,a)=>typeof o==="number"?n(a):t[a]===o);if(e==="DELETE")return s("issues","comments",0)||s("pulls","comments",0)||s("comments",0)||s("issues","comments",0,"reactions",0)||s("pulls","comments",0,"reactions",0)||s("issues",0,"reactions",0)||s("issues",0,"labels")||t.length===4&&t[0]==="issues"&&n(1)&&t[2]==="labels"||s("releases",0)||s("releases","assets",0)||s("actions","runs",0)||s("actions","runs",0,"logs")||s("deployments",0)||s("milestones",0)||s("issues",0,"lock");if(e==="POST")return t.length===4&&t[0]==="actions"&&t[1]==="runs"&&n(2)&&["rerun","rerun-failed-jobs","cancel","force-cancel","approve"].includes(t[3])||s("actions","jobs",0,"rerun")||s("issues",0,"labels");if(e==="PUT")return s("pulls",0,"merge")||s("pulls",0,"update-branch")||s("issues",0,"labels")||s("issues",0,"lock");if(e==="GET")return s("pulls",0,"merge");return!1}function Bo(e){if(e[0]!=="repos"||e.length!==5||!/^\d+$/.test(e[4]))return;if(e[3]==="pulls")return new Set(["commits","comments","review_comments"]);if(e[3]==="issues")return new Set(["comments"]);return}var jo=new Set(["body","bodyText","bodyHTML","bodyUrl","bodyResourcePath","comments","reviews","latestReviews","latestOpinionatedReviews","reviewThreads","url","permalink","summary","text","description","message","messageBody","messageHeadline","commitBody","commitHeadline","annotations","rawDetails","note","diff","readme","payload"]),Go=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function qo(e){let r=[],t=0;while(t<e.length){let n=e[t];if(/[\s,\uFEFF]/.test(n)){t++;continue}if(n==="#"){let o=e.indexOf(`
|
|
33
|
+
`,t);t=o<0?e.length:o+1;continue}if(e.startsWith('"""',t)){let o=t+3;for(;;){let a=e.indexOf('"""',o);if(a<0)return null;if(e[a-1]==="\\"){o=a+3;continue}t=a+3;break}continue}if(n==='"'){let o=t+1;while(o<e.length&&e[o]!=='"'&&e[o]!==`
|
|
34
|
+
`)o+=e[o]==="\\"?2:1;if(e[o]!=='"')return null;t=o+1;continue}let s=/^[_A-Za-z][_0-9A-Za-z]*/.exec(e.slice(t,t+256));if(s){r.push({kind:"name",text:s[0]}),t+=s[0].length;continue}let i=/^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(e.slice(t,t+64));if(i){t+=i[0].length;continue}if(e.startsWith("...",t)){r.push({kind:"punct",text:"..."}),t+=3;continue}if("{}()[]:!$@=|&".includes(n)){r.push({kind:"punct",text:n}),t++;continue}return null}return r}function zo(e){let r=qo(e);if(!r)return!0;let t=[],n="",s=0;for(let i=0;i<r.length;i++){let o=r[i];if(o.kind==="punct"){if(o.text==="(")s++;else if(o.text===")"){if(s--,s<0)return!0}else if(s===0&&o.text==="{")t.push(n),n="";else if(s===0&&o.text==="}"){if(t.pop()===void 0)return!0;n=""}continue}if(s>0)continue;let a=r[i-1];if(a?.kind==="punct"&&(a.text==="@"||a.text==="$"))continue;if(r[i+1]?.kind==="punct"&&r[i+1].text===":")continue;if(o.text==="on"&&a?.kind==="punct"&&a.text==="...")continue;if(a?.kind==="name"&&a.text==="on"){n=o.text;continue}if(t.length===0){n=o.text;continue}if(jo.has(o.text)||/(?:Url|URL|HTML|Html)$/.test(o.text))return!0;if(o.text==="title"&&t.some((l)=>Go.has(l)))return!0;n=o.text}return s!==0||t.length!==0}function Uo(e,r){let t=ve(e,ue.api);if(W(t,"-h","--help"))return x;let n=t.positionals[0];if(!n)return r.appendsArgs?y("unclassifiable"):x;let s=Ho(n),i=te(t,"-X","--method"),o=i[i.length-1],a=te(t,"-f","--raw-field","-F","--field","--input"),l=o?o.value&&!o.value.opaque?o.value.value.toUpperCase():"?":a.length>0?"POST":"GET",u=Fo(l,s.segments),c=x;if(s.kind==="unclassifiable")c=y("unclassifiable");else if(s.kind==="sensitive"&&!u)c=y("api-rest");else if(s.kind==="graphql")c=Vo(t);if(r.debug||W(t,"--verbose")){if(s.kind==="download"&&!c.refused)c=y("api-rest");if(c.refused)return r.debug?y("debug-traffic"):c;return x}if(r.appendsArgs&&s.kind!=="other"&&s.kind!=="download")return y("unclassifiable");if(!c.refused||W(t,"--silent"))return x;if(an(t,Bo(s.segments)))return x;return c}function Vo(e){if(te(e,"--input").length>0)return y("unclassifiable");let r=te(e,"-f","--raw-field","-F","--field"),t=r.filter((n)=>n.value&&/^query=/.test(n.value.value));if(t.length===0||r.some((n)=>!n.value))return y("unclassifiable");for(let n of t){let s=n.value.value.slice(6);if((n.name==="-F"||n.name==="--field")&&s.startsWith("@")||n.value.opaque)return y("unclassifiable");if(zo(s))return y("api-graphql")}return x}function ht(e,r){let t=0;while(t<e.length&&e[t].value.startsWith("-")&&!e[t].opaque){if(["--help","-h","--version"].includes(e[t].value))return x;t++}if(t>=e.length)return r.appendsArgs?y("unclassifiable"):x;let n=e[t],s=e.slice(t+1);if(n.opaque)return y("unclassifiable");switch(n.value){case"pr":case"issue":case"release":case"discussion":case"search":case"project":return Do(n.value,s,r);case"api":return Uo(s,r);case"status":return s.length>0&&s.every((i)=>i.value==="-h"||i.value==="--help")?x:y("composite-other");case"help":case"version":return x;case"cs":case"codespace":{let i=s.findIndex((o)=>o.value==="--");if(s.some((o)=>o.value==="ssh")&&i>=0&&i+1<s.length){let o=V(s.slice(i+1).map((a)=>a.value).join(" "),r.depth+1,r.debug);if(o.refused)return o}break}}if(!Ao.has(n.value))return y("unclassifiable");if(r.debug)return y("debug-traffic");return x}var gt=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","fish"]),Zo=new Set(["su","runuser","script","flock"]),Ko=new Set(["secrets","op","unbuffer","caffeinate","chronic","strace","ltrace","firejail","bwrap","nsenter","unshare","chroot","sg","retry","parallel","doppler","aws-vault","dotenv","direnv","faketime","taskset","numactl","cgexec","systemd-run","docker","podman","kubectl","mise","asdf","rtx","devbox","gosu","su-exec","setpriv","pkexec","with-contenv","uv","poetry","pipenv","npx","bunx","pnpm","yarn","nix","nix-shell","infisical","chamber","envchain","dotenvx","teller","vault","chrt","coproc","prlimit","ionice","cpulimit","trickle","proxychains","proxychains4","torsocks","tsocks","catchsegv","valgrind"]),Xo=new Map([["bun",["x","exec"]],["npm",["exec","x"]],["deno",["run"]]]),Yo=new Set(["-I","-L","-l","-n","-P","-s","-d","-E","-e","-a","--arg-file","--delimiter","--max-args","--max-lines","--max-procs","--max-chars","--replace","--eof","--process-slot-var"]),Qo=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),dt=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/,Jo=/^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/,el=6;function Or(e,r){let t,n;for(let s of e){let i=Jo.exec(s.value);if(!i)continue;let o={...s,value:i[2]};if(i[1]==="GH_DEBUG")t=o;else if(i[1]==="DEBUG")n=o}if(t)return t.opaque||!["","0","false","no"].includes(t.value);if(n&&(n.opaque||["1","true","yes","api"].includes(n.value)))return!0;return r}function cn(e){let r=P(e),t=0;return{segments:r.segments.map((s)=>{let i=s.words[0],o=e.slice(t,i.start);return t=s.words[s.words.length-1].end,{words:s.words,redirects:s.redirects,sepBefore:o}}),trustworthy:r.trustworthy}}var Tr=(e)=>/(?:^|[^|])\|&?$/.test(e.trim());function rn(e,r){if(!gt.has(e))return!1;if(fn(r))return!1;for(let t=0;t<r.length;t++){let n=r[t].value;if(n==="--")return t+1>=r.length;if(n==="-"||n==="-s")return!0;if(/^[-+][A-Za-z]*[oO]$/.test(n)){t++;continue}if(!n.startsWith("-")&&!n.startsWith("+"))return!1}return!0}function sn(e){let{segments:r}=cn(e.trim());if(r.length!==1)return null;let t=r[0],n=L(t);if(n<0)return null;let s=ae(ke(t.words[n].text).value),i=t.words.slice(n+1).filter((o,a)=>!t.redirects.has(a+n+1)).map((o)=>ke(o.text));if(s==="echo")return i.filter((o,a)=>!(a===0&&/^-[neE]+$/.test(o.value))).map((o)=>o.value).join(" ");if(s==="printf"){let[o,...a]=i.filter((u)=>u.value!=="--");if(!o)return null;let l=0;return o.value.replace(/\\n/g,`
|
|
35
|
+
`).replace(/%s/g,()=>a[l++]?.value??"")+(l<a.length?" "+a.slice(l).map((u)=>u.value).join(" "):"")}if(s==="cat"){let o=e.indexOf("<<");if(o<0)return null;let a=we(e,o),l=e.indexOf(`
|
|
36
|
+
`,o);if(!a||l<0)return null;let u=st(e,l,[a]);if(u<0)return null;let c=e.slice(l+1,u);return c.slice(0,c.lastIndexOf(a.delimiter)).replace(/\n$/,"")}return null}function en(e,r,t){for(let n of nn(e).bodies){let s=sn(n);if(s===null)continue;let i=V(s,r+1,t.debug);if(i.refused)return i}return x}function V(e,r=0,t=!1){if(typeof e!=="string"||!e.trim())return x;if(r>el)return dt.test(e)?y("unclassifiable"):x;let{segments:n,trustworthy:s}=cn(e);if(!s)return dt.test(e)?y("unclassifiable"):x;let i=t,o=(a)=>V(a,r+1,i);for(let a of rl(e)){if(a.runsBody){let l=o(a.body);if(l.refused)return l}if(!a.quoted){let l=nn(a.body,"heredoc");if(!l.complete&&dt.test(a.body))return y("unclassifiable");for(let u of l.bodies){let c=o(u);if(c.refused)return c}}}for(let a=0;a<n.length;a++){let l=n[a];for(let b of l.words){let R=nn(b.text);if(!R.complete&&dt.test(b.text))return y("unclassifiable");for(let H of R.bodies){let M=o(H);if(M.refused)return M}}let u=L(l),c=l.words.map((b,R)=>({word:ke(b.text),redirect:l.redirects.has(R)})),f=c.slice(0,u<0?c.length:u).map((b)=>b.word),d=u>=0?ae(c[u].word.value):"";if(u<0||["export","declare","typeset","readonly","local"].includes(d)){if(i=Or([...f,...c.slice(u+1).map((b)=>b.word)],i),u<0)continue}let h=Or(f,i),p=c.slice(u+1).filter((b)=>!b.redirect).map((b)=>b.word),m=c.slice(u+1).filter((b)=>b.redirect).map((b)=>b.word),O=c[u].word,A=ae(O.value),I={depth:r,appendsArgs:!1,debug:h};if(u>0&&c[u-1].word.value==="function"){let b=p.filter((H)=>!["{","()","(",")"].includes(H.value)),R=on(b,I);if(R.refused)return R;continue}if(a>0&&Tr(l.sepBefore)&&rn(A,p)){let b=n[a-1],R=tl(e,b),H=R===null?null:sn(R);if(H!==null){let M=V(H,r+1,h);if(M.refused)return M}}let j=n[a+1];if(j&&/<\(\s*$/.test(j.sepBefore)&&(gt.has(A)||A==="source"||A===".")){let b=j.words[0].start-j.sepBefore.length+j.sepBefore.lastIndexOf("("),R=oe(e,b),H=R<0?null:sn(e.slice(b+1,R-1));if(H!==null){let M=V(H,r+1,h);if(M.refused)return M}}let k=$r(A,O,p,m,l.words.slice(0,u+1),I);if(k.refused)return k}return x}function tl(e,r){let t=r.words[0],n=r.words[r.words.length-1];return t&&n?e.slice(t.start,n.end):null}function nl(e){let r=ae(e.value);return/[$`]/.test(r)||r===""?void 0:r}function $r(e,r,t,n,s,i){let o=i.depth,a=(l)=>V(l,o+1,i.debug);if(r.opaque){let l=nl(r);if(l===void 0){let u=t.find((f)=>!f.value.startsWith("-")),c=ht(t,i);if(!c.refused)return x;return c.rule!=="unclassifiable"||u!==void 0&&!u.opaque&&To.has(u.value)?c:x}e=l}if(e==="gh")return ht(t,i);if(gt.has(e)){let l=fn(t);if(l){let u=a(l.value);if(u.refused||!l.opaque)return u;return en(l.raw,o,i)}for(let u of n){let c=a(u.value);if(c.refused)return c;if(u.opaque){let f=en(u.raw,o,i);if(f.refused)return f}}return x}if(Zo.has(e)){let l=t.findIndex((c)=>c.value==="-c"||c.value==="--command"||/^-[A-Za-z]*c$/.test(c.value)),u=l>=0?t[l+1]:void 0;return u?a(u.value):tn(t,i)}if(e==="eval"||e==="watch"){let l=t;if(e==="watch"){let c=0;while(c<t.length&&t[c].value.startsWith("-")){if(t[c].value==="--"){c++;break}if(["-n","--interval","-q","--equexit"].includes(t[c].value))c++;c++}l=t.slice(c)}let u=a(l.map((c)=>c.value).join(" "));if(u.refused)return u;for(let c of l){let f=en(c.raw,o,i);if(f.refused)return f}return x}if(e==="env")return a(Be([...s.map((l)=>ke(l.text).value),...t.map((l)=>l.value)]));if(e==="ssh"){let l=0;for(;l<t.length;l++){let f=t[l].value;if(!f.startsWith("-"))break;if(Qo.has(f))l++}let u=t.slice(l+1);if(u[0]?.value==="--")u.shift();let c=u.map((f)=>f.value).join(" ");return c?a(c):x}if(e==="xargs"){let l=0,u=!1;for(;l<t.length;l++){let c=t[l].value;if(c==="--"){l++;break}if(!c.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(c))u=!0;if(Yo.has(c))l++}return on(t.slice(l),{depth:o,appendsArgs:!u,debug:i.debug})}if(e==="find"){for(let l=0;l<t.length;l++){if(!["-exec","-execdir","-ok","-okdir"].includes(t[l].value))continue;let u=l+1;while(u<t.length&&t[u].value!==";"&&t[u].value!=="+")u++;let c=on(t.slice(l+1,u),i);if(c.refused)return c;l=u}return x}if(Ko.has(e))return tn(t,i);if(Xo.get(e)?.includes(t[0]?.value??""))return tn(t.slice(1),i);return x}function on(e,r){if(e.length===0)return x;let t=ae(e[0].value);if(t==="gh")return ht(e.slice(1),r);if(gt.has(t)){let n=fn(e.slice(1));return n?V(n.value,r.depth+1,r.debug):x}return $r(t,e[0],e.slice(1),[],[],r)}function tn(e,r){let t=e.findIndex((n)=>!n.opaque&&ae(n.value)==="gh"&&(n.value==="gh"||n.value.includes("/")));return t>=0?ht(e.slice(t+1),r):x}function fn(e){for(let r=0;r<e.length;r++){let t=e[r].value;if(t==="--")return;if(!t.startsWith("-")&&!t.startsWith("+"))return;if(t==="-c"||/^-[A-Za-z]+$/.test(t)&&t.includes("c"))return e.slice(r+1).find((n)=>!n.value.startsWith("-")||n.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test(t))r++}return}function rl(e){let r=[],t=0;for(;;){let n=e.indexOf("<<",t);if(n<0)break;if(t=n+2,e[n+2]==="<"||n>0&&e[n-1]==="<"){t=n+3;continue}let s=we(e,n);if(!s)continue;let i=e.lastIndexOf(`
|
|
37
|
+
`,n)+1,o=e.indexOf(`
|
|
38
|
+
`,n);if(o<0)continue;let a=st(e,o,[s]),l=a<0?e.slice(o+1):e.slice(o+1,a),u=a<0?l:l.slice(0,Math.max(0,l.lastIndexOf(s.delimiter))).replace(/\n$/,""),c=e.slice(i,n)+" HEREDOC_OPERATOR "+e.slice(s.end,o);r.push({body:u,runsBody:sl(c),quoted:s.quoted})}return r}function sl(e){let{segments:r}=cn(e),t=r.findIndex((a)=>a.words.some((l)=>l.text==="HEREDOC_OPERATOR"));if(t<0)return!1;let n=(a)=>{let l=L(a);if(l<0)return{verb:"",args:[]};let u=a.words.slice(l+1).filter((c)=>c.text!=="HEREDOC_OPERATOR").map((c)=>ke(c.text));return{verb:ae(ke(a.words[l].text).value),args:u}},{verb:s,args:i}=n(r[t]);if(s==="ssh"||rn(s,i))return!0;if((s==="source"||s===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(i[0]?.value??""))return!0;let o=r[t+1];if(s==="cat"&&o&&Tr(o.sepBefore)){let a=n(o);return a.verb==="ssh"||rn(a.verb,a.args)}return!1}var il=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function Cr(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:ln}}}var ol=new Set(["Bash","Monitor"]);function Pr(e){if(e?.hook_event_name!=="PreToolUse"||!ol.has(e.tool_name??""))return{continue:!0};let r=he(e);if(!r.trim())return{continue:!0};try{return V(r).refused?Cr():{continue:!0}}catch{return il.test(r)?Cr():{continue:!0}}}function hn(e){if(e!=="trash-guard"&&e!=="workspace-repos-guard")throw Error("Invalid safety capability")}function Wr(e,r){hn(e);let t=e,n=JSON.parse(r);if(!n||Array.isArray(n)||n.hook_event_name!=="PreToolUse"||typeof n.tool_name!=="string"||!n.tool_input||typeof n.tool_input!=="object"||Array.isArray(n.tool_input)||typeof n.cwd!=="string"||!Ir(n.cwd))throw Error("Invalid safety input");if(n.tool_name==="Bash"&&typeof n.tool_input.command!=="string")throw Error("Invalid shell input");if(n.tool_name==="Monitor"&&n.tool_input.command!==void 0&&typeof n.tool_input.command!=="string")throw Error("Invalid monitor input");let s=n.hasna_execution;if(s!==void 0&&(!s||Object.keys(s).sort().join()!=="agent,schema"||s.schema!=="hasna.hooks.execution.v1"||typeof s.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(s.agent)))throw Error("Invalid execution capability");let i=s===void 0?void 0:{runtime:process.execPath,home:dn(),path:process.env.PATH,agent:s.agent};if(i&&(!Ir(i.runtime)||!i.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(n.tool_name)){if(n.tool_input.command!==void 0&&n.tool_input.patch!==void 0&&n.tool_input.command!==n.tool_input.patch)throw Error("Conflicting patch aliases");let A=n.tool_input.command??n.tool_input.patch;if(typeof A!=="string")throw Error("Invalid patch input");n.tool_input={...n.tool_input,command:A,patch:A}}let o=n.tool_name==="Monitor",a=n.tool_name==="Bash"||o&&typeof n.tool_input.command==="string",l=o&&a?{...n,tool_name:"Bash"}:n,u=(A)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:A}}),c=gr(l).output,f=Pr(l),d=l.tool_input.command,h=()=>Se(d,{home:dn(),cwd:n.cwd}).handoffHits.length>0,p=a&&(h()||!!ie(d,h)),m=t==="trash-guard"&&(!o||a)?zn(l,{home:dn(),cwd:n.cwd,findTrash:Qe,inspectTrash:Pe,execution:i}):{continue:!0};if(o&&m.hookSpecificOutput?.permissionDecision==="allow")m=u("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let O=c.decision==="block"?u(c.reason):f.hookSpecificOutput?f:p?u("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):m;return JSON.stringify({verdict:"continue"in O?null:O})}var Nr=process.argv[1];hn(Nr);process.stdout.write(Wr(Nr,await Bun.stdin.text()));
|