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