@hasna/hooks 0.13.0 → 0.13.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/hooks/scratch-lifecycle.js +5 -5
- package/bin/hooks/stop-review.js +2 -2
- package/bin/hooks-mcp.js +931 -73
- package/bin/index.js +1289 -427
- package/bin/native-safety-entry.js +37 -37
- package/bin/native-safety-worker.cjs +37 -37
- package/bin/serve.js +119 -119
- package/dist/index.js +1196 -338
- package/dist/native-readiness.js +11 -11
- package/dist/native-safety.js +9 -9
- package/dist/opencode-stop-plugin.js +5 -5
- package/dist/sdk/index.js +7 -7
- package/dist/storage.js +34 -34
- package/dist/sumi-stop-plugin.js +7 -7
- package/hooks/local-executors.ts +97 -12
- package/package.json +1 -1
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{homedir as
|
|
3
|
-
`)[0]}finally{Mr(t)}let s=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(n);if(s&&s[1]!=="/usr/bin/env")return Xe(s[1],!0);if(n!=="#!/usr/bin/env bun"||!Xe("/usr/bin/env",!0))return!1;for(let i of r.split(":").slice(0,64)){if(!Ur(i))return!1;let o=ne(i,"bun");try{if(!kt(o).isFile())continue;Hr(o,Ke.X_OK)}catch{continue}return Xe(o,!0)}return!1}function Ce(e){let r=e;for(;;){let t=Te(r);if(!t.isDirectory()||!$e(t.uid)||(t.mode&18)!==0)return!1;let n=de(r);if(n===r)return!0;r=n}}function Pe(e=process.env){let r=e.PATH??"",t=Date.now()+2000,n="missing",s=(i)=>{if(n==="missing"||n==="unrecognized_package"||i.startsWith("unsafe_"))n=i};for(let i of r.split(":").slice(0,64)){if(!Ye(i)||Date.now()>=t)continue;let o=ne(i,"trash");try{let a=kt(o);if(!a.isFile()||!$e(a.uid)||(a.mode&73)===0||(a.mode&18)!==0){s("unsafe_executable");continue}let l=xt(o);if(!Ce(ne(i))||!Ce(de(l))){s("unsafe_directory");continue}if(!Xe(o)){s("unsafe_directory");continue}let u=ne(de(l),"../.."),c=yt(u,"package.json"),f=kt(c);if(!f.isFile()||!$e(f.uid)||f.size>16384||(f.mode&18)!==0||Te(c).isSymbolicLink()){s("unsafe_manifest");continue}let d=JSON.parse(jr(c,"utf8"));if(d.name!=="@hasna/trash"||typeof d.version!=="string"||typeof d.bin?.trash!=="string"||xt(ne(u,d.bin.trash))!==l){s("unrecognized_package");continue}try{if(!Vr(l,r)){s("unsafe_interpreter");continue}}catch{s("unsafe_interpreter");continue}let h=t-Date.now();if(h<=0){s("identity_failed");break}let p=zr(o,["--identity"],{encoding:"utf8",timeout:h,maxBuffer:2048,env:{PATH:r},stdio:["ignore","pipe","pipe"]});if(p.error||p.status!==0||Date.now()>=t){s("identity_failed");continue}let m=JSON.parse(p.stdout);if(m.name==="@hasna/trash"&&m.version===d.version&&m.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:o,version:d.version};s("unsupported_protocol")}catch{}}return{ok:!1,code:n}}function Qe(e=process.env){let r=Pe(e);return r.ok?r.path:null}function he(e){let r=e.tool_input?.command;return typeof r==="string"?r:""}var yn=["/","/bin","/boot","/dev","/etc","/home","/lib","/lib32","/lib64","/libx32","/opt","/proc","/root","/run","/sbin","/srv","/sys","/usr","/var","/Applications","/Library","/System","/Users","/Volumes","/private"];var We=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,z=(e)=>e.split("/").pop()??"";function Je(e){let r=e.startsWith("~")?e.slice(1).split("/",1)[0]:"";if(r&&!/['"\\]/.test(r))return!0;let t=null,n=0;for(let s=0;s<e.length;s++){let i=e[s];if(t==="'"){if(i==="'")t=null;continue}if(i==="\\"){s++;continue}if(t==='"'){if(i==='"')t=null;continue}if(i==="'"||i==='"')t=i;else if(i==="$"&&e[s+1]==="{")n++,s++;else if(i==="}"&&n>0)n--;else if(i==="{"||i==="}")return!0}return!1}var vt=64;function xn(e,r){let t=0;for(let n=r;n<e.length;n++)if(e[n]==="\\")n++;else if(e[n]==="{")t++;else if(e[n]==="}"&&--t===0)return n;return e.length-1}function Zr(e){let r=e.match(/^([-+]?\d+)\.\.([-+]?\d+)(?:\.\.([-+]?\d+))?$/),t=r?null:e.match(/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([-+]?\d+))?$/),n=r??t;if(!n)return null;let s=r?Number(n[1]):n[1].charCodeAt(0),i=r?Number(n[2]):n[2].charCodeAt(0),o=Math.abs(Number(n[3]??1))||1;if(!Number.isSafeInteger(s)||!Number.isSafeInteger(i)||!Number.isSafeInteger(o))return"overflow";if(Math.floor(Math.abs(i-s)/o)+1>vt)return"overflow";let a=r&&(/^[-+]?0\d/.test(n[1])||/^[-+]?0\d/.test(n[2]))?Math.max(n[1].length,n[2].length):0,l=[];for(let u=s;s<=i?u<=i:u>=i;u+=s<=i?o:-o)if(!r)l.push(String.fromCharCode(u));else l.push(u<0?`-${String(-u).padStart(a-1,"0")}`:String(u).padStart(a,"0"));return l}function Kr(e){let r=null,t=0;for(let n=0;n<e.length;n++){let s=e[n];if(r==="'"){if(s==="'")r=null;continue}if(s==="\\"){n++;continue}if(r==='"'){if(s==='"')r=null;continue}if(s==="'"||s==='"')r=s;else if(s==="$"&&e[n+1]==="{")n=xn(e,n+1);else if(s==="{"){if(++t>vt)return"overflow";let i=null,o=0,a=!0,l=[];for(let u=n;u<e.length;u++){let c=e[u];if(i==="'"){if(c==="'")i=null;continue}if(c==="\\"){a=!1,u++;continue}if(i==='"'){if(c==='"')i=null;continue}if(c==="'"||c==='"')i=c,a=!1;else if(c==="$"&&e[u+1]==="{")u=xn(e,u+1),a=!1;else if(c==="{")o++;else if(c===","&&o===1)l.push(u);else if(c==="}"&&--o===0){if(l.length>0){let d=[n,...l,u];return{open:n,close:u,parts:d.slice(0,-1).map((h,p)=>e.slice(h+1,d[p+1]))}}let f=a?Zr(e.slice(n+1,u)):null;if(f==="overflow")return f;if(f)return{open:n,close:u,parts:f};break}}}}return null}function re(e){if(e.length>4096&&e.includes("{"))return null;let r=Kr(e);if(r===null)return[e];if(r==="overflow")return null;let t=[];for(let n of r.parts){let s=re(e.slice(0,r.open)+n+e.slice(r.close+1));if(s===null||t.push(...s)>vt)return null}return t}var g={arg:"none"},w={arg:"value"},Ie={arg:"optional"},Z={arg:"none",effect:"lookup"},v={arg:"none",effect:"refuse"},X={help:v,version:v},Xr=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,_t={timeout:{short:{k:w,s:w,v:g},long:{"kill-after":w,signal:w,verbose:g,foreground:g,"preserve-status":g,...X},positionals:[Xr]},env:{short:{i:g,"0":g,v:g,u:w,a:w,C:v,S:v},long:{"ignore-environment":g,null:g,debug:g,unset:w,argv0:w,chdir:v,"split-string":v,"block-signal":Ie,"default-signal":Ie,"ignore-signal":Ie,"list-signal-handling":v,...X},env:!0},nice:{short:{n:w},long:{adjustment:w,...X},numericOption:!0},nohup:{short:{},long:{...X}},command:{short:{p:g,v:Z,V:Z},long:{}},exec:{short:{c:g,l:g,a:w},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:w,o:w,e:w},long:{input:w,output:w,error:w,...X}},time:{short:{p:g,a:g,q:g,v:g,f:w,o:v,V:v},long:{portability:g,append:g,quiet:g,verbose:g,format:w,output:v,...X}},ionice:{short:{c:w,n:w,t:g,p:v,P:v,u:v,h:v,V:v},long:{class:w,classdata:w,ignore:g,pid:v,pgid:v,uid:v,...X}},setsid:{short:{c:g,f:g,w:g,h:v,V:v},long:{ctty:g,fork:g,wait:g,...X}}},Yr=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function Qr(e,r,t){let n=!1,s=(i)=>{if(!i||i.effect==="refuse")return!1;if(i.effect==="lookup")n=!0;return!0};while(t<r.length){let i=r[t];if(i.opaque)return null;let o=i.text;if(o==="--"){t++;break}if(o==="-"&&e.env){t++;continue}if(!o.startsWith("-")||o==="-")break;if(e.numericOption&&/^-[-+]?\d+$/.test(o)){t++;continue}if(o.startsWith("--")){let a=o.indexOf("="),l=a<0?o.slice(2):o.slice(2,a),u=Object.keys(e.long),c=u.includes(l)?[l]:u.filter((d)=>l&&d.startsWith(l));if(c.length!==1)return null;let f=e.long[c[0]];if(!s(f))return null;if(f.arg==="none"&&a>=0)return null;if(f.arg==="value"&&a<0){let d=r[++t];if(!d||d.opaque)return null}t++;continue}for(let a=1;a<o.length;a++){let l=e.short[o[a]];if(!s(l))return null;if(l.arg==="value"){if(a===o.length-1){let u=r[++t];if(!u||u.opaque)return null}break}}t++}if(n)return-1;for(let i of e.positionals??[]){let o=r[t];if(!o||o.opaque||!i.test(o.text))return null;t++}if(e.env||e.assignments){for(;t<r.length&&We.test(r[t].text);t++)if(r[t].opaque)return null}return t}function se(e,r=_t){let t=0;while(t<e.length&&(We.test(e[t].text)||Yr.has(e[t].text)))t++;for(let n=0;n<16;n++){if(t>=e.length)return{index:-1};if(e[t].opaque)return n===0?{index:t}:null;let s=Object.hasOwn(r,z(e[t].text))?r[z(e[t].text)]:void 0;if(!s)return{index:t};let i=Qr(s,e,t+1);if(i===null)return null;if(i<0)return{index:-1};t=i}return null}function Jr(e){return/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred|trash)(?![A-Za-z0-9_.-])/.test(e)}var Y={on:!1};function ie(e,r){if(!e.includes("\\")||!e.includes('"'))return;let t=Y.on;Y.on=!0;try{return r()}finally{Y.on=t}}var Rt=(e)=>e.split("/").pop()??"",Ot={perl:{letters:new Set(["e","E"]),long:new Set},python:{letters:new Set(["c"]),long:new Set},python2:{letters:new Set(["c"]),long:new Set},python3:{letters:new Set(["c"]),long:new Set},ruby:{letters:new Set(["e"]),long:new Set},node:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},nodejs:{letters:new Set(["e","p"]),long:new Set(["--eval","--print"])},bun:{letters:new Set(["e"]),long:new Set(["--eval"])},deno:{letters:new Set(["e"]),long:new Set(["--eval"])},php:{letters:new Set(["r"]),long:new Set},lua:{letters:new Set(["e"]),long:new Set},luajit:{letters:new Set(["e"]),long:new Set},Rscript:{letters:new Set(["e"]),long:new Set}},En=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,es=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),ts=new Set(["ssh","scp","sftp"]),ns=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),kn=new Set(["proxycommand","localcommand","knownhostscommand"]),rs=/(?:`|\$\()|\b(?:system|exec|execve|execvp|popen|spawn|posix_spawn|fork|subprocess|Popen|check_output|check_call|shell_exec|passthru|proc_open|pcntl_exec|qx|open|fopen|sysopen|unlink|remove|delete|rmtree|rmdir|mkdir|rename|truncate|ftruncate|chmod|chown|symlink|writeFile|createWriteStream|appendFile|child_process|FileUtils|shutil|Kernel|require|import|load|eval|os|sys|io|fs|File|IO|Dir|Path|pathlib|Deno|Bun)|%x\W/,ss=/[|>]|\b(?:system|getline|close|fflush|print\w*\s*>>?)/;function On(e){if(Jr(e.text))return!1;if(e.kind==="awk")return!ss.test(e.text);if(e.kind==="c-interp")return!rs.test(e.text);return!1}function is(e,r,t,n){let s=Ot[e]??(En.test(e)?Ot[e.replace(/[0-9.]+$/,"")]:void 0);if(!s)return null;let i=[],o=!1,a=(l)=>{if(l+1>=r.length||n(l+1))return o=!0,l;return i.push({text:r[l+1],kind:"c-interp"}),l+1};for(let l=t+1;l<r.length;l++){let u=r[l];if(u==="--")break;if(!u.startsWith("-")||u==="-")break;if(u.startsWith("--")){let f=u.indexOf("="),d=f<0?u:u.slice(0,f);if(s.long.has(d))if(f>=0)i.push({text:u.slice(f+1),kind:"c-interp"});else l=a(l);continue}let c=u.slice(1);for(let f=0;f<c.length;f++){if(!s.letters.has(c[f]))continue;if(f<c.length-1)i.push({text:c.slice(f+1),kind:"c-interp"});else l=a(l);break}}if(i.length===0&&!o)return null;return{programs:i,unresolved:o}}function os(e,r,t){let n=r+1;for(;n<e.length&&e[n].startsWith("-");n++)if(e[n]==="-L"||e[n]==="--log-level")n++;if(e[n]!=="eval"||t(n))return null;let s=[],i=!1;for(n++;n<e.length;n++){if(t(n)){i=!0;continue}if(!e[n].startsWith("-"))s.push({text:e[n],kind:"c-interp"})}return s.length===0&&!i?null:{programs:s,unresolved:i}}function ls(e,r,t){let n=[],s=!1,i=r+1;for(;i<e.length;i++){let o=e[i];if(o==="--"){i++;break}if(!o.startsWith("-")||o==="-")break;if(o==="-e"||o.startsWith("-e")){let a=o==="-e"?null:o.slice(2);if(a!==null)n.push({text:a,kind:"awk"});else if(i+1<e.length&&!t(i+1))n.push({text:e[++i],kind:"awk"});else s=!0}else if(o==="-f"||o.startsWith("-f")){if(s=!0,o==="-f")i++}else if(o==="-v"||o.startsWith("-v")){if(o==="-v")i++}}if(n.length===0&&!s){if(i<e.length)if(t(i))s=!0;else n.push({text:e[i],kind:"awk"})}return{programs:n,unresolved:s}}function as(e,r,t){let n=e[r],s,i=r;if(n==="-o"){if(r+1>=e.length)return{value:null,next:r};if(t(r+1))return{value:null,next:r+1};s=e[r+1],i=r+1}else s=n.slice(2);return{value:s,next:i}}function us(e,r,t){let n=[],s=!1;for(let i=r+1;i<e.length;i++){let o=e[i];if(o==="--")break;if(!o.startsWith("-")||o==="-")break;if(o.startsWith("--"))continue;if(o==="-o"||o.startsWith("-o")){let{value:l,next:u}=as(e,i,t);if(i=u,l===null){s=!0;continue}let c=l.indexOf("="),f=c>=0?c:l.search(/\s/),d=(f>=0?l.slice(0,f):l).trim().toLowerCase(),h=f>=0?l.slice(f+1).trim():"";if(kn.has(d))n.push({text:h,kind:"shell"});continue}if(o==="-F"||o.startsWith("-F")){if(s=!0,o==="-F")i++;continue}if(o==="-S"||o.startsWith("-S")){let l=o==="-S"?i+1<e.length&&!t(i+1)?e[++i]:null:o.slice(2);if(l===null)s=!0;else n.push({text:l,kind:"shell"});continue}let a=o.slice(1);for(let l=0;l<a.length;l++){if(!ns.has(a[l]))continue;if(l<a.length-1)break;if(a[l]==="o"||a[l]==="F"||a[l]==="S"){if(i+1<e.length){let u=e[i+1];if(a[l]==="o")if(!t(i+1)){let c=u.indexOf("="),f=c>=0?c:u.search(/\s/),d=(f>=0?u.slice(0,f):u).trim().toLowerCase();if(kn.has(d))n.push({text:f>=0?u.slice(f+1).trim():"",kind:"shell"})}else s=!0;else if(a[l]==="F")s=!0;else if(!t(i+1))n.push({text:u,kind:"shell"});i++}}else if(i+1<e.length)i++}}return{programs:n,unresolved:s}}function cs(e,r,t){let n=[],s=!1,i=!1;for(let o=r+1;o<e.length;o++){let a=e[o];if(a==="--")break;if(a==="-e"||a==="--rsh")if(i=!0,o+1<e.length&&!t(o+1))n.push({text:e[++o],kind:"shell"});else s=!0;else if(a.startsWith("--rsh="))i=!0,n.push({text:a.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(a)&&a.length>2&&!a.startsWith("--"))i=!0,n.push({text:a.slice(a.indexOf("e")+1),kind:"shell"})}return i?{programs:n,unresolved:s}:null}var fs=/^(?:true|false|yes|no|on|off|1|0|)$/i,ds=[/^core\.(?:pager|editor|sshcommand|askpass|alternaterefscommand)$/,/^sequence\.editor$/,/^diff\.external$/,/^interactive\.difffilter$/,/^imap\.tunnel$/,/^gc\.recentobjectshook$/,/^gpg\.program$/,/^gpg\.ssh\.defaultkeycommand$/,/^uploadpack\.packobjectshook$/,/^instaweb\.(?:browser|httpd)$/,/^credential\.(?:.+\.)?helper$/,/^diff\..+\.(?:command|textconv)$/,/^(?:difftool|mergetool|man|browser)\..+\.(?:cmd|path)$/,/^guitool\..+\.cmd$/,/^merge\..+\.driver$/,/^gpg\..+\.program$/,/^remote\..+\.(?:uploadpack|receivepack)$/,/^filter\..+\.(?:clean|smudge|process)$/,/^tar\..+\.command$/,/^trailer\..+\.(?:cmd|command)$/,/^sendemail\.(?:.+\.)?(?:tocmd|cccmd|headercmd|sendmailcmd)$/];function Rn(e,r){let t=e.toLowerCase(),n=(s)=>s===void 0?{kind:"unresolved"}:{kind:"command",text:s};if(/^alias\./.test(t))return r!==void 0&&r.trimStart().startsWith("!")?n(r.trimStart().slice(1)):{kind:"unresolved"};if(/^pager\./.test(t)||t==="core.fsmonitor")return r!==void 0&&fs.test(r)?{kind:"harmless"}:n(r);if(t==="core.gitproxy")return r!==void 0&&/^none(?:\s+for\s+\S+)?$/.test(r)?{kind:"harmless"}:n(r?.replace(/\s+for\s+\S+$/,""));if(/^submodule\..+\.update$/.test(t))return r!==void 0&&r.trimStart().startsWith("!")?n(r.trimStart().slice(1)):r===void 0?{kind:"unresolved"}:{kind:"harmless"};if(/^sendemail\.(?:.+\.)?smtpserver$/.test(t))return r!==void 0&&!r.startsWith("/")?{kind:"harmless"}:n(r);if(/^credential\.(?:.+\.)?helper$/.test(t)){if(r==="")return{kind:"harmless"};if(r===void 0)return{kind:"unresolved"};let s=r.trimStart();return n(s.startsWith("!")?s.slice(1):s.startsWith("/")?s:`git credential-${s}`)}if(ds.some((s)=>s.test(t)))return n(r);if(t==="core.hookspath")return r==="/dev/null"?{kind:"harmless"}:{kind:"unresolved"};if(t==="include.path"||/^includeif\..+\.path$/.test(t))return{kind:"unresolved"};if(t==="protocol.allow")return r!==void 0&&/^(?:never|user)$/i.test(r)?{kind:"harmless"}:{kind:"unresolved"};if(t==="protocol.ext.allow")return r!==void 0&&/^never$/i.test(r)?{kind:"harmless"}:{kind:"unresolved"};return{kind:"harmless"}}function vn(e){return/[$\x60]/.test(e)||["","x","/x","!x"].some((r)=>Rn(e,r).kind!=="harmless")}var hs=new Set(["GIT_PAGER","GIT_EDITOR","GIT_SEQUENCE_EDITOR","GIT_EXTERNAL_DIFF","GIT_SSH","GIT_SSH_COMMAND","GIT_ASKPASS","SSH_ASKPASS","GIT_PROXY_COMMAND","PAGER","EDITOR","VISUAL"]),ps=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function gs(e){let r=/'((?:[^']|'\\'')*)'/y,t=(i)=>i.replace(/'\\''/g,"'"),n=[],s=0;while(s<e.length){if(/\s/.test(e[s])){s++;continue}r.lastIndex=s;let i=r.exec(e);if(!i)return null;if(s=r.lastIndex,e[s]==="="){r.lastIndex=s+1;let o=r.exec(e);if(!o)return null;s=r.lastIndex,n.push([t(i[1]),t(o[1])])}else{let o=t(i[1]),a=o.indexOf("=");n.push(a<0?[o,void 0]:[o.slice(0,a),o.slice(a+1)])}}return n}function ms(e,r,t){let n=[],s=!1,i=(u,c,f=!0)=>{if(!f||/[$\x60]/.test(u)){s=!0;return}let d=Rn(u,c);if(d.kind==="unresolved")s=!0;else if(d.kind==="command")n.push({text:d.text,kind:"shell"})},o=(u,c)=>{let f=u.indexOf("="),d=f<0?u:u.slice(0,f),h=f<0?"true":u.slice(f+1);if(!c)return i(d,h);if(vn(d))s=!0},a=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let u=r+1;u<e.length;u++){let c=e[u];if(!c.startsWith("-")||c==="-")break;if(c==="--")break;if(c==="-c"){if(u+1>=e.length)break;o(e[u+1],t(u+1)),u++}else if(c.startsWith("-c")&&!c.startsWith("--"))o(c.slice(2),t(u));else if(c==="--config-env"||c.startsWith("--config-env=")){let f=c==="--config-env"?e[++u]??"":c.slice(13),d=f.indexOf("="),h=d<0?f:f.slice(0,d);if(t(u)||vn(h))s=!0}else if(c.startsWith("--exec-path="))s=!0;else if(a.has(c))u++}let l=new Map;for(let u=0;u<r;u++){let c=e[u].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!c)continue;let[,f,d]=c,h=t(u);if(hs.has(f))if(h)s=!0;else n.push({text:d,kind:"shell"});else if(ps.has(f)){if(h||d!=="/dev/null"||f==="GIT_EXEC_PATH"||f==="GIT_TEMPLATE_DIR")s=!0}else if(f==="GIT_ALLOW_PROTOCOL"){if(h||d.split(":").includes("ext"))s=!0}else if(f==="GIT_CONFIG_PARAMETERS"){let p=h?null:gs(d);if(p===null)s=!0;else for(let[m,O]of p)i(m,O??"true")}else if(/^GIT_CONFIG_(?:KEY|VALUE)_\d+$/.test(f)){let p=f.replace(/^GIT_CONFIG_(?:KEY|VALUE)_/,""),m=l.get(p)??{};if(f.startsWith("GIT_CONFIG_KEY_"))m.key=d;else m.value=d;if(h)m.opaque=!0;l.set(p,m)}}for(let u of l.values()){if(u.key===void 0)continue;if(u.opaque)o(`${u.key}=`,!0);else i(u.key,u.value)}if(n.length===0&&!s)return null;return{programs:n,unresolved:s}}function Ne(e){if(/^~/.test(e))return null;let r="";for(let t=0;t<e.length;t++){let n=e[t];if(n==="'"){let s=e.indexOf("'",t+1);if(s<0)return null;r+=e.slice(t+1,s),t=s}else if(n==="$"||n==="`")return null;else if(n==='"'){let s=t+1;for(;s<e.length&&e[s]!=='"';s++){let i=e[s];if(i==="$"||i==="`")return null;if(i==="\\"&&s+1<e.length&&/[$\x60"\\\n]/.test(e[s+1])){if(e[++s]!==`
|
|
4
|
-
`||
|
|
5
|
-
`));if(
|
|
6
|
-
`,
|
|
7
|
-
`)return!1;if(
|
|
8
|
-
`)return!1;if(
|
|
9
|
-
`)){let
|
|
10
|
-
`))return!1;
|
|
11
|
-
`||!
|
|
12
|
-
`;
|
|
13
|
-
`||
|
|
14
|
-
`,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function
|
|
15
|
-
`?"":`\\${
|
|
16
|
-
`,
|
|
17
|
-
`,
|
|
18
|
-
`,
|
|
19
|
-
`&&
|
|
20
|
-
`,
|
|
21
|
-
`){if(
|
|
22
|
-
`,
|
|
23
|
-
`,
|
|
24
|
-
`||
|
|
25
|
-
`))};return
|
|
26
|
-
`))};if(!n.trustworthy){let l=pe(e);return l===e?t:{...Se(l,r),trustworthy:!1}}let i=[],o=(l,u=t.refusals)=>{if(l.kind==="refuse")u.push({reason:l.reason});else if(l.kind==="rm"&&l.handoff)t.handoffHits.push(l.hit);else if(l.kind==="rm"){if(t.rmHits.push(l.hit),l.protectedReason)t.protectedHits.push({reason:l.protectedReason})}},a=s.cwd;for(let l of n.segments){let u=L(l),c=Nt(l),f=u<0?{kind:"none"}:$t(l,u,a,s);if(f.kind!=="cd")o(f);let d=(h)=>h!==null&&h>=0&&rt(l.words[h].text);if(c===null||d(u)||d(c)){if(l.words.some((h,p)=>!l.redirects.has(p)&&(Tt($t(l,p,a,s))||Vs(h.text))))i.push({reason:ui})}else if(c>=0&&c!==u){let h=$t(l,c,a,s);if(Tt(h))if(Tt(f))i.push({reason:di});else o(h,i)}if(f.kind==="cd")a=f.cwd}if(s.depth<3)for(let l of n.substitutions){let u=Se(l,{cwd:a,home:s.home,depth:s.depth+1});if(u.rmHits.length>0||u.refusals.length>0||u.handoffHits.length>0||u.protectedHits.length>0||!u.trustworthy&&U(l)){t.refusals.push({reason:"This command runs a delete inside a command substitution `$(\u2026)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(n.substitutions.some((l)=>U(l)))t.refusals.push({reason:"This command nests a delete inside command substitutions deeper than this hook will follow. Run the delete as a separate `rm -- <path>` command."});return t.refusals.push(...i),t}function pi(e){return e.words.map((r)=>r.text).join(" ")}function Dt(e,r){let t=r+1;while(t<e.words.length){let n=T(e.words[t].text);if(!n.startsWith("-"))return n;if(t++,Gs.has(n))t++}return null}function gi(e,r){if(e.words.slice(r+1).map((n)=>T(n.text)).includes("--cached"))return!0;return qn(e,r)}function qn(e,r){let t=e.words.slice(r+1).map((n)=>T(n.text));return t.includes("-n")||t.includes("--dry-run")}function Pn(e){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(e))return e;return`'${e.replace(/'/g,"'\\''")}'`}function mi(e,r,t,n){let s=n?["/usr/bin/env","-i",`HOME=${n.home}`,`PATH=${n.path}`,`HASNA_TRASH_AGENT=${n.agent}`,n.runtime,"--config=/dev/null","--no-env-file","--no-macros","--no-install",t,"guard"].map(Pn).join(" "):`${Pn(t)} guard`,i=[...r].sort((a,l)=>l.word.start-a.word.start),o=e;for(let a of i)o=`${o.slice(0,a.word.start)}${s}${o.slice(a.word.end)}`;return o}function bi(e,r,t,n,s){if(!r||r===e)return!1;if(t.length===0)return!1;let i=Se(r,{cwd:n,home:s});if(!i.trustworthy)return!1;if(i.rmHits.length>0||i.handoffHits.length>0)return!1;return i.refusals.length===0}function Si(e,r){let t={};for(let[n,s]of Object.entries(e??{}))t[n]=s;if(t.command=r,typeof t.description!=="string"||t.description.trim()==="")t.description=Is;if(typeof t.timeout!=="number"||!Number.isFinite(t.timeout)||t.timeout<=0)t.timeout=Ps;if(typeof t.run_in_background!=="boolean")t.run_in_background=!1;if("dangerouslyDisableSandbox"in t&&typeof t.dangerouslyDisableSandbox!=="boolean")delete t.dangerouslyDisableSandbox;return t}function wi(e,r,t,n,s){if(typeof e.command!=="string"||e.command.trim()==="")return!1;if(typeof e.description!=="string"||e.description.trim()==="")return!1;if(typeof e.timeout!=="number"||!Number.isFinite(e.timeout)||e.timeout<=0)return!1;if(typeof e.run_in_background!=="boolean")return!1;if("dangerouslyDisableSandbox"in e&&typeof e.dangerouslyDisableSandbox!=="boolean")return!1;return bi(r,e.command,t,n,s)}function yi(e){let r=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return P(e,Fn).segments.some((n)=>{let s=Nt(n);return[L(n),...s===null?[]:[s]].some((i)=>{if(n.words.slice(0,i<0?n.words.length:i).some((l)=>Hn.test(T(l.text))||r.has(be(l.text))))return!0;if(i<0)return!1;let a=n.words[i];return r.has(be(a.text))||/^\s*\(\s*\)\s*\{/.test(e.slice(a.end))})})}function B(e){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e}}}function xi(e){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:e}}}function ki(e){try{if(e.inspectTrash){let r=e.inspectTrash();return r.ok?{path:r.path,error:null}:{path:null,error:`${r.code}: ${wn[r.code]}`}}return{path:e.findTrash(),error:null}}catch(r){return{path:null,error:r instanceof Error?r.message:String(r)}}}var vi="[trash-guard] No verified @hasna/trash guard was found on PATH. This deletion is refused. Install the current @hasna/trash package with Bun and run its setup; the operating-system trash utility is not a compatible guard.",In="[trash-guard] The rewrite of this command did not verify (the delete could not be redirected cleanly), so the command is refused rather than run unredirected. Re-run the delete as a plain `rm -- <path>` command.";function Wn(e,r){if(e.refusals.length>0)return B(`[trash-guard] ${e.refusals[0].reason}`);if(e.protectedHits.length>0)return B(`[trash-guard] ${e.protectedHits[0].reason}`);if(!e.trustworthy)return U(r)?B("[trash-guard] This command could not be parsed to the end (unterminated quote, substitution or here-document), so a delete inside it cannot be redirected. Re-run the delete as a plain `rm -- <path>` command."):{continue:!0};if(e.rmHits.length===0){if(e.handoffHits.some((t)=>t.cwdOnly))return B("[trash-guard] This delete runs from inside a protected repository checkout but names only paths outside it. Run it from outside the checkout (`cd /tmp && rm -- <path>`), where it is redirected into trash.");return{continue:!0}}if(e.handoffHits.length>0)return B("[trash-guard] This command mixes a delete under the protected repo-checkout roots (owned by workspace-repos-guard) with a delete outside them, and a partial rewrite would leave one of them unredirected. Re-run them as separate commands, so each delete is handled by the hook that owns it.");return null}function zn(e,r){if(e.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(e.tool_name??"")){let p=e.tool_input?.command;if(typeof p!=="string")return B("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(p))return B("[trash-guard] Delete File would bypass recoverable deletion. First use `trash put -- <path>` or the trash_put MCP tool, then submit any remaining edits without the deletion block.");return{continue:!0}}if(e.tool_name!=="Bash")return{continue:!0};if(typeof e.tool_input?.command!=="string")return B("[trash-guard] The Bash tool call carried no readable `command`, so this hook cannot verify what would run. Refusing a call it cannot verify. Re-run the delete explicitly as `rm -- <path>` so it can be redirected into trash.");let n=he(e);if(!n.trim())return{continue:!0};let s=()=>Se(n,{cwd:r.cwd,home:r.home}),i=(p)=>p.rmHits.map((m)=>m.word.start).join(),o=(p)=>p()||!!ie(n,p),a=s(),l=Wn(a,n),u=ie(n,()=>{let p=s();return{result:p,verdict:Wn(p,n)}});if(u){let{result:p,verdict:m}=u;if(m&&!("continue"in m))return m;if(!m&&(!l||("continue"in l))&&i(p)!==i(a))return B(In)}if(l)return l;let c=ki(r);if(c.error!==null)return B(`[trash-guard] The guard could not resolve the \`trash\` binary (${c.error}), so this \`rm\` cannot be redirected into a recoverable delete \u2014 and an unrecoverable delete is never allowed, so the command is refused rather than run. Fix the environment (PATH, permissions) and re-run the same command.`);if(c.path===null)return B(vi);let f=c.path;if(r.execution&&o(()=>yi(n)))return B("[trash-guard] A deletion combined with shell environment changes cannot use the verified native execution context. Run the deletion as a separate plain rm command.");let d=mi(n,a.rmHits,f,r.execution),h=Si(e.tool_input,d);if(r.execution)h.hasna_execution="hasna.hooks.execution.v1";if(o(()=>!wi(h,n,a.rmHits,r.cwd,r.home)))return B(In);return xi(h)}import{closeSync as _i,constants as Un,fstatSync as Ei,lstatSync as Oi,openSync as Ri,readFileSync as Ai,statSync as Ti}from"fs";import{homedir as nr}from"os";import{dirname as Lt,isAbsolute as rr,join as ye,normalize as xe,relative as $i,resolve as Ue,sep as jt}from"path";var Ci=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),Pi=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),Ii=["hasna","hasnaxyz","hasna-products"],Ge="workspace-repos-guard";function Wi(e){return ye(e,".hasna","repos","clones")}function Ni(e){return ye(e,"workspace","repos")}function sr(e){return[Wi(e),Ni(e)]}function Di(e){return ye(e,".hasna","hooks","config","workspace-repos-guard-orgs")}var Li=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function Ht(e){let r=process.getuid?.();return r!==void 0&&(e.uid===0||e.uid===r)&&(e.mode&18)===0}function Hi(e){let r=Di(e),t;try{let s=Ri(r,Un.O_RDONLY|Un.O_NOFOLLOW);try{let o=Ei(s);if(!o.isFile()||!Ht(o)||o.size>4096)return null;t=Ai(s,"utf8")}finally{_i(s)}let i=xe(e);for(let o=Lt(r);o!==i;o=Lt(o)){let a=Oi(o);if(!a.isDirectory()||!Ht(a)||o===Lt(o))return null}if(!Ht(Ti(i)))return null}catch{return null}let n=t.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return n.length>0&&n.every((s)=>Li.test(s))?new Set(n):null}function Mi(e=process.env,r=nr()){let t=e.WORKSPACE_REPOS_GUARD_ORGS;if(typeof t==="string"&&t.trim())return new Set(t.split(",").map((n)=>n.trim()).filter(Boolean));return Hi(r)??new Set(Ii)}function Mt(e,r,t,n){if(n==="read")return{blocked:!1};let s=$i(r,e);if(s===""){if(n==="delete")return{blocked:!0,reason:`[${Ge}] delete of the protected repo-checkout root is forbidden: ${r}`};return{blocked:!0,reason:`[${Ge}] writes directly to the protected repo-checkout root are forbidden: ${r}`}}if(s.startsWith(`..${jt}`)||s===".."||rr(s))return{blocked:!1};let i=s.split(jt).filter(Boolean);if(n==="delete")return{blocked:!0,reason:`[${Ge}] delete under the protected repo-checkout root (${r}) is forbidden at any depth: ${e}`};if(i.length<=1)return{blocked:!0,reason:`[${Ge}] writing would create a top-level entry directly under the protected repo-checkout root (${r}); only GitHub-org folders belong there: ${e}`};let o=i[0];if(!t.has(o))return{blocked:!0,reason:`[${Ge}] '${o}' is not an allowed GitHub org under the protected repo-checkout root (${r}); allowed: ${[...t].join(", ")}: ${e}`};return{blocked:!1}}var ir=/\b(?:-o|--output|-O|--output-document|-out)\b/,Fi=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,Bi=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function or(e){return e.replace(Fi," ")}function ji(e){let r=[],t=null,n=0,s=0,i=!1,o=0;for(let a=0;a<e.length;a++){let l=e[a];if(t==="'"){if(l==="'")t=null;continue}if(l==="\\"){a++;continue}if(l==="("){n++;continue}if(l===")"){if(--n<0)return[e];continue}if(l==="$"&&e[a+1]==="{"){s++,a++;continue}if(l==="}"&&s>0){s--;continue}if(l==="`"){i=!i;continue}if(t==='"'){if(l==='"')t=null;continue}if(l==="'"||l==='"'){t=l;continue}if(l!=="|"||n>0||s>0||i||e[a-1]===">")continue;if(r.push(e.slice(o,a)),e[a+1]==="&")a++;o=a+1}if(t||n!==0||s!==0||i)return[e];return r.push(e.slice(o)),r}function Gi(e){let r=[],t="",n="",s=null,i=!1,o=()=>{if(!i)return;let a=n.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),l=t.startsWith("~")&&!/^~(?:\/|$)/.test(n);r.push({text:l?`./${t}`:t,opaque:/[$\x60*?[]/.test(a)||/[()]/.test(a)||Je(n)}),t="",n="",i=!1};for(let a=0;a<e.length;a++){let l=e[a];if(s==="'"){if(l==="'")s=null;else t+=l;n+=l;continue}if(l==="\\"&&a+1<e.length){let u=e[a+1];t+=s==='"'&&!/[$\x60"\\\n]/.test(u)?l+u:s==='"'&&u===`
|
|
27
|
-
`&&!
|
|
28
|
-
`)
|
|
29
|
-
`),
|
|
30
|
-
`));for(let
|
|
31
|
-
`))?null:{outer:
|
|
32
|
-
`),bodies:s}}var fo="/";function at(e,r,t){if(!e)return[];let n=P(e).trustworthy?e:pe(e),s=co(e);return[...n===e?[]:at(n,r,t),...s?[...tr(s.outer,r,t),...s.bodies.flatMap((i)=>at(i,r,fo))]:tr(e,r,t)]}var ho=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,po=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function Qn(e,r,t=!1){let n=[],s=0;for(let a of r)n.push(s),s+=a.length;let i=P(e);if(!i.trustworthy||!t&&i.substitutions.length>0)return null;let o=i.segments.flatMap((a)=>a.words).filter((a)=>r.some((l,u)=>u%2===1&&n[u]<a.end&&n[u]+l.length>a.start));return o.length>0?{lexed:i,offsets:n,words:o}:null}function Jn(e,r,t=[]){if(zt(r)!=="read")return!1;let n=L(e),s=e.words.filter((c,f)=>!e.redirects.has(f)),i=se(s.map((c)=>Ut(c.text)));if(i===null)return!1;let o=[n<0?1/0:n,i.index<0?1/0:e.words.indexOf(s[i.index])];if(e.words.some((c,f)=>f<Math.max(...o)&&!e.redirects.has(f)&&We.test(T(c.text))))return!1;if([n<0?null:e.words[n].text,i.index<0?null:s[i.index].text].every((c)=>c===null||dr.has(z(T(c)))))return!0;let l=s.filter((c)=>!t.includes(c)),u=l.map((c)=>T(c.text));return le(l.map((c)=>c.text).join(" "))==="read"&&le(u.join(" "))==="read"&&!u.some((c)=>ar.has(c))}function go(e,r,t,n){let s=(i)=>i.start<n&&i.end>t;if(!r.words.some(s))return!1;return r.lexed.segments.filter((i)=>i.words.some(s)).some((i)=>ot(i))}var er=(e,r)=>e.slice(r.words[0].start,r.words[r.words.length-1].end);function mo(e,r,t,n){let s=(o)=>o.start<n&&o.end>t,i=r.words.filter(s);if(i.length===0||i.some((o)=>!po.test(o.text)))return!1;for(let o of r.lexed.segments.filter((a)=>a.words.some(s)))if(!Jn(o,er(e,o),r.words))return!1;for(let o of i){let a=o.text.slice(1,-1);if(a.includes("<<"))return!1;let l=P(a);if(!l.trustworthy||l.substitutions.length>0)return!1;if(!l.segments.every((u)=>Jn(u,er(a,u))))return!1}return!0}function tr(e,r,t){if(!e)return[];let n=sr(r),s=(h)=>n.some((p)=>h===p||h.startsWith(`${p}${jt}`)),i=e.split(ho),o=Qn(e,i),a=o??Qn(e,i,!0),l=[],u=[t],c=new Set([t]),f=!0,d=[];for(let h=0;h<i.length;h+=2){let p=h===0?"":i[h-1].trim();if(p==="||")f=!1;else if(p!=="&&")f=!0;if(p!=="&&"||!f)u=[...c];let m=i[h],O=(m.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,A=(m.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let S=0;S<O;S++)d.push({current:[...u],reachable:new Set(c),certain:f});let I=Ui(m),j=o!==null&&mo(e,o,o.offsets[h],o.offsets[h]+m.length),k=!j&&(a!==null&&go(e,a,a.offsets[h],a.offsets[h]+m.length)||lt(m.trim())),b=I.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),R=b?null:I.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(R){for(let S of Xn(R[1],u,r)??[])c.add(S);f=!1,u=[...c]}let H=Gt(r),M=n.map((S)=>Gt(S.slice(r.length+1))).join("|"),_e=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${H}"*)/(?:${M})`),pn=new RegExp(`(${_e.source})([^\\s"';&|<>()\`]*|$)`,"g"),gn=(S)=>{let N=[],F;pn.lastIndex=0;while((F=pn.exec(S))!==null)N.push(xe(ze(F[0],r)).replace(/\/+$/,""));return N},mn=a===null?0:a.offsets[h],bn=(S)=>S.start<mn+m.length&&S.end>mn,Dr=a!==null&&a.words.some(bn)?qe({segments:a.lexed.segments.filter((S)=>S.words.some(bn))}):[m.trim(),I].flatMap((S)=>{let N=P(S);if(!N.trustworthy)N=P(pe(S));return N.trustworthy?qe(N):[]}),mt=ji(I).map((S,N)=>{let F=N===0?[...new Set(Dr)]:[],Ee=!1,Oe=or(S).replace(Bi,(St,ce)=>{if(!ce||/[$\x60]/.test(ce))Ee=!0;if(ce)F.push(ce);return" "}),Re=j?"read":k?"delete":zt(Oe);return{commandPart:Oe,operands:F,op:Ee&&Re==="read"?"write":Re}}),Lr=mt.some((S)=>S.op==="delete")?"delete":mt.some((S)=>S.op==="write")?"write":"read",bt=u.filter(s);if(k)for(let S of bt)l.push({path:S,op:"delete"});for(let S of mt){let N=!1;for(let D of gn(S.commandPart))N=!0,l.push({path:D,op:Lr});for(let D of S.operands){let K=gn(D);for(let q of K)l.push({path:q,op:"write"});if(K.length>0)continue;for(let q of bt)l.push({path:xe(Ue(q,ze(D,r))),op:"write"})}if(N||S.op==="read")continue;let F=Gi(S.commandPart),Ee=Zi(S.commandPart,F),Oe=z(F[Ee]?.text??""),Re=F.slice(Ee+1),St=((Oe==="trash"?eo(Re):null)??Ki(Oe,Re)).map((D)=>D.opaque?".":D.text),ce=S.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(S.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(S.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(S.commandPart),Ae=[];if(ce)for(let D of St.length>0?St:["."])Ae.push({operand:D,op:S.op});else{let D=S.commandPart.match(Vi),K=F.at(-1);if(Ae.push({operand:D?D[1]:!K||K.opaque?".":K.text,op:S.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(S.commandPart))F.forEach((q,Sn)=>{let fe,wt=q.text.match(/^-[A-Za-z]*?t(.*)$/),Ze=q.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(wt&&!q.text.startsWith("--"))fe=wt[1]?{text:wt[1],opaque:q.opaque}:F[Sn+1];else if(Ze&&"--target-directory".startsWith(Ze[1]))fe=Ze[2]!==void 0?{text:Ze[2],opaque:q.opaque}:F[Sn+1];if(fe)Ae.push({operand:fe.opaque||!fe.text?".":fe.text,op:S.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(S.commandPart))Ae.push({operand:".",op:S.op})}for(let D of bt)for(let{operand:K,op:q}of Ae)l.push({path:xe(Ue(D,ze(K,r))),op:q})}if(b){let S=Xn(b[1],u,r);if(S){for(let N of S)c.add(N);if(f)u=S}else f=!1}for(let S=0;S<A&&d.length>0;S++)({current:u,reachable:c,certain:f}=d.pop())}return l}var bo=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function So(e,r){let t=[],n;while((n=bo.exec(e))!==null){let s=n[1]==="Delete File"?"delete":"write";t.push({path:xe(Ue(r,n[2])),op:s})}return t}function gr(e,r={}){let t=[];if(e.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:t};let n=typeof e.tool_name==="string"?e.tool_name:"",s=r.home??nr(),i=sr(s),o=Mi(process.env,s);if(n==="Bash"){let d=he(e);if(!d)return{output:{continue:!0},warnings:t};let h=typeof e.cwd==="string"&&e.cwd?e.cwd:process.cwd(),p=at(d,s,h);p.unshift(...ie(d,()=>at(d,s,h))??[]);for(let m of p)for(let O of i){let A=Mt(m.path,O,o,m.op);if(A.blocked)return{output:{decision:"block",reason:A.reason},warnings:t}}return{output:{continue:!0},warnings:t}}let a=e.tool_input??{},l=typeof e.cwd==="string"&&e.cwd?e.cwd:process.cwd();if(Pi.has(n)){let d=typeof a.patch==="string"?a.patch:"";if(!d)return{output:{continue:!0},warnings:t};let h=So(d,l);for(let p of h)for(let m of i){let O=Mt(p.path,m,o,p.op);if(O.blocked)return{output:{decision:"block",reason:O.reason},warnings:t}}return{output:{continue:!0},warnings:t}}if(!Ci.has(n))return{output:{continue:!0},warnings:t};let u=typeof a.file_path==="string"?a.file_path:typeof a.path==="string"?a.path:typeof a.notebook_path==="string"?a.notebook_path:null;if(!u)return{output:{continue:!0},warnings:t};let c=ze(u,s),f=rr(c)?xe(c):Ue(l,c);for(let d of i){let h=Mt(f,d,o,"write");if(h.blocked)return{output:{decision:"block",reason:h.reason},warnings:t}}return{output:{continue:!0},warnings:t}}var wo=new Set(["id","node_id","databaseId","fullDatabaseId","number","state","state_reason","stateReason","status","conclusion","bucket","name","login","sha","oid","abbreviatedOid","ref","headRefName","baseRefName","headRefOid","baseRefOid","head_sha","headSha","head_branch","headBranch","merged","mergeable","mergeable_state","mergeStateStatus","draft","isDraft","locked","isLocked","title","displayTitle","display_title","created_at","updated_at","closed_at","merged_at","started_at","completed_at","submitted_at","pushed_at","published_at","createdAt","updatedAt","closedAt","mergedAt","startedAt","completedAt","submittedAt","pushedAt","publishedAt","tag_name","tagName","total_count","totalCount","count","additions","deletions","changes","changed_files","changedFiles","filename","path","event","workflow","workflowName","workflow_id","workflowDatabaseId","run_id","run_number","run_attempt","attempt","check_suite_id","default_branch","defaultBranch","full_name","fullName","nameWithOwner","private","isPrivate","visibility","archived","isArchived","fork","isFork","isRequired","is_required","required","context","type","__typename","role","permission","size","reviewDecision","author_association","authorAssociation","isCrossRepository","maintainerCanModify","maintainer_can_modify","commentsCount","language","digest","size_in_bytes","run_started_at","date","wait_timer","ahead_by","behind_by","total_commits","expired","current_user_can_approve","environment","html_url"]),yo=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),wr=new Set(["length","utf8bytelength","not","type","any","all","isempty","empty","test","startswith","endswith","contains","inside","has","in","index","rindex","indices","floor","ceil","round","fabs","sqrt","isinfinite","isnan","isnormal","infinite","nan","true","false","null"]),yr=new Set(["tostring","tojson","ascii_downcase","ascii_upcase","ltrimstr","rtrimstr","trim","ltrim","rtrim","sort","unique","reverse","first","last","min","max","add","flatten","join","split","values","nulls","strings","numbers","booleans","arrays","objects","iterables","scalars","sort_by","group_by","unique_by","min_by","max_by","select","limit","to_entries","from_entries"]),xo=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),ko=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class Kt extends Error{}var _=()=>{throw new Kt};function Vt(e,r){let t=[],n="",s=r+1;while(s<e.length){let i=e[s];if(i==='"'){if(n)t.push(n);return{end:s+1,parts:t}}if(i==="\\"){let o=e[s+1];if(o==="("){let a=1,l=s+2;while(l<e.length&&a>0){let u=e[l];if(u==='"'){l=Vt(e,l).end;continue}if(u==="(")a++;else if(u===")")a--;l++}if(a!==0)_();if(n)t.push(n),n="";t.push({src:e.slice(s+2,l-1)}),s=l;continue}if(o===void 0)_();n+=o,s+=2;continue}n+=i,s++}return _()}function xr(e){let r=[],t=0,n=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while(t<e.length){let s=e[t];if(/\s/.test(s)){t++;continue}if(s==="#")_();if(s==='"'){let l=Vt(e,t);r.push({t:"str",parts:l.parts}),t=l.end;continue}if(s==="."){if(e[t+1]===".")_();let l=/^[A-Za-z_][A-Za-z0-9_]*/.exec(e.slice(t+1));if(l){r.push({t:"field",name:l[0]}),t+=1+l[0].length;continue}if(e[t+1]==='"'){let u=Vt(e,t+1);if(u.parts.some((c)=>typeof c!=="string"))_();r.push({t:"field",name:u.parts.join("")}),t=u.end;continue}r.push({t:"dot"}),t++;continue}if(s==="$"||s==="@"){let l=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(e.slice(t));if(!l||s==="$")_();r.push({t:"fmt",name:l[0]}),t+=l[0].length;continue}let i=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(e.slice(t));if(i){r.push({t:"num"}),t+=i[0].length;continue}let o=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(e.slice(t));if(o){r.push({t:"ident",name:o[0]}),t+=o[0].length;continue}let a=n.find((l)=>e.startsWith(l,t));if(!a)_();r.push({t:"op",v:a}),t+=a.length}return r}var vo=new Set(["if","then","elif","else","end","as","def","reduce","foreach","try","catch","label","import","include","and","or","__loc__","error","input","inputs","debug","stderr","env","halt","halt_error","input_filename","input_line_number","recurse","paths","leaf_paths","getpath","setpath","delpaths","del","path","splits","sub","gsub","capture","match","scan","keys","keys_unsorted","map_values","with_entries","tostream","fromstream","truncate_stream","walk","tonumber","implode","explode","ascii","fromjson"]);class Xt{tokens;at=0;constructor(e){this.tokens=e}parse(){if(this.tokens.length===0)_();let e=this.pipe();if(this.at!==this.tokens.length)_();return e}peek(){return this.tokens[this.at]}isOp(e){let r=this.peek();return!!r&&r.t==="op"&&r.v===e}isIdent(e){let r=this.peek();return!!r&&r.t==="ident"&&r.name===e}expectOp(e){if(!this.isOp(e))_();this.at++}pipe(){let e=this.comma();if(this.isIdent("as"))_();if(this.isOp("|"))this.at++,e={k:"pipe",a:e,b:this.pipe()};return e}comma(){let e=this.alt();while(this.isOp(","))this.at++,e={k:"comma",a:e,b:this.alt()};return e}alt(){let e=this.or();if(this.isOp("//"))return this.at++,{k:"alt",a:e,b:this.alt()};return e}or(){let e=this.and();while(this.isIdent("or"))this.at++,e={k:"bool",a:e,b:this.and()};return e}and(){let e=this.cmp();while(this.isIdent("and"))this.at++,e={k:"bool",a:e,b:this.cmp()};return e}cmp(){let e=this.add();for(let r of["==","!=","<=",">=","<",">"])if(this.isOp(r))return this.at++,{k:"bool",a:e,b:this.add()};for(let r of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(r))_();return e}add(){let e=this.mul();while(this.isOp("+")||this.isOp("-"))this.at++,e={k:"arith",a:e,b:this.mul()};return e}mul(){let e=this.unary();while(this.isOp("*")||this.isOp("/")||this.isOp("%"))this.at++,e={k:"arith",a:e,b:this.unary()};return e}unary(){if(this.isOp("-"))return this.at++,{k:"neg",of:this.postfix()};return this.postfix()}objectValue(){let e=this.unary();if(this.isOp("|"))this.at++,e={k:"pipe",a:e,b:this.objectValue()};return e}postfix(){let e=this.primary();for(;;){let r=this.peek();if(!r)return e;if(r.t==="field"){this.at++,e={k:"field",name:r.name,of:e};continue}if(r.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(r.t==="op"&&r.v==="?"){this.at++,e={k:"opt",of:e};continue}if(r.t==="op"&&r.v==="["){e=this.bracket(e);continue}return e}}bracket(e){if(this.expectOp("["),this.isOp("]"))return this.at++,{k:"iter",of:e};if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:e}}let r=this.pipe();if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:e}}return this.expectOp("]"),{k:"index",of:e,key:r}}primary(){let e=this.peek();if(!e)return _();switch(this.at++,e.t){case"dot":return{k:"dot"};case"field":return{k:"field",name:e.name};case"num":return{k:"lit"};case"str":return this.stringNode(e.parts);case"fmt":{if(!ko.has(e.name))_();let r=this.peek();if(r?.t==="str")return this.at++,{k:"fmt",name:e.name,str:this.stringNode(r.parts)};return{k:"fmt",name:e.name}}case"ident":{if(vo.has(e.name))_();if(e.name==="map"||wr.has(e.name)||yr.has(e.name)){let r=[];if(this.isOp("(")){this.at++,r.push(this.pipe());while(this.isOp(";"))this.at++,r.push(this.pipe());this.expectOp(")")}return{k:"call",name:e.name,args:r}}return _()}case"op":{if(e.v==="("){let r=this.pipe();return this.expectOp(")"),r}if(e.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let r=this.pipe();return this.expectOp("]"),{k:"array",of:r}}if(e.v==="{")return this.object();return _()}}return _()}stringNode(e){let r=[];for(let t of e){if(typeof t==="string")continue;r.push(new Xt(xr(t.src)).parse())}return r.length===0?{k:"str",parts:r,text:e.join("")}:{k:"str",parts:r}}object(){let e=[];if(this.isOp("}"))return this.at++,{k:"object",entries:e};for(;;){let r=this.peek();if(!r)_();this.at++;let t;if(r.t==="ident")t=r.name;else if(r.t==="str"){if(r.parts.some((n)=>typeof n!=="string"))_();t=r.parts.join("")}else _();if(this.isOp(":"))this.at++,e.push({key:"static",value:this.objectValue()});else e.push({key:"static",value:{k:"field",name:t}});if(this.isOp(",")){this.at++;continue}return this.expectOp("}"),{k:"object",entries:e}}}}function Yt(e){if(typeof e==="object"&&"union"in e)return e.union.every(Yt);return e==="safe"||typeof e==="object"&&wo.has(e.leaf)}var Ve=(...e)=>e.every(Yt)?"safe":"tainted";function Zt(...e){let r=[];for(let t of e)if(typeof t==="object"&&"union"in t)r.push(...t.union);else r.push(t);return r.length===1?r[0]:{union:r}}function ut(e,r){return typeof e==="object"&&"union"in e?Zt(...e.union.map(r)):r(e)}var ct=(e)=>typeof e==="object"&&("leaf"in e)&&yo.has(e.leaf),J=(e)=>ut(e,(r)=>r==="safe"?"safe":r==="tainted"||ct(r)?"tainted":"unknown");function mr(e){return e.k==="lit"||e.k==="str"&&e.parts.length===0||e.k==="call"&&["true","false","null"].includes(e.name)&&e.args.length===0}function br(e,r,t){return ut(e,(n)=>{if(n==="safe"||n==="tainted")return n;if(ct(n))return"tainted";if(n==="root"&&t.rootScalars.has(r))return"safe";return{leaf:r}})}function E(e,r,t){switch(e.k){case"dot":return r;case"field":return br(e.of?E(e.of,r,t):r,e.name,t);case"iter":return J(E(e.of,r,t));case"index":{let n=E(e.of,r,t);if(e.key.k==="str"&&e.key.text!==void 0)return br(n,e.key.text,t);if(e.key.k==="lit")return J(n);return E(e.key,r,t),"tainted"}case"slice":return ut(E(e.of,r,t),(n)=>n==="root"?"unknown":ct(n)?"tainted":n);case"opt":return E(e.of,r,t);case"lit":return"safe";case"str":return Ve(...e.parts.map((n)=>E(n,r,t)));case"fmt":return e.str?E(e.str,r,t):r;case"array":return e.of?Ve(E(e.of,r,t)):"safe";case"object":return Ve(...e.entries.map((n)=>E(n.value,r,t)));case"pipe":return E(e.b,E(e.a,r,t),t);case"comma":return Zt(E(e.a,r,t),E(e.b,r,t));case"alt":return Zt(E(e.a,r,t),E(e.b,r,t));case"bool":return E(e.a,r,t),E(e.b,r,t),"safe";case"arith":return Ve(E(e.a,r,t),E(e.b,r,t));case"neg":return E(e.of,r,t);case"call":return _o(e,r,t)}}var Sr=(e)=>ut(e,(r)=>r==="root"?"unknown":ct(r)?"tainted":r);function _o(e,r,t){let{name:n,args:s}=e;if(xo.has(n)&&n!=="limit"&&!s.every(mr))_();switch(n){case"map":if(s.length!==1)_();return Ve(E(s[0],J(r),t));case"select":if(s.length!==1)_();return E(s[0],r,t),r;case"limit":if(s.length!==2||!mr(s[0]))_();return E(s[1],r,t);case"first":case"last":if(s.length>1)_();return s.length===1?E(s[0],r,t):J(r);case"min":case"max":return J(r);case"sort_by":case"group_by":case"unique_by":if(s.length!==1)_();return E(s[0],J(r),t),Sr(r);case"min_by":case"max_by":if(s.length!==1)_();return E(s[0],J(r),t),J(r);case"any":case"all":case"isempty":for(let i of s)E(i,"unknown",t);return"safe"}if(wr.has(n))return"safe";if(yr.has(n))return Sr(r);return _()}function kr(e,r={}){if(typeof e!=="string"||!e.trim()||e.length>4096)return!1;try{let t=new Xt(xr(e)).parse();return Yt(E(t,"root",{rootScalars:r.rootScalars??new Set}))}catch(t){if(t instanceof Kt)return!1;return!1}}var ln="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",x={refused:!1},y=(e)=>({refused:!0,rule:e}),Qt=new Set(["additions","assignees","author","baseRefName","baseRefOid","changedFiles","closed","closedAt","createdAt","deletions","files","fullDatabaseId","headRefName","headRefOid","headRepository","headRepositoryOwner","id","isCrossRepository","isDraft","labels","maintainerCanModify","mergeCommit","mergeStateStatus","mergeable","mergedAt","mergedBy","number","potentialMergeCommit","reactionGroups","reviewDecision","reviewRequests","state","title","updatedAt","url"]),Jt=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),vr=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),_r=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),Eo=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),Oo=new Set(["author","committer","id","parents","repository","sha","url"]),Ro=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function Rr(e){let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(n==="\\"){t++;continue}if(n==="'"){let s=e.indexOf("'",t+1);if(s<0)return!1;t=s;continue}if(n==='"'){t++;while(t<e.length&&e[t]!=='"')t+=e[t]==="\\"?2:1;continue}if(n==="{"){r.push({list:!1});continue}if(r.length===0)continue;if(n===","||n==="."&&e[t+1]===".")r[r.length-1].list=!0;else if(n==="}"&&r.pop().list)return!0}return!1}function ke(e){let r="",t=!1,n=0,s=(i)=>e[i]==="`"||e[i]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(e[i+1]??"");while(n<e.length){let i=e[n];if(i==="\\"){r+=e[n+1]??"",n+=2;continue}if(i==="$"&&e[n+1]==="'"){t=!0,r+=i,n++;continue}if(i==="'"){let o=e.indexOf("'",n+1);if(o<0){t=!0,r+=e.slice(n+1);break}r+=e.slice(n+1,o),n=o+1;continue}if(i==='"'){n++;while(n<e.length&&e[n]!=='"'){if(e[n]==="\\"&&/[$`"\\\n]/.test(e[n+1]??"")){r+=e[n+1],n+=2;continue}if(s(n))t=!0;r+=e[n],n++}if(n>=e.length)t=!0;n++;continue}if(s(n)||i==="*"||i==="?"||i==="[")t=!0;r+=i,n++}if(!t&&e.includes("{")&&Rr(e))t=!0;return{value:r,opaque:t,raw:e}}var ae=(e)=>e.slice(e.lastIndexOf("/")+1);function nn(e,r="word"){let t=[],n=!1;for(let s=0;s<e.length;s++){let i=e[s];if(i==="\\"){s++;continue}if(r==="word"&&i==="'"&&!n){let o=e.indexOf("'",s+1);if(o<0)return{bodies:t,complete:!1};s=o;continue}if(r==="word"&&i==='"'){n=!n;continue}if(i==="`"){let o=s+1;while(o<e.length&&e[o]!=="`")o+=e[o]==="\\"?2:1;if(o>=e.length)return{bodies:t,complete:!1};t.push(e.slice(s+1,o)),s=o;continue}if(i==="$"&&e[s+1]==="("){let o=oe(e,s+1);if(o<0)return{bodies:t,complete:!1};t.push(e.slice(s+2,o-1)),s=o-1}}return{bodies:t,complete:!0}}function ve(e,r){let t=new Set(r.values),n={flags:[],positionals:[]},s=(i,o)=>({value:i,opaque:o.opaque,raw:o.raw});for(let i=0;i<e.length;i++){let o=e[i],a=o.value;if(a==="--"){n.positionals.push(...e.slice(i+1));break}if(a.startsWith("--")&&a.length>2){let l=a.indexOf("="),u=l>=0?a.slice(0,l):a;if(l>=0)n.flags.push({name:u,value:s(a.slice(l+1),o),inline:!0});else if(t.has(u)){let c=e[i+1];n.flags.push(c?{name:u,value:c}:{name:u,missing:!0}),i++}else n.flags.push({name:u});continue}if(a.startsWith("-")&&a.length>1){for(let l=1;l<a.length;l++){let u="-"+a[l],c=a.slice(l+1);if(c.startsWith("=")){n.flags.push({name:u,value:s(c.slice(1),o),inline:!0});break}if(!t.has(u)){n.flags.push({name:u});continue}if(c)n.flags.push({name:u,value:s(c,o),inline:!0});else{let f=e[i+1];n.flags.push(f?{name:u,value:f}:{name:u,missing:!0}),i++}break}continue}n.positionals.push(o)}return n}function W(e,...r){let t=!1;for(let n of e.flags){if(!r.includes(n.name))continue;if(!n.inline){t=!0;continue}let s=n.value;t=!s.opaque&&["1","t","T","TRUE","true","True"].includes(s.value)}return t}var te=(e,...r)=>e.flags.filter((t)=>r.includes(t.name)),G=["-R","--repo","-q","--jq","-t","--template","--json"],ue={"pr view":{values:G},"issue view":{values:G},"release view":{values:G},"discussion view":{values:[...G,"--after","-L","--limit","--order"]},"pr list":{values:[...G,"--app","-a","--assignee","-A","--author","-B","--base","-H","--head","-l","--label","-L","--limit","-S","--search","-s","--state"]},"issue list":{values:[...G,"--app","-a","--assignee","-A","--author","-l","--label","-L","--limit","--mention","-m","--milestone","-S","--search","-s","--state"]},"discussion list":{values:[...G,"--after","-A","--author","-c","--category","-l","--label","-L","--limit","--order","-S","--search","--sort","-s","--state"]},"release list":{values:[...G,"-L","--limit","-O","--order"]},"pr status":{values:G},"issue status":{values:G},"pr checks":{values:[...G,"-i","--interval"]},"pr diff":{values:["-R","--repo"]},search:{values:[...G,"--app","--assignee","--author","--author-date","--author-email","--author-name","--base","--checks","--closed","--commenter","--committer","--committer-date","--committer-email","--committer-name","--created","--hash","--head","--interactions","--involves","--label","--language","--limit","-L","--match","--mentions","--merged-at","--milestone","--no-assignee","--no-label","--no-milestone","--no-project","--order","--owner","--parent","--project","--reactions","--review","--review-requested","--reviewed-by","--sort","--state","--team-mentions","--tree","--updated","--visibility","--extension","--filename","--size","--forks","--good-first-issue","--help-wanted-issues","--number-topics","--stars","--topic","--followers","--include-forks","--license"]},"project item-list":{values:["--format","-L","--limit","--owner","-q","--jq","-t","--template","--query","--field","--field-id"]},api:{values:["-X","--method","-H","--header","-f","--raw-field","-F","--field","-q","--jq","-t","--template","-p","--preview","--input","--hostname","--cache"]},group:{values:["-R","--repo"]}},Ao=new Set(["auth","browse","codespace","cs","gist","org","repo","skill","cache","run","workflow","co","agent-task","alias","attestation","completion","config","copilot","extension","ext","extensions","gpg-key","label","licenses","preview","ruleset","secret","ssh-key","variable","help","version","accessibility","actions","environment","exit-codes","formatting","mintty","reference","telemetry"]),To=new Set(["pr","issue","release","discussion","search","project","api","status"]),$o=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),Co=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),Po=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),Io=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function pt(e,r){let t=te(e,"--json"),n=[],s=!1;for(let i of t){if(i.missing){if(r.appendsArgs)s=!0;continue}if(!i.value)continue;if(i.value.opaque)s=!0;n.push(...i.value.value.split(",").map((o)=>o.trim()).filter(Boolean))}return{present:t.length>0,opaque:s,fields:n}}function an(e,r){if(W(e,"--verbose")||te(e,"-t","--template").length>0)return!1;let t=te(e,"-q","--jq");return t.length>0&&t.every((n)=>n.value!==void 0&&!n.value.opaque&&kr(n.value.value,{rootScalars:r}))}function un(e,r,t,n){let s=pt(e,t);if(s.opaque)return y("unclassifiable");if(s.fields.every((i)=>r.has(i)))return x;if(t.debug)return y("debug-traffic");return an(e)?x:y(n)}function ft(e,r,t,n,s){let i=ve(e,ue[r]);if(W(i,"-h","--help"))return x;if(W(i,"-w","--web"))return n.debug?y("debug-traffic"):x;if(s&&W(i,"-c","--comments"))return y("view-comments");if(!pt(i,n).present)return y(n.debug?"debug-traffic":"view-human");return un(i,t,n,"json-composite")}function ee(e,r,t,n){let s=ve(e,ue[r]);if(W(s,"-h","--help"))return x;if(n.debug&&(W(s,"-w","--web")||!pt(s,n).present))return y("debug-traffic");if(W(s,"-w","--web"))return x;return un(s,t,n,"json-composite")}function Wo(e,r){let t=ve(e,ue["pr checks"]);if(W(t,"-h","--help"))return x;if(r.debug)return y("debug-traffic");if(W(t,"-w","--web"))return x;if(!pt(t,r).present)return y("checks-human");return un(t,Ro,r,"checks-json")}function No(e){let r=new Set(ue.group.values);for(let t=0;t<e.length;t++){let n=e[t].value;if(n==="--")return{sub:e[t+1],rest:e.slice(t+2)};if(!n.startsWith("-")||n==="-")return{sub:e[t],rest:[...e.slice(0,t),...e.slice(t+1)]};if(r.has(n))t++}return{rest:e}}function Do(e,r,t){let{sub:n,rest:s}=No(r);if(!n)return t.appendsArgs?y("unclassifiable"):x;if(n.opaque)return y("unclassifiable");let i=n.value;if((e==="pr"?$o:e==="issue"?Co:e==="release"?Po:e==="discussion"?Io:new Set).has(i))return t.debug?y("debug-traffic"):x;if(t.appendsArgs&&!(e==="project"&&i!=="item-list"))return y("unclassifiable");switch(e){case"pr":if(i==="view")return ft(s,"pr view",Qt,t,!0);if(i==="list"||i==="ls")return ee(s,"pr list",Qt,t);if(i==="status")return ee(s,"pr status",Qt,t);if(i==="checks")return Wo(s,t);if(i==="diff"){let a=ve(s,ue["pr diff"]);if(W(a,"-h","--help"))return x;if(t.debug)return y("debug-traffic");return W(a,"--patch")?y("composite-other"):x}return y("unclassifiable");case"issue":if(i==="view")return ft(s,"issue view",Jt,t,!0);if(i==="list"||i==="ls")return ee(s,"issue list",Jt,t);if(i==="status")return ee(s,"issue status",Jt,t);return y("unclassifiable");case"release":if(i==="view")return ft(s,"release view",vr,t,!1);if(i==="list"||i==="ls")return ee(s,"release list",vr,t);return y("unclassifiable");case"discussion":if(i==="view")return ft(s,"discussion view",_r,t,!0);if(i==="list"||i==="ls")return ee(s,"discussion list",_r,t);return y("unclassifiable");case"search":if(i==="prs"||i==="issues")return ee(s,"search",Eo,t);if(i==="commits")return ee(s,"search",Oo,t);if(i==="code"||i==="repos")return t.debug?y("debug-traffic"):x;return y("unclassifiable");case"project":{if(t.debug)return y("debug-traffic");if(i!=="item-list")return x;let a=ve(s,ue["project item-list"]);if(W(a,"-h","--help"))return x;let l=te(a,"--format");if(l.some((u)=>!u.value||u.value.opaque))return y("unclassifiable");if(l.every((u)=>u.value.value!=="json"))return x;return an(a)?x:y("composite-other")}}return y("unclassifiable")}var Ar=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function Lo(e){let r=e.value.trim(),t=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(r);if(t){let i=t[1].toLowerCase(),o=t[2]??"/";if(i==="api.github.com"||/^api\./.test(i))r=o;else if(/^\/api\/v3(?:\/|$)/i.test(o))r=o.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(o))r="graphql";else return null}r=r.replace(/[?#].*$/,"");let n=[],s=[];for(let i of r.split("/")){let o;try{o=decodeURIComponent(i)}catch{return null}for(let a of o.split("/")){if(a===""||a===".")continue;if(a===".."){n.pop(),s.pop();continue}n.push(a.toLowerCase()),s.push(e.opaque&&/[$`]/.test(a)||/[*?[]/.test(a)||Rr(a))}}return{segments:n,opaque:s}}function Ho(e){let r=Lo(e);if(!r)return{kind:"unclassifiable",segments:[]};let{segments:t,opaque:n}=r,s=(l)=>({kind:l,segments:t});if(t.length===1&&t[0]==="graphql")return s("graphql");if(t.length===0)return s(e.opaque?"unclassifiable":"other");if(n[0])return s("unclassifiable");let i,o=[];if(t[0]==="repos")i=t.slice(3),o=n.slice(3);else if(t[0]==="repositories")i=t.slice(2),o=n.slice(2);if(i){if((t[0]==="repos"?n.slice(1,3):n.slice(1,2)).some(Boolean)){let u=n.findIndex(Boolean),c=t.findIndex((f,d)=>d>u&&!n[d]&&Mo.has(f));return s(c<0?"unclassifiable":Er(t.slice(c),n.slice(c)))}return s(Er(i,o))}let a=t[0];if(a==="issues")return s("sensitive");if(a==="user"&&t[1]==="issues")return s("sensitive");if(a==="orgs"&&t[2]==="issues")return s("sensitive");if(a==="search")return s(t[1]==="issues"||t[1]==="commits"?"sensitive":t[1]!==void 0&&n[1]?"unclassifiable":"other");if(a==="events"||a==="networks")return s("sensitive");if((a==="users"||a==="orgs")&&t.slice(2).some((l)=>l==="events"||l==="received_events"||l==="discussions"))return s("sensitive");if((a==="users"||a==="orgs")&&t[2]==="projectsv2"&&t[4]==="items")return s("sensitive");if(a==="orgs"&&t[2]==="hooks"&&t[4]==="deliveries"&&t[5]!==void 0||a==="app"&&t[1]==="hook"&&t[2]==="deliveries"&&t[3]!==void 0)return s("sensitive");if(a==="teams"&&t.includes("discussions"))return s("sensitive");if(a==="projects"&&t.includes("cards"))return s("sensitive");if(n.some(Boolean))return s(t.some((l)=>l==="events"||l==="discussions"||l==="issues")?"sensitive":"unclassifiable");return s("other")}var Mo=new Set([...Ar,"branches","git","actions","hooks","zipball","tarball"]);function Er(e,r){let[t,n]=e;if(t===void 0)return"other";if(r[0])return"unclassifiable";if(t==="issues"&&/^\d+$/.test(n??"")&&e[2]==="labels")return"other";if(Ar.has(t))return"sensitive";if(t==="branches"){if(e.length===1||e.slice(1).some((s)=>s==="protection")||e[e.length-1]==="rename")return"other";return r.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if(t==="git")return n===void 0||n==="commits"||n==="tags"?"sensitive":r[1]?"unclassifiable":"other";if(t==="actions"){if(n===void 0)return"sensitive";if(r[1])return"unclassifiable";if(n==="runs"||n==="jobs"){if(e[e.length-1]==="logs"&&e.length>=4&&!r.some(Boolean))return"download";return"sensitive"}if(n==="workflows"&&e[3]==="runs")return"sensitive";if(n==="artifacts"&&e.length===4)return"download";return"other"}if(t==="hooks"&&e[2]==="deliveries"&&e[3]!==void 0)return"sensitive";if(t==="zipball"||t==="tarball")return"download";return"other"}function Fo(e,r){if(r[0]!=="repos"||r.length<5)return!1;let t=r.slice(3),n=(i)=>/^\d+$/.test(t[i]??""),s=(...i)=>t.length===i.length&&i.every((o,a)=>typeof o==="number"?n(a):t[a]===o);if(e==="DELETE")return s("issues","comments",0)||s("pulls","comments",0)||s("comments",0)||s("issues","comments",0,"reactions",0)||s("pulls","comments",0,"reactions",0)||s("issues",0,"reactions",0)||s("issues",0,"labels")||t.length===4&&t[0]==="issues"&&n(1)&&t[2]==="labels"||s("releases",0)||s("releases","assets",0)||s("actions","runs",0)||s("actions","runs",0,"logs")||s("deployments",0)||s("milestones",0)||s("issues",0,"lock");if(e==="POST")return t.length===4&&t[0]==="actions"&&t[1]==="runs"&&n(2)&&["rerun","rerun-failed-jobs","cancel","force-cancel","approve"].includes(t[3])||s("actions","jobs",0,"rerun")||s("issues",0,"labels");if(e==="PUT")return s("pulls",0,"merge")||s("pulls",0,"update-branch")||s("issues",0,"labels")||s("issues",0,"lock");if(e==="GET")return s("pulls",0,"merge");return!1}function Bo(e){if(e[0]!=="repos"||e.length!==5||!/^\d+$/.test(e[4]))return;if(e[3]==="pulls")return new Set(["commits","comments","review_comments"]);if(e[3]==="issues")return new Set(["comments"]);return}var jo=new Set(["body","bodyText","bodyHTML","bodyUrl","bodyResourcePath","comments","reviews","latestReviews","latestOpinionatedReviews","reviewThreads","url","permalink","summary","text","description","message","messageBody","messageHeadline","commitBody","commitHeadline","annotations","rawDetails","note","diff","readme","payload"]),Go=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function qo(e){let r=[],t=0;while(t<e.length){let n=e[t];if(/[\s,\uFEFF]/.test(n)){t++;continue}if(n==="#"){let o=e.indexOf(`
|
|
33
|
-
|
|
34
|
-
`)
|
|
35
|
-
`).replace(/%s/g,()=>
|
|
36
|
-
`,
|
|
37
|
-
`,
|
|
38
|
-
`,
|
|
2
|
+
import{homedir as M1}from"os";import{isAbsolute as E2}from"path";import{isAbsolute as E3,join as WZ,normalize as S3,resolve as f3,sep as v0}from"path";import{dirname as VZ,isAbsolute as aZ,join as _0,resolve as $Z}from"path";import{accessSync as h2,closeSync as w2,constants as nZ,fstatSync as g2,lstatSync as yZ,openSync as u2,readFileSync as l2,readlinkSync as m2,readSync as p2,realpathSync as I0,statSync as T0}from"fs";import{spawnSync as c2}from"child_process";var N1={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 RZ(Z){return Z===0||Z===process.getuid?.()}function oZ(Z,z=!1){let $=Z;for(let J=0;J<32;J++){if(!aZ($)||$.length>4096||!vZ("/"))return!1;let Y=$.split("/"),X=Y.pop();if(!X||X==="."||X==="..")return!1;let Q="/";for(let H of Y){if(!H||H===".")continue;if(H===".."){Q=VZ(Q);continue}let M=_0(Q,H),V=yZ(M);if(z&&M==="/bin"&&V.isSymbolicLink()&&V.uid===0){let G=I0(M);if(!vZ(G))return!1;Q=G;continue}if(!V.isDirectory()||!RZ(V.uid)||V.mode&18)return!1;Q=M}let B=_0(Q,X),K=yZ(B);if(!RZ(K.uid))return!1;if(K.isSymbolicLink()){let H=m2(B);$=aZ(H)?H:Q+"/"+H;continue}return K.isFile()&&Boolean(K.mode&73)&&!(K.mode&18)}return!1}function i2(Z){if(!aZ(Z)||$Z(Z)!==(Z.replace(/\/+$/,"")||"/"))return!1;for(let z=$Z(Z);;z=VZ(z)){try{return yZ(z),vZ(z)}catch($){if($.code!=="ENOENT")return!1}if(VZ(z)===z)return!1}}function d2(Z,z){let $=u2(Z,nZ.O_RDONLY|nZ.O_NONBLOCK|nZ.O_NOFOLLOW),J;try{if(!g2($).isFile())return!1;let X=Buffer.alloc(256),Q=p2($,X,0,X.length,0);J=X.subarray(0,Q).toString("utf8").split(`
|
|
3
|
+
`)[0]}finally{w2($)}let Y=/^#!(\/[A-Za-z0-9_./-]+)$/.exec(J);if(Y&&Y[1]!=="/usr/bin/env")return oZ(Y[1],!0);if(J!=="#!/usr/bin/env bun"||!oZ("/usr/bin/env",!0))return!1;for(let X of z.split(":").slice(0,64)){if(!i2(X))return!1;let Q=$Z(X,"bun");try{if(!T0(Q).isFile())continue;h2(Q,nZ.X_OK)}catch{continue}return oZ(Q,!0)}return!1}function vZ(Z){let z=Z;for(;;){let $=yZ(z);if(!$.isDirectory()||!RZ($.uid)||($.mode&18)!==0)return!1;let J=VZ(z);if(J===z)return!0;z=J}}function bZ(Z=process.env){let z=Z.PATH??"",$=Date.now()+2000,J="missing",Y=(X)=>{if(J==="missing"||J==="unrecognized_package"||X.startsWith("unsafe_"))J=X};for(let X of z.split(":").slice(0,64)){if(!aZ(X)||Date.now()>=$)continue;let Q=$Z(X,"trash");try{let B=T0(Q);if(!B.isFile()||!RZ(B.uid)||(B.mode&73)===0||(B.mode&18)!==0){Y("unsafe_executable");continue}let K=I0(Q);if(!vZ($Z(X))||!vZ(VZ(K))){Y("unsafe_directory");continue}if(!oZ(Q)){Y("unsafe_directory");continue}let H=$Z(VZ(K),"../.."),M=_0(H,"package.json"),V=T0(M);if(!V.isFile()||!RZ(V.uid)||V.size>16384||(V.mode&18)!==0||yZ(M).isSymbolicLink()){Y("unsafe_manifest");continue}let G=JSON.parse(l2(M,"utf8"));if(G.name!=="@hasna/trash"||typeof G.version!=="string"||typeof G.bin?.trash!=="string"||I0($Z(H,G.bin.trash))!==K){Y("unrecognized_package");continue}try{if(!d2(K,z)){Y("unsafe_interpreter");continue}}catch{Y("unsafe_interpreter");continue}let U=$-Date.now();if(U<=0){Y("identity_failed");break}let j=c2(Q,["--identity"],{encoding:"utf8",timeout:U,maxBuffer:2048,env:{PATH:z},stdio:["ignore","pipe","pipe"]});if(j.error||j.status!==0||Date.now()>=$){Y("identity_failed");continue}let F=JSON.parse(j.stdout);if(F.name==="@hasna/trash"&&F.version===G.version&&F.guardProtocol==="hasna.trash.guard.v1")return{ok:!0,path:Q,version:G.version};Y("unsupported_protocol")}catch{}}return{ok:!1,code:J}}function rZ(Z=process.env){let z=bZ(Z);return z.ok?z.path:null}function GZ(Z){let z=Z.tool_input?.command;return typeof z==="string"?z:""}var D1=["/","/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 SZ=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,c=(Z)=>Z.split("/").pop()??"";function tZ(Z){let z=Z.startsWith("~")?Z.slice(1).split("/",1)[0]:"";if(z&&!/['"\\]/.test(z))return!0;let $=null,J=0;for(let Y=0;Y<Z.length;Y++){let X=Z[Y];if($==="'"){if(X==="'")$=null;continue}if(X==="\\"){Y++;continue}if($==='"'){if(X==='"')$=null;continue}if(X==="'"||X==='"')$=X;else if(X==="$"&&Z[Y+1]==="{")J++,Y++;else if(X==="}"&&J>0)J--;else if(X==="{"||X==="}")return!0}return!1}var q0=64;function _1(Z,z){let $=0;for(let J=z;J<Z.length;J++)if(Z[J]==="\\")J++;else if(Z[J]==="{")$++;else if(Z[J]==="}"&&--$===0)return J;return Z.length-1}function s2(Z){let z=Z.match(/^([-+]?\d+)\.\.([-+]?\d+)(?:\.\.([-+]?\d+))?$/),$=z?null:Z.match(/^([A-Za-z])\.\.([A-Za-z])(?:\.\.([-+]?\d+))?$/),J=z??$;if(!J)return null;let Y=z?Number(J[1]):J[1].charCodeAt(0),X=z?Number(J[2]):J[2].charCodeAt(0),Q=Math.abs(Number(J[3]??1))||1;if(!Number.isSafeInteger(Y)||!Number.isSafeInteger(X)||!Number.isSafeInteger(Q))return"overflow";if(Math.floor(Math.abs(X-Y)/Q)+1>q0)return"overflow";let B=z&&(/^[-+]?0\d/.test(J[1])||/^[-+]?0\d/.test(J[2]))?Math.max(J[1].length,J[2].length):0,K=[];for(let H=Y;Y<=X?H<=X:H>=X;H+=Y<=X?Q:-Q)if(!z)K.push(String.fromCharCode(H));else K.push(H<0?`-${String(-H).padStart(B-1,"0")}`:String(H).padStart(B,"0"));return K}function n2(Z){let z=null,$=0;for(let J=0;J<Z.length;J++){let Y=Z[J];if(z==="'"){if(Y==="'")z=null;continue}if(Y==="\\"){J++;continue}if(z==='"'){if(Y==='"')z=null;continue}if(Y==="'"||Y==='"')z=Y;else if(Y==="$"&&Z[J+1]==="{")J=_1(Z,J+1);else if(Y==="{"){if(++$>q0)return"overflow";let X=null,Q=0,B=!0,K=[];for(let H=J;H<Z.length;H++){let M=Z[H];if(X==="'"){if(M==="'")X=null;continue}if(M==="\\"){B=!1,H++;continue}if(X==='"'){if(M==='"')X=null;continue}if(M==="'"||M==='"')X=M,B=!1;else if(M==="$"&&Z[H+1]==="{")H=_1(Z,H+1),B=!1;else if(M==="{")Q++;else if(M===","&&Q===1)K.push(H);else if(M==="}"&&--Q===0){if(K.length>0){let G=[J,...K,H];return{open:J,close:H,parts:G.slice(0,-1).map((U,j)=>Z.slice(U+1,G[j+1]))}}let V=B?s2(Z.slice(J+1,H)):null;if(V==="overflow")return V;if(V)return{open:J,close:H,parts:V};break}}}}return null}function JZ(Z){if(Z.length>4096&&Z.includes("{"))return null;let z=n2(Z);if(z===null)return[Z];if(z==="overflow")return null;let $=[];for(let J of z.parts){let Y=JZ(Z.slice(0,z.open)+J+Z.slice(z.close+1));if(Y===null||$.push(...Y)>q0)return null}return $}var W={arg:"none"},_={arg:"value"},EZ={arg:"optional"},s={arg:"none",effect:"lookup"},C={arg:"none",effect:"refuse"},o={help:C,version:C},o2=/^(?:\d+(?:\.\d*)?|\.\d+)[smhd]?$/,C0={timeout:{short:{k:_,s:_,v:W},long:{"kill-after":_,signal:_,verbose:W,foreground:W,"preserve-status":W,...o},positionals:[o2]},env:{short:{i:W,"0":W,v:W,u:_,a:_,C,S:C},long:{"ignore-environment":W,null:W,debug:W,unset:_,argv0:_,chdir:C,"split-string":C,"block-signal":EZ,"default-signal":EZ,"ignore-signal":EZ,"list-signal-handling":C,...o},env:!0},nice:{short:{n:_},long:{adjustment:_,...o},numericOption:!0},nohup:{short:{},long:{...o}},command:{short:{p:W,v:s,V:s},long:{}},exec:{short:{c:W,l:W,a:_},long:{}},builtin:{short:{},long:{}},stdbuf:{short:{i:_,o:_,e:_},long:{input:_,output:_,error:_,...o}},time:{short:{p:W,a:W,q:W,v:W,f:_,o:C,V:C},long:{portability:W,append:W,quiet:W,verbose:W,format:_,output:C,...o}},ionice:{short:{c:_,n:_,t:W,p:C,P:C,u:C,h:C,V:C},long:{class:_,classdata:_,ignore:W,pid:C,pgid:C,uid:C,...o}},setsid:{short:{c:W,f:W,w:W,h:C,V:C},long:{ctty:W,fork:W,wait:W,...o}}},a2=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]);function r2(Z,z,$){let J=!1,Y=(X)=>{if(!X||X.effect==="refuse")return!1;if(X.effect==="lookup")J=!0;return!0};while($<z.length){let X=z[$];if(X.opaque)return null;let Q=X.text;if(Q==="--"){$++;break}if(Q==="-"&&Z.env){$++;continue}if(!Q.startsWith("-")||Q==="-")break;if(Z.numericOption&&/^-[-+]?\d+$/.test(Q)){$++;continue}if(Q.startsWith("--")){let B=Q.indexOf("="),K=B<0?Q.slice(2):Q.slice(2,B),H=Object.keys(Z.long),M=H.includes(K)?[K]:H.filter((G)=>K&&G.startsWith(K));if(M.length!==1)return null;let V=Z.long[M[0]];if(!Y(V))return null;if(V.arg==="none"&&B>=0)return null;if(V.arg==="value"&&B<0){let G=z[++$];if(!G||G.opaque)return null}$++;continue}for(let B=1;B<Q.length;B++){let K=Z.short[Q[B]];if(!Y(K))return null;if(K.arg==="value"){if(B===Q.length-1){let H=z[++$];if(!H||H.opaque)return null}break}}$++}if(J)return-1;for(let X of Z.positionals??[]){let Q=z[$];if(!Q||Q.opaque||!X.test(Q.text))return null;$++}if(Z.env||Z.assignments){for(;$<z.length&&SZ.test(z[$].text);$++)if(z[$].opaque)return null}return $}function zZ(Z,z=C0){let $=0;while($<Z.length&&(SZ.test(Z[$].text)||a2.has(Z[$].text)))$++;for(let J=0;J<16;J++){if($>=Z.length)return{index:-1};if(Z[$].opaque)return J===0?{index:$}:null;let Y=Object.hasOwn(z,c(Z[$].text))?z[c(Z[$].text)]:void 0;if(!Y)return{index:$};let X=r2(Y,Z,$+1);if(X===null)return null;if(X<0)return{index:-1};$=X}return null}function t2(Z){return/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred|trash)(?![A-Za-z0-9_.-])/.test(Z)}var a={on:!1};function YZ(Z,z){if(!Z.includes("\\")||!Z.includes('"'))return;let $=a.on;a.on=!0;try{return z()}finally{a.on=$}}var L0=(Z)=>Z.split("/").pop()??"",O0={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}},C1=/^(python|perl|ruby|lua|php|node)[0-9.]+$/,e2=new Set(["awk","gawk","mawk","nawk","busybox-awk"]),Z3=new Set(["ssh","scp","sftp"]),$3=new Set("bcDEeFIiJLlmOoPpQRSWw".split("")),I1=new Set(["proxycommand","localcommand","knownhostscommand"]),J3=/(?:`|\$\()|\b(?:system|exec|execve|execvp|popen|spawn|posix_spawn|fork|subprocess|Popen|check_output|check_call|shell_exec|passthru|proc_open|pcntl_exec|qx|open|fopen|sysopen|unlink|remove|delete|rmtree|rmdir|mkdir|rename|truncate|ftruncate|chmod|chown|symlink|writeFile|createWriteStream|appendFile|child_process|FileUtils|shutil|Kernel|require|import|load|eval|os|sys|io|fs|File|IO|Dir|Path|pathlib|Deno|Bun)|%x\W/,z3=/system|getline|close|fflush|@(?![@/])/;function Y3(Z){if(z3.test(Z))return!1;if(!/[|>]/.test(Z))return!0;if(/\\\r?\n/.test(Z))return!1;let z=Z.search(/print/);return z<0||!/[|>]/.test(Z.slice(z))}var X3=/\.\s*(?!(?:argv|std(?:in|out|err)|exit|write|loads?|dumps?|strip|split(?:lines)?|join|replace|(?:start|end)swith|lower|find|count|get|items|keys|values|append|sort|read)\b)[a-zA-Z_]/,Q3=/(?<![\w.])(?:breakpoint|case|compile|\w*attr|eval|exec|globals|help|locals|type|vars)\b|(?<!\w)_/;function P1(Z){return Z.replace(/#.*|\\[^]|([rRbBuUfFtT]{0,2})("""|'''|(["'])(?!\3\3))((?:\\[^]|(?!\2)[^\\])*)\2|\w+/g,(z,$,J,Y,X)=>{if(!J)return z[0]==="#"?"":z;if(!/[ft]/i.test($))return/^[rbt]+$/.test(X)?"~":"%";let Q="",B=X.replace(/\{\{|\}\}|\{([^{}#]*)\}/g,(K,H="")=>(Q+=`${P1(H)},`,""));return/[{}]/.test(B)?"'":`(${Q})`})}function K3(Z){if(Z.length>8192||/`|\$\(/.test(Z))return!1;let z=P1(Z);if(/['"\\]|[^\0-\x7f]/.test(z)||Q3.test(z))return!1;if(/\b(?:import|from)\b/.test(z.replace(/\bimport\s+(?:json|sys)(?:\s*,\s*(?:json|sys))*(?=\s*(?:;|$))/gm,"")))return!1;if(/\bopen\b/.test(z.replace(/\bopen\([\w.[\]%]+(?:,\s*(?:mode=)?~)?(?:,\s*encoding=%)?\)/g,"")))return!1;return!X3.test(z)}function O1(Z){if(t2(Z.text))return!1;if(Z.kind==="awk")return Y3(Z.text);if(Z.kind==="c-interp")return Z.language==="python"?K3(Z.text):!J3.test(Z.text);return!1}function B3(Z,z,$,J){let Y=O0[Z]??(C1.test(Z)?O0[Z.replace(/[0-9.]+$/,"")]:void 0);if(!Y)return null;let X=(H)=>Z.startsWith("python3")?{text:H,kind:"c-interp",language:"python"}:{text:H,kind:"c-interp"},Q=[],B=!1,K=(H)=>{if(H+1>=z.length||J(H+1))return B=!0,H;return Q.push(X(z[H+1])),H+1};for(let H=$+1;H<z.length;H++){let M=z[H];if(M==="--")break;if(!M.startsWith("-")||M==="-")break;if(M.startsWith("--")){let G=M.indexOf("="),U=G<0?M:M.slice(0,G);if(Y.long.has(U))if(G>=0)Q.push(X(M.slice(G+1)));else H=K(H);continue}let V=M.slice(1);for(let G=0;G<V.length;G++){if(!Y.letters.has(V[G]))continue;if(G<V.length-1)Q.push(X(V.slice(G+1)));else H=K(H);break}}if(Q.length===0&&!B)return null;return{programs:Q,unresolved:B}}function H3(Z,z,$){let J=z+1;for(;J<Z.length&&Z[J].startsWith("-");J++)if(Z[J]==="-L"||Z[J]==="--log-level")J++;if(Z[J]!=="eval"||$(J))return null;let Y=[],X=!1;for(J++;J<Z.length;J++){if($(J)){X=!0;continue}if(!Z[J].startsWith("-"))Y.push({text:Z[J],kind:"c-interp"})}return Y.length===0&&!X?null:{programs:Y,unresolved:X}}function M3(Z,z,$){let J=[],Y=!1,X=z+1;for(;X<Z.length;X++){let Q=Z[X];if(Q==="--"){X++;break}if(!Q.startsWith("-")||Q==="-")break;if(Q==="-e"||Q.startsWith("-e")){let B=Q==="-e"?null:Q.slice(2);if(B!==null)J.push({text:B,kind:"awk"});else if(X+1<Z.length&&!$(X+1))J.push({text:Z[++X],kind:"awk"});else Y=!0}else if(Q==="-f"||Q.startsWith("-f")){if(Y=!0,Q==="-f")X++}else if(Q==="-v"||Q.startsWith("-v")){if(Q==="-v")X++}}if(J.length===0&&!Y){if(X<Z.length)if($(X))Y=!0;else J.push({text:Z[X],kind:"awk"})}return{programs:J,unresolved:Y}}function V3(Z,z,$){let J=Z[z],Y,X=z;if(J==="-o"){if(z+1>=Z.length)return{value:null,next:z};if($(z+1))return{value:null,next:z+1};Y=Z[z+1],X=z+1}else Y=J.slice(2);return{value:Y,next:X}}function G3(Z,z,$){let J=[],Y=!1;for(let X=z+1;X<Z.length;X++){let Q=Z[X];if(Q==="--")break;if(!Q.startsWith("-")||Q==="-")break;if(Q.startsWith("--"))continue;if(Q==="-o"||Q.startsWith("-o")){let{value:K,next:H}=V3(Z,X,$);if(X=H,K===null){Y=!0;continue}let M=K.indexOf("="),V=M>=0?M:K.search(/\s/),G=(V>=0?K.slice(0,V):K).trim().toLowerCase(),U=V>=0?K.slice(V+1).trim():"";if(I1.has(G))J.push({text:U,kind:"shell"});continue}if(Q==="-F"||Q.startsWith("-F")){if(Y=!0,Q==="-F")X++;continue}if(Q==="-S"||Q.startsWith("-S")){let K=Q==="-S"?X+1<Z.length&&!$(X+1)?Z[++X]:null:Q.slice(2);if(K===null)Y=!0;else J.push({text:K,kind:"shell"});continue}let B=Q.slice(1);for(let K=0;K<B.length;K++){if(!$3.has(B[K]))continue;if(K<B.length-1)break;if(B[K]==="o"||B[K]==="F"||B[K]==="S"){if(X+1<Z.length){let H=Z[X+1];if(B[K]==="o")if(!$(X+1)){let M=H.indexOf("="),V=M>=0?M:H.search(/\s/),G=(V>=0?H.slice(0,V):H).trim().toLowerCase();if(I1.has(G))J.push({text:V>=0?H.slice(V+1).trim():"",kind:"shell"})}else Y=!0;else if(B[K]==="F")Y=!0;else if(!$(X+1))J.push({text:H,kind:"shell"});X++}}else if(X+1<Z.length)X++}}return{programs:J,unresolved:Y}}function U3(Z,z,$){let J=[],Y=!1,X=!1;for(let Q=z+1;Q<Z.length;Q++){let B=Z[Q];if(B==="--")break;if(B==="-e"||B==="--rsh")if(X=!0,Q+1<Z.length&&!$(Q+1))J.push({text:Z[++Q],kind:"shell"});else Y=!0;else if(B.startsWith("--rsh="))X=!0,J.push({text:B.slice(6),kind:"shell"});else if(/^-[A-Za-z]*e/.test(B)&&B.length>2&&!B.startsWith("--"))X=!0,J.push({text:B.slice(B.indexOf("e")+1),kind:"shell"})}return X?{programs:J,unresolved:Y}:null}var j3=/^(?: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 L1(Z,z){let $=Z.toLowerCase(),J=(Y)=>Y===void 0?{kind:"unresolved"}:{kind:"command",text:Y};if(/^alias\./.test($))return z!==void 0&&z.trimStart().startsWith("!")?J(z.trimStart().slice(1)):{kind:"unresolved"};if(/^pager\./.test($)||$==="core.fsmonitor")return z!==void 0&&j3.test(z)?{kind:"harmless"}:J(z);if($==="core.gitproxy")return z!==void 0&&/^none(?:\s+for\s+\S+)?$/.test(z)?{kind:"harmless"}:J(z?.replace(/\s+for\s+\S+$/,""));if(/^submodule\..+\.update$/.test($))return z!==void 0&&z.trimStart().startsWith("!")?J(z.trimStart().slice(1)):z===void 0?{kind:"unresolved"}:{kind:"harmless"};if(/^sendemail\.(?:.+\.)?smtpserver$/.test($))return z!==void 0&&!z.startsWith("/")?{kind:"harmless"}:J(z);if(/^credential\.(?:.+\.)?helper$/.test($)){if(z==="")return{kind:"harmless"};if(z===void 0)return{kind:"unresolved"};let Y=z.trimStart();return J(Y.startsWith("!")?Y.slice(1):Y.startsWith("/")?Y:`git credential-${Y}`)}if(W3.some((Y)=>Y.test($)))return J(z);if($==="core.hookspath")return z==="/dev/null"?{kind:"harmless"}:{kind:"unresolved"};if($==="include.path"||/^includeif\..+\.path$/.test($))return{kind:"unresolved"};if($==="protocol.allow")return z!==void 0&&/^(?:never|user)$/i.test(z)?{kind:"harmless"}:{kind:"unresolved"};if($==="protocol.ext.allow")return z!==void 0&&/^never$/i.test(z)?{kind:"harmless"}:{kind:"unresolved"};return{kind:"harmless"}}function T1(Z){return/[$\x60]/.test(Z)||["","x","/x","!x"].some((z)=>L1(Z,z).kind!=="harmless")}var F3=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"]),N3=new Set(["GIT_EXEC_PATH","GIT_TEMPLATE_DIR","GIT_CONFIG_GLOBAL","GIT_CONFIG_SYSTEM"]);function D3(Z){let z=/'((?:[^']|'\\'')*)'/y,$=(X)=>X.replace(/'\\''/g,"'"),J=[],Y=0;while(Y<Z.length){if(/\s/.test(Z[Y])){Y++;continue}z.lastIndex=Y;let X=z.exec(Z);if(!X)return null;if(Y=z.lastIndex,Z[Y]==="="){z.lastIndex=Y+1;let Q=z.exec(Z);if(!Q)return null;Y=z.lastIndex,J.push([$(X[1]),$(Q[1])])}else{let Q=$(X[1]),B=Q.indexOf("=");J.push(B<0?[Q,void 0]:[Q.slice(0,B),Q.slice(B+1)])}}return J}function _3(Z,z,$){let J=[],Y=!1,X=(H,M,V=!0)=>{if(!V||/[$\x60]/.test(H)){Y=!0;return}let G=L1(H,M);if(G.kind==="unresolved")Y=!0;else if(G.kind==="command")J.push({text:G.text,kind:"shell"})},Q=(H,M)=>{let V=H.indexOf("="),G=V<0?H:H.slice(0,V),U=V<0?"true":H.slice(V+1);if(!M)return X(G,U);if(T1(G))Y=!0},B=new Set(["-C","--git-dir","--work-tree","--namespace","--attr-source","--list-cmds","--super-prefix"]);for(let H=z+1;H<Z.length;H++){let M=Z[H];if(!M.startsWith("-")||M==="-")break;if(M==="--")break;if(M==="-c"){if(H+1>=Z.length)break;Q(Z[H+1],$(H+1)),H++}else if(M.startsWith("-c")&&!M.startsWith("--"))Q(M.slice(2),$(H));else if(M==="--config-env"||M.startsWith("--config-env=")){let V=M==="--config-env"?Z[++H]??"":M.slice(13),G=V.indexOf("="),U=G<0?V:V.slice(0,G);if($(H)||T1(U))Y=!0}else if(M.startsWith("--exec-path="))Y=!0;else if(B.has(M))H++}let K=new Map;for(let H=0;H<z;H++){let M=Z[H].match(/^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/s);if(!M)continue;let[,V,G]=M,U=$(H);if(F3.has(V))if(U)Y=!0;else J.push({text:G,kind:"shell"});else if(N3.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:D3(G);if(j===null)Y=!0;else for(let[F,L]of j)X(F,L??"true")}else if(/^GIT_CONFIG_(?:KEY|VALUE)_\d+$/.test(V)){let j=V.replace(/^GIT_CONFIG_(?:KEY|VALUE)_/,""),F=K.get(j)??{};if(V.startsWith("GIT_CONFIG_KEY_"))F.key=G;else F.value=G;if(U)F.opaque=!0;K.set(j,F)}}for(let H of K.values()){if(H.key===void 0)continue;if(H.opaque)Q(`${H.key}=`,!0);else X(H.key,H.value)}if(J.length===0&&!Y)return null;return{programs:J,unresolved:Y}}function fZ(Z){if(/^~/.test(Z))return null;let z="";for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return null;z+=Z.slice($+1,Y),$=Y}else if(J==="$"||J==="`")return null;else if(J==='"'){let Y=$+1;for(;Y<Z.length&&Z[Y]!=='"';Y++){let X=Z[Y];if(X==="$"||X==="`")return null;if(X==="\\"&&Y+1<Z.length&&/[$\x60"\\\n]/.test(Z[Y+1])){if(Z[++Y]!==`
|
|
4
|
+
`||a.on)z+=Z[Y];continue}z+=X}if(Y>=Z.length)return null;$=Y}else if(J==="\\"){if($+1>=Z.length)return null;z+=Z[++$]}else if("*?[{}".includes(J))return null;else z+=J}return z}function q1(Z){let z=null;for(let $=0;$<Z.length;$++){let J=Z[$];if(z==="'"){if(J==="'")z=null;continue}if(J==="\\"){$++;continue}if(J==="$"||J==="`")return!1;if(z==='"'){if(J==='"')z=null;continue}if(J==="'"||J==='"'){z=J;continue}if(J==="<"&&Z[$+1]==="<"&&Z[$+2]!=="<")return!1}return z===null}var I3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]),T3=new Set(["--rcfile","--init-file"]),UZ=(Z)=>Z.replace(/\$'(?:[^'\\]|\\[\s\S])*'/g,(z)=>z.replace(/\\[\s\S]/g,($)=>$==="\\'"?"\\x27":$));function xZ(Z,z,$=fZ){if(z<0||z>=Z.length)return null;let J=L0($(Z[z])??"");if(J==="eval"){let B=z+1;if(fZ(Z[B]??"")==="--")B++;let K=Z.slice(B);if(K.length===0)return null;if(K.length>1)return{program:null,literal:!1};let H=fZ(K[0]);return H!==null&&q1(H)?{program:H,literal:!0}:{program:H,literal:!1}}if(!I3.has(J))return null;let Y=!1,X=z+1;for(;X<Z.length;X++){let B=fZ(Z[X]);if(B===null){if(Y)break;return/^"[^"]*"$/.test(Z[X])?null:{program:null,literal:!1}}if(B==="--"){X++;break}if(!/^[-+]./.test(B))break;if(B.startsWith("--")){if(T3.has(B))X++;continue}let K=B.slice(1);if(B[0]==="-"&&K.includes("c"))Y=!0;if(/[oO]/.test(K))X++}if(!Y||X>=Z.length)return null;let Q=fZ(Z[X]);return Q!==null&&q1(Q)?{program:Q,literal:!0}:{program:Q,literal:!1}}function q3(Z,z,$){let J=C3(Z,z,$);if(J===null)return{programs:[],unresolved:!0};let Y=new Set;for(let{scripts:X,mayFail:Q}of J){let B=P3(X.join(`
|
|
5
|
+
`));if(B===null){if(Q)continue;return{programs:[],unresolved:!0}}if(B.executes)return{programs:X.map((K)=>({text:K,kind:"shell"})),unresolved:!0};for(let K of B.writes)Y.add(K)}if(Y.size===0)return null;return{programs:[],unresolved:!1,writes:[...Y]}}var P0="quiet silent debug follow-symlinks posix regexp-extended separate sandbox unbuffered null-data zero-terminated binary help version in-place file expression line-length".split(" ");function C3(Z,z,$){let J=[],Y=[],X=!1,Q=-1,B=!1,K=!1;for(let V=z+1;V<Z.length;V++){let G=Z[V];if(K||!/^-./.test(G)){Y.push(V);continue}if($(V))return null;if(G==="--"){K=!0;continue}let U,j;if(G[1]==="-"){let F=G.indexOf("="),L=(F<0?G:G.slice(0,F)).slice(2),y=P0.filter((l)=>l.startsWith(L)),E=P0.includes(L)?L:y.length===1?y[0]:"";if(P0.indexOf(E)<15){if(!E)return null;continue}if(U=E[0],F>=0)j=G.slice(F+1)}else{let F=1;while("nrEsuzb".includes(G[F]??"_"))F++;if(U=G[F]??"",U==="i"||U==="I"){let L=F===G.length-1&&V+1<Z.length&&!$(V+1)?Z[V+1]:void 0;if(U==="I"){if(B=X=!0,F===G.length-1){if(L===void 0)return null;Q=V+1}}else if(L===""||L?.startsWith("."))X=!0,Q=V+1;continue}if(U==="")continue;if(!"efl".includes(U))return null;j=G.slice(F+1)||void 0}if(U==="f")return null;if(j===void 0){if(j=Z[++V],j===void 0||$(V))return null}if(U==="e")J.push(j)}let H=(V)=>{if(J.length>0)return J;let G=Y.find((U)=>U!==V);return G===void 0?[]:$(G)?null:[Z[G]]},M=[];if(!B)M.push({scripts:H(-1),mayFail:Q>=0&&J.length===0&&Y[0]===Q});if(X)M.push({scripts:H(Q),mayFail:!1});return M.some((V)=>V.scripts===null)?null:M}function P3(Z){let z=[],$=!1,J=0,Y=Z.length,X=()=>Z[J]??"",Q=()=>{while(X()===" "||X()==="\t")J++;let H=J,M=Z.indexOf(`
|
|
6
|
+
`,J);return J=M<0?Y:M,Z.slice(H,J)},B=()=>{let H=Q();if(H&&!/^\/dev\/std(?:out|err)$/.test(H))z.push(H)},K=(H,M)=>{for(;J<Y;J++){let V=Z[J];if(V===`
|
|
7
|
+
`)return!1;if(V==="\\"){if(++J>=Y)return!1}else if(V===H)return J++,!0;else if(M&&V==="["){let G=J+1;if(Z[G]==="^")G++;if(Z[G]==="]")G++;for(;Z[G]!=="]";G++){if(G>=Y||Z[G]===`
|
|
8
|
+
`)return!1;if(Z[G]==="["&&":.=".includes(Z[G+1]||`
|
|
9
|
+
`)){let U=Z.indexOf(Z[G+1]+"]",G+2);if(U<0||Z.slice(G,U).includes(`
|
|
10
|
+
`))return!1;G=U+1}}J=G}}return!1};while(J<Y){let H=Z[J++];if(H==="/"||H==="\\"){let M=H==="\\"?Z[J++]??"":"/";if(!M||M===`
|
|
11
|
+
`||!K(M,!0))return null}else if(H==="#")Q();else if(":btTv".includes(H)){while(X()===" "||X()==="\t")J++;while(J<Y&&!/[\s;]/.test(X()))J++}else if("aic".includes(H)){while(X()===" "||X()==="\t")J++;if(X()==="\\")J+=2;for(;J<Y&&Z[J]!==`
|
|
12
|
+
`;J++)if(Z[J]==="\\")J++}else if(H==="e")$=!0,Q();else if(H==="r"||H==="R")Q();else if(H==="w"||H==="W")B();else if(H==="s"||H==="y"){let M=Z[J++]??"";if(!M||M===`
|
|
13
|
+
`||M==="\\"||!K(M,H==="s")||!K(M,!1))return null;for(;H==="s"&&" \tgpiImMe0123456789w".includes(X()||"_");J++){if(X()==="e")$=!0;if(X()==="w"){J++,B();break}}}}return{writes:z,executes:$}}var O3=new Set(["-exec","-execdir","-ok","-okdir"]),L3=new Set(["-exec","-execdir"]),A3=new Set("0oprtx"),y3=new Set("adEILnPsJRS"),R3=new Set("eil"),eZ={"--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 v3(Z){if(Object.hasOwn(eZ,Z))return eZ[Z];let z=Object.keys(eZ).filter(($)=>$.startsWith(Z));return z.length===1?eZ[z[0]]:null}function kZ(Z,z,$,J=0){while(z<Z.length){if($(z)){z++;continue}let Y=Z[z];if(Y==="--"){z++;break}if(!Y.startsWith("-")||Y==="-")break;if(Y.startsWith("--")){let B=Y.indexOf("="),K=v3(B<0?Y:Y.slice(0,B));if(K===null){if(J>=4)return[];return[...kZ(Z,z+1,$,J+1),...kZ(Z,z+2,$,J+1)]}z+=K==="value"&&B<0?2:1;continue}let X=!1,Q=!1;for(let B=1;B<Y.length;B++){let K=Y[B];if(A3.has(K))continue;if(R3.has(K))break;if(y3.has(K)){X=B===Y.length-1;break}Q=!0;break}if(Q){if(J>=4)return[];return[...kZ(Z,z+1,$,J+1),...kZ(Z,z+2,$,J+1)]}z+=X?2:1}while(z<Z.length&&$(z))z++;return z<Z.length?[z]:[]}function hZ(Z,z,$=()=>!1){if(z<0||z>=Z.length)return[];let J=L0(Z[z]);if(J==="xargs")return[...new Set(kZ(Z,z+1,$))].map((X)=>({start:X,end:Z.length}));if(J!=="find")return[];let Y=[];for(let X=z+1;X<Z.length;X++){if($(X)||!O3.has(Z[X]))continue;let Q=X+1,B=Q;for(;B<Z.length;B++){if($(B))continue;if(Z[B]===";")break;if(Z[B]==="+"&&B>Q&&Z[B-1]==="{}"&&L3.has(Z[X]))break}if(Q<B)Y.push({start:Q,end:B});X=B}return Y}function wZ(Z,z,$){if(z<0||z>=Z.length)return null;let J=L0(Z[z]);if(J==="deno"){let Y=H3(Z,z,$);if(Y)return Y}if(Object.hasOwn(O0,J)||C1.test(J))return B3(J,Z,z,$);if(e2.has(J))return M3(Z,z,$);if(Z3.has(J))return G3(Z,z,$);if(J==="rsync")return U3(Z,z,$);if(J==="git")return _3(Z,z,$);if(J==="sed")return q3(Z,z,$);return null}var k3=600000,x3="Delete via trash guard (rm intercepted and made recoverable)",h3=[".hasna/repos/clones","workspace/repos"],w3=[".hasna",".ssh",".aws"],A0={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."},g3=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env"]),u3={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"]},l3={timeout:1},m3={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:s,l:s,v:s,D:C,R:C,h:C,K:C,V:C},long:{askpass:W,bell:W,background:W,"close-from":_,chdir:C,"preserve-env":EZ,edit:s,group:_,"set-home":W,help:C,host:C,login:W,"remove-timestamp":C,"reset-timestamp":W,list:s,"no-update":W,"non-interactive":W,"preserve-groups":W,prompt:_,chroot:C,role:_,stdin:W,shell:W,type:_,"command-timeout":_,"other-user":_,user:_,version:C,validate:s},assignments:!0},doas:{short:{n:W,s:W,u:_,C,L:C},long:{}},flock:{short:{s:W,x:W,e:W,n:W,u:W,o:W,F:W,w:_,E:_,h:C,V:C},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:C,version:C},positionals:[/^[\s\S]+$/]}},p3={...C0,...m3},x1=new Set(["-c","--command"]),c3=new Set(["busybox","toybox"]),b0=new Set(["rm","rmdir","unlink","shred"]),i3=new Set(["!","{","}","then","do","else","elif","if","while","until","for","case","esac","fi","done","select","function"]),d3=new Set(["-C","-c","--git-dir","--work-tree","--namespace","--exec-path","--config-env"]),s3=/(^|[^A-Za-z0-9_.-])(rm|rmdir|unlink|shred)(?![A-Za-z0-9_.-])/;function i(Z){return s3.test(R(Z))}function uZ(Z){return Z.map((z)=>z.replace(/^-[iv0]*S|^--split-string=/," ")).join(" ")}var h1=/^[A-Za-z_][A-Za-z0-9_]*=/;function $0(Z){let z=Z.lastIndexOf("/");return z>=0?Z.slice(z+1):Z}var A1={a:"\x07",b:"\b",e:"\x1B",E:"\x1B",f:"\f",n:`
|
|
14
|
+
`,r:"\r",t:"\t",v:"\v","\\":"\\","'":"'",'"':'"',"?":"?"};function n3(Z,z){let $="",J=z;while(J<Z.length&&Z[J]!=="'"){if(Z[J]!=="\\"||J+1>=Z.length){$+=Z[J++];continue}let Y=Z[J+1],X=Z.slice(J+1),Q;if(Object.hasOwn(A1,Y))$+=A1[Y],J+=2;else if(Q=X.match(/^[0-7]{1,3}/))$+=String.fromCharCode(parseInt(Q[0],8)&255),J+=1+Q[0].length;else if((Q=X.match(/^x([0-9A-Fa-f]{1,2})/))||(Q=X.match(/^u([0-9A-Fa-f]{1,4})/))||(Q=X.match(/^U([0-9A-Fa-f]{1,8})/))){let B=parseInt(Q[1],16);$+=B<=1114111?String.fromCodePoint(B):"",J+=1+Q[0].length}else if(Y==="c"&&J+2<Z.length)$+=String.fromCharCode(Z.charCodeAt(J+2)&31),J+=3;else $+=`\\${Y}`,J+=2}return{text:$,end:Math.min(J+1,Z.length)}}function v(Z){return w1(Z,!0)}function w1(Z,z){let $="",J=0;while(J<Z.length){let Y=Z[J];if(z&&Y==="$"&&Z[J+1]==="'"){let X=n3(Z,J+2);$+=X.text,J=X.end;continue}if(z&&Y==="$"&&Z[J+1]==='"'){J++;continue}if(Y==="\\"){if(J+1<Z.length)$+=Z[J+1];J+=2;continue}if(Y==="'"){let X=Z.indexOf("'",J+1);if(X===-1){$+=Z.slice(J+1);break}$+=Z.slice(J+1,X),J=X+1;continue}if(Y==='"'){J++;while(J<Z.length&&Z[J]!=='"'){if(Z[J]==="\\"&&J+1<Z.length){let X=Z[J+1];$+=a.on||/[$`"\\]/.test(X)?X:X===`
|
|
15
|
+
`?"":`\\${X}`,J+=2;continue}$+=Z[J],J++}J++;continue}$+=Y,J++}return $}function J0(Z){if(tZ(Z))return!0;let z=null;for(let $=0;$<Z.length;$++){let J=Z[$];if(z==="'"){if(J==="'")z=null;continue}if(J==="\\"){$++;continue}if(J==="`"||J==="$")return!0;if(J==='"'){z=z===null?'"':null;continue}if(z!==null)continue;if(J==="'")z="'";else if(J==="*"||J==="?")return!0;else if(J==="["&&o3(Z,$+1,"]"))return!0}return!1}function o3(Z,z,$){let J=null;for(let Y=z;Y<Z.length;Y++){let X=Z[Y];if(J!=="'"&&X==="\\")Y++;else if(J===null&&X===$)return!0;else if(X==="'"&&J!=='"')J=J==="'"?null:"'";else if(X==='"'&&J!=="'")J=J==='"'?null:'"'}return!1}function a3(Z){if(!J0(Z))return!1;let z=JZ(Z);return z===null||z.some(($)=>v($).split(/[^A-Za-z0-9_]+/).some((J)=>b0.has(J)))}function FZ(Z){return $0(v(Z))}var g1={deep:!0};function E0(Z,z){return Z.replace(/\\([$`\\"])/g,($,J)=>J==='"'&&!z?$:J)}function r3(Z,z,$){let J=[],Y=z+1;while(Y<$-1){let X=Z[Y];if(X==="\\"){Y+=2;continue}if(X==="`"){let Q=lZ(Z,Y);if(Q<0)return null;J.push(E0(Z.slice(Y+1,Q-1),!0)),Y=Q;continue}if(X==="$"&&Z[Y+1]==="("){let Q=XZ(Z,Y+1);if(Q<0)return null;J.push(Z.slice(Y+2,Q-1)),Y=Q;continue}Y++}return J}function t3(Z){let z=[],$=0;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==="`"){let Y=lZ(Z,$);if(Y<0)return null;z.push(E0(Z.slice($+1,Y-1),!1)),$=Y;continue}if(J==="$"&&Z[$+1]==="("){let Y=XZ(Z,$+1);if(Y<0)return null;z.push(Z.slice($+2,Y-1)),$=Y;continue}$++}return z}function y1(Z,z,$,J){let Y=z+1;for(let X of $){let Q=Math.min(Y,Z.length);for(;;){if(Y>Z.length){Y=Z.length+1;break}let K=Z.indexOf(`
|
|
16
|
+
`,Y),H=K===-1?Z.length:K,M=Z.slice(Y,H).replace(/\r$/,"");if(X.stripTabs)M=M.replace(/^\t+/,"");if(M===X.delimiter)break;Y=H+1}let B=Z.slice(Q,Math.min(Y,Z.length));if(X.owner.push(B),!X.quoted){let K=t3(B);if(!K)return-1;J.push(...K)}if(Y<=Z.length){let K=Z.indexOf(`
|
|
17
|
+
`,Y);Y=(K===-1?Z.length:K)+1}}return Math.min(Y-1,Z.length)}function u1(Z,z){let $=Z.indexOf("'",z+1);return $===-1?-1:$+1}function lZ(Z,z){let $=z+1;while($<Z.length){if(Z[$]==="\\"){$+=2;continue}if(Z[$]==="`")return $+1;$++}return-1}function l1(Z,z){let $=z+1;while($<Z.length){let J=Z[$];if(J==="\\"){$+=2;continue}if(J==='"')return $+1;if(J==="`"){let Y=lZ(Z,$);if(Y<0)return-1;$=Y;continue}if(J==="$"&&Z[$+1]==="("){let Y=XZ(Z,$+1);if(Y<0)return-1;$=Y;continue}$++}return-1}function DZ(Z,z){if(Z[z]!=="<"||Z[z+1]!=="<"||Z[z+2]==="<")return null;let $=z+2,J=Z[$]==="-";if(J)$++;while(Z[$]===" "||Z[$]==="\t")$++;let Y="",X=!1;while($<Z.length&&!/[\s;|&<>()]/.test(Z[$])){let Q=Z[$];if(Q==="'"||Q==='"'){let B=Z.indexOf(Q,$+1);if(B<0)return null;Y+=Z.slice($+1,B),X=!0,$=B+1;continue}if(Q==="\\"){if($+1>=Z.length)return null;Y+=Z[$+1],X=!0,$+=2;continue}Y+=Q,$++}return Y?{delimiter:Y,stripTabs:J,quoted:X,end:$}:null}function z0(Z,z,$){let J=z+1;for(let Y of $)for(;;){if(J>Z.length)return-1;let X=Z.indexOf(`
|
|
18
|
+
`,J),Q=X===-1?Z.length:X,B=Z.slice(J,Q);if(B.endsWith("\r"))B=B.slice(0,-1);let K=Y.stripTabs?B.length-B.replace(/^\t+/,"").length:0;if(Y.stripTabs)B=B.slice(K);if(B===Y.delimiter){J=Q+1;break}if(B.startsWith(Y.delimiter)&&/^\s*\)/.test(B.slice(Y.delimiter.length))){if(Y===$[$.length-1])return J+K+Y.delimiter.length;return-1}if(X===-1)return-1;J=X+1}return J-1}function XZ(Z,z){let $=Z.length,J=Z[z+1]==="(",Y=0,X=z,Q=[];while(X<$){let B=Z[X];if(B==="\\"){X+=2;continue}if(B==="'"){let K=u1(Z,X);if(K<0)return-1;X=K;continue}if(B==='"'){let K=l1(Z,X);if(K<0)return-1;X=K;continue}if(B==="`"){let K=lZ(Z,X);if(K<0)return-1;X=K;continue}if(!J&&B==="<"&&Z[X+1]==="<"){if(Z[X+2]==="<"){X+=3;continue}let K=DZ(Z,X);if(!K)return-1;Q.push(K),X=K.end;continue}if(B===`
|
|
19
|
+
`&&Q.length>0){let K=z0(Z,X,Q);if(K<0)return-1;Q=[],X=K;continue}if(!J&&B==="#"&&/[\s;&|(]/.test(Z[X-1])){let K=Z.indexOf(`
|
|
20
|
+
`,X);if(K<0)return-1;X=K;continue}if(B==="(")Y++;else if(B===")"){if(Y--,Y===0)return Q.length>0?-1:X+1}X++}return-1}function b(Z,z={}){let $=z.deep===!0,J=[],Y=[],X=[],Q=new Set,B=[],K=[],H=-1,M=!1,V=!0,G=0,U=Z.length,j=(q)=>{if(H>=0){let N=X.length;if(X.push({text:Z.slice(H,q),start:H,end:q}),M)Q.add(N);H=-1,M=!1}},F=(q)=>{if(j(q),X.length>0)J.push($?{words:X,redirects:Q,heredocs:B}:{words:X,redirects:Q});if(X=[],Q=new Set,$)B=[];M=!1},L=(q)=>u1(Z,q),y=(q)=>lZ(Z,q),E=(q)=>XZ(Z,q),l=(q)=>l1(Z,q);while(G<U){let q=Z[G];if(q===" "||q==="\t"||q==="\r"){j(G),G++;continue}if(q===`
|
|
21
|
+
`){if(F(G),K.length>0){let N=y1(Z,G,K,Y);if(K=[],N<0)V=!1,G=U;else G=N;continue}G++;continue}if(q===";"){F(G),G++;continue}if(q==="&"){F(G),G+=Z[G+1]==="&"?2:1;continue}if(q==="|"){F(G),G+=Z[G+1]==="|"?2:1;continue}if($&&q==="("&&H>=0&&"?*+@!".includes(Z[G-1])){V=!1,G=U;continue}if(q==="("||q===")"){F(G),G++;continue}if(q==="<"&&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 CZ=G+2+N[0].length;if(CZ<U&&!/[\s;&|()<>]/.test(Z[CZ])){V=!1,G=U;continue}j(G),K.push({delimiter:N[2],quoted:N[1]!=="",stripTabs:N[0].startsWith("-"),owner:B}),G=CZ;continue}let A=Z.indexOf(`
|
|
22
|
+
`,G+2+N[0].length);if(A===-1){V=!1,G=U;continue}let h=Z.slice(A+1),w=e3(h,N[2]);if(w===-1){V=!1,G=U;continue}j(G),G=A+1+w+N[2].length;continue}if(q===">"||q==="<"){if(H>=0&&/^\d+$/.test(Z.slice(H,G)))H=-1;if(j(G),M=!0,G++,Z[G]===q||Z[G]==="&"||q===">"&&Z[G]==="|"||q==="<"&&Z[G]===">")G++;continue}if(q==="'"){if(H<0)H=G;let N=L(G);if(N<0)V=!1,G=U;else G=N;continue}if(q==='"'){if(H<0)H=G;let N=l(G),A=N<0||!$?[]:r3(Z,G,N);if(N<0||!A)V=!1,G=U;else Y.push(...A),G=N;continue}if(q==="`"){if(H<0)H=G;let N=y(G);if(N<0)V=!1,G=U;else{let A=Z.slice(G+1,N-1);Y.push($?E0(A,!1):A),G=N}continue}if(q==="$"&&Z[G+1]==="("){if(H<0)H=G;let N=E(G+1);if(N<0)V=!1,G=U;else Y.push(Z.slice(G+2,N-1)),G=N;continue}if(q==="\\"){if(H<0)H=G;if(G+1>=U)V=!1,G=U;else G+=2;continue}if(H<0)H=G;G++}if(F(U),K.length>0&&y1(Z,U,K,Y)<0)V=!1;return{segments:J,trustworthy:V,substitutions:Y}}function e3(Z,z){let $=0;while($<=Z.length){let J=Z.indexOf(z,$);if(J===-1)return-1;let Y=J===0||Z[J-1]===`
|
|
23
|
+
`,X=J+z.length,Q=X===Z.length||Z[X]===`
|
|
24
|
+
`||Z[X]==="\r";if(Y&&Q)return J;$=J+1}return-1}function R(Z){return w1(Z,!1)}function x(Z){let z=0,$=0;while(z<Z.words.length&&$++<32){if(Z.redirects.has(z)){z++;continue}let J=Z.words[z].text,Y=v(J);if(h1.test(Y)&&!Y.startsWith("-")){z++;continue}if(i3.has(Y)){z++;continue}let X=$0(Y);if(X==="command")for(let B of Z.words.filter((K,H)=>H>z&&!Z.redirects.has(H))){let K=v(B.text);if(K==="--"||!K.startsWith("-"))break;if(/^-[pvV]*[vV][pvV]*$/.test(K))return-1}let Q=u3[X];if(Q){let B=z;z++;while(z<Z.words.length){if(Z.redirects.has(z)){z++;continue}let H=v(Z.words[z].text);if(!H.startsWith("-")||H==="-")break;if(H==="--"){z++;break}if(X==="env"&&(/^-[iv0]*S/.test(H)||/^--split-string(?:=|$)/.test(H)))return B;if(z++,Q.includes(H)||X==="exec"&&/^-[cl]*a$/.test(H)){while(Z.redirects.has(z))z++;z++}}let K=l3[X]??0;while(K>0&&z<Z.words.length){let H=v(Z.words[z].text);if(H.startsWith("-")&&H!=="-")break;z++,K--}continue}return z}return-1}function Z4(Z,z){let $=[],J=!1;for(let Y=z+1;Y<Z.words.length;Y++){if(Z.redirects.has(Y))continue;let X=R(Z.words[Y].text);if(!J){if(X==="--"){J=!0;continue}if(X.startsWith("-")&&X!=="-")continue}$.push(Z.words[Y])}return $}function S0(Z){return h3.map((z)=>WZ(Z,...z.split("/")))}function $4(Z,z){if(Z==="~"||Z==="$HOME"||Z==="${HOME}")return z;if(Z.startsWith("~/"))return WZ(z,Z.slice(2));if(Z.startsWith("$HOME/"))return WZ(z,Z.slice(6));if(Z.startsWith("${HOME}/"))return WZ(z,Z.slice(8));return Z}function Z0(Z,z,$){let J=R(Z);if(!J)return null;if(J.includes("`"))return null;if(J==="$HOME"||J==="${HOME}"||J==="$HOME/"||J==="${HOME}/")return $;if(J.replace(/\$\{HOME\}/g,"").replace(/\$HOME/g,"").includes("$"))return null;if(/[*?[\]]/.test(J))return null;if(J.startsWith("~")){let B=$4(J,$);if(B===J)return null;J=B}let Q=(E3(J)?S3(J):f3(z,J)).replace(/\/+$/,"");return Q===""?"/":Q}function r(Z,z){return Z===z||Z.startsWith(`${z}${v0}`)}var J4=/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/,z4=!1,Y4=/^[A-Za-z0-9._@+-]{1,128}$/,X4=512;function jZ(Z){return`'${Z.replace(/[\u0000-\u001f\u007f-\u009f]/g,"?").slice(0,X4).replace(/'/g,"'\\''")}'`}function R1(Z){return Y4.test(Z)?`\`${Z}\``:"a name that is not a plain identifier"}function Q4(Z,z){let $=`${WZ(z,".hasna","scratchpad","scratch")}${v0}`;if(!Z.startsWith($))return null;let[J,Y]=Z.slice($.length).split(v0);if(!J)return{content:!1,reason:"the scratch root itself holds every session, not one session's content"};if(J.endsWith(".")||!J4.test(J))return{content:!1,reason:`${R1(J)} is not a session id this carve-out accepts (real ids are mixed case, e.g. \`ses_ebbb3f564ffe7PDf32UBmlNI3v\`)`};if(!Y)return z4?{content:!0}:{content:!1,reason:`${R1(J)} is a session root; removing it would also remove its \`meta.json\` and \`.lock\` control files, and whether the root itself is scratch is an open decision (Todos 264c4be0) \u2014 remove specific children instead`};let X=Y.normalize("NFKC").toLowerCase();if(X==="meta.json"||X===".lock")return{content:!1,reason:`\`${X}\` is session control state, not scratch`};return{content:!0}}function K4(Z,z){if(Z===z)return`${jZ(Z)} is the home directory itself, which is never deleted or trashed. Delete a specific file or directory inside it instead.`;for(let $ of D1){if(Z!==$&&!r($,Z))continue;return $==="/"?`${jZ(Z)} is the filesystem root, which is never deleted.`:`${jZ(Z)} is the system root \`${$}\` (or an ancestor of it), which is never deleted or trashed.`}for(let $ of w3){let J=WZ(z,$),Y=r(Z,J);if(!Y&&!r(J,Z))continue;if($===".hasna"&&Y){let X=Q4(Z,z);if(X?.content===!0)continue;if(X&&X.content===!1)return`${jZ(Z)} is inside the protected \`~/${$}\` tree and is not sanctioned scratch, because ${X.reason}. Nothing under \`~/${$}\` is deleted or trashed outside that one carve-out.`}return Y?`${jZ(Z)} is inside the protected \`~/${$}\` tree, which is never deleted or trashed. Delete a specific file inside it, and only when you are sure.`:`${jZ(Z)} contains the protected \`~/${$}\` tree, which is never deleted or trashed. Delete a specific file or directory inside it instead.`}return null}function B4(Z,z,$){let J=S0($);if(J.some((Y)=>r(z,Y)))return!0;return Z.some((Y)=>Y!==null&&J.some((X)=>r(Y,X)))}var v1=new WeakMap;function H4(Z){let z=v1.get(Z);if(z)return z;let $=Z.words.map((Q)=>v(Q.text)),J=$.findIndex((Q)=>Q==="-exec"||Q==="-execdir"||Q==="-ok"||Q==="-okdir"),Y=-1;Z.words.forEach((Q,B)=>{if(x1.has(R(Q.text)))Y=B});let X={findDelete:$.includes("-delete"),findExecDelete:J>=0&&$.slice(J).some((Q)=>b0.has($0(Q))),namesDelete:$.some((Q)=>b0.has($0(Q))),lastFlockCommand:Y,textMention:i(N4(Z)),envMention:i(uZ(Z.words.map((Q)=>R(Q.text)))),bodiesMention:i((Z.heredocs??[]).join(`
|
|
25
|
+
`))};return v1.set(Z,X),X}var M4=new Set(["sh","bash","zsh","dash","ksh","ash","mksh"]);function V4(Z,z){if(!M4.has(FZ(Z.words[z].text)))return!1;for(let $=z+1;$<Z.words.length;$++){if(Z.redirects.has($))continue;let J=R(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 y0=(Z)=>Z.kind==="rm"||Z.kind==="refuse",G4="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.",U4="This delete's brace pattern names more paths than this hook will check. Run the delete on explicit paths with `rm -- <path> \u2026`, which is redirected into trash.",j4="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.",W4="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 f0(Z){let z=[];Z.words.forEach((Y,X)=>{if(!Z.redirects.has(X))z.push(X)});let $=z.map((Y)=>{let X=Z.words[Y].text;return{text:v(X),opaque:J0(X)}}),J=zZ($,p3);if(J===null)return null;return J.index<0?-1:z[J.index]}function R0(Z,z,$,J){let Y=FZ(Z.words[z].text);if(Y==="cd"){let K=Z.words[z+1];if(!K)return{kind:"none"};return{kind:"cd",cwd:Z0(K.text,$,J.home)??J.cwd}}if(Object.hasOwn(A0,Y))return{kind:"refuse",reason:A0[Y]};let X=m1(Z,z,$,J);if(X)return X;if(Y==="rm"){let K=Z4(Z,z);if(K.length===0)return{kind:"none"};let H={word:Z.words[z],operands:K},M=S0(J.home),V=(j)=>j!==null&&M.some((F)=>r(j,F)),G=[],U=[];for(let j of K){let F=Z0(j.text,$,J.home);if(G.push(F),!j.text.includes("{"))continue;let L=JZ(j.text);if(L===null)return{kind:"refuse",reason:U4};for(let y of L){let E=Z0(y,$,J.home);if(E===null)continue;if(V(E)&&!V(F))return{kind:"refuse",reason:j4};U.push(E)}}if(B4(G,$,J.home))return H.cwdOnly=G.every((j)=>j!==null&&!V(j)),{kind:"rm",hit:H,handoff:!0,protectedReason:null};for(let j of[...G,...U]){if(!j)continue;let F=K4(j,J.home);if(F)return{kind:"rm",hit:H,handoff:!1,protectedReason:F}}return{kind:"rm",hit:H,handoff:!1,protectedReason:null}}if(c3.has(Y)){let K=Z.words.findIndex((M,V)=>V>z&&!R(M.text).startsWith("-")),H=K>=0?FZ(Z.words[K].text):"";if(H==="rm"||Object.hasOwn(A0,H))return{kind:"refuse",reason:`\`${Y} ${H}\` runs the ${Y} applet, whose own \`rm\` is not GNU \`rm\` and cannot be rewritten in place. Run the delete as \`rm -- <path>\`, which is redirected into trash.`};return{kind:"none"}}if(Y==="git"){let K=k0(Z,z);if(K==="rm"||K==="clean"){if(!(K==="rm"?D4(Z,z):p1(Z,z)))return{kind:"refuse",reason:K==="rm"?"`git rm` is refused: without `--cached` it deletes the working-tree file, and its semantics are not `rm`'s. Use `rm -- <path>` (intercepted and redirected into trash) to remove the file, or `git rm --cached -- <path>` to unstage it without deleting.":"`git clean` deletes untracked files irrecoverably and is refused. Remove them explicitly with `rm -- <path>` (intercepted and redirected into trash), or preview with `git clean -n`."}}return{kind:"none"}}let Q=H4(Z);if(Y==="find"){if(Q.findDelete)return{kind:"refuse",reason:"`find -delete` deletes files irrecoverably and is refused. List the paths first (`find \u2026 -print`), then remove them explicitly with `rm -- <path>` so the delete is redirected into trash."};if(Q.findExecDelete)return{kind:"refuse",reason:"`find -exec <delete>` is refused: the delete runs through find, not through `rm`, and cannot be redirected into trash. Remove the paths explicitly with `rm -- <path>`."};return{kind:"none"}}if(Y==="xargs"&&Q.namesDelete)return{kind:"refuse",reason:"`xargs rm` takes its targets from stdin, so this hook cannot verify what would be deleted. Pipe the paths into an explicit `rm -- <path> \u2026` instead, which is redirected into trash."};let B=Y==="flock"?Q.lastFlockCommand>z:x1.has(Y);if(g3.has(Y)||B){let K=V4(Z,z)?J.bodiesMention:Q.bodiesMention;if((Y==="env"?Q.envMention:Q.textMention)||K)return{kind:"refuse",reason:`\`${B?"flock":Y}\` runs a command string this hook cannot rewrite in place. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or as a script that uses \`trash guard\` itself.`}}return{kind:"none"}}function m1(Z,z,$,J,Y={segment:Z,index:z},X=0){let Q=FZ(Z.words[z].text);for(let V of hZ(Z.words.map((G)=>v(G.text)),z,(G)=>Z.redirects.has(G))){if(X>=8)return gZ(Y.segment,Y.index,$,J.home)?{kind:"refuse",reason:F4}: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=f0(G);for(let j of new Set([x(G),U??-1])){if(j<0)continue;let F=m1(G,j,$,J,Y,X+1);if(F)return F}}let B=Z.words.map((V,G)=>({word:V,at:G})).filter(({at:V})=>!Z.redirects.has(V)),K=B.findIndex(({at:V})=>V===z),H=K<0?null:xZ(B.map(({word:V})=>V.text),K,v);if(H&&!H.literal&&(gZ(Z,z,$,J.home)||gZ(Y.segment,Y.index,$,J.home)))return{kind:"refuse",reason:`\`${Q}\` runs a shell program that is not a plain literal (an expansion, a substitution, ANSI-C \`$'\u2026'\` quoting or several words), so this hook cannot read what it would delete under a protected repository checkout. Write the program out literally, or run it from outside the checkout.`};let M=wZ(Z.words.map((V)=>v(V.text)),z,(V)=>V>=0&&V<Z.words.length&&(Z.redirects.has(V)||J0(Z.words[V].text)));if(!M||!(gZ(Z,z,$,J.home)||gZ(Y.segment,Y.index,$,J.home)))return null;if(!M.unresolved&&!M.programs.some((V)=>i(V.text)))return null;return{kind:"refuse",reason:`\`${Q}\` runs a program locally (an interpreter's inline program or a command-running option) this hook cannot rewrite, and it could delete a file under a protected repository checkout. Run the delete directly as \`rm -- <path>\` (intercepted and redirected into trash), or run the command from outside the checkout.`}}var F4="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 gZ(Z,z,$,J){let Y=S0(J),X=(Q)=>Q!==null&&Y.some((B)=>r(Q,B));if(Y.some((Q)=>r($,Q)))return!0;for(let Q=z+1;Q<Z.words.length;Q++){if(Z.redirects.has(Q))continue;if(X(Z0(Z.words[Q].text,$,J)))return!0}return!1}function NZ(Z,z){let $={rmHits:[],handoffHits:[],refusals:[],protectedHits:[],trustworthy:!0},J=b(Z,g1);$.trustworthy=J.trustworthy;let Y={cwd:z.cwd,home:z.home,depth:z.depth??0,bodiesMention:i(J.segments.flatMap((K)=>K.heredocs??[]).join(`
|
|
26
|
+
`))};if(!J.trustworthy){let K=UZ(Z);return K===Z?$:{...NZ(K,z),trustworthy:!1}}let X=[],Q=(K,H=$.refusals)=>{if(K.kind==="refuse")H.push({reason:K.reason});else if(K.kind==="rm"&&K.handoff)$.handoffHits.push(K.hit);else if(K.kind==="rm"){if($.rmHits.push(K.hit),K.protectedReason)$.protectedHits.push({reason:K.protectedReason})}},B=Y.cwd;for(let K of J.segments){let H=x(K),M=f0(K),V=H<0?{kind:"none"}:R0(K,H,B,Y);if(V.kind!=="cd")Q(V);let G=(U)=>U!==null&&U>=0&&J0(K.words[U].text);if(M===null||G(H)||G(M)){if(K.words.some((U,j)=>!K.redirects.has(j)&&(y0(R0(K,j,B,Y))||a3(U.text))))X.push({reason:G4})}else if(M>=0&&M!==H){let U=R0(K,M,B,Y);if(y0(U))if(y0(V))X.push({reason:W4});else Q(U,X)}if(V.kind==="cd")B=V.cwd}if(Y.depth<3)for(let K of J.substitutions){let H=NZ(K,{cwd:B,home:Y.home,depth:Y.depth+1});if(H.rmHits.length>0||H.refusals.length>0||H.handoffHits.length>0||H.protectedHits.length>0||!H.trustworthy&&i(K)){$.refusals.push({reason:"This command runs a delete inside a command substitution `$(\u2026)`, which this hook cannot rewrite. Run the delete as a separate `rm -- <path>` command, which is redirected into trash."});break}}else if(J.substitutions.some((K)=>i(K)))$.refusals.push({reason:"This command nests a delete inside command substitutions deeper than this hook will follow. Run the delete as a separate `rm -- <path>` command."});return $.refusals.push(...X),$}function N4(Z){return Z.words.map((z)=>z.text).join(" ")}function k0(Z,z){let $=z+1;while($<Z.words.length){let J=R(Z.words[$].text);if(!J.startsWith("-"))return J;if($++,d3.has(J))$++}return null}function D4(Z,z){if(Z.words.slice(z+1).map((J)=>R(J.text)).includes("--cached"))return!0;return p1(Z,z)}function p1(Z,z){let $=Z.words.slice(z+1).map((J)=>R(J.text));return $.includes("-n")||$.includes("--dry-run")}function b1(Z){if(/^[A-Za-z0-9_\-./+=:,@%^]+$/.test(Z))return Z;return`'${Z.replace(/'/g,"'\\''")}'`}function _4(Z,z,$,J){let Y=J?["/usr/bin/env","-i",`HOME=${J.home}`,`PATH=${J.path}`,`HASNA_TRASH_AGENT=${J.agent}`,J.runtime,"--config=/dev/null","--no-env-file","--no-macros","--no-install",$,"guard"].map(b1).join(" "):`${b1($)} guard`,X=[...z].sort((B,K)=>K.word.start-B.word.start),Q=Z;for(let B of X)Q=`${Q.slice(0,B.word.start)}${Y}${Q.slice(B.word.end)}`;return Q}function I4(Z,z,$,J,Y){if(!z||z===Z)return!1;if($.length===0)return!1;let X=NZ(z,{cwd:J,home:Y});if(!X.trustworthy)return!1;if(X.rmHits.length>0||X.handoffHits.length>0)return!1;return X.refusals.length===0}function T4(Z,z){let $={};for(let[J,Y]of Object.entries(Z??{}))$[J]=Y;if($.command=z,typeof $.description!=="string"||$.description.trim()==="")$.description=x3;if(typeof $.timeout!=="number"||!Number.isFinite($.timeout)||$.timeout<=0)$.timeout=k3;if(typeof $.run_in_background!=="boolean")$.run_in_background=!1;if("dangerouslyDisableSandbox"in $&&typeof $.dangerouslyDisableSandbox!=="boolean")delete $.dangerouslyDisableSandbox;return $}function q4(Z,z,$,J,Y){if(typeof Z.command!=="string"||Z.command.trim()==="")return!1;if(typeof Z.description!=="string"||Z.description.trim()==="")return!1;if(typeof Z.timeout!=="number"||!Number.isFinite(Z.timeout)||Z.timeout<=0)return!1;if(typeof Z.run_in_background!=="boolean")return!1;if("dangerouslyDisableSandbox"in Z&&typeof Z.dangerouslyDisableSandbox!=="boolean")return!1;return I4(z,Z.command,$,J,Y)}function C4(Z){let z=new Set(["export","set","unset","readonly","declare","typeset","local","alias","unalias","read","readarray","mapfile","getopts","trap","enable","function","env","sudo","doas","stdbuf"]);return b(Z,g1).segments.some((J)=>{let Y=f0(J);return[x(J),...Y===null?[]:[Y]].some((X)=>{if(J.words.slice(0,X<0?J.words.length:X).some((K)=>h1.test(R(K.text))||z.has(FZ(K.text))))return!0;if(X<0)return!1;let B=J.words[X];return z.has(FZ(B.text))||/^\s*\(\s*\)\s*\{/.test(Z.slice(B.end))})})}function u(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:Z}}}function P4(Z){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:Z}}}function O4(Z){try{if(Z.inspectTrash){let z=Z.inspectTrash();return z.ok?{path:z.path,error:null}:{path:null,error:`${z.code}: ${N1[z.code]}`}}return{path:Z.findTrash(),error:null}}catch(z){return{path:null,error:z instanceof Error?z.message:String(z)}}}var L4="[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.",E1="[trash-guard] The rewrite of this command did not verify (the delete could not be redirected cleanly), so the command is refused rather than run unredirected. Re-run the delete as a plain `rm -- <path>` command.";function S1(Z,z){if(Z.refusals.length>0)return u(`[trash-guard] ${Z.refusals[0].reason}`);if(Z.protectedHits.length>0)return u(`[trash-guard] ${Z.protectedHits[0].reason}`);if(!Z.trustworthy)return i(z)?u("[trash-guard] This command could not be parsed to the end (unterminated quote, substitution or here-document), so a delete inside it cannot be redirected. Re-run the delete as a plain `rm -- <path>` command."):{continue:!0};if(Z.rmHits.length===0){if(Z.handoffHits.some(($)=>$.cwdOnly))return u("[trash-guard] This delete runs from inside a protected repository checkout but names only paths outside it. Run it from outside the checkout (`cd /tmp && rm -- <path>`), where it is redirected into trash.");return{continue:!0}}if(Z.handoffHits.length>0)return u("[trash-guard] This command mixes a delete under the protected repo-checkout roots (owned by workspace-repos-guard) with a delete outside them, and a partial rewrite would leave one of them unredirected. Re-run them as separate commands, so each delete is handled by the hook that owns it.");return null}function c1(Z,z){if(Z.hook_event_name!=="PreToolUse")return{continue:!0};if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(Z.tool_name??"")){let j=Z.tool_input?.command;if(typeof j!=="string")return u("[trash-guard] Unreadable patch input; deletion safety cannot be checked.");if(/^\s*\*\*\* Delete File:/m.test(j))return u("[trash-guard] Delete File would bypass recoverable deletion. First use `trash put -- <path>` or the trash_put MCP tool, then submit any remaining edits without the deletion block.");return{continue:!0}}if(Z.tool_name!=="Bash")return{continue:!0};if(typeof Z.tool_input?.command!=="string")return u("[trash-guard] The Bash tool call carried no readable `command`, so this hook cannot verify what would run. Refusing a call it cannot verify. Re-run the delete explicitly as `rm -- <path>` so it can be redirected into trash.");let J=GZ(Z);if(!J.trim())return{continue:!0};let Y=()=>NZ(J,{cwd:z.cwd,home:z.home}),X=(j)=>j.rmHits.map((F)=>F.word.start).join(),Q=(j)=>j()||!!YZ(J,j),B=Y(),K=S1(B,J),H=YZ(J,()=>{let j=Y();return{result:j,verdict:S1(j,J)}});if(H){let{result:j,verdict:F}=H;if(F&&!("continue"in F))return F;if(!F&&(!K||("continue"in K))&&X(j)!==X(B))return u(E1)}if(K)return K;let M=O4(z);if(M.error!==null)return u(`[trash-guard] The guard could not resolve the \`trash\` binary (${M.error}), so this \`rm\` cannot be redirected into a recoverable delete \u2014 and an unrecoverable delete is never allowed, so the command is refused rather than run. Fix the environment (PATH, permissions) and re-run the same command.`);if(M.path===null)return u(L4);let V=M.path;if(z.execution&&Q(()=>C4(J)))return u("[trash-guard] A deletion combined with shell environment changes cannot use the verified native execution context. Run the deletion as a separate plain rm command.");let G=_4(J,B.rmHits,V,z.execution),U=T4(Z.tool_input,G);if(z.execution)U.hasna_execution="hasna.hooks.execution.v1";if(Q(()=>!q4(U,J,B.rmHits,z.cwd,z.home)))return u(E1);return P4(U)}import{closeSync as A4,constants as i1,fstatSync as y4,lstatSync as R4,openSync as v4,readFileSync as b4,statSync as E4}from"fs";import{homedir as $2}from"os";import{dirname as x0,isAbsolute as J2,join as _Z,normalize as IZ,relative as S4,resolve as iZ,sep as l0}from"path";var f4=new Set(["Write","Edit","MultiEdit","NotebookEdit"]),k4=new Set(["apply_patch","ApplyPatch","functions.apply_patch"]),x4=["hasna","hasnaxyz","hasna-products"],mZ="workspace-repos-guard";function h4(Z){return _Z(Z,".hasna","repos","clones")}function w4(Z){return _Z(Z,"workspace","repos")}function z2(Z){return[h4(Z),w4(Z)]}function g4(Z){return _Z(Z,".hasna","hooks","config","workspace-repos-guard-orgs")}var u4=/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/;function h0(Z){let z=process.getuid?.();return z!==void 0&&(Z.uid===0||Z.uid===z)&&(Z.mode&18)===0}function l4(Z){let z=g4(Z),$;try{let Y=v4(z,i1.O_RDONLY|i1.O_NOFOLLOW);try{let Q=y4(Y);if(!Q.isFile()||!h0(Q)||Q.size>4096)return null;$=b4(Y,"utf8")}finally{A4(Y)}let X=IZ(Z);for(let Q=x0(z);Q!==X;Q=x0(Q)){let B=R4(Q);if(!B.isDirectory()||!h0(B)||Q===x0(Q))return null}if(!h0(E4(X)))return null}catch{return null}let J=$.replace(/#[^\n]*/g,"").split(/[\s,]+/).filter(Boolean);return J.length>0&&J.every((Y)=>u4.test(Y))?new Set(J):null}function m4(Z=process.env,z=$2()){let $=Z.WORKSPACE_REPOS_GUARD_ORGS;if(typeof $==="string"&&$.trim())return new Set($.split(",").map((J)=>J.trim()).filter(Boolean));return l4(z)??new Set(x4)}function w0(Z,z,$,J){if(J==="read")return{blocked:!1};let Y=S4(z,Z);if(Y===""){if(J==="delete")return{blocked:!0,reason:`[${mZ}] delete of the protected repo-checkout root is forbidden: ${z}`};return{blocked:!0,reason:`[${mZ}] writes directly to the protected repo-checkout root are forbidden: ${z}`}}if(Y.startsWith(`..${l0}`)||Y===".."||J2(Y))return{blocked:!1};let X=Y.split(l0).filter(Boolean);if(J==="delete")return{blocked:!0,reason:`[${mZ}] delete under the protected repo-checkout root (${z}) is forbidden at any depth: ${Z}`};if(X.length<=1)return{blocked:!0,reason:`[${mZ}] writing would create a top-level entry directly under the protected repo-checkout root (${z}); only GitHub-org folders belong there: ${Z}`};let Q=X[0];if(!$.has(Q))return{blocked:!0,reason:`[${mZ}] '${Q}' is not an allowed GitHub org under the protected repo-checkout root (${z}); allowed: ${[...$].join(", ")}: ${Z}`};return{blocked:!1}}var Y2=/\b(?:-o|--output|-O|--output-document|-out)\b/,p4=/\d*[<>]&\s*(?:\d+|-)(?=$|[\s;&|)])/g,c4=/(?:\d+|&)?(?:>>|>\||>&|<>|>)\s*([^\s;&|<>()\x60]*)/g;function X2(Z){return Z.replace(p4," ")}function i4(Z){let z=[],$=null,J=0,Y=0,X=!1,Q=0;for(let B=0;B<Z.length;B++){let K=Z[B];if($==="'"){if(K==="'")$=null;continue}if(K==="\\"){B++;continue}if(K==="("){J++;continue}if(K===")"){if(--J<0)return[Z];continue}if(K==="$"&&Z[B+1]==="{"){Y++,B++;continue}if(K==="}"&&Y>0){Y--;continue}if(K==="`"){X=!X;continue}if($==='"'){if(K==='"')$=null;continue}if(K==="'"||K==='"'){$=K;continue}if(K!=="|"||J>0||Y>0||X||Z[B-1]===">")continue;if(z.push(Z.slice(Q,B)),Z[B+1]==="&")B++;Q=B+1}if($||J!==0||Y!==0||X)return[Z];return z.push(Z.slice(Q)),z}function d4(Z){let z=[],$="",J="",Y=null,X=!1,Q=()=>{if(!X)return;let B=J.replace(/^"?\$\{?HOME\}?"?(?=\/|$)/,""),K=$.startsWith("~")&&!/^~(?:\/|$)/.test(J);z.push({text:K?`./${$}`:$,opaque:/[$\x60*?[]/.test(B)||/[()]/.test(B)||tZ(J)}),$="",J="",X=!1};for(let B=0;B<Z.length;B++){let K=Z[B];if(Y==="'"){if(K==="'")Y=null;else $+=K;J+=K;continue}if(K==="\\"&&B+1<Z.length){let H=Z[B+1];$+=Y==='"'&&!/[$\x60"\\\n]/.test(H)?K+H:Y==='"'&&H===`
|
|
27
|
+
`&&!a.on?"":H,J+=K+H,X=!0,B++;continue}if(Y==='"'){if(K==='"')Y=null;else $+=K;J+=K;continue}if(/\s/.test(K)){Q();continue}if(X=!0,J+=K,K==="'"||K==='"')Y=K;else $+=K}if(Y)J+="$";return Q(),z}function g0(Z,z,$){let J=Z[z];return J==="--help"||J==="--version"||$&&(J==="-h"||J==="-V")}var d1={read:0,write:1,delete:2};function Y0(...Z){return Z.reduce((z,$)=>d1[$]>d1[z]?$:z,"read")}var s4=new Set(["status","doctor","list","info","get","pending","station","setup","backup","storage","retrieval","backup-storage","backup-inspect","backup-refresh","help"]),Q2=new Set(["put","rm","delete","remove"]),n4=new Set([...Q2,"restore","restore-capsule","recover","release","locks","retention","hold","unhold","pin","unpin","retrieve","backup-retrieve"]),K2=new Set(["-delete","-exec","-execdir","-ok","-okdir","-fls","-fprint","-fprint0","-fprintf"]);function p0(Z){let z=null;for(let $=0;$<Z.length;$++){let J=Z[$];if(z==="'"){if(J==="'")z=null;continue}if(J==="\\"){$++;continue}if(J==="$"||J==="`")return!0;if(z==='"'){if(J==='"')z=null;continue}if(J==="'"||J==='"')z=J;else if("*?[{".includes(J))return!0}return z!==null}function c0(Z){let z=Z.trim();if(!z)return"read";if(Q0(z))return"delete";let $=b(z);if(!$.trustworthy||$.substitutions.length||/\$\{[^}]*[|;()]|[<>]\(/.test(z))return QZ(z);let J=$.segments.flatMap((Y)=>{let X=s1(Y),Q=Y.words.filter((H,M)=>!Y.redirects.has(M)).map((H)=>H.text),B=Q.map(JZ);if(B.every((H,M)=>H!==null&&H.length===1&&H[0]===Q[M]))return[X];if(B.some((H)=>H===null))return[X,QZ(Q.join(" "))];let K=b(B.flatMap((H)=>H??[]).join(" "));return[X,...K.trustworthy?K.segments.map(s1):[QZ(Q.join(" "))]]});return Y0(...J)}function s1(Z){let z=Z.words.map((X,Q)=>({word:X,at:Q})).filter(({at:X})=>!Z.redirects.has(X)),$=x(Z),J=$<0?"read":n1(Z,$),Y=zZ(z.map(({word:X})=>i0(X.text)));if(Y===null)return Y0(J,QZ(z.map(({word:X})=>R(X.text)).join(" ")));if(Y.index<0||z[Y.index].at===$)return J;return Y0(J,n1(Z,z[Y.index].at))}function B2(Z,z,$=0){if(z<0||$>8)return $>8;let J=Z.words.map((H,M)=>({word:H,at:M})).filter(({at:H})=>!Z.redirects.has(H)),Y=J.findIndex(({at:H})=>H===z),X=Y<0?null:xZ(J.map(({word:H})=>H.text),Y,v);if(X){if(!X.literal)return!0;let H=b(X.program);if(H.trustworthy&&H.segments.some((M)=>X0(M,$+1)))return!0}let Q=Z.words.map((H)=>v(H.text));for(let H of hZ(Q,z,(M)=>Z.redirects.has(M)))if(X0(H2(Z,H.start,H.end),$+1))return!0;let K=wZ(Q,z,(H)=>H>=0&&H<Z.words.length&&(Z.redirects.has(H)||p0(Z.words[H].text)));if(!K)return!1;if(K.unresolved)return!0;return K.programs.some((H)=>H.kind==="shell"?c0(H.text)!=="read":!O1(H))}function H2(Z,z,$){let J=new Set([...Z.redirects].filter((Y)=>Y>=z&&Y<$).map((Y)=>Y-z));return{words:Z.words.slice(z,$),redirects:J}}function X0(Z,z=0){return M2(Z).some(($)=>B2(Z,$,z))}function i0(Z){return{text:v(Z),opaque:/[$\x60]/.test(Z)&&!/^(?:[^$\x60"'\\]|\$'(?:[^'\\]|\\.)*')+$/.test(Z)}}function M2(Z){let z=new Set,$=x(Z);if($>=0)z.add($);let J=Z.words.map((X,Q)=>({word:X,at:Q})).filter(({at:X})=>!Z.redirects.has(X)),Y=zZ(J.map(({word:X})=>i0(X.text)));if(Y!==null&&Y.index>=0)z.add(J[Y.index].at);return[...z]}function pZ(Z,z=0){if(z>8)return[];let $=[];for(let J of Z.segments){let Y=J.words.map((B)=>v(B.text)),X=(B)=>B>=0&&B<J.words.length&&(J.redirects.has(B)||p0(J.words[B].text)),Q=J.words.filter((B,K)=>!J.redirects.has(K));for(let B of M2(J)){$.push(...(wZ(Y,B,X)?.writes??[]).map((M)=>M[0]==="/"?M:`./${M}`));let K=xZ(Q.map((M)=>M.text),Q.indexOf(J.words[B]),v),H=K?.literal?b(K.program):null;if(H?.trustworthy)$.push(...pZ(H,z+1));for(let M of hZ(Y,B,(V)=>J.redirects.has(V)))$.push(...pZ({segments:[H2(J,M.start,M.end)]},z+1))}}for(let J of Z.substitutions??[]){let Y=b(J);if(Y.trustworthy)$.push(...pZ(Y,z+1))}return $}function Q0(Z,z=0){if(z>4)return!1;let $=b(Z),J=$.trustworthy?Z:UZ(Z);if(J!==Z)return Q0(J,z+1);if($.trustworthy&&$.segments.some((X)=>X0(X)))return!0;return(U2(Z)??$.substitutions).some((X)=>Q0(X,z+1))}function n1(Z,z){if(B2(Z,z))return"delete";let $=Z.words.filter((X,Q)=>Q>=z&&!Z.redirects.has(Q)),J=$.map((X)=>v(X.text)),Y=J[0].split("/").pop();if(["rm","rmdir","shred"].includes(Y??""))return g0(J,1,!1)?"read":"delete";if(["unlink","rmtree","del"].includes(Y??""))return"delete";if(Y==="trash"){let X=1;while(X<J.length&&J[X].startsWith("-")){let Q=J[X++];if(["--help","-h","--version","-V","--identity"].includes(Q))return"read";if(["--agent","--spool","--files","--info","--config"].includes(Q))X++;else if(!["--json","--local"].includes(Q))return"delete"}if(X===J.length||s4.has(J[X]))return"read";if(n4.has(J[X])&&g0(J,X+1,!0))return"read";if(["restore","restore-capsule"].includes(J[X]))return"write";return"delete"}if(Y==="git"){let X=k0(Z,z);if(X==="clean"||X==="rm")return J[1]===X&&g0(J,2,!0)?"read":"delete";return X==="clone"||X==="init"?"write":"read"}if(Y==="find"&&!$.some((X)=>p0(X.text))&&!J.some((X)=>K2.has(X)))return"read";if(Y==="env"&&i(uZ(J)))return"delete";if(["sh","bash","zsh","dash","ksh","ash","mksh","eval","source",".","su","runuser","env","xargs","find","busybox","toybox"].includes(Y??""))return QZ(J.join(" "));if(["mkdir","mkfile","touch","mv","cp","ln","tee","install","dd","rsync","scp","truncate"].includes(Y??""))return"write";if(Y==="curl"||Y==="wget")return Y2.test(J.join(" "))?"write":"read";if(Y==="sed"&&J.slice(1).some((X)=>/^-i|^--in-place(?:=|$)/.test(X)))return"write";if(["python","python3","node","bun"].includes(Y??"")&&J.some((X)=>X==="-c"||X==="-e"))return"write";return"read"}function QZ(Z){let z=Z.replace(/[{},]/g," ");return z===Z?u0(Z):Y0(u0(Z),u0(z))}function u0(Z){let z=Z.trim();if(!z)return"read";if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:rm|rmdir|unlink|shred|trash|rmtree|del)(?:\s|$)/.test(z))return"delete";if(/\bgit\b/.test(z)){if(/\bgit\b[^;&|]*\b(?:clean|rm)\b/.test(z))return"delete";if(/\bgit\b[^;&|]*\b(?:clone|init)\b/.test(z))return"write";return"read"}if(/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|mv|cp|ln|tee|install|dd)(?:\s|$)/.test(z))return"write";if(/\b(?:curl|wget)\b/.test(z)){if(Y2.test(z))return"write";return"read"}if(/\bsed\b/.test(z)){if(/(?:^|\s)-i\S*(?:\s|$)|--in-place(?:\s|$)/.test(z))return"write"}else if(/\b(?:rsync|scp|truncate)\b/.test(z))return"write";else if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(z))return"write";if(/(?:^|[;&|])\s*echo\b/.test(z)||/>/.test(X2(z)))return"write";return"read"}function cZ(Z,z){let $=Z.trim(),J=$.match(/^(['"])([\s\S]*)\1$/);if(J)$=J[2];if($=$.replace(/^"*\$HOME"*\//,"$HOME/"),$=$.replace(/^"*\$\{HOME\}"*\//,"${HOME}/"),$==="~")return z;if($.startsWith("~/"))return _Z(z,$.slice(2));if($==="$HOME"||$==="${HOME}")return z;if($.startsWith("$HOME/"))return _Z(z,$.slice(6));if($.startsWith("${HOME}/"))return _Z(z,$.slice(8));let Y=$.match(new RegExp(`^"*${m0(z)}"*/`));if(Y)return z+"/"+$.slice(Y[0].length);return Z}function o4(Z){let z=Z.trim();while(z.startsWith("(")||/^\{(?:\s|$)/.test(z))z=z.slice(1).trim();while(z.endsWith(")")||/(?:^|\s)\}$/.test(z))z=z.slice(0,-1).trim();return z}function m0(Z){return Z.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function o1(Z,z,$){if(Z===void 0)return[$];let J=cZ(Z,$),Y=J.match(/^(['"])(.*)\1$/);if(Y)J=Y[2];if(!J||J==="-"||/[$\x60*?[\]{}~\\'"]/.test(J))return null;return[...new Set(z.map((X)=>iZ(X,J)))]}var a4=/(?:^|\s)(\.\.?|[^\s"';&|<>()\x60/]+(?:\/[^\s"';&|<>()\x60]*)?)\s*$/;function r4(Z,z){let $=zZ(z);if(!$||$.index<=0||z[$.index].opaque)return 0;let J=b(Z);if(!J.trustworthy||J.substitutions.length>0||J.segments.length!==1)return 0;let[Y]=J.segments;if(Y.redirects.size>0||Y.words.length!==z.length)return 0;if(Y.words.some((X,Q)=>R(X.text)!==z[Q].text))return 0;return x(Y)===$.index?$.index:0}function t4(Z,z){let $=0;if(Z==="git")$=z.findIndex((Y)=>Y.text==="rm"||Y.text==="clean")+1;let J=!1;return z.slice($).filter((Y)=>{if(!J&&Y.text==="--")return J=!0,!1;if(!J&&Y.text.startsWith("-")&&!Y.opaque)return!1;return J=!0,!0})}var e4=new Set(["--agent","--spool","--files","--info","--config"]),Z5=new Set(["--spool","--files","--info","--config"]),$5=new Set(["--json","--local","--help","-h","--version","--identity"]),a1={"--agent":/^[^-]/,"--retention":/^(?:\d+(?:\.\d+)?|never)$/},J5=new Set(["--to"]);function z5(Z){let z=[],$=0;for(;$<Z.length&&Z[$].text.startsWith("-");$++){let X=Z[$];if(X.opaque)return null;if(e4.has(X.text)){let Q=Z[++$];if(!Q||Q.opaque)return null;if(Z5.has(X.text))z.push(Q)}else if(!$5.has(X.text))return null}let J=Z[$];if(!J||J.opaque||!Q2.has(J.text))return null;let Y=!1;for($++;$<Z.length;$++){let X=Z[$];if(Y||X.opaque||X.text==="-"||!X.text.startsWith("-")){z.push(X);continue}if(X.text==="--"){Y=!0;continue}let Q=X.text.indexOf("="),B=Q<0?X.text:X.text.slice(0,Q);if(J5.has(B)){if(Q>=0)z.push({text:X.text.slice(Q+1),opaque:!1});else if(Z[$+1]&&!Z[$+1].text.startsWith("-"))z.push(Z[++$]);continue}let K=Z[$+1];if(Q<0&&Object.hasOwn(a1,B)&&K&&!K.opaque&&a1[B].test(K.text))$++}return z}function Y5(Z){let z=Z.split(`
|
|
28
|
+
`),$=[],J=[],Y=0;while(Y<z.length){let X=Y,Q=z[Y++].replace(/\r$/,""),B=[];for(let K=0;K<Q.length;K++){let H=Q[K],M=J[J.length-1];if(H==="\\"){K++;continue}if(H==="$"&&Q[K+1]==="("&&Q[K+2]==="("){let V=Q.indexOf("))",K+3);if(V<0)return null;K=V+1;continue}if(H==="$"&&Q[K+1]==="("){J.push(0),K++;continue}if(H==="$"&&Q[K+1]==="[")return null;if(H==="$"&&Q[K+1]==="{"){let V=Q.indexOf("}",K+2);if(V<0||/['"\x60$]|<</.test(Q.slice(K+2,V)))return null;K=V;continue}if(H==="`"){let V=Q.indexOf("`",K+1);if(V<0)return null;K=V;continue}if(M==='"'){if(H==='"')J.pop();continue}if(H==="'"){let V=Q.indexOf("'",K+1);if(V<0)return null;K=V;continue}if(H==='"'){J.push('"');continue}if(H==="#"&&(K===0||/[\s;&|()]/.test(Q[K-1])))break;if(H==="("&&Q[K+1]==="("&&(K===0||/[\s;&|(]/.test(Q[K-1]))){let V=Q.indexOf("))",K+2);if(V<0)return null;K=V+1;continue}if(typeof M==="number"&&(H==="("||H===")")){if(H==="(")J[J.length-1]=M+1;else if(M===0)J.pop();else J[J.length-1]=M-1;continue}if(H==="<"&&Q[K+1]==="<"){if(Q[K+2]==="<"){K+=2;continue}let V=DZ(Q,K);if(!V)return null;B.push({marker:V,from:K}),K=V.end-1}}for(let{marker:K,from:H}of B){let M=Y;for(;;){if(Y>=z.length)return null;let V=z[Y++].replace(/\r$/,"");if(K.stripTabs)V=V.replace(/^\t+/,"");if(V===K.delimiter)break}$.push({line:X,from:H,to:K.end,start:M,end:Y-1,quoted:K.quoted})}}return J.length===0?$:null}var X5=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"]),Q5=new Set([".","source","eval","env","alias","hash"]),K5=new Set(["tee","cp","mv","install","ln"]),V2=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"]),B5=new Set(["add","commit","tag","notes","status","diff","log","show","rev-parse","branch","switch","push","fetch","hash-object","apply"]),H5=new Set(["pr","issue","api","release","gist"]);function M5(Z,z){let $=Z[z];if($==="gh")return H5.has(Z[z+1]??"");if($!=="git")return V2.has($);for(let J=z+1;J<Z.length;J++){let Y=Z[J];if(Y==="-C")J++;else if(Y==="--no-pager"||Y==="-P")continue;else return!Y.startsWith("-")&&B5.has(Y)}return!1}function V5(Z,z){for(let $=z+1;$<Z.length;$++){let J=Z[$];if(J==="\\")$++;else if(J==='"')return $;else if(J==="$"&&Z[$+1]==="("){if($=G2(Z,$+1),$<0)return-1}else if(J==="`"){if($=Z.indexOf("`",$+1),$<0)return-1}}return-1}function G2(Z,z){let $=0;for(let J=z;J<Z.length;J++){let Y=Z[J];if(Y==="\\")J++;else if(Y==="'"||Y==="`"){if(J=Z.indexOf(Y,J+1),J<0)return-1}else if(Y==='"'){if(J=V5(Z,J),J<0)return-1}else if(Y==="(")$++;else if(Y===")"&&--$===0)return J}return-1}function U2(Z){let z=[],$=!1;for(let J=0;J<Z.length;J++){let Y=Z[J];if(Y==="\\")J++;else if(Y==="'"&&!$){let X=Z.indexOf("'",J+1);if(X<0)return null;J=X}else if(Y==='"')$=!$;else if(Y==="$"&&Z[J+1]==="("){let X=G2(Z,J+1);if(X<0)return null;let Q=Z.slice(J+2,X);if(Z[J+2]==="("){if(/\$\(|\x60/.test(Q))return null}else z.push(Q);J=X}else if(Y==="`"){let X=Z.indexOf("`",J+1);if(X<0)return null;z.push(Z.slice(J+1,X)),J=X}}return $?null:z}function G5(Z){if(/[<>]\(/.test(Z))return!0;let z=[],$=[Z];for(let Y=0;$.length>0;Y++){if(Y>64)return!0;let X=$.shift(),Q=b(X),B=U2(X);if(!Q.trustworthy||!B)return!0;z.push(...Q.segments),$.push(...new Set([...Q.substitutions,...B]))}let J=new Set;for(let Y of z){let X=Y.words.map((K)=>R(K.text));for(let K of Y.redirects)J.add(c(X[K]??""));let Q=x(Y);if(Q<0)continue;let B=c(X[Q]);if(K5.has(B)){for(let K of X.slice(Q+1))if(!K.startsWith("-"))J.add(c(K))}if(B==="dd"){for(let K of X)if(K.startsWith("of="))J.add(c(K.slice(3)))}}J.delete("");for(let Y of z){for(let H of Y.words){let M=c(R(H.text));if(X5.has(M)||/^(?:python|pypy|node|perl|ruby|php|lua)[0-9.]+$/.test(M))return!0}let X=x(Y),Q=Y.words.map((H,M)=>({text:R(H.text),at:M})).filter(({at:H})=>!Y.redirects.has(H));if(Q.some(({text:H,at:M})=>(X<0||M<X)&&SZ.test(H)))return!0;if(X<0)continue;let B=Y.words[X].text,K=R(B);if(/[$\x60]/.test(B)||K.includes("/")||Q5.has(K)||J.has(K))return!0;if(!M5(Q.filter(({at:H})=>H>=X).map(({text:H})=>H),0))return!0}return!1}function U5(Z){if(!Z.includes("<<"))return null;let z=Y5(Z);if(!z||z.length===0)return null;let $=Z.split(`
|
|
29
|
+
`),J=[...$],Y=[];for(let Q of z){let B=$.slice(Q.start,Q.end);if(!Q.quoted&&B.some((K)=>/\$\(|\x60/.test(K)))return null;Y.push(B.join(`
|
|
30
|
+
`));for(let K=Q.start;K<=Q.end;K++)J[K]=""}let X=[...J];for(let Q of[...z].reverse()){let B=X[Q.line];X[Q.line]=B.slice(0,Q.from)+" ".repeat(Q.to-Q.from)+B.slice(Q.to)}return G5(X.join(`
|
|
31
|
+
`))?null:{outer:J.join(`
|
|
32
|
+
`),bodies:Y}}var j5="/";function K0(Z,z,$){if(!Z)return[];let J=b(Z).trustworthy?Z:UZ(Z),Y=U5(Z);return[...J===Z?[]:K0(J,z,$),...Y?[...Z2(Y.outer,z,$),...Y.bodies.flatMap((X)=>K0(X,z,j5))]:Z2(Z,z,$)]}var W5=/(\s*&&\s*|\s*\|\|\s*|;\s*|\n+)/,F5=/^(?:'[^']*'|"[^"$\x60\\]*")$/;function r1(Z,z,$=!1){let J=[],Y=0;for(let B of z)J.push(Y),Y+=B.length;let X=b(Z);if(!X.trustworthy||!$&&X.substitutions.length>0)return null;let Q=X.segments.flatMap((B)=>B.words).filter((B)=>z.some((K,H)=>H%2===1&&J[H]<B.end&&J[H]+K.length>B.start));return Q.length>0?{lexed:X,offsets:J,words:Q}:null}function t1(Z,z,$=[]){if(c0(z)!=="read")return!1;let J=x(Z),Y=Z.words.filter((M,V)=>!Z.redirects.has(V)),X=zZ(Y.map((M)=>i0(M.text)));if(X===null)return!1;let Q=[J<0?1/0:J,X.index<0?1/0:Z.words.indexOf(Y[X.index])];if(Z.words.some((M,V)=>V<Math.max(...Q)&&!Z.redirects.has(V)&&SZ.test(R(M.text))))return!1;if([J<0?null:Z.words[J].text,X.index<0?null:Y[X.index].text].every((M)=>M===null||V2.has(c(R(M)))))return!0;let K=Y.filter((M)=>!$.includes(M)),H=K.map((M)=>R(M.text));return QZ(K.map((M)=>M.text).join(" "))==="read"&&QZ(H.join(" "))==="read"&&!H.some((M)=>K2.has(M))}function N5(Z,z,$,J){let Y=(X)=>X.start<J&&X.end>$;if(!z.words.some(Y))return!1;return z.lexed.segments.filter((X)=>X.words.some(Y)).some((X)=>X0(X))}var e1=(Z,z)=>Z.slice(z.words[0].start,z.words[z.words.length-1].end);function D5(Z,z,$,J){let Y=(Q)=>Q.start<J&&Q.end>$,X=z.words.filter(Y);if(X.length===0||X.some((Q)=>!F5.test(Q.text)))return!1;for(let Q of z.lexed.segments.filter((B)=>B.words.some(Y)))if(!t1(Q,e1(Z,Q),z.words))return!1;for(let Q of X){let B=Q.text.slice(1,-1);if(B.includes("<<"))return!1;let K=b(B);if(!K.trustworthy||K.substitutions.length>0)return!1;if(!K.segments.every((H)=>t1(H,e1(B,H))))return!1}return!0}function Z2(Z,z,$){if(!Z)return[];let J=z2(z),Y=(U)=>J.some((j)=>U===j||U.startsWith(`${j}${l0}`)),X=Z.split(W5),Q=r1(Z,X),B=Q??r1(Z,X,!0),K=[],H=[$],M=new Set([$]),V=!0,G=[];for(let U=0;U<X.length;U+=2){let j=U===0?"":X[U-1].trim();if(j==="||")V=!1;else if(j!=="&&")V=!0;if(j!=="&&"||!V)H=[...M];let F=X[U],L=(F.match(/^[\s({]*/)?.[0].match(/\(/g)??[]).length,y=(F.match(/[\s)}]*$/)?.[0].match(/\)/g)??[]).length;for(let D=0;D<L;D++)G.push({current:[...H],reachable:new Set(M),certain:V});let E=o4(F),l=Q!==null&&D5(Z,Q,Q.offsets[U],Q.offsets[U]+F.length),q=!l&&(B!==null&&N5(Z,B,B.offsets[U],B.offsets[U]+F.length)||Q0(F.trim())),N=E.match(/^cd(?:\s+(?:-[A-Za-z@]+|--))*(?:\s+([^\s;&|<>()\x60]+))?$/),A=N?null:E.match(/(?:^|\s)cd(?:\s+(?:-[A-Za-z]+|--))*\s+([^\s;&|<>()\x60]+)/);if(A){for(let D of o1(A[1],H,z)??[])M.add(D);V=!1,H=[...M]}let h=m0(z),w=J.map((D)=>m0(D.slice(z.length+1))).join("|"),CZ=new RegExp(`(?:~|\\$HOME"*|\\$\\{HOME\\}"*|${h}"*)/(?:${w})`),G1=new RegExp(`(${CZ.source})([^\\s"';&|<>()\`]*|$)`,"g"),U1=(D)=>{let f=[],g;G1.lastIndex=0;while((g=G1.exec(D))!==null)f.push(IZ(cZ(g[0],z)).replace(/\/+$/,""));return f},j1=B===null?0:B.offsets[U],W1=(D)=>D.start<j1+F.length&&D.end>j1,k2=B!==null&&B.words.some(W1)?pZ({segments:B.lexed.segments.filter((D)=>D.words.some(W1))}):[F.trim(),E].flatMap((D)=>{let f=b(D);if(!f.trustworthy)f=b(UZ(D));return f.trustworthy?pZ(f):[]}),W0=i4(E).map((D,f)=>{let g=f===0?[...new Set(k2)]:[],PZ=!1,OZ=X2(D).replace(c4,(N0,HZ)=>{if(!HZ||/[$\x60]/.test(HZ))PZ=!0;if(HZ)g.push(HZ);return" "}),LZ=l?"read":q?"delete":c0(OZ);return{commandPart:OZ,operands:g,op:PZ&&LZ==="read"?"write":LZ}}),x2=W0.some((D)=>D.op==="delete")?"delete":W0.some((D)=>D.op==="write")?"write":"read",F0=H.filter(Y);if(q)for(let D of F0)K.push({path:D,op:"delete"});for(let D of W0){let f=!1;for(let k of U1(D.commandPart))f=!0,K.push({path:k,op:x2});for(let k of D.operands){let n=U1(k);for(let p of n)K.push({path:p,op:"write"});if(n.length>0)continue;for(let p of F0)K.push({path:IZ(iZ(p,cZ(k,z))),op:"write"})}if(f||D.op==="read")continue;let g=d4(D.commandPart),PZ=r4(D.commandPart,g),OZ=c(g[PZ]?.text??""),LZ=g.slice(PZ+1),N0=((OZ==="trash"?z5(LZ):null)??t4(OZ,LZ)).map((k)=>k.opaque?".":k.text),HZ=D.op==="delete"||/(?:^|\s)\\?(?:[^\s;&|<>()]*\/)?(?:mkdir|mkfile|touch|tee|truncate|install|mv)(?:\s|$)/.test(D.commandPart)||/(?:^|\s)sed(?:\s|$)/.test(D.commandPart)&&/(?:^|\s)(?:-i\S*|--in-place\S*)(?:\s|$)/.test(D.commandPart),AZ=[];if(HZ)for(let k of N0.length>0?N0:["."])AZ.push({operand:k,op:D.op});else{let k=D.commandPart.match(a4),n=g.at(-1);if(AZ.push({operand:k?k[1]:!n||n.opaque?".":n.text,op:D.op}),/(?:^|\s)(?:cp|ln|install|mv)(?:\s|$)/.test(D.commandPart))g.forEach((p,F1)=>{let MZ,D0=p.text.match(/^-[A-Za-z]*?t(.*)$/),sZ=p.text.match(/^(--t[a-z-]*)(?:=(.*))?$/);if(D0&&!p.text.startsWith("--"))MZ=D0[1]?{text:D0[1],opaque:p.opaque}:g[F1+1];else if(sZ&&"--target-directory".startsWith(sZ[1]))MZ=sZ[2]!==void 0?{text:sZ[2],opaque:p.opaque}:g[F1+1];if(MZ)AZ.push({operand:MZ.opaque||!MZ.text?".":MZ.text,op:D.op})});if(/(?:^|\s)(?:python3?|node|bun)\b[^;&|]*\s+-[ce](?:\s|$)/.test(D.commandPart))AZ.push({operand:".",op:D.op})}for(let k of F0)for(let{operand:n,op:p}of AZ)K.push({path:IZ(iZ(k,cZ(n,z))),op:p})}if(N){let D=o1(N[1],H,z);if(D){for(let f of D)M.add(f);if(V)H=D}else V=!1}for(let D=0;D<y&&G.length>0;D++)({current:H,reachable:M,certain:V}=G.pop())}return K}var _5=/^\s*\*\*\*\s+(Add File|Update File|Delete File):\s+(\S+)\s*$/gm;function I5(Z,z){let $=[],J;while((J=_5.exec(Z))!==null){let Y=J[1]==="Delete File"?"delete":"write";$.push({path:IZ(iZ(z,J[2])),op:Y})}return $}function j2(Z,z={}){let $=[];if(Z.hook_event_name!=="PreToolUse")return{output:{continue:!0},warnings:$};let J=typeof Z.tool_name==="string"?Z.tool_name:"",Y=z.home??$2(),X=z2(Y),Q=m4(process.env,Y);if(J==="Bash"){let G=GZ(Z);if(!G)return{output:{continue:!0},warnings:$};let U=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd(),j=K0(G,Y,U);j.unshift(...YZ(G,()=>K0(G,Y,U))??[]);for(let F of j)for(let L of X){let y=w0(F.path,L,Q,F.op);if(y.blocked)return{output:{decision:"block",reason:y.reason},warnings:$}}return{output:{continue:!0},warnings:$}}let B=Z.tool_input??{},K=typeof Z.cwd==="string"&&Z.cwd?Z.cwd:process.cwd();if(k4.has(J)){let G=typeof B.patch==="string"?B.patch:"";if(!G)return{output:{continue:!0},warnings:$};let U=I5(G,K);for(let j of U)for(let F of X){let L=w0(j.path,F,Q,j.op);if(L.blocked)return{output:{decision:"block",reason:L.reason},warnings:$}}return{output:{continue:!0},warnings:$}}if(!f4.has(J))return{output:{continue:!0},warnings:$};let H=typeof B.file_path==="string"?B.file_path:typeof B.path==="string"?B.path:typeof B.notebook_path==="string"?B.notebook_path:null;if(!H)return{output:{continue:!0},warnings:$};let M=cZ(H,Y),V=J2(M)?IZ(M):iZ(K,M);for(let G of X){let U=w0(V,G,Q,"write");if(U.blocked)return{output:{decision:"block",reason:U.reason},warnings:$}}return{output:{continue:!0},warnings:$}}var T5=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"]),q5=new Set(["payload","client_payload","inputs","config","metadata","output","properties","custom_properties","variables"]),D2=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"]),_2=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"]),C5=new Set(["test","startswith","endswith","contains","inside","has","in","index","rindex","indices","ltrimstr","rtrimstr","join","split","flatten","limit"]),P5=new Set(["@text","@json","@csv","@tsv","@sh","@base64","@uri","@html"]);class n0 extends Error{}var P=()=>{throw new n0};function d0(Z,z){let $=[],J="",Y=z+1;while(Y<Z.length){let X=Z[Y];if(X==='"'){if(J)$.push(J);return{end:Y+1,parts:$}}if(X==="\\"){let Q=Z[Y+1];if(Q==="("){let B=1,K=Y+2;while(K<Z.length&&B>0){let H=Z[K];if(H==='"'){K=d0(Z,K).end;continue}if(H==="(")B++;else if(H===")")B--;K++}if(B!==0)P();if(J)$.push(J),J="";$.push({src:Z.slice(Y+2,K-1)}),Y=K;continue}if(Q===void 0)P();J+=Q,Y+=2;continue}J+=X,Y++}return P()}function I2(Z){let z=[],$=0,J=["?//","|=","+=","-=","*=","/=","%=","//=","==","!=","<=",">=","//","|",",","+","-","*","/","%","<",">","=","(",")","[","]","{","}",":",";","?"];while($<Z.length){let Y=Z[$];if(/\s/.test(Y)){$++;continue}if(Y==="#")P();if(Y==='"'){let K=d0(Z,$);z.push({t:"str",parts:K.parts}),$=K.end;continue}if(Y==="."){if(Z[$+1]===".")P();let K=/^[A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($+1));if(K){z.push({t:"field",name:K[0]}),$+=1+K[0].length;continue}if(Z[$+1]==='"'){let H=d0(Z,$+1);if(H.parts.some((M)=>typeof M!=="string"))P();z.push({t:"field",name:H.parts.join("")}),$=H.end;continue}z.push({t:"dot"}),$++;continue}if(Y==="$"||Y==="@"){let K=/^[@$][A-Za-z_][A-Za-z0-9_]*/.exec(Z.slice($));if(!K||Y==="$")P();z.push({t:"fmt",name:K[0]}),$+=K[0].length;continue}let X=/^[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?/.exec(Z.slice($));if(X){z.push({t:"num"}),$+=X[0].length;continue}let Q=/^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*/.exec(Z.slice($));if(Q){z.push({t:"ident",name:Q[0]}),$+=Q[0].length;continue}let B=J.find((K)=>Z.startsWith(K,$));if(!B)P();z.push({t:"op",v:B}),$+=B.length}return z}var O5=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 o0{tokens;at=0;constructor(Z){this.tokens=Z}parse(){if(this.tokens.length===0)P();let Z=this.pipe();if(this.at!==this.tokens.length)P();return Z}peek(){return this.tokens[this.at]}isOp(Z){let z=this.peek();return!!z&&z.t==="op"&&z.v===Z}isIdent(Z){let z=this.peek();return!!z&&z.t==="ident"&&z.name===Z}expectOp(Z){if(!this.isOp(Z))P();this.at++}pipe(){let Z=this.comma();if(this.isIdent("as"))P();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.pipe()};return Z}comma(){let Z=this.alt();while(this.isOp(","))this.at++,Z={k:"comma",a:Z,b:this.alt()};return Z}alt(){let Z=this.or();if(this.isOp("//"))return this.at++,{k:"alt",a:Z,b:this.alt()};return Z}or(){let Z=this.and();while(this.isIdent("or"))this.at++,Z={k:"bool",a:Z,b:this.and()};return Z}and(){let Z=this.cmp();while(this.isIdent("and"))this.at++,Z={k:"bool",a:Z,b:this.cmp()};return Z}cmp(){let Z=this.add();for(let z of["==","!=","<=",">=","<",">"])if(this.isOp(z))return this.at++,{k:"bool",a:Z,b:this.add()};for(let z of["=","|=","+=","-=","*=","/=","%=","//=","?//"])if(this.isOp(z))P();return Z}add(){let Z=this.mul();while(this.isOp("+")||this.isOp("-"))this.at++,Z={k:"arith",a:Z,b:this.mul()};return Z}mul(){let Z=this.unary();while(this.isOp("*")||this.isOp("/")||this.isOp("%"))this.at++,Z={k:"arith",a:Z,b:this.unary()};return Z}unary(){if(this.isOp("-"))return this.at++,{k:"neg",of:this.postfix()};return this.postfix()}objectValue(){let Z=this.unary();if(this.isOp("|"))this.at++,Z={k:"pipe",a:Z,b:this.objectValue()};return Z}postfix(){let Z=this.primary();for(;;){let z=this.peek();if(!z)return Z;if(z.t==="field"){this.at++,Z={k:"field",name:z.name,of:Z};continue}if(z.t==="dot"&&this.tokens[this.at+1]?.t==="op"&&this.tokens[this.at+1].v==="["){this.at++;continue}if(z.t==="op"&&z.v==="?"){this.at++,Z={k:"opt",of:Z};continue}if(z.t==="op"&&z.v==="["){Z=this.bracket(Z);continue}return Z}}bracket(Z){if(this.expectOp("["),this.isOp("]"))return this.at++,{k:"iter",of:Z};if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}let z=this.pipe();if(this.isOp(":")){if(this.at++,!this.isOp("]"))this.pipe();return this.expectOp("]"),{k:"slice",of:Z}}return this.expectOp("]"),{k:"index",of:Z,key:z}}primary(){let Z=this.peek();if(!Z)return P();switch(this.at++,Z.t){case"dot":return{k:"dot"};case"field":return{k:"field",name:Z.name};case"num":return{k:"lit"};case"str":return this.stringNode(Z.parts);case"fmt":{if(!P5.has(Z.name))P();let z=this.peek();if(z?.t==="str")return this.at++,{k:"fmt",name:Z.name,str:this.stringNode(z.parts)};return{k:"fmt",name:Z.name}}case"ident":{if(O5.has(Z.name))P();if(Z.name==="map"||D2.has(Z.name)||_2.has(Z.name)){let z=[];if(this.isOp("(")){this.at++,z.push(this.pipe());while(this.isOp(";"))this.at++,z.push(this.pipe());this.expectOp(")")}return{k:"call",name:Z.name,args:z}}return P()}case"op":{if(Z.v==="("){let z=this.pipe();return this.expectOp(")"),z}if(Z.v==="["){if(this.isOp("]"))return this.at++,{k:"array"};let z=this.pipe();return this.expectOp("]"),{k:"array",of:z}}if(Z.v==="{")return this.object();return P()}}return P()}stringNode(Z){let z=[];for(let $ of Z){if(typeof $==="string")continue;z.push(new o0(I2($.src)).parse())}return z.length===0?{k:"str",parts:z,text:Z.join("")}:{k:"str",parts:z}}object(){let Z=[];if(this.isOp("}"))return this.at++,{k:"object",entries:Z};for(;;){let z=this.peek();if(!z)P();this.at++;let $;if(z.t==="ident")$=z.name;else if(z.t==="str"){if(z.parts.some((J)=>typeof J!=="string"))P();$=z.parts.join("")}else P();if(this.isOp(":"))this.at++,Z.push({key:"static",value:this.objectValue()});else Z.push({key:"static",value:{k:"field",name:$}});if(this.isOp(",")){this.at++;continue}return this.expectOp("}"),{k:"object",entries:Z}}}}function a0(Z){if(typeof Z==="object"&&"union"in Z)return Z.union.every(a0);return Z==="safe"||typeof Z==="object"&&T5.has(Z.leaf)}var dZ=(...Z)=>Z.every(a0)?"safe":"tainted";function s0(...Z){let z=[];for(let $ of Z)if(typeof $==="object"&&"union"in $)z.push(...$.union);else z.push($);return z.length===1?z[0]:{union:z}}function B0(Z,z){return typeof Z==="object"&&"union"in Z?s0(...Z.union.map(z)):z(Z)}var H0=(Z)=>typeof Z==="object"&&("leaf"in Z)&&q5.has(Z.leaf),t=(Z)=>B0(Z,(z)=>z==="safe"?"safe":z==="tainted"||H0(z)?"tainted":"unknown");function W2(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 F2(Z,z,$){return B0(Z,(J)=>{if(J==="safe"||J==="tainted")return J;if(H0(J))return"tainted";if(J==="root"&&$.rootScalars.has(z))return"safe";return{leaf:z}})}function O(Z,z,$){switch(Z.k){case"dot":return z;case"field":return F2(Z.of?O(Z.of,z,$):z,Z.name,$);case"iter":return t(O(Z.of,z,$));case"index":{let J=O(Z.of,z,$);if(Z.key.k==="str"&&Z.key.text!==void 0)return F2(J,Z.key.text,$);if(Z.key.k==="lit")return t(J);return O(Z.key,z,$),"tainted"}case"slice":return B0(O(Z.of,z,$),(J)=>J==="root"?"unknown":H0(J)?"tainted":J);case"opt":return O(Z.of,z,$);case"lit":return"safe";case"str":return dZ(...Z.parts.map((J)=>O(J,z,$)));case"fmt":return Z.str?O(Z.str,z,$):z;case"array":return Z.of?dZ(O(Z.of,z,$)):"safe";case"object":return dZ(...Z.entries.map((J)=>O(J.value,z,$)));case"pipe":return O(Z.b,O(Z.a,z,$),$);case"comma":return s0(O(Z.a,z,$),O(Z.b,z,$));case"alt":return s0(O(Z.a,z,$),O(Z.b,z,$));case"bool":return O(Z.a,z,$),O(Z.b,z,$),"safe";case"arith":return dZ(O(Z.a,z,$),O(Z.b,z,$));case"neg":return O(Z.of,z,$);case"call":return L5(Z,z,$)}}var N2=(Z)=>B0(Z,(z)=>z==="root"?"unknown":H0(z)?"tainted":z);function L5(Z,z,$){let{name:J,args:Y}=Z;if(C5.has(J)&&J!=="limit"&&!Y.every(W2))P();switch(J){case"map":if(Y.length!==1)P();return dZ(O(Y[0],t(z),$));case"select":if(Y.length!==1)P();return O(Y[0],z,$),z;case"limit":if(Y.length!==2||!W2(Y[0]))P();return O(Y[1],z,$);case"first":case"last":if(Y.length>1)P();return Y.length===1?O(Y[0],z,$):t(z);case"min":case"max":return t(z);case"sort_by":case"group_by":case"unique_by":if(Y.length!==1)P();return O(Y[0],t(z),$),N2(z);case"min_by":case"max_by":if(Y.length!==1)P();return O(Y[0],t(z),$),t(z);case"any":case"all":case"isempty":for(let X of Y)O(X,"unknown",$);return"safe"}if(D2.has(J))return"safe";if(_2.has(J))return N2(z);return P()}function T2(Z,z={}){if(typeof Z!=="string"||!Z.trim()||Z.length>4096)return!1;try{let $=new o0(I2(Z)).parse();return a0(O($,"root",{rootScalars:z.rootScalars??new Set}))}catch($){if($ instanceof n0)return!1;return!1}}var X1="composite output withheld: signed-link shape; use bounded scalar projections per class disposition 799310",T={refused:!1},I=(Z)=>({refused:!0,rule:Z}),r0=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"]),t0=new Set(["assignees","author","closed","closedAt","createdAt","id","isPinned","labels","number","reactionGroups","state","stateReason","subIssuesSummary","title","updatedAt","url"]),q2=new Set(["apiUrl","author","createdAt","databaseId","id","isDraft","isImmutable","isLatest","isPrerelease","name","publishedAt","tagName","tarballUrl","targetCommitish","uploadUrl","url","zipballUrl"]),C2=new Set(["answerChosenAt","answerChosenBy","answered","author","closed","closedAt","createdAt","id","labels","locked","number","reactionGroups","state","stateReason","title","updatedAt","url"]),A5=new Set(["assignees","author","authorAssociation","closedAt","commentsCount","createdAt","id","isDraft","isLocked","isPullRequest","labels","number","repository","state","title","updatedAt","url"]),y5=new Set(["author","committer","id","parents","repository","sha","url"]),R5=new Set(["bucket","completedAt","event","name","startedAt","state","workflow"]);function L2(Z){let z=[];for(let $=0;$<Z.length;$++){let J=Z[$];if(J==="\\"){$++;continue}if(J==="'"){let Y=Z.indexOf("'",$+1);if(Y<0)return!1;$=Y;continue}if(J==='"'){$++;while($<Z.length&&Z[$]!=='"')$+=Z[$]==="\\"?2:1;continue}if(J==="{"){z.push({list:!1});continue}if(z.length===0)continue;if(J===","||J==="."&&Z[$+1]===".")z[z.length-1].list=!0;else if(J==="}"&&z.pop().list)return!0}return!1}function TZ(Z){let z="",$=!1,J=0,Y=(X)=>Z[X]==="`"||Z[X]==="$"&&/[A-Za-z_{(@*#?$!0-9-]/.test(Z[X+1]??"");while(J<Z.length){let X=Z[J];if(X==="\\"){z+=Z[J+1]??"",J+=2;continue}if(X==="$"&&Z[J+1]==="'"){$=!0,z+=X,J++;continue}if(X==="'"){let Q=Z.indexOf("'",J+1);if(Q<0){$=!0,z+=Z.slice(J+1);break}z+=Z.slice(J+1,Q),J=Q+1;continue}if(X==='"'){J++;while(J<Z.length&&Z[J]!=='"'){if(Z[J]==="\\"&&/[$`"\\\n]/.test(Z[J+1]??"")){z+=Z[J+1],J+=2;continue}if(Y(J))$=!0;z+=Z[J],J++}if(J>=Z.length)$=!0;J++;continue}if(Y(J)||X==="*"||X==="?"||X==="[")$=!0;z+=X,J++}if(!$&&Z.includes("{")&&L2(Z))$=!0;return{value:z,opaque:$,raw:Z}}var KZ=(Z)=>Z.slice(Z.lastIndexOf("/")+1);function $1(Z,z="word"){let $=[],J=!1;for(let Y=0;Y<Z.length;Y++){let X=Z[Y];if(X==="\\"){Y++;continue}if(z==="word"&&X==="'"&&!J){let Q=Z.indexOf("'",Y+1);if(Q<0)return{bodies:$,complete:!1};Y=Q;continue}if(z==="word"&&X==='"'){J=!J;continue}if(X==="`"){let Q=Y+1;while(Q<Z.length&&Z[Q]!=="`")Q+=Z[Q]==="\\"?2:1;if(Q>=Z.length)return{bodies:$,complete:!1};$.push(Z.slice(Y+1,Q)),Y=Q;continue}if(X==="$"&&Z[Y+1]==="("){let Q=XZ(Z,Y+1);if(Q<0)return{bodies:$,complete:!1};$.push(Z.slice(Y+2,Q-1)),Y=Q-1}}return{bodies:$,complete:!0}}function qZ(Z,z){let $=new Set(z.values),J={flags:[],positionals:[]},Y=(X,Q)=>({value:X,opaque:Q.opaque,raw:Q.raw});for(let X=0;X<Z.length;X++){let Q=Z[X],B=Q.value;if(B==="--"){J.positionals.push(...Z.slice(X+1));break}if(B.startsWith("--")&&B.length>2){let K=B.indexOf("="),H=K>=0?B.slice(0,K):B;if(K>=0)J.flags.push({name:H,value:Y(B.slice(K+1),Q),inline:!0});else if($.has(H)){let M=Z[X+1];J.flags.push(M?{name:H,value:M}:{name:H,missing:!0}),X++}else J.flags.push({name:H});continue}if(B.startsWith("-")&&B.length>1){for(let K=1;K<B.length;K++){let H="-"+B[K],M=B.slice(K+1);if(M.startsWith("=")){J.flags.push({name:H,value:Y(M.slice(1),Q),inline:!0});break}if(!$.has(H)){J.flags.push({name:H});continue}if(M)J.flags.push({name:H,value:Y(M,Q),inline:!0});else{let V=Z[X+1];J.flags.push(V?{name:H,value:V}:{name:H,missing:!0}),X++}break}continue}J.positionals.push(Q)}return J}function S(Z,...z){let $=!1;for(let J of Z.flags){if(!z.includes(J.name))continue;if(!J.inline){$=!0;continue}let Y=J.value;$=!Y.opaque&&["1","t","T","TRUE","true","True"].includes(Y.value)}return $}var ZZ=(Z,...z)=>Z.flags.filter(($)=>z.includes($.name)),m=["-R","--repo","-q","--jq","-t","--template","--json"],BZ={"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"]}},v5=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"]),b5=new Set(["pr","issue","release","discussion","search","project","api","status"]),E5=new Set(["create","new","checkout","co","close","comment","edit","lock","merge","ready","reopen","revert","review","unlock","update-branch"]),S5=new Set(["create","new","close","comment","delete","develop","edit","lock","pin","reopen","transfer","unlock","unpin"]),f5=new Set(["create","new","delete","delete-asset","download","edit","upload","verify","verify-asset"]),k5=new Set(["create","new","close","comment","delete","edit","lock","reopen","unlock","answer","unanswer"]);function U0(Z,z){let $=ZZ(Z,"--json"),J=[],Y=!1;for(let X of $){if(X.missing){if(z.appendsArgs)Y=!0;continue}if(!X.value)continue;if(X.value.opaque)Y=!0;J.push(...X.value.value.split(",").map((Q)=>Q.trim()).filter(Boolean))}return{present:$.length>0,opaque:Y,fields:J}}function Q1(Z,z){if(S(Z,"--verbose")||ZZ(Z,"-t","--template").length>0)return!1;let $=ZZ(Z,"-q","--jq");return $.length>0&&$.every((J)=>J.value!==void 0&&!J.value.opaque&&T2(J.value.value,{rootScalars:z}))}function K1(Z,z,$,J){let Y=U0(Z,$);if(Y.opaque)return I("unclassifiable");if(Y.fields.every((X)=>z.has(X)))return T;if($.debug)return I("debug-traffic");return Q1(Z)?T:I(J)}function M0(Z,z,$,J,Y){let X=qZ(Z,BZ[z]);if(S(X,"-h","--help"))return T;if(S(X,"-w","--web"))return J.debug?I("debug-traffic"):T;if(Y&&S(X,"-c","--comments"))return I("view-comments");if(!U0(X,J).present)return I(J.debug?"debug-traffic":"view-human");return K1(X,$,J,"json-composite")}function e(Z,z,$,J){let Y=qZ(Z,BZ[z]);if(S(Y,"-h","--help"))return T;if(J.debug&&(S(Y,"-w","--web")||!U0(Y,J).present))return I("debug-traffic");if(S(Y,"-w","--web"))return T;return K1(Y,$,J,"json-composite")}function x5(Z,z){let $=qZ(Z,BZ["pr checks"]);if(S($,"-h","--help"))return T;if(z.debug)return I("debug-traffic");if(S($,"-w","--web"))return T;if(!U0($,z).present)return I("checks-human");return K1($,R5,z,"checks-json")}function h5(Z){let z=new Set(BZ.group.values);for(let $=0;$<Z.length;$++){let J=Z[$].value;if(J==="--")return{sub:Z[$+1],rest:Z.slice($+2)};if(!J.startsWith("-")||J==="-")return{sub:Z[$],rest:[...Z.slice(0,$),...Z.slice($+1)]};if(z.has(J))$++}return{rest:Z}}function w5(Z,z,$){let{sub:J,rest:Y}=h5(z);if(!J)return $.appendsArgs?I("unclassifiable"):T;if(J.opaque)return I("unclassifiable");let X=J.value;if((Z==="pr"?E5:Z==="issue"?S5:Z==="release"?f5:Z==="discussion"?k5:new Set).has(X))return $.debug?I("debug-traffic"):T;if($.appendsArgs&&!(Z==="project"&&X!=="item-list"))return I("unclassifiable");switch(Z){case"pr":if(X==="view")return M0(Y,"pr view",r0,$,!0);if(X==="list"||X==="ls")return e(Y,"pr list",r0,$);if(X==="status")return e(Y,"pr status",r0,$);if(X==="checks")return x5(Y,$);if(X==="diff"){let B=qZ(Y,BZ["pr diff"]);if(S(B,"-h","--help"))return T;if($.debug)return I("debug-traffic");return S(B,"--patch")?I("composite-other"):T}return I("unclassifiable");case"issue":if(X==="view")return M0(Y,"issue view",t0,$,!0);if(X==="list"||X==="ls")return e(Y,"issue list",t0,$);if(X==="status")return e(Y,"issue status",t0,$);return I("unclassifiable");case"release":if(X==="view")return M0(Y,"release view",q2,$,!1);if(X==="list"||X==="ls")return e(Y,"release list",q2,$);return I("unclassifiable");case"discussion":if(X==="view")return M0(Y,"discussion view",C2,$,!0);if(X==="list"||X==="ls")return e(Y,"discussion list",C2,$);return I("unclassifiable");case"search":if(X==="prs"||X==="issues")return e(Y,"search",A5,$);if(X==="commits")return e(Y,"search",y5,$);if(X==="code"||X==="repos")return $.debug?I("debug-traffic"):T;return I("unclassifiable");case"project":{if($.debug)return I("debug-traffic");if(X!=="item-list")return T;let B=qZ(Y,BZ["project item-list"]);if(S(B,"-h","--help"))return T;let K=ZZ(B,"--format");if(K.some((H)=>!H.value||H.value.opaque))return I("unclassifiable");if(K.every((H)=>H.value.value!=="json"))return T;return Q1(B)?T:I("composite-other")}}return I("unclassifiable")}var A2=new Set(["pulls","issues","commits","check-runs","check-suites","statuses","comments","releases","compare","events","discussions","deployments","milestones"]);function g5(Z){let z=Z.value.trim(),$=/^https?:\/\/([^/]+)(\/.*)?$/i.exec(z);if($){let X=$[1].toLowerCase(),Q=$[2]??"/";if(X==="api.github.com"||/^api\./.test(X))z=Q;else if(/^\/api\/v3(?:\/|$)/i.test(Q))z=Q.replace(/^\/api\/v3/i,"");else if(/^\/api\/graphql(?:[/?#]|$)/i.test(Q))z="graphql";else return null}z=z.replace(/[?#].*$/,"");let J=[],Y=[];for(let X of z.split("/")){let Q;try{Q=decodeURIComponent(X)}catch{return null}for(let B of Q.split("/")){if(B===""||B===".")continue;if(B===".."){J.pop(),Y.pop();continue}J.push(B.toLowerCase()),Y.push(Z.opaque&&/[$`]/.test(B)||/[*?[]/.test(B)||L2(B))}}return{segments:J,opaque:Y}}function u5(Z){let z=g5(Z);if(!z)return{kind:"unclassifiable",segments:[]};let{segments:$,opaque:J}=z,Y=(K)=>({kind:K,segments:$});if($.length===1&&$[0]==="graphql")return Y("graphql");if($.length===0)return Y(Z.opaque?"unclassifiable":"other");if(J[0])return Y("unclassifiable");let X,Q=[];if($[0]==="repos")X=$.slice(3),Q=J.slice(3);else if($[0]==="repositories")X=$.slice(2),Q=J.slice(2);if(X){if(($[0]==="repos"?J.slice(1,3):J.slice(1,2)).some(Boolean)){let H=J.findIndex(Boolean),M=$.findIndex((V,G)=>G>H&&!J[G]&&l5.has(V));return Y(M<0?"unclassifiable":P2($.slice(M),J.slice(M)))}return Y(P2(X,Q))}let B=$[0];if(B==="issues")return Y("sensitive");if(B==="user"&&$[1]==="issues")return Y("sensitive");if(B==="orgs"&&$[2]==="issues")return Y("sensitive");if(B==="search")return Y($[1]==="issues"||$[1]==="commits"?"sensitive":$[1]!==void 0&&J[1]?"unclassifiable":"other");if(B==="events"||B==="networks")return Y("sensitive");if((B==="users"||B==="orgs")&&$.slice(2).some((K)=>K==="events"||K==="received_events"||K==="discussions"))return Y("sensitive");if((B==="users"||B==="orgs")&&$[2]==="projectsv2"&&$[4]==="items")return Y("sensitive");if(B==="orgs"&&$[2]==="hooks"&&$[4]==="deliveries"&&$[5]!==void 0||B==="app"&&$[1]==="hook"&&$[2]==="deliveries"&&$[3]!==void 0)return Y("sensitive");if(B==="teams"&&$.includes("discussions"))return Y("sensitive");if(B==="projects"&&$.includes("cards"))return Y("sensitive");if(J.some(Boolean))return Y($.some((K)=>K==="events"||K==="discussions"||K==="issues")?"sensitive":"unclassifiable");return Y("other")}var l5=new Set([...A2,"branches","git","actions","hooks","zipball","tarball"]);function P2(Z,z){let[$,J]=Z;if($===void 0)return"other";if(z[0])return"unclassifiable";if($==="issues"&&/^\d+$/.test(J??"")&&Z[2]==="labels")return"other";if(A2.has($))return"sensitive";if($==="branches"){if(Z.length===1||Z.slice(1).some((Y)=>Y==="protection")||Z[Z.length-1]==="rename")return"other";return z.slice(1).some(Boolean)?"unclassifiable":"sensitive"}if($==="git")return J===void 0||J==="commits"||J==="tags"?"sensitive":z[1]?"unclassifiable":"other";if($==="actions"){if(J===void 0)return"sensitive";if(z[1])return"unclassifiable";if(J==="runs"||J==="jobs"){if(Z[Z.length-1]==="logs"&&Z.length>=4&&!z.some(Boolean))return"download";return"sensitive"}if(J==="workflows"&&Z[3]==="runs")return"sensitive";if(J==="artifacts"&&Z.length===4)return"download";return"other"}if($==="hooks"&&Z[2]==="deliveries"&&Z[3]!==void 0)return"sensitive";if($==="zipball"||$==="tarball")return"download";return"other"}function m5(Z,z){if(z[0]!=="repos"||z.length<5)return!1;let $=z.slice(3),J=(X)=>/^\d+$/.test($[X]??""),Y=(...X)=>$.length===X.length&&X.every((Q,B)=>typeof Q==="number"?J(B):$[B]===Q);if(Z==="DELETE")return Y("issues","comments",0)||Y("pulls","comments",0)||Y("comments",0)||Y("issues","comments",0,"reactions",0)||Y("pulls","comments",0,"reactions",0)||Y("issues",0,"reactions",0)||Y("issues",0,"labels")||$.length===4&&$[0]==="issues"&&J(1)&&$[2]==="labels"||Y("releases",0)||Y("releases","assets",0)||Y("actions","runs",0)||Y("actions","runs",0,"logs")||Y("deployments",0)||Y("milestones",0)||Y("issues",0,"lock");if(Z==="POST")return $.length===4&&$[0]==="actions"&&$[1]==="runs"&&J(2)&&["rerun","rerun-failed-jobs","cancel","force-cancel","approve"].includes($[3])||Y("actions","jobs",0,"rerun")||Y("issues",0,"labels");if(Z==="PUT")return Y("pulls",0,"merge")||Y("pulls",0,"update-branch")||Y("issues",0,"labels")||Y("issues",0,"lock");if(Z==="GET")return Y("pulls",0,"merge");return!1}function p5(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 c5=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"]),i5=new Set(["checkRuns","checkRun","checkSuites","checkSuite","contexts","statusCheckRollup","annotations","CheckRun","CheckSuite","StatusContext","CheckAnnotation","latestStatus","status","statuses"]);function d5(Z){let z=[],$=0;while($<Z.length){let J=Z[$];if(/[\s,\uFEFF]/.test(J)){$++;continue}if(J==="#"){let Q=Z.indexOf(`
|
|
33
|
+
`,$);$=Q<0?Z.length:Q+1;continue}if(Z.startsWith('"""',$)){let Q=$+3;for(;;){let B=Z.indexOf('"""',Q);if(B<0)return null;if(Z[B-1]==="\\"){Q=B+3;continue}$=B+3;break}continue}if(J==='"'){let Q=$+1;while(Q<Z.length&&Z[Q]!=='"'&&Z[Q]!==`
|
|
34
|
+
`)Q+=Z[Q]==="\\"?2:1;if(Z[Q]!=='"')return null;$=Q+1;continue}let Y=/^[_A-Za-z][_0-9A-Za-z]*/.exec(Z.slice($,$+256));if(Y){z.push({kind:"name",text:Y[0]}),$+=Y[0].length;continue}let X=/^-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(Z.slice($,$+64));if(X){$+=X[0].length;continue}if(Z.startsWith("...",$)){z.push({kind:"punct",text:"..."}),$+=3;continue}if("{}()[]:!$@=|&".includes(J)){z.push({kind:"punct",text:J}),$++;continue}return null}return z}function s5(Z){let z=d5(Z);if(!z)return!0;let $=[],J="",Y=0;for(let X=0;X<z.length;X++){let Q=z[X];if(Q.kind==="punct"){if(Q.text==="(")Y++;else if(Q.text===")"){if(Y--,Y<0)return!0}else if(Y===0&&Q.text==="{")$.push(J),J="";else if(Y===0&&Q.text==="}"){if($.pop()===void 0)return!0;J=""}continue}if(Y>0)continue;let B=z[X-1];if(B?.kind==="punct"&&(B.text==="@"||B.text==="$"))continue;if(z[X+1]?.kind==="punct"&&z[X+1].text===":")continue;if(Q.text==="on"&&B?.kind==="punct"&&B.text==="...")continue;if(B?.kind==="name"&&B.text==="on"){J=Q.text;continue}if($.length===0){J=Q.text;continue}if(c5.has(Q.text)||/(?:Url|URL|HTML|Html)$/.test(Q.text))return!0;if(Q.text==="title"&&$.some((K)=>i5.has(K)))return!0;J=Q.text}return Y!==0||$.length!==0}function n5(Z,z){let $=qZ(Z,BZ.api);if(S($,"-h","--help"))return T;let J=$.positionals[0];if(!J)return z.appendsArgs?I("unclassifiable"):T;let Y=u5(J),X=ZZ($,"-X","--method"),Q=X[X.length-1],B=ZZ($,"-f","--raw-field","-F","--field","--input"),K=Q?Q.value&&!Q.value.opaque?Q.value.value.toUpperCase():"?":B.length>0?"POST":"GET",H=m5(K,Y.segments),M=T;if(Y.kind==="unclassifiable")M=I("unclassifiable");else if(Y.kind==="sensitive"&&!H)M=I("api-rest");else if(Y.kind==="graphql")M=o5($);if(z.debug||S($,"--verbose")){if(Y.kind==="download"&&!M.refused)M=I("api-rest");if(M.refused)return z.debug?I("debug-traffic"):M;return T}if(z.appendsArgs&&Y.kind!=="other"&&Y.kind!=="download")return I("unclassifiable");if(!M.refused||S($,"--silent"))return T;if(Q1($,p5(Y.segments)))return T;return M}function o5(Z){if(ZZ(Z,"--input").length>0)return I("unclassifiable");let z=ZZ(Z,"-f","--raw-field","-F","--field"),$=z.filter((J)=>J.value&&/^query=/.test(J.value.value));if($.length===0||z.some((J)=>!J.value))return I("unclassifiable");for(let J of $){let Y=J.value.value.slice(6);if((J.name==="-F"||J.name==="--field")&&Y.startsWith("@")||J.value.opaque)return I("unclassifiable");if(s5(Y))return I("api-graphql")}return T}function G0(Z,z){let $=0;while($<Z.length&&Z[$].value.startsWith("-")&&!Z[$].opaque){if(["--help","-h","--version"].includes(Z[$].value))return T;$++}if($>=Z.length)return z.appendsArgs?I("unclassifiable"):T;let J=Z[$],Y=Z.slice($+1);if(J.opaque)return I("unclassifiable");switch(J.value){case"pr":case"issue":case"release":case"discussion":case"search":case"project":return w5(J.value,Y,z);case"api":return n5(Y,z);case"status":return Y.length>0&&Y.every((X)=>X.value==="-h"||X.value==="--help")?T:I("composite-other");case"help":case"version":return T;case"cs":case"codespace":{let X=Y.findIndex((Q)=>Q.value==="--");if(Y.some((Q)=>Q.value==="ssh")&&X>=0&&X+1<Y.length){let Q=d(Y.slice(X+1).map((B)=>B.value).join(" "),z.depth+1,z.debug);if(Q.refused)return Q}break}}if(!v5.has(J.value))return I("unclassifiable");if(z.debug)return I("debug-traffic");return T}var j0=new Set(["sh","bash","zsh","dash","ksh","ash","mksh","fish"]),a5=new Set(["su","runuser","script","flock"]),r5=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"]),t5=new Map([["bun",["x","exec"]],["npm",["exec","x"]],["deno",["run"]]]),e5=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"]),Z6=new Set(["-b","-c","-D","-E","-e","-F","-I","-i","-J","-L","-l","-m","-O","-o","-p","-Q","-R","-S","-W","-w"]),V0=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/,$6=/^([A-Za-z_][A-Za-z0-9_]*)=([\s\S]*)$/,J6=6;function O2(Z,z){let $,J;for(let Y of Z){let X=$6.exec(Y.value);if(!X)continue;let Q={...Y,value:X[2]};if(X[1]==="GH_DEBUG")$=Q;else if(X[1]==="DEBUG")J=Q}if($)return $.opaque||!["","0","false","no"].includes($.value);if(J&&(J.opaque||["1","true","yes","api"].includes(J.value)))return!0;return z}function B1(Z){let z=b(Z),$=0;return{segments:z.segments.map((Y)=>{let X=Y.words[0],Q=Z.slice($,X.start);return $=Y.words[Y.words.length-1].end,{words:Y.words,redirects:Y.redirects,sepBefore:Q}}),trustworthy:z.trustworthy}}var y2=(Z)=>/(?:^|[^|])\|&?$/.test(Z.trim());function J1(Z,z){if(!j0.has(Z))return!1;if(H1(z))return!1;for(let $=0;$<z.length;$++){let J=z[$].value;if(J==="--")return $+1>=z.length;if(J==="-"||J==="-s")return!0;if(/^[-+][A-Za-z]*[oO]$/.test(J)){$++;continue}if(!J.startsWith("-")&&!J.startsWith("+"))return!1}return!0}function z1(Z){let{segments:z}=B1(Z.trim());if(z.length!==1)return null;let $=z[0],J=x($);if(J<0)return null;let Y=KZ(TZ($.words[J].text).value),X=$.words.slice(J+1).filter((Q,B)=>!$.redirects.has(B+J+1)).map((Q)=>TZ(Q.text));if(Y==="echo")return X.filter((Q,B)=>!(B===0&&/^-[neE]+$/.test(Q.value))).map((Q)=>Q.value).join(" ");if(Y==="printf"){let[Q,...B]=X.filter((H)=>H.value!=="--");if(!Q)return null;let K=0;return Q.value.replace(/\\n/g,`
|
|
35
|
+
`).replace(/%s/g,()=>B[K++]?.value??"")+(K<B.length?" "+B.slice(K).map((H)=>H.value).join(" "):"")}if(Y==="cat"){let Q=Z.indexOf("<<");if(Q<0)return null;let B=DZ(Z,Q),K=Z.indexOf(`
|
|
36
|
+
`,Q);if(!B||K<0)return null;let H=z0(Z,K,[B]);if(H<0)return null;let M=Z.slice(K+1,H);return M.slice(0,M.lastIndexOf(B.delimiter)).replace(/\n$/,"")}return null}function e0(Z,z,$){for(let J of $1(Z).bodies){let Y=z1(J);if(Y===null)continue;let X=d(Y,z+1,$.debug);if(X.refused)return X}return T}function d(Z,z=0,$=!1){if(typeof Z!=="string"||!Z.trim())return T;if(z>J6)return V0.test(Z)?I("unclassifiable"):T;let{segments:J,trustworthy:Y}=B1(Z);if(!Y)return V0.test(Z)?I("unclassifiable"):T;let X=$,Q=(B)=>d(B,z+1,X);for(let B of X6(Z)){if(B.runsBody){let K=Q(B.body);if(K.refused)return K}if(!B.quoted){let K=$1(B.body,"heredoc");if(!K.complete&&V0.test(B.body))return I("unclassifiable");for(let H of K.bodies){let M=Q(H);if(M.refused)return M}}}for(let B=0;B<J.length;B++){let K=J[B];for(let N of K.words){let A=$1(N.text);if(!A.complete&&V0.test(N.text))return I("unclassifiable");for(let h of A.bodies){let w=Q(h);if(w.refused)return w}}let H=x(K),M=K.words.map((N,A)=>({word:TZ(N.text),redirect:K.redirects.has(A)})),V=M.slice(0,H<0?M.length:H).map((N)=>N.word),G=H>=0?KZ(M[H].word.value):"";if(H<0||["export","declare","typeset","readonly","local"].includes(G)){if(X=O2([...V,...M.slice(H+1).map((N)=>N.word)],X),H<0)continue}let U=O2(V,X),j=M.slice(H+1).filter((N)=>!N.redirect).map((N)=>N.word),F=M.slice(H+1).filter((N)=>N.redirect).map((N)=>N.word),L=M[H].word,y=KZ(L.value),E={depth:z,appendsArgs:!1,debug:U};if(H>0&&M[H-1].word.value==="function"){let N=j.filter((h)=>!["{","()","(",")"].includes(h.value)),A=Y1(N,E);if(A.refused)return A;continue}if(B>0&&y2(K.sepBefore)&&J1(y,j)){let N=J[B-1],A=z6(Z,N),h=A===null?null:z1(A);if(h!==null){let w=d(h,z+1,U);if(w.refused)return w}}let l=J[B+1];if(l&&/<\(\s*$/.test(l.sepBefore)&&(j0.has(y)||y==="source"||y===".")){let N=l.words[0].start-l.sepBefore.length+l.sepBefore.lastIndexOf("("),A=XZ(Z,N),h=A<0?null:z1(Z.slice(N+1,A-1));if(h!==null){let w=d(h,z+1,U);if(w.refused)return w}}let q=R2(y,L,j,F,K.words.slice(0,H+1),E);if(q.refused)return q}return T}function z6(Z,z){let $=z.words[0],J=z.words[z.words.length-1];return $&&J?Z.slice($.start,J.end):null}function Y6(Z){let z=KZ(Z.value);return/[$`]/.test(z)||z===""?void 0:z}function R2(Z,z,$,J,Y,X){let Q=X.depth,B=(K)=>d(K,Q+1,X.debug);if(z.opaque){let K=Y6(z);if(K===void 0){let H=$.find((V)=>!V.value.startsWith("-")),M=G0($,X);if(!M.refused)return T;return M.rule!=="unclassifiable"||H!==void 0&&!H.opaque&&b5.has(H.value)?M:T}Z=K}if(Z==="gh")return G0($,X);if(j0.has(Z)){let K=H1($);if(K){let H=B(K.value);if(H.refused||!K.opaque)return H;return e0(K.raw,Q,X)}for(let H of J){let M=B(H.value);if(M.refused)return M;if(H.opaque){let V=e0(H.raw,Q,X);if(V.refused)return V}}return T}if(a5.has(Z)){let K=$.findIndex((M)=>M.value==="-c"||M.value==="--command"||/^-[A-Za-z]*c$/.test(M.value)),H=K>=0?$[K+1]:void 0;return H?B(H.value):Z1($,X)}if(Z==="eval"||Z==="watch"){let K=$;if(Z==="watch"){let M=0;while(M<$.length&&$[M].value.startsWith("-")){if($[M].value==="--"){M++;break}if(["-n","--interval","-q","--equexit"].includes($[M].value))M++;M++}K=$.slice(M)}let H=B(K.map((M)=>M.value).join(" "));if(H.refused)return H;for(let M of K){let V=e0(M.raw,Q,X);if(V.refused)return V}return T}if(Z==="env")return B(uZ([...Y.map((K)=>TZ(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(Z6.has(V))K++}let H=$.slice(K+1);if(H[0]?.value==="--")H.shift();let M=H.map((V)=>V.value).join(" ");return M?B(M):T}if(Z==="xargs"){let K=0,H=!1;for(;K<$.length;K++){let M=$[K].value;if(M==="--"){K++;break}if(!M.startsWith("-"))break;if(/^-I|^-i|^--replace/.test(M))H=!0;if(e5.has(M))K++}return Y1($.slice(K),{depth:Q,appendsArgs:!H,debug:X.debug})}if(Z==="find"){for(let K=0;K<$.length;K++){if(!["-exec","-execdir","-ok","-okdir"].includes($[K].value))continue;let H=K+1;while(H<$.length&&$[H].value!==";"&&$[H].value!=="+")H++;let M=Y1($.slice(K+1,H),X);if(M.refused)return M;K=H}return T}if(r5.has(Z))return Z1($,X);if(t5.get(Z)?.includes($[0]?.value??""))return Z1($.slice(1),X);return T}function Y1(Z,z){if(Z.length===0)return T;let $=KZ(Z[0].value);if($==="gh")return G0(Z.slice(1),z);if(j0.has($)){let J=H1(Z.slice(1));return J?d(J.value,z.depth+1,z.debug):T}return R2($,Z[0],Z.slice(1),[],[],z)}function Z1(Z,z){let $=Z.findIndex((J)=>!J.opaque&&KZ(J.value)==="gh"&&(J.value==="gh"||J.value.includes("/")));return $>=0?G0(Z.slice($+1),z):T}function H1(Z){for(let z=0;z<Z.length;z++){let $=Z[z].value;if($==="--")return;if(!$.startsWith("-")&&!$.startsWith("+"))return;if($==="-c"||/^-[A-Za-z]+$/.test($)&&$.includes("c"))return Z.slice(z+1).find((J)=>!J.value.startsWith("-")||J.value==="-");if(/^[-+][A-Za-z]*[oO]$/.test($))z++}return}function X6(Z){let z=[],$=0;for(;;){let J=Z.indexOf("<<",$);if(J<0)break;if($=J+2,Z[J+2]==="<"||J>0&&Z[J-1]==="<"){$=J+3;continue}let Y=DZ(Z,J);if(!Y)continue;let X=Z.lastIndexOf(`
|
|
37
|
+
`,J)+1,Q=Z.indexOf(`
|
|
38
|
+
`,J);if(Q<0)continue;let B=z0(Z,Q,[Y]),K=B<0?Z.slice(Q+1):Z.slice(Q+1,B),H=B<0?K:K.slice(0,Math.max(0,K.lastIndexOf(Y.delimiter))).replace(/\n$/,""),M=Z.slice(X,J)+" HEREDOC_OPERATOR "+Z.slice(Y.end,Q);z.push({body:H,runsBody:Q6(M),quoted:Y.quoted})}return z}function Q6(Z){let{segments:z}=B1(Z),$=z.findIndex((B)=>B.words.some((K)=>K.text==="HEREDOC_OPERATOR"));if($<0)return!1;let J=(B)=>{let K=x(B);if(K<0)return{verb:"",args:[]};let H=B.words.slice(K+1).filter((M)=>M.text!=="HEREDOC_OPERATOR").map((M)=>TZ(M.text));return{verb:KZ(TZ(B.words[K].text).value),args:H}},{verb:Y,args:X}=J(z[$]);if(Y==="ssh"||J1(Y,X))return!0;if((Y==="source"||Y===".")&&["/dev/stdin","/dev/fd/0","/proc/self/fd/0"].includes(X[0]?.value??""))return!0;let Q=z[$+1];if(Y==="cat"&&Q&&y2(Q.sepBefore)){let B=J(Q);return B.verb==="ssh"||J1(B.verb,B.args)}return!1}var K6=/(?:^|[^A-Za-z0-9_.-])gh(?:$|[^A-Za-z0-9_.-])/;function v2(){return{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:X1}}}var B6=new Set(["Bash","Monitor"]);function b2(Z){if(Z?.hook_event_name!=="PreToolUse"||!B6.has(Z.tool_name??""))return{continue:!0};let z=GZ(Z);if(!z.trim())return{continue:!0};try{return d(z).refused?v2():{continue:!0}}catch{return K6.test(z)?v2():{continue:!0}}}function V1(Z){if(Z!=="trash-guard"&&Z!=="workspace-repos-guard")throw Error("Invalid safety capability")}function S2(Z,z){V1(Z);let $=Z,J=JSON.parse(z);if(!J||Array.isArray(J)||J.hook_event_name!=="PreToolUse"||typeof J.tool_name!=="string"||!J.tool_input||typeof J.tool_input!=="object"||Array.isArray(J.tool_input)||typeof J.cwd!=="string"||!E2(J.cwd))throw Error("Invalid safety input");if(J.tool_name==="Bash"&&typeof J.tool_input.command!=="string")throw Error("Invalid shell input");if(J.tool_name==="Monitor"&&J.tool_input.command!==void 0&&typeof J.tool_input.command!=="string")throw Error("Invalid monitor input");let Y=J.hasna_execution;if(Y!==void 0&&(!Y||Object.keys(Y).sort().join()!=="agent,schema"||Y.schema!=="hasna.hooks.execution.v1"||typeof Y.agent!=="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(Y.agent)))throw Error("Invalid execution capability");let X=Y===void 0?void 0:{runtime:process.execPath,home:M1(),path:process.env.PATH,agent:Y.agent};if(X&&(!E2(X.runtime)||!X.path))throw Error("Invalid bound execution context");if(["apply_patch","ApplyPatch","functions.apply_patch"].includes(J.tool_name)){if(J.tool_input.command!==void 0&&J.tool_input.patch!==void 0&&J.tool_input.command!==J.tool_input.patch)throw Error("Conflicting patch aliases");let y=J.tool_input.command??J.tool_input.patch;if(typeof y!=="string")throw Error("Invalid patch input");J.tool_input={...J.tool_input,command:y,patch:y}}let Q=J.tool_name==="Monitor",B=J.tool_name==="Bash"||Q&&typeof J.tool_input.command==="string",K=Q&&B?{...J,tool_name:"Bash"}:J,H=(y)=>({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:y}}),M=j2(K).output,V=b2(K),G=K.tool_input.command,U=()=>NZ(G,{home:M1(),cwd:J.cwd}).handoffHits.length>0,j=B&&(U()||!!YZ(G,U)),F=$==="trash-guard"&&(!Q||B)?c1(K,{home:M1(),cwd:J.cwd,findTrash:rZ,inspectTrash:bZ,execution:X}):{continue:!0};if(Q&&F.hookSpecificOutput?.permissionDecision==="allow")F=H("[trash-guard] A deletion inside a Monitor command is refused; run it with the Bash tool, where it is redirected into trash.");let L=M.decision==="block"?H(M.reason):V.hookSpecificOutput?V:j?H("[workspace-repos-guard] Deletion under a protected repository checkout is refused."):F;return JSON.stringify({verdict:"continue"in L?null:L})}var f2=process.argv[1];V1(f2);process.stdout.write(S2(f2,await Bun.stdin.text()));
|