@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,37 +1,37 @@
|
|
|
1
|
-
var{defineProperty:
|
|
2
|
-
`)[0]}finally{P.closeSync($)}let Y=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(J);if(Y&&Y[1]!=="/usr/bin/env")return iZ(Y[1],!0);if(J!=="#!/usr/bin/env bun"||!iZ("/usr/bin/env",!0))return!1;for(let X of z.split(":").slice(0,64)){if(!b3(X))return!1;let Q=v.resolve(X,"bun");try{if(!P.statSync(Q).isFile())continue;P.accessSync(Q,P.constants.X_OK)}catch{continue}return iZ(Q,!0)}return!1}function yZ(Z){let z=Z;for(;;){let $=P.lstatSync(z);if(!$.isDirectory()||!AZ($.uid)||($.mode&18)!==0)return!1;let J=v.dirname(z);if(J===z)return!0;z=J}}function RZ(Z=process.env){let z=Z.PATH??"",$=Date.now()+2000,J="missing",Y=(X)=>{if(J==="missing"||J==="unrecognized_package"||X.startsWith("unsafe_"))J=X};for(let X of z.split(":").slice(0,64)){if(!v.isAbsolute(X)||Date.now()>=$)continue;let Q=v.resolve(X,"trash");try{let H=P.statSync(Q);if(!H.isFile()||!AZ(H.uid)||(H.mode&73)===0||(H.mode&18)!==0){Y("unsafe_executable");continue}let K=P.realpathSync(Q);if(!yZ(v.resolve(X))||!yZ(v.dirname(K))){Y("unsafe_directory");continue}if(!iZ(Q)){Y("unsafe_directory");continue}let B=v.resolve(v.dirname(K),"../.."),M=v.join(B,"package.json"),V=P.statSync(M);if(!V.isFile()||!AZ(V.uid)||V.size>16384||(V.mode&18)!==0||P.lstatSync(M).isSymbolicLink()){Y("unsafe_manifest");continue}let G=JSON.parse(P.readFileSync(M,"utf8"));if(G.name!=="@hasna/trash"||typeof G.version!=="string"||typeof G.bin?.trash!=="string"||P.realpathSync(v.resolve(B,G.bin.trash))!==K){Y("unrecognized_package");continue}try{if(!E3(K,z)){Y("unsafe_interpreter");continue}}catch{Y("unsafe_interpreter");continue}let U=$-Date.now();if(U<=0){Y("identity_failed");break}let j=B2.spawnSync(Q,["--identity"],{encoding:"utf8",timeout:U,maxBuffer:2048,env:{PATH:z},stdio:["ignore","pipe","pipe"]});if(j.error||j.status!==0||Date.now()>=$){Y("identity_failed");continue}let N=JSON.parse(j.stdout);if(N.name==="@hasna/trash"&&N.version===G.version&&N.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:Q,version:G.version};Y("unsupported_protocol")}catch{}}return{ok:!1,code:J}}function dZ(Z=process.env){let z=RZ(Z);return z.ok?z.path:null}function WZ(Z){let z=Z.tool_input?.command;return typeof z==="string"?z:""}var V2=["/","/bin","/boot","/dev","/etc","/home","/lib","/lib32","/lib64","/libx32","/opt","/proc","/root","/run","/sbin","/srv","/sys","/usr","/var","/Applications","/Library","/System","/Users","/Volumes","/private"];var bZ=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,o=(Z)=>Z.split("/").pop()??"";function sZ(Z){let z=Z.startsWith("~")?Z.slice(1).split("/",1)[0]:"";if(z&&!/['"\\]/.test(z))return!0;let $=null,J=0;for(let Y=0;Y<Z.length;Y++){let X=Z[Y];if($==="'"){if(X==="'")$=null;continue}if(X==="\\"){Y++;continue}if($==='"'){if(X==='"')$=null;continue}if(X==="'"||X==='"')$=X;else if(X==="$"&&Z[Y+1]==="{")J++,Y++;else if(X==="}"&&J>0)J--;else if(X==="{"||X==="}")return!0}return!1}var N0=64;function G2(Z,z){let $=0;for(let J=z;J<Z.length;J++)if(Z[J]==="\\")J++;else if(Z[J]==="{")$++;else if(Z[J]==="}"&&--$===0)return J;return Z.length-1}function S3(Z){let z=Z.match(/^([-+]?\d+)\.\.([-+]?\d+)(?:\.\.([-+]?\d+))?$/),$=z?null:Z.match(/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([-+]?\d+))?$/),J=z??$;if(!J)return null;let Y=z?Number(J[1]):J[1].charCodeAt(0),X=z?Number(J[2]):J[2].charCodeAt(0),Q=Math.abs(Number(J[3]??1))||1;if(!Number.isSafeInteger(Y)||!Number.isSafeInteger(X)||!Number.isSafeInteger(Q))return"overflow";if(Math.floor(Math.abs(X-Y)/Q)+1>N0)return"overflow";let H=z&&(/^[-+]?0\d/.test(J[1])||/^[-+]?0\d/.test(J[2]))?Math.max(J[1].length,J[2].length):0,K=[];for(let B=Y;Y<=X?B<=X:B>=X;B+=Y<=X?Q:-Q)if(!z)K.push(String.fromCharCode(B));else K.push(B<0?`-${String(-B).padStart(H-1,"0")}`:String(B).padStart(H,"0"));return K}function f3(Z){let z=null,$=0;for(let J=0;J<Z.length;J++){let Y=Z[J];if(z==="'"){if(Y==="'")z=null;continue}if(Y==="\\"){J++;continue}if(z==='"'){if(Y==='"')z=null;continue}if(Y==="'"||Y==='"')z=Y;else if(Y==="$"&&Z[J+1]==="{")J=G2(Z,J+1);else if(Y==="{"){if(++$>N0)return"overflow";let X=null,Q=0,H=!0,K=[];for(let B=J;B<Z.length;B++){let M=Z[B];if(X==="'"){if(M==="'")X=null;continue}if(M==="\\"){H=!1,B++;continue}if(X==='"'){if(M==='"')X=null;continue}if(M==="'"||M==='"')X=M,H=!1;else if(M==="$"&&Z[B+1]==="{")B=G2(Z,B+1),H=!1;else if(M==="{")Q++;else if(M===","&&Q===1)K.push(B);else if(M==="}"&&--Q===0){if(K.length>0){let G=[J,...K,B];return{open:J,close:B,parts:G.slice(0,-1).map((U,j)=>Z.slice(U+1,G[j+1]))}}let V=H?S3(Z.slice(J+1,B)):null;if(V==="overflow")return V;if(V)return{open:J,close:B,parts:V};break}}}}return null}function QZ(Z){if(Z.length>4096&&Z.includes("{"))return null;let z=f3(Z);if(z===null)return[Z];if(z==="overflow")return null;let $=[];for(let J of z.parts){let Y=QZ(Z.slice(0,z.open)+J+Z.slice(z.close+1));if(Y===null||$.push(...Y)>N0)return null}return $}var W={arg:"none"},D={arg:"value"},vZ={arg:"optional"},t={arg:"none",effect:"lookup"},C={arg:"none",effect:"refuse"},ZZ={help:C,version:C},k3=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,F0={timeout:{short:{k:D,s:D,v:W},long:{"kill-after":D,signal:D,verbose:W,foreground:W,"preserve-status":W,...ZZ},positionals:[k3]},env:{short:{i:W,"0":W,v:W,u:D,a:D,C,S:C},long:{"ignore-environment":W,null:W,debug:W,unset:D,argv0:D,chdir:C,"split-string":C,"block-signal":vZ,"default-signal":vZ,"ignore-signal":vZ,"list-signal-handling":C,...ZZ},env:!0},nice:{short:{n:D},long:{adjustment:D,...ZZ},numericOption:!0},nohup:{short:{},long:{...ZZ}},command:{short:{p:W,v:t,V:t},long:{}},exec:{short:{c:W,l:W,a:D},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:D,o:D,e:D},long:{input:D,output:D,error:D,...ZZ}},time:{short:{p:W,a:W,q:W,v:W,f:D,o:C,V:C},long:{portability:W,append:W,quiet:W,verbose:W,format:D,output:C,...ZZ}},ionice:{short:{c:D,n:D,t:W,p:C,P:C,u:C,h:C,V:C},long:{class:D,classdata:D,ignore:W,pid:C,pgid:C,uid:C,...ZZ}},setsid:{short:{c:W,f:W,w:W,h:C,V:C},long:{ctty:W,fork:W,wait:W,...ZZ}}},x3=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function h3(Z,z,$){let J=!1,Y=(X)=>{if(!X||X.effect==="refuse")return!1;if(X.effect==="lookup")J=!0;return!0};while($<z.length){let X=z[$];if(X.opaque)return null;let Q=X.text;if(Q==="--"){$++;break}if(Q==="-"&&Z.env){$++;continue}if(!Q.startsWith("-")||Q==="-")break;if(Z.numericOption&&/^-[-+]?\d+$/.test(Q)){$++;continue}if(Q.startsWith("--")){let H=Q.indexOf("="),K=H<0?Q.slice(2):Q.slice(2,H),B=Object.keys(Z.long),M=B.includes(K)?[K]:B.filter((G)=>K&&G.startsWith(K));if(M.length!==1)return null;let V=Z.long[M[0]];if(!Y(V))return null;if(V.arg==="none"&&H>=0)return null;if(V.arg==="value"&&H<0){let G=z[++$];if(!G||G.opaque)return null}$++;continue}for(let H=1;H<Q.length;H++){let K=Z.short[Q[H]];if(!Y(K))return null;if(K.arg==="value"){if(H===Q.length-1){let B=z[++$];if(!B||B.opaque)return null}break}}$++}if(J)return-1;for(let X of Z.positionals??[]){let Q=z[$];if(!Q||Q.opaque||!X.test(Q.text))return null;$++}if(Z.env||Z.assignments){for(;$<z.length&&bZ.test(z[$].text);$++)if(z[$].opaque)return null}return $}function KZ(Z,z=F0){let $=0;while($<Z.length&&(bZ.test(Z[$].text)||x3.has(Z[$].text)))$++;for(let J=0;J<16;J++){if($>=Z.length)return{index:-1};if(Z[$].opaque)return J===0?{index:$}:null;let Y=Object.hasOwn(z,o(Z[$].text))?z[o(Z[$].text)]:void 0;if(!Y)return{index:$};let X=h3(Y,Z,$+1);if(X===null)return null;if(X<0)return{index:-1};$=X}return null}function w3(Z){return/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred|trash)(?![A-Za-z0-9_.-])/.test(Z)}var $Z={on:!1};function HZ(Z,z){if(!Z.includes("\\")||!Z.includes('"'))return;let $=$Z.on;$Z.on=!0;try{return z()}finally{$Z.on=$}}var I0=(Z)=>Z.split("/").pop()??"",D0={perl:{letters:new Set(["e","E"]),long:new Set},python:{letters:new Set(["c"]),long:new Set},python2:{letters:new Set(["c"]),long:new Set},python3:{letters:new Set(["c"]),long:new Set},ruby:{letters:new Set(["e"]),long:new Set},node:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},nodejs:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},bun:{letters:new Set(["e"]),long:new Set(["--eval"])},deno:{letters:new Set(["e"]),long:new Set(["--eval"])},php:{letters:new Set(["r"]),long:new Set},lua:{letters:new Set(["e"]),long:new Set},luajit:{letters:new Set(["e"]),long:new Set},Rscript:{letters:new Set(["e"]),long:new Set}},N2=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,g3=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),u3=new Set(["ssh","scp","sftp"]),l3=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),U2=new Set(["proxycommand","localcommand","knownhostscommand"]),m3=/(?:`|\$\()|\b(?:system|exec|execve|execvp|popen|spawn|posix_spawn|fork|subprocess|Popen|check_output|check_call|shell_exec|passthru|proc_open|pcntl_exec|qx|open|fopen|sysopen|unlink|remove|delete|rmtree|rmdir|mkdir|rename|truncate|ftruncate|chmod|chown|symlink|writeFile|createWriteStream|appendFile|child_process|FileUtils|shutil|Kernel|require|import|load|eval|os|sys|io|fs|File|IO|Dir|Path|pathlib|Deno|Bun)|%x\W/,p3=/[|>]|\b(?:system|getline|close|fflush|print\w*\s*>>?)/;function F2(Z){if(w3(Z.text))return!1;if(Z.kind==="awk")return!p3.test(Z.text);if(Z.kind==="c-interp")return!m3.test(Z.text);return!1}function c3(Z,z,$,J){let Y=D0[Z]??(N2.test(Z)?D0[Z.replace(/[0-9.]+$/,"")]:void 0);if(!Y)return null;let X=[],Q=!1,H=(K)=>{if(K+1>=z.length||J(K+1))return Q=!0,K;return X.push({text:z[K+1],kind:"c-interp"}),K+1};for(let K=$+1;K<z.length;K++){let B=z[K];if(B==="--")break;if(!B.startsWith("-")||B==="-")break;if(B.startsWith("--")){let V=B.indexOf("="),G=V<0?B:B.slice(0,V);if(Y.long.has(G))if(V>=0)X.push({text:B.slice(V+1),kind:"c-interp"});else K=H(K);continue}let M=B.slice(1);for(let V=0;V<M.length;V++){if(!Y.letters.has(M[V]))continue;if(V<M.length-1)X.push({text:M.slice(V+1),kind:"c-interp"});else K=H(K);break}}if(X.length===0&&!Q)return null;return{programs:X,unresolved:Q}}function i3(Z,z,$){let J=z+1;for(;J<Z.length&&Z[J].startsWith("-");J++)if(Z[J]==="-L"||Z[J]==="--log-level")J++;if(Z[J]!=="eval"||$(J))return null;let Y=[],X=!1;for(J++;J<Z.length;J++){if($(J)){X=!0;continue}if(!Z[J].startsWith("-"))Y.push({text:Z[J],kind:"c-interp"})}return Y.length===0&&!X?null:{programs:Y,unresolved:X}}function d3(Z,z,$){let J=[],Y=!1,X=z+1;for(;X<Z.length;X++){let Q=Z[X];if(Q==="--"){X++;break}if(!Q.startsWith("-")||Q==="-")break;if(Q==="-e"||Q.startsWith("-e")){let H=Q==="-e"?null:Q.slice(2);if(H!==null)J.push({text:H,kind:"awk"});else if(X+1<Z.length&&!$(X+1))J.push({text:Z[++X],kind:"awk"});else Y=!0}else if(Q==="-f"||Q.startsWith("-f")){if(Y=!0,Q==="-f")X++}else if(Q==="-v"||Q.startsWith("-v")){if(Q==="-v")X++}}if(J.length===0&&!Y){if(X<Z.length)if($(X))Y=!0;else J.push({text:Z[X],kind:"awk"})}return{programs:J,unresolved:Y}}function s3(Z,z,$){let J=Z[z],Y,X=z;if(J==="-o"){if(z+1>=Z.length)return{value:null,next:z};if($(z+1))return{value:null,next:z+1};Y=Z[z+1],X=z+1}else Y=J.slice(2);return{value:Y,next:X}}function n3(Z,z,$){let J=[],Y=!1;for(let X=z+1;X<Z.length;X++){let Q=Z[X];if(Q==="--")break;if(!Q.startsWith("-")||Q==="-")break;if(Q.startsWith("--"))continue;if(Q==="-o"||Q.startsWith("-o")){let{value:K,next:B}=s3(Z,X,$);if(X=B,K===null){Y=!0;continue}let M=K.indexOf("="),V=M>=0?M:K.search(/\s/),G=(V>=0?K.slice(0,V):K).trim().toLowerCase(),U=V>=0?K.slice(V+1).trim():"";if(U2.has(G))J.push({text:U,kind:"shell"});continue}if(Q==="-F"||Q.startsWith("-F")){if(Y=!0,Q==="-F")X++;continue}if(Q==="-S"||Q.startsWith("-S")){let K=Q==="-S"?X+1<Z.length&&!$(X+1)?Z[++X]:null:Q.slice(2);if(K===null)Y=!0;else J.push({text:K,kind:"shell"});continue}let H=Q.slice(1);for(let K=0;K<H.length;K++){if(!l3.has(H[K]))continue;if(K<H.length-1)break;if(H[K]==="o"||H[K]==="F"||H[K]==="S"){if(X+1<Z.length){let B=Z[X+1];if(H[K]==="o")if(!$(X+1)){let M=B.indexOf("="),V=M>=0?M:B.search(/\s/),G=(V>=0?B.slice(0,V):B).trim().toLowerCase();if(U2.has(G))J.push({text:V>=0?B.slice(V+1).trim():"",kind:"shell"})}else Y=!0;else if(H[K]==="F")Y=!0;else if(!$(X+1))J.push({text:B,kind:"shell"});X++}}else if(X+1<Z.length)X++}}return{programs:J,unresolved:Y}}function o3(Z,z,$){let J=[],Y=!1,X=!1;for(let Q=z+1;Q<Z.length;Q++){let H=Z[Q];if(H==="--")break;if(H==="-e"||H==="--rsh")if(X=!0,Q+1<Z.length&&!$(Q+1))J.push({text:Z[++Q],kind:"shell"});else Y=!0;else if(H.startsWith("--rsh="))X=!0,J.push({text:H.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(H)&&H.length>2&&!H.startsWith("--"))X=!0,J.push({text:H.slice(H.indexOf("e")+1),kind:"shell"})}return X?{programs:J,unresolved:Y}:null}var a3=/^(?:true|false|yes|no|on|off|1|0|)$/i,r3=[/^core\.(?:pager|editor|sshcommand|askpass|alternaterefscommand)$/,/^sequence\.editor$/,/^diff\.external$/,/^interactive\.difffilter$/,/^imap\.tunnel$/,/^gc\.recentobjectshook$/,/^gpg\.program$/,/^gpg\.ssh\.defaultkeycommand$/,/^uploadpack\.packobjectshook$/,/^instaweb\.(?:browser|httpd)$/,/^credential\.(?:.+\.)?helper$/,/^diff\..+\.(?:command|textconv)$/,/^(?:difftool|mergetool|man|browser)\..+\.(?:cmd|path)$/,/^guitool\..+\.cmd$/,/^merge\..+\.driver$/,/^gpg\..+\.program$/,/^remote\..+\.(?:uploadpack|receivepack)$/,/^filter\..+\.(?:clean|smudge|process)$/,/^tar\..+\.command$/,/^trailer\..+\.(?:cmd|command)$/,/^sendemail\.(?:.+\.)?(?:tocmd|cccmd|headercmd|sendmailcmd)$/];function _2(Z,z){let $=Z.toLowerCase(),J=(Y)=>Y===void 0?{kind:"unresolved"}:{kind:"command",text:Y};if(/^alias\./.test($))return z!==void 0&&z.trimStart().startsWith("!")?J(z.trimStart().slice(1)):{kind:"unresolved"};if(/^pager\./.test($)||$==="core.fsmonitor")return z!==void 0&&a3.test(z)?{kind:"harmless"}:J(z);if($==="core.gitproxy")return z!==void 0&&/^none(?:\s+for\s+\S+)?$/.test(z)?{kind:"harmless"}:J(z?.replace(/\s+for\s+\S+$/,""));if(/^submodule\..+\.update$/.test($))return z!==void 0&&z.trimStart().startsWith("!")?J(z.trimStart().slice(1)):z===void 0?{kind:"unresolved"}:{kind:"harmless"};if(/^sendemail\.(?:.+\.)?smtpserver$/.test($))return z!==void 0&&!z.startsWith("/")?{kind:"harmless"}:J(z);if(/^credential\.(?:.+\.)?helper$/.test($)){if(z==="")return{kind:"harmless"};if(z===void 0)return{kind:"unresolved"};let Y=z.trimStart();return J(Y.startsWith("!")?Y.slice(1):Y.startsWith("/")?Y:`git credential-${Y}`)}if(r3.some((Y)=>Y.test($)))return J(z);if($==="core.hookspath")return z==="/dev/null"?{kind:"harmless"}:{kind:"unresolved"};if($==="include.path"||/^includeif\..+\.path$/.test($))return{kind:"unresolved"};if($==="protocol.allow")return z!==void 0&&/^(?:never|user)$/i.test(z)?{kind:"harmless"}:{kind:"unresolved"};if($==="protocol.ext.allow")return z!==void 0&&/^never$/i.test(z)?{kind:"harmless"}:{kind:"unresolved"};return{kind:"harmless"}}function j2(Z){return/[$\x60]/.test(Z)||["","x","/x","!x"].some((z)=>_2(Z,z).kind!=="harmless")}var t3=new Set(["GIT_PAGER","GIT_EDITOR","GIT_SEQUENCE_EDITOR","GIT_EXTERNAL_DIFF","GIT_SSH","GIT_SSH_COMMAND","GIT_ASKPASS","SSH_ASKPASS","GIT_PROXY_COMMAND","PAGER","EDITOR","VISUAL"]),e3=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function Z4(Z){let z=/'((?:[^']|'\\'')*)'/y,$=(X)=>X.replace(/'\\''/g,"'"),J=[],Y=0;while(Y<Z.length){if(/\s/.test(Z[Y])){Y++;continue}z.lastIndex=Y;let X=z.exec(Z);if(!X)return null;if(Y=z.lastIndex,Z[Y]==="="){z.lastIndex=Y+1;let Q=z.exec(Z);if(!Q)return null;Y=z.lastIndex,J.push([$(X[1]),$(Q[1])])}else{let Q=$(X[1]),H=Q.indexOf("=");J.push(H<0?[Q,void 0]:[Q.slice(0,H),Q.slice(H+1)])}}return J}function $4(Z,z,$){let J=[],Y=!1,X=(B,M,V=!0)=>{if(!V||/[$\x60]/.test(B)){Y=!0;return}let G=_2(B,M);if(G.kind==="unresolved")Y=!0;else if(G.kind==="command")J.push({text:G.text,kind:"shell"})},Q=(B,M)=>{let V=B.indexOf("="),G=V<0?B:B.slice(0,V),U=V<0?"true":B.slice(V+1);if(!M)return X(G,U);if(j2(G))Y=!0},H=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let B=z+1;B<Z.length;B++){let M=Z[B];if(!M.startsWith("-")||M==="-")break;if(M==="--")break;if(M==="-c"){if(B+1>=Z.length)break;Q(Z[B+1],$(B+1)),B++}else if(M.startsWith("-c")&&!M.startsWith("--"))Q(M.slice(2),$(B));else if(M==="--config-env"||M.startsWith("--config-env=")){let V=M==="--config-env"?Z[++B]??"":M.slice(13),G=V.indexOf("="),U=G<0?V:V.slice(0,G);if($(B)||j2(U))Y=!0}else if(M.startsWith("--exec-path="))Y=!0;else if(H.has(M))B++}let K=new Map;for(let B=0;B<z;B++){let M=Z[B].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!M)continue;let[,V,G]=M,U=$(B);if(t3.has(V))if(U)Y=!0;else J.push({text:G,kind:"shell"});else if(e3.has(V)){if(U||G!=="/dev/null"||V==="GIT_EXEC_PATH"||V==="GIT_TEMPLATE_DIR")Y=!0}else if(V==="GIT_ALLOW_PROTOCOL"){if(U||G.split(":").includes("ext"))Y=!0}else if(V==="GIT_CONFIG_PARAMETERS"){let j=U?null:Z4(G);if(j===null)Y=!0;else for(let[N,y]of j)X(N,y??"true")}else if(/^GIT_CONFIG_(?:KEY|VALUE)_\d+$/.test(V)){let j=V.replace(/^GIT_CONFIG_(?:KEY|VALUE)_/,""),N=K.get(j)??{};if(V.startsWith("GIT_CONFIG_KEY_"))N.key=G;else N.value=G;if(U)N.opaque=!0;K.set(j,N)}}for(let B of K.values()){if(B.key===void 0)continue;if(B.opaque)Q(`${B.key}=`,!0);else X(B.key,B.value)}if(J.length===0&&!Y)return null;return{programs:J,unresolved:Y}}function EZ(Z){if(/^~/.test(Z))return null;let z="";for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return null;z+=Z.slice($+1,Y),$=Y}else if(J==="$"||J==="`")return null;else if(J==='"'){let Y=$+1;for(;Y<Z.length&&Z[Y]!=='"';Y++){let X=Z[Y];if(X==="$"||X==="`")return null;if(X==="\\"&&Y+1<Z.length&&/[$\x60"\\\n]/.test(Z[Y+1])){if(Z[++Y]!==`
|
|
3
|
-
|
|
4
|
-
`));if(
|
|
5
|
-
`,
|
|
6
|
-
`)return!1;if(
|
|
7
|
-
`)return!1;if(
|
|
8
|
-
`)){let
|
|
9
|
-
`))return!1;
|
|
10
|
-
`||!
|
|
11
|
-
`;
|
|
12
|
-
`||
|
|
13
|
-
`,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function
|
|
14
|
-
`?"":`\\${
|
|
15
|
-
`,
|
|
16
|
-
`,
|
|
17
|
-
`,
|
|
18
|
-
`&&
|
|
19
|
-
`,
|
|
20
|
-
`){if(
|
|
21
|
-
`,
|
|
22
|
-
`,
|
|
23
|
-
`||
|
|
24
|
-
`))};return
|
|
25
|
-
`))};if(!J.trustworthy){let K=NZ(Z);return K===Z?$:{..._Z(K,z),trustworthy:!1}}let X=[],Q=(K,B=$.refusals)=>{if(K.kind==="refuse")B.push({reason:K.reason});else if(K.kind==="rm"&&K.handoff)$.handoffHits.push(K.hit);else if(K.kind==="rm"){if($.rmHits.push(K.hit),K.protectedReason)$.protectedHits.push({reason:K.protectedReason})}},H=Y.cwd;for(let K of J.segments){let B=l(K),M=A0(K),V=B<0?{kind:"none"}:C0(K,B,H,Y);if(V.kind!=="cd")Q(V);let G=(U)=>U!==null&&U>=0&&rZ(K.words[U].text);if(M===null||G(B)||G(M)){if(K.words.some((U,j)=>!K.redirects.has(j)&&(q0(C0(K,j,H,Y))||R4(U.text))))X.push({reason:l4})}else if(M>=0&&M!==B){let U=C0(K,M,H,Y);if(q0(U))if(q0(V))X.push({reason:c4});else Q(U,X)}if(V.kind==="cd")H=V.cwd}if(Y.depth<3)for(let K of J.substitutions){let B=_Z(K,{cwd:H,home:Y.home,depth:Y.depth+1});if(B.rmHits.length>0||B.refusals.length>0||B.handoffHits.length>0||B.protectedHits.length>0||!B.trustworthy&&a(K)){$.refusals.push({reason:"This command runs a delete inside a command substitution `$(…)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(J.substitutions.some((K)=>a(K)))$.refusals.push({reason:"This command nests a delete inside command substitutions deeper than this hook will follow. Run the delete as a separate `rm -- <path>` command."});return $.refusals.push(...X),$}function d4(Z){return Z.words.map((z)=>z.text).join(" ")}function y0(Z,z){let $=z+1;while($<Z.words.length){let J=E(Z.words[$].text);if(!J.startsWith("-"))return J;if($++,O4.has(J))$++}return null}function s4(Z,z){if(Z.words.slice(z+1).map((J)=>E(J.text)).includes("--cached"))return!0;return f2(Z,z)}function f2(Z,z){let $=Z.words.slice(z+1).map((J)=>E(J.text));return $.includes("-n")||$.includes("--dry-run")}function q2(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function n4(Z,z,$,J){let Y=J?["/usr/bin/env","-i",`HOME=${J.home}`,`PATH=${J.path}`,`HASNA_TRASH_AGENT=${J.agent}`,J.runtime,"--config=/dev/null","--no-env-file","--no-macros","--no-install",$,"guard"].map(q2).join(" "):`${q2($)} guard`,X=[...z].sort((H,K)=>K.word.start-H.word.start),Q=Z;for(let H of X)Q=`${Q.slice(0,H.word.start)}${Y}${Q.slice(H.word.end)}`;return Q}function o4(Z,z,$,J,Y){if(!z||z===Z)return!1;if($.length===0)return!1;let X=_Z(z,{cwd:J,home:Y});if(!X.trustworthy)return!1;if(X.rmHits.length>0||X.handoffHits.length>0)return!1;return X.refusals.length===0}function a4(Z,z){let $={};for(let[J,Y]of Object.entries(Z??{}))$[J]=Y;if($.command=z,typeof $.description!=="string"||$.description.trim()==="")$.description=W4;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=j4;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function r4(Z,z,$,J,Y){if(typeof Z.command!=="string"||Z.command.trim()==="")return!1;if(typeof Z.description!=="string"||Z.description.trim()==="")return!1;if(typeof Z.timeout!=="number"||!Number.isFinite(Z.timeout)||Z.timeout<=0)return!1;if(typeof Z.run_in_background!=="boolean")return!1;if("dangerouslyDisableSandbox"in Z&&typeof Z.dangerouslyDisableSandbox!=="boolean")return!1;return o4(z,Z.command,$,J,Y)}function t4(Z){let z=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return f(Z,v2).segments.some((J)=>{let Y=A0(J);return[l(J),...Y===null?[]:[Y]].some((X)=>{if(J.words.slice(0,X<0?J.words.length:X).some((K)=>y2.test(E(K.text))||z.has(FZ(K.text))))return!0;if(X<0)return!1;let H=J.words[X];return z.has(FZ(H.text))||/^\s*\(\s*\)\s*\{/.test(Z.slice(H.end))})})}function i(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function e4(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function Z5(Z){try{if(Z.inspectTrash){let z=Z.inspectTrash();return z.ok?{path:z.path,error:null}:{path:null,error:`${z.code}: ${M2[z.code]}`}}return{path:Z.findTrash(),error:null}}catch(z){return{path:null,error:z instanceof Error?z.message:String(z)}}}var $5="[trash-guard] No verified @hasna/trash guard was found on PATH. This deletion is refused. Install the current @hasna/trash package with Bun and run its setup; the operating-system trash utility is not a compatible guard.",C2="[trash-guard] The rewrite of this command did not verify (the delete could not be redirected cleanly), so the command is refused rather than run unredirected. Re-run the delete as a plain `rm -- <path>` command.";function P2(Z,z){if(Z.refusals.length>0)return i(`[trash-guard] ${Z.refusals[0].reason}`);if(Z.protectedHits.length>0)return i(`[trash-guard] ${Z.protectedHits[0].reason}`);if(!Z.trustworthy)return a(z)?i("[trash-guard] This command could not be parsed to the end (unterminated quote, substitution or here-document), so a delete inside it cannot be redirected. Re-run the delete as a plain `rm -- <path>` command."):{continue:!0};if(Z.rmHits.length===0){if(Z.handoffHits.some(($)=>$.cwdOnly))return i("[trash-guard] This delete runs from inside a protected repository checkout but names only paths outside it. Run it from outside the checkout (`cd /tmp && rm -- <path>`), where it is redirected into trash.");return{continue:!0}}if(Z.handoffHits.length>0)return i("[trash-guard] This command mixes a delete under the protected repo-checkout roots (owned by workspace-repos-guard) with a delete outside them, and a partial rewrite would leave one of them unredirected. Re-run them as separate commands, so each delete is handled by the hook that owns it.");return null}function k2(Z,z){if(Z.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(Z.tool_name??"")){let j=Z.tool_input?.command;if(typeof j!=="string")return i("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(j))return i("[trash-guard] Delete File would bypass recoverable deletion. First use `trash put -- <path>` or the trash_put MCP tool, then submit any remaining edits without the deletion block.");return{continue:!0}}if(Z.tool_name!=="Bash")return{continue:!0};if(typeof Z.tool_input?.command!=="string")return i("[trash-guard] The Bash tool call carried no readable `command`, so this hook cannot verify what would run. Refusing a call it cannot verify. Re-run the delete explicitly as `rm -- <path>` so it can be redirected into trash.");let J=WZ(Z);if(!J.trim())return{continue:!0};let Y=()=>_Z(J,{cwd:z.cwd,home:z.home}),X=(j)=>j.rmHits.map((N)=>N.word.start).join(),Q=(j)=>j()||!!HZ(J,j),H=Y(),K=P2(H,J),B=HZ(J,()=>{let j=Y();return{result:j,verdict:P2(j,J)}});if(B){let{result:j,verdict:N}=B;if(N&&!("continue"in N))return N;if(!N&&(!K||("continue"in K))&&X(j)!==X(H))return i(C2)}if(K)return K;let M=Z5(z);if(M.error!==null)return i(`[trash-guard] The guard could not resolve the \`trash\` binary (${M.error}), so this \`rm\` cannot be redirected into a recoverable delete — and an unrecoverable delete is never allowed, so the command is refused rather than run. Fix the environment (PATH, permissions) and re-run the same command.`);if(M.path===null)return i($5);let V=M.path;if(z.execution&&Q(()=>t4(J)))return i("[trash-guard] A deletion combined with shell environment changes cannot use the verified native execution context. Run the deletion as a separate plain rm command.");let G=n4(J,H.rmHits,V,z.execution),U=a4(Z.tool_input,G);if(z.execution)U.hasna_execution="hasna.hooks.execution.v1";if(Q(()=>!r4(U,J,H.rmHits,z.cwd,z.home)))return i(C2);return e4(U)}var h=require("node:fs"),f0=require("node:os"),O=require("node:path");var J5=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),z5=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),Y5=["hasna","hasnaxyz","hasna-products"],uZ="workspace-repos-guard";function X5(Z){return O.join(Z,".hasna","repos","clones")}function Q5(Z){return O.join(Z,"workspace","repos")}function i2(Z){return[X5(Z),Q5(Z)]}function K5(Z){return O.join(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var H5=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function R0(Z){let z=process.getuid?.();return z!==void 0&&(Z.uid===0||Z.uid===z)&&(Z.mode&18)===0}function B5(Z){let z=K5(Z),$;try{let Y=h.openSync(z,h.constants.O_RDONLY|h.constants.O_NOFOLLOW);try{let Q=h.fstatSync(Y);if(!Q.isFile()||!R0(Q)||Q.size>4096)return null;$=h.readFileSync(Y,"utf8")}finally{h.closeSync(Y)}let X=O.normalize(Z);for(let Q=O.dirname(z);Q!==X;Q=O.dirname(Q)){let H=h.lstatSync(Q);if(!H.isDirectory()||!R0(H)||Q===O.dirname(Q))return null}if(!R0(h.statSync(X)))return null}catch{return null}let J=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return J.length>0&&J.every((Y)=>H5.test(Y))?new Set(J):null}function M5(Z=process.env,z=f0.homedir()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((J)=>J.trim()).filter(Boolean));return B5(z)??new Set(Y5)}function v0(Z,z,$,J){if(J==="read")return{blocked:!1};let Y=O.relative(z,Z);if(Y===""){if(J==="delete")return{blocked:!0,reason:`[${uZ}] delete of the protected repo-checkout root is forbidden: ${z}`};return{blocked:!0,reason:`[${uZ}] writes directly to the protected repo-checkout root are forbidden: ${z}`}}if(Y.startsWith(`..${O.sep}`)||Y===".."||O.isAbsolute(Y))return{blocked:!1};let X=Y.split(O.sep).filter(Boolean);if(J==="delete")return{blocked:!0,reason:`[${uZ}] delete under the protected repo-checkout root (${z}) is forbidden at any depth: ${Z}`};if(X.length<=1)return{blocked:!0,reason:`[${uZ}] writing would create a top-level entry directly under the protected repo-checkout root (${z}); only GitHub-org folders belong there: ${Z}`};let Q=X[0];if(!$.has(Q))return{blocked:!0,reason:`[${uZ}] '${Q}' is not an allowed GitHub org under the protected repo-checkout root (${z}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var d2=/\b(?:-o|--output|-O|--output-document|-out)\b/,V5=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,G5=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function s2(Z){return Z.replace(V5," ")}function U5(Z){let z=[],$=null,J=0,Y=0,X=!1,Q=0;for(let H=0;H<Z.length;H++){let K=Z[H];if($==="'"){if(K==="'")$=null;continue}if(K==="\\"){H++;continue}if(K==="("){J++;continue}if(K===")"){if(--J<0)return[Z];continue}if(K==="$"&&Z[H+1]==="{"){Y++,H++;continue}if(K==="}"&&Y>0){Y--;continue}if(K==="`"){X=!X;continue}if($==='"'){if(K==='"')$=null;continue}if(K==="'"||K==='"'){$=K;continue}if(K!=="|"||J>0||Y>0||X||Z[H-1]===">")continue;if(z.push(Z.slice(Q,H)),Z[H+1]==="&")H++;Q=H+1}if($||J!==0||Y!==0||X)return[Z];return z.push(Z.slice(Q)),z}function j5(Z){let z=[],$="",J="",Y=null,X=!1,Q=()=>{if(!X)return;let H=J.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),K=$.startsWith("~")&&!/^~(?:\/|$)/.test(J);z.push({text:K?`./${$}`:$,opaque:/[$\x60*?[]/.test(H)||/[()]/.test(H)||sZ(J)}),$="",J="",X=!1};for(let H=0;H<Z.length;H++){let K=Z[H];if(Y==="'"){if(K==="'")Y=null;else $+=K;J+=K;continue}if(K==="\\"&&H+1<Z.length){let B=Z[H+1];$+=Y==='"'&&!/[$\x60"\\\n]/.test(B)?K+B:Y==='"'&&B===`
|
|
26
|
-
|
|
27
|
-
`)
|
|
28
|
-
`),
|
|
29
|
-
`));for(let
|
|
30
|
-
`))?null:{outer:
|
|
31
|
-
`),bodies:Y}}var x5="/";function J0(Z,z,$){if(!Z)return[];let J=f(Z).trustworthy?Z:NZ(Z),Y=k5(Z);return[...J===Z?[]:J0(J,z,$),...Y?[...c2(Y.outer,z,$),...Y.bodies.flatMap((X)=>J0(X,z,x5))]:c2(Z,z,$)]}var h5=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,w5=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function l2(Z,z,$=!1){let J=[],Y=0;for(let H of z)J.push(Y),Y+=H.length;let X=f(Z);if(!X.trustworthy||!$&&X.substitutions.length>0)return null;let Q=X.segments.flatMap((H)=>H.words).filter((H)=>z.some((K,B)=>B%2===1&&J[B]<H.end&&J[B]+K.length>H.start));return Q.length>0?{lexed:X,offsets:J,words:Q}:null}function m2(Z,z,$=[]){if(x0(z)!=="read")return!1;let J=l(Z),Y=Z.words.filter((M,V)=>!Z.redirects.has(V)),X=KZ(Y.map((M)=>h0(M.text)));if(X===null)return!1;let Q=[J<0?1/0:J,X.index<0?1/0:Z.words.indexOf(Y[X.index])];if(Z.words.some((M,V)=>V<Math.max(...Q)&&!Z.redirects.has(V)&&bZ.test(E(M.text))))return!1;if([J<0?null:Z.words[J].text,X.index<0?null:Y[X.index].text].every((M)=>M===null||e2.has(o(E(M)))))return!0;let K=Y.filter((M)=>!$.includes(M)),B=K.map((M)=>E(M.text));return MZ(K.map((M)=>M.text).join(" "))==="read"&&MZ(B.join(" "))==="read"&&!B.some((M)=>o2.has(M))}function g5(Z,z,$,J){let Y=(X)=>X.start<J&&X.end>$;if(!z.words.some(Y))return!1;return z.lexed.segments.filter((X)=>X.words.some(Y)).some((X)=>Z0(X))}var p2=(Z,z)=>Z.slice(z.words[0].start,z.words[z.words.length-1].end);function u5(Z,z,$,J){let Y=(Q)=>Q.start<J&&Q.end>$,X=z.words.filter(Y);if(X.length===0||X.some((Q)=>!w5.test(Q.text)))return!1;for(let Q of z.lexed.segments.filter((H)=>H.words.some(Y)))if(!m2(Q,p2(Z,Q),z.words))return!1;for(let Q of X){let H=Q.text.slice(1,-1);if(H.includes("<<"))return!1;let K=f(H);if(!K.trustworthy||K.substitutions.length>0)return!1;if(!K.segments.every((B)=>m2(B,p2(H,B))))return!1}return!0}function c2(Z,z,$){if(!Z)return[];let J=i2(z),Y=(U)=>J.some((j)=>U===j||U.startsWith(`${j}${O.sep}`)),X=Z.split(h5),Q=l2(Z,X),H=Q??l2(Z,X,!0),K=[],B=[$],M=new Set([$]),V=!0,G=[];for(let U=0;U<X.length;U+=2){let j=U===0?"":X[U-1].trim();if(j==="||")V=!1;else if(j!=="&&")V=!0;if(j!=="&&"||!V)B=[...M];let N=X[U],y=(N.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,b=(N.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let _=0;_<y;_++)G.push({current:[...B],reachable:new Set(M),certain:V});let k=F5(N),d=Q!==null&&u5(Z,Q,Q.offsets[U],Q.offsets[U]+N.length),q=!d&&(H!==null&&g5(Z,H,H.offsets[U],H.offsets[U]+N.length)||$0(N.trim())),F=k.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),R=F?null:k.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(R){for(let _ of g2(R[1],B,z)??[])M.add(_);V=!1,B=[...M]}let m=S0(z),p=J.map((_)=>S0(_.slice(z.length+1))).join("|"),qZ=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${m}"*)/(?:${p})`),z2=new RegExp(`(${qZ.source})([^\\s"';&|<>()\`]*|$)`,"g"),Y2=(_)=>{let g=[],c;z2.lastIndex=0;while((c=z2.exec(_))!==null)g.push(O.normalize(mZ(c[0],z)).replace(/\/+$/,""));return g},X2=H===null?0:H.offsets[U],Q2=(_)=>_.start<X2+N.length&&_.end>X2,T3=H!==null&&H.words.some(Q2)?lZ({segments:H.lexed.segments.filter((_)=>_.words.some(Q2))}):[N.trim(),k].flatMap((_)=>{let g=f(_);if(!g.trustworthy)g=f(NZ(_));return g.trustworthy?lZ(g):[]}),V0=U5(k).map((_,g)=>{let c=g===0?[...new Set(T3)]:[],CZ=!1,PZ=s2(_).replace(G5,(U0,UZ)=>{if(!UZ||/[$\x60]/.test(UZ))CZ=!0;if(UZ)c.push(UZ);return" "}),OZ=d?"read":q?"delete":x0(PZ);return{commandPart:PZ,operands:c,op:CZ&&OZ==="read"?"write":OZ}}),q3=V0.some((_)=>_.op==="delete")?"delete":V0.some((_)=>_.op==="write")?"write":"read",G0=B.filter(Y);if(q)for(let _ of G0)K.push({path:_,op:"delete"});for(let _ of V0){let g=!1;for(let u of Y2(_.commandPart))g=!0,K.push({path:u,op:q3});for(let u of _.operands){let e=Y2(u);for(let n of e)K.push({path:n,op:"write"});if(e.length>0)continue;for(let n of G0)K.push({path:O.normalize(O.resolve(n,mZ(u,z))),op:"write"})}if(g||_.op==="read")continue;let c=j5(_.commandPart),CZ=D5(_.commandPart,c),PZ=o(c[CZ]?.text??""),OZ=c.slice(CZ+1),U0=((PZ==="trash"?O5(OZ):null)??I5(PZ,OZ)).map((u)=>u.opaque?".":u.text),UZ=_.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(_.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(_.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(_.commandPart),LZ=[];if(UZ)for(let u of U0.length>0?U0:["."])LZ.push({operand:u,op:_.op});else{let u=_.commandPart.match(_5),e=c.at(-1);if(LZ.push({operand:u?u[1]:!e||e.opaque?".":e.text,op:_.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(_.commandPart))c.forEach((n,K2)=>{let jZ,j0=n.text.match(/^-[A-Za-z]*?t(.*)$/),cZ=n.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(j0&&!n.text.startsWith("--"))jZ=j0[1]?{text:j0[1],opaque:n.opaque}:c[K2+1];else if(cZ&&"--target-directory".startsWith(cZ[1]))jZ=cZ[2]!==void 0?{text:cZ[2],opaque:n.opaque}:c[K2+1];if(jZ)LZ.push({operand:jZ.opaque||!jZ.text?".":jZ.text,op:_.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(_.commandPart))LZ.push({operand:".",op:_.op})}for(let u of G0)for(let{operand:e,op:n}of LZ)K.push({path:O.normalize(O.resolve(u,mZ(e,z))),op:n})}if(F){let _=g2(F[1],B,z);if(_){for(let g of _)M.add(g);if(V)B=_}else V=!1}for(let _=0;_<b&&G.length>0;_++)({current:B,reachable:M,certain:V}=G.pop())}return K}var l5=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function m5(Z,z){let $=[],J;while((J=l5.exec(Z))!==null){let Y=J[1]==="Delete File"?"delete":"write";$.push({path:O.normalize(O.resolve(z,J[2])),op:Y})}return $}function J3(Z,z={}){let $=[];if(Z.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:$};let J=typeof Z.tool_name==="string"?Z.tool_name:"",Y=z.home??f0.homedir(),X=i2(Y),Q=M5(process.env,Y);if(J==="Bash"){let G=WZ(Z);if(!G)return{output:{continue:!0},warnings:$};let U=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd(),j=J0(G,Y,U);j.unshift(...HZ(G,()=>J0(G,Y,U))??[]);for(let N of j)for(let y of X){let b=v0(N.path,y,Q,N.op);if(b.blocked)return{output:{decision:"block",reason:b.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let H=Z.tool_input??{},K=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(z5.has(J)){let G=typeof H.patch==="string"?H.patch:"";if(!G)return{output:{continue:!0},warnings:$};let U=m5(G,K);for(let j of U)for(let N of X){let y=v0(j.path,N,Q,j.op);if(y.blocked)return{output:{decision:"block",reason:y.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!J5.has(J))return{output:{continue:!0},warnings:$};let B=typeof H.file_path==="string"?H.file_path:typeof H.path==="string"?H.path:typeof H.notebook_path==="string"?H.notebook_path:null;if(!B)return{output:{continue:!0},warnings:$};let M=mZ(B,Y),V=O.isAbsolute(M)?O.normalize(M):O.resolve(K,M);for(let G of X){let U=v0(V,G,Q,"write");if(U.blocked)return{output:{decision:"block",reason:U.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var p5=new Set(["id","node_id","databaseId","fullDatabaseId","number","state","state_reason","stateReason","status","conclusion","bucket","name","login","sha","oid","abbreviatedOid","ref","headRefName","baseRefName","headRefOid","baseRefOid","head_sha","headSha","head_branch","headBranch","merged","mergeable","mergeable_state","mergeStateStatus","draft","isDraft","locked","isLocked","title","displayTitle","display_title","created_at","updated_at","closed_at","merged_at","started_at","completed_at","submitted_at","pushed_at","published_at","createdAt","updatedAt","closedAt","mergedAt","startedAt","completedAt","submittedAt","pushedAt","publishedAt","tag_name","tagName","total_count","totalCount","count","additions","deletions","changes","changed_files","changedFiles","filename","path","event","workflow","workflowName","workflow_id","workflowDatabaseId","run_id","run_number","run_attempt","attempt","check_suite_id","default_branch","defaultBranch","full_name","fullName","nameWithOwner","private","isPrivate","visibility","archived","isArchived","fork","isFork","isRequired","is_required","required","context","type","__typename","role","permission","size","reviewDecision","author_association","authorAssociation","isCrossRepository","maintainerCanModify","maintainer_can_modify","commentsCount","language","digest","size_in_bytes","run_started_at","date","wait_timer","ahead_by","behind_by","total_commits","expired","current_user_can_approve","environment","html_url"]),c5=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),Q3=new Set(["length","utf8bytelength","not","type","any","all","isempty","empty","test","startswith","endswith","contains","inside","has","in","index","rindex","indices","floor","ceil","round","fabs","sqrt","isinfinite","isnan","isnormal","infinite","nan","true","false","null"]),K3=new Set(["tostring","tojson","ascii_downcase","ascii_upcase","ltrimstr","rtrimstr","trim","ltrim","rtrim","sort","unique","reverse","first","last","min","max","add","flatten","join","split","values","nulls","strings","numbers","booleans","arrays","objects","iterables","scalars","sort_by","group_by","unique_by","min_by","max_by","select","limit","to_entries","from_entries"]),i5=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),d5=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class u0 extends Error{}var L=()=>{throw new u0};function w0(Z,z){let $=[],J="",Y=z+1;while(Y<Z.length){let X=Z[Y];if(X==='"'){if(J)$.push(J);return{end:Y+1,parts:$}}if(X==="\\"){let Q=Z[Y+1];if(Q==="("){let H=1,K=Y+2;while(K<Z.length&&H>0){let B=Z[K];if(B==='"'){K=w0(Z,K).end;continue}if(B==="(")H++;else if(B===")")H--;K++}if(H!==0)L();if(J)$.push(J),J="";$.push({src:Z.slice(Y+2,K-1)}),Y=K;continue}if(Q===void 0)L();J+=Q,Y+=2;continue}J+=X,Y++}return L()}function H3(Z){let z=[],$=0,J=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let Y=Z[$];if(/\s/.test(Y)){$++;continue}if(Y==="#")L();if(Y==='"'){let K=w0(Z,$);z.push({t:"str",parts:K.parts}),$=K.end;continue}if(Y==="."){if(Z[$+1]===".")L();let K=/^[A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($+1));if(K){z.push({t:"field",name:K[0]}),$+=1+K[0].length;continue}if(Z[$+1]==='"'){let B=w0(Z,$+1);if(B.parts.some((M)=>typeof M!=="string"))L();z.push({t:"field",name:B.parts.join("")}),$=B.end;continue}z.push({t:"dot"}),$++;continue}if(Y==="$"||Y==="@"){let K=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($));if(!K||Y==="$")L();z.push({t:"fmt",name:K[0]}),$+=K[0].length;continue}let X=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(Z.slice($));if(X){z.push({t:"num"}),$+=X[0].length;continue}let Q=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(Z.slice($));if(Q){z.push({t:"ident",name:Q[0]}),$+=Q[0].length;continue}let H=J.find((K)=>Z.startsWith(K,$));if(!H)L();z.push({t:"op",v:H}),$+=H.length}return z}var s5=new Set(["if","then","elif","else","end","as","def","reduce","foreach","try","catch","label","import","include","and","or","__loc__","error","input","inputs","debug","stderr","env","halt","halt_error","input_filename","input_line_number","recurse","paths","leaf_paths","getpath","setpath","delpaths","del","path","splits","sub","gsub","capture","match","scan","keys","keys_unsorted","map_values","with_entries","tostream","fromstream","truncate_stream","walk","tonumber","implode","explode","ascii","fromjson"]);class l0{tokens;at=0;constructor(Z){this.tokens=Z}parse(){if(this.tokens.length===0)L();let Z=this.pipe();if(this.at!==this.tokens.length)L();return Z}peek(){return this.tokens[this.at]}isOp(Z){let z=this.peek();return!!z&&z.t==="op"&&z.v===Z}isIdent(Z){let z=this.peek();return!!z&&z.t==="ident"&&z.name===Z}expectOp(Z){if(!this.isOp(Z))L();this.at++}pipe(){let Z=this.comma();if(this.isIdent("as"))L();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.pipe()};return Z}comma(){let Z=this.alt();while(this.isOp(","))this.at++,Z={k:"comma",a:Z,b:this.alt()};return Z}alt(){let Z=this.or();if(this.isOp("//"))return this.at++,{k:"alt",a:Z,b:this.alt()};return Z}or(){let Z=this.and();while(this.isIdent("or"))this.at++,Z={k:"bool",a:Z,b:this.and()};return Z}and(){let Z=this.cmp();while(this.isIdent("and"))this.at++,Z={k:"bool",a:Z,b:this.cmp()};return Z}cmp(){let Z=this.add();for(let z of["==","!=","<=",">=","<",">"])if(this.isOp(z))return this.at++,{k:"bool",a:Z,b:this.add()};for(let z of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(z))L();return Z}add(){let Z=this.mul();while(this.isOp("+")||this.isOp("-"))this.at++,Z={k:"arith",a:Z,b:this.mul()};return Z}mul(){let Z=this.unary();while(this.isOp("*")||this.isOp("/")||this.isOp("%"))this.at++,Z={k:"arith",a:Z,b:this.unary()};return Z}unary(){if(this.isOp("-"))return this.at++,{k:"neg",of:this.postfix()};return this.postfix()}objectValue(){let Z=this.unary();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.objectValue()};return Z}postfix(){let Z=this.primary();for(;;){let z=this.peek();if(!z)return Z;if(z.t==="field"){this.at++,Z={k:"field",name:z.name,of:Z};continue}if(z.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(z.t==="op"&&z.v==="?"){this.at++,Z={k:"opt",of:Z};continue}if(z.t==="op"&&z.v==="["){Z=this.bracket(Z);continue}return Z}}bracket(Z){if(this.expectOp("["),this.isOp("]"))return this.at++,{k:"iter",of:Z};if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}let z=this.pipe();if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}return this.expectOp("]"),{k:"index",of:Z,key:z}}primary(){let Z=this.peek();if(!Z)return L();switch(this.at++,Z.t){case"dot":return{k:"dot"};case"field":return{k:"field",name:Z.name};case"num":return{k:"lit"};case"str":return this.stringNode(Z.parts);case"fmt":{if(!d5.has(Z.name))L();let z=this.peek();if(z?.t==="str")return this.at++,{k:"fmt",name:Z.name,str:this.stringNode(z.parts)};return{k:"fmt",name:Z.name}}case"ident":{if(s5.has(Z.name))L();if(Z.name==="map"||Q3.has(Z.name)||K3.has(Z.name)){let z=[];if(this.isOp("(")){this.at++,z.push(this.pipe());while(this.isOp(";"))this.at++,z.push(this.pipe());this.expectOp(")")}return{k:"call",name:Z.name,args:z}}return L()}case"op":{if(Z.v==="("){let z=this.pipe();return this.expectOp(")"),z}if(Z.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let z=this.pipe();return this.expectOp("]"),{k:"array",of:z}}if(Z.v==="{")return this.object();return L()}}return L()}stringNode(Z){let z=[];for(let $ of Z){if(typeof $==="string")continue;z.push(new l0(H3($.src)).parse())}return z.length===0?{k:"str",parts:z,text:Z.join("")}:{k:"str",parts:z}}object(){let Z=[];if(this.isOp("}"))return this.at++,{k:"object",entries:Z};for(;;){let z=this.peek();if(!z)L();this.at++;let $;if(z.t==="ident")$=z.name;else if(z.t==="str"){if(z.parts.some((J)=>typeof J!=="string"))L();$=z.parts.join("")}else L();if(this.isOp(":"))this.at++,Z.push({key:"static",value:this.objectValue()});else Z.push({key:"static",value:{k:"field",name:$}});if(this.isOp(",")){this.at++;continue}return this.expectOp("}"),{k:"object",entries:Z}}}}function m0(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(m0);return Z==="safe"||typeof Z==="object"&&p5.has(Z.leaf)}var pZ=(...Z)=>Z.every(m0)?"safe":"tainted";function g0(...Z){let z=[];for(let $ of Z)if(typeof $==="object"&&"union"in $)z.push(...$.union);else z.push($);return z.length===1?z[0]:{union:z}}function z0(Z,z){return typeof Z==="object"&&"union"in Z?g0(...Z.union.map(z)):z(Z)}var Y0=(Z)=>typeof Z==="object"&&("leaf"in Z)&&c5.has(Z.leaf),zZ=(Z)=>z0(Z,(z)=>z==="safe"?"safe":z==="tainted"||Y0(z)?"tainted":"unknown");function z3(Z){return Z.k==="lit"||Z.k==="str"&&Z.parts.length===0||Z.k==="call"&&["true","false","null"].includes(Z.name)&&Z.args.length===0}function Y3(Z,z,$){return z0(Z,(J)=>{if(J==="safe"||J==="tainted")return J;if(Y0(J))return"tainted";if(J==="root"&&$.rootScalars.has(z))return"safe";return{leaf:z}})}function A(Z,z,$){switch(Z.k){case"dot":return z;case"field":return Y3(Z.of?A(Z.of,z,$):z,Z.name,$);case"iter":return zZ(A(Z.of,z,$));case"index":{let J=A(Z.of,z,$);if(Z.key.k==="str"&&Z.key.text!==void 0)return Y3(J,Z.key.text,$);if(Z.key.k==="lit")return zZ(J);return A(Z.key,z,$),"tainted"}case"slice":return z0(A(Z.of,z,$),(J)=>J==="root"?"unknown":Y0(J)?"tainted":J);case"opt":return A(Z.of,z,$);case"lit":return"safe";case"str":return pZ(...Z.parts.map((J)=>A(J,z,$)));case"fmt":return Z.str?A(Z.str,z,$):z;case"array":return Z.of?pZ(A(Z.of,z,$)):"safe";case"object":return pZ(...Z.entries.map((J)=>A(J.value,z,$)));case"pipe":return A(Z.b,A(Z.a,z,$),$);case"comma":return g0(A(Z.a,z,$),A(Z.b,z,$));case"alt":return g0(A(Z.a,z,$),A(Z.b,z,$));case"bool":return A(Z.a,z,$),A(Z.b,z,$),"safe";case"arith":return pZ(A(Z.a,z,$),A(Z.b,z,$));case"neg":return A(Z.of,z,$);case"call":return n5(Z,z,$)}}var X3=(Z)=>z0(Z,(z)=>z==="root"?"unknown":Y0(z)?"tainted":z);function n5(Z,z,$){let{name:J,args:Y}=Z;if(i5.has(J)&&J!=="limit"&&!Y.every(z3))L();switch(J){case"map":if(Y.length!==1)L();return pZ(A(Y[0],zZ(z),$));case"select":if(Y.length!==1)L();return A(Y[0],z,$),z;case"limit":if(Y.length!==2||!z3(Y[0]))L();return A(Y[1],z,$);case"first":case"last":if(Y.length>1)L();return Y.length===1?A(Y[0],z,$):zZ(z);case"min":case"max":return zZ(z);case"sort_by":case"group_by":case"unique_by":if(Y.length!==1)L();return A(Y[0],zZ(z),$),X3(z);case"min_by":case"max_by":if(Y.length!==1)L();return A(Y[0],zZ(z),$),zZ(z);case"any":case"all":case"isempty":for(let X of Y)A(X,"unknown",$);return"safe"}if(Q3.has(J))return"safe";if(K3.has(J))return X3(z);return L()}function B3(Z,z={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new l0(H3(Z)).parse();return m0(A($,"root",{rootScalars:z.rootScalars??new Set}))}catch($){if($ instanceof u0)return!1;return!1}}var r0="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",T={refused:!1},I=(Z)=>({refused:!0,rule:Z}),p0=new Set(["additions","assignees","author","baseRefName","baseRefOid","changedFiles","closed","closedAt","createdAt","deletions","files","fullDatabaseId","headRefName","headRefOid","headRepository","headRepositoryOwner","id","isCrossRepository","isDraft","labels","maintainerCanModify","mergeCommit","mergeStateStatus","mergeable","mergedAt","mergedBy","number","potentialMergeCommit","reactionGroups","reviewDecision","reviewRequests","state","title","updatedAt","url"]),c0=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),M3=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),V3=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),o5=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),a5=new Set(["author","committer","id","parents","repository","sha","url"]),r5=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function j3(Z){let z=[];for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="\\"){$++;continue}if(J==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return!1;$=Y;continue}if(J==='"'){$++;while($<Z.length&&Z[$]!=='"')$+=Z[$]==="\\"?2:1;continue}if(J==="{"){z.push({list:!1});continue}if(z.length===0)continue;if(J===","||J==="."&&Z[$+1]===".")z[z.length-1].list=!0;else if(J==="}"&&z.pop().list)return!0}return!1}function IZ(Z){let z="",$=!1,J=0,Y=(X)=>Z[X]==="`"||Z[X]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(Z[X+1]??"");while(J<Z.length){let X=Z[J];if(X==="\\"){z+=Z[J+1]??"",J+=2;continue}if(X==="$"&&Z[J+1]==="'"){$=!0,z+=X,J++;continue}if(X==="'"){let Q=Z.indexOf("'",J+1);if(Q<0){$=!0,z+=Z.slice(J+1);break}z+=Z.slice(J+1,Q),J=Q+1;continue}if(X==='"'){J++;while(J<Z.length&&Z[J]!=='"'){if(Z[J]==="\\"&&/[$`"\\\n]/.test(Z[J+1]??"")){z+=Z[J+1],J+=2;continue}if(Y(J))$=!0;z+=Z[J],J++}if(J>=Z.length)$=!0;J++;continue}if(Y(J)||X==="*"||X==="?"||X==="[")$=!0;z+=X,J++}if(!$&&Z.includes("{")&&j3(Z))$=!0;return{value:z,opaque:$,raw:Z}}var VZ=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function s0(Z,z="word"){let $=[],J=!1;for(let Y=0;Y<Z.length;Y++){let X=Z[Y];if(X==="\\"){Y++;continue}if(z==="word"&&X==="'"&&!J){let Q=Z.indexOf("'",Y+1);if(Q<0)return{bodies:$,complete:!1};Y=Q;continue}if(z==="word"&&X==='"'){J=!J;continue}if(X==="`"){let Q=Y+1;while(Q<Z.length&&Z[Q]!=="`")Q+=Z[Q]==="\\"?2:1;if(Q>=Z.length)return{bodies:$,complete:!1};$.push(Z.slice(Y+1,Q)),Y=Q;continue}if(X==="$"&&Z[Y+1]==="("){let Q=BZ(Z,Y+1);if(Q<0)return{bodies:$,complete:!1};$.push(Z.slice(Y+2,Q-1)),Y=Q-1}}return{bodies:$,complete:!0}}function TZ(Z,z){let $=new Set(z.values),J={flags:[],positionals:[]},Y=(X,Q)=>({value:X,opaque:Q.opaque,raw:Q.raw});for(let X=0;X<Z.length;X++){let Q=Z[X],H=Q.value;if(H==="--"){J.positionals.push(...Z.slice(X+1));break}if(H.startsWith("--")&&H.length>2){let K=H.indexOf("="),B=K>=0?H.slice(0,K):H;if(K>=0)J.flags.push({name:B,value:Y(H.slice(K+1),Q),inline:!0});else if($.has(B)){let M=Z[X+1];J.flags.push(M?{name:B,value:M}:{name:B,missing:!0}),X++}else J.flags.push({name:B});continue}if(H.startsWith("-")&&H.length>1){for(let K=1;K<H.length;K++){let B="-"+H[K],M=H.slice(K+1);if(M.startsWith("=")){J.flags.push({name:B,value:Y(M.slice(1),Q),inline:!0});break}if(!$.has(B)){J.flags.push({name:B});continue}if(M)J.flags.push({name:B,value:Y(M,Q),inline:!0});else{let V=Z[X+1];J.flags.push(V?{name:B,value:V}:{name:B,missing:!0}),X++}break}continue}J.positionals.push(Q)}return J}function w(Z,...z){let $=!1;for(let J of Z.flags){if(!z.includes(J.name))continue;if(!J.inline){$=!0;continue}let Y=J.value;$=!Y.opaque&&["1","t","T","TRUE","true","True"].includes(Y.value)}return $}var XZ=(Z,...z)=>Z.flags.filter(($)=>z.includes($.name)),s=["-R","--repo","-q","--jq","-t","--template","--json"],GZ={"pr view":{values:s},"issue view":{values:s},"release view":{values:s},"discussion view":{values:[...s,"--after","-L","--limit","--order"]},"pr list":{values:[...s,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...s,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...s,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...s,"-L","--limit","-O","--order"]},"pr status":{values:s},"issue status":{values:s},"pr checks":{values:[...s,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...s,"--app","--assignee","--author","--author-date","--author-email","--author-name","--base","--checks","--closed","--commenter","--committer","--committer-date","--committer-email","--committer-name","--created","--hash","--head","--interactions","--involves","--label","--language","--limit","-L","--match","--mentions","--merged-at","--milestone","--no-assignee","--no-label","--no-milestone","--no-project","--order","--owner","--parent","--project","--reactions","--review","--review-requested","--reviewed-by","--sort","--state","--team-mentions","--tree","--updated","--visibility","--extension","--filename","--size","--forks","--good-first-issue","--help-wanted-issues","--number-topics","--stars","--topic","--followers","--include-forks","--license"]},"project item-list":{values:["--format","-L","--limit","--owner","-q","--jq","-t","--template","--query","--field","--field-id"]},api:{values:["-X","--method","-H","--header","-f","--raw-field","-F","--field","-q","--jq","-t","--template","-p","--preview","--input","--hostname","--cache"]},group:{values:["-R","--repo"]}},t5=new Set(["auth","browse","codespace","cs","gist","org","repo","skill","cache","run","workflow","co","agent-task","alias","attestation","completion","config","copilot","extension","ext","extensions","gpg-key","label","licenses","preview","ruleset","secret","ssh-key","variable","help","version","accessibility","actions","environment","exit-codes","formatting","mintty","reference","telemetry"]),e5=new Set(["pr","issue","release","discussion","search","project","api","status"]),Z6=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),$6=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),J6=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),z6=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function H0(Z,z){let $=XZ(Z,"--json"),J=[],Y=!1;for(let X of $){if(X.missing){if(z.appendsArgs)Y=!0;continue}if(!X.value)continue;if(X.value.opaque)Y=!0;J.push(...X.value.value.split(",").map((Q)=>Q.trim()).filter(Boolean))}return{present:$.length>0,opaque:Y,fields:J}}function t0(Z,z){if(w(Z,"--verbose")||XZ(Z,"-t","--template").length>0)return!1;let $=XZ(Z,"-q","--jq");return $.length>0&&$.every((J)=>J.value!==void 0&&!J.value.opaque&&B3(J.value.value,{rootScalars:z}))}function e0(Z,z,$,J){let Y=H0(Z,$);if(Y.opaque)return I("unclassifiable");if(Y.fields.every((X)=>z.has(X)))return T;if($.debug)return I("debug-traffic");return t0(Z)?T:I(J)}function X0(Z,z,$,J,Y){let X=TZ(Z,GZ[z]);if(w(X,"-h","--help"))return T;if(w(X,"-w","--web"))return J.debug?I("debug-traffic"):T;if(Y&&w(X,"-c","--comments"))return I("view-comments");if(!H0(X,J).present)return I(J.debug?"debug-traffic":"view-human");return e0(X,$,J,"json-composite")}function YZ(Z,z,$,J){let Y=TZ(Z,GZ[z]);if(w(Y,"-h","--help"))return T;if(J.debug&&(w(Y,"-w","--web")||!H0(Y,J).present))return I("debug-traffic");if(w(Y,"-w","--web"))return T;return e0(Y,$,J,"json-composite")}function Y6(Z,z){let $=TZ(Z,GZ["pr checks"]);if(w($,"-h","--help"))return T;if(z.debug)return I("debug-traffic");if(w($,"-w","--web"))return T;if(!H0($,z).present)return I("checks-human");return e0($,r5,z,"checks-json")}function X6(Z){let z=new Set(GZ.group.values);for(let $=0;$<Z.length;$++){let J=Z[$].value;if(J==="--")return{sub:Z[$+1],rest:Z.slice($+2)};if(!J.startsWith("-")||J==="-")return{sub:Z[$],rest:[...Z.slice(0,$),...Z.slice($+1)]};if(z.has(J))$++}return{rest:Z}}function Q6(Z,z,$){let{sub:J,rest:Y}=X6(z);if(!J)return $.appendsArgs?I("unclassifiable"):T;if(J.opaque)return I("unclassifiable");let X=J.value;if((Z==="pr"?Z6:Z==="issue"?$6:Z==="release"?J6:Z==="discussion"?z6:new Set).has(X))return $.debug?I("debug-traffic"):T;if($.appendsArgs&&!(Z==="project"&&X!=="item-list"))return I("unclassifiable");switch(Z){case"pr":if(X==="view")return X0(Y,"pr view",p0,$,!0);if(X==="list"||X==="ls")return YZ(Y,"pr list",p0,$);if(X==="status")return YZ(Y,"pr status",p0,$);if(X==="checks")return Y6(Y,$);if(X==="diff"){let H=TZ(Y,GZ["pr diff"]);if(w(H,"-h","--help"))return T;if($.debug)return I("debug-traffic");return w(H,"--patch")?I("composite-other"):T}return I("unclassifiable");case"issue":if(X==="view")return X0(Y,"issue view",c0,$,!0);if(X==="list"||X==="ls")return YZ(Y,"issue list",c0,$);if(X==="status")return YZ(Y,"issue status",c0,$);return I("unclassifiable");case"release":if(X==="view")return X0(Y,"release view",M3,$,!1);if(X==="list"||X==="ls")return YZ(Y,"release list",M3,$);return I("unclassifiable");case"discussion":if(X==="view")return X0(Y,"discussion view",V3,$,!0);if(X==="list"||X==="ls")return YZ(Y,"discussion list",V3,$);return I("unclassifiable");case"search":if(X==="prs"||X==="issues")return YZ(Y,"search",o5,$);if(X==="commits")return YZ(Y,"search",a5,$);if(X==="code"||X==="repos")return $.debug?I("debug-traffic"):T;return I("unclassifiable");case"project":{if($.debug)return I("debug-traffic");if(X!=="item-list")return T;let H=TZ(Y,GZ["project item-list"]);if(w(H,"-h","--help"))return T;let K=XZ(H,"--format");if(K.some((B)=>!B.value||B.value.opaque))return I("unclassifiable");if(K.every((B)=>B.value.value!=="json"))return T;return t0(H)?T:I("composite-other")}}return I("unclassifiable")}var W3=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function K6(Z){let z=Z.value.trim(),$=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(z);if($){let X=$[1].toLowerCase(),Q=$[2]??"/";if(X==="api.github.com"||/^api\./.test(X))z=Q;else if(/^\/api\/v3(?:\/|$)/i.test(Q))z=Q.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(Q))z="graphql";else return null}z=z.replace(/[?#].*$/,"");let J=[],Y=[];for(let X of z.split("/")){let Q;try{Q=decodeURIComponent(X)}catch{return null}for(let H of Q.split("/")){if(H===""||H===".")continue;if(H===".."){J.pop(),Y.pop();continue}J.push(H.toLowerCase()),Y.push(Z.opaque&&/[$`]/.test(H)||/[*?[]/.test(H)||j3(H))}}return{segments:J,opaque:Y}}function H6(Z){let z=K6(Z);if(!z)return{kind:"unclassifiable",segments:[]};let{segments:$,opaque:J}=z,Y=(K)=>({kind:K,segments:$});if($.length===1&&$[0]==="graphql")return Y("graphql");if($.length===0)return Y(Z.opaque?"unclassifiable":"other");if(J[0])return Y("unclassifiable");let X,Q=[];if($[0]==="repos")X=$.slice(3),Q=J.slice(3);else if($[0]==="repositories")X=$.slice(2),Q=J.slice(2);if(X){if(($[0]==="repos"?J.slice(1,3):J.slice(1,2)).some(Boolean)){let B=J.findIndex(Boolean),M=$.findIndex((V,G)=>G>B&&!J[G]&&B6.has(V));return Y(M<0?"unclassifiable":G3($.slice(M),J.slice(M)))}return Y(G3(X,Q))}let H=$[0];if(H==="issues")return Y("sensitive");if(H==="user"&&$[1]==="issues")return Y("sensitive");if(H==="orgs"&&$[2]==="issues")return Y("sensitive");if(H==="search")return Y($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&J[1]?"unclassifiable":"other");if(H==="events"||H==="networks")return Y("sensitive");if((H==="users"||H==="orgs")&&$.slice(2).some((K)=>K==="events"||K==="received_events"||K==="discussions"))return Y("sensitive");if((H==="users"||H==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return Y("sensitive");if(H==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||H==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return Y("sensitive");if(H==="teams"&&$.includes("discussions"))return Y("sensitive");if(H==="projects"&&$.includes("cards"))return Y("sensitive");if(J.some(Boolean))return Y($.some((K)=>K==="events"||K==="discussions"||K==="issues")?"sensitive":"unclassifiable");return Y("other")}var B6=new Set([...W3,"branches","git","actions","hooks","zipball","tarball"]);function G3(Z,z){let[$,J]=Z;if($===void 0)return"other";if(z[0])return"unclassifiable";if($==="issues"&&/^\d+$/.test(J??"")&&Z[2]==="labels")return"other";if(W3.has($))return"sensitive";if($==="branches"){if(Z.length===1||Z.slice(1).some((Y)=>Y==="protection")||Z[Z.length-1]==="rename")return"other";return z.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if($==="git")return J===void 0||J==="commits"||J==="tags"?"sensitive":z[1]?"unclassifiable":"other";if($==="actions"){if(J===void 0)return"sensitive";if(z[1])return"unclassifiable";if(J==="runs"||J==="jobs"){if(Z[Z.length-1]==="logs"&&Z.length>=4&&!z.some(Boolean))return"download";return"sensitive"}if(J==="workflows"&&Z[3]==="runs")return"sensitive";if(J==="artifacts"&&Z.length===4)return"download";return"other"}if($==="hooks"&&Z[2]==="deliveries"&&Z[3]!==void 0)return"sensitive";if($==="zipball"||$==="tarball")return"download";return"other"}function M6(Z,z){if(z[0]!=="repos"||z.length<5)return!1;let $=z.slice(3),J=(X)=>/^\d+$/.test($[X]??""),Y=(...X)=>$.length===X.length&&X.every((Q,H)=>typeof Q==="number"?J(H):$[H]===Q);if(Z==="DELETE")return Y("issues","comments",0)||Y("pulls","comments",0)||Y("comments",0)||Y("issues","comments",0,"reactions",0)||Y("pulls","comments",0,"reactions",0)||Y("issues",0,"reactions",0)||Y("issues",0,"labels")||$.length===4&&$[0]==="issues"&&J(1)&&$[2]==="labels"||Y("releases",0)||Y("releases","assets",0)||Y("actions","runs",0)||Y("actions","runs",0,"logs")||Y("deployments",0)||Y("milestones",0)||Y("issues",0,"lock");if(Z==="POST")return $.length===4&&$[0]==="actions"&&$[1]==="runs"&&J(2)&&["rerun","rerun-failed-jobs","cancel","force-cancel","approve"].includes($[3])||Y("actions","jobs",0,"rerun")||Y("issues",0,"labels");if(Z==="PUT")return Y("pulls",0,"merge")||Y("pulls",0,"update-branch")||Y("issues",0,"labels")||Y("issues",0,"lock");if(Z==="GET")return Y("pulls",0,"merge");return!1}function V6(Z){if(Z[0]!=="repos"||Z.length!==5||!/^\d+$/.test(Z[4]))return;if(Z[3]==="pulls")return new Set(["commits","comments","review_comments"]);if(Z[3]==="issues")return new Set(["comments"]);return}var G6=new Set(["body","bodyText","bodyHTML","bodyUrl","bodyResourcePath","comments","reviews","latestReviews","latestOpinionatedReviews","reviewThreads","url","permalink","summary","text","description","message","messageBody","messageHeadline","commitBody","commitHeadline","annotations","rawDetails","note","diff","readme","payload"]),U6=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function j6(Z){let z=[],$=0;while($<Z.length){let J=Z[$];if(/[\s,]/.test(J)){$++;continue}if(J==="#"){let Q=Z.indexOf(`
|
|
32
|
-
|
|
33
|
-
`)
|
|
34
|
-
`).replace(/%s/g,()=>
|
|
35
|
-
`,
|
|
36
|
-
`,
|
|
37
|
-
`,
|
|
1
|
+
var{defineProperty:bt,getOwnPropertyNames:Rr,getOwnPropertyDescriptor:Ar}=Object,Tr=Object.prototype.hasOwnProperty;function $r(e){return this[e]}var Cr=(e)=>{var r=(fn??=new WeakMap).get(e),t;if(r)return r;if(r=bt({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of Rr(e))if(!Tr.call(r,n))bt(r,n,{get:$r.bind(e,n),enumerable:!(t=Ar(e,n))||t.enumerable})}return fn.set(e,r),r},fn;var Ir=(e)=>e;function Pr(e,r){this[e]=Ir.bind(null,r)}var Wr=(e,r)=>{for(var t in r)bt(e,t,{get:r[t],enumerable:!0,configurable:!0,set:Pr.bind(r,t)})};var qo={};Wr(qo,{abi:()=>Bo,evaluate:()=>Go,version:()=>jo});module.exports=Cr(qo);var dt=require("node:os"),sn=require("node:path");var L=require("node:path");var C=require("node:path"),_=require("node:fs"),dn=require("node:child_process"),hn={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 Te(e){return e===0||e===process.getuid?.()}function Ve(e,r=!1){let t=e;for(let n=0;n<32;n++){if(!C.isAbsolute(t)||t.length>4096||!$e("/"))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=C.dirname(o);continue}let c=C.join(o,u),f=_.lstatSync(c);if(r&&c==="/bin"&&f.isSymbolicLink()&&f.uid===0){let d=_.realpathSync(c);if(!$e(d))return!1;o=d;continue}if(!f.isDirectory()||!Te(f.uid)||f.mode&18)return!1;o=c}let a=C.join(o,i),l=_.lstatSync(a);if(!Te(l.uid))return!1;if(l.isSymbolicLink()){let u=_.readlinkSync(a);t=C.isAbsolute(u)?u:o+"/"+u;continue}return l.isFile()&&Boolean(l.mode&73)&&!(l.mode&18)}return!1}function Nr(e){if(!C.isAbsolute(e)||C.resolve(e)!==(e.replace(/\/+$/,"")||"/"))return!1;for(let r=C.resolve(e);;r=C.dirname(r)){try{return _.lstatSync(r),$e(r)}catch(t){if(t.code!=="ENOENT")return!1}if(C.dirname(r)===r)return!1}}function Dr(e,r){let t=_.openSync(e,_.constants.O_RDONLY|_.constants.O_NONBLOCK|_.constants.O_NOFOLLOW),n;try{if(!_.fstatSync(t).isFile())return!1;let i=Buffer.alloc(256),o=_.readSync(t,i,0,i.length,0);n=i.subarray(0,o).toString("utf8").split(`
|
|
2
|
+
`)[0]}finally{_.closeSync(t)}let s=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(n);if(s&&s[1]!=="/usr/bin/env")return Ve(s[1],!0);if(n!=="#!/usr/bin/env bun"||!Ve("/usr/bin/env",!0))return!1;for(let i of r.split(":").slice(0,64)){if(!Nr(i))return!1;let o=C.resolve(i,"bun");try{if(!_.statSync(o).isFile())continue;_.accessSync(o,_.constants.X_OK)}catch{continue}return Ve(o,!0)}return!1}function $e(e){let r=e;for(;;){let t=_.lstatSync(r);if(!t.isDirectory()||!Te(t.uid)||(t.mode&18)!==0)return!1;let n=C.dirname(r);if(n===r)return!0;r=n}}function Ce(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(!C.isAbsolute(i)||Date.now()>=t)continue;let o=C.resolve(i,"trash");try{let a=_.statSync(o);if(!a.isFile()||!Te(a.uid)||(a.mode&73)===0||(a.mode&18)!==0){s("unsafe_executable");continue}let l=_.realpathSync(o);if(!$e(C.resolve(i))||!$e(C.dirname(l))){s("unsafe_directory");continue}if(!Ve(o)){s("unsafe_directory");continue}let u=C.resolve(C.dirname(l),"../.."),c=C.join(u,"package.json"),f=_.statSync(c);if(!f.isFile()||!Te(f.uid)||f.size>16384||(f.mode&18)!==0||_.lstatSync(c).isSymbolicLink()){s("unsafe_manifest");continue}let d=JSON.parse(_.readFileSync(c,"utf8"));if(d.name!=="@hasna/trash"||typeof d.version!=="string"||typeof d.bin?.trash!=="string"||_.realpathSync(C.resolve(u,d.bin.trash))!==l){s("unrecognized_package");continue}try{if(!Dr(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=dn.spawnSync(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 Ze(e=process.env){let r=Ce(e);return r.ok?r.path:null}function me(e){let r=e.tool_input?.command;return typeof r==="string"?r:""}var pn=["/","/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 Pe=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,X=(e)=>e.split("/").pop()??"";function Ke(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 St=64;function gn(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 Lr(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>St)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 Hr(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=gn(e,n+1);else if(s==="{"){if(++t>St)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=gn(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?Lr(e.slice(n+1,u)):null;if(f==="overflow")return f;if(f)return{open:n,close:u,parts:f};break}}}}return null}function le(e){if(e.length>4096&&e.includes("{"))return null;let r=Hr(e);if(r===null)return[e];if(r==="overflow")return null;let t=[];for(let n of r.parts){let s=le(e.slice(0,r.open)+n+e.slice(r.close+1));if(s===null||t.push(...s)>St)return null}return t}var g={arg:"none"},w={arg:"value"},Ie={arg:"optional"},J={arg:"none",effect:"lookup"},v={arg:"none",effect:"refuse"},te={help:v,version:v},Mr=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,wt={timeout:{short:{k:w,s:w,v:g},long:{"kill-after":w,signal:w,verbose:g,foreground:g,"preserve-status":g,...te},positionals:[Mr]},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,...te},env:!0},nice:{short:{n:w},long:{adjustment:w,...te},numericOption:!0},nohup:{short:{},long:{...te}},command:{short:{p:g,v:J,V:J},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,...te}},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,...te}},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,...te}},setsid:{short:{c:g,f:g,w:g,h:v,V:v},long:{ctty:g,fork:g,wait:g,...te}}},Fr=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function Br(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&&Pe.test(r[t].text);t++)if(r[t].opaque)return null}return t}function ae(e,r=wt){let t=0;while(t<e.length&&(Pe.test(e[t].text)||Fr.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,X(e[t].text))?r[X(e[t].text)]:void 0;if(!s)return{index:t};let i=Br(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 ne={on:!1};function ue(e,r){if(!e.includes("\\")||!e.includes('"'))return;let t=ne.on;ne.on=!0;try{return r()}finally{ne.on=t}}var kt=(e)=>e.split("/").pop()??"",xt={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}},wn=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,Gr=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),qr=new Set(["ssh","scp","sftp"]),zr=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),mn=new Set(["proxycommand","localcommand","knownhostscommand"]),Ur=/(?:`|\$\()|\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/,Vr=/[|>]|\b(?:system|getline|close|fflush|print\w*\s*>>?)/;function yn(e){if(jr(e.text))return!1;if(e.kind==="awk")return!Vr.test(e.text);if(e.kind==="c-interp")return!Ur.test(e.text);return!1}function Zr(e,r,t,n){let s=xt[e]??(wn.test(e)?xt[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 Kr(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 Xr(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 Yr(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 Qr(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}=Yr(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(mn.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(!zr.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(mn.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 Jr(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 es=/^(?:true|false|yes|no|on|off|1|0|)$/i,ts=[/^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 xn(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&&es.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(ts.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 bn(e){return/[$\x60]/.test(e)||["","x","/x","!x"].some((r)=>xn(e,r).kind!=="harmless")}var ns=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"]),rs=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function ss(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 is(e,r,t){let n=[],s=!1,i=(u,c,f=!0)=>{if(!f||/[$\x60]/.test(u)){s=!0;return}let d=xn(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(bn(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)||bn(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(ns.has(f))if(h)s=!0;else n.push({text:d,kind:"shell"});else if(rs.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:ss(d);if(p===null)s=!0;else for(let[m,A]of p)i(m,A??"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 We(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]!==`
|
|
3
|
+
`||ne.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 Sn(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 os=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]),ls=new Set(["--rcfile","--init-file"]),be=(e)=>e.replace(/\$'(?:[^'\\]|\\[\s\S])*'/g,(r)=>r.replace(/\\[\s\S]/g,(t)=>t==="\\'"?"\\x27":t));function De(e,r,t=We){if(r<0||r>=e.length)return null;let n=kt(t(e[r])??"");if(n==="eval"){let a=r+1;if(We(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=We(l[0]);return u!==null&&Sn(u)?{program:u,literal:!0}:{program:u,literal:!1}}if(!os.has(n))return null;let s=!1,i=r+1;for(;i<e.length;i++){let a=We(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(ls.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=We(e[i]);return o!==null&&Sn(o)?{program:o,literal:!0}:{program:o,literal:!1}}function as(e,r,t){let n=us(e,r,t);if(n===null)return{programs:[],unresolved:!0};let s=new Set;for(let{scripts:i,mayFail:o}of n){let a=cs(i.join(`
|
|
4
|
+
`));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 yt="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 us(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("="),A=(m<0?d:d.slice(0,m)).slice(2),I=yt.filter((V)=>V.startsWith(A)),D=yt.includes(A)?A:I.length===1?I[0]:"";if(yt.indexOf(D)<15){if(!D)return null;continue}if(h=D[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 A=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(A===void 0)return null;o=f+1}}else if(A===""||A?.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 cs(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(`
|
|
5
|
+
`,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===`
|
|
6
|
+
`)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]===`
|
|
7
|
+
`)return!1;if(e[d]==="["&&":.=".includes(e[d+1]||`
|
|
8
|
+
`)){let h=e.indexOf(e[d+1]+"]",d+2);if(h<0||e.slice(d,h).includes(`
|
|
9
|
+
`))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===`
|
|
10
|
+
`||!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]!==`
|
|
11
|
+
`;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===`
|
|
12
|
+
`||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 fs=new Set(["-exec","-execdir","-ok","-okdir"]),ds=new Set(["-exec","-execdir"]),hs=new Set("0oprtx"),ps=new Set("adEILnPsJRS"),gs=new Set("eil"),Xe={"--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 ms(e){if(Object.hasOwn(Xe,e))return Xe[e];let r=Object.keys(Xe).filter((t)=>t.startsWith(e));return r.length===1?Xe[r[0]]:null}function Ne(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=ms(a<0?s:s.slice(0,a));if(l===null){if(n>=4)return[];return[...Ne(e,r+1,t,n+1),...Ne(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(hs.has(l))continue;if(gs.has(l))break;if(ps.has(l)){i=a===s.length-1;break}o=!0;break}if(o){if(n>=4)return[];return[...Ne(e,r+1,t,n+1),...Ne(e,r+2,t,n+1)]}r+=i?2:1}while(r<e.length&&t(r))r++;return r<e.length?[r]:[]}function Le(e,r,t=()=>!1){if(r<0||r>=e.length)return[];let n=kt(e[r]);if(n==="xargs")return[...new Set(Ne(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)||!fs.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]==="{}"&&ds.has(e[i]))break}if(o<a)s.push({start:o,end:a});i=a}return s}function He(e,r,t){if(r<0||r>=e.length)return null;let n=kt(e[r]);if(n==="deno"){let s=Kr(e,r,t);if(s)return s}if(Object.hasOwn(xt,n)||wn.test(n))return Zr(n,e,r,t);if(Gr.has(n))return Xr(e,r,t);if(qr.has(n))return Qr(e,r,t);if(n==="rsync")return Jr(e,r,t);if(n==="git")return is(e,r,t);if(n==="sed")return as(e,r,t);return null}var Ss=600000,ws="Delete via trash guard (rm intercepted and made recoverable)",ys=[".hasna/repos/clones","workspace/repos"],xs=[".hasna",".ssh",".aws"],vt={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."},ks=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env"]),vs={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"]},_s={timeout:1},Es={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:J,l:J,v:J,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:J,group:w,"set-home":g,help:v,host:v,login:g,"remove-timestamp":v,"reset-timestamp":g,list:J,"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:J},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]+$/]}},Os={...wt,...Es},Cn=new Set(["-c","--command"]),Rs=new Set(["busybox","toybox"]),Ot=new Set(["rm","rmdir","unlink","shred"]),As=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]),Ts=new Set(["-C","-c","--git-dir","--work-tree","--namespace","--exec-path","--config-env"]),$s=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/;function Y(e){return $s.test(P(e))}function Fe(e){return e.map((r)=>r.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var In=/^[A-Za-z_][A-Za-z0-9_]*=/;function Qe(e){let r=e.lastIndexOf("/");return r>=0?e.slice(r+1):e}var kn={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
|
|
13
|
+
`,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function Cs(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(kn,s))t+=kn[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 W(e){return Pn(e,!0)}function Pn(e,r){let t="",n=0;while(n<e.length){let s=e[n];if(r&&s==="$"&&e[n+1]==="'"){let i=Cs(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+=ne.on||/[$`"\\]/.test(i)?i:i===`
|
|
14
|
+
`?"":`\\${i}`,n+=2;continue}t+=e[n],n++}n++;continue}t+=s,n++}return t}function Je(e){if(Ke(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==="["&&Is(e,t+1,"]"))return!0}return!1}function Is(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 Ps(e){if(!Je(e))return!1;let r=le(e);return r===null||r.some((t)=>W(t).split(/[^A-Za-z0-9_]+/).some((n)=>Ot.has(n)))}function we(e){return Qe(W(e))}var Wn={deep:!0};function Rt(e,r){return e.replace(/\\([$`\\"])/g,(t,n)=>n==='"'&&!r?t:n)}function Ws(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=Be(e,s);if(o<0)return null;n.push(Rt(e.slice(s+1,o-1),!0)),s=o;continue}if(i==="$"&&e[s+1]==="("){let o=ce(e,s+1);if(o<0)return null;n.push(e.slice(s+2,o-1)),s=o;continue}s++}return n}function Ns(e){let r=[],t=0;while(t<e.length){let n=e[t];if(n==="\\"){t+=2;continue}if(n==="`"){let s=Be(e,t);if(s<0)return null;r.push(Rt(e.slice(t+1,s-1),!1)),t=s;continue}if(n==="$"&&e[t+1]==="("){let s=ce(e,t+1);if(s<0)return null;r.push(e.slice(t+2,s-1)),t=s;continue}t++}return r}function vn(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(`
|
|
15
|
+
`,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=Ns(a);if(!l)return-1;n.push(...l)}if(s<=e.length){let l=e.indexOf(`
|
|
16
|
+
`,s);s=(l===-1?e.length:l)+1}}return Math.min(s-1,e.length)}function Nn(e,r){let t=e.indexOf("'",r+1);return t===-1?-1:t+1}function Be(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 Dn(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=Be(e,t);if(s<0)return-1;t=s;continue}if(n==="$"&&e[t+1]==="("){let s=ce(e,t+1);if(s<0)return-1;t=s;continue}t++}return-1}function xe(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 et(e,r,t){let n=r+1;for(let s of t)for(;;){if(n>e.length)return-1;let i=e.indexOf(`
|
|
17
|
+
`,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 ce(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=Nn(e,i);if(l<0)return-1;i=l;continue}if(a==='"'){let l=Dn(e,i);if(l<0)return-1;i=l;continue}if(a==="`"){let l=Be(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=xe(e,i);if(!l)return-1;o.push(l),i=l.end;continue}if(a===`
|
|
18
|
+
`&&o.length>0){let l=et(e,i,o);if(l<0)return-1;o=[],i=l;continue}if(!n&&a==="#"&&/[\s;&|(]/.test(e[i-1])){let l=e.indexOf(`
|
|
19
|
+
`,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 N(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},A=(k)=>Nn(e,k),I=(k)=>Be(e,k),D=(k)=>ce(e,k),V=(k)=>Dn(e,k);while(d<h){let k=e[d];if(k===" "||k==="\t"||k==="\r"){p(d),d++;continue}if(k===`
|
|
20
|
+
`){if(m(d),l.length>0){let b=vn(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 T=e.indexOf(`
|
|
21
|
+
`,d+2+b[0].length);if(T===-1){f=!1,d=h;continue}let G=e.slice(T+1),q=Ds(G,b[2]);if(q===-1){f=!1,d=h;continue}p(d),d=T+1+q+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=A(d);if(b<0)f=!1,d=h;else d=b;continue}if(k==='"'){if(u<0)u=d;let b=V(d),T=b<0||!t?[]:Ws(e,d,b);if(b<0||!T)f=!1,d=h;else s.push(...T),d=b;continue}if(k==="`"){if(u<0)u=d;let b=I(d);if(b<0)f=!1,d=h;else{let T=e.slice(d+1,b-1);s.push(t?Rt(T,!1):T),d=b}continue}if(k==="$"&&e[d+1]==="("){if(u<0)u=d;let b=D(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&&vn(e,h,l,s)<0)f=!1;return{segments:n,trustworthy:f,substitutions:s}}function Ds(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]===`
|
|
22
|
+
`,i=n+r.length,o=i===e.length||e[i]===`
|
|
23
|
+
`||e[i]==="\r";if(s&&o)return n;t=n+1}return-1}function P(e){return Pn(e,!1)}function j(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=W(n);if(In.test(s)&&!s.startsWith("-")){r++;continue}if(As.has(s)){r++;continue}let i=Qe(s);if(i==="command")for(let a of e.words.filter((l,u)=>u>r&&!e.redirects.has(u))){let l=W(a.text);if(l==="--"||!l.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(l))return-1}let o=vs[i];if(o){let a=r;r++;while(r<e.words.length){if(e.redirects.has(r)){r++;continue}let u=W(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=_s[i]??0;while(l>0&&r<e.words.length){let u=W(e.words[r].text);if(u.startsWith("-")&&u!=="-")break;r++,l--}continue}return r}return-1}function Ls(e,r){let t=[],n=!1;for(let s=r+1;s<e.words.length;s++){if(e.redirects.has(s))continue;let i=P(e.words[s].text);if(!n){if(i==="--"){n=!0;continue}if(i.startsWith("-")&&i!=="-")continue}t.push(e.words[s])}return t}function At(e){return ys.map((r)=>L.join(e,...r.split("/")))}function Hs(e,r){if(e==="~"||e==="$HOME"||e==="${HOME}")return r;if(e.startsWith("~/"))return L.join(r,e.slice(2));if(e.startsWith("$HOME/"))return L.join(r,e.slice(6));if(e.startsWith("${HOME}/"))return L.join(r,e.slice(8));return e}function Ye(e,r,t){let n=P(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=Hs(n,t);if(a===n)return null;n=a}let o=(L.isAbsolute(n)?L.normalize(n):L.resolve(r,n)).replace(/\/+$/,"");return o===""?"/":o}function re(e,r){return e===r||e.startsWith(`${r}${L.sep}`)}var Ms=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/,Fs=!1,Bs=/^[A-Za-z0-9._@+-]{1,128}$/,js=512;function Se(e){return`'${e.replace(/[\u0000-\u001f\u007f-\u009f]/g,"?").slice(0,js).replace(/'/g,"'\\''")}'`}function _n(e){return Bs.test(e)?`\`${e}\``:"a name that is not a plain identifier"}function Gs(e,r){let t=`${L.join(r,".hasna","scratchpad","scratch")}${L.sep}`;if(!e.startsWith(t))return null;let[n,s]=e.slice(t.length).split(L.sep);if(!n)return{content:!1,reason:"the scratch root itself holds every session, not one session's content"};if(n.endsWith(".")||!Ms.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 Fs?{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) — 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 qs(e,r){if(e===r)return`${Se(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 pn){if(e!==t&&!re(t,e))continue;return t==="/"?`${Se(e)} is the filesystem root, which is never deleted.`:`${Se(e)} is the system root \`${t}\` (or an ancestor of it), which is never deleted or trashed.`}for(let t of xs){let n=L.join(r,t),s=re(e,n);if(!s&&!re(n,e))continue;if(t===".hasna"&&s){let i=Gs(e,r);if(i?.content===!0)continue;if(i&&i.content===!1)return`${Se(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?`${Se(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.`:`${Se(e)} contains the protected \`~/${t}\` tree, which is never deleted or trashed. Delete a specific file or directory inside it instead.`}return null}function zs(e,r,t){let n=At(t);if(n.some((s)=>re(r,s)))return!0;return e.some((s)=>s!==null&&n.some((i)=>re(s,i)))}var En=new WeakMap;function Us(e){let r=En.get(e);if(r)return r;let t=e.words.map((o)=>W(o.text)),n=t.findIndex((o)=>o==="-exec"||o==="-execdir"||o==="-ok"||o==="-okdir"),s=-1;e.words.forEach((o,a)=>{if(Cn.has(P(o.text)))s=a});let i={findDelete:t.includes("-delete"),findExecDelete:n>=0&&t.slice(n).some((o)=>Ot.has(Qe(o))),namesDelete:t.some((o)=>Ot.has(Qe(o))),lastFlockCommand:s,textMention:Y(ei(e)),envMention:Y(Fe(e.words.map((o)=>P(o.text)))),bodiesMention:Y((e.heredocs??[]).join(`
|
|
24
|
+
`))};return En.set(e,i),i}var Vs=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]);function Zs(e,r){if(!Vs.has(we(e.words[r].text)))return!1;for(let t=r+1;t<e.words.length;t++){if(e.redirects.has(t))continue;let n=P(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 _t=(e)=>e.kind==="rm"||e.kind==="refuse",Ks="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.",Xs="This delete's brace pattern names more paths than this hook will check. Run the delete on explicit paths with `rm -- <path> …`, which is redirected into trash.",Ys="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.",Qs="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 Tt(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:W(i),opaque:Je(i)}}),n=ae(t,Os);if(n===null)return null;return n.index<0?-1:r[n.index]}function Et(e,r,t,n){let s=we(e.words[r].text);if(s==="cd"){let l=e.words[r+1];if(!l)return{kind:"none"};return{kind:"cd",cwd:Ye(l.text,t,n.home)??n.cwd}}if(Object.hasOwn(vt,s))return{kind:"refuse",reason:vt[s]};let i=Ln(e,r,t,n);if(i)return i;if(s==="rm"){let l=Ls(e,r);if(l.length===0)return{kind:"none"};let u={word:e.words[r],operands:l},c=At(n.home),f=(p)=>p!==null&&c.some((m)=>re(p,m)),d=[],h=[];for(let p of l){let m=Ye(p.text,t,n.home);if(d.push(m),!p.text.includes("{"))continue;let A=le(p.text);if(A===null)return{kind:"refuse",reason:Xs};for(let I of A){let D=Ye(I,t,n.home);if(D===null)continue;if(f(D)&&!f(m))return{kind:"refuse",reason:Ys};h.push(D)}}if(zs(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=qs(p,n.home);if(m)return{kind:"rm",hit:u,handoff:!1,protectedReason:m}}return{kind:"rm",hit:u,handoff:!1,protectedReason:null}}if(Rs.has(s)){let l=e.words.findIndex((c,f)=>f>r&&!P(c.text).startsWith("-")),u=l>=0?we(e.words[l].text):"";if(u==="rm"||Object.hasOwn(vt,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=$t(e,r);if(l==="rm"||l==="clean"){if(!(l==="rm"?ti(e,r):Hn(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=Us(e);if(s==="find"){if(o.findDelete)return{kind:"refuse",reason:"`find -delete` deletes files irrecoverably and is refused. List the paths first (`find … -print`), then remove them explicitly with `rm -- <path>` so the delete is redirected into trash."};if(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> …` instead, which is redirected into trash."};let a=s==="flock"?o.lastFlockCommand>r:Cn.has(s);if(ks.has(s)||a){let l=Zs(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 Ln(e,r,t,n,s={segment:e,index:r},i=0){let o=we(e.words[r].text);for(let f of Le(e.words.map((d)=>W(d.text)),r,(d)=>e.redirects.has(d))){if(i>=8)return Me(s.segment,s.index,t,n.home)?{kind:"refuse",reason:Js}: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=Tt(d);for(let p of new Set([j(d),h??-1])){if(p<0)continue;let m=Ln(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:De(a.map(({word:f})=>f.text),l,W);if(u&&!u.literal&&(Me(e,r,t,n.home)||Me(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 \`$'…'\` 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=He(e.words.map((f)=>W(f.text)),r,(f)=>f>=0&&f<e.words.length&&(e.redirects.has(f)||Je(e.words[f].text)));if(!c||!(Me(e,r,t,n.home)||Me(s.segment,s.index,t,n.home)))return null;if(!c.unresolved&&!c.programs.some((f)=>Y(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 Js="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 Me(e,r,t,n){let s=At(n),i=(o)=>o!==null&&s.some((a)=>re(o,a));if(s.some((o)=>re(t,o)))return!0;for(let o=r+1;o<e.words.length;o++){if(e.redirects.has(o))continue;if(i(Ye(e.words[o].text,t,n)))return!0}return!1}function ye(e,r){let t={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},n=N(e,Wn);t.trustworthy=n.trustworthy;let s={cwd:r.cwd,home:r.home,depth:r.depth??0,bodiesMention:Y(n.segments.flatMap((l)=>l.heredocs??[]).join(`
|
|
25
|
+
`))};if(!n.trustworthy){let l=be(e);return l===e?t:{...ye(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=j(l),c=Tt(l),f=u<0?{kind:"none"}:Et(l,u,a,s);if(f.kind!=="cd")o(f);let d=(h)=>h!==null&&h>=0&&Je(l.words[h].text);if(c===null||d(u)||d(c)){if(l.words.some((h,p)=>!l.redirects.has(p)&&(_t(Et(l,p,a,s))||Ps(h.text))))i.push({reason:Ks})}else if(c>=0&&c!==u){let h=Et(l,c,a,s);if(_t(h))if(_t(f))i.push({reason:Qs});else o(h,i)}if(f.kind==="cd")a=f.cwd}if(s.depth<3)for(let l of n.substitutions){let u=ye(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&&Y(l)){t.refusals.push({reason:"This command runs a delete inside a command substitution `$(…)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(n.substitutions.some((l)=>Y(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 ei(e){return e.words.map((r)=>r.text).join(" ")}function $t(e,r){let t=r+1;while(t<e.words.length){let n=P(e.words[t].text);if(!n.startsWith("-"))return n;if(t++,Ts.has(n))t++}return null}function ti(e,r){if(e.words.slice(r+1).map((n)=>P(n.text)).includes("--cached"))return!0;return Hn(e,r)}function Hn(e,r){let t=e.words.slice(r+1).map((n)=>P(n.text));return t.includes("-n")||t.includes("--dry-run")}function On(e){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(e))return e;return`'${e.replace(/'/g,"'\\''")}'`}function ni(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(On).join(" "):`${On(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 ri(e,r,t,n,s){if(!r||r===e)return!1;if(t.length===0)return!1;let i=ye(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=ws;if(typeof t.timeout!=="number"||!Number.isFinite(t.timeout)||t.timeout<=0)t.timeout=Ss;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 ii(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 ri(r,e.command,t,n,s)}function oi(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 N(e,Wn).segments.some((n)=>{let s=Tt(n);return[j(n),...s===null?[]:[s]].some((i)=>{if(n.words.slice(0,i<0?n.words.length:i).some((l)=>In.test(P(l.text))||r.has(we(l.text))))return!0;if(i<0)return!1;let a=n.words[i];return r.has(we(a.text))||/^\s*\(\s*\)\s*\{/.test(e.slice(a.end))})})}function U(e){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e}}}function li(e){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:e}}}function ai(e){try{if(e.inspectTrash){let r=e.inspectTrash();return r.ok?{path:r.path,error:null}:{path:null,error:`${r.code}: ${hn[r.code]}`}}return{path:e.findTrash(),error:null}}catch(r){return{path:null,error:r instanceof Error?r.message:String(r)}}}var ui="[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.",Rn="[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 An(e,r){if(e.refusals.length>0)return U(`[trash-guard] ${e.refusals[0].reason}`);if(e.protectedHits.length>0)return U(`[trash-guard] ${e.protectedHits[0].reason}`);if(!e.trustworthy)return Y(r)?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(e.rmHits.length===0){if(e.handoffHits.some((t)=>t.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(e.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 Mn(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 U("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(p))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(e.tool_name!=="Bash")return{continue:!0};if(typeof e.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 n=me(e);if(!n.trim())return{continue:!0};let s=()=>ye(n,{cwd:r.cwd,home:r.home}),i=(p)=>p.rmHits.map((m)=>m.word.start).join(),o=(p)=>p()||!!ue(n,p),a=s(),l=An(a,n),u=ue(n,()=>{let p=s();return{result:p,verdict:An(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 U(Rn)}if(l)return l;let c=ai(r);if(c.error!==null)return U(`[trash-guard] The guard could not resolve the \`trash\` binary (${c.error}), so this \`rm\` cannot be redirected into a recoverable delete — and an unrecoverable delete is never allowed, so the command is refused rather than run. Fix the environment (PATH, permissions) and re-run the same command.`);if(c.path===null)return U(ui);let f=c.path;if(r.execution&&o(()=>oi(n)))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 d=ni(n,a.rmHits,f,r.execution),h=si(e.tool_input,d);if(r.execution)h.hasna_execution="hasna.hooks.execution.v1";if(o(()=>!ii(h,n,a.rmHits,r.cwd,r.home)))return U(Rn);return li(h)}var H=require("node:fs"),Dt=require("node:os"),E=require("node:path");var ci=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),fi=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),di=["hasna","hasnaxyz","hasna-products"],je="workspace-repos-guard";function hi(e){return E.join(e,".hasna","repos","clones")}function pi(e){return E.join(e,"workspace","repos")}function Kn(e){return[hi(e),pi(e)]}function gi(e){return E.join(e,".hasna","hooks","config","workspace-repos-guard-orgs")}var mi=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function Ct(e){let r=process.getuid?.();return r!==void 0&&(e.uid===0||e.uid===r)&&(e.mode&18)===0}function bi(e){let r=gi(e),t;try{let s=H.openSync(r,H.constants.O_RDONLY|H.constants.O_NOFOLLOW);try{let o=H.fstatSync(s);if(!o.isFile()||!Ct(o)||o.size>4096)return null;t=H.readFileSync(s,"utf8")}finally{H.closeSync(s)}let i=E.normalize(e);for(let o=E.dirname(r);o!==i;o=E.dirname(o)){let a=H.lstatSync(o);if(!a.isDirectory()||!Ct(a)||o===E.dirname(o))return null}if(!Ct(H.statSync(i)))return null}catch{return null}let n=t.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return n.length>0&&n.every((s)=>mi.test(s))?new Set(n):null}function Si(e=process.env,r=Dt.homedir()){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 bi(r)??new Set(di)}function It(e,r,t,n){if(n==="read")return{blocked:!1};let s=E.relative(r,e);if(s===""){if(n==="delete")return{blocked:!0,reason:`[${je}] delete of the protected repo-checkout root is forbidden: ${r}`};return{blocked:!0,reason:`[${je}] writes directly to the protected repo-checkout root are forbidden: ${r}`}}if(s.startsWith(`..${E.sep}`)||s===".."||E.isAbsolute(s))return{blocked:!1};let i=s.split(E.sep).filter(Boolean);if(n==="delete")return{blocked:!0,reason:`[${je}] delete under the protected repo-checkout root (${r}) is forbidden at any depth: ${e}`};if(i.length<=1)return{blocked:!0,reason:`[${je}] 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:`[${je}] '${o}' is not an allowed GitHub org under the protected repo-checkout root (${r}); allowed: ${[...t].join(", ")}: ${e}`};return{blocked:!1}}var Xn=/\b(?:-o|--output|-O|--output-document|-out)\b/,wi=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,yi=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function Yn(e){return e.replace(wi," ")}function xi(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 ki(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)||Ke(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===`
|
|
26
|
+
`&&!ne.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 Pt(e,r,t){let n=e[r];return n==="--help"||n==="--version"||t&&(n==="-h"||n==="-V")}var Fn={read:0,write:1,delete:2};function tt(...e){return e.reduce((r,t)=>Fn[t]>Fn[r]?t:r,"read")}var vi=new Set(["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"]),Qn=new Set(["put","rm","delete","remove"]),_i=new Set([...Qn,"restore","restore-capsule","recover","release","locks","retention","hold","unhold","pin","unpin","retrieve","backup-retrieve"]),Jn=new Set(["-delete","-exec","-execdir","-ok","-okdir","-fls","-fprint","-fprint0","-fprintf"]);function Lt(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 Ht(e){let r=e.trim();if(!r)return"read";if(rt(r))return"delete";let t=N(r);if(!t.trustworthy||t.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(r))return fe(r);let n=t.segments.flatMap((s)=>{let i=Bn(s),o=s.words.filter((u,c)=>!s.redirects.has(c)).map((u)=>u.text),a=o.map(le);if(a.every((u,c)=>u!==null&&u.length===1&&u[0]===o[c]))return[i];if(a.some((u)=>u===null))return[i,fe(o.join(" "))];let l=N(a.flatMap((u)=>u??[]).join(" "));return[i,...l.trustworthy?l.segments.map(Bn):[fe(o.join(" "))]]});return tt(...n)}function Bn(e){let r=e.words.map((i,o)=>({word:i,at:o})).filter(({at:i})=>!e.redirects.has(i)),t=j(e),n=t<0?"read":jn(e,t),s=ae(r.map(({word:i})=>Mt(i.text)));if(s===null)return tt(n,fe(r.map(({word:i})=>P(i.text)).join(" ")));if(s.index<0||r[s.index].at===t)return n;return tt(n,jn(e,r[s.index].at))}function er(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:De(n.map(({word:u})=>u.text),s,W);if(i){if(!i.literal)return!0;let u=N(i.program);if(u.trustworthy&&u.segments.some((c)=>nt(c,t+1)))return!0}let o=e.words.map((u)=>W(u.text));for(let u of Le(o,r,(c)=>e.redirects.has(c)))if(nt(tr(e,u.start,u.end),t+1))return!0;let l=He(o,r,(u)=>u>=0&&u<e.words.length&&(e.redirects.has(u)||Lt(e.words[u].text)));if(!l)return!1;if(l.unresolved)return!0;return l.programs.some((u)=>u.kind==="shell"?Ht(u.text)!=="read":!yn(u))}function tr(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 nt(e,r=0){return nr(e).some((t)=>er(e,t,r))}function Mt(e){return{text:W(e),opaque:/[$\x60]/.test(e)&&!/^(?:[^$\x60"'\\]|\$'(?:[^'\\]|\\.)*')+$/.test(e)}}function nr(e){let r=new Set,t=j(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=ae(n.map(({word:i})=>Mt(i.text)));if(s!==null&&s.index>=0)r.add(n[s.index].at);return[...r]}function Ge(e,r=0){if(r>8)return[];let t=[];for(let n of e.segments){let s=n.words.map((a)=>W(a.text)),i=(a)=>a>=0&&a<n.words.length&&(n.redirects.has(a)||Lt(n.words[a].text)),o=n.words.filter((a,l)=>!n.redirects.has(l));for(let a of nr(n)){t.push(...(He(s,a,i)?.writes??[]).map((c)=>c[0]==="/"?c:`./${c}`));let l=De(o.map((c)=>c.text),o.indexOf(n.words[a]),W),u=l?.literal?N(l.program):null;if(u?.trustworthy)t.push(...Ge(u,r+1));for(let c of Le(s,a,(f)=>n.redirects.has(f)))t.push(...Ge({segments:[tr(n,c.start,c.end)]},r+1))}}for(let n of e.substitutions??[]){let s=N(n);if(s.trustworthy)t.push(...Ge(s,r+1))}return t}function rt(e,r=0){if(r>4)return!1;let t=N(e),n=t.trustworthy?e:be(e);if(n!==e)return rt(n,r+1);if(t.trustworthy&&t.segments.some((i)=>nt(i)))return!0;return(ir(e)??t.substitutions).some((i)=>rt(i,r+1))}function jn(e,r){if(er(e,r))return"delete";let t=e.words.filter((i,o)=>o>=r&&!e.redirects.has(o)),n=t.map((i)=>W(i.text)),s=n[0].split("/").pop();if(["rm","rmdir","shred"].includes(s??""))return Pt(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||vi.has(n[i]))return"read";if(_i.has(n[i])&&Pt(n,i+1,!0))return"read";if(["restore","restore-capsule"].includes(n[i]))return"write";return"delete"}if(s==="git"){let i=$t(e,r);if(i==="clean"||i==="rm")return n[1]===i&&Pt(n,2,!0)?"read":"delete";return i==="clone"||i==="init"?"write":"read"}if(s==="find"&&!t.some((i)=>Lt(i.text))&&!n.some((i)=>Jn.has(i)))return"read";if(s==="env"&&Y(Fe(n)))return"delete";if(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env","xargs","find","busybox","toybox"].includes(s??""))return fe(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 Xn.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 fe(e){let r=e.replace(/[{},]/g," ");return r===e?Wt(e):tt(Wt(e),Wt(r))}function Wt(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(Xn.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(Yn(r)))return"write";return"read"}function qe(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 E.join(r,t.slice(2));if(t==="$HOME"||t==="${HOME}")return r;if(t.startsWith("$HOME/"))return E.join(r,t.slice(6));if(t.startsWith("${HOME}/"))return E.join(r,t.slice(8));let s=t.match(new RegExp(`^"*${Nt(r)}"*/`));if(s)return r+"/"+t.slice(s[0].length);return e}function Ei(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 Nt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Gn(e,r,t){if(e===void 0)return[t];let n=qe(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)=>E.resolve(i,n)))]}var Oi=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function Ri(e,r){let t=ae(r);if(!t||t.index<=0||r[t.index].opaque)return 0;let n=N(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)=>P(i.text)!==r[o].text))return 0;return j(s)===t.index?t.index:0}function Ai(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 Ti=new Set(["--agent","--spool","--files","--info","--config"]),$i=new Set(["--spool","--files","--info","--config"]),Ci=new Set(["--json","--local","--help","-h","--version","--identity"]),qn={"--agent":/^[^-]/,"--retention":/^(?:\d+(?:\.\d+)?|never)$/},Ii=new Set(["--to"]);function Pi(e){let r=[],t=0;for(;t<e.length&&e[t].text.startsWith("-");t++){let i=e[t];if(i.opaque)return null;if(Ti.has(i.text)){let o=e[++t];if(!o||o.opaque)return null;if($i.has(i.text))r.push(o)}else if(!Ci.has(i.text))return null}let n=e[t];if(!n||n.opaque||!Qn.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(Ii.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(qn,a)&&l&&!l.opaque&&qn[a].test(l.text))t++}return r}function Wi(e){let r=e.split(`
|
|
27
|
+
`),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=xe(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 Ni=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"]),Di=new Set([".","source","eval","env","alias","hash"]),Li=new Set(["tee","cp","mv","install","ln"]),rr=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"]),Hi=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),Mi=new Set(["pr","issue","api","release","gist"]);function Fi(e,r){let t=e[r];if(t==="gh")return Mi.has(e[r+1]??"");if(t!=="git")return rr.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("-")&&Hi.has(s)}return!1}function Bi(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=sr(e,t+1),t<0)return-1}else if(n==="`"){if(t=e.indexOf("`",t+1),t<0)return-1}}return-1}function sr(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=Bi(e,n),n<0)return-1}else if(s==="(")t++;else if(s===")"&&--t===0)return n}return-1}function ir(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=sr(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 ji(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=N(i),a=ir(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)=>P(l.text));for(let l of s.redirects)n.add(X(i[l]??""));let o=j(s);if(o<0)continue;let a=X(i[o]);if(Li.has(a)){for(let l of i.slice(o+1))if(!l.startsWith("-"))n.add(X(l))}if(a==="dd"){for(let l of i)if(l.startsWith("of="))n.add(X(l.slice(3)))}}n.delete("");for(let s of r){for(let u of s.words){let c=X(P(u.text));if(Ni.has(c)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(c))return!0}let i=j(s),o=s.words.map((u,c)=>({text:P(u.text),at:c})).filter(({at:u})=>!s.redirects.has(u));if(o.some(({text:u,at:c})=>(i<0||c<i)&&Pe.test(u)))return!0;if(i<0)continue;let a=s.words[i].text,l=P(a);if(/[$\x60]/.test(a)||l.includes("/")||Di.has(l)||n.has(l))return!0;if(!Fi(o.filter(({at:u})=>u>=i).map(({text:u})=>u),0))return!0}return!1}function Gi(e){if(!e.includes("<<"))return null;let r=Wi(e);if(!r||r.length===0)return null;let t=e.split(`
|
|
28
|
+
`),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(`
|
|
29
|
+
`));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 ji(i.join(`
|
|
30
|
+
`))?null:{outer:n.join(`
|
|
31
|
+
`),bodies:s}}var qi="/";function st(e,r,t){if(!e)return[];let n=N(e).trustworthy?e:be(e),s=Gi(e);return[...n===e?[]:st(n,r,t),...s?[...Zn(s.outer,r,t),...s.bodies.flatMap((i)=>st(i,r,qi))]:Zn(e,r,t)]}var zi=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,Ui=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function zn(e,r,t=!1){let n=[],s=0;for(let a of r)n.push(s),s+=a.length;let i=N(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 Un(e,r,t=[]){if(Ht(r)!=="read")return!1;let n=j(e),s=e.words.filter((c,f)=>!e.redirects.has(f)),i=ae(s.map((c)=>Mt(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)&&Pe.test(P(c.text))))return!1;if([n<0?null:e.words[n].text,i.index<0?null:s[i.index].text].every((c)=>c===null||rr.has(X(P(c)))))return!0;let l=s.filter((c)=>!t.includes(c)),u=l.map((c)=>P(c.text));return fe(l.map((c)=>c.text).join(" "))==="read"&&fe(u.join(" "))==="read"&&!u.some((c)=>Jn.has(c))}function Vi(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)=>nt(i))}var Vn=(e,r)=>e.slice(r.words[0].start,r.words[r.words.length-1].end);function Zi(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)=>!Ui.test(o.text)))return!1;for(let o of r.lexed.segments.filter((a)=>a.words.some(s)))if(!Un(o,Vn(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=N(a);if(!l.trustworthy||l.substitutions.length>0)return!1;if(!l.segments.every((u)=>Un(u,Vn(a,u))))return!1}return!0}function Zn(e,r,t){if(!e)return[];let n=Kn(r),s=(h)=>n.some((p)=>h===p||h.startsWith(`${p}${E.sep}`)),i=e.split(zi),o=zn(e,i),a=o??zn(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],A=(m.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,I=(m.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let S=0;S<A;S++)d.push({current:[...u],reachable:new Set(c),certain:f});let D=Ei(m),V=o!==null&&Zi(e,o,o.offsets[h],o.offsets[h]+m.length),k=!V&&(a!==null&&Vi(e,a,a.offsets[h],a.offsets[h]+m.length)||rt(m.trim())),b=D.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),T=b?null:D.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(T){for(let S of Gn(T[1],u,r)??[])c.add(S);f=!1,u=[...c]}let G=Nt(r),q=n.map((S)=>Nt(S.slice(r.length+1))).join("|"),_e=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${G}"*)/(?:${q})`),on=new RegExp(`(${_e.source})([^\\s"';&|<>()\`]*|$)`,"g"),ln=(S)=>{let F=[],z;on.lastIndex=0;while((z=on.exec(S))!==null)F.push(E.normalize(qe(z[0],r)).replace(/\/+$/,""));return F},an=a===null?0:a.offsets[h],un=(S)=>S.start<an+m.length&&S.end>an,Er=a!==null&&a.words.some(un)?Ge({segments:a.lexed.segments.filter((S)=>S.words.some(un))}):[m.trim(),D].flatMap((S)=>{let F=N(S);if(!F.trustworthy)F=N(be(S));return F.trustworthy?Ge(F):[]}),ht=xi(D).map((S,F)=>{let z=F===0?[...new Set(Er)]:[],Ee=!1,Oe=Yn(S).replace(yi,(gt,pe)=>{if(!pe||/[$\x60]/.test(pe))Ee=!0;if(pe)z.push(pe);return" "}),Re=V?"read":k?"delete":Ht(Oe);return{commandPart:Oe,operands:z,op:Ee&&Re==="read"?"write":Re}}),Or=ht.some((S)=>S.op==="delete")?"delete":ht.some((S)=>S.op==="write")?"write":"read",pt=u.filter(s);if(k)for(let S of pt)l.push({path:S,op:"delete"});for(let S of ht){let F=!1;for(let B of ln(S.commandPart))F=!0,l.push({path:B,op:Or});for(let B of S.operands){let ee=ln(B);for(let K of ee)l.push({path:K,op:"write"});if(ee.length>0)continue;for(let K of pt)l.push({path:E.normalize(E.resolve(K,qe(B,r))),op:"write"})}if(F||S.op==="read")continue;let z=ki(S.commandPart),Ee=Ri(S.commandPart,z),Oe=X(z[Ee]?.text??""),Re=z.slice(Ee+1),gt=((Oe==="trash"?Pi(Re):null)??Ai(Oe,Re)).map((B)=>B.opaque?".":B.text),pe=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(pe)for(let B of gt.length>0?gt:["."])Ae.push({operand:B,op:S.op});else{let B=S.commandPart.match(Oi),ee=z.at(-1);if(Ae.push({operand:B?B[1]:!ee||ee.opaque?".":ee.text,op:S.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(S.commandPart))z.forEach((K,cn)=>{let ge,mt=K.text.match(/^-[A-Za-z]*?t(.*)$/),Ue=K.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(mt&&!K.text.startsWith("--"))ge=mt[1]?{text:mt[1],opaque:K.opaque}:z[cn+1];else if(Ue&&"--target-directory".startsWith(Ue[1]))ge=Ue[2]!==void 0?{text:Ue[2],opaque:K.opaque}:z[cn+1];if(ge)Ae.push({operand:ge.opaque||!ge.text?".":ge.text,op:S.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(S.commandPart))Ae.push({operand:".",op:S.op})}for(let B of pt)for(let{operand:ee,op:K}of Ae)l.push({path:E.normalize(E.resolve(B,qe(ee,r))),op:K})}if(b){let S=Gn(b[1],u,r);if(S){for(let F of S)c.add(F);if(f)u=S}else f=!1}for(let S=0;S<I&&d.length>0;S++)({current:u,reachable:c,certain:f}=d.pop())}return l}var Ki=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function Xi(e,r){let t=[],n;while((n=Ki.exec(e))!==null){let s=n[1]==="Delete File"?"delete":"write";t.push({path:E.normalize(E.resolve(r,n[2])),op:s})}return t}function or(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??Dt.homedir(),i=Kn(s),o=Si(process.env,s);if(n==="Bash"){let d=me(e);if(!d)return{output:{continue:!0},warnings:t};let h=typeof e.cwd==="string"&&e.cwd?e.cwd:process.cwd(),p=st(d,s,h);p.unshift(...ue(d,()=>st(d,s,h))??[]);for(let m of p)for(let A of i){let I=It(m.path,A,o,m.op);if(I.blocked)return{output:{decision:"block",reason:I.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(fi.has(n)){let d=typeof a.patch==="string"?a.patch:"";if(!d)return{output:{continue:!0},warnings:t};let h=Xi(d,l);for(let p of h)for(let m of i){let A=It(p.path,m,o,p.op);if(A.blocked)return{output:{decision:"block",reason:A.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=qe(u,s),f=E.isAbsolute(c)?E.normalize(c):E.resolve(l,c);for(let d of i){let h=It(f,d,o,"write");if(h.blocked)return{output:{decision:"block",reason:h.reason},warnings:t}}return{output:{continue:!0},warnings:t}}var Yi=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"]),Qi=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),cr=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"]),fr=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"]),Ji=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),eo=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class jt extends Error{}var O=()=>{throw new jt};function Ft(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=Ft(e,l).end;continue}if(u==="(")a++;else if(u===")")a--;l++}if(a!==0)O();if(n)t.push(n),n="";t.push({src:e.slice(s+2,l-1)}),s=l;continue}if(o===void 0)O();n+=o,s+=2;continue}n+=i,s++}return O()}function dr(e){let r=[],t=0,n=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while(t<e.length){let s=e[t];if(/\s/.test(s)){t++;continue}if(s==="#")O();if(s==='"'){let l=Ft(e,t);r.push({t:"str",parts:l.parts}),t=l.end;continue}if(s==="."){if(e[t+1]===".")O();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=Ft(e,t+1);if(u.parts.some((c)=>typeof c!=="string"))O();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==="$")O();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)O();r.push({t:"op",v:a}),t+=a.length}return r}var to=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 Gt{tokens;at=0;constructor(e){this.tokens=e}parse(){if(this.tokens.length===0)O();let e=this.pipe();if(this.at!==this.tokens.length)O();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))O();this.at++}pipe(){let e=this.comma();if(this.isIdent("as"))O();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))O();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 O();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(!eo.has(e.name))O();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(to.has(e.name))O();if(e.name==="map"||cr.has(e.name)||fr.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 O()}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 O()}}return O()}stringNode(e){let r=[];for(let t of e){if(typeof t==="string")continue;r.push(new Gt(dr(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)O();this.at++;let t;if(r.t==="ident")t=r.name;else if(r.t==="str"){if(r.parts.some((n)=>typeof n!=="string"))O();t=r.parts.join("")}else O();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 qt(e){if(typeof e==="object"&&"union"in e)return e.union.every(qt);return e==="safe"||typeof e==="object"&&Yi.has(e.leaf)}var ze=(...e)=>e.every(qt)?"safe":"tainted";function Bt(...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 it(e,r){return typeof e==="object"&&"union"in e?Bt(...e.union.map(r)):r(e)}var ot=(e)=>typeof e==="object"&&("leaf"in e)&&Qi.has(e.leaf),se=(e)=>it(e,(r)=>r==="safe"?"safe":r==="tainted"||ot(r)?"tainted":"unknown");function lr(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 ar(e,r,t){return it(e,(n)=>{if(n==="safe"||n==="tainted")return n;if(ot(n))return"tainted";if(n==="root"&&t.rootScalars.has(r))return"safe";return{leaf:r}})}function R(e,r,t){switch(e.k){case"dot":return r;case"field":return ar(e.of?R(e.of,r,t):r,e.name,t);case"iter":return se(R(e.of,r,t));case"index":{let n=R(e.of,r,t);if(e.key.k==="str"&&e.key.text!==void 0)return ar(n,e.key.text,t);if(e.key.k==="lit")return se(n);return R(e.key,r,t),"tainted"}case"slice":return it(R(e.of,r,t),(n)=>n==="root"?"unknown":ot(n)?"tainted":n);case"opt":return R(e.of,r,t);case"lit":return"safe";case"str":return ze(...e.parts.map((n)=>R(n,r,t)));case"fmt":return e.str?R(e.str,r,t):r;case"array":return e.of?ze(R(e.of,r,t)):"safe";case"object":return ze(...e.entries.map((n)=>R(n.value,r,t)));case"pipe":return R(e.b,R(e.a,r,t),t);case"comma":return Bt(R(e.a,r,t),R(e.b,r,t));case"alt":return Bt(R(e.a,r,t),R(e.b,r,t));case"bool":return R(e.a,r,t),R(e.b,r,t),"safe";case"arith":return ze(R(e.a,r,t),R(e.b,r,t));case"neg":return R(e.of,r,t);case"call":return no(e,r,t)}}var ur=(e)=>it(e,(r)=>r==="root"?"unknown":ot(r)?"tainted":r);function no(e,r,t){let{name:n,args:s}=e;if(Ji.has(n)&&n!=="limit"&&!s.every(lr))O();switch(n){case"map":if(s.length!==1)O();return ze(R(s[0],se(r),t));case"select":if(s.length!==1)O();return R(s[0],r,t),r;case"limit":if(s.length!==2||!lr(s[0]))O();return R(s[1],r,t);case"first":case"last":if(s.length>1)O();return s.length===1?R(s[0],r,t):se(r);case"min":case"max":return se(r);case"sort_by":case"group_by":case"unique_by":if(s.length!==1)O();return R(s[0],se(r),t),ur(r);case"min_by":case"max_by":if(s.length!==1)O();return R(s[0],se(r),t),se(r);case"any":case"all":case"isempty":for(let i of s)R(i,"unknown",t);return"safe"}if(cr.has(n))return"safe";if(fr.has(n))return ur(r);return O()}function hr(e,r={}){if(typeof e!=="string"||!e.trim()||e.length>4096)return!1;try{let t=new Gt(dr(e)).parse();return qt(R(t,"root",{rootScalars:r.rootScalars??new Set}))}catch(t){if(t instanceof jt)return!1;return!1}}var Jt="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",x={refused:!1},y=(e)=>({refused:!0,rule:e}),zt=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"]),Ut=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),pr=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),gr=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),ro=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),so=new Set(["author","committer","id","parents","repository","sha","url"]),io=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function Sr(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("{")&&Sr(e))t=!0;return{value:r,opaque:t,raw:e}}var de=(e)=>e.slice(e.lastIndexOf("/")+1);function Kt(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=ce(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 M(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 oe=(e,...r)=>e.flags.filter((t)=>r.includes(t.name)),Z=["-R","--repo","-q","--jq","-t","--template","--json"],he={"pr view":{values:Z},"issue view":{values:Z},"release view":{values:Z},"discussion view":{values:[...Z,"--after","-L","--limit","--order"]},"pr list":{values:[...Z,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...Z,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...Z,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...Z,"-L","--limit","-O","--order"]},"pr status":{values:Z},"issue status":{values:Z},"pr checks":{values:[...Z,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...Z,"--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"]}},oo=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"]),lo=new Set(["pr","issue","release","discussion","search","project","api","status"]),ao=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),uo=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),co=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),fo=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function ct(e,r){let t=oe(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 en(e,r){if(M(e,"--verbose")||oe(e,"-t","--template").length>0)return!1;let t=oe(e,"-q","--jq");return t.length>0&&t.every((n)=>n.value!==void 0&&!n.value.opaque&&hr(n.value.value,{rootScalars:r}))}function tn(e,r,t,n){let s=ct(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 en(e)?x:y(n)}function lt(e,r,t,n,s){let i=ve(e,he[r]);if(M(i,"-h","--help"))return x;if(M(i,"-w","--web"))return n.debug?y("debug-traffic"):x;if(s&&M(i,"-c","--comments"))return y("view-comments");if(!ct(i,n).present)return y(n.debug?"debug-traffic":"view-human");return tn(i,t,n,"json-composite")}function ie(e,r,t,n){let s=ve(e,he[r]);if(M(s,"-h","--help"))return x;if(n.debug&&(M(s,"-w","--web")||!ct(s,n).present))return y("debug-traffic");if(M(s,"-w","--web"))return x;return tn(s,t,n,"json-composite")}function ho(e,r){let t=ve(e,he["pr checks"]);if(M(t,"-h","--help"))return x;if(r.debug)return y("debug-traffic");if(M(t,"-w","--web"))return x;if(!ct(t,r).present)return y("checks-human");return tn(t,io,r,"checks-json")}function po(e){let r=new Set(he.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 go(e,r,t){let{sub:n,rest:s}=po(r);if(!n)return t.appendsArgs?y("unclassifiable"):x;if(n.opaque)return y("unclassifiable");let i=n.value;if((e==="pr"?ao:e==="issue"?uo:e==="release"?co:e==="discussion"?fo: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 lt(s,"pr view",zt,t,!0);if(i==="list"||i==="ls")return ie(s,"pr list",zt,t);if(i==="status")return ie(s,"pr status",zt,t);if(i==="checks")return ho(s,t);if(i==="diff"){let a=ve(s,he["pr diff"]);if(M(a,"-h","--help"))return x;if(t.debug)return y("debug-traffic");return M(a,"--patch")?y("composite-other"):x}return y("unclassifiable");case"issue":if(i==="view")return lt(s,"issue view",Ut,t,!0);if(i==="list"||i==="ls")return ie(s,"issue list",Ut,t);if(i==="status")return ie(s,"issue status",Ut,t);return y("unclassifiable");case"release":if(i==="view")return lt(s,"release view",pr,t,!1);if(i==="list"||i==="ls")return ie(s,"release list",pr,t);return y("unclassifiable");case"discussion":if(i==="view")return lt(s,"discussion view",gr,t,!0);if(i==="list"||i==="ls")return ie(s,"discussion list",gr,t);return y("unclassifiable");case"search":if(i==="prs"||i==="issues")return ie(s,"search",ro,t);if(i==="commits")return ie(s,"search",so,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,he["project item-list"]);if(M(a,"-h","--help"))return x;let l=oe(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 en(a)?x:y("composite-other")}}return y("unclassifiable")}var wr=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function mo(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)||Sr(a))}}return{segments:n,opaque:s}}function bo(e){let r=mo(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]&&So.has(f));return s(c<0?"unclassifiable":mr(t.slice(c),n.slice(c)))}return s(mr(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 So=new Set([...wr,"branches","git","actions","hooks","zipball","tarball"]);function mr(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(wr.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 wo(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 yo(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 xo=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"]),ko=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function vo(e){let r=[],t=0;while(t<e.length){let n=e[t];if(/[\s,]/.test(n)){t++;continue}if(n==="#"){let o=e.indexOf(`
|
|
32
|
+
`,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]!==`
|
|
33
|
+
`)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 _o(e){let r=vo(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(xo.has(o.text)||/(?:Url|URL|HTML|Html)$/.test(o.text))return!0;if(o.text==="title"&&t.some((l)=>ko.has(l)))return!0;n=o.text}return s!==0||t.length!==0}function Eo(e,r){let t=ve(e,he.api);if(M(t,"-h","--help"))return x;let n=t.positionals[0];if(!n)return r.appendsArgs?y("unclassifiable"):x;let s=bo(n),i=oe(t,"-X","--method"),o=i[i.length-1],a=oe(t,"-f","--raw-field","-F","--field","--input"),l=o?o.value&&!o.value.opaque?o.value.value.toUpperCase():"?":a.length>0?"POST":"GET",u=wo(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=Oo(t);if(r.debug||M(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||M(t,"--silent"))return x;if(en(t,yo(s.segments)))return x;return c}function Oo(e){if(oe(e,"--input").length>0)return y("unclassifiable");let r=oe(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(_o(s))return y("api-graphql")}return x}function ut(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 go(n.value,s,r);case"api":return Eo(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=Q(s.slice(i+1).map((a)=>a.value).join(" "),r.depth+1,r.debug);if(o.refused)return o}break}}if(!oo.has(n.value))return y("unclassifiable");if(r.debug)return y("debug-traffic");return x}var ft=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","fish"]),Ro=new Set(["su","runuser","script","flock"]),Ao=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"]),To=new Map([["bun",["x","exec"]],["npm",["exec","x"]],["deno",["run"]]]),$o=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"]),Co=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),at=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/,Io=/^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/,Po=6;function br(e,r){let t,n;for(let s of e){let i=Io.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 nn(e){let r=N(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 yr=(e)=>/(?:^|[^|])\|&?$/.test(e.trim());function Xt(e,r){if(!ft.has(e))return!1;if(rn(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 Yt(e){let{segments:r}=nn(e.trim());if(r.length!==1)return null;let t=r[0],n=j(t);if(n<0)return null;let s=de(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,`
|
|
34
|
+
`).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=xe(e,o),l=e.indexOf(`
|
|
35
|
+
`,o);if(!a||l<0)return null;let u=et(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 Vt(e,r,t){for(let n of Kt(e).bodies){let s=Yt(n);if(s===null)continue;let i=Q(s,r+1,t.debug);if(i.refused)return i}return x}function Q(e,r=0,t=!1){if(typeof e!=="string"||!e.trim())return x;if(r>Po)return at.test(e)?y("unclassifiable"):x;let{segments:n,trustworthy:s}=nn(e);if(!s)return at.test(e)?y("unclassifiable"):x;let i=t,o=(a)=>Q(a,r+1,i);for(let a of Do(e)){if(a.runsBody){let l=o(a.body);if(l.refused)return l}if(!a.quoted){let l=Kt(a.body,"heredoc");if(!l.complete&&at.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 T=Kt(b.text);if(!T.complete&&at.test(b.text))return y("unclassifiable");for(let G of T.bodies){let q=o(G);if(q.refused)return q}}let u=j(l),c=l.words.map((b,T)=>({word:ke(b.text),redirect:l.redirects.has(T)})),f=c.slice(0,u<0?c.length:u).map((b)=>b.word),d=u>=0?de(c[u].word.value):"";if(u<0||["export","declare","typeset","readonly","local"].includes(d)){if(i=br([...f,...c.slice(u+1).map((b)=>b.word)],i),u<0)continue}let h=br(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),A=c[u].word,I=de(A.value),D={depth:r,appendsArgs:!1,debug:h};if(u>0&&c[u-1].word.value==="function"){let b=p.filter((G)=>!["{","()","(",")"].includes(G.value)),T=Qt(b,D);if(T.refused)return T;continue}if(a>0&&yr(l.sepBefore)&&Xt(I,p)){let b=n[a-1],T=Wo(e,b),G=T===null?null:Yt(T);if(G!==null){let q=Q(G,r+1,h);if(q.refused)return q}}let V=n[a+1];if(V&&/<\(\s*$/.test(V.sepBefore)&&(ft.has(I)||I==="source"||I===".")){let b=V.words[0].start-V.sepBefore.length+V.sepBefore.lastIndexOf("("),T=ce(e,b),G=T<0?null:Yt(e.slice(b+1,T-1));if(G!==null){let q=Q(G,r+1,h);if(q.refused)return q}}let k=xr(I,A,p,m,l.words.slice(0,u+1),D);if(k.refused)return k}return x}function Wo(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 No(e){let r=de(e.value);return/[$`]/.test(r)||r===""?void 0:r}function xr(e,r,t,n,s,i){let o=i.depth,a=(l)=>Q(l,o+1,i.debug);if(r.opaque){let l=No(r);if(l===void 0){let u=t.find((f)=>!f.value.startsWith("-")),c=ut(t,i);if(!c.refused)return x;return c.rule!=="unclassifiable"||u!==void 0&&!u.opaque&&lo.has(u.value)?c:x}e=l}if(e==="gh")return ut(t,i);if(ft.has(e)){let l=rn(t);if(l){let u=a(l.value);if(u.refused||!l.opaque)return u;return Vt(l.raw,o,i)}for(let u of n){let c=a(u.value);if(c.refused)return c;if(u.opaque){let f=Vt(u.raw,o,i);if(f.refused)return f}}return x}if(Ro.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):Zt(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=Vt(c.raw,o,i);if(f.refused)return f}return x}if(e==="env")return a(Fe([...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(Co.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($o.has(c))l++}return Qt(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=Qt(t.slice(l+1,u),i);if(c.refused)return c;l=u}return x}if(Ao.has(e))return Zt(t,i);if(To.get(e)?.includes(t[0]?.value??""))return Zt(t.slice(1),i);return x}function Qt(e,r){if(e.length===0)return x;let t=de(e[0].value);if(t==="gh")return ut(e.slice(1),r);if(ft.has(t)){let n=rn(e.slice(1));return n?Q(n.value,r.depth+1,r.debug):x}return xr(t,e[0],e.slice(1),[],[],r)}function Zt(e,r){let t=e.findIndex((n)=>!n.opaque&&de(n.value)==="gh"&&(n.value==="gh"||n.value.includes("/")));return t>=0?ut(e.slice(t+1),r):x}function rn(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 Do(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=xe(e,n);if(!s)continue;let i=e.lastIndexOf(`
|
|
36
|
+
`,n)+1,o=e.indexOf(`
|
|
37
|
+
`,n);if(o<0)continue;let a=et(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:Lo(c),quoted:s.quoted})}return r}function Lo(e){let{segments:r}=nn(e),t=r.findIndex((a)=>a.words.some((l)=>l.text==="HEREDOC_OPERATOR"));if(t<0)return!1;let n=(a)=>{let l=j(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:de(ke(a.words[l].text).value),args:u}},{verb:s,args:i}=n(r[t]);if(s==="ssh"||Xt(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&&yr(o.sepBefore)){let a=n(o);return a.verb==="ssh"||Xt(a.verb,a.args)}return!1}var Ho=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function kr(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Jt}}}var Mo=new Set(["Bash","Monitor"]);function vr(e){if(e?.hook_event_name!=="PreToolUse"||!Mo.has(e.tool_name??""))return{continue:!0};let r=me(e);if(!r.trim())return{continue:!0};try{return Q(r).refused?kr():{continue:!0}}catch{return Ho.test(r)?kr():{continue:!0}}}function Fo(e){if(e!=="trash-guard"&&e!=="workspace-repos-guard")throw Error("Invalid safety capability")}function _r(e,r){Fo(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"||!sn.isAbsolute(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:dt.homedir(),path:process.env.PATH,agent:s.agent};if(i&&(!sn.isAbsolute(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 I=n.tool_input.command??n.tool_input.patch;if(typeof I!=="string")throw Error("Invalid patch input");n.tool_input={...n.tool_input,command:I,patch:I}}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=(I)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:I}}),c=or(l).output,f=vr(l),d=l.tool_input.command,h=()=>ye(d,{home:dt.homedir(),cwd:n.cwd}).handoffHits.length>0,p=a&&(h()||!!ue(d,h)),m=t==="trash-guard"&&(!o||a)?Mn(l,{home:dt.homedir(),cwd:n.cwd,findTrash:Ze,inspectTrash:Ce,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 A=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 A?null:A})}var Bo=2,jo="0.13.0";function Go(e,r){return _r(e,r)}
|