@hasna/hooks 0.12.10 → 0.12.14

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.
Files changed (57) hide show
  1. package/README.md +69 -6
  2. package/bin/hooks/stop-review.js +1235 -0
  3. package/bin/hooks-mcp.js +298 -85
  4. package/bin/index.js +3309 -1086
  5. package/bin/native-readiness-entry.js +5 -1
  6. package/bin/native-safety-entry.js +27 -25
  7. package/bin/native-safety-worker.cjs +27 -25
  8. package/bin/serve.js +1362 -70
  9. package/dist/db/remote-storage.d.ts +7 -1
  10. package/dist/index.d.ts +4 -1
  11. package/dist/index.js +1665 -257
  12. package/dist/lib/codex-safety-check.d.ts +1 -1
  13. package/dist/lib/hosted-registry.d.ts +70 -0
  14. package/dist/lib/legacy-registry-artifact.d.ts +23 -0
  15. package/dist/lib/manifest.d.ts +7 -0
  16. package/dist/lib/native-safety.d.ts +1 -0
  17. package/dist/lib/native-target.d.ts +7 -0
  18. package/dist/lib/opencode-stop-plugin.d.ts +55 -0
  19. package/dist/lib/registry-artifact.d.ts +36 -0
  20. package/dist/lib/registry.d.ts +4 -0
  21. package/dist/lib/stop-review-context.d.ts +12 -0
  22. package/dist/lib/store.d.ts +4 -0
  23. package/dist/lib/sumi-stop-plugin.d.ts +129 -0
  24. package/dist/lib/sync.d.ts +10 -0
  25. package/dist/lib/transport.d.ts +1 -1
  26. package/dist/native-readiness.d.ts +1 -1
  27. package/dist/native-readiness.js +5 -1
  28. package/dist/openapi.d.ts +160 -16
  29. package/dist/opencode-stop-plugin.js +384 -0
  30. package/dist/registry-auth.d.ts +5 -0
  31. package/dist/registry-http.d.ts +4 -0
  32. package/dist/sdk/generated.d.ts +32 -12
  33. package/dist/sdk/index.d.ts +28 -5
  34. package/dist/sdk/index.js +49 -24
  35. package/dist/sdk/registry-client.d.ts +1 -1
  36. package/dist/serve.d.ts +4 -4
  37. package/dist/storage.js +33 -2
  38. package/dist/sumi-stop-plugin.js +380 -0
  39. package/hooks/hook-stop-review/README.md +109 -0
  40. package/hooks/hook-stop-review/manifest.json +10 -0
  41. package/hooks/hook-stop-review/package.json +11 -0
  42. package/hooks/hook-stop-review/src/hook.ts +59 -0
  43. package/hooks/hook-stop-review/src/index.ts +3 -0
  44. package/hooks/hook-stop-review/src/jev.ts +121 -0
  45. package/hooks/hook-stop-review/src/native.ts +246 -0
  46. package/hooks/hook-stop-review/src/policy.ts +145 -0
  47. package/hooks/hook-stop-review/src/runtime.ts +309 -0
  48. package/hooks/hook-stop-review/src/types.ts +121 -0
  49. package/hooks/hook-trash-guard/src/hook.ts +96 -0
  50. package/hooks/hook-workspace-repos-guard/src/hook.ts +116 -3
  51. package/hooks/local-executors.ts +841 -0
  52. package/package.json +22 -4
  53. package/scripts/build-bundled-hooks.ts +40 -0
  54. package/scripts/validate-bundled-hooks.ts +78 -0
  55. package/scripts/validate-opencode-stop-plugin.ts +42 -0
  56. package/scripts/validate-package.ts +9 -0
  57. package/scripts/validate-sumi-stop-plugin.ts +47 -0
@@ -1,25 +1,27 @@
1
- var{defineProperty:rZ,getOwnPropertyNames:g2,getOwnPropertyDescriptor:u2}=Object,l2=Object.prototype.hasOwnProperty;function m2(Z){return this[Z]}var p2=(Z)=>{var X=(k0??=new WeakMap).get(Z),$;if(X)return X;if(X=rZ({},"__esModule",{value:!0}),Z&&typeof Z==="object"||typeof Z==="function"){for(var J of g2(Z))if(!l2.call(X,J))rZ(X,J,{get:m2.bind(Z,J),enumerable:!($=u2(Z,J))||$.enumerable})}return k0.set(Z,X),X},k0;var c2=(Z)=>Z;function i2(Z,X){this[Z]=c2.bind(null,X)}var d2=(Z,X)=>{for(var $ in X)rZ(Z,$,{get:X[$],enumerable:!0,configurable:!0,set:i2.bind(X,$)})};var F5={};d2(F5,{version:()=>C5,evaluate:()=>T5,abi:()=>D5});module.exports=p2(F5);var sZ=require("node:os"),S0=require("node:path");var S=require("node:path");var R=require("node:path"),F=require("node:fs"),x0=require("node:child_process"),w0={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 DZ(Z){return Z===0||Z===process.getuid?.()}function bZ(Z,X=!1){let $=Z;for(let J=0;J<32;J++){if(!R.isAbsolute($)||$.length>4096||!CZ("/"))return!1;let z=$.split("/"),Y=z.pop();if(!Y||Y==="."||Y==="..")return!1;let Q="/";for(let B of z){if(!B||B===".")continue;if(B===".."){Q=R.dirname(Q);continue}let M=R.join(Q,B),V=F.lstatSync(M);if(X&&M==="/bin"&&V.isSymbolicLink()&&V.uid===0){let G=F.realpathSync(M);if(!CZ(G))return!1;Q=G;continue}if(!V.isDirectory()||!DZ(V.uid)||V.mode&18)return!1;Q=M}let H=R.join(Q,Y),K=F.lstatSync(H);if(!DZ(K.uid))return!1;if(K.isSymbolicLink()){let B=F.readlinkSync(H);$=R.isAbsolute(B)?B:Q+"/"+B;continue}return K.isFile()&&Boolean(K.mode&73)&&!(K.mode&18)}return!1}function s2(Z){if(!R.isAbsolute(Z)||R.resolve(Z)!==(Z.replace(/\/+$/,"")||"/"))return!1;for(let X=R.resolve(Z);;X=R.dirname(X)){try{return F.lstatSync(X),CZ(X)}catch($){if($.code!=="ENOENT")return!1}if(R.dirname(X)===X)return!1}}function n2(Z,X){let $=F.openSync(Z,F.constants.O_RDONLY|F.constants.O_NONBLOCK|F.constants.O_NOFOLLOW),J;try{if(!F.fstatSync($).isFile())return!1;let Y=Buffer.alloc(256),Q=F.readSync($,Y,0,Y.length,0);J=Y.subarray(0,Q).toString("utf8").split(`
2
- `)[0]}finally{F.closeSync($)}let z=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(J);if(z&&z[1]!=="/usr/bin/env")return bZ(z[1],!0);if(J!=="#!/usr/bin/env bun"||!bZ("/usr/bin/env",!0))return!1;for(let Y of X.split(":").slice(0,64)){if(!s2(Y))return!1;let Q=R.resolve(Y,"bun");try{if(!F.statSync(Q).isFile())continue;F.accessSync(Q,F.constants.X_OK)}catch{continue}return bZ(Q,!0)}return!1}function CZ(Z){let X=Z;for(;;){let $=F.lstatSync(X);if(!$.isDirectory()||!DZ($.uid)||($.mode&18)!==0)return!1;let J=R.dirname(X);if(J===X)return!0;X=J}}function TZ(Z=process.env){let X=Z.PATH??"",$=Date.now()+2000,J="missing",z=(Y)=>{if(J==="missing"||J==="unrecognized_package"||Y.startsWith("unsafe_"))J=Y};for(let Y of X.split(":").slice(0,64)){if(!R.isAbsolute(Y)||Date.now()>=$)continue;let Q=R.resolve(Y,"trash");try{let H=F.statSync(Q);if(!H.isFile()||!DZ(H.uid)||(H.mode&73)===0||(H.mode&18)!==0){z("unsafe_executable");continue}let K=F.realpathSync(Q);if(!CZ(R.resolve(Y))||!CZ(R.dirname(K))){z("unsafe_directory");continue}if(!bZ(Q)){z("unsafe_directory");continue}let B=R.resolve(R.dirname(K),"../.."),M=R.join(B,"package.json"),V=F.statSync(M);if(!V.isFile()||!DZ(V.uid)||V.size>16384||(V.mode&18)!==0||F.lstatSync(M).isSymbolicLink()){z("unsafe_manifest");continue}let G=JSON.parse(F.readFileSync(M,"utf8"));if(G.name!=="@hasna/trash"||typeof G.version!=="string"||typeof G.bin?.trash!=="string"||F.realpathSync(R.resolve(B,G.bin.trash))!==K){z("unrecognized_package");continue}try{if(!n2(K,X)){z("unsafe_interpreter");continue}}catch{z("unsafe_interpreter");continue}let j=$-Date.now();if(j<=0){z("identity_failed");break}let D=x0.spawnSync(Q,["--identity"],{encoding:"utf8",timeout:j,maxBuffer:2048,env:{PATH:X},stdio:["ignore","pipe","pipe"]});if(D.error||D.status!==0||Date.now()>=$){z("identity_failed");continue}let v=JSON.parse(D.stdout);if(v.name==="@hasna/trash"&&v.version===G.version&&v.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:Q,version:G.version};z("unsupported_protocol")}catch{}}return{ok:!1,code:J}}function fZ(Z=process.env){let X=TZ(Z);return X.ok?X.path:null}function GZ(Z){let X=Z.tool_input?.command;return typeof X==="string"?X:""}var h0=["/","/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 PZ=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,s=(Z)=>Z.split("/").pop()??"";function kZ(Z){let X=Z.startsWith("~")?Z.slice(1).split("/",1)[0]:"";if(X&&!/['"\\]/.test(X))return!0;let $=null,J=0;for(let z=0;z<Z.length;z++){let Y=Z[z];if($==="'"){if(Y==="'")$=null;continue}if(Y==="\\"){z++;continue}if($==='"'){if(Y==='"')$=null;continue}if(Y==="'"||Y==='"')$=Y;else if(Y==="$"&&Z[z+1]==="{")J++,z++;else if(Y==="}"&&J>0)J--;else if(Y==="{"||Y==="}")return!0}return!1}var tZ=64;function g0(Z,X){let $=0;for(let J=X;J<Z.length;J++)if(Z[J]==="\\")J++;else if(Z[J]==="{")$++;else if(Z[J]==="}"&&--$===0)return J;return Z.length-1}function a2(Z){let X=Z.match(/^([-+]?\d+)\.\.([-+]?\d+)(?:\.\.([-+]?\d+))?$/),$=X?null:Z.match(/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([-+]?\d+))?$/),J=X??$;if(!J)return null;let z=X?Number(J[1]):J[1].charCodeAt(0),Y=X?Number(J[2]):J[2].charCodeAt(0),Q=Math.abs(Number(J[3]??1))||1;if(!Number.isSafeInteger(z)||!Number.isSafeInteger(Y)||!Number.isSafeInteger(Q))return"overflow";if(Math.floor(Math.abs(Y-z)/Q)+1>tZ)return"overflow";let H=X&&(/^[-+]?0\d/.test(J[1])||/^[-+]?0\d/.test(J[2]))?Math.max(J[1].length,J[2].length):0,K=[];for(let B=z;z<=Y?B<=Y:B>=Y;B+=z<=Y?Q:-Q)if(!X)K.push(String.fromCharCode(B));else K.push(B<0?`-${String(-B).padStart(H-1,"0")}`:String(B).padStart(H,"0"));return K}function o2(Z){let X=null,$=0;for(let J=0;J<Z.length;J++){let z=Z[J];if(X==="'"){if(z==="'")X=null;continue}if(z==="\\"){J++;continue}if(X==='"'){if(z==='"')X=null;continue}if(z==="'"||z==='"')X=z;else if(z==="$"&&Z[J+1]==="{")J=g0(Z,J+1);else if(z==="{"){if(++$>tZ)return"overflow";let Y=null,Q=0,H=!0,K=[];for(let B=J;B<Z.length;B++){let M=Z[B];if(Y==="'"){if(M==="'")Y=null;continue}if(M==="\\"){H=!1,B++;continue}if(Y==='"'){if(M==='"')Y=null;continue}if(M==="'"||M==='"')Y=M,H=!1;else if(M==="$"&&Z[B+1]==="{")B=g0(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((j,D)=>Z.slice(j+1,G[D+1]))}}let V=H?a2(Z.slice(J+1,B)):null;if(V==="overflow")return V;if(V)return{open:J,close:B,parts:V};break}}}}return null}function XZ(Z){if(Z.length>4096&&Z.includes("{"))return null;let X=o2(Z);if(X===null)return[Z];if(X==="overflow")return null;let $=[];for(let J of X.parts){let z=XZ(Z.slice(0,X.open)+J+Z.slice(X.close+1));if(z===null||$.push(...z)>tZ)return null}return $}var U={arg:"none"},q={arg:"value"},FZ={arg:"optional"},a={arg:"none",effect:"lookup"},T={arg:"none",effect:"refuse"},t={help:T,version:T},r2=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,eZ={timeout:{short:{k:q,s:q,v:U},long:{"kill-after":q,signal:q,verbose:U,foreground:U,"preserve-status":U,...t},positionals:[r2]},env:{short:{i:U,"0":U,v:U,u:q,a:q,C:T,S:T},long:{"ignore-environment":U,null:U,debug:U,unset:q,argv0:q,chdir:T,"split-string":T,"block-signal":FZ,"default-signal":FZ,"ignore-signal":FZ,"list-signal-handling":T,...t},env:!0},nice:{short:{n:q},long:{adjustment:q,...t},numericOption:!0},nohup:{short:{},long:{...t}},command:{short:{p:U,v:a,V:a},long:{}},exec:{short:{c:U,l:U,a:q},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:q,o:q,e:q},long:{input:q,output:q,error:q,...t}},time:{short:{p:U,a:U,q:U,v:U,f:q,o:T,V:T},long:{portability:U,append:U,quiet:U,verbose:U,format:q,output:T,...t}},ionice:{short:{c:q,n:q,t:U,p:T,P:T,u:T,h:T,V:T},long:{class:q,classdata:q,ignore:U,pid:T,pgid:T,uid:T,...t}},setsid:{short:{c:U,f:U,w:U,h:T,V:T},long:{ctty:U,fork:U,wait:U,...t}}},t2=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function e2(Z,X,$){let J=!1,z=(Y)=>{if(!Y||Y.effect==="refuse")return!1;if(Y.effect==="lookup")J=!0;return!0};while($<X.length){let Y=X[$];if(Y.opaque)return null;let Q=Y.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(!z(V))return null;if(V.arg==="none"&&H>=0)return null;if(V.arg==="value"&&H<0){let G=X[++$];if(!G||G.opaque)return null}$++;continue}for(let H=1;H<Q.length;H++){let K=Z.short[Q[H]];if(!z(K))return null;if(K.arg==="value"){if(H===Q.length-1){let B=X[++$];if(!B||B.opaque)return null}break}}$++}if(J)return-1;for(let Y of Z.positionals??[]){let Q=X[$];if(!Q||Q.opaque||!Y.test(Q.text))return null;$++}if(Z.env||Z.assignments){for(;$<X.length&&PZ.test(X[$].text);$++)if(X[$].opaque)return null}return $}function VZ(Z,X=eZ){let $=0;while($<Z.length&&(PZ.test(Z[$].text)||t2.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 z=Object.hasOwn(X,s(Z[$].text))?X[s(Z[$].text)]:void 0;if(!z)return{index:$};let Y=e2(z,Z,$+1);if(Y===null)return null;if(Y<0)return{index:-1};$=Y}return null}var $3=600000,J3="Delete via trash guard (rm intercepted and made recoverable)",X3=[".hasna/repos/clones","workspace/repos"],z3=[".hasna",".ssh",".aws"],Z0={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."},Y3=new Set(["sh","bash","zsh","dash","ksh","ash","eval","source",".","su","runuser","env"]),Q3={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"]},K3={timeout:1},H3={sudo:{short:{A:U,B:U,b:U,E:U,H:U,i:U,k:U,N:U,n:U,P:U,S:U,s:U,C:q,g:q,p:q,r:q,T:q,t:q,U:q,u:q,e:a,l:a,v:a,D:T,R:T,h:T,K:T,V:T},long:{askpass:U,bell:U,background:U,"close-from":q,chdir:T,"preserve-env":FZ,edit:a,group:q,"set-home":U,help:T,host:T,login:U,"remove-timestamp":T,"reset-timestamp":U,list:a,"no-update":U,"non-interactive":U,"preserve-groups":U,prompt:q,chroot:T,role:q,stdin:U,shell:U,type:q,"command-timeout":q,"other-user":q,user:q,version:T,validate:a},assignments:!0},doas:{short:{n:U,s:U,u:q,C:T,L:T},long:{}},flock:{short:{s:U,x:U,e:U,n:U,u:U,o:U,F:U,w:q,E:q,h:T,V:T},long:{shared:U,exclusive:U,unlock:U,nonblock:U,nonblocking:U,nb:U,timeout:q,wait:q,"conflict-exit-code":q,close:U,"no-fork":U,fcntl:U,verbose:U,help:T,version:T},positionals:[/^[\s\S]+$/]}},B3={...eZ,...H3},d0=new Set(["-c","--command"]),M3=new Set(["busybox","toybox"]),z0=new Set(["rm","rmdir","unlink","shred"]),G3=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]),V3=new Set(["-C","-c","--git-dir","--work-tree","--namespace","--exec-path","--config-env"]),U3=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/;function o(Z){return U3.test(y(Z))}function LZ(Z){return Z.map((X)=>X.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var s0=/^[A-Za-z_][A-Za-z0-9_]*=/;function xZ(Z){let X=Z.lastIndexOf("/");return X>=0?Z.slice(X+1):Z}var u0={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
3
- `,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function j3(Z,X){let $="",J=X;while(J<Z.length&&Z[J]!=="'"){if(Z[J]!=="\\"||J+1>=Z.length){$+=Z[J++];continue}let z=Z[J+1],Y=Z.slice(J+1),Q;if(Object.hasOwn(u0,z))$+=u0[z],J+=2;else if(Q=Y.match(/^[0-7]{1,3}/))$+=String.fromCharCode(parseInt(Q[0],8)&255),J+=1+Q[0].length;else if((Q=Y.match(/^x([0-9A-Fa-f]{1,2})/))||(Q=Y.match(/^u([0-9A-Fa-f]{1,4})/))||(Q=Y.match(/^U([0-9A-Fa-f]{1,8})/))){let H=parseInt(Q[1],16);$+=H<=1114111?String.fromCodePoint(H):"",J+=1+Q[0].length}else if(z==="c"&&J+2<Z.length)$+=String.fromCharCode(Z.charCodeAt(J+2)&31),J+=3;else $+=`\\${z}`,J+=2}return{text:$,end:Math.min(J+1,Z.length)}}function wZ(Z){let X="",$=0;while($<Z.length){let J=Z[$];if(J==="$"&&Z[$+1]==="'"){let z=j3(Z,$+2);X+=z.text,$=z.end;continue}if(J==="$"&&Z[$+1]==='"'){$++;continue}if(J==="\\"){if($+1<Z.length)X+=Z[$+1];$+=2;continue}if(J==="'"){let z=Z.indexOf("'",$+1);if(z===-1){X+=Z.slice($+1);break}X+=Z.slice($+1,z),$=z+1;continue}if(J==='"'){$++;while($<Z.length&&Z[$]!=='"'){if(Z[$]==="\\"&&$+1<Z.length){X+=Z[$+1],$+=2;continue}X+=Z[$],$++}$++;continue}X+=J,$++}return X}function Y0(Z){if(kZ(Z))return!0;let X=null;for(let $=0;$<Z.length;$++){let J=Z[$];if(X==="'"){if(J==="'")X=null;continue}if(J==="\\"){$++;continue}if(J==="`"||J==="$")return!0;if(J==='"'){X=X===null?'"':null;continue}if(X!==null)continue;if(J==="'")X="'";else if(J==="*"||J==="?")return!0;else if(J==="["&&W3(Z,$+1,"]"))return!0}return!1}function W3(Z,X,$){let J=null;for(let z=X;z<Z.length;z++){let Y=Z[z];if(J!=="'"&&Y==="\\")z++;else if(J===null&&Y===$)return!0;else if(Y==="'"&&J!=='"')J=J==="'"?null:"'";else if(Y==='"'&&J!=="'")J=J==='"'?null:'"'}return!1}function q3(Z){if(!Y0(Z))return!1;let X=XZ(Z);return X===null||X.some(($)=>wZ($).split(/[^A-Za-z0-9_]+/).some((J)=>z0.has(J)))}function OZ(Z){return xZ(wZ(Z))}var n0={deep:!0};function Q0(Z,X){return Z.replace(/\\([$`\\"])/g,($,J)=>J==='"'&&!X?$:J)}function N3(Z,X,$){let J=[],z=X+1;while(z<$-1){let Y=Z[z];if(Y==="\\"){z+=2;continue}if(Y==="`"){let Q=vZ(Z,z);if(Q<0)return null;J.push(Q0(Z.slice(z+1,Q-1),!0)),z=Q;continue}if(Y==="$"&&Z[z+1]==="("){let Q=zZ(Z,z+1);if(Q<0)return null;J.push(Z.slice(z+2,Q-1)),z=Q;continue}z++}return J}function _3(Z){let X=[],$=0;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==="`"){let z=vZ(Z,$);if(z<0)return null;X.push(Q0(Z.slice($+1,z-1),!1)),$=z;continue}if(J==="$"&&Z[$+1]==="("){let z=zZ(Z,$+1);if(z<0)return null;X.push(Z.slice($+2,z-1)),$=z;continue}$++}return X}function l0(Z,X,$,J){let z=X+1;for(let Y of $){let Q=Math.min(z,Z.length);for(;;){if(z>Z.length){z=Z.length+1;break}let K=Z.indexOf(`
4
- `,z),B=K===-1?Z.length:K,M=Z.slice(z,B).replace(/\r$/,"");if(Y.stripTabs)M=M.replace(/^\t+/,"");if(M===Y.delimiter)break;z=B+1}let H=Z.slice(Q,Math.min(z,Z.length));if(Y.owner.push(H),!Y.quoted){let K=_3(H);if(!K)return-1;J.push(...K)}if(z<=Z.length){let K=Z.indexOf(`
5
- `,z);z=(K===-1?Z.length:K)+1}}return Math.min(z-1,Z.length)}function a0(Z,X){let $=Z.indexOf("'",X+1);return $===-1?-1:$+1}function vZ(Z,X){let $=X+1;while($<Z.length){if(Z[$]==="\\"){$+=2;continue}if(Z[$]==="`")return $+1;$++}return-1}function o0(Z,X){let $=X+1;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==='"')return $+1;if(J==="`"){let z=vZ(Z,$);if(z<0)return-1;$=z;continue}if(J==="$"&&Z[$+1]==="("){let z=zZ(Z,$+1);if(z<0)return-1;$=z;continue}$++}return-1}function jZ(Z,X){if(Z[X]!=="<"||Z[X+1]!=="<"||Z[X+2]==="<")return null;let $=X+2,J=Z[$]==="-";if(J)$++;while(Z[$]===" "||Z[$]==="\t")$++;let z="",Y=!1;while($<Z.length&&!/[\s;|&<>()]/.test(Z[$])){let Q=Z[$];if(Q==="'"||Q==='"'){let H=Z.indexOf(Q,$+1);if(H<0)return null;z+=Z.slice($+1,H),Y=!0,$=H+1;continue}if(Q==="\\"){if($+1>=Z.length)return null;z+=Z[$+1],Y=!0,$+=2;continue}z+=Q,$++}return z?{delimiter:z,stripTabs:J,quoted:Y,end:$}:null}function hZ(Z,X,$){let J=X+1;for(let z of $)for(;;){if(J>Z.length)return-1;let Y=Z.indexOf(`
6
- `,J),Q=Y===-1?Z.length:Y,H=Z.slice(J,Q);if(H.endsWith("\r"))H=H.slice(0,-1);let K=z.stripTabs?H.length-H.replace(/^\t+/,"").length:0;if(z.stripTabs)H=H.slice(K);if(H===z.delimiter){J=Q+1;break}if(H.startsWith(z.delimiter)&&/^\s*\)/.test(H.slice(z.delimiter.length))){if(z===$[$.length-1])return J+K+z.delimiter.length;return-1}if(Y===-1)return-1;J=Y+1}return J-1}function zZ(Z,X){let $=Z.length,J=Z[X+1]==="(",z=0,Y=X,Q=[];while(Y<$){let H=Z[Y];if(H==="\\"){Y+=2;continue}if(H==="'"){let K=a0(Z,Y);if(K<0)return-1;Y=K;continue}if(H==='"'){let K=o0(Z,Y);if(K<0)return-1;Y=K;continue}if(H==="`"){let K=vZ(Z,Y);if(K<0)return-1;Y=K;continue}if(!J&&H==="<"&&Z[Y+1]==="<"){if(Z[Y+2]==="<"){Y+=3;continue}let K=jZ(Z,Y);if(!K)return-1;Q.push(K),Y=K.end;continue}if(H===`
7
- `&&Q.length>0){let K=hZ(Z,Y,Q);if(K<0)return-1;Q=[],Y=K;continue}if(!J&&H==="#"&&/[\s;&|(]/.test(Z[Y-1])){let K=Z.indexOf(`
8
- `,Y);if(K<0)return-1;Y=K;continue}if(H==="(")z++;else if(H===")"){if(z--,z===0)return Q.length>0?-1:Y+1}Y++}return-1}function i(Z,X={}){let $=X.deep===!0,J=[],z=[],Y=[],Q=new Set,H=[],K=[],B=-1,M=!1,V=!0,G=0,j=Z.length,D=(I)=>{if(B>=0){let W=Y.length;if(Y.push({text:Z.slice(B,I),start:B,end:I}),M)Q.add(W);B=-1,M=!1}},v=(I)=>{if(D(I),Y.length>0)J.push($?{words:Y,redirects:Q,heredocs:H}:{words:Y,redirects:Q});if(Y=[],Q=new Set,$)H=[];M=!1},w=(I)=>a0(Z,I),E=(I)=>vZ(Z,I),HZ=(I)=>zZ(Z,I),p=(I)=>o0(Z,I);while(G<j){let I=Z[G];if(I===" "||I==="\t"||I==="\r"){D(G),G++;continue}if(I===`
9
- `){if(v(G),K.length>0){let W=l0(Z,G,K,z);if(K=[],W<0)V=!1,G=j;else G=W;continue}G++;continue}if(I===";"){v(G),G++;continue}if(I==="&"){v(G),G+=Z[G+1]==="&"?2:1;continue}if(I==="|"){v(G),G+=Z[G+1]==="|"?2:1;continue}if($&&I==="("&&B>=0&&"?*+@!".includes(Z[G-1])){V=!1,G=j;continue}if(I==="("||I===")"){v(G),G++;continue}if(I==="<"&&Z[G+1]==="<"&&Z[G+2]!=="<"){let W=Z.slice(G+2).match(/^-?[ \t]*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/);if(!W){V=!1,G=j;continue}if($){let BZ=G+2+W[0].length;if(BZ<j&&!/[\s;&|()<>]/.test(Z[BZ])){V=!1,G=j;continue}D(G),K.push({delimiter:W[2],quoted:W[1]!=="",stripTabs:W[0].startsWith("-"),owner:H}),G=BZ;continue}let A=Z.indexOf(`
10
- `,G+2+W[0].length);if(A===-1){V=!1,G=j;continue}let h=Z.slice(A+1),k=I3(h,W[2]);if(k===-1){V=!1,G=j;continue}D(G),G=A+1+k+W[2].length;continue}if(I===">"||I==="<"){if(B>=0&&/^\d+$/.test(Z.slice(B,G)))B=-1;if(D(G),M=!0,G++,Z[G]===I||Z[G]==="&"||I===">"&&Z[G]==="|"||I==="<"&&Z[G]===">")G++;continue}if(I==="'"){if(B<0)B=G;let W=w(G);if(W<0)V=!1,G=j;else G=W;continue}if(I==='"'){if(B<0)B=G;let W=p(G),A=W<0||!$?[]:N3(Z,G,W);if(W<0||!A)V=!1,G=j;else z.push(...A),G=W;continue}if(I==="`"){if(B<0)B=G;let W=E(G);if(W<0)V=!1,G=j;else{let A=Z.slice(G+1,W-1);z.push($?Q0(A,!1):A),G=W}continue}if(I==="$"&&Z[G+1]==="("){if(B<0)B=G;let W=HZ(G+1);if(W<0)V=!1,G=j;else z.push(Z.slice(G+2,W-1)),G=W;continue}if(I==="\\"){if(B<0)B=G;if(G+1>=j)V=!1,G=j;else G+=2;continue}if(B<0)B=G;G++}if(v(j),K.length>0&&l0(Z,j,K,z)<0)V=!1;return{segments:J,trustworthy:V,substitutions:z}}function I3(Z,X){let $=0;while($<=Z.length){let J=Z.indexOf(X,$);if(J===-1)return-1;let z=J===0||Z[J-1]===`
11
- `,Y=J+X.length,Q=Y===Z.length||Z[Y]===`
12
- `||Z[Y]==="\r";if(z&&Q)return J;$=J+1}return-1}function y(Z){let X="",$=0;while($<Z.length){let J=Z[$];if(J==="\\"){if($+1<Z.length)X+=Z[$+1];$+=2;continue}if(J==="'"){let z=Z.indexOf("'",$+1);if(z===-1){X+=Z.slice($+1);break}X+=Z.slice($+1,z),$=z+1;continue}if(J==='"'){$++;while($<Z.length&&Z[$]!=='"'){if(Z[$]==="\\"&&$+1<Z.length){X+=Z[$+1],$+=2;continue}X+=Z[$],$++}$++;continue}X+=J,$++}return X}function l(Z){let X=0,$=0;while(X<Z.words.length&&$++<32){if(Z.redirects.has(X)){X++;continue}let J=Z.words[X].text,z=y(J);if(s0.test(z)&&!z.startsWith("-")){X++;continue}if(G3.has(z)){X++;continue}let Y=xZ(z);if(Y==="command")for(let H of Z.words.filter((K,B)=>B>X&&!Z.redirects.has(B))){let K=y(H.text);if(K==="--"||!K.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(K))return-1}let Q=Q3[Y];if(Q){let H=X;X++;while(X<Z.words.length){if(Z.redirects.has(X)){X++;continue}let B=y(Z.words[X].text);if(!B.startsWith("-")||B==="-")break;if(B==="--"){X++;break}if(Y==="env"&&(/^-[iv0]*S/.test(B)||/^--split-string(?:=|$)/.test(B)))return H;if(X++,Q.includes(B)||Y==="exec"&&/^-[cl]*a$/.test(B)){while(Z.redirects.has(X))X++;X++}}let K=K3[Y]??0;while(K>0&&X<Z.words.length){let B=y(Z.words[X].text);if(B.startsWith("-")&&B!=="-")break;X++,K--}continue}return X}return-1}function D3(Z,X){let $=[],J=!1;for(let z=X+1;z<Z.words.length;z++){if(Z.redirects.has(z))continue;let Y=y(Z.words[z].text);if(!J){if(Y==="--"){J=!0;continue}if(Y.startsWith("-")&&Y!=="-")continue}$.push(Z.words[z])}return $}function r0(Z){return X3.map((X)=>S.join(Z,...X.split("/")))}function C3(Z,X){if(Z==="~"||Z==="$HOME"||Z==="${HOME}")return X;if(Z.startsWith("~/"))return S.join(X,Z.slice(2));if(Z.startsWith("$HOME/"))return S.join(X,Z.slice(6));if(Z.startsWith("${HOME}/"))return S.join(X,Z.slice(8));return Z}function $0(Z,X,$){let J=y(Z);if(!J)return null;if(J.includes("`"))return null;if(J==="$HOME"||J==="${HOME}"||J==="$HOME/"||J==="${HOME}/")return $;if(J.replace(/\$\{HOME\}/g,"").replace(/\$HOME/g,"").includes("$"))return null;if(/[*?[\]]/.test(J))return null;if(J.startsWith("~")){let H=C3(J,$);if(H===J)return null;J=H}let Q=(S.isAbsolute(J)?S.normalize(J):S.resolve(X,J)).replace(/\/+$/,"");return Q===""?"/":Q}function UZ(Z,X){return Z===X||Z.startsWith(`${X}${S.sep}`)}function T3(Z,X){let $=`${S.join(X,".hasna","scratchpad","scratch")}${S.sep}`;if(!Z.startsWith($))return!1;let[J,z]=Z.slice($.length).split(S.sep);if(!J||!/^[a-z0-9][a-z0-9._-]{0,63}$/.test(J)||J.endsWith(".")||!z)return!1;let Y=z.normalize("NFKC").toLowerCase();return Y!=="meta.json"&&Y!==".lock"}function F3(Z,X){if(Z===X)return`\`${Z}\` is the home directory itself, which is never deleted or trashed. Delete a specific file or directory inside it instead.`;for(let $ of h0){if(Z!==$&&!UZ($,Z))continue;return $==="/"?`\`${Z}\` is the filesystem root, which is never deleted.`:`\`${Z}\` is the system root \`${$}\` (or an ancestor of it), which is never deleted or trashed.`}for(let $ of z3){let J=S.join(X,$);if($===".hasna"&&T3(Z,X))continue;if(!UZ(Z,J)&&!UZ(J,Z))continue;return`\`${Z}\` is the protected \`~/${$}\` path (or contains it), which is never deleted or trashed. Delete a specific file inside it, and only when you are sure.`}return null}function P3(Z,X,$){let J=r0($);if(J.some((z)=>UZ(X,z)))return!0;return Z.some((z)=>z!==null&&J.some((Y)=>UZ(z,Y)))}var m0=new WeakMap;function O3(Z){let X=m0.get(Z);if(X)return X;let $=Z.words.map((Q)=>wZ(Q.text)),J=$.findIndex((Q)=>Q==="-exec"||Q==="-execdir"||Q==="-ok"||Q==="-okdir"),z=-1;Z.words.forEach((Q,H)=>{if(d0.has(y(Q.text)))z=H});let Y={findDelete:$.includes("-delete"),findExecDelete:J>=0&&$.slice(J).some((Q)=>z0.has(xZ(Q))),namesDelete:$.some((Q)=>z0.has(xZ(Q))),lastFlockCommand:z,textMention:o(S3(Z)),envMention:o(LZ(Z.words.map((Q)=>y(Q.text)))),bodiesMention:o((Z.heredocs??[]).join(`
13
- `))};return m0.set(Z,Y),Y}var L3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]);function v3(Z,X){if(!L3.has(OZ(Z.words[X].text)))return!1;for(let $=X+1;$<Z.words.length;$++){if(Z.redirects.has($))continue;let J=y(Z.words[$].text);if(J==="--")return $+1>=Z.words.length;if(/^-[A-Za-z]*s/.test(J))return!0;if(/^-[A-Za-z]*c/.test(J))return!1;if(J==="-o"||J==="+o"||J==="-O"||J==="+O"){$++;continue}if(!/^[-+]/.test(J)||J==="-")return J==="-"}return!0}var J0=(Z)=>Z.kind==="rm"||Z.kind==="refuse",y3="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.",A3="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.",R3="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.",E3="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 t0(Z){let X=[];Z.words.forEach((z,Y)=>{if(!Z.redirects.has(Y))X.push(Y)});let $=X.map((z)=>{let Y=Z.words[z].text;return{text:wZ(Y),opaque:Y0(Y)}}),J=VZ($,B3);if(J===null)return null;return J.index<0?-1:X[J.index]}function X0(Z,X,$,J){let z=OZ(Z.words[X].text);if(z==="cd"){let H=Z.words[X+1];if(!H)return{kind:"none"};return{kind:"cd",cwd:$0(H.text,$,J.home)??J.cwd}}if(Object.hasOwn(Z0,z))return{kind:"refuse",reason:Z0[z]};if(z==="rm"){let H=D3(Z,X);if(H.length===0)return{kind:"none"};let K={word:Z.words[X],operands:H},B=r0(J.home),M=(j)=>j!==null&&B.some((D)=>UZ(j,D)),V=[],G=[];for(let j of H){let D=$0(j.text,$,J.home);if(V.push(D),!j.text.includes("{"))continue;let v=XZ(j.text);if(v===null)return{kind:"refuse",reason:A3};for(let w of v){let E=$0(w,$,J.home);if(E===null)continue;if(M(E)&&!M(D))return{kind:"refuse",reason:R3};G.push(E)}}if(P3(V,$,J.home))return K.cwdOnly=V.every((j)=>j!==null&&!M(j)),{kind:"rm",hit:K,handoff:!0,protectedReason:null};for(let j of[...V,...G]){if(!j)continue;let D=F3(j,J.home);if(D)return{kind:"rm",hit:K,handoff:!1,protectedReason:D}}return{kind:"rm",hit:K,handoff:!1,protectedReason:null}}if(M3.has(z)){let H=Z.words.findIndex((B,M)=>M>X&&!y(B.text).startsWith("-")),K=H>=0?OZ(Z.words[H].text):"";if(K==="rm"||Object.hasOwn(Z0,K))return{kind:"refuse",reason:`\`${z} ${K}\` runs the ${z} 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(z==="git"){let H=K0(Z,X);if(H==="rm"||H==="clean"){if(!(H==="rm"?b3(Z,X):e0(Z,X)))return{kind:"refuse",reason:H==="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 Y=O3(Z);if(z==="find"){if(Y.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(Y.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(z==="xargs"&&Y.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 Q=z==="flock"?Y.lastFlockCommand>X:d0.has(z);if(Y3.has(z)||Q){let H=v3(Z,X)?J.bodiesMention:Y.bodiesMention;if((z==="env"?Y.envMention:Y.textMention)||H)return{kind:"refuse",reason:`\`${Q?"flock":z}\` 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 yZ(Z,X){let $={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},J=i(Z,n0);$.trustworthy=J.trustworthy;let z={cwd:X.cwd,home:X.home,depth:X.depth??0,bodiesMention:o(J.segments.flatMap((K)=>K.heredocs??[]).join(`
14
- `))};if(!J.trustworthy)return $;let Y=[],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=z.cwd;for(let K of J.segments){let B=l(K),M=t0(K),V=B<0?{kind:"none"}:X0(K,B,H,z);if(V.kind!=="cd")Q(V);let G=(j)=>j!==null&&j>=0&&Y0(K.words[j].text);if(M===null||G(B)||G(M)){if(K.words.some((j,D)=>!K.redirects.has(D)&&(J0(X0(K,D,H,z))||q3(j.text))))Y.push({reason:y3})}else if(M>=0&&M!==B){let j=X0(K,M,H,z);if(J0(j))if(J0(V))Y.push({reason:E3});else Q(j,Y)}if(V.kind==="cd")H=V.cwd}if(z.depth<3)for(let K of J.substitutions){let B=yZ(K,{cwd:H,home:z.home,depth:z.depth+1});if(B.rmHits.length>0||B.refusals.length>0||B.handoffHits.length>0||B.protectedHits.length>0||!B.trustworthy&&o(K)){$.refusals.push({reason:"This command runs a delete inside a command substitution `$(…)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(J.substitutions.some((K)=>o(K)))$.refusals.push({reason:"This command nests a delete inside command substitutions deeper than this hook will follow. Run the delete as a separate `rm -- <path>` command."});return $.refusals.push(...Y),$}function S3(Z){return Z.words.map((X)=>X.text).join(" ")}function K0(Z,X){let $=X+1;while($<Z.words.length){let J=y(Z.words[$].text);if(!J.startsWith("-"))return J;if($++,V3.has(J))$++}return null}function b3(Z,X){if(Z.words.slice(X+1).map((J)=>y(J.text)).includes("--cached"))return!0;return e0(Z,X)}function e0(Z,X){let $=Z.words.slice(X+1).map((J)=>y(J.text));return $.includes("-n")||$.includes("--dry-run")}function p0(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function f3(Z,X,$,J){let z=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(p0).join(" "):`${p0($)} guard`,Y=[...X].sort((H,K)=>K.word.start-H.word.start),Q=Z;for(let H of Y)Q=`${Q.slice(0,H.word.start)}${z}${Q.slice(H.word.end)}`;return Q}function k3(Z,X,$,J,z){if(!X||X===Z)return!1;if($.length===0)return!1;let Y=yZ(X,{cwd:J,home:z});if(!Y.trustworthy)return!1;if(Y.rmHits.length>0||Y.handoffHits.length>0)return!1;return Y.refusals.length===0}function x3(Z,X){let $={};for(let[J,z]of Object.entries(Z??{}))$[J]=z;if($.command=X,typeof $.description!=="string"||$.description.trim()==="")$.description=J3;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=$3;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function w3(Z,X,$,J,z){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 k3(X,Z.command,$,J,z)}function h3(Z){let X=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return i(Z,n0).segments.some((J)=>{let z=t0(J);return[l(J),...z===null?[]:[z]].some((Y)=>{if(J.words.slice(0,Y<0?J.words.length:Y).some((K)=>s0.test(y(K.text))||X.has(OZ(K.text))))return!0;if(Y<0)return!1;let H=J.words[Y];return X.has(OZ(H.text))||/^\s*\(\s*\)\s*\{/.test(Z.slice(H.end))})})}function u(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function g3(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function u3(Z){try{if(Z.inspectTrash){let X=Z.inspectTrash();return X.ok?{path:X.path,error:null}:{path:null,error:`${X.code}: ${w0[X.code]}`}}return{path:Z.findTrash(),error:null}}catch(X){return{path:null,error:X instanceof Error?X.message:String(X)}}}var l3="[trash-guard] No verified @hasna/trash guard was found on PATH. This deletion is refused. Install the current @hasna/trash package with Bun and run its setup; the operating-system trash utility is not a compatible guard.";function Z2(Z,X){if(Z.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(Z.tool_name??"")){let B=Z.tool_input?.command;if(typeof B!=="string")return u("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(B))return u("[trash-guard] Delete File would bypass recoverable deletion. First use `trash put -- <path>` or the trash_put MCP tool, then submit any remaining edits without the deletion block.");return{continue:!0}}if(Z.tool_name!=="Bash")return{continue:!0};if(typeof Z.tool_input?.command!=="string")return u("[trash-guard] The Bash tool call carried no readable `command`, so this hook cannot verify what would run. Refusing a call it cannot verify. Re-run the delete explicitly as `rm -- <path>` so it can be redirected into trash.");let J=GZ(Z);if(!J.trim())return{continue:!0};let z=yZ(J,{cwd:X.cwd,home:X.home});if(z.refusals.length>0)return u(`[trash-guard] ${z.refusals[0].reason}`);if(z.protectedHits.length>0)return u(`[trash-guard] ${z.protectedHits[0].reason}`);if(!z.trustworthy)return o(J)?u("[trash-guard] This command could not be parsed to the end (unterminated quote, substitution or here-document), so a delete inside it cannot be redirected. Re-run the delete as a plain `rm -- <path>` command."):{continue:!0};if(z.rmHits.length===0){if(z.handoffHits.some((B)=>B.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.");if(z.handoffHits.length>0)return{continue:!0};return{continue:!0}}if(z.handoffHits.length>0)return u("[trash-guard] This command mixes a delete under the protected repo-checkout roots (owned by workspace-repos-guard) with a delete outside them, and a partial rewrite would leave one of them unredirected. Re-run them as separate commands, so each delete is handled by the hook that owns it.");let Y=u3(X);if(Y.error!==null)return u(`[trash-guard] The guard could not resolve the \`trash\` binary (${Y.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(Y.path===null)return u(l3);let Q=Y.path;if(X.execution&&h3(J))return u("[trash-guard] A deletion combined with shell environment changes cannot use the verified native execution context. Run the deletion as a separate plain rm command.");let H=f3(J,z.rmHits,Q,X.execution),K=x3(Z.tool_input,H);if(X.execution)K.hasna_execution="hasna.hooks.execution.v1";if(!w3(K,J,z.rmHits,X.cwd,X.home))return u("[trash-guard] The rewrite of this command did not verify (the delete could not be redirected cleanly), so the command is refused rather than run unredirected. Re-run the delete as a plain `rm -- <path>` command.");return g3(K)}var b=require("node:fs"),U0=require("node:os"),P=require("node:path");var m3=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),p3=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),c3=["hasna","hasnaxyz","hasna-products"],AZ="workspace-repos-guard";function i3(Z){return P.join(Z,".hasna","repos","clones")}function d3(Z){return P.join(Z,"workspace","repos")}function B2(Z){return[i3(Z),d3(Z)]}function s3(Z){return P.join(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var n3=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function H0(Z){let X=process.getuid?.();return X!==void 0&&(Z.uid===0||Z.uid===X)&&(Z.mode&18)===0}function a3(Z){let X=s3(Z),$;try{let z=b.openSync(X,b.constants.O_RDONLY|b.constants.O_NOFOLLOW);try{let Q=b.fstatSync(z);if(!Q.isFile()||!H0(Q)||Q.size>4096)return null;$=b.readFileSync(z,"utf8")}finally{b.closeSync(z)}let Y=P.normalize(Z);for(let Q=P.dirname(X);Q!==Y;Q=P.dirname(Q)){let H=b.lstatSync(Q);if(!H.isDirectory()||!H0(H)||Q===P.dirname(Q))return null}if(!H0(b.statSync(Y)))return null}catch{return null}let J=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return J.length>0&&J.every((z)=>n3.test(z))?new Set(J):null}function o3(Z=process.env,X=U0.homedir()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((J)=>J.trim()).filter(Boolean));return a3(X)??new Set(c3)}function B0(Z,X,$,J){if(J==="read")return{blocked:!1};let z=P.relative(X,Z);if(z===""){if(J==="delete")return{blocked:!0,reason:`[${AZ}] delete of the protected repo-checkout root is forbidden: ${X}`};return{blocked:!0,reason:`[${AZ}] writes directly to the protected repo-checkout root are forbidden: ${X}`}}if(z.startsWith(`..${P.sep}`)||z===".."||P.isAbsolute(z))return{blocked:!1};let Y=z.split(P.sep).filter(Boolean);if(J==="delete")return{blocked:!0,reason:`[${AZ}] delete under the protected repo-checkout root (${X}) is forbidden at any depth: ${Z}`};if(Y.length<=1)return{blocked:!0,reason:`[${AZ}] writing would create a top-level entry directly under the protected repo-checkout root (${X}); only GitHub-org folders belong there: ${Z}`};let Q=Y[0];if(!$.has(Q))return{blocked:!0,reason:`[${AZ}] '${Q}' is not an allowed GitHub org under the protected repo-checkout root (${X}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var M2=/\b(?:-o|--output|-O|--output-document|-out)\b/,r3=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,t3=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function G2(Z){return Z.replace(r3," ")}function e3(Z){let X=[],$=null,J=0,z=0,Y=!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]==="{"){z++,H++;continue}if(K==="}"&&z>0){z--;continue}if(K==="`"){Y=!Y;continue}if($==='"'){if(K==='"')$=null;continue}if(K==="'"||K==='"'){$=K;continue}if(K!=="|"||J>0||z>0||Y||Z[H-1]===">")continue;if(X.push(Z.slice(Q,H)),Z[H+1]==="&")H++;Q=H+1}if($||J!==0||z!==0||Y)return[Z];return X.push(Z.slice(Q)),X}function Z4(Z){let X=[],$="",J="",z=null,Y=!1,Q=()=>{if(!Y)return;let H=J.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),K=$.startsWith("~")&&!/^~(?:\/|$)/.test(J);X.push({text:K?`./${$}`:$,opaque:/[$\x60*?[]/.test(H)||/[()]/.test(H)||kZ(J)}),$="",J="",Y=!1};for(let H=0;H<Z.length;H++){let K=Z[H];if(z==="'"){if(K==="'")z=null;else $+=K;J+=K;continue}if(K==="\\"&&H+1<Z.length){let B=Z[H+1];$+=z==='"'&&!/[$\x60"\\\n]/.test(B)?K+B:B,J+=K+B,Y=!0,H++;continue}if(z==='"'){if(K==='"')z=null;else $+=K;J+=K;continue}if(/\s/.test(K)){Q();continue}if(Y=!0,J+=K,K==="'"||K==='"')z=K;else $+=K}if(z)J+="$";return Q(),X}function M0(Z,X,$){let J=Z[X];return J==="--help"||J==="--version"||$&&(J==="-h"||J==="-V")}var $2={read:0,write:1,delete:2};function gZ(...Z){return Z.reduce((X,$)=>$2[$]>$2[X]?$:X,"read")}var $4=new Set(["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"]),V2=new Set(["put","rm","delete","remove"]),J4=new Set([...V2,"restore","restore-capsule","recover","release","locks","retention","hold","unhold","pin","unpin","retrieve","backup-retrieve"]),U2=new Set(["-delete","-exec","-execdir","-ok","-okdir","-fls","-fprint","-fprint0","-fprintf"]);function X4(Z){let X=null;for(let $=0;$<Z.length;$++){let J=Z[$];if(X==="'"){if(J==="'")X=null;continue}if(J==="\\"){$++;continue}if(J==="$"||J==="`")return!0;if(X==='"'){if(J==='"')X=null;continue}if(J==="'"||J==='"')X=J;else if("*?[{".includes(J))return!0}return X!==null}function j2(Z){let X=Z.trim();if(!X)return"read";let $=i(X);if(!$.trustworthy||$.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(X))return YZ(X);let J=$.segments.flatMap((z)=>{let Y=J2(z),Q=z.words.filter((B,M)=>!z.redirects.has(M)).map((B)=>B.text),H=Q.map(XZ);if(H.every((B,M)=>B!==null&&B.length===1&&B[0]===Q[M]))return[Y];if(H.some((B)=>B===null))return[Y,YZ(Q.join(" "))];let K=i(H.flatMap((B)=>B??[]).join(" "));return[Y,...K.trustworthy?K.segments.map(J2):[YZ(Q.join(" "))]]});return gZ(...J)}function J2(Z){let X=Z.words.map((Y,Q)=>({word:Y,at:Q})).filter(({at:Y})=>!Z.redirects.has(Y)),$=l(Z),J=$<0?"read":X2(Z,$),z=VZ(X.map(({word:Y})=>({text:y(Y.text),opaque:/[$\x60]/.test(Y.text)})));if(z===null)return gZ(J,YZ(X.map(({word:Y})=>y(Y.text)).join(" ")));if(z.index<0||X[z.index].at===$)return J;return gZ(J,X2(Z,X[z.index].at))}function X2(Z,X){let $=Z.words.filter((Y,Q)=>Q>=X&&!Z.redirects.has(Q)),J=$.map((Y)=>y(Y.text)),z=J[0].split("/").pop();if(["rm","rmdir","shred"].includes(z??""))return M0(J,1,!1)?"read":"delete";if(["unlink","rmtree","del"].includes(z??""))return"delete";if(z==="trash"){let Y=1;while(Y<J.length&&J[Y].startsWith("-")){let Q=J[Y++];if(["--help","-h","--version","-V","--identity"].includes(Q))return"read";if(["--agent","--spool","--files","--info","--config"].includes(Q))Y++;else if(!["--json","--local"].includes(Q))return"delete"}if(Y===J.length||$4.has(J[Y]))return"read";if(J4.has(J[Y])&&M0(J,Y+1,!0))return"read";if(["restore","restore-capsule"].includes(J[Y]))return"write";return"delete"}if(z==="git"){let Y=K0(Z,X);if(Y==="clean"||Y==="rm")return J[1]===Y&&M0(J,2,!0)?"read":"delete";return Y==="clone"||Y==="init"?"write":"read"}if(z==="find"&&!$.some((Y)=>X4(Y.text))&&!J.some((Y)=>U2.has(Y)))return"read";if(z==="env"&&o(LZ(J)))return"delete";if(["sh","bash","zsh","dash","ksh","ash","eval","source",".","su","runuser","env","xargs","find","busybox","toybox"].includes(z??""))return YZ(J.join(" "));if(["mkdir","mkfile","touch","mv","cp","ln","tee","install","dd","rsync","scp","truncate"].includes(z??""))return"write";if(z==="curl"||z==="wget")return M2.test(J.join(" "))?"write":"read";if(z==="sed"&&J.slice(1).some((Y)=>/^-i|^--in-place(?:=|$)/.test(Y)))return"write";if(["python","python3","node","bun"].includes(z??"")&&J.some((Y)=>Y==="-c"||Y==="-e"))return"write";return"read"}function YZ(Z){let X=Z.replace(/[{},]/g," ");return X===Z?G0(Z):gZ(G0(Z),G0(X))}function G0(Z){let X=Z.trim();if(!X)return"read";if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:rm|rmdir|unlink|shred|trash|rmtree|del)(?:\s|$)/.test(X))return"delete";if(/\bgit\b/.test(X)){if(/\bgit\b[^;&|]*\b(?:clean|rm)\b/.test(X))return"delete";if(/\bgit\b[^;&|]*\b(?:clone|init)\b/.test(X))return"write";return"read"}if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|mv|cp|ln|tee|install|dd)(?:\s|$)/.test(X))return"write";if(/\b(?:curl|wget)\b/.test(X)){if(M2.test(X))return"write";return"read"}if(/\bsed\b/.test(X)){if(/(?:^|\s)-i\S*(?:\s|$)|--in-place(?:\s|$)/.test(X))return"write"}else if(/\b(?:rsync|scp|truncate)\b/.test(X))return"write";else if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(X))return"write";if(/(?:^|[;&|])\s*echo\b/.test(X)||/>/.test(G2(X)))return"write";return"read"}function RZ(Z,X){let $=Z.trim(),J=$.match(/^(['"])([\s\S]*)\1$/);if(J)$=J[2];if($=$.replace(/^"*\$HOME"*\//,"$HOME/"),$=$.replace(/^"*\$\{HOME\}"*\//,"${HOME}/"),$==="~")return X;if($.startsWith("~/"))return P.join(X,$.slice(2));if($==="$HOME"||$==="${HOME}")return X;if($.startsWith("$HOME/"))return P.join(X,$.slice(6));if($.startsWith("${HOME}/"))return P.join(X,$.slice(8));let z=$.match(new RegExp(`^"*${V0(X)}"*/`));if(z)return X+"/"+$.slice(z[0].length);return Z}function z4(Z){let X=Z.trim();while(X.startsWith("(")||/^\{(?:\s|$)/.test(X))X=X.slice(1).trim();while(X.endsWith(")")||/(?:^|\s)\}$/.test(X))X=X.slice(0,-1).trim();return X}function V0(Z){return Z.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function z2(Z,X,$){if(Z===void 0)return[$];let J=RZ(Z,$),z=J.match(/^(['"])(.*)\1$/);if(z)J=z[2];if(!J||J==="-"||/[$\x60*?[\]{}~\\'"]/.test(J))return null;return[...new Set(X.map((Y)=>P.resolve(Y,J)))]}var Y4=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function Q4(Z,X){let $=VZ(X);if(!$||$.index<=0||X[$.index].opaque)return 0;let J=i(Z);if(!J.trustworthy||J.substitutions.length>0||J.segments.length!==1)return 0;let[z]=J.segments;if(z.redirects.size>0||z.words.length!==X.length)return 0;if(z.words.some((Y,Q)=>y(Y.text)!==X[Q].text))return 0;return l(z)===$.index?$.index:0}function K4(Z,X){let $=0;if(Z==="git")$=X.findIndex((z)=>z.text==="rm"||z.text==="clean")+1;let J=!1;return X.slice($).filter((z)=>{if(!J&&z.text==="--")return J=!0,!1;if(!J&&z.text.startsWith("-")&&!z.opaque)return!1;return J=!0,!0})}var H4=new Set(["--agent","--spool","--files","--info","--config"]),B4=new Set(["--spool","--files","--info","--config"]),M4=new Set(["--json","--local","--help","-h","--version","--identity"]),Y2={"--agent":/^[^-]/,"--retention":/^(?:\d+(?:\.\d+)?|never)$/},G4=new Set(["--to"]);function V4(Z){let X=[],$=0;for(;$<Z.length&&Z[$].text.startsWith("-");$++){let Y=Z[$];if(Y.opaque)return null;if(H4.has(Y.text)){let Q=Z[++$];if(!Q||Q.opaque)return null;if(B4.has(Y.text))X.push(Q)}else if(!M4.has(Y.text))return null}let J=Z[$];if(!J||J.opaque||!V2.has(J.text))return null;let z=!1;for($++;$<Z.length;$++){let Y=Z[$];if(z||Y.opaque||Y.text==="-"||!Y.text.startsWith("-")){X.push(Y);continue}if(Y.text==="--"){z=!0;continue}let Q=Y.text.indexOf("="),H=Q<0?Y.text:Y.text.slice(0,Q);if(G4.has(H)){if(Q>=0)X.push({text:Y.text.slice(Q+1),opaque:!1});else if(Z[$+1]&&!Z[$+1].text.startsWith("-"))X.push(Z[++$]);continue}let K=Z[$+1];if(Q<0&&Object.hasOwn(Y2,H)&&K&&!K.opaque&&Y2[H].test(K.text))$++}return X}function U4(Z){let X=Z.split(`
15
- `),$=[],J=[],z=0;while(z<X.length){let Y=z,Q=X[z++].replace(/\r$/,""),H=[];for(let K=0;K<Q.length;K++){let B=Q[K],M=J[J.length-1];if(B==="\\"){K++;continue}if(B==="$"&&Q[K+1]==="("&&Q[K+2]==="("){let V=Q.indexOf("))",K+3);if(V<0)return null;K=V+1;continue}if(B==="$"&&Q[K+1]==="("){J.push(0),K++;continue}if(B==="$"&&Q[K+1]==="[")return null;if(B==="$"&&Q[K+1]==="{"){let V=Q.indexOf("}",K+2);if(V<0||/['"\x60$]|<</.test(Q.slice(K+2,V)))return null;K=V;continue}if(B==="`"){let V=Q.indexOf("`",K+1);if(V<0)return null;K=V;continue}if(M==='"'){if(B==='"')J.pop();continue}if(B==="'"){let V=Q.indexOf("'",K+1);if(V<0)return null;K=V;continue}if(B==='"'){J.push('"');continue}if(B==="#"&&(K===0||/[\s;&|()]/.test(Q[K-1])))break;if(B==="("&&Q[K+1]==="("&&(K===0||/[\s;&|(]/.test(Q[K-1]))){let V=Q.indexOf("))",K+2);if(V<0)return null;K=V+1;continue}if(typeof M==="number"&&(B==="("||B===")")){if(B==="(")J[J.length-1]=M+1;else if(M===0)J.pop();else J[J.length-1]=M-1;continue}if(B==="<"&&Q[K+1]==="<"){if(Q[K+2]==="<"){K+=2;continue}let V=jZ(Q,K);if(!V)return null;H.push({marker:V,from:K}),K=V.end-1}}for(let{marker:K,from:B}of H){let M=z;for(;;){if(z>=X.length)return null;let V=X[z++].replace(/\r$/,"");if(K.stripTabs)V=V.replace(/^\t+/,"");if(V===K.delimiter)break}$.push({line:Y,from:B,to:K.end,start:M,end:z-1,quoted:K.quoted})}}return J.length===0?$:null}var j4=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"]),W4=new Set([".","source","eval","env","alias","hash"]),q4=new Set(["tee","cp","mv","install","ln"]),W2=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"]),N4=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),_4=new Set(["pr","issue","api","release","gist"]);function I4(Z,X){let $=Z[X];if($==="gh")return _4.has(Z[X+1]??"");if($!=="git")return W2.has($);for(let J=X+1;J<Z.length;J++){let z=Z[J];if(z==="-C")J++;else if(z==="--no-pager"||z==="-P")continue;else return!z.startsWith("-")&&N4.has(z)}return!1}function D4(Z,X){for(let $=X+1;$<Z.length;$++){let J=Z[$];if(J==="\\")$++;else if(J==='"')return $;else if(J==="$"&&Z[$+1]==="("){if($=q2(Z,$+1),$<0)return-1}else if(J==="`"){if($=Z.indexOf("`",$+1),$<0)return-1}}return-1}function q2(Z,X){let $=0;for(let J=X;J<Z.length;J++){let z=Z[J];if(z==="\\")J++;else if(z==="'"||z==="`"){if(J=Z.indexOf(z,J+1),J<0)return-1}else if(z==='"'){if(J=D4(Z,J),J<0)return-1}else if(z==="(")$++;else if(z===")"&&--$===0)return J}return-1}function C4(Z){let X=[],$=!1;for(let J=0;J<Z.length;J++){let z=Z[J];if(z==="\\")J++;else if(z==="'"&&!$){let Y=Z.indexOf("'",J+1);if(Y<0)return null;J=Y}else if(z==='"')$=!$;else if(z==="$"&&Z[J+1]==="("){let Y=q2(Z,J+1);if(Y<0)return null;let Q=Z.slice(J+2,Y);if(Z[J+2]==="("){if(/\$\(|\x60/.test(Q))return null}else X.push(Q);J=Y}else if(z==="`"){let Y=Z.indexOf("`",J+1);if(Y<0)return null;X.push(Z.slice(J+1,Y)),J=Y}}return $?null:X}function T4(Z){if(/[<>]\(/.test(Z))return!0;let X=[],$=[Z];for(let z=0;$.length>0;z++){if(z>64)return!0;let Y=$.shift(),Q=i(Y),H=C4(Y);if(!Q.trustworthy||!H)return!0;X.push(...Q.segments),$.push(...new Set([...Q.substitutions,...H]))}let J=new Set;for(let z of X){let Y=z.words.map((K)=>y(K.text));for(let K of z.redirects)J.add(s(Y[K]??""));let Q=l(z);if(Q<0)continue;let H=s(Y[Q]);if(q4.has(H)){for(let K of Y.slice(Q+1))if(!K.startsWith("-"))J.add(s(K))}if(H==="dd"){for(let K of Y)if(K.startsWith("of="))J.add(s(K.slice(3)))}}J.delete("");for(let z of X){for(let B of z.words){let M=s(y(B.text));if(j4.has(M)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(M))return!0}let Y=l(z),Q=z.words.map((B,M)=>({text:y(B.text),at:M})).filter(({at:B})=>!z.redirects.has(B));if(Q.some(({text:B,at:M})=>(Y<0||M<Y)&&PZ.test(B)))return!0;if(Y<0)continue;let H=z.words[Y].text,K=y(H);if(/[$\x60]/.test(H)||K.includes("/")||W4.has(K)||J.has(K))return!0;if(!I4(Q.filter(({at:B})=>B>=Y).map(({text:B})=>B),0))return!0}return!1}function F4(Z){if(!Z.includes("<<"))return null;let X=U4(Z);if(!X||X.length===0)return null;let $=Z.split(`
16
- `),J=[...$],z=[];for(let Q of X){let H=$.slice(Q.start,Q.end);if(!Q.quoted&&H.some((K)=>/\$\(|\x60/.test(K)))return null;z.push(H.join(`
17
- `));for(let K=Q.start;K<=Q.end;K++)J[K]=""}let Y=[...J];for(let Q of[...X].reverse()){let H=Y[Q.line];Y[Q.line]=H.slice(0,Q.from)+" ".repeat(Q.to-Q.from)+H.slice(Q.to)}return T4(Y.join(`
18
- `))?null:{outer:J.join(`
19
- `),bodies:z}}var P4="/";function N2(Z,X,$){if(!Z)return[];let J=F4(Z);if(!J)return H2(Z,X,$);return[...H2(J.outer,X,$),...J.bodies.flatMap((z)=>N2(z,X,P4))]}var O4=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,L4=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function v4(Z,X){let $=[],J=0;for(let Q of X)$.push(J),J+=Q.length;let z=i(Z);if(!z.trustworthy||z.substitutions.length>0)return null;let Y=z.segments.flatMap((Q)=>Q.words).filter((Q)=>X.some((H,K)=>K%2===1&&$[K]<Q.end&&$[K]+H.length>Q.start));return Y.length>0?{lexed:z,offsets:$,words:Y}:null}function Q2(Z,X,$=[]){if(j2(X)!=="read")return!1;let J=l(Z),z=Z.words.filter((M,V)=>!Z.redirects.has(V)),Y=VZ(z.map((M)=>({text:y(M.text),opaque:/[$\x60]/.test(M.text)})));if(Y===null)return!1;let Q=[J<0?1/0:J,Y.index<0?1/0:Z.words.indexOf(z[Y.index])];if(Z.words.some((M,V)=>V<Math.max(...Q)&&!Z.redirects.has(V)&&PZ.test(y(M.text))))return!1;if([J<0?null:Z.words[J].text,Y.index<0?null:z[Y.index].text].every((M)=>M===null||W2.has(s(y(M)))))return!0;let K=z.filter((M)=>!$.includes(M)),B=K.map((M)=>y(M.text));return YZ(K.map((M)=>M.text).join(" "))==="read"&&YZ(B.join(" "))==="read"&&!B.some((M)=>U2.has(M))}var K2=(Z,X)=>Z.slice(X.words[0].start,X.words[X.words.length-1].end);function y4(Z,X,$,J){let z=(Q)=>Q.start<J&&Q.end>$,Y=X.words.filter(z);if(Y.length===0||Y.some((Q)=>!L4.test(Q.text)))return!1;for(let Q of X.lexed.segments.filter((H)=>H.words.some(z)))if(!Q2(Q,K2(Z,Q),X.words))return!1;for(let Q of Y){let H=Q.text.slice(1,-1);if(H.includes("<<"))return!1;let K=i(H);if(!K.trustworthy||K.substitutions.length>0)return!1;if(!K.segments.every((B)=>Q2(B,K2(H,B))))return!1}return!0}function H2(Z,X,$){if(!Z)return[];let J=B2(X),z=(G)=>J.some((j)=>G===j||G.startsWith(`${j}${P.sep}`)),Y=Z.split(O4),Q=v4(Z,Y),H=[],K=[$],B=new Set([$]),M=!0,V=[];for(let G=0;G<Y.length;G+=2){let j=G===0?"":Y[G-1].trim();if(j==="||")M=!1;else if(j!=="&&")M=!0;if(j!=="&&"||!M)K=[...B];let D=Y[G],v=(D.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,w=(D.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let C=0;C<v;C++)V.push({current:[...K],reachable:new Set(B),certain:M});let E=z4(D),HZ=Q!==null&&y4(Z,Q,Q.offsets[G],Q.offsets[G]+D.length),p=E.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),I=p?null:E.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(I){for(let C of z2(I[1],K,X)??[])B.add(C);M=!1,K=[...B]}let W=V0(X),A=J.map((C)=>V0(C.slice(X.length+1))).join("|"),h=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${W}"*)/(?:${A})`),k=new RegExp(`(${h.source})([^\\s"';&|<>()\`]*|$)`,"g"),BZ=(C)=>{let d=[],g;k.lastIndex=0;while((g=k.exec(C))!==null)d.push(P.normalize(RZ(g[0],X)).replace(/\/+$/,""));return d},nZ=e3(E).map((C)=>{let d=[],g=!1,NZ=G2(C).replace(t3,(aZ,JZ)=>{if(!JZ||/[$\x60]/.test(JZ))g=!0;if(JZ)d.push(JZ);return" "}),_Z=HZ?"read":j2(NZ);return{commandPart:NZ,operands:d,op:g&&_Z==="read"?"write":_Z}}),w2=nZ.some((C)=>C.op==="delete")?"delete":nZ.some((C)=>C.op==="write")?"write":"read",b0=K.filter(z);for(let C of nZ){let d=!1;for(let x of BZ(C.commandPart))d=!0,H.push({path:x,op:w2});for(let x of C.operands){let r=BZ(x);for(let c of r)H.push({path:c,op:"write"});if(r.length>0)continue;for(let c of b0)H.push({path:P.normalize(P.resolve(c,RZ(x,X))),op:"write"})}if(d||C.op==="read")continue;let g=Z4(C.commandPart),NZ=Q4(C.commandPart,g),_Z=s(g[NZ]?.text??""),aZ=g.slice(NZ+1),JZ=((_Z==="trash"?V4(aZ):null)??K4(_Z,aZ)).map((x)=>x.opaque?".":x.text),h2=C.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(C.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(C.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(C.commandPart),IZ=[];if(h2)for(let x of JZ.length>0?JZ:["."])IZ.push({operand:x,op:C.op});else{let x=C.commandPart.match(Y4),r=g.at(-1);if(IZ.push({operand:x?x[1]:!r||r.opaque?".":r.text,op:C.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(C.commandPart))g.forEach((c,f0)=>{let MZ,oZ=c.text.match(/^-[A-Za-z]*?t(.*)$/),SZ=c.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(oZ&&!c.text.startsWith("--"))MZ=oZ[1]?{text:oZ[1],opaque:c.opaque}:g[f0+1];else if(SZ&&"--target-directory".startsWith(SZ[1]))MZ=SZ[2]!==void 0?{text:SZ[2],opaque:c.opaque}:g[f0+1];if(MZ)IZ.push({operand:MZ.opaque||!MZ.text?".":MZ.text,op:C.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(C.commandPart))IZ.push({operand:".",op:C.op})}for(let x of b0)for(let{operand:r,op:c}of IZ)H.push({path:P.normalize(P.resolve(x,RZ(r,X))),op:c})}if(p){let C=z2(p[1],K,X);if(C){for(let d of C)B.add(d);if(M)K=C}else M=!1}for(let C=0;C<w&&V.length>0;C++)({current:K,reachable:B,certain:M}=V.pop())}return H}var A4=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function R4(Z,X){let $=[],J;while((J=A4.exec(Z))!==null){let z=J[1]==="Delete File"?"delete":"write";$.push({path:P.normalize(P.resolve(X,J[2])),op:z})}return $}function _2(Z,X={}){let $=[];if(Z.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:$};let J=typeof Z.tool_name==="string"?Z.tool_name:"",z=X.home??U0.homedir(),Y=B2(z),Q=o3(process.env,z);if(J==="Bash"){let G=GZ(Z);if(!G)return{output:{continue:!0},warnings:$};let j=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd(),D=N2(G,z,j);for(let v of D)for(let w of Y){let E=B0(v.path,w,Q,v.op);if(E.blocked)return{output:{decision:"block",reason:E.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let H=Z.tool_input??{},K=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(p3.has(J)){let G=typeof H.patch==="string"?H.patch:"";if(!G)return{output:{continue:!0},warnings:$};let j=R4(G,K);for(let D of j)for(let v of Y){let w=B0(D.path,v,Q,D.op);if(w.blocked)return{output:{decision:"block",reason:w.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!m3.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=RZ(B,z),V=P.isAbsolute(M)?P.normalize(M):P.resolve(K,M);for(let G of Y){let j=B0(V,G,Q,"write");if(j.blocked)return{output:{decision:"block",reason:j.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var E4=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"]),S4=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),T2=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"]),F2=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"]),b4=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),f4=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class q0 extends Error{}var O=()=>{throw new q0};function j0(Z,X){let $=[],J="",z=X+1;while(z<Z.length){let Y=Z[z];if(Y==='"'){if(J)$.push(J);return{end:z+1,parts:$}}if(Y==="\\"){let Q=Z[z+1];if(Q==="("){let H=1,K=z+2;while(K<Z.length&&H>0){let B=Z[K];if(B==='"'){K=j0(Z,K).end;continue}if(B==="(")H++;else if(B===")")H--;K++}if(H!==0)O();if(J)$.push(J),J="";$.push({src:Z.slice(z+2,K-1)}),z=K;continue}if(Q===void 0)O();J+=Q,z+=2;continue}J+=Y,z++}return O()}function P2(Z){let X=[],$=0,J=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let z=Z[$];if(/\s/.test(z)){$++;continue}if(z==="#")O();if(z==='"'){let K=j0(Z,$);X.push({t:"str",parts:K.parts}),$=K.end;continue}if(z==="."){if(Z[$+1]===".")O();let K=/^[A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($+1));if(K){X.push({t:"field",name:K[0]}),$+=1+K[0].length;continue}if(Z[$+1]==='"'){let B=j0(Z,$+1);if(B.parts.some((M)=>typeof M!=="string"))O();X.push({t:"field",name:B.parts.join("")}),$=B.end;continue}X.push({t:"dot"}),$++;continue}if(z==="$"||z==="@"){let K=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($));if(!K||z==="$")O();X.push({t:"fmt",name:K[0]}),$+=K[0].length;continue}let Y=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(Z.slice($));if(Y){X.push({t:"num"}),$+=Y[0].length;continue}let Q=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(Z.slice($));if(Q){X.push({t:"ident",name:Q[0]}),$+=Q[0].length;continue}let H=J.find((K)=>Z.startsWith(K,$));if(!H)O();X.push({t:"op",v:H}),$+=H.length}return X}var k4=new Set(["if","then","elif","else","end","as","def","reduce","foreach","try","catch","label","import","include","and","or","__loc__","error","input","inputs","debug","stderr","env","halt","halt_error","input_filename","input_line_number","recurse","paths","leaf_paths","getpath","setpath","delpaths","del","path","splits","sub","gsub","capture","match","scan","keys","keys_unsorted","map_values","with_entries","tostream","fromstream","truncate_stream","walk","tonumber","implode","explode","ascii","fromjson"]);class N0{tokens;at=0;constructor(Z){this.tokens=Z}parse(){if(this.tokens.length===0)O();let Z=this.pipe();if(this.at!==this.tokens.length)O();return Z}peek(){return this.tokens[this.at]}isOp(Z){let X=this.peek();return!!X&&X.t==="op"&&X.v===Z}isIdent(Z){let X=this.peek();return!!X&&X.t==="ident"&&X.name===Z}expectOp(Z){if(!this.isOp(Z))O();this.at++}pipe(){let Z=this.comma();if(this.isIdent("as"))O();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 X of["==","!=","<=",">=","<",">"])if(this.isOp(X))return this.at++,{k:"bool",a:Z,b:this.add()};for(let X of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(X))O();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 X=this.peek();if(!X)return Z;if(X.t==="field"){this.at++,Z={k:"field",name:X.name,of:Z};continue}if(X.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(X.t==="op"&&X.v==="?"){this.at++,Z={k:"opt",of:Z};continue}if(X.t==="op"&&X.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 X=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:X}}primary(){let Z=this.peek();if(!Z)return O();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(!f4.has(Z.name))O();let X=this.peek();if(X?.t==="str")return this.at++,{k:"fmt",name:Z.name,str:this.stringNode(X.parts)};return{k:"fmt",name:Z.name}}case"ident":{if(k4.has(Z.name))O();if(Z.name==="map"||T2.has(Z.name)||F2.has(Z.name)){let X=[];if(this.isOp("(")){this.at++,X.push(this.pipe());while(this.isOp(";"))this.at++,X.push(this.pipe());this.expectOp(")")}return{k:"call",name:Z.name,args:X}}return O()}case"op":{if(Z.v==="("){let X=this.pipe();return this.expectOp(")"),X}if(Z.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let X=this.pipe();return this.expectOp("]"),{k:"array",of:X}}if(Z.v==="{")return this.object();return O()}}return O()}stringNode(Z){let X=[];for(let $ of Z){if(typeof $==="string")continue;X.push(new N0(P2($.src)).parse())}return X.length===0?{k:"str",parts:X,text:Z.join("")}:{k:"str",parts:X}}object(){let Z=[];if(this.isOp("}"))return this.at++,{k:"object",entries:Z};for(;;){let X=this.peek();if(!X)O();this.at++;let $;if(X.t==="ident")$=X.name;else if(X.t==="str"){if(X.parts.some((J)=>typeof J!=="string"))O();$=X.parts.join("")}else O();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 _0(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(_0);return Z==="safe"||typeof Z==="object"&&E4.has(Z.leaf)}var EZ=(...Z)=>Z.every(_0)?"safe":"tainted";function W0(...Z){let X=[];for(let $ of Z)if(typeof $==="object"&&"union"in $)X.push(...$.union);else X.push($);return X.length===1?X[0]:{union:X}}function uZ(Z,X){return typeof Z==="object"&&"union"in Z?W0(...Z.union.map(X)):X(Z)}var lZ=(Z)=>typeof Z==="object"&&("leaf"in Z)&&S4.has(Z.leaf),e=(Z)=>uZ(Z,(X)=>X==="safe"?"safe":X==="tainted"||lZ(X)?"tainted":"unknown");function I2(Z){return Z.k==="lit"||Z.k==="str"&&Z.parts.length===0||Z.k==="call"&&["true","false","null"].includes(Z.name)&&Z.args.length===0}function D2(Z,X,$){return uZ(Z,(J)=>{if(J==="safe"||J==="tainted")return J;if(lZ(J))return"tainted";if(J==="root"&&$.rootScalars.has(X))return"safe";return{leaf:X}})}function L(Z,X,$){switch(Z.k){case"dot":return X;case"field":return D2(Z.of?L(Z.of,X,$):X,Z.name,$);case"iter":return e(L(Z.of,X,$));case"index":{let J=L(Z.of,X,$);if(Z.key.k==="str"&&Z.key.text!==void 0)return D2(J,Z.key.text,$);if(Z.key.k==="lit")return e(J);return L(Z.key,X,$),"tainted"}case"slice":return uZ(L(Z.of,X,$),(J)=>J==="root"?"unknown":lZ(J)?"tainted":J);case"opt":return L(Z.of,X,$);case"lit":return"safe";case"str":return EZ(...Z.parts.map((J)=>L(J,X,$)));case"fmt":return Z.str?L(Z.str,X,$):X;case"array":return Z.of?EZ(L(Z.of,X,$)):"safe";case"object":return EZ(...Z.entries.map((J)=>L(J.value,X,$)));case"pipe":return L(Z.b,L(Z.a,X,$),$);case"comma":return W0(L(Z.a,X,$),L(Z.b,X,$));case"alt":return W0(L(Z.a,X,$),L(Z.b,X,$));case"bool":return L(Z.a,X,$),L(Z.b,X,$),"safe";case"arith":return EZ(L(Z.a,X,$),L(Z.b,X,$));case"neg":return L(Z.of,X,$);case"call":return x4(Z,X,$)}}var C2=(Z)=>uZ(Z,(X)=>X==="root"?"unknown":lZ(X)?"tainted":X);function x4(Z,X,$){let{name:J,args:z}=Z;if(b4.has(J)&&J!=="limit"&&!z.every(I2))O();switch(J){case"map":if(z.length!==1)O();return EZ(L(z[0],e(X),$));case"select":if(z.length!==1)O();return L(z[0],X,$),X;case"limit":if(z.length!==2||!I2(z[0]))O();return L(z[1],X,$);case"first":case"last":if(z.length>1)O();return z.length===1?L(z[0],X,$):e(X);case"min":case"max":return e(X);case"sort_by":case"group_by":case"unique_by":if(z.length!==1)O();return L(z[0],e(X),$),C2(X);case"min_by":case"max_by":if(z.length!==1)O();return L(z[0],e(X),$),e(X);case"any":case"all":case"isempty":for(let Y of z)L(Y,"unknown",$);return"safe"}if(T2.has(J))return"safe";if(F2.has(J))return C2(X);return O()}function O2(Z,X={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new N0(P2(Z)).parse();return _0(L($,"root",{rootScalars:X.rootScalars??new Set}))}catch($){if($ instanceof q0)return!1;return!1}}var v0="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",_={refused:!1},N=(Z)=>({refused:!0,rule:Z}),I0=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"]),D0=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),L2=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),v2=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),w4=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),h4=new Set(["author","committer","id","parents","repository","sha","url"]),g4=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function R2(Z){let X=[];for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="\\"){$++;continue}if(J==="'"){let z=Z.indexOf("'",$+1);if(z<0)return!1;$=z;continue}if(J==='"'){$++;while($<Z.length&&Z[$]!=='"')$+=Z[$]==="\\"?2:1;continue}if(J==="{"){X.push({list:!1});continue}if(X.length===0)continue;if(J===","||J==="."&&Z[$+1]===".")X[X.length-1].list=!0;else if(J==="}"&&X.pop().list)return!0}return!1}function WZ(Z){let X="",$=!1,J=0,z=(Y)=>Z[Y]==="`"||Z[Y]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(Z[Y+1]??"");while(J<Z.length){let Y=Z[J];if(Y==="\\"){X+=Z[J+1]??"",J+=2;continue}if(Y==="$"&&Z[J+1]==="'"){$=!0,X+=Y,J++;continue}if(Y==="'"){let Q=Z.indexOf("'",J+1);if(Q<0){$=!0,X+=Z.slice(J+1);break}X+=Z.slice(J+1,Q),J=Q+1;continue}if(Y==='"'){J++;while(J<Z.length&&Z[J]!=='"'){if(Z[J]==="\\"&&/[$`"\\\n]/.test(Z[J+1]??"")){X+=Z[J+1],J+=2;continue}if(z(J))$=!0;X+=Z[J],J++}if(J>=Z.length)$=!0;J++;continue}if(z(J)||Y==="*"||Y==="?"||Y==="[")$=!0;X+=Y,J++}if(!$&&Z.includes("{")&&R2(Z))$=!0;return{value:X,opaque:$,raw:Z}}var QZ=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function F0(Z,X="word"){let $=[],J=!1;for(let z=0;z<Z.length;z++){let Y=Z[z];if(Y==="\\"){z++;continue}if(X==="word"&&Y==="'"&&!J){let Q=Z.indexOf("'",z+1);if(Q<0)return{bodies:$,complete:!1};z=Q;continue}if(X==="word"&&Y==='"'){J=!J;continue}if(Y==="`"){let Q=z+1;while(Q<Z.length&&Z[Q]!=="`")Q+=Z[Q]==="\\"?2:1;if(Q>=Z.length)return{bodies:$,complete:!1};$.push(Z.slice(z+1,Q)),z=Q;continue}if(Y==="$"&&Z[z+1]==="("){let Q=zZ(Z,z+1);if(Q<0)return{bodies:$,complete:!1};$.push(Z.slice(z+2,Q-1)),z=Q-1}}return{bodies:$,complete:!0}}function qZ(Z,X){let $=new Set(X.values),J={flags:[],positionals:[]},z=(Y,Q)=>({value:Y,opaque:Q.opaque,raw:Q.raw});for(let Y=0;Y<Z.length;Y++){let Q=Z[Y],H=Q.value;if(H==="--"){J.positionals.push(...Z.slice(Y+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:z(H.slice(K+1),Q),inline:!0});else if($.has(B)){let M=Z[Y+1];J.flags.push(M?{name:B,value:M}:{name:B,missing:!0}),Y++}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:z(M.slice(1),Q),inline:!0});break}if(!$.has(B)){J.flags.push({name:B});continue}if(M)J.flags.push({name:B,value:z(M,Q),inline:!0});else{let V=Z[Y+1];J.flags.push(V?{name:B,value:V}:{name:B,missing:!0}),Y++}break}continue}J.positionals.push(Q)}return J}function f(Z,...X){let $=!1;for(let J of Z.flags){if(!X.includes(J.name))continue;if(!J.inline){$=!0;continue}let z=J.value;$=!z.opaque&&["1","t","T","TRUE","true","True"].includes(z.value)}return $}var $Z=(Z,...X)=>Z.flags.filter(($)=>X.includes($.name)),m=["-R","--repo","-q","--jq","-t","--template","--json"],KZ={"pr view":{values:m},"issue view":{values:m},"release view":{values:m},"discussion view":{values:[...m,"--after","-L","--limit","--order"]},"pr list":{values:[...m,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...m,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...m,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...m,"-L","--limit","-O","--order"]},"pr status":{values:m},"issue status":{values:m},"pr checks":{values:[...m,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...m,"--app","--assignee","--author","--author-date","--author-email","--author-name","--base","--checks","--closed","--commenter","--committer","--committer-date","--committer-email","--committer-name","--created","--hash","--head","--interactions","--involves","--label","--language","--limit","-L","--match","--mentions","--merged-at","--milestone","--no-assignee","--no-label","--no-milestone","--no-project","--order","--owner","--parent","--project","--reactions","--review","--review-requested","--reviewed-by","--sort","--state","--team-mentions","--tree","--updated","--visibility","--extension","--filename","--size","--forks","--good-first-issue","--help-wanted-issues","--number-topics","--stars","--topic","--followers","--include-forks","--license"]},"project item-list":{values:["--format","-L","--limit","--owner","-q","--jq","-t","--template","--query","--field","--field-id"]},api:{values:["-X","--method","-H","--header","-f","--raw-field","-F","--field","-q","--jq","-t","--template","-p","--preview","--input","--hostname","--cache"]},group:{values:["-R","--repo"]}},u4=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"]),l4=new Set(["pr","issue","release","discussion","search","project","api","status"]),m4=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),p4=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),c4=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),i4=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function iZ(Z,X){let $=$Z(Z,"--json"),J=[],z=!1;for(let Y of $){if(Y.missing){if(X.appendsArgs)z=!0;continue}if(!Y.value)continue;if(Y.value.opaque)z=!0;J.push(...Y.value.value.split(",").map((Q)=>Q.trim()).filter(Boolean))}return{present:$.length>0,opaque:z,fields:J}}function y0(Z,X){if(f(Z,"--verbose")||$Z(Z,"-t","--template").length>0)return!1;let $=$Z(Z,"-q","--jq");return $.length>0&&$.every((J)=>J.value!==void 0&&!J.value.opaque&&O2(J.value.value,{rootScalars:X}))}function A0(Z,X,$,J){let z=iZ(Z,$);if(z.opaque)return N("unclassifiable");if(z.fields.every((Y)=>X.has(Y)))return _;if($.debug)return N("debug-traffic");return y0(Z)?_:N(J)}function mZ(Z,X,$,J,z){let Y=qZ(Z,KZ[X]);if(f(Y,"-h","--help"))return _;if(f(Y,"-w","--web"))return J.debug?N("debug-traffic"):_;if(z&&f(Y,"-c","--comments"))return N("view-comments");if(!iZ(Y,J).present)return N(J.debug?"debug-traffic":"view-human");return A0(Y,$,J,"json-composite")}function ZZ(Z,X,$,J){let z=qZ(Z,KZ[X]);if(f(z,"-h","--help"))return _;if(J.debug&&(f(z,"-w","--web")||!iZ(z,J).present))return N("debug-traffic");if(f(z,"-w","--web"))return _;return A0(z,$,J,"json-composite")}function d4(Z,X){let $=qZ(Z,KZ["pr checks"]);if(f($,"-h","--help"))return _;if(X.debug)return N("debug-traffic");if(f($,"-w","--web"))return _;if(!iZ($,X).present)return N("checks-human");return A0($,g4,X,"checks-json")}function s4(Z){let X=new Set(KZ.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(X.has(J))$++}return{rest:Z}}function n4(Z,X,$){let{sub:J,rest:z}=s4(X);if(!J)return $.appendsArgs?N("unclassifiable"):_;if(J.opaque)return N("unclassifiable");let Y=J.value;if((Z==="pr"?m4:Z==="issue"?p4:Z==="release"?c4:Z==="discussion"?i4:new Set).has(Y))return $.debug?N("debug-traffic"):_;if($.appendsArgs&&!(Z==="project"&&Y!=="item-list"))return N("unclassifiable");switch(Z){case"pr":if(Y==="view")return mZ(z,"pr view",I0,$,!0);if(Y==="list"||Y==="ls")return ZZ(z,"pr list",I0,$);if(Y==="status")return ZZ(z,"pr status",I0,$);if(Y==="checks")return d4(z,$);if(Y==="diff"){let H=qZ(z,KZ["pr diff"]);if(f(H,"-h","--help"))return _;if($.debug)return N("debug-traffic");return f(H,"--patch")?N("composite-other"):_}return N("unclassifiable");case"issue":if(Y==="view")return mZ(z,"issue view",D0,$,!0);if(Y==="list"||Y==="ls")return ZZ(z,"issue list",D0,$);if(Y==="status")return ZZ(z,"issue status",D0,$);return N("unclassifiable");case"release":if(Y==="view")return mZ(z,"release view",L2,$,!1);if(Y==="list"||Y==="ls")return ZZ(z,"release list",L2,$);return N("unclassifiable");case"discussion":if(Y==="view")return mZ(z,"discussion view",v2,$,!0);if(Y==="list"||Y==="ls")return ZZ(z,"discussion list",v2,$);return N("unclassifiable");case"search":if(Y==="prs"||Y==="issues")return ZZ(z,"search",w4,$);if(Y==="commits")return ZZ(z,"search",h4,$);if(Y==="code"||Y==="repos")return $.debug?N("debug-traffic"):_;return N("unclassifiable");case"project":{if($.debug)return N("debug-traffic");if(Y!=="item-list")return _;let H=qZ(z,KZ["project item-list"]);if(f(H,"-h","--help"))return _;let K=$Z(H,"--format");if(K.some((B)=>!B.value||B.value.opaque))return N("unclassifiable");if(K.every((B)=>B.value.value!=="json"))return _;return y0(H)?_:N("composite-other")}}return N("unclassifiable")}var E2=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function a4(Z){let X=Z.value.trim(),$=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(X);if($){let Y=$[1].toLowerCase(),Q=$[2]??"/";if(Y==="api.github.com"||/^api\./.test(Y))X=Q;else if(/^\/api\/v3(?:\/|$)/i.test(Q))X=Q.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(Q))X="graphql";else return null}X=X.replace(/[?#].*$/,"");let J=[],z=[];for(let Y of X.split("/")){let Q;try{Q=decodeURIComponent(Y)}catch{return null}for(let H of Q.split("/")){if(H===""||H===".")continue;if(H===".."){J.pop(),z.pop();continue}J.push(H.toLowerCase()),z.push(Z.opaque&&/[$`]/.test(H)||/[*?[]/.test(H)||R2(H))}}return{segments:J,opaque:z}}function o4(Z){let X=a4(Z);if(!X)return{kind:"unclassifiable",segments:[]};let{segments:$,opaque:J}=X,z=(K)=>({kind:K,segments:$});if($.length===1&&$[0]==="graphql")return z("graphql");if($.length===0)return z(Z.opaque?"unclassifiable":"other");if(J[0])return z("unclassifiable");let Y,Q=[];if($[0]==="repos")Y=$.slice(3),Q=J.slice(3);else if($[0]==="repositories")Y=$.slice(2),Q=J.slice(2);if(Y){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]&&r4.has(V));return z(M<0?"unclassifiable":y2($.slice(M),J.slice(M)))}return z(y2(Y,Q))}let H=$[0];if(H==="issues")return z("sensitive");if(H==="user"&&$[1]==="issues")return z("sensitive");if(H==="orgs"&&$[2]==="issues")return z("sensitive");if(H==="search")return z($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&J[1]?"unclassifiable":"other");if(H==="events"||H==="networks")return z("sensitive");if((H==="users"||H==="orgs")&&$.slice(2).some((K)=>K==="events"||K==="received_events"||K==="discussions"))return z("sensitive");if((H==="users"||H==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return z("sensitive");if(H==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||H==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return z("sensitive");if(H==="teams"&&$.includes("discussions"))return z("sensitive");if(H==="projects"&&$.includes("cards"))return z("sensitive");if(J.some(Boolean))return z($.some((K)=>K==="events"||K==="discussions"||K==="issues")?"sensitive":"unclassifiable");return z("other")}var r4=new Set([...E2,"branches","git","actions","hooks","zipball","tarball"]);function y2(Z,X){let[$,J]=Z;if($===void 0)return"other";if(X[0])return"unclassifiable";if($==="issues"&&/^\d+$/.test(J??"")&&Z[2]==="labels")return"other";if(E2.has($))return"sensitive";if($==="branches"){if(Z.length===1||Z.slice(1).some((z)=>z==="protection")||Z[Z.length-1]==="rename")return"other";return X.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if($==="git")return J===void 0||J==="commits"||J==="tags"?"sensitive":X[1]?"unclassifiable":"other";if($==="actions"){if(J===void 0)return"sensitive";if(X[1])return"unclassifiable";if(J==="runs"||J==="jobs"){if(Z[Z.length-1]==="logs"&&Z.length>=4&&!X.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 t4(Z,X){if(X[0]!=="repos"||X.length<5)return!1;let $=X.slice(3),J=(Y)=>/^\d+$/.test($[Y]??""),z=(...Y)=>$.length===Y.length&&Y.every((Q,H)=>typeof Q==="number"?J(H):$[H]===Q);if(Z==="DELETE")return z("issues","comments",0)||z("pulls","comments",0)||z("comments",0)||z("issues","comments",0,"reactions",0)||z("pulls","comments",0,"reactions",0)||z("issues",0,"reactions",0)||z("issues",0,"labels")||$.length===4&&$[0]==="issues"&&J(1)&&$[2]==="labels"||z("releases",0)||z("releases","assets",0)||z("actions","runs",0)||z("actions","runs",0,"logs")||z("deployments",0)||z("milestones",0)||z("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])||z("actions","jobs",0,"rerun")||z("issues",0,"labels");if(Z==="PUT")return z("pulls",0,"merge")||z("pulls",0,"update-branch")||z("issues",0,"labels")||z("issues",0,"lock");if(Z==="GET")return z("pulls",0,"merge");return!1}function e4(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 Z5=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"]),$5=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function J5(Z){let X=[],$=0;while($<Z.length){let J=Z[$];if(/[\s,]/.test(J)){$++;continue}if(J==="#"){let Q=Z.indexOf(`
20
- `,$);$=Q<0?Z.length:Q+1;continue}if(Z.startsWith('"""',$)){let Q=$+3;for(;;){let H=Z.indexOf('"""',Q);if(H<0)return null;if(Z[H-1]==="\\"){Q=H+3;continue}$=H+3;break}continue}if(J==='"'){let Q=$+1;while(Q<Z.length&&Z[Q]!=='"'&&Z[Q]!==`
21
- `)Q+=Z[Q]==="\\"?2:1;if(Z[Q]!=='"')return null;$=Q+1;continue}let z=/^[_A-Za-z][_0-9A-Za-z]*/.exec(Z.slice($,$+256));if(z){X.push({kind:"name",text:z[0]}),$+=z[0].length;continue}let Y=/^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(Z.slice($,$+64));if(Y){$+=Y[0].length;continue}if(Z.startsWith("...",$)){X.push({kind:"punct",text:"..."}),$+=3;continue}if("{}()[]:!$@=|&".includes(J)){X.push({kind:"punct",text:J}),$++;continue}return null}return X}function X5(Z){let X=J5(Z);if(!X)return!0;let $=[],J="",z=0;for(let Y=0;Y<X.length;Y++){let Q=X[Y];if(Q.kind==="punct"){if(Q.text==="(")z++;else if(Q.text===")"){if(z--,z<0)return!0}else if(z===0&&Q.text==="{")$.push(J),J="";else if(z===0&&Q.text==="}"){if($.pop()===void 0)return!0;J=""}continue}if(z>0)continue;let H=X[Y-1];if(H?.kind==="punct"&&(H.text==="@"||H.text==="$"))continue;if(X[Y+1]?.kind==="punct"&&X[Y+1].text===":")continue;if(Q.text==="on"&&H?.kind==="punct"&&H.text==="...")continue;if(H?.kind==="name"&&H.text==="on"){J=Q.text;continue}if($.length===0){J=Q.text;continue}if(Z5.has(Q.text)||/(?:Url|URL|HTML|Html)$/.test(Q.text))return!0;if(Q.text==="title"&&$.some((K)=>$5.has(K)))return!0;J=Q.text}return z!==0||$.length!==0}function z5(Z,X){let $=qZ(Z,KZ.api);if(f($,"-h","--help"))return _;let J=$.positionals[0];if(!J)return X.appendsArgs?N("unclassifiable"):_;let z=o4(J),Y=$Z($,"-X","--method"),Q=Y[Y.length-1],H=$Z($,"-f","--raw-field","-F","--field","--input"),K=Q?Q.value&&!Q.value.opaque?Q.value.value.toUpperCase():"?":H.length>0?"POST":"GET",B=t4(K,z.segments),M=_;if(z.kind==="unclassifiable")M=N("unclassifiable");else if(z.kind==="sensitive"&&!B)M=N("api-rest");else if(z.kind==="graphql")M=Y5($);if(X.debug||f($,"--verbose")){if(z.kind==="download"&&!M.refused)M=N("api-rest");if(M.refused)return X.debug?N("debug-traffic"):M;return _}if(X.appendsArgs&&z.kind!=="other"&&z.kind!=="download")return N("unclassifiable");if(!M.refused||f($,"--silent"))return _;if(y0($,e4(z.segments)))return _;return M}function Y5(Z){if($Z(Z,"--input").length>0)return N("unclassifiable");let X=$Z(Z,"-f","--raw-field","-F","--field"),$=X.filter((J)=>J.value&&/^query=/.test(J.value.value));if($.length===0||X.some((J)=>!J.value))return N("unclassifiable");for(let J of $){let z=J.value.value.slice(6);if((J.name==="-F"||J.name==="--field")&&z.startsWith("@")||J.value.opaque)return N("unclassifiable");if(X5(z))return N("api-graphql")}return _}function cZ(Z,X){let $=0;while($<Z.length&&Z[$].value.startsWith("-")&&!Z[$].opaque){if(["--help","-h","--version"].includes(Z[$].value))return _;$++}if($>=Z.length)return X.appendsArgs?N("unclassifiable"):_;let J=Z[$],z=Z.slice($+1);if(J.opaque)return N("unclassifiable");switch(J.value){case"pr":case"issue":case"release":case"discussion":case"search":case"project":return n4(J.value,z,X);case"api":return z5(z,X);case"status":return z.length>0&&z.every((Y)=>Y.value==="-h"||Y.value==="--help")?_:N("composite-other");case"help":case"version":return _;case"cs":case"codespace":{let Y=z.findIndex((Q)=>Q.value==="--");if(z.some((Q)=>Q.value==="ssh")&&Y>=0&&Y+1<z.length){let Q=n(z.slice(Y+1).map((H)=>H.value).join(" "),X.depth+1,X.debug);if(Q.refused)return Q}break}}if(!u4.has(J.value))return N("unclassifiable");if(X.debug)return N("debug-traffic");return _}var dZ=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","fish"]),Q5=new Set(["su","runuser","script","flock"]),K5=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"]),H5=new Map([["bun",["x","exec"]],["npm",["exec","x"]],["deno",["run"]]]),B5=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"]),M5=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),pZ=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/,G5=/^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/,V5=6;function A2(Z,X){let $,J;for(let z of Z){let Y=G5.exec(z.value);if(!Y)continue;let Q={...z,value:Y[2]};if(Y[1]==="GH_DEBUG")$=Q;else if(Y[1]==="DEBUG")J=Q}if($)return $.opaque||!["","0","false","no"].includes($.value);if(J&&(J.opaque||["1","true","yes","api"].includes(J.value)))return!0;return X}function R0(Z){let X=i(Z),$=0;return{segments:X.segments.map((z)=>{let Y=z.words[0],Q=Z.slice($,Y.start);return $=z.words[z.words.length-1].end,{words:z.words,redirects:z.redirects,sepBefore:Q}}),trustworthy:X.trustworthy}}var S2=(Z)=>/(?:^|[^|])\|&?$/.test(Z.trim());function P0(Z,X){if(!dZ.has(Z))return!1;if(E0(X))return!1;for(let $=0;$<X.length;$++){let J=X[$].value;if(J==="--")return $+1>=X.length;if(J==="-"||J==="-s")return!0;if(/^[-+][A-Za-z]*[oO]$/.test(J)){$++;continue}if(!J.startsWith("-")&&!J.startsWith("+"))return!1}return!0}function O0(Z){let{segments:X}=R0(Z.trim());if(X.length!==1)return null;let $=X[0],J=l($);if(J<0)return null;let z=QZ(WZ($.words[J].text).value),Y=$.words.slice(J+1).filter((Q,H)=>!$.redirects.has(H+J+1)).map((Q)=>WZ(Q.text));if(z==="echo")return Y.filter((Q,H)=>!(H===0&&/^-[neE]+$/.test(Q.value))).map((Q)=>Q.value).join(" ");if(z==="printf"){let[Q,...H]=Y.filter((B)=>B.value!=="--");if(!Q)return null;let K=0;return Q.value.replace(/\\n/g,`
22
- `).replace(/%s/g,()=>H[K++]?.value??"")+(K<H.length?" "+H.slice(K).map((B)=>B.value).join(" "):"")}if(z==="cat"){let Q=Z.indexOf("<<");if(Q<0)return null;let H=jZ(Z,Q),K=Z.indexOf(`
23
- `,Q);if(!H||K<0)return null;let B=hZ(Z,K,[H]);if(B<0)return null;let M=Z.slice(K+1,B);return M.slice(0,M.lastIndexOf(H.delimiter)).replace(/\n$/,"")}return null}function C0(Z,X,$){for(let J of F0(Z).bodies){let z=O0(J);if(z===null)continue;let Y=n(z,X+1,$.debug);if(Y.refused)return Y}return _}function n(Z,X=0,$=!1){if(typeof Z!=="string"||!Z.trim())return _;if(X>V5)return pZ.test(Z)?N("unclassifiable"):_;let{segments:J,trustworthy:z}=R0(Z);if(!z)return pZ.test(Z)?N("unclassifiable"):_;let Y=$,Q=(H)=>n(H,X+1,Y);for(let H of W5(Z)){if(H.runsBody){let K=Q(H.body);if(K.refused)return K}if(!H.quoted){let K=F0(H.body,"heredoc");if(!K.complete&&pZ.test(H.body))return N("unclassifiable");for(let B of K.bodies){let M=Q(B);if(M.refused)return M}}}for(let H=0;H<J.length;H++){let K=J[H];for(let W of K.words){let A=F0(W.text);if(!A.complete&&pZ.test(W.text))return N("unclassifiable");for(let h of A.bodies){let k=Q(h);if(k.refused)return k}}let B=l(K),M=K.words.map((W,A)=>({word:WZ(W.text),redirect:K.redirects.has(A)})),V=M.slice(0,B<0?M.length:B).map((W)=>W.word),G=B>=0?QZ(M[B].word.value):"";if(B<0||["export","declare","typeset","readonly","local"].includes(G)){if(Y=A2([...V,...M.slice(B+1).map((W)=>W.word)],Y),B<0)continue}let j=A2(V,Y),D=M.slice(B+1).filter((W)=>!W.redirect).map((W)=>W.word),v=M.slice(B+1).filter((W)=>W.redirect).map((W)=>W.word),w=M[B].word,E=QZ(w.value),HZ={depth:X,appendsArgs:!1,debug:j};if(B>0&&M[B-1].word.value==="function"){let W=D.filter((h)=>!["{","()","(",")"].includes(h.value)),A=L0(W,HZ);if(A.refused)return A;continue}if(H>0&&S2(K.sepBefore)&&P0(E,D)){let W=J[H-1],A=U5(Z,W),h=A===null?null:O0(A);if(h!==null){let k=n(h,X+1,j);if(k.refused)return k}}let p=J[H+1];if(p&&/<\(\s*$/.test(p.sepBefore)&&(dZ.has(E)||E==="source"||E===".")){let W=p.words[0].start-p.sepBefore.length+p.sepBefore.lastIndexOf("("),A=zZ(Z,W),h=A<0?null:O0(Z.slice(W+1,A-1));if(h!==null){let k=n(h,X+1,j);if(k.refused)return k}}let I=b2(E,w,D,v,K.words.slice(0,B+1),HZ);if(I.refused)return I}return _}function U5(Z,X){let $=X.words[0],J=X.words[X.words.length-1];return $&&J?Z.slice($.start,J.end):null}function j5(Z){let X=QZ(Z.value);return/[$`]/.test(X)||X===""?void 0:X}function b2(Z,X,$,J,z,Y){let Q=Y.depth,H=(K)=>n(K,Q+1,Y.debug);if(X.opaque){let K=j5(X);if(K===void 0){let B=$.find((V)=>!V.value.startsWith("-")),M=cZ($,Y);if(!M.refused)return _;return M.rule!=="unclassifiable"||B!==void 0&&!B.opaque&&l4.has(B.value)?M:_}Z=K}if(Z==="gh")return cZ($,Y);if(dZ.has(Z)){let K=E0($);if(K){let B=H(K.value);if(B.refused||!K.opaque)return B;return C0(K.raw,Q,Y)}for(let B of J){let M=H(B.value);if(M.refused)return M;if(B.opaque){let V=C0(B.raw,Q,Y);if(V.refused)return V}}return _}if(Q5.has(Z)){let K=$.findIndex((M)=>M.value==="-c"||M.value==="--command"||/^-[A-Za-z]*c$/.test(M.value)),B=K>=0?$[K+1]:void 0;return B?H(B.value):T0($,Y)}if(Z==="eval"||Z==="watch"){let K=$;if(Z==="watch"){let M=0;while(M<$.length&&$[M].value.startsWith("-")){if($[M].value==="--"){M++;break}if(["-n","--interval","-q","--equexit"].includes($[M].value))M++;M++}K=$.slice(M)}let B=H(K.map((M)=>M.value).join(" "));if(B.refused)return B;for(let M of K){let V=C0(M.raw,Q,Y);if(V.refused)return V}return _}if(Z==="env")return H(LZ([...z.map((K)=>WZ(K.text).value),...$.map((K)=>K.value)]));if(Z==="ssh"){let K=0;for(;K<$.length;K++){let V=$[K].value;if(!V.startsWith("-"))break;if(M5.has(V))K++}let B=$.slice(K+1);if(B[0]?.value==="--")B.shift();let M=B.map((V)=>V.value).join(" ");return M?H(M):_}if(Z==="xargs"){let K=0,B=!1;for(;K<$.length;K++){let M=$[K].value;if(M==="--"){K++;break}if(!M.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(M))B=!0;if(B5.has(M))K++}return L0($.slice(K),{depth:Q,appendsArgs:!B,debug:Y.debug})}if(Z==="find"){for(let K=0;K<$.length;K++){if(!["-exec","-execdir","-ok","-okdir"].includes($[K].value))continue;let B=K+1;while(B<$.length&&$[B].value!==";"&&$[B].value!=="+")B++;let M=L0($.slice(K+1,B),Y);if(M.refused)return M;K=B}return _}if(K5.has(Z))return T0($,Y);if(H5.get(Z)?.includes($[0]?.value??""))return T0($.slice(1),Y);return _}function L0(Z,X){if(Z.length===0)return _;let $=QZ(Z[0].value);if($==="gh")return cZ(Z.slice(1),X);if(dZ.has($)){let J=E0(Z.slice(1));return J?n(J.value,X.depth+1,X.debug):_}return b2($,Z[0],Z.slice(1),[],[],X)}function T0(Z,X){let $=Z.findIndex((J)=>!J.opaque&&QZ(J.value)==="gh"&&(J.value==="gh"||J.value.includes("/")));return $>=0?cZ(Z.slice($+1),X):_}function E0(Z){for(let X=0;X<Z.length;X++){let $=Z[X].value;if($==="--")return;if(!$.startsWith("-")&&!$.startsWith("+"))return;if($==="-c"||/^-[A-Za-z]+$/.test($)&&$.includes("c"))return Z.slice(X+1).find((J)=>!J.value.startsWith("-")||J.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test($))X++}return}function W5(Z){let X=[],$=0;for(;;){let J=Z.indexOf("<<",$);if(J<0)break;if($=J+2,Z[J+2]==="<"||J>0&&Z[J-1]==="<"){$=J+3;continue}let z=jZ(Z,J);if(!z)continue;let Y=Z.lastIndexOf(`
24
- `,J)+1,Q=Z.indexOf(`
25
- `,J);if(Q<0)continue;let H=hZ(Z,Q,[z]),K=H<0?Z.slice(Q+1):Z.slice(Q+1,H),B=H<0?K:K.slice(0,Math.max(0,K.lastIndexOf(z.delimiter))).replace(/\n$/,""),M=Z.slice(Y,J)+" HEREDOC_OPERATOR "+Z.slice(z.end,Q);X.push({body:B,runsBody:q5(M),quoted:z.quoted})}return X}function q5(Z){let{segments:X}=R0(Z),$=X.findIndex((H)=>H.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(H)=>{let K=l(H);if(K<0)return{verb:"",args:[]};let B=H.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>WZ(M.text));return{verb:QZ(WZ(H.words[K].text).value),args:B}},{verb:z,args:Y}=J(X[$]);if(z==="ssh"||P0(z,Y))return!0;if((z==="source"||z===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(Y[0]?.value??""))return!0;let Q=X[$+1];if(z==="cat"&&Q&&S2(Q.sepBefore)){let H=J(Q);return H.verb==="ssh"||P0(H.verb,H.args)}return!1}var N5=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function f2(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:v0}}}var _5=new Set(["Bash","Monitor"]);function k2(Z){if(Z?.hook_event_name!=="PreToolUse"||!_5.has(Z.tool_name??""))return{continue:!0};let X=GZ(Z);if(!X.trim())return{continue:!0};try{return n(X).refused?f2():{continue:!0}}catch{return N5.test(X)?f2():{continue:!0}}}function I5(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function x2(Z,X){I5(Z);let $=Z,J=JSON.parse(X);if(!J||Array.isArray(J)||J.hook_event_name!=="PreToolUse"||typeof J.tool_name!=="string"||!J.tool_input||typeof J.tool_input!=="object"||Array.isArray(J.tool_input)||typeof J.cwd!=="string"||!S0.isAbsolute(J.cwd))throw Error("Invalid safety input");if(J.tool_name==="Bash"&&typeof J.tool_input.command!=="string")throw Error("Invalid shell input");if(J.tool_name==="Monitor"&&J.tool_input.command!==void 0&&typeof J.tool_input.command!=="string")throw Error("Invalid monitor input");let z=J.hasna_execution;if(z!==void 0&&(!z||Object.keys(z).sort().join()!=="agent,schema"||z.schema!=="hasna.hooks.execution.v1"||typeof z.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(z.agent)))throw Error("Invalid execution capability");let Y=z===void 0?void 0:{runtime:process.execPath,home:sZ.homedir(),path:process.env.PATH,agent:z.agent};if(Y&&(!S0.isAbsolute(Y.runtime)||!Y.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(J.tool_name)){if(J.tool_input.command!==void 0&&J.tool_input.patch!==void 0&&J.tool_input.command!==J.tool_input.patch)throw Error("Conflicting patch aliases");let v=J.tool_input.command??J.tool_input.patch;if(typeof v!=="string")throw Error("Invalid patch input");J.tool_input={...J.tool_input,command:v,patch:v}}let Q=J.tool_name==="Monitor",H=J.tool_name==="Bash"||Q&&typeof J.tool_input.command==="string",K=Q&&H?{...J,tool_name:"Bash"}:J,B=(v)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:v}}),M=_2(K).output,V=k2(K),G=H&&yZ(K.tool_input.command,{home:sZ.homedir(),cwd:J.cwd}).handoffHits.length>0,j=$==="trash-guard"&&(!Q||H)?Z2(K,{home:sZ.homedir(),cwd:J.cwd,findTrash:fZ,inspectTrash:TZ,execution:Y}):{continue:!0};if(Q&&j.hookSpecificOutput?.permissionDecision==="allow")j=B("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let D=M.decision==="block"?B(M.reason):V.hookSpecificOutput?V:G?B("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):j;return JSON.stringify({verdict:"continue"in D?null:D})}var D5=2,C5="0.12.10";function T5(Z,X){return x2(Z,X)}
1
+ var{defineProperty:H0,getOwnPropertyNames:V3,getOwnPropertyDescriptor:G3}=Object,U3=Object.prototype.hasOwnProperty;function W3(Z){return this[Z]}var j3=(Z)=>{var J=(t0??=new WeakMap).get(Z),$;if(J)return J;if(J=H0({},"__esModule",{value:!0}),Z&&typeof Z==="object"||typeof Z==="function"){for(var z of V3(Z))if(!U3.call(J,z))H0(J,z,{get:W3.bind(Z,z),enumerable:!($=G3(Z,z))||$.enumerable})}return t0.set(Z,J),J},t0;var N3=(Z)=>Z;function F3(Z,J){this[Z]=N3.bind(null,J)}var _3=(Z,J)=>{for(var $ in J)H0(Z,$,{get:J[$],enumerable:!0,configurable:!0,set:F3.bind(J,$)})};var q6={};_3(q6,{version:()=>C6,evaluate:()=>D6,abi:()=>I6});module.exports=j3(q6);var z0=require("node:os"),n0=require("node:path");var b=require("node:path");var v=require("node:path"),P=require("node:fs"),e0=require("node:child_process"),Z2={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 CZ(Z){return Z===0||Z===process.getuid?.()}function xZ(Z,J=!1){let $=Z;for(let z=0;z<32;z++){if(!v.isAbsolute($)||$.length>4096||!DZ("/"))return!1;let Y=$.split("/"),Q=Y.pop();if(!Q||Q==="."||Q==="..")return!1;let X="/";for(let B of Y){if(!B||B===".")continue;if(B===".."){X=v.dirname(X);continue}let M=v.join(X,B),V=P.lstatSync(M);if(J&&M==="/bin"&&V.isSymbolicLink()&&V.uid===0){let G=P.realpathSync(M);if(!DZ(G))return!1;X=G;continue}if(!V.isDirectory()||!CZ(V.uid)||V.mode&18)return!1;X=M}let H=v.join(X,Q),K=P.lstatSync(H);if(!CZ(K.uid))return!1;if(K.isSymbolicLink()){let B=P.readlinkSync(H);$=v.isAbsolute(B)?B:X+"/"+B;continue}return K.isFile()&&Boolean(K.mode&73)&&!(K.mode&18)}return!1}function T3(Z){if(!v.isAbsolute(Z)||v.resolve(Z)!==(Z.replace(/\/+$/,"")||"/"))return!1;for(let J=v.resolve(Z);;J=v.dirname(J)){try{return P.lstatSync(J),DZ(J)}catch($){if($.code!=="ENOENT")return!1}if(v.dirname(J)===J)return!1}}function I3(Z,J){let $=P.openSync(Z,P.constants.O_RDONLY|P.constants.O_NONBLOCK|P.constants.O_NOFOLLOW),z;try{if(!P.fstatSync($).isFile())return!1;let Q=Buffer.alloc(256),X=P.readSync($,Q,0,Q.length,0);z=Q.subarray(0,X).toString("utf8").split(`
2
+ `)[0]}finally{P.closeSync($)}let Y=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(z);if(Y&&Y[1]!=="/usr/bin/env")return xZ(Y[1],!0);if(z!=="#!/usr/bin/env bun"||!xZ("/usr/bin/env",!0))return!1;for(let Q of J.split(":").slice(0,64)){if(!T3(Q))return!1;let X=v.resolve(Q,"bun");try{if(!P.statSync(X).isFile())continue;P.accessSync(X,P.constants.X_OK)}catch{continue}return xZ(X,!0)}return!1}function DZ(Z){let J=Z;for(;;){let $=P.lstatSync(J);if(!$.isDirectory()||!CZ($.uid)||($.mode&18)!==0)return!1;let z=v.dirname(J);if(z===J)return!0;J=z}}function qZ(Z=process.env){let J=Z.PATH??"",$=Date.now()+2000,z="missing",Y=(Q)=>{if(z==="missing"||z==="unrecognized_package"||Q.startsWith("unsafe_"))z=Q};for(let Q of J.split(":").slice(0,64)){if(!v.isAbsolute(Q)||Date.now()>=$)continue;let X=v.resolve(Q,"trash");try{let H=P.statSync(X);if(!H.isFile()||!CZ(H.uid)||(H.mode&73)===0||(H.mode&18)!==0){Y("unsafe_executable");continue}let K=P.realpathSync(X);if(!DZ(v.resolve(Q))||!DZ(v.dirname(K))){Y("unsafe_directory");continue}if(!xZ(X)){Y("unsafe_directory");continue}let B=v.resolve(v.dirname(K),"../.."),M=v.join(B,"package.json"),V=P.statSync(M);if(!V.isFile()||!CZ(V.uid)||V.size>16384||(V.mode&18)!==0||P.lstatSync(M).isSymbolicLink()){Y("unsafe_manifest");continue}let G=JSON.parse(P.readFileSync(M,"utf8"));if(G.name!=="@hasna/trash"||typeof G.version!=="string"||typeof G.bin?.trash!=="string"||P.realpathSync(v.resolve(B,G.bin.trash))!==K){Y("unrecognized_package");continue}try{if(!I3(K,J)){Y("unsafe_interpreter");continue}}catch{Y("unsafe_interpreter");continue}let U=$-Date.now();if(U<=0){Y("identity_failed");break}let j=e0.spawnSync(X,["--identity"],{encoding:"utf8",timeout:U,maxBuffer:2048,env:{PATH:J},stdio:["ignore","pipe","pipe"]});if(j.error||j.status!==0||Date.now()>=$){Y("identity_failed");continue}let F=JSON.parse(j.stdout);if(F.name==="@hasna/trash"&&F.version===G.version&&F.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:X,version:G.version};Y("unsupported_protocol")}catch{}}return{ok:!1,code:z}}function hZ(Z=process.env){let J=qZ(Z);return J.ok?J.path:null}function GZ(Z){let J=Z.tool_input?.command;return typeof J==="string"?J:""}var $2=["/","/bin","/boot","/dev","/etc","/home","/lib","/lib32","/lib64","/libx32","/opt","/proc","/root","/run","/sbin","/srv","/sys","/usr","/var","/Applications","/Library","/System","/Users","/Volumes","/private"];var OZ=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,n=(Z)=>Z.split("/").pop()??"";function wZ(Z){let J=Z.startsWith("~")?Z.slice(1).split("/",1)[0]:"";if(J&&!/['"\\]/.test(J))return!0;let $=null,z=0;for(let Y=0;Y<Z.length;Y++){let Q=Z[Y];if($==="'"){if(Q==="'")$=null;continue}if(Q==="\\"){Y++;continue}if($==='"'){if(Q==='"')$=null;continue}if(Q==="'"||Q==='"')$=Q;else if(Q==="$"&&Z[Y+1]==="{")z++,Y++;else if(Q==="}"&&z>0)z--;else if(Q==="{"||Q==="}")return!0}return!1}var B0=64;function J2(Z,J){let $=0;for(let z=J;z<Z.length;z++)if(Z[z]==="\\")z++;else if(Z[z]==="{")$++;else if(Z[z]==="}"&&--$===0)return z;return Z.length-1}function C3(Z){let J=Z.match(/^([-+]?\d+)\.\.([-+]?\d+)(?:\.\.([-+]?\d+))?$/),$=J?null:Z.match(/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([-+]?\d+))?$/),z=J??$;if(!z)return null;let Y=J?Number(z[1]):z[1].charCodeAt(0),Q=J?Number(z[2]):z[2].charCodeAt(0),X=Math.abs(Number(z[3]??1))||1;if(!Number.isSafeInteger(Y)||!Number.isSafeInteger(Q)||!Number.isSafeInteger(X))return"overflow";if(Math.floor(Math.abs(Q-Y)/X)+1>B0)return"overflow";let H=J&&(/^[-+]?0\d/.test(z[1])||/^[-+]?0\d/.test(z[2]))?Math.max(z[1].length,z[2].length):0,K=[];for(let B=Y;Y<=Q?B<=Q:B>=Q;B+=Y<=Q?X:-X)if(!J)K.push(String.fromCharCode(B));else K.push(B<0?`-${String(-B).padStart(H-1,"0")}`:String(B).padStart(H,"0"));return K}function D3(Z){let J=null,$=0;for(let z=0;z<Z.length;z++){let Y=Z[z];if(J==="'"){if(Y==="'")J=null;continue}if(Y==="\\"){z++;continue}if(J==='"'){if(Y==='"')J=null;continue}if(Y==="'"||Y==='"')J=Y;else if(Y==="$"&&Z[z+1]==="{")z=J2(Z,z+1);else if(Y==="{"){if(++$>B0)return"overflow";let Q=null,X=0,H=!0,K=[];for(let B=z;B<Z.length;B++){let M=Z[B];if(Q==="'"){if(M==="'")Q=null;continue}if(M==="\\"){H=!1,B++;continue}if(Q==='"'){if(M==='"')Q=null;continue}if(M==="'"||M==='"')Q=M,H=!1;else if(M==="$"&&Z[B+1]==="{")B=J2(Z,B+1),H=!1;else if(M==="{")X++;else if(M===","&&X===1)K.push(B);else if(M==="}"&&--X===0){if(K.length>0){let G=[z,...K,B];return{open:z,close:B,parts:G.slice(0,-1).map((U,j)=>Z.slice(U+1,G[j+1]))}}let V=H?C3(Z.slice(z+1,B)):null;if(V==="overflow")return V;if(V)return{open:z,close:B,parts:V};break}}}}return null}function QZ(Z){if(Z.length>4096&&Z.includes("{"))return null;let J=D3(Z);if(J===null)return[Z];if(J==="overflow")return null;let $=[];for(let z of J.parts){let Y=QZ(Z.slice(0,J.open)+z+Z.slice(J.close+1));if(Y===null||$.push(...Y)>B0)return null}return $}var W={arg:"none"},_={arg:"value"},PZ={arg:"optional"},r={arg:"none",effect:"lookup"},q={arg:"none",effect:"refuse"},e={help:q,version:q},q3=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,M0={timeout:{short:{k:_,s:_,v:W},long:{"kill-after":_,signal:_,verbose:W,foreground:W,"preserve-status":W,...e},positionals:[q3]},env:{short:{i:W,"0":W,v:W,u:_,a:_,C:q,S:q},long:{"ignore-environment":W,null:W,debug:W,unset:_,argv0:_,chdir:q,"split-string":q,"block-signal":PZ,"default-signal":PZ,"ignore-signal":PZ,"list-signal-handling":q,...e},env:!0},nice:{short:{n:_},long:{adjustment:_,...e},numericOption:!0},nohup:{short:{},long:{...e}},command:{short:{p:W,v:r,V:r},long:{}},exec:{short:{c:W,l:W,a:_},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:_,o:_,e:_},long:{input:_,output:_,error:_,...e}},time:{short:{p:W,a:W,q:W,v:W,f:_,o:q,V:q},long:{portability:W,append:W,quiet:W,verbose:W,format:_,output:q,...e}},ionice:{short:{c:_,n:_,t:W,p:q,P:q,u:q,h:q,V:q},long:{class:_,classdata:_,ignore:W,pid:q,pgid:q,uid:q,...e}},setsid:{short:{c:W,f:W,w:W,h:q,V:q},long:{ctty:W,fork:W,wait:W,...e}}},P3=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function O3(Z,J,$){let z=!1,Y=(Q)=>{if(!Q||Q.effect==="refuse")return!1;if(Q.effect==="lookup")z=!0;return!0};while($<J.length){let Q=J[$];if(Q.opaque)return null;let X=Q.text;if(X==="--"){$++;break}if(X==="-"&&Z.env){$++;continue}if(!X.startsWith("-")||X==="-")break;if(Z.numericOption&&/^-[-+]?\d+$/.test(X)){$++;continue}if(X.startsWith("--")){let H=X.indexOf("="),K=H<0?X.slice(2):X.slice(2,H),B=Object.keys(Z.long),M=B.includes(K)?[K]:B.filter((G)=>K&&G.startsWith(K));if(M.length!==1)return null;let V=Z.long[M[0]];if(!Y(V))return null;if(V.arg==="none"&&H>=0)return null;if(V.arg==="value"&&H<0){let G=J[++$];if(!G||G.opaque)return null}$++;continue}for(let H=1;H<X.length;H++){let K=Z.short[X[H]];if(!Y(K))return null;if(K.arg==="value"){if(H===X.length-1){let B=J[++$];if(!B||B.opaque)return null}break}}$++}if(z)return-1;for(let Q of Z.positionals??[]){let X=J[$];if(!X||X.opaque||!Q.test(X.text))return null;$++}if(Z.env||Z.assignments){for(;$<J.length&&OZ.test(J[$].text);$++)if(J[$].opaque)return null}return $}function XZ(Z,J=M0){let $=0;while($<Z.length&&(OZ.test(Z[$].text)||P3.has(Z[$].text)))$++;for(let z=0;z<16;z++){if($>=Z.length)return{index:-1};if(Z[$].opaque)return z===0?{index:$}:null;let Y=Object.hasOwn(J,n(Z[$].text))?J[n(Z[$].text)]:void 0;if(!Y)return{index:$};let Q=O3(Y,Z,$+1);if(Q===null)return null;if(Q<0)return{index:-1};$=Q}return null}function L3(Z){return/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred|trash)(?![A-Za-z0-9_.-])/.test(Z)}var G0=(Z)=>Z.split("/").pop()??"",V0={perl:{letters:new Set(["e","E"]),long:new Set},python:{letters:new Set(["c"]),long:new Set},python2:{letters:new Set(["c"]),long:new Set},python3:{letters:new Set(["c"]),long:new Set},ruby:{letters:new Set(["e"]),long:new Set},node:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},nodejs:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},bun:{letters:new Set(["e"]),long:new Set(["--eval"])},deno:{letters:new Set(["e"]),long:new Set(["--eval"])},php:{letters:new Set(["r"]),long:new Set},lua:{letters:new Set(["e"]),long:new Set},luajit:{letters:new Set(["e"]),long:new Set},Rscript:{letters:new Set(["e"]),long:new Set}},X2=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,y3=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),A3=new Set(["ssh","scp","sftp"]),R3=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),z2=new Set(["proxycommand","localcommand","knownhostscommand"]),v3=/(?:`|\$\()|\b(?:system|exec|execve|execvp|popen|spawn|posix_spawn|fork|subprocess|Popen|check_output|check_call|shell_exec|passthru|proc_open|pcntl_exec|qx|open|fopen|sysopen|unlink|remove|delete|rmtree|rmdir|mkdir|rename|truncate|ftruncate|chmod|chown|symlink|writeFile|createWriteStream|appendFile|child_process|FileUtils|shutil|Kernel|require|import|load|eval|os|sys|io|fs|File|IO|Dir|Path|pathlib)/,b3=/[|>]|\b(?:system|getline|close|fflush|print\w*\s*>>?)/;function K2(Z){if(L3(Z.text))return!1;if(Z.kind==="awk")return!b3.test(Z.text);if(Z.kind==="c-interp")return!v3.test(Z.text);return!1}function E3(Z,J,$,z){let Y=V0[Z]??(X2.test(Z)?V0[Z.replace(/[0-9.]+$/,"")]:void 0);if(!Y)return null;let Q=[],X=!1,H=(K)=>{if(K+1>=J.length||z(K+1))return X=!0,K;return Q.push({text:J[K+1],kind:"c-interp"}),K+1};for(let K=$+1;K<J.length;K++){let B=J[K];if(B==="--")break;if(!B.startsWith("-")||B==="-")break;if(B.startsWith("--")){let V=B.indexOf("="),G=V<0?B:B.slice(0,V);if(Y.long.has(G))if(V>=0)Q.push({text:B.slice(V+1),kind:"c-interp"});else K=H(K);continue}let M=B.slice(1);for(let V=0;V<M.length;V++){if(!Y.letters.has(M[V]))continue;if(V<M.length-1)Q.push({text:M.slice(V+1),kind:"c-interp"});else K=H(K);break}}if(Q.length===0&&!X)return null;return{programs:Q,unresolved:X}}function S3(Z,J,$){let z=[],Y=!1,Q=J+1;for(;Q<Z.length;Q++){let X=Z[Q];if(X==="--"){Q++;break}if(!X.startsWith("-")||X==="-")break;if(X==="-e"||X.startsWith("-e")){let H=X==="-e"?null:X.slice(2);if(H!==null)z.push({text:H,kind:"awk"});else if(Q+1<Z.length&&!$(Q+1))z.push({text:Z[++Q],kind:"awk"});else Y=!0}else if(X==="-f"||X.startsWith("-f")){if(Y=!0,X==="-f")Q++}else if(X==="-v"||X.startsWith("-v")){if(X==="-v")Q++}}if(z.length===0&&!Y){if(Q<Z.length)if($(Q))Y=!0;else z.push({text:Z[Q],kind:"awk"})}return{programs:z,unresolved:Y}}function f3(Z,J,$){let z=Z[J],Y,Q=J;if(z==="-o"){if(J+1>=Z.length)return{value:null,next:J};if($(J+1))return{value:null,next:J+1};Y=Z[J+1],Q=J+1}else Y=z.slice(2);return{value:Y,next:Q}}function k3(Z,J,$){let z=[],Y=!1;for(let Q=J+1;Q<Z.length;Q++){let X=Z[Q];if(X==="--")break;if(!X.startsWith("-")||X==="-")break;if(X.startsWith("--"))continue;if(X==="-o"||X.startsWith("-o")){let{value:K,next:B}=f3(Z,Q,$);if(Q=B,K===null){Y=!0;continue}let M=K.indexOf("="),V=M>=0?M:K.search(/\s/),G=(V>=0?K.slice(0,V):K).trim().toLowerCase(),U=V>=0?K.slice(V+1).trim():"";if(z2.has(G))z.push({text:U,kind:"shell"});continue}if(X==="-F"||X.startsWith("-F")){if(Y=!0,X==="-F")Q++;continue}if(X==="-S"||X.startsWith("-S")){let K=X==="-S"?Q+1<Z.length&&!$(Q+1)?Z[++Q]:null:X.slice(2);if(K===null)Y=!0;else z.push({text:K,kind:"shell"});continue}let H=X.slice(1);for(let K=0;K<H.length;K++){if(!R3.has(H[K]))continue;if(K<H.length-1)break;if(H[K]==="o"||H[K]==="F"||H[K]==="S"){if(Q+1<Z.length){let B=Z[Q+1];if(H[K]==="o")if(!$(Q+1)){let M=B.indexOf("="),V=M>=0?M:B.search(/\s/),G=(V>=0?B.slice(0,V):B).trim().toLowerCase();if(z2.has(G))z.push({text:V>=0?B.slice(V+1).trim():"",kind:"shell"})}else Y=!0;else if(H[K]==="F")Y=!0;else if(!$(Q+1))z.push({text:B,kind:"shell"});Q++}}else if(Q+1<Z.length)Q++}}return{programs:z,unresolved:Y}}function x3(Z,J,$){let z=[],Y=!1,Q=!1;for(let X=J+1;X<Z.length;X++){let H=Z[X];if(H==="--")break;if(H==="-e"||H==="--rsh")if(Q=!0,X+1<Z.length&&!$(X+1))z.push({text:Z[++X],kind:"shell"});else Y=!0;else if(H.startsWith("--rsh="))Q=!0,z.push({text:H.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(H)&&H.length>2&&!H.startsWith("--"))Q=!0,z.push({text:H.slice(H.indexOf("e")+1),kind:"shell"})}return Q?{programs:z,unresolved:Y}:null}var h3=/^(?:true|false|yes|no|on|off|1|0|)$/i,w3=[/^core\.(?:pager|editor|sshcommand|askpass|alternaterefscommand)$/,/^sequence\.editor$/,/^diff\.external$/,/^interactive\.difffilter$/,/^imap\.tunnel$/,/^gc\.recentobjectshook$/,/^gpg\.program$/,/^gpg\.ssh\.defaultkeycommand$/,/^uploadpack\.packobjectshook$/,/^instaweb\.(?:browser|httpd)$/,/^credential\.(?:.+\.)?helper$/,/^diff\..+\.(?:command|textconv)$/,/^(?:difftool|mergetool|man|browser)\..+\.(?:cmd|path)$/,/^guitool\..+\.cmd$/,/^merge\..+\.driver$/,/^gpg\..+\.program$/,/^remote\..+\.(?:uploadpack|receivepack)$/,/^filter\..+\.(?:clean|smudge|process)$/,/^tar\..+\.command$/,/^trailer\..+\.(?:cmd|command)$/,/^sendemail\.(?:.+\.)?(?:tocmd|cccmd|headercmd|sendmailcmd)$/];function H2(Z,J){let $=Z.toLowerCase(),z=(Y)=>Y===void 0?{kind:"unresolved"}:{kind:"command",text:Y};if(/^alias\./.test($))return J!==void 0&&J.trimStart().startsWith("!")?z(J.trimStart().slice(1)):{kind:"unresolved"};if(/^pager\./.test($)||$==="core.fsmonitor")return J!==void 0&&h3.test(J)?{kind:"harmless"}:z(J);if($==="core.gitproxy")return J!==void 0&&/^none(?:\s+for\s+\S+)?$/.test(J)?{kind:"harmless"}:z(J?.replace(/\s+for\s+\S+$/,""));if(/^submodule\..+\.update$/.test($))return J!==void 0&&J.trimStart().startsWith("!")?z(J.trimStart().slice(1)):J===void 0?{kind:"unresolved"}:{kind:"harmless"};if(/^sendemail\.(?:.+\.)?smtpserver$/.test($))return J!==void 0&&!J.startsWith("/")?{kind:"harmless"}:z(J);if(/^credential\.(?:.+\.)?helper$/.test($)){if(J==="")return{kind:"harmless"};if(J===void 0)return{kind:"unresolved"};let Y=J.trimStart();return z(Y.startsWith("!")?Y.slice(1):Y.startsWith("/")?Y:`git credential-${Y}`)}if(w3.some((Y)=>Y.test($)))return z(J);if($==="core.hookspath")return J==="/dev/null"?{kind:"harmless"}:{kind:"unresolved"};if($==="include.path"||/^includeif\..+\.path$/.test($))return{kind:"unresolved"};if($==="protocol.allow")return J!==void 0&&/^(?:never|user)$/i.test(J)?{kind:"harmless"}:{kind:"unresolved"};if($==="protocol.ext.allow")return J!==void 0&&/^never$/i.test(J)?{kind:"harmless"}:{kind:"unresolved"};return{kind:"harmless"}}function Y2(Z){return/[$\x60]/.test(Z)||["","x","/x","!x"].some((J)=>H2(Z,J).kind!=="harmless")}var g3=new Set(["GIT_PAGER","GIT_EDITOR","GIT_SEQUENCE_EDITOR","GIT_EXTERNAL_DIFF","GIT_SSH","GIT_SSH_COMMAND","GIT_ASKPASS","SSH_ASKPASS","GIT_PROXY_COMMAND","PAGER","EDITOR","VISUAL"]),l3=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function u3(Z){let J=/'((?:[^']|'\\'')*)'/y,$=(Q)=>Q.replace(/'\\''/g,"'"),z=[],Y=0;while(Y<Z.length){if(/\s/.test(Z[Y])){Y++;continue}J.lastIndex=Y;let Q=J.exec(Z);if(!Q)return null;if(Y=J.lastIndex,Z[Y]==="="){J.lastIndex=Y+1;let X=J.exec(Z);if(!X)return null;Y=J.lastIndex,z.push([$(Q[1]),$(X[1])])}else{let X=$(Q[1]),H=X.indexOf("=");z.push(H<0?[X,void 0]:[X.slice(0,H),X.slice(H+1)])}}return z}function m3(Z,J,$){let z=[],Y=!1,Q=(B,M,V=!0)=>{if(!V||/[$\x60]/.test(B)){Y=!0;return}let G=H2(B,M);if(G.kind==="unresolved")Y=!0;else if(G.kind==="command")z.push({text:G.text,kind:"shell"})},X=(B,M)=>{let V=B.indexOf("="),G=V<0?B:B.slice(0,V),U=V<0?"true":B.slice(V+1);if(!M)return Q(G,U);if(Y2(G))Y=!0},H=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let B=J+1;B<Z.length;B++){let M=Z[B];if(!M.startsWith("-")||M==="-")break;if(M==="--")break;if(M==="-c"){if(B+1>=Z.length)break;X(Z[B+1],$(B+1)),B++}else if(M.startsWith("-c")&&!M.startsWith("--"))X(M.slice(2),$(B));else if(M==="--config-env"||M.startsWith("--config-env=")){let V=M==="--config-env"?Z[++B]??"":M.slice(13),G=V.indexOf("="),U=G<0?V:V.slice(0,G);if($(B)||Y2(U))Y=!0}else if(M.startsWith("--exec-path="))Y=!0;else if(H.has(M))B++}let K=new Map;for(let B=0;B<J;B++){let M=Z[B].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!M)continue;let[,V,G]=M,U=$(B);if(g3.has(V))if(U)Y=!0;else z.push({text:G,kind:"shell"});else if(l3.has(V)){if(U||G!=="/dev/null"||V==="GIT_EXEC_PATH"||V==="GIT_TEMPLATE_DIR")Y=!0}else if(V==="GIT_ALLOW_PROTOCOL"){if(U||G.split(":").includes("ext"))Y=!0}else if(V==="GIT_CONFIG_PARAMETERS"){let j=U?null:u3(G);if(j===null)Y=!0;else for(let[F,E]of j)Q(F,E??"true")}else if(/^GIT_CONFIG_(?:KEY|VALUE)_\d+$/.test(V)){let j=V.replace(/^GIT_CONFIG_(?:KEY|VALUE)_/,""),F=K.get(j)??{};if(V.startsWith("GIT_CONFIG_KEY_"))F.key=G;else F.value=G;if(U)F.opaque=!0;K.set(j,F)}}for(let B of K.values()){if(B.key===void 0)continue;if(B.opaque)X(`${B.key}=`,!0);else Q(B.key,B.value)}if(z.length===0&&!Y)return null;return{programs:z,unresolved:Y}}function LZ(Z){let J={n:`
3
+ `,t:"\t",r:"\r",a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};if(/^~/.test(Z))return null;let $="";for(let z=0;z<Z.length;z++){let Y=Z[z];if(Y==="'"){let Q=Z.indexOf("'",z+1);if(Q<0)return null;$+=Z.slice(z+1,Q),z=Q}else if(Y==="$"&&Z[z+1]==="'"){let Q=z+2;for(;Q<Z.length&&Z[Q]!=="'";Q++){if(Z[Q]!=="\\"){$+=Z[Q];continue}let X=Z[Q+1],H;if(X!==void 0&&Object.hasOwn(J,X))$+=J[X],Q++;else if(H=Z.slice(Q+1).match(/^[0-7]{1,3}/))$+=String.fromCharCode(parseInt(H[0],8)&255),Q+=H[0].length;else if(H=Z.slice(Q+1).match(/^x([0-9A-Fa-f]{1,2})/))$+=String.fromCharCode(parseInt(H[1],16)),Q+=H[0].length;else return null}if(Q>=Z.length)return null;z=Q}else if(Y==="$"||Y==="`")return null;else if(Y==='"'){let Q=z+1;for(;Q<Z.length&&Z[Q]!=='"';Q++){let X=Z[Q];if(X==="$"||X==="`")return null;if(X==="\\"&&Q+1<Z.length&&/[$\x60"\\\n]/.test(Z[Q+1])){$+=Z[++Q];continue}$+=X}if(Q>=Z.length)return null;z=Q}else if(Y==="\\"){if(z+1>=Z.length)return null;$+=Z[++z]}else if("*?[{}".includes(Y))return null;else $+=Y}return $}function Q2(Z){let J=null;for(let $=0;$<Z.length;$++){let z=Z[$];if(J==="'"){if(z==="'")J=null;continue}if(z==="\\"){$++;continue}if(z==="$"||z==="`")return!1;if(J==='"'){if(z==='"')J=null;continue}if(z==="'"||z==='"'){J=z;continue}if(z==="<"&&Z[$+1]==="<"&&Z[$+2]!=="<")return!1}return J===null}var p3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]),c3=new Set(["--rcfile","--init-file"]);function lZ(Z,J){if(J<0||J>=Z.length)return null;let $=LZ(Z[J]),z=G0($??"");if(z==="eval"){let H=J+1;if(LZ(Z[H]??"")==="--")H++;let K=Z.slice(H);if(K.length===0)return null;if(K.length>1)return{program:null,literal:!1};let B=LZ(K[0]);return B!==null&&Q2(B)?{program:B,literal:!0}:{program:B,literal:!1}}if(!p3.has(z))return null;let Y=!1,Q=J+1;for(;Q<Z.length;Q++){let H=LZ(Z[Q]);if(H===null){if(Y)break;return/^"[^"]*"$/.test(Z[Q])?null:{program:null,literal:!1}}if(H==="--"){Q++;break}if(!/^[-+]./.test(H))break;if(H.startsWith("--")){if(c3.has(H))Q++;continue}let K=H.slice(1);if(H[0]==="-"&&K.includes("c"))Y=!0;if(/[oO]/.test(K))Q++}if(!Y||Q>=Z.length)return null;let X=LZ(Z[Q]);return X!==null&&Q2(X)?{program:X,literal:!0}:{program:X,literal:!1}}function i3(Z,J,$){let z=[],Y=!1,Q=!1,X=J+1,H=!1;for(;X<Z.length;X++){let V=Z[X];if(V==="--"){X++;break}if(V==="-i"||V.startsWith("-i")||V.startsWith("--in-place")){Q=!0;continue}if(V==="-e"||V==="--expression")if(H=!0,X+1<Z.length&&!$(X+1))z.push(Z[++X]);else Y=!0;else if(V.startsWith("-e"))H=!0,z.push(V.slice(2));else if(V.startsWith("--expression="))H=!0,z.push(V.slice(13));else if(V==="-f"||V==="--file"){if(H=!0,Y=!0,V==="-f")X++}else if(V.startsWith("-f")||V.startsWith("--file="))H=!0,Y=!0;else if(!V.startsWith("-")||V==="-")break}if(Q)return null;if(!H)if(X<Z.length)if($(X))Y=!0;else z.push(Z[X]);else return null;let K=z.join(`
4
+ `),B=Y||d3(K),M=s3(K);if(!B&&!M)return null;if(B)return{programs:z.map((V)=>({text:V,kind:"shell"})),unresolved:!0};return{programs:[],unresolved:!1}}var B2=String.raw`[\s0-9$,!]*(?:\/(?:\\.|[^\/\n])*\/[\s0-9$,!]*)?`;function d3(Z){if(new RegExp(`(?:^|[;{\\n])${B2}e(?:\\s|$|[^A-Za-z])`).test(Z))return!0;return M2(Z).some((J)=>J.includes("e"))}function s3(Z){if(new RegExp(`(?:^|[;{\\n])${B2}[wW]\\s+\\S`).test(Z))return!0;return M2(Z).some((J)=>J.includes("w"))}function M2(Z){let J=[];for(let $=0;$<Z.length;$++){if(Z[$]!=="s")continue;if($>0&&/[A-Za-z0-9_]/.test(Z[$-1]))continue;let z=Z[$+1];if(!z||/[\sA-Za-z0-9\\]/.test(z))continue;let Y=0,Q=$+2;for(;Q<Z.length&&Y<2;Q++){if(Z[Q]==="\\"){Q++;continue}if(Z[Q]===z)Y++}if(Y<2)continue;let X=Z.slice(Q).match(/^[a-zA-Z0-9]*/);J.push(X?X[0]:""),$=Q}return J}var n3=new Set(["-exec","-execdir","-ok","-okdir"]),a3=new Set(["-exec","-execdir"]),o3=new Set("0oprtx"),r3=new Set("adEILnPsJRS"),t3=new Set("eil"),gZ={"--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 e3(Z){if(Object.hasOwn(gZ,Z))return gZ[Z];let J=Object.keys(gZ).filter(($)=>$.startsWith(Z));return J.length===1?gZ[J[0]]:null}function yZ(Z,J,$,z=0){while(J<Z.length){if($(J)){J++;continue}let Y=Z[J];if(Y==="--"){J++;break}if(!Y.startsWith("-")||Y==="-")break;if(Y.startsWith("--")){let H=Y.indexOf("="),K=e3(H<0?Y:Y.slice(0,H));if(K===null){if(z>=4)return[];return[...yZ(Z,J+1,$,z+1),...yZ(Z,J+2,$,z+1)]}J+=K==="value"&&H<0?2:1;continue}let Q=!1,X=!1;for(let H=1;H<Y.length;H++){let K=Y[H];if(o3.has(K))continue;if(t3.has(K))break;if(r3.has(K)){Q=H===Y.length-1;break}X=!0;break}if(X){if(z>=4)return[];return[...yZ(Z,J+1,$,z+1),...yZ(Z,J+2,$,z+1)]}J+=Q?2:1}while(J<Z.length&&$(J))J++;return J<Z.length?[J]:[]}function uZ(Z,J,$=()=>!1){if(J<0||J>=Z.length)return[];let z=G0(Z[J]);if(z==="xargs")return[...new Set(yZ(Z,J+1,$))].map((Q)=>({start:Q,end:Z.length}));if(z!=="find")return[];let Y=[];for(let Q=J+1;Q<Z.length;Q++){if($(Q)||!n3.has(Z[Q]))continue;let X=Q+1,H=X;for(;H<Z.length;H++){if($(H))continue;if(Z[H]===";")break;if(Z[H]==="+"&&H>X&&Z[H-1]==="{}"&&a3.has(Z[Q]))break}if(X<H)Y.push({start:X,end:H});Q=H}return Y}function mZ(Z,J,$){if(J<0||J>=Z.length)return null;let z=G0(Z[J]);if(Object.hasOwn(V0,z)||X2.test(z))return E3(z,Z,J,$);if(y3.has(z))return S3(Z,J,$);if(A3.has(z))return k3(Z,J,$);if(z==="rsync")return x3(Z,J,$);if(z==="git")return m3(Z,J,$);if(z==="sed")return i3(Z,J,$);return null}var $4=600000,J4="Delete via trash guard (rm intercepted and made recoverable)",z4=[".hasna/repos/clones","workspace/repos"],Y4=[".hasna",".ssh",".aws"],U0={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."},Q4=new Set(["sh","bash","zsh","dash","ksh","ash","eval","source",".","su","runuser","env"]),X4={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"]},K4={timeout:1},H4={sudo:{short:{A:W,B:W,b:W,E:W,H:W,i:W,k:W,N:W,n:W,P:W,S:W,s:W,C:_,g:_,p:_,r:_,T:_,t:_,U:_,u:_,e:r,l:r,v:r,D:q,R:q,h:q,K:q,V:q},long:{askpass:W,bell:W,background:W,"close-from":_,chdir:q,"preserve-env":PZ,edit:r,group:_,"set-home":W,help:q,host:q,login:W,"remove-timestamp":q,"reset-timestamp":W,list:r,"no-update":W,"non-interactive":W,"preserve-groups":W,prompt:_,chroot:q,role:_,stdin:W,shell:W,type:_,"command-timeout":_,"other-user":_,user:_,version:q,validate:r},assignments:!0},doas:{short:{n:W,s:W,u:_,C:q,L:q},long:{}},flock:{short:{s:W,x:W,e:W,n:W,u:W,o:W,F:W,w:_,E:_,h:q,V:q},long:{shared:W,exclusive:W,unlock:W,nonblock:W,nonblocking:W,nb:W,timeout:_,wait:_,"conflict-exit-code":_,close:W,"no-fork":W,fcntl:W,verbose:W,help:q,version:q},positionals:[/^[\s\S]+$/]}},B4={...M0,...H4},F2=new Set(["-c","--command"]),M4=new Set(["busybox","toybox"]),N0=new Set(["rm","rmdir","unlink","shred"]),V4=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]),G4=new Set(["-C","-c","--git-dir","--work-tree","--namespace","--exec-path","--config-env"]),U4=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/;function a(Z){return U4.test(L(Z))}function RZ(Z){return Z.map((J)=>J.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var _2=/^[A-Za-z_][A-Za-z0-9_]*=/;function cZ(Z){let J=Z.lastIndexOf("/");return J>=0?Z.slice(J+1):Z}var V2={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
5
+ `,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function W4(Z,J){let $="",z=J;while(z<Z.length&&Z[z]!=="'"){if(Z[z]!=="\\"||z+1>=Z.length){$+=Z[z++];continue}let Y=Z[z+1],Q=Z.slice(z+1),X;if(Object.hasOwn(V2,Y))$+=V2[Y],z+=2;else if(X=Q.match(/^[0-7]{1,3}/))$+=String.fromCharCode(parseInt(X[0],8)&255),z+=1+X[0].length;else if((X=Q.match(/^x([0-9A-Fa-f]{1,2})/))||(X=Q.match(/^u([0-9A-Fa-f]{1,4})/))||(X=Q.match(/^U([0-9A-Fa-f]{1,8})/))){let H=parseInt(X[1],16);$+=H<=1114111?String.fromCodePoint(H):"",z+=1+X[0].length}else if(Y==="c"&&z+2<Z.length)$+=String.fromCharCode(Z.charCodeAt(z+2)&31),z+=3;else $+=`\\${Y}`,z+=2}return{text:$,end:Math.min(z+1,Z.length)}}function iZ(Z){let J="",$=0;while($<Z.length){let z=Z[$];if(z==="$"&&Z[$+1]==="'"){let Y=W4(Z,$+2);J+=Y.text,$=Y.end;continue}if(z==="$"&&Z[$+1]==='"'){$++;continue}if(z==="\\"){if($+1<Z.length)J+=Z[$+1];$+=2;continue}if(z==="'"){let Y=Z.indexOf("'",$+1);if(Y===-1){J+=Z.slice($+1);break}J+=Z.slice($+1,Y),$=Y+1;continue}if(z==='"'){$++;while($<Z.length&&Z[$]!=='"'){if(Z[$]==="\\"&&$+1<Z.length){J+=Z[$+1],$+=2;continue}J+=Z[$],$++}$++;continue}J+=z,$++}return J}function dZ(Z){if(wZ(Z))return!0;let J=null;for(let $=0;$<Z.length;$++){let z=Z[$];if(J==="'"){if(z==="'")J=null;continue}if(z==="\\"){$++;continue}if(z==="`"||z==="$")return!0;if(z==='"'){J=J===null?'"':null;continue}if(J!==null)continue;if(z==="'")J="'";else if(z==="*"||z==="?")return!0;else if(z==="["&&j4(Z,$+1,"]"))return!0}return!1}function j4(Z,J,$){let z=null;for(let Y=J;Y<Z.length;Y++){let Q=Z[Y];if(z!=="'"&&Q==="\\")Y++;else if(z===null&&Q===$)return!0;else if(Q==="'"&&z!=='"')z=z==="'"?null:"'";else if(Q==='"'&&z!=="'")z=z==='"'?null:'"'}return!1}function N4(Z){if(!dZ(Z))return!1;let J=QZ(Z);return J===null||J.some(($)=>iZ($).split(/[^A-Za-z0-9_]+/).some((z)=>N0.has(z)))}function UZ(Z){return cZ(iZ(Z))}var T2={deep:!0};function F0(Z,J){return Z.replace(/\\([$`\\"])/g,($,z)=>z==='"'&&!J?$:z)}function F4(Z,J,$){let z=[],Y=J+1;while(Y<$-1){let Q=Z[Y];if(Q==="\\"){Y+=2;continue}if(Q==="`"){let X=vZ(Z,Y);if(X<0)return null;z.push(F0(Z.slice(Y+1,X-1),!0)),Y=X;continue}if(Q==="$"&&Z[Y+1]==="("){let X=KZ(Z,Y+1);if(X<0)return null;z.push(Z.slice(Y+2,X-1)),Y=X;continue}Y++}return z}function _4(Z){let J=[],$=0;while($<Z.length){let z=Z[$];if(z==="\\"){$+=2;continue}if(z==="`"){let Y=vZ(Z,$);if(Y<0)return null;J.push(F0(Z.slice($+1,Y-1),!1)),$=Y;continue}if(z==="$"&&Z[$+1]==="("){let Y=KZ(Z,$+1);if(Y<0)return null;J.push(Z.slice($+2,Y-1)),$=Y;continue}$++}return J}function G2(Z,J,$,z){let Y=J+1;for(let Q of $){let X=Math.min(Y,Z.length);for(;;){if(Y>Z.length){Y=Z.length+1;break}let K=Z.indexOf(`
6
+ `,Y),B=K===-1?Z.length:K,M=Z.slice(Y,B).replace(/\r$/,"");if(Q.stripTabs)M=M.replace(/^\t+/,"");if(M===Q.delimiter)break;Y=B+1}let H=Z.slice(X,Math.min(Y,Z.length));if(Q.owner.push(H),!Q.quoted){let K=_4(H);if(!K)return-1;z.push(...K)}if(Y<=Z.length){let K=Z.indexOf(`
7
+ `,Y);Y=(K===-1?Z.length:K)+1}}return Math.min(Y-1,Z.length)}function I2(Z,J){let $=Z.indexOf("'",J+1);return $===-1?-1:$+1}function vZ(Z,J){let $=J+1;while($<Z.length){if(Z[$]==="\\"){$+=2;continue}if(Z[$]==="`")return $+1;$++}return-1}function C2(Z,J){let $=J+1;while($<Z.length){let z=Z[$];if(z==="\\"){$+=2;continue}if(z==='"')return $+1;if(z==="`"){let Y=vZ(Z,$);if(Y<0)return-1;$=Y;continue}if(z==="$"&&Z[$+1]==="("){let Y=KZ(Z,$+1);if(Y<0)return-1;$=Y;continue}$++}return-1}function WZ(Z,J){if(Z[J]!=="<"||Z[J+1]!=="<"||Z[J+2]==="<")return null;let $=J+2,z=Z[$]==="-";if(z)$++;while(Z[$]===" "||Z[$]==="\t")$++;let Y="",Q=!1;while($<Z.length&&!/[\s;|&<>()]/.test(Z[$])){let X=Z[$];if(X==="'"||X==='"'){let H=Z.indexOf(X,$+1);if(H<0)return null;Y+=Z.slice($+1,H),Q=!0,$=H+1;continue}if(X==="\\"){if($+1>=Z.length)return null;Y+=Z[$+1],Q=!0,$+=2;continue}Y+=X,$++}return Y?{delimiter:Y,stripTabs:z,quoted:Q,end:$}:null}function sZ(Z,J,$){let z=J+1;for(let Y of $)for(;;){if(z>Z.length)return-1;let Q=Z.indexOf(`
8
+ `,z),X=Q===-1?Z.length:Q,H=Z.slice(z,X);if(H.endsWith("\r"))H=H.slice(0,-1);let K=Y.stripTabs?H.length-H.replace(/^\t+/,"").length:0;if(Y.stripTabs)H=H.slice(K);if(H===Y.delimiter){z=X+1;break}if(H.startsWith(Y.delimiter)&&/^\s*\)/.test(H.slice(Y.delimiter.length))){if(Y===$[$.length-1])return z+K+Y.delimiter.length;return-1}if(Q===-1)return-1;z=Q+1}return z-1}function KZ(Z,J){let $=Z.length,z=Z[J+1]==="(",Y=0,Q=J,X=[];while(Q<$){let H=Z[Q];if(H==="\\"){Q+=2;continue}if(H==="'"){let K=I2(Z,Q);if(K<0)return-1;Q=K;continue}if(H==='"'){let K=C2(Z,Q);if(K<0)return-1;Q=K;continue}if(H==="`"){let K=vZ(Z,Q);if(K<0)return-1;Q=K;continue}if(!z&&H==="<"&&Z[Q+1]==="<"){if(Z[Q+2]==="<"){Q+=3;continue}let K=WZ(Z,Q);if(!K)return-1;X.push(K),Q=K.end;continue}if(H===`
9
+ `&&X.length>0){let K=sZ(Z,Q,X);if(K<0)return-1;X=[],Q=K;continue}if(!z&&H==="#"&&/[\s;&|(]/.test(Z[Q-1])){let K=Z.indexOf(`
10
+ `,Q);if(K<0)return-1;Q=K;continue}if(H==="(")Y++;else if(H===")"){if(Y--,Y===0)return X.length>0?-1:Q+1}Q++}return-1}function u(Z,J={}){let $=J.deep===!0,z=[],Y=[],Q=[],X=new Set,H=[],K=[],B=-1,M=!1,V=!0,G=0,U=Z.length,j=(C)=>{if(B>=0){let N=Q.length;if(Q.push({text:Z.slice(B,C),start:B,end:C}),M)X.add(N);B=-1,M=!1}},F=(C)=>{if(j(C),Q.length>0)z.push($?{words:Q,redirects:X,heredocs:H}:{words:Q,redirects:X});if(Q=[],X=new Set,$)H=[];M=!1},E=(C)=>I2(Z,C),k=(C)=>vZ(Z,C),m=(C)=>KZ(Z,C),d=(C)=>C2(Z,C);while(G<U){let C=Z[G];if(C===" "||C==="\t"||C==="\r"){j(G),G++;continue}if(C===`
11
+ `){if(F(G),K.length>0){let N=G2(Z,G,K,Y);if(K=[],N<0)V=!1,G=U;else G=N;continue}G++;continue}if(C===";"){F(G),G++;continue}if(C==="&"){F(G),G+=Z[G+1]==="&"?2:1;continue}if(C==="|"){F(G),G+=Z[G+1]==="|"?2:1;continue}if($&&C==="("&&B>=0&&"?*+@!".includes(Z[G-1])){V=!1,G=U;continue}if(C==="("||C===")"){F(G),G++;continue}if(C==="<"&&Z[G+1]==="<"&&Z[G+2]!=="<"){let N=Z.slice(G+2).match(/^-?[ \t]*(['"]?)([A-Za-z_][A-Za-z0-9_]*)\1/);if(!N){V=!1,G=U;continue}if($){let FZ=G+2+N[0].length;if(FZ<U&&!/[\s;&|()<>]/.test(Z[FZ])){V=!1,G=U;continue}j(G),K.push({delimiter:N[2],quoted:N[1]!=="",stripTabs:N[0].startsWith("-"),owner:H}),G=FZ;continue}let R=Z.indexOf(`
12
+ `,G+2+N[0].length);if(R===-1){V=!1,G=U;continue}let w=Z.slice(R+1),g=T4(w,N[2]);if(g===-1){V=!1,G=U;continue}j(G),G=R+1+g+N[2].length;continue}if(C===">"||C==="<"){if(B>=0&&/^\d+$/.test(Z.slice(B,G)))B=-1;if(j(G),M=!0,G++,Z[G]===C||Z[G]==="&"||C===">"&&Z[G]==="|"||C==="<"&&Z[G]===">")G++;continue}if(C==="'"){if(B<0)B=G;let N=E(G);if(N<0)V=!1,G=U;else G=N;continue}if(C==='"'){if(B<0)B=G;let N=d(G),R=N<0||!$?[]:F4(Z,G,N);if(N<0||!R)V=!1,G=U;else Y.push(...R),G=N;continue}if(C==="`"){if(B<0)B=G;let N=k(G);if(N<0)V=!1,G=U;else{let R=Z.slice(G+1,N-1);Y.push($?F0(R,!1):R),G=N}continue}if(C==="$"&&Z[G+1]==="("){if(B<0)B=G;let N=m(G+1);if(N<0)V=!1,G=U;else Y.push(Z.slice(G+2,N-1)),G=N;continue}if(C==="\\"){if(B<0)B=G;if(G+1>=U)V=!1,G=U;else G+=2;continue}if(B<0)B=G;G++}if(F(U),K.length>0&&G2(Z,U,K,Y)<0)V=!1;return{segments:z,trustworthy:V,substitutions:Y}}function T4(Z,J){let $=0;while($<=Z.length){let z=Z.indexOf(J,$);if(z===-1)return-1;let Y=z===0||Z[z-1]===`
13
+ `,Q=z+J.length,X=Q===Z.length||Z[Q]===`
14
+ `||Z[Q]==="\r";if(Y&&X)return z;$=z+1}return-1}function L(Z){let J="",$=0;while($<Z.length){let z=Z[$];if(z==="\\"){if($+1<Z.length)J+=Z[$+1];$+=2;continue}if(z==="'"){let Y=Z.indexOf("'",$+1);if(Y===-1){J+=Z.slice($+1);break}J+=Z.slice($+1,Y),$=Y+1;continue}if(z==='"'){$++;while($<Z.length&&Z[$]!=='"'){if(Z[$]==="\\"&&$+1<Z.length){J+=Z[$+1],$+=2;continue}J+=Z[$],$++}$++;continue}J+=z,$++}return J}function h(Z){let J=0,$=0;while(J<Z.words.length&&$++<32){if(Z.redirects.has(J)){J++;continue}let z=Z.words[J].text,Y=L(z);if(_2.test(Y)&&!Y.startsWith("-")){J++;continue}if(V4.has(Y)){J++;continue}let Q=cZ(Y);if(Q==="command")for(let H of Z.words.filter((K,B)=>B>J&&!Z.redirects.has(B))){let K=L(H.text);if(K==="--"||!K.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(K))return-1}let X=X4[Q];if(X){let H=J;J++;while(J<Z.words.length){if(Z.redirects.has(J)){J++;continue}let B=L(Z.words[J].text);if(!B.startsWith("-")||B==="-")break;if(B==="--"){J++;break}if(Q==="env"&&(/^-[iv0]*S/.test(B)||/^--split-string(?:=|$)/.test(B)))return H;if(J++,X.includes(B)||Q==="exec"&&/^-[cl]*a$/.test(B)){while(Z.redirects.has(J))J++;J++}}let K=K4[Q]??0;while(K>0&&J<Z.words.length){let B=L(Z.words[J].text);if(B.startsWith("-")&&B!=="-")break;J++,K--}continue}return J}return-1}function I4(Z,J){let $=[],z=!1;for(let Y=J+1;Y<Z.words.length;Y++){if(Z.redirects.has(Y))continue;let Q=L(Z.words[Y].text);if(!z){if(Q==="--"){z=!0;continue}if(Q.startsWith("-")&&Q!=="-")continue}$.push(Z.words[Y])}return $}function _0(Z){return z4.map((J)=>b.join(Z,...J.split("/")))}function C4(Z,J){if(Z==="~"||Z==="$HOME"||Z==="${HOME}")return J;if(Z.startsWith("~/"))return b.join(J,Z.slice(2));if(Z.startsWith("$HOME/"))return b.join(J,Z.slice(6));if(Z.startsWith("${HOME}/"))return b.join(J,Z.slice(8));return Z}function pZ(Z,J,$){let z=L(Z);if(!z)return null;if(z.includes("`"))return null;if(z==="$HOME"||z==="${HOME}"||z==="$HOME/"||z==="${HOME}/")return $;if(z.replace(/\$\{HOME\}/g,"").replace(/\$HOME/g,"").includes("$"))return null;if(/[*?[\]]/.test(z))return null;if(z.startsWith("~")){let H=C4(z,$);if(H===z)return null;z=H}let X=(b.isAbsolute(z)?b.normalize(z):b.resolve(J,z)).replace(/\/+$/,"");return X===""?"/":X}function ZZ(Z,J){return Z===J||Z.startsWith(`${J}${b.sep}`)}function D4(Z,J){let $=`${b.join(J,".hasna","scratchpad","scratch")}${b.sep}`;if(!Z.startsWith($))return!1;let[z,Y]=Z.slice($.length).split(b.sep);if(!z||!/^[a-z0-9][a-z0-9._-]{0,63}$/.test(z)||z.endsWith(".")||!Y)return!1;let Q=Y.normalize("NFKC").toLowerCase();return Q!=="meta.json"&&Q!==".lock"}function q4(Z,J){if(Z===J)return`\`${Z}\` is the home directory itself, which is never deleted or trashed. Delete a specific file or directory inside it instead.`;for(let $ of $2){if(Z!==$&&!ZZ($,Z))continue;return $==="/"?`\`${Z}\` is the filesystem root, which is never deleted.`:`\`${Z}\` is the system root \`${$}\` (or an ancestor of it), which is never deleted or trashed.`}for(let $ of Y4){let z=b.join(J,$);if($===".hasna"&&D4(Z,J))continue;if(!ZZ(Z,z)&&!ZZ(z,Z))continue;return`\`${Z}\` is the protected \`~/${$}\` path (or contains it), which is never deleted or trashed. Delete a specific file inside it, and only when you are sure.`}return null}function P4(Z,J,$){let z=_0($);if(z.some((Y)=>ZZ(J,Y)))return!0;return Z.some((Y)=>Y!==null&&z.some((Q)=>ZZ(Y,Q)))}var U2=new WeakMap;function O4(Z){let J=U2.get(Z);if(J)return J;let $=Z.words.map((X)=>iZ(X.text)),z=$.findIndex((X)=>X==="-exec"||X==="-execdir"||X==="-ok"||X==="-okdir"),Y=-1;Z.words.forEach((X,H)=>{if(F2.has(L(X.text)))Y=H});let Q={findDelete:$.includes("-delete"),findExecDelete:z>=0&&$.slice(z).some((X)=>N0.has(cZ(X))),namesDelete:$.some((X)=>N0.has(cZ(X))),lastFlockCommand:Y,textMention:a(S4(Z)),envMention:a(RZ(Z.words.map((X)=>L(X.text)))),bodiesMention:a((Z.heredocs??[]).join(`
15
+ `))};return U2.set(Z,Q),Q}var L4=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]);function y4(Z,J){if(!L4.has(UZ(Z.words[J].text)))return!1;for(let $=J+1;$<Z.words.length;$++){if(Z.redirects.has($))continue;let z=L(Z.words[$].text);if(z==="--")return $+1>=Z.words.length;if(/^-[A-Za-z]*s/.test(z))return!0;if(/^-[A-Za-z]*c/.test(z))return!1;if(z==="-o"||z==="+o"||z==="-O"||z==="+O"){$++;continue}if(!/^[-+]/.test(z)||z==="-")return z==="-"}return!0}var W0=(Z)=>Z.kind==="rm"||Z.kind==="refuse",A4="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.",R4="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.",v4="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.",b4="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 T0(Z){let J=[];Z.words.forEach((Y,Q)=>{if(!Z.redirects.has(Q))J.push(Q)});let $=J.map((Y)=>{let Q=Z.words[Y].text;return{text:iZ(Q),opaque:dZ(Q)}}),z=XZ($,B4);if(z===null)return null;return z.index<0?-1:J[z.index]}function j0(Z,J,$,z){let Y=UZ(Z.words[J].text);if(Y==="cd"){let K=Z.words[J+1];if(!K)return{kind:"none"};return{kind:"cd",cwd:pZ(K.text,$,z.home)??z.cwd}}if(Object.hasOwn(U0,Y))return{kind:"refuse",reason:U0[Y]};let Q=D2(Z,J,$,z);if(Q)return Q;if(Y==="rm"){let K=I4(Z,J);if(K.length===0)return{kind:"none"};let B={word:Z.words[J],operands:K},M=_0(z.home),V=(j)=>j!==null&&M.some((F)=>ZZ(j,F)),G=[],U=[];for(let j of K){let F=pZ(j.text,$,z.home);if(G.push(F),!j.text.includes("{"))continue;let E=QZ(j.text);if(E===null)return{kind:"refuse",reason:R4};for(let k of E){let m=pZ(k,$,z.home);if(m===null)continue;if(V(m)&&!V(F))return{kind:"refuse",reason:v4};U.push(m)}}if(P4(G,$,z.home))return B.cwdOnly=G.every((j)=>j!==null&&!V(j)),{kind:"rm",hit:B,handoff:!0,protectedReason:null};for(let j of[...G,...U]){if(!j)continue;let F=q4(j,z.home);if(F)return{kind:"rm",hit:B,handoff:!1,protectedReason:F}}return{kind:"rm",hit:B,handoff:!1,protectedReason:null}}if(M4.has(Y)){let K=Z.words.findIndex((M,V)=>V>J&&!L(M.text).startsWith("-")),B=K>=0?UZ(Z.words[K].text):"";if(B==="rm"||Object.hasOwn(U0,B))return{kind:"refuse",reason:`\`${Y} ${B}\` runs the ${Y} applet, whose own \`rm\` is not GNU \`rm\` and cannot be rewritten in place. Run the delete as \`rm -- <path>\`, which is redirected into trash.`};return{kind:"none"}}if(Y==="git"){let K=I0(Z,J);if(K==="rm"||K==="clean"){if(!(K==="rm"?f4(Z,J):q2(Z,J)))return{kind:"refuse",reason:K==="rm"?"`git rm` is refused: without `--cached` it deletes the working-tree file, and its semantics are not `rm`'s. Use `rm -- <path>` (intercepted and redirected into trash) to remove the file, or `git rm --cached -- <path>` to unstage it without deleting.":"`git clean` deletes untracked files irrecoverably and is refused. Remove them explicitly with `rm -- <path>` (intercepted and redirected into trash), or preview with `git clean -n`."}}return{kind:"none"}}let X=O4(Z);if(Y==="find"){if(X.findDelete)return{kind:"refuse",reason:"`find -delete` deletes files irrecoverably and is refused. List the paths first (`find … -print`), then remove them explicitly with `rm -- <path>` so the delete is redirected into trash."};if(X.findExecDelete)return{kind:"refuse",reason:"`find -exec <delete>` is refused: the delete runs through find, not through `rm`, and cannot be redirected into trash. Remove the paths explicitly with `rm -- <path>`."};return{kind:"none"}}if(Y==="xargs"&&X.namesDelete)return{kind:"refuse",reason:"`xargs rm` takes its targets from stdin, so this hook cannot verify what would be deleted. Pipe the paths into an explicit `rm -- <path> …` instead, which is redirected into trash."};let H=Y==="flock"?X.lastFlockCommand>J:F2.has(Y);if(Q4.has(Y)||H){let K=y4(Z,J)?z.bodiesMention:X.bodiesMention;if((Y==="env"?X.envMention:X.textMention)||K)return{kind:"refuse",reason:`\`${H?"flock":Y}\` runs a command string this hook cannot rewrite in place. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or as a script that uses \`trash guard\` itself.`}}return{kind:"none"}}function D2(Z,J,$,z,Y={segment:Z,index:J},Q=0){let X=UZ(Z.words[J].text);for(let V of uZ(Z.words.map((G)=>L(G.text)),J,(G)=>Z.redirects.has(G))){if(Q>=8)return AZ(Y.segment,Y.index,$,z.home)?{kind:"refuse",reason:E4}:null;let G={words:Z.words.slice(V.start,V.end),redirects:new Set([...Z.redirects].filter((j)=>j>=V.start&&j<V.end).map((j)=>j-V.start))},U=T0(G);for(let j of new Set([h(G),U??-1])){if(j<0)continue;let F=D2(G,j,$,z,Y,Q+1);if(F)return F}}let H=Z.words.map((V,G)=>({word:V,at:G})).filter(({at:V})=>!Z.redirects.has(V)),K=H.findIndex(({at:V})=>V===J),B=K<0?null:lZ(H.map(({word:V})=>V.text),K);if(B&&!B.literal&&(AZ(Z,J,$,z.home)||AZ(Y.segment,Y.index,$,z.home)))return{kind:"refuse",reason:`\`${X}\` runs a shell program that is not a plain literal (an expansion, a substitution or several words), so this hook cannot read what it would delete under a protected repository checkout. Write the program out literally, or run it from outside the checkout.`};let M=mZ(Z.words.map((V)=>L(V.text)),J,(V)=>V>=0&&V<Z.words.length&&(Z.redirects.has(V)||dZ(Z.words[V].text)));if(!M||!(AZ(Z,J,$,z.home)||AZ(Y.segment,Y.index,$,z.home)))return null;if(!M.unresolved&&!M.programs.some((V)=>a(V.text)))return null;return{kind:"refuse",reason:`\`${X}\` runs a program locally (an interpreter's inline program or a command-running option) this hook cannot rewrite, and it could delete a file under a protected repository checkout. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or run the command from outside the checkout.`}}var E4="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 AZ(Z,J,$,z){let Y=_0(z),Q=(X)=>X!==null&&Y.some((H)=>ZZ(X,H));if(Y.some((X)=>ZZ($,X)))return!0;for(let X=J+1;X<Z.words.length;X++){if(Z.redirects.has(X))continue;if(Q(pZ(Z.words[X].text,$,z)))return!0}return!1}function bZ(Z,J){let $={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},z=u(Z,T2);$.trustworthy=z.trustworthy;let Y={cwd:J.cwd,home:J.home,depth:J.depth??0,bodiesMention:a(z.segments.flatMap((K)=>K.heredocs??[]).join(`
16
+ `))};if(!z.trustworthy)return $;let Q=[],X=(K,B=$.refusals)=>{if(K.kind==="refuse")B.push({reason:K.reason});else if(K.kind==="rm"&&K.handoff)$.handoffHits.push(K.hit);else if(K.kind==="rm"){if($.rmHits.push(K.hit),K.protectedReason)$.protectedHits.push({reason:K.protectedReason})}},H=Y.cwd;for(let K of z.segments){let B=h(K),M=T0(K),V=B<0?{kind:"none"}:j0(K,B,H,Y);if(V.kind!=="cd")X(V);let G=(U)=>U!==null&&U>=0&&dZ(K.words[U].text);if(M===null||G(B)||G(M)){if(K.words.some((U,j)=>!K.redirects.has(j)&&(W0(j0(K,j,H,Y))||N4(U.text))))Q.push({reason:A4})}else if(M>=0&&M!==B){let U=j0(K,M,H,Y);if(W0(U))if(W0(V))Q.push({reason:b4});else X(U,Q)}if(V.kind==="cd")H=V.cwd}if(Y.depth<3)for(let K of z.substitutions){let B=bZ(K,{cwd:H,home:Y.home,depth:Y.depth+1});if(B.rmHits.length>0||B.refusals.length>0||B.handoffHits.length>0||B.protectedHits.length>0||!B.trustworthy&&a(K)){$.refusals.push({reason:"This command runs a delete inside a command substitution `$(…)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(z.substitutions.some((K)=>a(K)))$.refusals.push({reason:"This command nests a delete inside command substitutions deeper than this hook will follow. Run the delete as a separate `rm -- <path>` command."});return $.refusals.push(...Q),$}function S4(Z){return Z.words.map((J)=>J.text).join(" ")}function I0(Z,J){let $=J+1;while($<Z.words.length){let z=L(Z.words[$].text);if(!z.startsWith("-"))return z;if($++,G4.has(z))$++}return null}function f4(Z,J){if(Z.words.slice(J+1).map((z)=>L(z.text)).includes("--cached"))return!0;return q2(Z,J)}function q2(Z,J){let $=Z.words.slice(J+1).map((z)=>L(z.text));return $.includes("-n")||$.includes("--dry-run")}function W2(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function k4(Z,J,$,z){let Y=z?["/usr/bin/env","-i",`HOME=${z.home}`,`PATH=${z.path}`,`HASNA_TRASH_AGENT=${z.agent}`,z.runtime,"--config=/dev/null","--no-env-file","--no-macros","--no-install",$,"guard"].map(W2).join(" "):`${W2($)} guard`,Q=[...J].sort((H,K)=>K.word.start-H.word.start),X=Z;for(let H of Q)X=`${X.slice(0,H.word.start)}${Y}${X.slice(H.word.end)}`;return X}function x4(Z,J,$,z,Y){if(!J||J===Z)return!1;if($.length===0)return!1;let Q=bZ(J,{cwd:z,home:Y});if(!Q.trustworthy)return!1;if(Q.rmHits.length>0||Q.handoffHits.length>0)return!1;return Q.refusals.length===0}function h4(Z,J){let $={};for(let[z,Y]of Object.entries(Z??{}))$[z]=Y;if($.command=J,typeof $.description!=="string"||$.description.trim()==="")$.description=J4;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=$4;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function w4(Z,J,$,z,Y){if(typeof Z.command!=="string"||Z.command.trim()==="")return!1;if(typeof Z.description!=="string"||Z.description.trim()==="")return!1;if(typeof Z.timeout!=="number"||!Number.isFinite(Z.timeout)||Z.timeout<=0)return!1;if(typeof Z.run_in_background!=="boolean")return!1;if("dangerouslyDisableSandbox"in Z&&typeof Z.dangerouslyDisableSandbox!=="boolean")return!1;return x4(J,Z.command,$,z,Y)}function g4(Z){let J=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return u(Z,T2).segments.some((z)=>{let Y=T0(z);return[h(z),...Y===null?[]:[Y]].some((Q)=>{if(z.words.slice(0,Q<0?z.words.length:Q).some((K)=>_2.test(L(K.text))||J.has(UZ(K.text))))return!0;if(Q<0)return!1;let H=z.words[Q];return J.has(UZ(H.text))||/^\s*\(\s*\)\s*\{/.test(Z.slice(H.end))})})}function p(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function l4(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function u4(Z){try{if(Z.inspectTrash){let J=Z.inspectTrash();return J.ok?{path:J.path,error:null}:{path:null,error:`${J.code}: ${Z2[J.code]}`}}return{path:Z.findTrash(),error:null}}catch(J){return{path:null,error:J instanceof Error?J.message:String(J)}}}var m4="[trash-guard] No verified @hasna/trash guard was found on PATH. This deletion is refused. Install the current @hasna/trash package with Bun and run its setup; the operating-system trash utility is not a compatible guard.";function P2(Z,J){if(Z.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(Z.tool_name??"")){let B=Z.tool_input?.command;if(typeof B!=="string")return p("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(B))return p("[trash-guard] Delete File would bypass recoverable deletion. First use `trash put -- <path>` or the trash_put MCP tool, then submit any remaining edits without the deletion block.");return{continue:!0}}if(Z.tool_name!=="Bash")return{continue:!0};if(typeof Z.tool_input?.command!=="string")return p("[trash-guard] The Bash tool call carried no readable `command`, so this hook cannot verify what would run. Refusing a call it cannot verify. Re-run the delete explicitly as `rm -- <path>` so it can be redirected into trash.");let z=GZ(Z);if(!z.trim())return{continue:!0};let Y=bZ(z,{cwd:J.cwd,home:J.home});if(Y.refusals.length>0)return p(`[trash-guard] ${Y.refusals[0].reason}`);if(Y.protectedHits.length>0)return p(`[trash-guard] ${Y.protectedHits[0].reason}`);if(!Y.trustworthy)return a(z)?p("[trash-guard] This command could not be parsed to the end (unterminated quote, substitution or here-document), so a delete inside it cannot be redirected. Re-run the delete as a plain `rm -- <path>` command."):{continue:!0};if(Y.rmHits.length===0){if(Y.handoffHits.some((B)=>B.cwdOnly))return p("[trash-guard] This delete runs from inside a protected repository checkout but names only paths outside it. Run it from outside the checkout (`cd /tmp && rm -- <path>`), where it is redirected into trash.");if(Y.handoffHits.length>0)return{continue:!0};return{continue:!0}}if(Y.handoffHits.length>0)return p("[trash-guard] This command mixes a delete under the protected repo-checkout roots (owned by workspace-repos-guard) with a delete outside them, and a partial rewrite would leave one of them unredirected. Re-run them as separate commands, so each delete is handled by the hook that owns it.");let Q=u4(J);if(Q.error!==null)return p(`[trash-guard] The guard could not resolve the \`trash\` binary (${Q.error}), so this \`rm\` cannot be redirected into a recoverable delete — and an unrecoverable delete is never allowed, so the command is refused rather than run. Fix the environment (PATH, permissions) and re-run the same command.`);if(Q.path===null)return p(m4);let X=Q.path;if(J.execution&&g4(z))return p("[trash-guard] A deletion combined with shell environment changes cannot use the verified native execution context. Run the deletion as a separate plain rm command.");let H=k4(z,Y.rmHits,X,J.execution),K=h4(Z.tool_input,H);if(J.execution)K.hasna_execution="hasna.hooks.execution.v1";if(!w4(K,z,Y.rmHits,J.cwd,J.home))return p("[trash-guard] The rewrite of this command did not verify (the delete could not be redirected cleanly), so the command is refused rather than run unredirected. Re-run the delete as a plain `rm -- <path>` command.");return l4(K)}var S=require("node:fs"),y0=require("node:os"),O=require("node:path");var p4=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),c4=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),i4=["hasna","hasnaxyz","hasna-products"],EZ="workspace-repos-guard";function d4(Z){return O.join(Z,".hasna","repos","clones")}function s4(Z){return O.join(Z,"workspace","repos")}function f2(Z){return[d4(Z),s4(Z)]}function n4(Z){return O.join(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var a4=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function C0(Z){let J=process.getuid?.();return J!==void 0&&(Z.uid===0||Z.uid===J)&&(Z.mode&18)===0}function o4(Z){let J=n4(Z),$;try{let Y=S.openSync(J,S.constants.O_RDONLY|S.constants.O_NOFOLLOW);try{let X=S.fstatSync(Y);if(!X.isFile()||!C0(X)||X.size>4096)return null;$=S.readFileSync(Y,"utf8")}finally{S.closeSync(Y)}let Q=O.normalize(Z);for(let X=O.dirname(J);X!==Q;X=O.dirname(X)){let H=S.lstatSync(X);if(!H.isDirectory()||!C0(H)||X===O.dirname(X))return null}if(!C0(S.statSync(Q)))return null}catch{return null}let z=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return z.length>0&&z.every((Y)=>a4.test(Y))?new Set(z):null}function r4(Z=process.env,J=y0.homedir()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((z)=>z.trim()).filter(Boolean));return o4(J)??new Set(i4)}function D0(Z,J,$,z){if(z==="read")return{blocked:!1};let Y=O.relative(J,Z);if(Y===""){if(z==="delete")return{blocked:!0,reason:`[${EZ}] delete of the protected repo-checkout root is forbidden: ${J}`};return{blocked:!0,reason:`[${EZ}] writes directly to the protected repo-checkout root are forbidden: ${J}`}}if(Y.startsWith(`..${O.sep}`)||Y===".."||O.isAbsolute(Y))return{blocked:!1};let Q=Y.split(O.sep).filter(Boolean);if(z==="delete")return{blocked:!0,reason:`[${EZ}] delete under the protected repo-checkout root (${J}) is forbidden at any depth: ${Z}`};if(Q.length<=1)return{blocked:!0,reason:`[${EZ}] writing would create a top-level entry directly under the protected repo-checkout root (${J}); only GitHub-org folders belong there: ${Z}`};let X=Q[0];if(!$.has(X))return{blocked:!0,reason:`[${EZ}] '${X}' is not an allowed GitHub org under the protected repo-checkout root (${J}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var k2=/\b(?:-o|--output|-O|--output-document|-out)\b/,t4=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,e4=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function x2(Z){return Z.replace(t4," ")}function Z5(Z){let J=[],$=null,z=0,Y=0,Q=!1,X=0;for(let H=0;H<Z.length;H++){let K=Z[H];if($==="'"){if(K==="'")$=null;continue}if(K==="\\"){H++;continue}if(K==="("){z++;continue}if(K===")"){if(--z<0)return[Z];continue}if(K==="$"&&Z[H+1]==="{"){Y++,H++;continue}if(K==="}"&&Y>0){Y--;continue}if(K==="`"){Q=!Q;continue}if($==='"'){if(K==='"')$=null;continue}if(K==="'"||K==='"'){$=K;continue}if(K!=="|"||z>0||Y>0||Q||Z[H-1]===">")continue;if(J.push(Z.slice(X,H)),Z[H+1]==="&")H++;X=H+1}if($||z!==0||Y!==0||Q)return[Z];return J.push(Z.slice(X)),J}function $5(Z){let J=[],$="",z="",Y=null,Q=!1,X=()=>{if(!Q)return;let H=z.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),K=$.startsWith("~")&&!/^~(?:\/|$)/.test(z);J.push({text:K?`./${$}`:$,opaque:/[$\x60*?[]/.test(H)||/[()]/.test(H)||wZ(z)}),$="",z="",Q=!1};for(let H=0;H<Z.length;H++){let K=Z[H];if(Y==="'"){if(K==="'")Y=null;else $+=K;z+=K;continue}if(K==="\\"&&H+1<Z.length){let B=Z[H+1];$+=Y==='"'&&!/[$\x60"\\\n]/.test(B)?K+B:B,z+=K+B,Q=!0,H++;continue}if(Y==='"'){if(K==='"')Y=null;else $+=K;z+=K;continue}if(/\s/.test(K)){X();continue}if(Q=!0,z+=K,K==="'"||K==='"')Y=K;else $+=K}if(Y)z+="$";return X(),J}function q0(Z,J,$){let z=Z[J];return z==="--help"||z==="--version"||$&&(z==="-h"||z==="-V")}var O2={read:0,write:1,delete:2};function nZ(...Z){return Z.reduce((J,$)=>O2[$]>O2[J]?$:J,"read")}var J5=new Set(["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"]),h2=new Set(["put","rm","delete","remove"]),z5=new Set([...h2,"restore","restore-capsule","recover","release","locks","retention","hold","unhold","pin","unpin","retrieve","backup-retrieve"]),w2=new Set(["-delete","-exec","-execdir","-ok","-okdir","-fls","-fprint","-fprint0","-fprintf"]);function g2(Z){let J=null;for(let $=0;$<Z.length;$++){let z=Z[$];if(J==="'"){if(z==="'")J=null;continue}if(z==="\\"){$++;continue}if(z==="$"||z==="`")return!0;if(J==='"'){if(z==='"')J=null;continue}if(z==="'"||z==='"')J=z;else if("*?[{".includes(z))return!0}return J!==null}function A0(Z){let J=Z.trim();if(!J)return"read";if(R0(J))return"delete";let $=u(J);if(!$.trustworthy||$.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(J))return HZ(J);let z=$.segments.flatMap((Y)=>{let Q=L2(Y),X=Y.words.filter((B,M)=>!Y.redirects.has(M)).map((B)=>B.text),H=X.map(QZ);if(H.every((B,M)=>B!==null&&B.length===1&&B[0]===X[M]))return[Q];if(H.some((B)=>B===null))return[Q,HZ(X.join(" "))];let K=u(H.flatMap((B)=>B??[]).join(" "));return[Q,...K.trustworthy?K.segments.map(L2):[HZ(X.join(" "))]]});return nZ(...z)}function L2(Z){let J=Z.words.map((Q,X)=>({word:Q,at:X})).filter(({at:Q})=>!Z.redirects.has(Q)),$=h(Z),z=$<0?"read":y2(Z,$),Y=XZ(J.map(({word:Q})=>({text:L(Q.text),opaque:/[$\x60]/.test(Q.text)})));if(Y===null)return nZ(z,HZ(J.map(({word:Q})=>L(Q.text)).join(" ")));if(Y.index<0||J[Y.index].at===$)return z;return nZ(z,y2(Z,J[Y.index].at))}function O0(Z,J,$=0){if(J<0||$>8)return $>8;let z=Z.words.map((B,M)=>({word:B,at:M})).filter(({at:B})=>!Z.redirects.has(B)),Y=z.findIndex(({at:B})=>B===J),Q=Y<0?null:lZ(z.map(({word:B})=>B.text),Y);if(Q){if(!Q.literal)return!0;let B=u(Q.program);if(B.trustworthy&&B.segments.some((M)=>aZ(M,$+1)))return!0}let X=Z.words.map((B)=>L(B.text));for(let B of uZ(X,J,(M)=>Z.redirects.has(M)))if(aZ(Y5(Z,B.start,B.end),$+1))return!0;let K=mZ(X,J,(B)=>B>=0&&B<Z.words.length&&(Z.redirects.has(B)||g2(Z.words[B].text)));if(!K)return!1;if(K.unresolved)return!0;return K.programs.some((B)=>B.kind==="shell"?A0(B.text)!=="read":!K2(B))}function Y5(Z,J,$){let z=new Set([...Z.redirects].filter((Y)=>Y>=J&&Y<$).map((Y)=>Y-J));return{words:Z.words.slice(J,$),redirects:z}}function aZ(Z,J=0){let $=h(Z);if($>=0&&O0(Z,$,J))return!0;let z=Z.words.map((Q,X)=>({word:Q,at:X})).filter(({at:Q})=>!Z.redirects.has(Q)),Y=XZ(z.map(({word:Q})=>({text:L(Q.text),opaque:/[$\x60]/.test(Q.text)})));return Y!==null&&Y.index>=0&&z[Y.index].at!==$&&O0(Z,z[Y.index].at,J)}function R0(Z,J=0){if(J>4)return!1;let $=u(Z);if($.trustworthy&&$.segments.some((Y)=>aZ(Y)))return!0;return(m2(Z)??$.substitutions).some((Y)=>R0(Y,J+1))}function y2(Z,J){if(O0(Z,J))return"delete";let $=Z.words.filter((Q,X)=>X>=J&&!Z.redirects.has(X)),z=$.map((Q)=>L(Q.text)),Y=z[0].split("/").pop();if(["rm","rmdir","shred"].includes(Y??""))return q0(z,1,!1)?"read":"delete";if(["unlink","rmtree","del"].includes(Y??""))return"delete";if(Y==="trash"){let Q=1;while(Q<z.length&&z[Q].startsWith("-")){let X=z[Q++];if(["--help","-h","--version","-V","--identity"].includes(X))return"read";if(["--agent","--spool","--files","--info","--config"].includes(X))Q++;else if(!["--json","--local"].includes(X))return"delete"}if(Q===z.length||J5.has(z[Q]))return"read";if(z5.has(z[Q])&&q0(z,Q+1,!0))return"read";if(["restore","restore-capsule"].includes(z[Q]))return"write";return"delete"}if(Y==="git"){let Q=I0(Z,J);if(Q==="clean"||Q==="rm")return z[1]===Q&&q0(z,2,!0)?"read":"delete";return Q==="clone"||Q==="init"?"write":"read"}if(Y==="find"&&!$.some((Q)=>g2(Q.text))&&!z.some((Q)=>w2.has(Q)))return"read";if(Y==="env"&&a(RZ(z)))return"delete";if(["sh","bash","zsh","dash","ksh","ash","eval","source",".","su","runuser","env","xargs","find","busybox","toybox"].includes(Y??""))return HZ(z.join(" "));if(["mkdir","mkfile","touch","mv","cp","ln","tee","install","dd","rsync","scp","truncate"].includes(Y??""))return"write";if(Y==="curl"||Y==="wget")return k2.test(z.join(" "))?"write":"read";if(Y==="sed"&&z.slice(1).some((Q)=>/^-i|^--in-place(?:=|$)/.test(Q)))return"write";if(["python","python3","node","bun"].includes(Y??"")&&z.some((Q)=>Q==="-c"||Q==="-e"))return"write";return"read"}function HZ(Z){let J=Z.replace(/[{},]/g," ");return J===Z?P0(Z):nZ(P0(Z),P0(J))}function P0(Z){let J=Z.trim();if(!J)return"read";if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:rm|rmdir|unlink|shred|trash|rmtree|del)(?:\s|$)/.test(J))return"delete";if(/\bgit\b/.test(J)){if(/\bgit\b[^;&|]*\b(?:clean|rm)\b/.test(J))return"delete";if(/\bgit\b[^;&|]*\b(?:clone|init)\b/.test(J))return"write";return"read"}if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|mv|cp|ln|tee|install|dd)(?:\s|$)/.test(J))return"write";if(/\b(?:curl|wget)\b/.test(J)){if(k2.test(J))return"write";return"read"}if(/\bsed\b/.test(J)){if(/(?:^|\s)-i\S*(?:\s|$)|--in-place(?:\s|$)/.test(J))return"write"}else if(/\b(?:rsync|scp|truncate)\b/.test(J))return"write";else if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(J))return"write";if(/(?:^|[;&|])\s*echo\b/.test(J)||/>/.test(x2(J)))return"write";return"read"}function SZ(Z,J){let $=Z.trim(),z=$.match(/^(['"])([\s\S]*)\1$/);if(z)$=z[2];if($=$.replace(/^"*\$HOME"*\//,"$HOME/"),$=$.replace(/^"*\$\{HOME\}"*\//,"${HOME}/"),$==="~")return J;if($.startsWith("~/"))return O.join(J,$.slice(2));if($==="$HOME"||$==="${HOME}")return J;if($.startsWith("$HOME/"))return O.join(J,$.slice(6));if($.startsWith("${HOME}/"))return O.join(J,$.slice(8));let Y=$.match(new RegExp(`^"*${L0(J)}"*/`));if(Y)return J+"/"+$.slice(Y[0].length);return Z}function Q5(Z){let J=Z.trim();while(J.startsWith("(")||/^\{(?:\s|$)/.test(J))J=J.slice(1).trim();while(J.endsWith(")")||/(?:^|\s)\}$/.test(J))J=J.slice(0,-1).trim();return J}function L0(Z){return Z.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function A2(Z,J,$){if(Z===void 0)return[$];let z=SZ(Z,$),Y=z.match(/^(['"])(.*)\1$/);if(Y)z=Y[2];if(!z||z==="-"||/[$\x60*?[\]{}~\\'"]/.test(z))return null;return[...new Set(J.map((Q)=>O.resolve(Q,z)))]}var X5=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function K5(Z,J){let $=XZ(J);if(!$||$.index<=0||J[$.index].opaque)return 0;let z=u(Z);if(!z.trustworthy||z.substitutions.length>0||z.segments.length!==1)return 0;let[Y]=z.segments;if(Y.redirects.size>0||Y.words.length!==J.length)return 0;if(Y.words.some((Q,X)=>L(Q.text)!==J[X].text))return 0;return h(Y)===$.index?$.index:0}function H5(Z,J){let $=0;if(Z==="git")$=J.findIndex((Y)=>Y.text==="rm"||Y.text==="clean")+1;let z=!1;return J.slice($).filter((Y)=>{if(!z&&Y.text==="--")return z=!0,!1;if(!z&&Y.text.startsWith("-")&&!Y.opaque)return!1;return z=!0,!0})}var B5=new Set(["--agent","--spool","--files","--info","--config"]),M5=new Set(["--spool","--files","--info","--config"]),V5=new Set(["--json","--local","--help","-h","--version","--identity"]),R2={"--agent":/^[^-]/,"--retention":/^(?:\d+(?:\.\d+)?|never)$/},G5=new Set(["--to"]);function U5(Z){let J=[],$=0;for(;$<Z.length&&Z[$].text.startsWith("-");$++){let Q=Z[$];if(Q.opaque)return null;if(B5.has(Q.text)){let X=Z[++$];if(!X||X.opaque)return null;if(M5.has(Q.text))J.push(X)}else if(!V5.has(Q.text))return null}let z=Z[$];if(!z||z.opaque||!h2.has(z.text))return null;let Y=!1;for($++;$<Z.length;$++){let Q=Z[$];if(Y||Q.opaque||Q.text==="-"||!Q.text.startsWith("-")){J.push(Q);continue}if(Q.text==="--"){Y=!0;continue}let X=Q.text.indexOf("="),H=X<0?Q.text:Q.text.slice(0,X);if(G5.has(H)){if(X>=0)J.push({text:Q.text.slice(X+1),opaque:!1});else if(Z[$+1]&&!Z[$+1].text.startsWith("-"))J.push(Z[++$]);continue}let K=Z[$+1];if(X<0&&Object.hasOwn(R2,H)&&K&&!K.opaque&&R2[H].test(K.text))$++}return J}function W5(Z){let J=Z.split(`
17
+ `),$=[],z=[],Y=0;while(Y<J.length){let Q=Y,X=J[Y++].replace(/\r$/,""),H=[];for(let K=0;K<X.length;K++){let B=X[K],M=z[z.length-1];if(B==="\\"){K++;continue}if(B==="$"&&X[K+1]==="("&&X[K+2]==="("){let V=X.indexOf("))",K+3);if(V<0)return null;K=V+1;continue}if(B==="$"&&X[K+1]==="("){z.push(0),K++;continue}if(B==="$"&&X[K+1]==="[")return null;if(B==="$"&&X[K+1]==="{"){let V=X.indexOf("}",K+2);if(V<0||/['"\x60$]|<</.test(X.slice(K+2,V)))return null;K=V;continue}if(B==="`"){let V=X.indexOf("`",K+1);if(V<0)return null;K=V;continue}if(M==='"'){if(B==='"')z.pop();continue}if(B==="'"){let V=X.indexOf("'",K+1);if(V<0)return null;K=V;continue}if(B==='"'){z.push('"');continue}if(B==="#"&&(K===0||/[\s;&|()]/.test(X[K-1])))break;if(B==="("&&X[K+1]==="("&&(K===0||/[\s;&|(]/.test(X[K-1]))){let V=X.indexOf("))",K+2);if(V<0)return null;K=V+1;continue}if(typeof M==="number"&&(B==="("||B===")")){if(B==="(")z[z.length-1]=M+1;else if(M===0)z.pop();else z[z.length-1]=M-1;continue}if(B==="<"&&X[K+1]==="<"){if(X[K+2]==="<"){K+=2;continue}let V=WZ(X,K);if(!V)return null;H.push({marker:V,from:K}),K=V.end-1}}for(let{marker:K,from:B}of H){let M=Y;for(;;){if(Y>=J.length)return null;let V=J[Y++].replace(/\r$/,"");if(K.stripTabs)V=V.replace(/^\t+/,"");if(V===K.delimiter)break}$.push({line:Q,from:B,to:K.end,start:M,end:Y-1,quoted:K.quoted})}}return z.length===0?$:null}var j5=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"]),N5=new Set([".","source","eval","env","alias","hash"]),F5=new Set(["tee","cp","mv","install","ln"]),l2=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"]),_5=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),T5=new Set(["pr","issue","api","release","gist"]);function I5(Z,J){let $=Z[J];if($==="gh")return T5.has(Z[J+1]??"");if($!=="git")return l2.has($);for(let z=J+1;z<Z.length;z++){let Y=Z[z];if(Y==="-C")z++;else if(Y==="--no-pager"||Y==="-P")continue;else return!Y.startsWith("-")&&_5.has(Y)}return!1}function C5(Z,J){for(let $=J+1;$<Z.length;$++){let z=Z[$];if(z==="\\")$++;else if(z==='"')return $;else if(z==="$"&&Z[$+1]==="("){if($=u2(Z,$+1),$<0)return-1}else if(z==="`"){if($=Z.indexOf("`",$+1),$<0)return-1}}return-1}function u2(Z,J){let $=0;for(let z=J;z<Z.length;z++){let Y=Z[z];if(Y==="\\")z++;else if(Y==="'"||Y==="`"){if(z=Z.indexOf(Y,z+1),z<0)return-1}else if(Y==='"'){if(z=C5(Z,z),z<0)return-1}else if(Y==="(")$++;else if(Y===")"&&--$===0)return z}return-1}function m2(Z){let J=[],$=!1;for(let z=0;z<Z.length;z++){let Y=Z[z];if(Y==="\\")z++;else if(Y==="'"&&!$){let Q=Z.indexOf("'",z+1);if(Q<0)return null;z=Q}else if(Y==='"')$=!$;else if(Y==="$"&&Z[z+1]==="("){let Q=u2(Z,z+1);if(Q<0)return null;let X=Z.slice(z+2,Q);if(Z[z+2]==="("){if(/\$\(|\x60/.test(X))return null}else J.push(X);z=Q}else if(Y==="`"){let Q=Z.indexOf("`",z+1);if(Q<0)return null;J.push(Z.slice(z+1,Q)),z=Q}}return $?null:J}function D5(Z){if(/[<>]\(/.test(Z))return!0;let J=[],$=[Z];for(let Y=0;$.length>0;Y++){if(Y>64)return!0;let Q=$.shift(),X=u(Q),H=m2(Q);if(!X.trustworthy||!H)return!0;J.push(...X.segments),$.push(...new Set([...X.substitutions,...H]))}let z=new Set;for(let Y of J){let Q=Y.words.map((K)=>L(K.text));for(let K of Y.redirects)z.add(n(Q[K]??""));let X=h(Y);if(X<0)continue;let H=n(Q[X]);if(F5.has(H)){for(let K of Q.slice(X+1))if(!K.startsWith("-"))z.add(n(K))}if(H==="dd"){for(let K of Q)if(K.startsWith("of="))z.add(n(K.slice(3)))}}z.delete("");for(let Y of J){for(let B of Y.words){let M=n(L(B.text));if(j5.has(M)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(M))return!0}let Q=h(Y),X=Y.words.map((B,M)=>({text:L(B.text),at:M})).filter(({at:B})=>!Y.redirects.has(B));if(X.some(({text:B,at:M})=>(Q<0||M<Q)&&OZ.test(B)))return!0;if(Q<0)continue;let H=Y.words[Q].text,K=L(H);if(/[$\x60]/.test(H)||K.includes("/")||N5.has(K)||z.has(K))return!0;if(!I5(X.filter(({at:B})=>B>=Q).map(({text:B})=>B),0))return!0}return!1}function q5(Z){if(!Z.includes("<<"))return null;let J=W5(Z);if(!J||J.length===0)return null;let $=Z.split(`
18
+ `),z=[...$],Y=[];for(let X of J){let H=$.slice(X.start,X.end);if(!X.quoted&&H.some((K)=>/\$\(|\x60/.test(K)))return null;Y.push(H.join(`
19
+ `));for(let K=X.start;K<=X.end;K++)z[K]=""}let Q=[...z];for(let X of[...J].reverse()){let H=Q[X.line];Q[X.line]=H.slice(0,X.from)+" ".repeat(X.to-X.from)+H.slice(X.to)}return D5(Q.join(`
20
+ `))?null:{outer:z.join(`
21
+ `),bodies:Y}}var P5="/";function p2(Z,J,$){if(!Z)return[];let z=q5(Z);if(!z)return S2(Z,J,$);return[...S2(z.outer,J,$),...z.bodies.flatMap((Y)=>p2(Y,J,P5))]}var O5=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,L5=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function v2(Z,J,$=!1){let z=[],Y=0;for(let H of J)z.push(Y),Y+=H.length;let Q=u(Z);if(!Q.trustworthy||!$&&Q.substitutions.length>0)return null;let X=Q.segments.flatMap((H)=>H.words).filter((H)=>J.some((K,B)=>B%2===1&&z[B]<H.end&&z[B]+K.length>H.start));return X.length>0?{lexed:Q,offsets:z,words:X}:null}function b2(Z,J,$=[]){if(A0(J)!=="read")return!1;let z=h(Z),Y=Z.words.filter((M,V)=>!Z.redirects.has(V)),Q=XZ(Y.map((M)=>({text:L(M.text),opaque:/[$\x60]/.test(M.text)})));if(Q===null)return!1;let X=[z<0?1/0:z,Q.index<0?1/0:Z.words.indexOf(Y[Q.index])];if(Z.words.some((M,V)=>V<Math.max(...X)&&!Z.redirects.has(V)&&OZ.test(L(M.text))))return!1;if([z<0?null:Z.words[z].text,Q.index<0?null:Y[Q.index].text].every((M)=>M===null||l2.has(n(L(M)))))return!0;let K=Y.filter((M)=>!$.includes(M)),B=K.map((M)=>L(M.text));return HZ(K.map((M)=>M.text).join(" "))==="read"&&HZ(B.join(" "))==="read"&&!B.some((M)=>w2.has(M))}function y5(Z,J,$,z){let Y=(Q)=>Q.start<z&&Q.end>$;if(!J.words.some(Y))return!1;return J.lexed.segments.filter((Q)=>Q.words.some(Y)).some((Q)=>aZ(Q))}var E2=(Z,J)=>Z.slice(J.words[0].start,J.words[J.words.length-1].end);function A5(Z,J,$,z){let Y=(X)=>X.start<z&&X.end>$,Q=J.words.filter(Y);if(Q.length===0||Q.some((X)=>!L5.test(X.text)))return!1;for(let X of J.lexed.segments.filter((H)=>H.words.some(Y)))if(!b2(X,E2(Z,X),J.words))return!1;for(let X of Q){let H=X.text.slice(1,-1);if(H.includes("<<"))return!1;let K=u(H);if(!K.trustworthy||K.substitutions.length>0)return!1;if(!K.segments.every((B)=>b2(B,E2(H,B))))return!1}return!0}function S2(Z,J,$){if(!Z)return[];let z=f2(J),Y=(U)=>z.some((j)=>U===j||U.startsWith(`${j}${O.sep}`)),Q=Z.split(O5),X=v2(Z,Q),H=X??v2(Z,Q,!0),K=[],B=[$],M=new Set([$]),V=!0,G=[];for(let U=0;U<Q.length;U+=2){let j=U===0?"":Q[U-1].trim();if(j==="||")V=!1;else if(j!=="&&")V=!0;if(j!=="&&"||!V)B=[...M];let F=Q[U],E=(F.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,k=(F.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let D=0;D<E;D++)G.push({current:[...B],reachable:new Set(M),certain:V});let m=Q5(F),d=X!==null&&A5(Z,X,X.offsets[U],X.offsets[U]+F.length),C=!d&&(H!==null&&y5(Z,H,H.offsets[U],H.offsets[U]+F.length)||R0(F.trim())),N=m.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),R=N?null:m.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(R){for(let D of A2(R[1],B,J)??[])M.add(D);V=!1,B=[...M]}let w=L0(J),g=z.map((D)=>L0(D.slice(J.length+1))).join("|"),FZ=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${w}"*)/(?:${g})`),a0=new RegExp(`(${FZ.source})([^\\s"';&|<>()\`]*|$)`,"g"),o0=(D)=>{let s=[],l;a0.lastIndex=0;while((l=a0.exec(D))!==null)s.push(O.normalize(SZ(l[0],J)).replace(/\/+$/,""));return s},Y0=Z5(m).map((D)=>{let s=[],l=!1,_Z=x2(D).replace(e4,(X0,YZ)=>{if(!YZ||/[$\x60]/.test(YZ))l=!0;if(YZ)s.push(YZ);return" "}),TZ=d?"read":C?"delete":A0(_Z);return{commandPart:_Z,operands:s,op:l&&TZ==="read"?"write":TZ}}),B3=Y0.some((D)=>D.op==="delete")?"delete":Y0.some((D)=>D.op==="write")?"write":"read",Q0=B.filter(Y);if(C)for(let D of Q0)K.push({path:D,op:"delete"});for(let D of Y0){let s=!1;for(let x of o0(D.commandPart))s=!0,K.push({path:x,op:B3});for(let x of D.operands){let t=o0(x);for(let i of t)K.push({path:i,op:"write"});if(t.length>0)continue;for(let i of Q0)K.push({path:O.normalize(O.resolve(i,SZ(x,J))),op:"write"})}if(s||D.op==="read")continue;let l=$5(D.commandPart),_Z=K5(D.commandPart,l),TZ=n(l[_Z]?.text??""),X0=l.slice(_Z+1),YZ=((TZ==="trash"?U5(X0):null)??H5(TZ,X0)).map((x)=>x.opaque?".":x.text),M3=D.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(D.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(D.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(D.commandPart),IZ=[];if(M3)for(let x of YZ.length>0?YZ:["."])IZ.push({operand:x,op:D.op});else{let x=D.commandPart.match(X5),t=l.at(-1);if(IZ.push({operand:x?x[1]:!t||t.opaque?".":t.text,op:D.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(D.commandPart))l.forEach((i,r0)=>{let VZ,K0=i.text.match(/^-[A-Za-z]*?t(.*)$/),kZ=i.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(K0&&!i.text.startsWith("--"))VZ=K0[1]?{text:K0[1],opaque:i.opaque}:l[r0+1];else if(kZ&&"--target-directory".startsWith(kZ[1]))VZ=kZ[2]!==void 0?{text:kZ[2],opaque:i.opaque}:l[r0+1];if(VZ)IZ.push({operand:VZ.opaque||!VZ.text?".":VZ.text,op:D.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(D.commandPart))IZ.push({operand:".",op:D.op})}for(let x of Q0)for(let{operand:t,op:i}of IZ)K.push({path:O.normalize(O.resolve(x,SZ(t,J))),op:i})}if(N){let D=A2(N[1],B,J);if(D){for(let s of D)M.add(s);if(V)B=D}else V=!1}for(let D=0;D<k&&G.length>0;D++)({current:B,reachable:M,certain:V}=G.pop())}return K}var R5=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function v5(Z,J){let $=[],z;while((z=R5.exec(Z))!==null){let Y=z[1]==="Delete File"?"delete":"write";$.push({path:O.normalize(O.resolve(J,z[2])),op:Y})}return $}function c2(Z,J={}){let $=[];if(Z.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:$};let z=typeof Z.tool_name==="string"?Z.tool_name:"",Y=J.home??y0.homedir(),Q=f2(Y),X=r4(process.env,Y);if(z==="Bash"){let G=GZ(Z);if(!G)return{output:{continue:!0},warnings:$};let U=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd(),j=p2(G,Y,U);for(let F of j)for(let E of Q){let k=D0(F.path,E,X,F.op);if(k.blocked)return{output:{decision:"block",reason:k.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let H=Z.tool_input??{},K=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(c4.has(z)){let G=typeof H.patch==="string"?H.patch:"";if(!G)return{output:{continue:!0},warnings:$};let U=v5(G,K);for(let j of U)for(let F of Q){let E=D0(j.path,F,X,j.op);if(E.blocked)return{output:{decision:"block",reason:E.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!p4.has(z))return{output:{continue:!0},warnings:$};let B=typeof H.file_path==="string"?H.file_path:typeof H.path==="string"?H.path:typeof H.notebook_path==="string"?H.notebook_path:null;if(!B)return{output:{continue:!0},warnings:$};let M=SZ(B,Y),V=O.isAbsolute(M)?O.normalize(M):O.resolve(K,M);for(let G of Q){let U=D0(V,G,X,"write");if(U.blocked)return{output:{decision:"block",reason:U.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var b5=new Set(["id","node_id","databaseId","fullDatabaseId","number","state","state_reason","stateReason","status","conclusion","bucket","name","login","sha","oid","abbreviatedOid","ref","headRefName","baseRefName","headRefOid","baseRefOid","head_sha","headSha","head_branch","headBranch","merged","mergeable","mergeable_state","mergeStateStatus","draft","isDraft","locked","isLocked","title","displayTitle","display_title","created_at","updated_at","closed_at","merged_at","started_at","completed_at","submitted_at","pushed_at","published_at","createdAt","updatedAt","closedAt","mergedAt","startedAt","completedAt","submittedAt","pushedAt","publishedAt","tag_name","tagName","total_count","totalCount","count","additions","deletions","changes","changed_files","changedFiles","filename","path","event","workflow","workflowName","workflow_id","workflowDatabaseId","run_id","run_number","run_attempt","attempt","check_suite_id","default_branch","defaultBranch","full_name","fullName","nameWithOwner","private","isPrivate","visibility","archived","isArchived","fork","isFork","isRequired","is_required","required","context","type","__typename","role","permission","size","reviewDecision","author_association","authorAssociation","isCrossRepository","maintainerCanModify","maintainer_can_modify","commentsCount","language","digest","size_in_bytes","run_started_at","date","wait_timer","ahead_by","behind_by","total_commits","expired","current_user_can_approve","environment","html_url"]),E5=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),n2=new Set(["length","utf8bytelength","not","type","any","all","isempty","empty","test","startswith","endswith","contains","inside","has","in","index","rindex","indices","floor","ceil","round","fabs","sqrt","isinfinite","isnan","isnormal","infinite","nan","true","false","null"]),a2=new Set(["tostring","tojson","ascii_downcase","ascii_upcase","ltrimstr","rtrimstr","trim","ltrim","rtrim","sort","unique","reverse","first","last","min","max","add","flatten","join","split","values","nulls","strings","numbers","booleans","arrays","objects","iterables","scalars","sort_by","group_by","unique_by","min_by","max_by","select","limit","to_entries","from_entries"]),S5=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),f5=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class E0 extends Error{}var y=()=>{throw new E0};function v0(Z,J){let $=[],z="",Y=J+1;while(Y<Z.length){let Q=Z[Y];if(Q==='"'){if(z)$.push(z);return{end:Y+1,parts:$}}if(Q==="\\"){let X=Z[Y+1];if(X==="("){let H=1,K=Y+2;while(K<Z.length&&H>0){let B=Z[K];if(B==='"'){K=v0(Z,K).end;continue}if(B==="(")H++;else if(B===")")H--;K++}if(H!==0)y();if(z)$.push(z),z="";$.push({src:Z.slice(Y+2,K-1)}),Y=K;continue}if(X===void 0)y();z+=X,Y+=2;continue}z+=Q,Y++}return y()}function o2(Z){let J=[],$=0,z=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let Y=Z[$];if(/\s/.test(Y)){$++;continue}if(Y==="#")y();if(Y==='"'){let K=v0(Z,$);J.push({t:"str",parts:K.parts}),$=K.end;continue}if(Y==="."){if(Z[$+1]===".")y();let K=/^[A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($+1));if(K){J.push({t:"field",name:K[0]}),$+=1+K[0].length;continue}if(Z[$+1]==='"'){let B=v0(Z,$+1);if(B.parts.some((M)=>typeof M!=="string"))y();J.push({t:"field",name:B.parts.join("")}),$=B.end;continue}J.push({t:"dot"}),$++;continue}if(Y==="$"||Y==="@"){let K=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($));if(!K||Y==="$")y();J.push({t:"fmt",name:K[0]}),$+=K[0].length;continue}let Q=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(Z.slice($));if(Q){J.push({t:"num"}),$+=Q[0].length;continue}let X=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(Z.slice($));if(X){J.push({t:"ident",name:X[0]}),$+=X[0].length;continue}let H=z.find((K)=>Z.startsWith(K,$));if(!H)y();J.push({t:"op",v:H}),$+=H.length}return J}var k5=new Set(["if","then","elif","else","end","as","def","reduce","foreach","try","catch","label","import","include","and","or","__loc__","error","input","inputs","debug","stderr","env","halt","halt_error","input_filename","input_line_number","recurse","paths","leaf_paths","getpath","setpath","delpaths","del","path","splits","sub","gsub","capture","match","scan","keys","keys_unsorted","map_values","with_entries","tostream","fromstream","truncate_stream","walk","tonumber","implode","explode","ascii","fromjson"]);class S0{tokens;at=0;constructor(Z){this.tokens=Z}parse(){if(this.tokens.length===0)y();let Z=this.pipe();if(this.at!==this.tokens.length)y();return Z}peek(){return this.tokens[this.at]}isOp(Z){let J=this.peek();return!!J&&J.t==="op"&&J.v===Z}isIdent(Z){let J=this.peek();return!!J&&J.t==="ident"&&J.name===Z}expectOp(Z){if(!this.isOp(Z))y();this.at++}pipe(){let Z=this.comma();if(this.isIdent("as"))y();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.pipe()};return Z}comma(){let Z=this.alt();while(this.isOp(","))this.at++,Z={k:"comma",a:Z,b:this.alt()};return Z}alt(){let Z=this.or();if(this.isOp("//"))return this.at++,{k:"alt",a:Z,b:this.alt()};return Z}or(){let Z=this.and();while(this.isIdent("or"))this.at++,Z={k:"bool",a:Z,b:this.and()};return Z}and(){let Z=this.cmp();while(this.isIdent("and"))this.at++,Z={k:"bool",a:Z,b:this.cmp()};return Z}cmp(){let Z=this.add();for(let J of["==","!=","<=",">=","<",">"])if(this.isOp(J))return this.at++,{k:"bool",a:Z,b:this.add()};for(let J of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(J))y();return Z}add(){let Z=this.mul();while(this.isOp("+")||this.isOp("-"))this.at++,Z={k:"arith",a:Z,b:this.mul()};return Z}mul(){let Z=this.unary();while(this.isOp("*")||this.isOp("/")||this.isOp("%"))this.at++,Z={k:"arith",a:Z,b:this.unary()};return Z}unary(){if(this.isOp("-"))return this.at++,{k:"neg",of:this.postfix()};return this.postfix()}objectValue(){let Z=this.unary();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.objectValue()};return Z}postfix(){let Z=this.primary();for(;;){let J=this.peek();if(!J)return Z;if(J.t==="field"){this.at++,Z={k:"field",name:J.name,of:Z};continue}if(J.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(J.t==="op"&&J.v==="?"){this.at++,Z={k:"opt",of:Z};continue}if(J.t==="op"&&J.v==="["){Z=this.bracket(Z);continue}return Z}}bracket(Z){if(this.expectOp("["),this.isOp("]"))return this.at++,{k:"iter",of:Z};if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}let J=this.pipe();if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}return this.expectOp("]"),{k:"index",of:Z,key:J}}primary(){let Z=this.peek();if(!Z)return y();switch(this.at++,Z.t){case"dot":return{k:"dot"};case"field":return{k:"field",name:Z.name};case"num":return{k:"lit"};case"str":return this.stringNode(Z.parts);case"fmt":{if(!f5.has(Z.name))y();let J=this.peek();if(J?.t==="str")return this.at++,{k:"fmt",name:Z.name,str:this.stringNode(J.parts)};return{k:"fmt",name:Z.name}}case"ident":{if(k5.has(Z.name))y();if(Z.name==="map"||n2.has(Z.name)||a2.has(Z.name)){let J=[];if(this.isOp("(")){this.at++,J.push(this.pipe());while(this.isOp(";"))this.at++,J.push(this.pipe());this.expectOp(")")}return{k:"call",name:Z.name,args:J}}return y()}case"op":{if(Z.v==="("){let J=this.pipe();return this.expectOp(")"),J}if(Z.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let J=this.pipe();return this.expectOp("]"),{k:"array",of:J}}if(Z.v==="{")return this.object();return y()}}return y()}stringNode(Z){let J=[];for(let $ of Z){if(typeof $==="string")continue;J.push(new S0(o2($.src)).parse())}return J.length===0?{k:"str",parts:J,text:Z.join("")}:{k:"str",parts:J}}object(){let Z=[];if(this.isOp("}"))return this.at++,{k:"object",entries:Z};for(;;){let J=this.peek();if(!J)y();this.at++;let $;if(J.t==="ident")$=J.name;else if(J.t==="str"){if(J.parts.some((z)=>typeof z!=="string"))y();$=J.parts.join("")}else y();if(this.isOp(":"))this.at++,Z.push({key:"static",value:this.objectValue()});else Z.push({key:"static",value:{k:"field",name:$}});if(this.isOp(",")){this.at++;continue}return this.expectOp("}"),{k:"object",entries:Z}}}}function f0(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(f0);return Z==="safe"||typeof Z==="object"&&b5.has(Z.leaf)}var fZ=(...Z)=>Z.every(f0)?"safe":"tainted";function b0(...Z){let J=[];for(let $ of Z)if(typeof $==="object"&&"union"in $)J.push(...$.union);else J.push($);return J.length===1?J[0]:{union:J}}function oZ(Z,J){return typeof Z==="object"&&"union"in Z?b0(...Z.union.map(J)):J(Z)}var rZ=(Z)=>typeof Z==="object"&&("leaf"in Z)&&E5.has(Z.leaf),$Z=(Z)=>oZ(Z,(J)=>J==="safe"?"safe":J==="tainted"||rZ(J)?"tainted":"unknown");function i2(Z){return Z.k==="lit"||Z.k==="str"&&Z.parts.length===0||Z.k==="call"&&["true","false","null"].includes(Z.name)&&Z.args.length===0}function d2(Z,J,$){return oZ(Z,(z)=>{if(z==="safe"||z==="tainted")return z;if(rZ(z))return"tainted";if(z==="root"&&$.rootScalars.has(J))return"safe";return{leaf:J}})}function A(Z,J,$){switch(Z.k){case"dot":return J;case"field":return d2(Z.of?A(Z.of,J,$):J,Z.name,$);case"iter":return $Z(A(Z.of,J,$));case"index":{let z=A(Z.of,J,$);if(Z.key.k==="str"&&Z.key.text!==void 0)return d2(z,Z.key.text,$);if(Z.key.k==="lit")return $Z(z);return A(Z.key,J,$),"tainted"}case"slice":return oZ(A(Z.of,J,$),(z)=>z==="root"?"unknown":rZ(z)?"tainted":z);case"opt":return A(Z.of,J,$);case"lit":return"safe";case"str":return fZ(...Z.parts.map((z)=>A(z,J,$)));case"fmt":return Z.str?A(Z.str,J,$):J;case"array":return Z.of?fZ(A(Z.of,J,$)):"safe";case"object":return fZ(...Z.entries.map((z)=>A(z.value,J,$)));case"pipe":return A(Z.b,A(Z.a,J,$),$);case"comma":return b0(A(Z.a,J,$),A(Z.b,J,$));case"alt":return b0(A(Z.a,J,$),A(Z.b,J,$));case"bool":return A(Z.a,J,$),A(Z.b,J,$),"safe";case"arith":return fZ(A(Z.a,J,$),A(Z.b,J,$));case"neg":return A(Z.of,J,$);case"call":return x5(Z,J,$)}}var s2=(Z)=>oZ(Z,(J)=>J==="root"?"unknown":rZ(J)?"tainted":J);function x5(Z,J,$){let{name:z,args:Y}=Z;if(S5.has(z)&&z!=="limit"&&!Y.every(i2))y();switch(z){case"map":if(Y.length!==1)y();return fZ(A(Y[0],$Z(J),$));case"select":if(Y.length!==1)y();return A(Y[0],J,$),J;case"limit":if(Y.length!==2||!i2(Y[0]))y();return A(Y[1],J,$);case"first":case"last":if(Y.length>1)y();return Y.length===1?A(Y[0],J,$):$Z(J);case"min":case"max":return $Z(J);case"sort_by":case"group_by":case"unique_by":if(Y.length!==1)y();return A(Y[0],$Z(J),$),s2(J);case"min_by":case"max_by":if(Y.length!==1)y();return A(Y[0],$Z(J),$),$Z(J);case"any":case"all":case"isempty":for(let Q of Y)A(Q,"unknown",$);return"safe"}if(n2.has(z))return"safe";if(a2.has(z))return s2(J);return y()}function r2(Z,J={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new S0(o2(Z)).parse();return f0(A($,"root",{rootScalars:J.rootScalars??new Set}))}catch($){if($ instanceof E0)return!1;return!1}}var p0="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",I={refused:!1},T=(Z)=>({refused:!0,rule:Z}),k0=new Set(["additions","assignees","author","baseRefName","baseRefOid","changedFiles","closed","closedAt","createdAt","deletions","files","fullDatabaseId","headRefName","headRefOid","headRepository","headRepositoryOwner","id","isCrossRepository","isDraft","labels","maintainerCanModify","mergeCommit","mergeStateStatus","mergeable","mergedAt","mergedBy","number","potentialMergeCommit","reactionGroups","reviewDecision","reviewRequests","state","title","updatedAt","url"]),x0=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),t2=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),e2=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),h5=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),w5=new Set(["author","committer","id","parents","repository","sha","url"]),g5=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function J3(Z){let J=[];for(let $=0;$<Z.length;$++){let z=Z[$];if(z==="\\"){$++;continue}if(z==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return!1;$=Y;continue}if(z==='"'){$++;while($<Z.length&&Z[$]!=='"')$+=Z[$]==="\\"?2:1;continue}if(z==="{"){J.push({list:!1});continue}if(J.length===0)continue;if(z===","||z==="."&&Z[$+1]===".")J[J.length-1].list=!0;else if(z==="}"&&J.pop().list)return!0}return!1}function jZ(Z){let J="",$=!1,z=0,Y=(Q)=>Z[Q]==="`"||Z[Q]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(Z[Q+1]??"");while(z<Z.length){let Q=Z[z];if(Q==="\\"){J+=Z[z+1]??"",z+=2;continue}if(Q==="$"&&Z[z+1]==="'"){$=!0,J+=Q,z++;continue}if(Q==="'"){let X=Z.indexOf("'",z+1);if(X<0){$=!0,J+=Z.slice(z+1);break}J+=Z.slice(z+1,X),z=X+1;continue}if(Q==='"'){z++;while(z<Z.length&&Z[z]!=='"'){if(Z[z]==="\\"&&/[$`"\\\n]/.test(Z[z+1]??"")){J+=Z[z+1],z+=2;continue}if(Y(z))$=!0;J+=Z[z],z++}if(z>=Z.length)$=!0;z++;continue}if(Y(z)||Q==="*"||Q==="?"||Q==="[")$=!0;J+=Q,z++}if(!$&&Z.includes("{")&&J3(Z))$=!0;return{value:J,opaque:$,raw:Z}}var BZ=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function g0(Z,J="word"){let $=[],z=!1;for(let Y=0;Y<Z.length;Y++){let Q=Z[Y];if(Q==="\\"){Y++;continue}if(J==="word"&&Q==="'"&&!z){let X=Z.indexOf("'",Y+1);if(X<0)return{bodies:$,complete:!1};Y=X;continue}if(J==="word"&&Q==='"'){z=!z;continue}if(Q==="`"){let X=Y+1;while(X<Z.length&&Z[X]!=="`")X+=Z[X]==="\\"?2:1;if(X>=Z.length)return{bodies:$,complete:!1};$.push(Z.slice(Y+1,X)),Y=X;continue}if(Q==="$"&&Z[Y+1]==="("){let X=KZ(Z,Y+1);if(X<0)return{bodies:$,complete:!1};$.push(Z.slice(Y+2,X-1)),Y=X-1}}return{bodies:$,complete:!0}}function NZ(Z,J){let $=new Set(J.values),z={flags:[],positionals:[]},Y=(Q,X)=>({value:Q,opaque:X.opaque,raw:X.raw});for(let Q=0;Q<Z.length;Q++){let X=Z[Q],H=X.value;if(H==="--"){z.positionals.push(...Z.slice(Q+1));break}if(H.startsWith("--")&&H.length>2){let K=H.indexOf("="),B=K>=0?H.slice(0,K):H;if(K>=0)z.flags.push({name:B,value:Y(H.slice(K+1),X),inline:!0});else if($.has(B)){let M=Z[Q+1];z.flags.push(M?{name:B,value:M}:{name:B,missing:!0}),Q++}else z.flags.push({name:B});continue}if(H.startsWith("-")&&H.length>1){for(let K=1;K<H.length;K++){let B="-"+H[K],M=H.slice(K+1);if(M.startsWith("=")){z.flags.push({name:B,value:Y(M.slice(1),X),inline:!0});break}if(!$.has(B)){z.flags.push({name:B});continue}if(M)z.flags.push({name:B,value:Y(M,X),inline:!0});else{let V=Z[Q+1];z.flags.push(V?{name:B,value:V}:{name:B,missing:!0}),Q++}break}continue}z.positionals.push(X)}return z}function f(Z,...J){let $=!1;for(let z of Z.flags){if(!J.includes(z.name))continue;if(!z.inline){$=!0;continue}let Y=z.value;$=!Y.opaque&&["1","t","T","TRUE","true","True"].includes(Y.value)}return $}var zZ=(Z,...J)=>Z.flags.filter(($)=>J.includes($.name)),c=["-R","--repo","-q","--jq","-t","--template","--json"],MZ={"pr view":{values:c},"issue view":{values:c},"release view":{values:c},"discussion view":{values:[...c,"--after","-L","--limit","--order"]},"pr list":{values:[...c,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...c,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...c,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...c,"-L","--limit","-O","--order"]},"pr status":{values:c},"issue status":{values:c},"pr checks":{values:[...c,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...c,"--app","--assignee","--author","--author-date","--author-email","--author-name","--base","--checks","--closed","--commenter","--committer","--committer-date","--committer-email","--committer-name","--created","--hash","--head","--interactions","--involves","--label","--language","--limit","-L","--match","--mentions","--merged-at","--milestone","--no-assignee","--no-label","--no-milestone","--no-project","--order","--owner","--parent","--project","--reactions","--review","--review-requested","--reviewed-by","--sort","--state","--team-mentions","--tree","--updated","--visibility","--extension","--filename","--size","--forks","--good-first-issue","--help-wanted-issues","--number-topics","--stars","--topic","--followers","--include-forks","--license"]},"project item-list":{values:["--format","-L","--limit","--owner","-q","--jq","-t","--template","--query","--field","--field-id"]},api:{values:["-X","--method","-H","--header","-f","--raw-field","-F","--field","-q","--jq","-t","--template","-p","--preview","--input","--hostname","--cache"]},group:{values:["-R","--repo"]}},l5=new Set(["auth","browse","codespace","cs","gist","org","repo","skill","cache","run","workflow","co","agent-task","alias","attestation","completion","config","copilot","extension","ext","extensions","gpg-key","label","licenses","preview","ruleset","secret","ssh-key","variable","help","version","accessibility","actions","environment","exit-codes","formatting","mintty","reference","telemetry"]),u5=new Set(["pr","issue","release","discussion","search","project","api","status"]),m5=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),p5=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),c5=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),i5=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function $0(Z,J){let $=zZ(Z,"--json"),z=[],Y=!1;for(let Q of $){if(Q.missing){if(J.appendsArgs)Y=!0;continue}if(!Q.value)continue;if(Q.value.opaque)Y=!0;z.push(...Q.value.value.split(",").map((X)=>X.trim()).filter(Boolean))}return{present:$.length>0,opaque:Y,fields:z}}function c0(Z,J){if(f(Z,"--verbose")||zZ(Z,"-t","--template").length>0)return!1;let $=zZ(Z,"-q","--jq");return $.length>0&&$.every((z)=>z.value!==void 0&&!z.value.opaque&&r2(z.value.value,{rootScalars:J}))}function i0(Z,J,$,z){let Y=$0(Z,$);if(Y.opaque)return T("unclassifiable");if(Y.fields.every((Q)=>J.has(Q)))return I;if($.debug)return T("debug-traffic");return c0(Z)?I:T(z)}function tZ(Z,J,$,z,Y){let Q=NZ(Z,MZ[J]);if(f(Q,"-h","--help"))return I;if(f(Q,"-w","--web"))return z.debug?T("debug-traffic"):I;if(Y&&f(Q,"-c","--comments"))return T("view-comments");if(!$0(Q,z).present)return T(z.debug?"debug-traffic":"view-human");return i0(Q,$,z,"json-composite")}function JZ(Z,J,$,z){let Y=NZ(Z,MZ[J]);if(f(Y,"-h","--help"))return I;if(z.debug&&(f(Y,"-w","--web")||!$0(Y,z).present))return T("debug-traffic");if(f(Y,"-w","--web"))return I;return i0(Y,$,z,"json-composite")}function d5(Z,J){let $=NZ(Z,MZ["pr checks"]);if(f($,"-h","--help"))return I;if(J.debug)return T("debug-traffic");if(f($,"-w","--web"))return I;if(!$0($,J).present)return T("checks-human");return i0($,g5,J,"checks-json")}function s5(Z){let J=new Set(MZ.group.values);for(let $=0;$<Z.length;$++){let z=Z[$].value;if(z==="--")return{sub:Z[$+1],rest:Z.slice($+2)};if(!z.startsWith("-")||z==="-")return{sub:Z[$],rest:[...Z.slice(0,$),...Z.slice($+1)]};if(J.has(z))$++}return{rest:Z}}function n5(Z,J,$){let{sub:z,rest:Y}=s5(J);if(!z)return $.appendsArgs?T("unclassifiable"):I;if(z.opaque)return T("unclassifiable");let Q=z.value;if((Z==="pr"?m5:Z==="issue"?p5:Z==="release"?c5:Z==="discussion"?i5:new Set).has(Q))return $.debug?T("debug-traffic"):I;if($.appendsArgs&&!(Z==="project"&&Q!=="item-list"))return T("unclassifiable");switch(Z){case"pr":if(Q==="view")return tZ(Y,"pr view",k0,$,!0);if(Q==="list"||Q==="ls")return JZ(Y,"pr list",k0,$);if(Q==="status")return JZ(Y,"pr status",k0,$);if(Q==="checks")return d5(Y,$);if(Q==="diff"){let H=NZ(Y,MZ["pr diff"]);if(f(H,"-h","--help"))return I;if($.debug)return T("debug-traffic");return f(H,"--patch")?T("composite-other"):I}return T("unclassifiable");case"issue":if(Q==="view")return tZ(Y,"issue view",x0,$,!0);if(Q==="list"||Q==="ls")return JZ(Y,"issue list",x0,$);if(Q==="status")return JZ(Y,"issue status",x0,$);return T("unclassifiable");case"release":if(Q==="view")return tZ(Y,"release view",t2,$,!1);if(Q==="list"||Q==="ls")return JZ(Y,"release list",t2,$);return T("unclassifiable");case"discussion":if(Q==="view")return tZ(Y,"discussion view",e2,$,!0);if(Q==="list"||Q==="ls")return JZ(Y,"discussion list",e2,$);return T("unclassifiable");case"search":if(Q==="prs"||Q==="issues")return JZ(Y,"search",h5,$);if(Q==="commits")return JZ(Y,"search",w5,$);if(Q==="code"||Q==="repos")return $.debug?T("debug-traffic"):I;return T("unclassifiable");case"project":{if($.debug)return T("debug-traffic");if(Q!=="item-list")return I;let H=NZ(Y,MZ["project item-list"]);if(f(H,"-h","--help"))return I;let K=zZ(H,"--format");if(K.some((B)=>!B.value||B.value.opaque))return T("unclassifiable");if(K.every((B)=>B.value.value!=="json"))return I;return c0(H)?I:T("composite-other")}}return T("unclassifiable")}var z3=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function a5(Z){let J=Z.value.trim(),$=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(J);if($){let Q=$[1].toLowerCase(),X=$[2]??"/";if(Q==="api.github.com"||/^api\./.test(Q))J=X;else if(/^\/api\/v3(?:\/|$)/i.test(X))J=X.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(X))J="graphql";else return null}J=J.replace(/[?#].*$/,"");let z=[],Y=[];for(let Q of J.split("/")){let X;try{X=decodeURIComponent(Q)}catch{return null}for(let H of X.split("/")){if(H===""||H===".")continue;if(H===".."){z.pop(),Y.pop();continue}z.push(H.toLowerCase()),Y.push(Z.opaque&&/[$`]/.test(H)||/[*?[]/.test(H)||J3(H))}}return{segments:z,opaque:Y}}function o5(Z){let J=a5(Z);if(!J)return{kind:"unclassifiable",segments:[]};let{segments:$,opaque:z}=J,Y=(K)=>({kind:K,segments:$});if($.length===1&&$[0]==="graphql")return Y("graphql");if($.length===0)return Y(Z.opaque?"unclassifiable":"other");if(z[0])return Y("unclassifiable");let Q,X=[];if($[0]==="repos")Q=$.slice(3),X=z.slice(3);else if($[0]==="repositories")Q=$.slice(2),X=z.slice(2);if(Q){if(($[0]==="repos"?z.slice(1,3):z.slice(1,2)).some(Boolean)){let B=z.findIndex(Boolean),M=$.findIndex((V,G)=>G>B&&!z[G]&&r5.has(V));return Y(M<0?"unclassifiable":Z3($.slice(M),z.slice(M)))}return Y(Z3(Q,X))}let H=$[0];if(H==="issues")return Y("sensitive");if(H==="user"&&$[1]==="issues")return Y("sensitive");if(H==="orgs"&&$[2]==="issues")return Y("sensitive");if(H==="search")return Y($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&z[1]?"unclassifiable":"other");if(H==="events"||H==="networks")return Y("sensitive");if((H==="users"||H==="orgs")&&$.slice(2).some((K)=>K==="events"||K==="received_events"||K==="discussions"))return Y("sensitive");if((H==="users"||H==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return Y("sensitive");if(H==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||H==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return Y("sensitive");if(H==="teams"&&$.includes("discussions"))return Y("sensitive");if(H==="projects"&&$.includes("cards"))return Y("sensitive");if(z.some(Boolean))return Y($.some((K)=>K==="events"||K==="discussions"||K==="issues")?"sensitive":"unclassifiable");return Y("other")}var r5=new Set([...z3,"branches","git","actions","hooks","zipball","tarball"]);function Z3(Z,J){let[$,z]=Z;if($===void 0)return"other";if(J[0])return"unclassifiable";if($==="issues"&&/^\d+$/.test(z??"")&&Z[2]==="labels")return"other";if(z3.has($))return"sensitive";if($==="branches"){if(Z.length===1||Z.slice(1).some((Y)=>Y==="protection")||Z[Z.length-1]==="rename")return"other";return J.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if($==="git")return z===void 0||z==="commits"||z==="tags"?"sensitive":J[1]?"unclassifiable":"other";if($==="actions"){if(z===void 0)return"sensitive";if(J[1])return"unclassifiable";if(z==="runs"||z==="jobs"){if(Z[Z.length-1]==="logs"&&Z.length>=4&&!J.some(Boolean))return"download";return"sensitive"}if(z==="workflows"&&Z[3]==="runs")return"sensitive";if(z==="artifacts"&&Z.length===4)return"download";return"other"}if($==="hooks"&&Z[2]==="deliveries"&&Z[3]!==void 0)return"sensitive";if($==="zipball"||$==="tarball")return"download";return"other"}function t5(Z,J){if(J[0]!=="repos"||J.length<5)return!1;let $=J.slice(3),z=(Q)=>/^\d+$/.test($[Q]??""),Y=(...Q)=>$.length===Q.length&&Q.every((X,H)=>typeof X==="number"?z(H):$[H]===X);if(Z==="DELETE")return Y("issues","comments",0)||Y("pulls","comments",0)||Y("comments",0)||Y("issues","comments",0,"reactions",0)||Y("pulls","comments",0,"reactions",0)||Y("issues",0,"reactions",0)||Y("issues",0,"labels")||$.length===4&&$[0]==="issues"&&z(1)&&$[2]==="labels"||Y("releases",0)||Y("releases","assets",0)||Y("actions","runs",0)||Y("actions","runs",0,"logs")||Y("deployments",0)||Y("milestones",0)||Y("issues",0,"lock");if(Z==="POST")return $.length===4&&$[0]==="actions"&&$[1]==="runs"&&z(2)&&["rerun","rerun-failed-jobs","cancel","force-cancel","approve"].includes($[3])||Y("actions","jobs",0,"rerun")||Y("issues",0,"labels");if(Z==="PUT")return Y("pulls",0,"merge")||Y("pulls",0,"update-branch")||Y("issues",0,"labels")||Y("issues",0,"lock");if(Z==="GET")return Y("pulls",0,"merge");return!1}function e5(Z){if(Z[0]!=="repos"||Z.length!==5||!/^\d+$/.test(Z[4]))return;if(Z[3]==="pulls")return new Set(["commits","comments","review_comments"]);if(Z[3]==="issues")return new Set(["comments"]);return}var Z6=new Set(["body","bodyText","bodyHTML","bodyUrl","bodyResourcePath","comments","reviews","latestReviews","latestOpinionatedReviews","reviewThreads","url","permalink","summary","text","description","message","messageBody","messageHeadline","commitBody","commitHeadline","annotations","rawDetails","note","diff","readme","payload"]),$6=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function J6(Z){let J=[],$=0;while($<Z.length){let z=Z[$];if(/[\s,]/.test(z)){$++;continue}if(z==="#"){let X=Z.indexOf(`
22
+ `,$);$=X<0?Z.length:X+1;continue}if(Z.startsWith('"""',$)){let X=$+3;for(;;){let H=Z.indexOf('"""',X);if(H<0)return null;if(Z[H-1]==="\\"){X=H+3;continue}$=H+3;break}continue}if(z==='"'){let X=$+1;while(X<Z.length&&Z[X]!=='"'&&Z[X]!==`
23
+ `)X+=Z[X]==="\\"?2:1;if(Z[X]!=='"')return null;$=X+1;continue}let Y=/^[_A-Za-z][_0-9A-Za-z]*/.exec(Z.slice($,$+256));if(Y){J.push({kind:"name",text:Y[0]}),$+=Y[0].length;continue}let Q=/^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(Z.slice($,$+64));if(Q){$+=Q[0].length;continue}if(Z.startsWith("...",$)){J.push({kind:"punct",text:"..."}),$+=3;continue}if("{}()[]:!$@=|&".includes(z)){J.push({kind:"punct",text:z}),$++;continue}return null}return J}function z6(Z){let J=J6(Z);if(!J)return!0;let $=[],z="",Y=0;for(let Q=0;Q<J.length;Q++){let X=J[Q];if(X.kind==="punct"){if(X.text==="(")Y++;else if(X.text===")"){if(Y--,Y<0)return!0}else if(Y===0&&X.text==="{")$.push(z),z="";else if(Y===0&&X.text==="}"){if($.pop()===void 0)return!0;z=""}continue}if(Y>0)continue;let H=J[Q-1];if(H?.kind==="punct"&&(H.text==="@"||H.text==="$"))continue;if(J[Q+1]?.kind==="punct"&&J[Q+1].text===":")continue;if(X.text==="on"&&H?.kind==="punct"&&H.text==="...")continue;if(H?.kind==="name"&&H.text==="on"){z=X.text;continue}if($.length===0){z=X.text;continue}if(Z6.has(X.text)||/(?:Url|URL|HTML|Html)$/.test(X.text))return!0;if(X.text==="title"&&$.some((K)=>$6.has(K)))return!0;z=X.text}return Y!==0||$.length!==0}function Y6(Z,J){let $=NZ(Z,MZ.api);if(f($,"-h","--help"))return I;let z=$.positionals[0];if(!z)return J.appendsArgs?T("unclassifiable"):I;let Y=o5(z),Q=zZ($,"-X","--method"),X=Q[Q.length-1],H=zZ($,"-f","--raw-field","-F","--field","--input"),K=X?X.value&&!X.value.opaque?X.value.value.toUpperCase():"?":H.length>0?"POST":"GET",B=t5(K,Y.segments),M=I;if(Y.kind==="unclassifiable")M=T("unclassifiable");else if(Y.kind==="sensitive"&&!B)M=T("api-rest");else if(Y.kind==="graphql")M=Q6($);if(J.debug||f($,"--verbose")){if(Y.kind==="download"&&!M.refused)M=T("api-rest");if(M.refused)return J.debug?T("debug-traffic"):M;return I}if(J.appendsArgs&&Y.kind!=="other"&&Y.kind!=="download")return T("unclassifiable");if(!M.refused||f($,"--silent"))return I;if(c0($,e5(Y.segments)))return I;return M}function Q6(Z){if(zZ(Z,"--input").length>0)return T("unclassifiable");let J=zZ(Z,"-f","--raw-field","-F","--field"),$=J.filter((z)=>z.value&&/^query=/.test(z.value.value));if($.length===0||J.some((z)=>!z.value))return T("unclassifiable");for(let z of $){let Y=z.value.value.slice(6);if((z.name==="-F"||z.name==="--field")&&Y.startsWith("@")||z.value.opaque)return T("unclassifiable");if(z6(Y))return T("api-graphql")}return I}function Z0(Z,J){let $=0;while($<Z.length&&Z[$].value.startsWith("-")&&!Z[$].opaque){if(["--help","-h","--version"].includes(Z[$].value))return I;$++}if($>=Z.length)return J.appendsArgs?T("unclassifiable"):I;let z=Z[$],Y=Z.slice($+1);if(z.opaque)return T("unclassifiable");switch(z.value){case"pr":case"issue":case"release":case"discussion":case"search":case"project":return n5(z.value,Y,J);case"api":return Y6(Y,J);case"status":return Y.length>0&&Y.every((Q)=>Q.value==="-h"||Q.value==="--help")?I:T("composite-other");case"help":case"version":return I;case"cs":case"codespace":{let Q=Y.findIndex((X)=>X.value==="--");if(Y.some((X)=>X.value==="ssh")&&Q>=0&&Q+1<Y.length){let X=o(Y.slice(Q+1).map((H)=>H.value).join(" "),J.depth+1,J.debug);if(X.refused)return X}break}}if(!l5.has(z.value))return T("unclassifiable");if(J.debug)return T("debug-traffic");return I}var J0=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","fish"]),X6=new Set(["su","runuser","script","flock"]),K6=new Set(["secrets","op","unbuffer","caffeinate","chronic","strace","ltrace","firejail","bwrap","nsenter","unshare","chroot","sg","retry","parallel","doppler","aws-vault","dotenv","direnv","faketime","taskset","numactl","cgexec","systemd-run","docker","podman","kubectl","mise","asdf","rtx","devbox","gosu","su-exec","setpriv","pkexec","with-contenv","uv","poetry","pipenv","npx","bunx","pnpm","yarn","nix","nix-shell","infisical","chamber","envchain","dotenvx","teller","vault","chrt","coproc","prlimit","ionice","cpulimit","trickle","proxychains","proxychains4","torsocks","tsocks","catchsegv","valgrind"]),H6=new Map([["bun",["x","exec"]],["npm",["exec","x"]],["deno",["run"]]]),B6=new Set(["-I","-L","-l","-n","-P","-s","-d","-E","-e","-a","--arg-file","--delimiter","--max-args","--max-lines","--max-procs","--max-chars","--replace","--eof","--process-slot-var"]),M6=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),eZ=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/,V6=/^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/,G6=6;function $3(Z,J){let $,z;for(let Y of Z){let Q=V6.exec(Y.value);if(!Q)continue;let X={...Y,value:Q[2]};if(Q[1]==="GH_DEBUG")$=X;else if(Q[1]==="DEBUG")z=X}if($)return $.opaque||!["","0","false","no"].includes($.value);if(z&&(z.opaque||["1","true","yes","api"].includes(z.value)))return!0;return J}function d0(Z){let J=u(Z),$=0;return{segments:J.segments.map((Y)=>{let Q=Y.words[0],X=Z.slice($,Q.start);return $=Y.words[Y.words.length-1].end,{words:Y.words,redirects:Y.redirects,sepBefore:X}}),trustworthy:J.trustworthy}}var Y3=(Z)=>/(?:^|[^|])\|&?$/.test(Z.trim());function l0(Z,J){if(!J0.has(Z))return!1;if(s0(J))return!1;for(let $=0;$<J.length;$++){let z=J[$].value;if(z==="--")return $+1>=J.length;if(z==="-"||z==="-s")return!0;if(/^[-+][A-Za-z]*[oO]$/.test(z)){$++;continue}if(!z.startsWith("-")&&!z.startsWith("+"))return!1}return!0}function u0(Z){let{segments:J}=d0(Z.trim());if(J.length!==1)return null;let $=J[0],z=h($);if(z<0)return null;let Y=BZ(jZ($.words[z].text).value),Q=$.words.slice(z+1).filter((X,H)=>!$.redirects.has(H+z+1)).map((X)=>jZ(X.text));if(Y==="echo")return Q.filter((X,H)=>!(H===0&&/^-[neE]+$/.test(X.value))).map((X)=>X.value).join(" ");if(Y==="printf"){let[X,...H]=Q.filter((B)=>B.value!=="--");if(!X)return null;let K=0;return X.value.replace(/\\n/g,`
24
+ `).replace(/%s/g,()=>H[K++]?.value??"")+(K<H.length?" "+H.slice(K).map((B)=>B.value).join(" "):"")}if(Y==="cat"){let X=Z.indexOf("<<");if(X<0)return null;let H=WZ(Z,X),K=Z.indexOf(`
25
+ `,X);if(!H||K<0)return null;let B=sZ(Z,K,[H]);if(B<0)return null;let M=Z.slice(K+1,B);return M.slice(0,M.lastIndexOf(H.delimiter)).replace(/\n$/,"")}return null}function h0(Z,J,$){for(let z of g0(Z).bodies){let Y=u0(z);if(Y===null)continue;let Q=o(Y,J+1,$.debug);if(Q.refused)return Q}return I}function o(Z,J=0,$=!1){if(typeof Z!=="string"||!Z.trim())return I;if(J>G6)return eZ.test(Z)?T("unclassifiable"):I;let{segments:z,trustworthy:Y}=d0(Z);if(!Y)return eZ.test(Z)?T("unclassifiable"):I;let Q=$,X=(H)=>o(H,J+1,Q);for(let H of j6(Z)){if(H.runsBody){let K=X(H.body);if(K.refused)return K}if(!H.quoted){let K=g0(H.body,"heredoc");if(!K.complete&&eZ.test(H.body))return T("unclassifiable");for(let B of K.bodies){let M=X(B);if(M.refused)return M}}}for(let H=0;H<z.length;H++){let K=z[H];for(let N of K.words){let R=g0(N.text);if(!R.complete&&eZ.test(N.text))return T("unclassifiable");for(let w of R.bodies){let g=X(w);if(g.refused)return g}}let B=h(K),M=K.words.map((N,R)=>({word:jZ(N.text),redirect:K.redirects.has(R)})),V=M.slice(0,B<0?M.length:B).map((N)=>N.word),G=B>=0?BZ(M[B].word.value):"";if(B<0||["export","declare","typeset","readonly","local"].includes(G)){if(Q=$3([...V,...M.slice(B+1).map((N)=>N.word)],Q),B<0)continue}let U=$3(V,Q),j=M.slice(B+1).filter((N)=>!N.redirect).map((N)=>N.word),F=M.slice(B+1).filter((N)=>N.redirect).map((N)=>N.word),E=M[B].word,k=BZ(E.value),m={depth:J,appendsArgs:!1,debug:U};if(B>0&&M[B-1].word.value==="function"){let N=j.filter((w)=>!["{","()","(",")"].includes(w.value)),R=m0(N,m);if(R.refused)return R;continue}if(H>0&&Y3(K.sepBefore)&&l0(k,j)){let N=z[H-1],R=U6(Z,N),w=R===null?null:u0(R);if(w!==null){let g=o(w,J+1,U);if(g.refused)return g}}let d=z[H+1];if(d&&/<\(\s*$/.test(d.sepBefore)&&(J0.has(k)||k==="source"||k===".")){let N=d.words[0].start-d.sepBefore.length+d.sepBefore.lastIndexOf("("),R=KZ(Z,N),w=R<0?null:u0(Z.slice(N+1,R-1));if(w!==null){let g=o(w,J+1,U);if(g.refused)return g}}let C=Q3(k,E,j,F,K.words.slice(0,B+1),m);if(C.refused)return C}return I}function U6(Z,J){let $=J.words[0],z=J.words[J.words.length-1];return $&&z?Z.slice($.start,z.end):null}function W6(Z){let J=BZ(Z.value);return/[$`]/.test(J)||J===""?void 0:J}function Q3(Z,J,$,z,Y,Q){let X=Q.depth,H=(K)=>o(K,X+1,Q.debug);if(J.opaque){let K=W6(J);if(K===void 0){let B=$.find((V)=>!V.value.startsWith("-")),M=Z0($,Q);if(!M.refused)return I;return M.rule!=="unclassifiable"||B!==void 0&&!B.opaque&&u5.has(B.value)?M:I}Z=K}if(Z==="gh")return Z0($,Q);if(J0.has(Z)){let K=s0($);if(K){let B=H(K.value);if(B.refused||!K.opaque)return B;return h0(K.raw,X,Q)}for(let B of z){let M=H(B.value);if(M.refused)return M;if(B.opaque){let V=h0(B.raw,X,Q);if(V.refused)return V}}return I}if(X6.has(Z)){let K=$.findIndex((M)=>M.value==="-c"||M.value==="--command"||/^-[A-Za-z]*c$/.test(M.value)),B=K>=0?$[K+1]:void 0;return B?H(B.value):w0($,Q)}if(Z==="eval"||Z==="watch"){let K=$;if(Z==="watch"){let M=0;while(M<$.length&&$[M].value.startsWith("-")){if($[M].value==="--"){M++;break}if(["-n","--interval","-q","--equexit"].includes($[M].value))M++;M++}K=$.slice(M)}let B=H(K.map((M)=>M.value).join(" "));if(B.refused)return B;for(let M of K){let V=h0(M.raw,X,Q);if(V.refused)return V}return I}if(Z==="env")return H(RZ([...Y.map((K)=>jZ(K.text).value),...$.map((K)=>K.value)]));if(Z==="ssh"){let K=0;for(;K<$.length;K++){let V=$[K].value;if(!V.startsWith("-"))break;if(M6.has(V))K++}let B=$.slice(K+1);if(B[0]?.value==="--")B.shift();let M=B.map((V)=>V.value).join(" ");return M?H(M):I}if(Z==="xargs"){let K=0,B=!1;for(;K<$.length;K++){let M=$[K].value;if(M==="--"){K++;break}if(!M.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(M))B=!0;if(B6.has(M))K++}return m0($.slice(K),{depth:X,appendsArgs:!B,debug:Q.debug})}if(Z==="find"){for(let K=0;K<$.length;K++){if(!["-exec","-execdir","-ok","-okdir"].includes($[K].value))continue;let B=K+1;while(B<$.length&&$[B].value!==";"&&$[B].value!=="+")B++;let M=m0($.slice(K+1,B),Q);if(M.refused)return M;K=B}return I}if(K6.has(Z))return w0($,Q);if(H6.get(Z)?.includes($[0]?.value??""))return w0($.slice(1),Q);return I}function m0(Z,J){if(Z.length===0)return I;let $=BZ(Z[0].value);if($==="gh")return Z0(Z.slice(1),J);if(J0.has($)){let z=s0(Z.slice(1));return z?o(z.value,J.depth+1,J.debug):I}return Q3($,Z[0],Z.slice(1),[],[],J)}function w0(Z,J){let $=Z.findIndex((z)=>!z.opaque&&BZ(z.value)==="gh"&&(z.value==="gh"||z.value.includes("/")));return $>=0?Z0(Z.slice($+1),J):I}function s0(Z){for(let J=0;J<Z.length;J++){let $=Z[J].value;if($==="--")return;if(!$.startsWith("-")&&!$.startsWith("+"))return;if($==="-c"||/^-[A-Za-z]+$/.test($)&&$.includes("c"))return Z.slice(J+1).find((z)=>!z.value.startsWith("-")||z.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test($))J++}return}function j6(Z){let J=[],$=0;for(;;){let z=Z.indexOf("<<",$);if(z<0)break;if($=z+2,Z[z+2]==="<"||z>0&&Z[z-1]==="<"){$=z+3;continue}let Y=WZ(Z,z);if(!Y)continue;let Q=Z.lastIndexOf(`
26
+ `,z)+1,X=Z.indexOf(`
27
+ `,z);if(X<0)continue;let H=sZ(Z,X,[Y]),K=H<0?Z.slice(X+1):Z.slice(X+1,H),B=H<0?K:K.slice(0,Math.max(0,K.lastIndexOf(Y.delimiter))).replace(/\n$/,""),M=Z.slice(Q,z)+" HEREDOC_OPERATOR "+Z.slice(Y.end,X);J.push({body:B,runsBody:N6(M),quoted:Y.quoted})}return J}function N6(Z){let{segments:J}=d0(Z),$=J.findIndex((H)=>H.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let z=(H)=>{let K=h(H);if(K<0)return{verb:"",args:[]};let B=H.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>jZ(M.text));return{verb:BZ(jZ(H.words[K].text).value),args:B}},{verb:Y,args:Q}=z(J[$]);if(Y==="ssh"||l0(Y,Q))return!0;if((Y==="source"||Y===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(Q[0]?.value??""))return!0;let X=J[$+1];if(Y==="cat"&&X&&Y3(X.sepBefore)){let H=z(X);return H.verb==="ssh"||l0(H.verb,H.args)}return!1}var F6=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function X3(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:p0}}}var _6=new Set(["Bash","Monitor"]);function K3(Z){if(Z?.hook_event_name!=="PreToolUse"||!_6.has(Z.tool_name??""))return{continue:!0};let J=GZ(Z);if(!J.trim())return{continue:!0};try{return o(J).refused?X3():{continue:!0}}catch{return F6.test(J)?X3():{continue:!0}}}function T6(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function H3(Z,J){T6(Z);let $=Z,z=JSON.parse(J);if(!z||Array.isArray(z)||z.hook_event_name!=="PreToolUse"||typeof z.tool_name!=="string"||!z.tool_input||typeof z.tool_input!=="object"||Array.isArray(z.tool_input)||typeof z.cwd!=="string"||!n0.isAbsolute(z.cwd))throw Error("Invalid safety input");if(z.tool_name==="Bash"&&typeof z.tool_input.command!=="string")throw Error("Invalid shell input");if(z.tool_name==="Monitor"&&z.tool_input.command!==void 0&&typeof z.tool_input.command!=="string")throw Error("Invalid monitor input");let Y=z.hasna_execution;if(Y!==void 0&&(!Y||Object.keys(Y).sort().join()!=="agent,schema"||Y.schema!=="hasna.hooks.execution.v1"||typeof Y.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(Y.agent)))throw Error("Invalid execution capability");let Q=Y===void 0?void 0:{runtime:process.execPath,home:z0.homedir(),path:process.env.PATH,agent:Y.agent};if(Q&&(!n0.isAbsolute(Q.runtime)||!Q.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(z.tool_name)){if(z.tool_input.command!==void 0&&z.tool_input.patch!==void 0&&z.tool_input.command!==z.tool_input.patch)throw Error("Conflicting patch aliases");let F=z.tool_input.command??z.tool_input.patch;if(typeof F!=="string")throw Error("Invalid patch input");z.tool_input={...z.tool_input,command:F,patch:F}}let X=z.tool_name==="Monitor",H=z.tool_name==="Bash"||X&&typeof z.tool_input.command==="string",K=X&&H?{...z,tool_name:"Bash"}:z,B=(F)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:F}}),M=c2(K).output,V=K3(K),G=H&&bZ(K.tool_input.command,{home:z0.homedir(),cwd:z.cwd}).handoffHits.length>0,U=$==="trash-guard"&&(!X||H)?P2(K,{home:z0.homedir(),cwd:z.cwd,findTrash:hZ,inspectTrash:qZ,execution:Q}):{continue:!0};if(X&&U.hookSpecificOutput?.permissionDecision==="allow")U=B("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let j=M.decision==="block"?B(M.reason):V.hookSpecificOutput?V:G?B("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):U;return JSON.stringify({verdict:"continue"in j?null:j})}var I6=2,C6="0.12.14";function D6(Z,J){return H3(Z,J)}