@tokmizer/plugin 0.9.67 → 0.9.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.codex-plugin/plugin.json +1 -1
  3. package/dist/bin/tkr-agent-hook.js +13 -12
  4. package/dist/bin/tkr-codex-hook.js +75 -69
  5. package/dist/bin/tkr-copilot-hook.js +12 -11
  6. package/dist/bin/tkr-crush-hook.js +12 -11
  7. package/dist/bin/tkr-cursor-hook.js +12 -11
  8. package/dist/bin/tkr-daemon.js +134 -128
  9. package/dist/bin/tkr-droid-hook.js +12 -11
  10. package/dist/bin/tkr-exec +0 -0
  11. package/dist/bin/tkr-exec.js +83 -78
  12. package/dist/bin/tkr-gemini-hook.js +12 -11
  13. package/dist/bin/tkr-grok-hook.js +12 -11
  14. package/dist/bin/tkr-junie-hook.js +12 -11
  15. package/dist/bin/tkr-processor.js +102 -96
  16. package/dist/bin/tkr-qwen-hook.js +12 -11
  17. package/dist/bin/tkr-shim.js +85 -80
  18. package/dist/bin/tkr-trae-hook.js +12 -11
  19. package/dist/bin/tkr-zcode-hook.js +12 -11
  20. package/dist/bin/tkr.js +281 -277
  21. package/dist/hooks-host/post-tool-use.js +95 -90
  22. package/dist/hooks-host/pre-tool-use.js +13 -12
  23. package/dist/hooks-host/reducer-stop.js +24 -24
  24. package/dist/hooks-host/session-recap.js +1 -1
  25. package/dist/index.js +95 -90
  26. package/dist/native/manifest.json +12 -12
  27. package/dist/native/single.json +12 -12
  28. package/dist/native/tkr-exec-darwin-arm64 +0 -0
  29. package/dist/native/tkr-exec-darwin-x64 +0 -0
  30. package/dist/native/tkr-exec-linux-arm64 +0 -0
  31. package/dist/native/tkr-exec-linux-x64 +0 -0
  32. package/dist/native/tkr-exec-win32-arm64.exe +0 -0
  33. package/dist/native/tkr-exec-win32-x64.exe +0 -0
  34. package/hooks/hooks.json +7 -2
  35. package/hooks/on-session-start.mjs +12 -0
  36. package/package.json +7 -7
  37. package/scripts/install-native.mjs +7 -3
@@ -1,20 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __tkrCreateRequire } from "node:module"; const require = __tkrCreateRequire(import.meta.url);
3
- function M(e=5e3){return new Promise(t=>{let n=[],r=process.stdin,o=!1,i=()=>{o||(o=!0,clearTimeout(l),r.off("data",s),r.pause(),r.unref?.(),t(Buffer.concat(n).toString("utf8")))},s=u=>{n.push(Buffer.isBuffer(u)?u:Buffer.from(u))},l=setTimeout(i,e);r.on("data",s).once("end",i).once("error",i),r.resume()})}import{appendFileSync as $t,chmodSync as Tt,mkdirSync as Ct,existsSync as Et,readFileSync as to,rmSync as no}from"node:fs";import{dirname as Ot,join as vt}from"node:path";import bt from"node:os";import{join as yt}from"node:path";function E(){return process.env.TOKMIZER_HOME||yt(bt.homedir(),".tokmizer")}import{readFileSync as wt,renameSync as St,statSync as xt,writeFileSync as At}from"node:fs";function Ee(e,t,n){try{if(xt(e).size<=t)return;let r=wt(e,"utf8").split(`
4
- `).filter(l=>l.trim()!==""),o=[],i=0;for(let l=r.length-1;l>=0;l-=1){let u=r[l],a=Buffer.byteLength(u)+1;if(i+a>n)break;o.push(u),i+=a}o.reverse();let s=`${e}.tmp-${process.pid}`;At(s,o.length?`${o.join(`
3
+ function G(e=5e3){return new Promise(t=>{let n=[],r=process.stdin,o=!1,i=()=>{o||(o=!0,clearTimeout(l),r.off("data",s),r.pause(),r.unref?.(),t(Buffer.concat(n).toString("utf8")))},s=u=>{n.push(Buffer.isBuffer(u)?u:Buffer.from(u))},l=setTimeout(i,e);r.on("data",s).once("end",i).once("error",i),r.resume()})}import{appendFileSync as Vt,chmodSync as Kt,mkdirSync as qt,existsSync as Yt,readFileSync as Yo,rmSync as Xo}from"node:fs";import{dirname as Xt,join as Qt}from"node:path";import zt from"node:os";import{join as Jt}from"node:path";function S(){return process.env.TOKMIZER_HOME||Jt(zt.homedir(),".tokmizer")}import{readFileSync as Bt,renameSync as Wt,statSync as Gt,writeFileSync as Zt}from"node:fs";function ze(e,t,n){try{if(Gt(e).size<=t)return;let r=Bt(e,"utf8").split(`
4
+ `).filter(l=>l.trim()!==""),o=[],i=0;for(let l=r.length-1;l>=0;l-=1){let u=r[l],a=Buffer.byteLength(u)+1;if(i+a>n)break;o.push(u),i+=a}o.reverse();let s=`${e}.tmp-${process.pid}`;Zt(s,o.length?`${o.join(`
5
5
  `)}
6
- `:"",{mode:384}),St(s,e)}catch{}}var Rt="usage.jsonl";var Oe=2*1024*1024;function Pt(){return vt(E(),Rt)}function y(e,t,n=Pt()){try{let r=Ot(n);Et(r)||Ct(r,{recursive:!0,mode:448});let o=e.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";$t(n,`{"t":${Math.floor(Date.now()/1e3)},"s":"${o}","o":${t?1:0}}
7
- `,{mode:384}),Tt(n,384),Ee(n,Oe,Oe/2)}catch{}}import{spawnSync as bn}from"node:child_process";import{existsSync as W,readFileSync as G,readdirSync as oe}from"node:fs";import{homedir as R}from"node:os";import{fileURLToPath as yn}from"node:url";import{dirname as qe,join as p,resolve as wn}from"node:path";function It(e,t){let n=e.slice(0,t).split(/\r?\n/);return[n.length,n.pop().length+1]}function Nt(e,t,n){let r=e.split(/\r?\n/),o="",i=(Math.log10(t+1)|0)+1;for(let s=t-1;s<=t+1;s++){let l=r[s-1];l&&(o+=s.toString().padEnd(i," "),o+=": ",o+=l,o+=`
6
+ `:"",{mode:384}),Wt(s,e)}catch{}}var en="usage.jsonl";var Je=2*1024*1024;function tn(){return Qt(S(),en)}function y(e,t,n=tn()){try{let r=Xt(n);Yt(r)||qt(r,{recursive:!0,mode:448});let o=e.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";Vt(n,`{"t":${Math.floor(Date.now()/1e3)},"s":"${o}","o":${t?1:0}}
7
+ `,{mode:384}),Kt(n,384),ze(n,Je,Je/2)}catch{}}import{accessSync as fn,chmodSync as dn,constants as pn,existsSync as se,mkdirSync as mn,readdirSync as gn,readFileSync as hn,realpathSync as qe,renameSync as kn,unlinkSync as _n,writeFileSync as bn}from"node:fs";import{basename as Se,dirname as O,join as T,sep as D}from"node:path";import yn from"node:os";import{realpathSync as Be}from"node:fs";import{delimiter as sn,join as j}from"node:path";import un from"node:os";import{basename as nn}from"node:path";var rn={exec:"tkr-exec",processor:"tkr-processor",daemon:"tkr-daemon","shim-run":"tkr-shim"},on={codex:"tkr-codex-hook",cursor:"tkr-cursor-hook",gemini:"tkr-gemini-hook",agent:"tkr-agent-hook",copilot:"tkr-copilot-hook",droid:"tkr-droid-hook",trae:"tkr-trae-hook",qwen:"tkr-qwen-hook",crush:"tkr-crush-hook",junie:"tkr-junie-hook",zcode:"tkr-zcode-hook",grok:"tkr-grok-hook",context:"tkr-context-hook","pre-tool-use":"pre-tool-use","post-tool-use":"post-tool-use","session-recap":"session-recap","session-start":"on-session-start","reducer-session-start":"reducer-session-start","reducer-prompt-submit":"reducer-prompt-submit","reducer-stop":"reducer-stop","command-expansion":"command-expansion"};function ie(e){let t=nn(e).replace(/\.(m?js|ts)$/,"");if(t==="tkr")return[];for(let[n,r]of Object.entries(rn))if(r===t)return[n];for(let[n,r]of Object.entries(on))if(r===t)return["hook",n];return null}function Z(){return!1}function We(e,t){try{return Be(e)===Be(t)}catch{return!1}}function be(e=process.env.PATH??"",t=process.platform,n=process.execPath){let r=t==="win32"?"tkr.exe":"tkr";for(let o of e.split(t==="win32"?";":sn)){if(!o||o.includes("node_modules"))continue;let i=j(o,r);if(We(i,n))return i}if(t!=="win32"){let o=un.homedir();for(let i of[j(o,".local","bin",r),j(o,".local","share","tokmizer","current","dist","bin",r),j("/opt/homebrew/bin",r),j("/usr/local/bin",r),j("/home/linuxbrew/.linuxbrew/bin",r)])if(We(i,n))return i}return n}import{rmSync as ln,statSync as an}from"node:fs";import{join as Ge}from"node:path";function Ze(){return Ge(S(),"shims")}function ye(){return Ge(S(),"fail-open")}var cn=24*36e5;function A(e=Date.now()){try{if(e-an(ye()).mtimeMs<cn)return!0;ln(ye(),{force:!0})}catch{}return!1}function Ve(){return`[ -f ${P(ye())} ]`}function P(e){return`'${e.replace(/'/g,"'\\''")}'`}function Ke(e){if(!e.startsWith("'")||!e.endsWith("'")||e.length<2)return null;let n=e.slice(1,-1).split("'\\''");return n.some(r=>r.includes("'"))?null:n.join("'")}var Xe=1,V="tkr-shim.stable",Qe=/^(?:0|[1-9]\d{0,5})\.(?:0|[1-9]\d{0,5})\.(?:0|[1-9]\d{0,5})$/;function wn(){return T(S(),"bin","tkr-shim-launch")}function Sn(){return T(S(),"bin","tkr-run")}function Ye(){return T(process.env.CLAUDE_CONFIG_DIR||T(yn.homedir(),".claude"),"plugins","cache","tokmizer","tokmizer")}function xn(e){let t=O(O(O(e)));return Qe.test(Se(t))&&Se(O(t))==="tokmizer"?O(t):null}function xe(e){return/[\n\r]/.test(e)||e.includes(`${D}_npx${D}`)||e.includes(`${D}.bun${D}install${D}cache${D}`)}function $e(e){let t=e.match(/^(.*)[\\/]Cellar[\\/]([^\\/]+)[\\/][^\\/]+[\\/](.*)$/);if(!t)return e;let n=T(t[1],"opt",t[2],t[3]);try{return qe(n)===qe(e)?n:e}catch{return e}}function $n(e=process.execPath){return xe(e)?"":$e(e)}function An(e,t=Z()){if(t&&ie(e)){let o=be();return{single:xe(o)?"":$e(o),js:"",cache:Ye(),node:""}}let n=$n(),r=xn(e);return r?{single:"",js:"",cache:r,node:n}:{single:"",js:xe(e)?"":$e(e),cache:Ye(),node:n}}function Tn(e){try{return fn(e,pn.X_OK),!0}catch{return!1}}function Cn(e){let t=null,n=-1,r;try{r=gn(e)}catch{return null}for(let o of r){if(!Qe.test(o))continue;let i=T(e,o);if(!se(T(i,"dist","bin","tkr-shim.js"))||!se(T(i,"dist","bin",V)))continue;let[s,l,u]=o.split(".").map(Number),a=s*1e6+l*1e3+u;a>n&&(n=a,t=i)}return t}function we(e){return e.single&&Tn(e.single)||e.js&&se(e.js)&&(Se(e.js)!=="tkr-shim.js"||se(T(O(e.js),V)))?!0:e.cache!==""&&Cn(e.cache)!==null}function vn(e,t){return["_tk_t=",`if [ -n "$_tk_j" ] && [ -f "${t}" ] && { [ "\${_tk_j##*/}" != tkr-shim.js ] || [ -f "\${_tk_j%/*}/${V}" ]; }; then _tk_t=${t}; fi`,'if [ -z "$_tk_t" ] && [ -n "$_tk_k" ] && [ -d "$_tk_k" ]; then'," _tk_b=-1",' for _tk_r in "$_tk_k"/*/; do'," _tk_v=${_tk_r%/}; _tk_v=${_tk_v##*/}"," case $_tk_v in *[!0-9.]*|.*|*.|*..*|0[0-9]*|*.0[0-9]*|*[0-9][0-9][0-9][0-9][0-9][0-9][0-9]*) continue ;; [0-9]*.[0-9]*.[0-9]*) ;; *) continue ;; esac"," case ${_tk_v#*.*.} in *.*) continue ;; esac",` [ -f "\${_tk_r}dist/bin/${e}" ] && [ -f "\${_tk_r}dist/bin/${V}" ] || continue`," _tk_1=${_tk_v%%.*}; _tk_2=${_tk_v#*.}; _tk_3=${_tk_2#*.}; _tk_2=${_tk_2%%.*}"," _tk_v=$((_tk_1 * 1000000 + _tk_2 * 1000 + _tk_3))",` if [ "$_tk_v" -gt "$_tk_b" ]; then _tk_b=$_tk_v; _tk_t=\${_tk_r}dist/bin/${e}; fi`," done","fi",'if [ -z "$_tk_t" ]; then',` _tk_d=${P(Ze())}`," set -f; _tk_o=$IFS; IFS=:"," for _tk_e in $PATH; do"," case $_tk_e in /*/node_modules/*|*/node_modules) continue ;; /*) ;; *) continue ;; esac",' [ ! "$_tk_e" -ef "$_tk_d" ] || continue',' for _tk_g in "$_tk_e/../lib/node_modules/@tokmizer/plugin/dist/bin" "$_tk_e/../opt/tokmizer/libexec/lib/node_modules/@tokmizer/plugin/dist/bin"; do',` if [ -f "$_tk_g/${V}" ] && [ -f "$_tk_g/${e}" ]; then _tk_t=$_tk_g/${e}; break 2; fi`," done"," done"," IFS=$_tk_o; set +f","fi","_tk_x=",'if [ -n "$_tk_t" ]; then',' for _tk_x in "$_tk_n" "$(command -v node 2>/dev/null)" /opt/homebrew/bin/node /usr/local/bin/node /usr/bin/node ""; do',' [ -n "$_tk_x" ] && [ -x "$_tk_x" ] && break'," done","fi"]}function En(e){return["#!/bin/sh",`_tk_f=${Xe}`,`_tk_s=${P(e.single)}`,`_tk_j=${P(e.js)}`,`_tk_k=${P(e.cache)}`,`_tk_n=${P(e.node)}`,'[ "$#" -gt 0 ] || exit 0',`if ! ${Ve()}; then`,' if [ -n "$_tk_s" ] && [ -x "$_tk_s" ]; then exec "$_tk_s" exec "$@"; fi',...vn("tkr-exec.js","${_tk_j%/*}/tkr-exec.js").map(t=>` ${t}`),' if [ -n "$_tk_t" ]; then'," _tk_r=${_tk_t%/*}",' if [ -f "$_tk_r/tkr-exec" ] && [ -s "$_tk_r/tkr-exec" ] && [ -x "$_tk_r/tkr-exec" ]; then exec "$_tk_r/tkr-exec" "$@"; fi',' if [ -n "$_tk_x" ] && [ -s "$_tk_t" ]; then exec "$_tk_x" "$_tk_t" "$@"; fi'," fi","fi",'exec "$@"',""].join(`
8
+ `)}function et(e){let t=Sn(),n=An(T(O(e),"tkr-shim.js")),r=Rn(t);if(r&&r.format===Xe&&we(r.target)&&JSON.stringify(r.target)===JSON.stringify(n))return t;if(!we(n))return r&&we(r.target)?t:null;let o=`${t}.${process.pid}.tmp`;try{return mn(O(t),{recursive:!0,mode:448}),bn(o,En(n),{mode:493}),dn(o,493),kn(o,t),t}catch{try{_n(o)}catch{}return null}}function On(e){let t=l=>{let u=e.match(new RegExp(`^${l}=(.*)$`,"m"));return u?l==="_tk_f"?u[1]:Ke(u[1]):null},n=Number(t("_tk_f")),r=t("_tk_s"),o=t("_tk_j"),i=t("_tk_k"),s=t("_tk_n")??"";return!Number.isInteger(n)||r===null||o===null||i===null?null:{format:n,target:{single:r,js:o,cache:i,node:s}}}function Rn(e=wn()){try{return On(hn(e,"utf8"))}catch{return null}}import{spawnSync as kr}from"node:child_process";import{existsSync as M,readFileSync as Q,readdirSync as de}from"node:fs";import{homedir as I}from"node:os";import{fileURLToPath as _r}from"node:url";import{dirname as bt,join as p,resolve as br}from"node:path";function Nn(e,t){let n=e.slice(0,t).split(/\r?\n/);return[n.length,n.pop().length+1]}function Pn(e,t,n){let r=e.split(/\r?\n/),o="",i=(Math.log10(t+1)|0)+1;for(let s=t-1;s<=t+1;s++){let l=r[s-1];l&&(o+=s.toString().padEnd(i," "),o+=": ",o+=l,o+=`
8
9
  `,s===t&&(o+=" ".repeat(i+n+2),o+=`^
9
- `))}return o}var f=class e extends Error{line;column;codeblock;constructor(t,n){let[r,o]=It(n.toml,n.ptr),i=Nt(n.toml,r,o);super(`Invalid TOML document: ${t}
10
+ `))}return o}var f=class e extends Error{line;column;codeblock;constructor(t,n){let[r,o]=Nn(n.toml,n.ptr),i=Pn(n.toml,r,o);super(`Invalid TOML document: ${t}
10
11
 
11
- ${i}`,n),this.line=r,this.column=o,this.codeblock=i}static x(t,n,r){throw new e(t,{toml:n.s,ptr:r??n.p})}};function X(e){let t=e.p,n=e.s.charCodeAt(e.p++),r=n,o=n===39,i=n===e.s.charCodeAt(e.p)&&n===e.s.charCodeAt(e.p+1);i&&((n=e.s.charCodeAt(e.p+=2))===10?e.p++:n===13&&e.s.charCodeAt(e.p+1)===10&&(e.p+=2));let s="",l=e.p,u=0;for(;e.p<e.s.length;e.p++)if(n=e.s.charCodeAt(e.p),i&&(n===10||n===13&&e.s.charCodeAt(e.p+1)===10))u=u&&3;else if(n<32&&n!==9||n===127)f.x("control characters are not allowed in strings",e);else if((!u||u===3)&&n===r&&(!i||e.s.charCodeAt(e.p+1)===r&&e.s.charCodeAt(e.p+2)===r)){if(i&&(e.s.charCodeAt(e.p+3)===r&&e.p++,e.s.charCodeAt(e.p+3)===r&&e.p++),!u){let a=e.s.slice(l,e.p);s=s?s+a:a}return e.p+=i?3:1,s}else if(!u)!o&&n===92&&(s+=e.s.slice(l,l=e.p),u=1);else if(u===1)if(n===120||n===117||n===85){let a=e.p++-1,c=0,d=n===120?2:n===117?4:8;for(let _=0;_<d;_++,e.p++){let m=e.s.charCodeAt(e.p),h=m>=48&&m<=57?m-48:m>=65&&m<=70?m-65+10:m>=97&&m<=102?m-97+10:-1;h<0&&f.x("invalid non-hex character in unicode escape",e),c=c<<4|h}(c<0||c>1114111||c>=55296&&c<=57343)&&f.x("invalid unicode escape",e,a),s+=String.fromCodePoint(c),l=e.p--,u=0}else i&&(n===32||n===9)?u=2:(n===98?s+="\b":n===116?s+=" ":n===110?s+=`
12
- `:n===102?s+="\f":n===114?s+="\r":n===101?s+="\x1B":n===34?s+='"':n===92?s+="\\":f.x("unrecognised escape sequence",e),l=e.p+1,u=0);else n!==32&&n!==9&&(u===2&&f.x("invalid escape: only line-ending whitespace may be escaped",e,l),u=!o&&n===92?1:0,l=e.p);f.x("unfinished string",e,t)}var Ht=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i,U=class e extends Date{#t=!1;#n=!1;#e=null;constructor(t,n,r){let o=!0,i=!0,s="Z",l;if(typeof t=="string")if(n)e:{if(n<3){if(+t.slice(11,13)>23){t="";break e}n===2?(s=null,t+="Z"):(l=t.charCodeAt(t.length-1))!==90&&l!==122&&(s=t.slice(t.length-6)),r&&(t=t.slice(0,10)+"T"+t.slice(11))}else n===4&&(t=+t.slice(0,2)>23?"":`0000-01-01T${t}Z`);o=n!==4,i=n!==3}else{let u=t.match(Ht);u?(u[1]||(o=!1,t=`0000-01-01T${t}`),i=!!u[2],i&&t[10]===" "&&(t=t.replace(" ","T")),u[2]&&+u[2]>23?t="":(s=u[3]||null,!s&&i&&(t+="Z"))):t=""}super(t),isNaN(this.getTime())||(this.#t=o,this.#n=i,this.#e=s)}isDateTime(){return this.#t&&this.#n}isLocal(){return!this.#t||!this.#n||!this.#e}isDate(){return this.#t&&!this.#n}isTime(){return this.#n&&!this.#t}isValid(){return this.#t||this.#n}toISOString(){let t=super.toISOString();if(this.isDate())return t.slice(0,10);if(this.isTime())return t.slice(11,23);if(this.#e===null)return t.slice(0,-1);if(this.#e==="Z"||this.#e==="z")return t;let n=+this.#e.slice(1,3)*60+ +this.#e.slice(4,6);return n=this.#e[0]==="-"?n:-n,new Date(this.getTime()-n*6e4).toISOString().slice(0,-1)+this.#e}static wrapAsOffsetDateTime(t,n="Z"){let r=new e(t);return r.#e=n,r}static wrapAsLocalDateTime(t){let n=new e(t);return n.#e=null,n}static wrapAsLocalDate(t){let n=new e(t);return n.#n=!1,n.#e=null,n}static wrapAsLocalTime(t){let n=new e(t);return n.#t=!1,n.#e=null,n}};function b(e,t=10){return t===16?e>47&&e<58||e>64&&e<71||e>96&&e<103:e>47&&e<48+t}function de(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function J(e,t){let n=e.p,r=e.s.charCodeAt(e.p);if(r===91||r===123){e.d--||f.x("document contains excessively nested structures. aborting.",e);let o=r===91?Pe(e):Re(e);return e.d++,o}return r===34||r===39?X(e):r===116?((e.s.charCodeAt(++e.p)!==114||e.s.charCodeAt(++e.p)!==117||e.s.charCodeAt(++e.p)!==101)&&f.x("invalid value",e,n),e.p++,!0):r===102?((e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==108||e.s.charCodeAt(++e.p)!==115||e.s.charCodeAt(++e.p)!==101)&&f.x("invalid value",e,n),e.p++,!1):r===43||r===45?Q(e,e.p,e.s.charCodeAt(++e.p),44-r,t):e.s.charCodeAt(e.p+4)===45&&e.s.charCodeAt(e.p+7)===45?Lt(e,r,t):e.s.charCodeAt(e.p+2)===58?Dt(e,r,t):Q(e,e.p,r,0,t)}function Q(e,t,n,r,o){let i=n,s=0,l=!1;if(i===105)return(e.s.charCodeAt(++e.p)!==110||e.s.charCodeAt(++e.p)!==102)&&f.x("invalid value",e,t),e.p++,(r||1)/0;if(i===110)return(e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==110)&&f.x("invalid value",e,t),e.p++,NaN;if(i===48){if(++e.p>=e.s.length||de(i=e.s.charCodeAt(e.p),o))return e.bi===!0?0n:0;if(!r){if(i===120)return fe(e,t,16,o);if(i===98)return fe(e,t,2,o);if(i===111)return fe(e,t,8,o)}i===46?s=2:i===101||i===69?s=4:f.x("illegal leading zero",e,t)}else b(i)||f.x("invalid value",e,t);for(;++e.p<e.s.length&&(i=e.s.charCodeAt(e.p),!de(i,o));)s||(s=1),i===95?(s&1||f.x("illegal underscore",e),s+=11,l=!0):s===1&&i===46?s=2:(s===1||s===3)&&(i===101||i===69)?s=4:s===4&&(i===43||i===45)||(b(i)?s>9?s-=11:s&1||s++:f.x("illegal character in numeric literal",e));if(!s){let a=(n-48)*(r||1);return e.bi===!0?BigInt(a):a}s&1||f.x("unfinished numeric value",e,t);let u=e.s.slice(t,e.p);return l&&(u=u.replaceAll("_","")),s>1?parseFloat(u):ve(e,u,10,t)}function fe(e,t,n,r){let o,i=1;for(;++e.p<e.s.length&&(o=e.s.charCodeAt(e.p),!de(o,r));)o===95?(i&1&&f.x("illegal underscore",e),i=3):b(o,n)?i&1&&i--:f.x("illegal character in numeric literal",e);i&1&&f.x("unfinished numeric value",e);let s=e.s.slice(t+2,e.p);return i&&(s=s.replaceAll("_","")),ve(e,s,n,t)}function ve(e,t,n,r){if(e.bi!==!0)e:{let o=parseInt(t,n);if(!Number.isSafeInteger(o)){if(e.bi)break e;f.x("integer value cannot be represented losslessly",e,r)}return o}return BigInt(n===10?t:(n===2?"0b":n===8?"0o":"0x")+t)}function Lt(e,t,n){let r=e.p++,o;if(!b(t)||!b(e.s.charCodeAt(e.p++))||!b(e.s.charCodeAt(e.p++))||!b(e.s.charCodeAt(e.p++)))return Q(e,e.p=r,t,0,n);if(e.p+=5,b(e.s.charCodeAt(e.p++))||f.x("invalid date-time: date part is malformed",e,r),e.p>=e.s.length||((t=e.s.charCodeAt(e.p))!==32||(o=!0,!b(e.s.charCodeAt(e.p+1))))&&t!==84&&t!==116){let s=e.s.slice(r,e.p);return z(e,s,3,!1,r)}if(e.s.charCodeAt(e.p+=3)!==58&&f.x("invalid date-time: time part is malformed",e,r),e.s.charCodeAt(e.p+=3)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;b(e.s.charCodeAt(++e.p)););if(t=e.s.charCodeAt(e.p)){if(t===90||t===122){let s=e.s.slice(r,++e.p);return z(e,s,1,o,r,"[+00:00]")}if(t===43||t===45){let s=e.s.slice(r,e.p+=6);return z(e,s,1,o,r,!e.ld&&"["+e.s.slice(e.p-6,e.p)+"]")}}let i=e.s.slice(r,e.p);return z(e,i,2,o,r)}function Dt(e,t,n){let r=e.p;if(!b(t)||!b(e.s.charCodeAt(++e.p)))return Q(e,--e.p,t,0,n);if(e.s.charCodeAt(e.p+=4)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;b(e.s.charCodeAt(++e.p)););let o=e.s.slice(r,e.p);return z(e,o,4,!1,r)}function z(e,t,n,r,o,i){if(e.ld){let s=new U(t,n,r);return s.isValid()||f.x("invalid date",e,o),s}try{switch(i&&(t+=i),n){case 1:return Temporal.ZonedDateTime.from(t);case 2:return Temporal.PlainDateTime.from(t);case 3:return Temporal.PlainDate.from(t);case 4:return Temporal.PlainTime.from(t)}}catch(s){f.x(s instanceof Error?s.message:""+s,e,o)}}function jt(e){for(;e.p<e.s.length;e.p++){let t=e.s.charCodeAt(e.p);if(t===10)break;if(t===13&&e.s.charCodeAt(e.p+1)===10){e.p++;break}(t<32&&t!==9||t===127)&&f.x("control characters are not allowed in comments",e)}}function S(e,t,n){let r;for(;e.p<e.s.length;){for(;e.p<e.s.length&&((r=e.s.charCodeAt(e.p))===32||r===9||!t&&(r===10||r===13&&e.s.charCodeAt(e.p+1)===10));)e.p++;if(n||r!==35)break;jt(e)}}function ee(e,t=61){let n,r=0,o=[],i,s=e.s.charCodeAt(n=e.p);do{if(s===t)return r||f.x("unexpected end of key",e),r===1&&o.push(e.s.slice(i,e.p)),e.p++,o;s===46?(r||f.x("illegal empty bare key",e),r===1&&o.push(e.s.slice(i,e.p)),r=0):!r&&(s===34||s===39)?(s===e.s.charCodeAt(e.p+1)&&s===e.s.charCodeAt(e.p+2)&&f.x("illegal quoted key: multiline strings are not allowed",e),o.push(X(e)),r=2,e.p--):s===32||s===9?r===1&&(o.push(e.s.slice(i,e.p)),r=2):r===2||s<48&&s!==45||s>57&&s<65||s>90&&s<97&&s!==95||s>122?f.x("illegal character in key",e):r||(r=1,i=e.p)}while(s=e.s.charCodeAt(++e.p));f.x("incomplete key-value: cannot find end of key",e,n)}function Re(e){let t=e.p++,n=Object.create(null),r=new Set,o;for(;e.p<e.s.length;){if(S(e),(o=e.s.charCodeAt(e.p))===125)return e.p++,n;let i,s=n,l=!1,u=e.p,a=ee(e);for(let d=0;d<a.length;d++){d&&(s=l?s[i]:s[i]=Object.create(null)),i=a[d],(l=Object.hasOwn(s,i))&&(typeof s[i]!="object"||r.has(s[i]))&&f.x("trying to redefine an already defined value",e,u);let _=i==="__proto__";if(e.uk&&(_||i==="constructor")){s=e.uk!==1&&f.x("document contains an unsafe property",e,u);break}!l&&_&&Object.defineProperty(s,i,{enumerable:!0,configurable:!0,writable:!0})}l&&f.x("trying to redefine an already defined value",e,u),S(e,!0,!0);let c=J(e,125);if(s&&typeof(s[i]=c)=="object"&&r.add(c),S(e),(o=e.s.charCodeAt(e.p++))===125)return n;o!==44&&f.x("expected comma or end of structure",e,e.p-1)}f.x("unfinished table",e,t)}function Pe(e){let t=e.p++,n=[],r;for(;e.p<e.s.length;){if(S(e),(r=e.s.charCodeAt(e.p))===93)return e.p++,n;if(n.push(J(e,93)),S(e),(r=e.s.charCodeAt(e.p++))===93)return n;r!==44&&f.x("expected comma or end of structure",e,e.p-1)}f.x("unfinished array",e,t)}function Ie(e,t,n,r,o){let i=n,s=r,l,u=!1,a;for(let c=0;c<t.length;c++){if(c){if(i=u?i[l]:i[l]=Object.create(null),s=(a=s[l]).c,o===0&&(a.t===1||a.t===2))return null;if(a.t===2){let d=i.length-1;i=i[d],s=s[d].c}}if(l=t[c],(u=Object.hasOwn(i,l))&&s[l]?.t===0&&s[l]?.d)return null;if(!u){let d=l==="__proto__";if(e.uk&&(d||l==="constructor"))return!1;d&&(Object.defineProperty(i,l,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(s,l,{enumerable:!0,configurable:!0,writable:!0})),s[l]={t:c<t.length-1&&o===2?3:o,d:!1,i:0,c:Object.create(null)}}}if(a=s[l],a.t!==o&&!(o===1&&a.t===3)||(o===2&&(a.d||(a.d=!0,i[l]=[]),i[l].push(i=Object.create(null)),a.c[a.i++]=a={t:1,d:!1,i:0,c:Object.create(null)}),a.d))return null;if(a.d=!0,o===1)i=u?i[l]:i[l]=Object.create(null);else if(o===0&&u)return null;return[l,i,a.c]}function Ne(e,t,n){(t===null||e.uk===2)&&f.x(t===null?"trying to redefine an already defined table or value":"document contains an unsafe property",e,n)}function pe(e,t={}){let n={s:e,p:0,d:t.maxDepth??1e3,bi:t.integersAsBigInt??!1,ld:t.useLegacyDate??!0,uk:t.unsafeKeyBehaviour==="throw"?2:t.unsafeKeyBehaviour==="drop"?1:0},r=Object.create(null),o=Object.create(null),i,s=!1,l=r,u=o;for(e.charCodeAt(0)===65279&&n.p++,S(n);n.p<e.length;){if(e.charCodeAt(n.p)===91){let a=e.charCodeAt(++n.p)===91;i=n.p+=+a,s=!1;let c=ee(n,93);a&&(e.charCodeAt(n.p)!==93&&f.x("expected end of table array declaration",n),n.p++);let d=Ie(n,c,r,o,a?2:1);d?(u=d[2],l=d[1]):(Ne(n,d,i),s=!0)}else{i=n.p;let a=ee(n),c=Ie(n,a,l,u,0);!c&&!s&&Ne(n,c,i),S(n,!0,!0);let d=J(n,void 0);c&&!s&&(c[1][c[0]]=d)}S(n,!0),n.p<e.length&&(i=e.charCodeAt(n.p))!==10&&(i!==13||e.charCodeAt(n.p+1)!==10)&&f.x("each key-value declaration must be followed by an end-of-line",n),S(n)}return r}var Oo=!!"".isWellFormed;function te(){return!1}import{execFileSync as sn}from"node:child_process";import{mkdirSync as ln,readFileSync as Me,renameSync as un,statSync as an,writeFileSync as cn}from"node:fs";import{join as Ue}from"node:path";import{closeSync as Ft,openSync as Mt,readSync as Ut,readdirSync as zt,readFileSync as Jt,statSync as De}from"node:fs";import{homedir as Bt}from"node:os";import{isAbsolute as Wt,join as ne,resolve as Gt}from"node:path";var Zt=/^[A-Za-z0-9._+@%:,/-]+$/,Vt=new Set(["7f454c46","feedface","feedfacf","cefaedfe","cffaedfe","cafebabe","bebafeca"]),qt=32,Kt=4*1024*1024;function ge(e){let t;try{t=Mt(e,"r");let n=Buffer.alloc(4),r=Ut(t,n,0,4,0);return r>=2&&n[0]===35&&n[1]===33?"#!":r===4?n.toString("hex"):null}catch{return null}finally{t!==void 0&&Ft(t)}}function B(e,t=process.platform){try{let n=De(e);if(!n.isFile())return!1;if(t==="win32")return!0;if((n.mode&73)===0)return!1;let r=ge(e);return r==="#!"||r!==null&&Vt.has(r)}catch{return!1}}function Yt(e){if(/\.[A-Za-z0-9]+$/.test(e))return[e];let t=(process.env.PATHEXT??".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);return[e,...t.map(n=>e+n.toLowerCase())]}function N(e,t,n,r=process.platform){if(!Zt.test(e))return!1;let o=r==="win32";if(e.includes("/"))return B(Gt(t??process.cwd(),e),r);if(!n)return!1;let i=o?Yt(e):[e];for(let s of n.split(o?";":":"))if(!(!s||!Wt(s))){for(let l of i)if(B(ne(s,l),r))return!0}return!1}var Xt=/^eval \$'([^\s'()=]+) \(\) /,Qt=/^([^\s'"()=]+) \(\) \{$/,en=/^alias -- ([^\s=]+)=(.*)$/,tn=/^# (?:Shell Options|Aliases|Shopt|Check for |Shadow )/,nn=/^export PATH=(.*)$/,rn=/^(?:--colou?r(?:=\S+)?|-G)$/;function Le(e){return e.length>=2&&e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1).replace(/'\\''/g,"'"):e.length>=2&&e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function on(e,t){let n="";for(let r of e.split(`
13
- `)){let o=nn.exec(r);if(o&&n!=="# Functions"){let i=Le(o[1].trim());/[$`\\]/.test(i)||t.paths.push(i);continue}if(r.startsWith("# ")&&(n!=="# Functions"||tn.test(r))){n=r;continue}if(n==="# Functions"){let i=Xt.exec(r)??Qt.exec(r);i&&t.functions.add(i[1])}else if(n==="# Aliases"){let i=en.exec(r);i&&t.aliases.set(i[1],Le(i[2].trim()))}}}function me(e){return e?.code==="ENOENT"}function je(e){let t={functions:new Set,aliases:new Map,paths:[],uncertain:!1},n=ne(e||ne(Bt(),".claude"),"shell-snapshots"),r=[];try{for(let o of zt(n)){if(!o.startsWith("snapshot-")||!o.endsWith(".sh"))continue;let i=ne(n,o);try{let s=De(i);s.isFile()&&r.push({path:i,mtime:s.mtimeMs,size:s.size})}catch(s){me(s)||(t.uncertain=!0)}}}catch(o){return me(o)||(t.uncertain=!0),t}r=r.sort((o,i)=>i.mtime-o.mtime).slice(0,qt);for(let o of r)try{if(o.size>Kt)throw new Error("snapshot too large");on(Jt(o.path,"utf8"),t)}catch(i){me(i)||(t.uncertain=!0)}return t}function Fe(e,t){if(t.uncertain||t.functions.has(e))return!0;let n=t.aliases.get(e);if(n===void 0)return!1;let r=n.trim().split(/\s+/);return r[0]!==e||!r.slice(1).every(o=>rn.test(o))}var fn="exec-probe.json",dn=6e4;function pn(){return Ue(E(),fn)}function mn(e){try{let t=JSON.parse(Me(e,"utf8"));if(t==null||typeof t!="object")return null;let n=t;return typeof n.key!="string"||typeof n.ok!="boolean"?null:{key:n.key,ok:n.ok,at:typeof n.at=="number"?n.at:0,skipped:typeof n.skipped=="number"&&n.skipped>=0?n.skipped:0}}catch{return null}}function gn(e,t){try{ln(Ue(e,".."),{recursive:!0,mode:448});let n=`${e}.${process.pid}.tmp`;cn(n,JSON.stringify(t),{mode:384}),un(n,e)}catch{}}function hn(e){try{return sn(e,["--native-check"],{encoding:"utf8",timeout:2e3,maxBuffer:1024,stdio:["ignore","pipe","ignore"],windowsHide:!0}).startsWith("tokmizer-native ")}catch{return!1}}function kn(e,t){try{let r=Me(e,"utf8").split(`
14
- `,1)[0].slice(2).trim().split(/\s+/),o=r[0]??"";return o==="/usr/bin/env"?N(r[1]??"",void 0,t):B(o)}catch{return!1}}function _n(e,t,n){try{let r=an(e);return[e,r.size,r.mtimeMs,r.ino,r.mode,t?n??"":""].join("|")}catch{return`${e}|missing`}}function he(e,t=process.platform,n=process.env.PATH,r=pn(),o=Date.now()){let i=t!=="win32"&&ge(e)==="#!",s=_n(e,i,n),l=mn(r);if(l?.key===s&&(l.ok||o-l.at<dn))return l.ok;let u=B(e,t)&&(i?kn(e,n):hn(e));return gn(r,{key:s,ok:u,at:o,skipped:(l?.skipped??0)+(u?0:1)}),u}var Sn=new Set(["tkr","tkr-exec","token","claude","cd","export","source","echo","mkdir","rm","mv","cp","chmod","ln","true","false",":","test","[","exit","return","nohup","sudo","doas","env"]),xn=new Set(["for","while","until","if","then","else","elif","fi","do","done","case","esac","select","function","time","coproc","in","!","[[","]]","{","}",".","declare","typeset","local","readonly","unset","set","shift","trap","wait","read","eval","exec","break","continue","pushd","popd","dirs","alias","unalias","hash","ulimit","umask","getopts","let","shopt","builtin","command","compgen","complete","disown","suspend","jobs","fg","bg","kill","history","fc","bind","enable","caller","type","printf","pwd","times","logout","mapfile","readarray","help","which","print","whence","where","autoload","zmodload","setopt","unsetopt","emulate","noglob","rehash","functions","bindkey","zle","vared","sched","limit","unlimit","zstyle","zparseopts","ttyctl"]),ze=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),Je="(?:dev|start|serve|watch|preview)",An=new RegExp(`^(?:\\S*/)?(?:bun\\s+(?:install|i|add|remove|rm|update|outdated|audit|test|build|pm|x)(?:\\s|$)|bun\\s+run\\s+(?!${Je}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|deno\\s+(?:test|lint|fmt|check|compile|install|info|doc|bench|outdated)(?:\\s|$)|deno\\s+task\\s+(?!${Je}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|php\\s+-l(?:\\s|$)|php\\s+(?:\\S*/)?(?:phpunit|pest|paratest|phpstan|pint|ecs|php-cs-fixer|psalm|rector|run-tests\\.php)(?:\\s|$)|php\\s+artisan\\s+(?!(?:serve|tinker|queue:work|queue:listen|horizon|octane:start|reverb:start|schedule:work|pail|dev)(?:\\s|$))\\S)`),$n=/(?:^|\s)--watch(?:\s|=|$)/;function Tn(e){return An.test(e)&&!$n.test(e)}var Cn=/^((?:\S*\/)?(sh|bash|zsh|dash|ksh|fish)\s+(-[elux]*c[elux]*)\s+)(['"])/,En=/[()$]|(?:^|[;&|\n]\s*)(?:and|or|not|begin|end|if|else|switch|case|while|for|function|return)(?:\s|;|$)/,Ke=3;function Ye(e){let t=Cn.exec(e);if(!t)return null;let n=t[2]==="fish";if(n&&t[3]!=="-c")return null;let r=t[4],o=t[1].length+1,i=e.indexOf(r,o);if(i<=o)return null;let s=e.slice(i+1);if(s&&!/^\s/.test(s))return null;let l=e.slice(o,i);return r==='"'&&/[$`\\!]/.test(l)||n&&En.test(l)?null:{script:l,start:o,end:i,quote:r}}var On=new Set(["cd","export","set","unset","source",".","true",":","pushd","popd"]);function vn(e){return be(e).filter(n=>{if(n.kind!=="cmd"||n.unsafe)return!1;let r=Qe(n.text);return r!==""&&!On.has(r)&&!_e.test(r)}).length>1}function Rn(e,t,n,r,o){if(n>=Ke)return null;let i=Ye(e);if(!i)return null;let{script:s,start:l,end:u,quote:a}=i,c=[],d=et(s,t,n+1,r,$=>c.push($));if(d===s||a==='"'&&/["$`]/.test(d))return null;let _=a==="'"?d.replace(/'/g,"'\\''"):d,m=`${e.slice(0,l)}${_}${e.slice(u)}`,h=vn(s);if(o)for(let $ of h?[e,...c]:c)o($);return h?`${t} ${m}`:m}var Be=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,Pn=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]);function In(e,t){let n=ie(t);return n==="tail"||n==="journalctl"?Be.test(e):n==="stern"?!0:Pn.has(n)?/\blogs?\b/.test(e)&&Be.test(e):!1}var _e=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,Nn=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,Hn=/(?:^|[;&|\n({])\s*[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/;function ie(e){let t=e.lastIndexOf("/");return t===-1?e:e.slice(t+1)}function Xe(e){let t=new Array(e.length).fill(!1),n=[],r=0;for(;r<e.length;){let o=e[r],i=e[r+1],s=n[n.length-1];if(s==="'"){o==="'"&&n.pop(),r+=1;continue}if(o==="\\"){if(i===void 0)return null;r+=2;continue}if(s==="$'"){o==="'"&&n.pop(),r+=1;continue}if(o==="$"&&(i==="("||i==="{")){n.push(i==="("?")":"}"),r+=2;continue}if(o==="`"){s==="`"?n.pop():n.push("`"),r+=1;continue}if(s==='"'){o==='"'&&n.pop(),r+=1;continue}if(o==="$"&&i==="'"){n.push("$'"),r+=2;continue}if(o==="'"||o==='"'){n.push(o),r+=1;continue}if(o==="("||o==="{"&&s==="}"){n.push(o==="("?")":"}"),r+=1;continue}if(o===s){n.pop(),r+=1;continue}if(o===")"&&s===void 0)return null;t[r]=s===void 0,r+=1}return n.length===0?t:null}function We(e){let t=Xe(e);if(!t)return!0;for(let n=0;n<e.length;n++)if(t[n]&&e[n]===">")return!0;return!1}function be(e){let t=Xe(e);if(!t)return[{kind:"cmd",text:e,unsafe:!0}];let n=[],r="",o=0,i=()=>{r.length>0&&(n.push({kind:"cmd",text:r}),r="")},s=(l,u)=>{i(),n.push({kind:"sep",text:l}),o+=u};for(;o<e.length;){let l=e[o],u=e[o+1];if(t[o]){if(l===">"&&u==="|"){r+=">|",o+=2;continue}if(l==="&"&&u==="&"){s("&&",2);continue}if(l==="&"&&u!==">"){let a=r.replace(/\s+$/,""),c=a[a.length-1];if(c!==">"&&c!=="<"&&c!=="&"){s("&",1);continue}}if(l==="|"&&u==="|"){s("||",2);continue}if(l==="|"&&u==="&"){s("|&",2);continue}if(l===";"&&u===";"){let a=e[o+2]==="&";s(a?";;&":";;",a?3:2);continue}if(l===";"||l===`
15
- `||l==="|"){s(l,1);continue}}r+=l,o+=1}return i(),n}function Qe(e){return e.trim().split(/\s+/)[0]??""}function x(e,t=process.platform){try{let n=qe(yn(import.meta.url)),r=t==="win32",o=e&&e!=="claude-code"&&e!=="codex"&&!r?`TOKMIZER_HOST=${e} `:"";if(r&&(!e||e==="claude-code")){let l=p(n,"..","bin","tkr-exec.exe");if(W(l))return he(l,t)?`'${l.replace(/\\/g,"/").replace(/'/g,"'\\''")}'`:null}let i=p(n,"..","bin","tkr-exec");if(!r&&W(i))return he(i,t)?`${o}'${i.replace(/'/g,"'\\''")}'`:null;if(te()){let l=r?process.execPath.replace(/\\/g,"/"):process.execPath;return`${o}'${l.replace(/'/g,"'\\''")}' exec`}let s=p(n,"..","bin","tkr-exec.js");return W(s)?`${o}node '${s.replace(/'/g,"'\\''")}'`:null}catch{return null}}function Ln(e,t="tkr-exec",n=()=>!0,r){return et(e,t,0,n,r)}function et(e,t,n,r,o){if(e.includes("<<")||Hn.test(e))return e;let i=be(e),s=[];for(let l=0;l<i.length;l++){let u=i[l];if(u.kind==="sep"||u.unsafe){s.push(u.text);continue}let a=u.text.trim();if(!a){s.push(u.text);continue}let c=Qe(a),d=i[l+1],_=d?.kind==="sep"&&(d.text==="|"||d.text==="|&"),m=d?.kind==="sep"&&d.text==="&",h=!_&&!m&&!We(u.text)&&!u.text.includes("<(")&&!u.text.includes(">(")?Rn(a,t,n,r,o):null;if(h!==null){s.push(`${u.text.match(/^\s*/)?.[0]??""}${h}${u.text.match(/\s*$/)?.[0]??""}`);continue}if(a===t||a.startsWith(t)&&/^\s/.test(a.slice(t.length))||Sn.has(c)||xn.has(c)||(ze.has(c)||ze.has(ie(c)))&&!Tn(a)||_e.test(c)||c.startsWith("(")||c.startsWith("#")||c.startsWith("<")||c.startsWith(">")||Nn.test(a)||In(a,c)||c.endsWith(")")||_||m||We(u.text)||u.text.includes("<(")||u.text.includes(">(")||c==="node"&&a.includes("tkr-exec.js")||!r(c)){s.push(u.text);continue}let $=u.text.match(/^\s*/)?.[0]??"",w=u.text.match(/\s*$/)?.[0]??"";o?.(a),s.push(`${$}${t} ${a}${w}`)}return s.join("")}var Dn=new Set(["command","workdir","timeout_ms","yield_time_ms","max_output_tokens","shell","login","tty","description"]),jn=new Set(["cd","cat","head","tail","ls","tree","find","grep","rg","wc","nl","sort","cut","diff","stat","file","du","df","ps","jq","yq","pwd","which"]),Fn=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),Mn={find:/^-(?:delete|exec|execdir|ok|okdir|fprint|fls)/,sort:/^(?:-[^-]*o|--output|--compress-program)/,rg:/^(?:--pre|--hostname-bin|-[^-]*z|--search-zip)/,yq:/^(?:-[^-]*[is]|--inplace|--split-exp)/,file:/^(?:-C|--compile)/,tree:/^(?:-o|--output|-R$|-H$)/,git:/^(?:--output|--ext-diff|--textconv|-c$|--exec-path|--git-dir|--work-tree)/,eslint:/^--fix/},re=["test","run test","run build","run lint","run typecheck"],Un={npm:new Set(re),pnpm:new Set([...re,"build","lint","typecheck"]),yarn:new Set([...re,"build","lint","typecheck"]),bun:new Set(re),cargo:new Set(["test","build","check","clippy"]),go:new Set(["test","build","vet"]),mvn:new Set(["test","compile","verify"]),gradle:new Set(["test","build","check"]),dotnet:new Set(["test","build"])},zn=new Set(["pytest","tsc","vitest","jest","eslint","mypy"]);function tt(e,t,n=0){if(/\$|`|<\(|>\(|\\\r?\n/.test(e)||/>/.test(e.replace(/2>&1|[12]?>\s*\/dev\/null/g,"")))return!1;for(let r of be(e)){if(r.kind==="sep")continue;if(r.unsafe)return!1;let o=n<Ke?Ye(r.text.trim()):null;if(o){if(!tt(o.script,t,n+1))return!1;continue}let i=r.text.trim().split(/\s+/).filter(Boolean).map(a=>a.replace(/['"\\]/g,""));if(i.length===0)continue;if(i.some(a=>_e.test(a)))return!1;let s=ie(i[0]);if(s!==i[0])return!1;let l=Mn[s];if(l&&i.slice(1).some(a=>l.test(a)))return!1;if((s==="git"?Fn.has(i[1]??""):jn.has(s))||t&&zn.has(s))continue;let u=t?Un[s]:void 0;if(!(u&&(u.has(i[1]??"")||i[1]==="run"&&u.has(`run ${i[2]??""}`))))return!1}return!0}function nt(e,t,n=x(t),r=y,o=se(),i=process.env.PATH,s=ye){if(!g(e)||e.tool_name!=="Bash"||t==="claude-code"&&Bn(s()))return null;let l=e.tool_input;if(!g(l)||l.run_in_background)return null;let u=l.command;if(typeof u!="string"||!u||t==="codex"&&Object.keys(l).some($=>!Dn.has($)))return null;let a=typeof e.cwd=="string"&&e.cwd?e.cwd:l.workdir,c=typeof a=="string"&&a?a:void 0,d=typeof e.session_id=="string"&&e.session_id?e.session_id:"unknown",_=typeof e.permission_mode=="string"?e.permission_mode:void 0,m=ct(u,{host:t,sessionId:d,cwd:c,claudeDirs:o,pathEnv:i,permissionMode:_},n,r);if(!m)return null;let h={...l,command:m.command};return JSON.stringify({hookSpecificOutput:t==="codex"?{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:h}:m.allowedBy?{hookEventName:"PreToolUse",permissionDecision:"allow",permissionDecisionReason:`Tokmizer: allowed by your rule ${m.allowedBy}`,updatedInput:h}:{hookEventName:"PreToolUse",updatedInput:h}})}var Jn=/(?:^|\s)--(?:disallowedTools|disallowed-tools|settings|setting-sources)(?:[=\s]|$)/;function ye(e=process.env,t=process.platform){let n=Number(e.CLAUDE_PID)||process.ppid;if(t==="win32"||!Number.isInteger(n)||n<=1)return null;try{let r=bn("ps",["-ww","-o","args=","-p",String(n)],{encoding:"utf8",timeout:2e3});return r.status===0&&r.stdout.trim()?r.stdout:null}catch{return null}}function Bn(e){return e===null||Jn.test(e)}function Wn(e,t){if(!W(e))return"missing";try{let n=G(e,"utf8");return JSON.parse(t?rt(n):n)}catch{return"unreadable"}}function rt(e){let t="",n=!1;for(let r=0;r<e.length;r++){let o=e[r];if(n){t+=o,o==="\\"?t+=e[++r]??"":o==='"'&&(n=!1);continue}if(o==='"')n=!0,t+=o;else if(o==="/"&&e[r+1]==="/"){for(;r<e.length&&e[r]!==`
12
+ ${i}`,n),this.line=r,this.column=o,this.codeblock=i}static x(t,n,r){throw new e(t,{toml:n.s,ptr:r??n.p})}};function ue(e){let t=e.p,n=e.s.charCodeAt(e.p++),r=n,o=n===39,i=n===e.s.charCodeAt(e.p)&&n===e.s.charCodeAt(e.p+1);i&&((n=e.s.charCodeAt(e.p+=2))===10?e.p++:n===13&&e.s.charCodeAt(e.p+1)===10&&(e.p+=2));let s="",l=e.p,u=0;for(;e.p<e.s.length;e.p++)if(n=e.s.charCodeAt(e.p),i&&(n===10||n===13&&e.s.charCodeAt(e.p+1)===10))u=u&&3;else if(n<32&&n!==9||n===127)f.x("control characters are not allowed in strings",e);else if((!u||u===3)&&n===r&&(!i||e.s.charCodeAt(e.p+1)===r&&e.s.charCodeAt(e.p+2)===r)){if(i&&(e.s.charCodeAt(e.p+3)===r&&e.p++,e.s.charCodeAt(e.p+3)===r&&e.p++),!u){let a=e.s.slice(l,e.p);s=s?s+a:a}return e.p+=i?3:1,s}else if(!u)!o&&n===92&&(s+=e.s.slice(l,l=e.p),u=1);else if(u===1)if(n===120||n===117||n===85){let a=e.p++-1,c=0,d=n===120?2:n===117?4:8;for(let _=0;_<d;_++,e.p++){let m=e.s.charCodeAt(e.p),h=m>=48&&m<=57?m-48:m>=65&&m<=70?m-65+10:m>=97&&m<=102?m-97+10:-1;h<0&&f.x("invalid non-hex character in unicode escape",e),c=c<<4|h}(c<0||c>1114111||c>=55296&&c<=57343)&&f.x("invalid unicode escape",e,a),s+=String.fromCodePoint(c),l=e.p--,u=0}else i&&(n===32||n===9)?u=2:(n===98?s+="\b":n===116?s+=" ":n===110?s+=`
13
+ `:n===102?s+="\f":n===114?s+="\r":n===101?s+="\x1B":n===34?s+='"':n===92?s+="\\":f.x("unrecognised escape sequence",e),l=e.p+1,u=0);else n!==32&&n!==9&&(u===2&&f.x("invalid escape: only line-ending whitespace may be escaped",e,l),u=!o&&n===92?1:0,l=e.p);f.x("unfinished string",e,t)}var In=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i,K=class e extends Date{#t=!1;#n=!1;#e=null;constructor(t,n,r){let o=!0,i=!0,s="Z",l;if(typeof t=="string")if(n)e:{if(n<3){if(+t.slice(11,13)>23){t="";break e}n===2?(s=null,t+="Z"):(l=t.charCodeAt(t.length-1))!==90&&l!==122&&(s=t.slice(t.length-6)),r&&(t=t.slice(0,10)+"T"+t.slice(11))}else n===4&&(t=+t.slice(0,2)>23?"":`0000-01-01T${t}Z`);o=n!==4,i=n!==3}else{let u=t.match(In);u?(u[1]||(o=!1,t=`0000-01-01T${t}`),i=!!u[2],i&&t[10]===" "&&(t=t.replace(" ","T")),u[2]&&+u[2]>23?t="":(s=u[3]||null,!s&&i&&(t+="Z"))):t=""}super(t),isNaN(this.getTime())||(this.#t=o,this.#n=i,this.#e=s)}isDateTime(){return this.#t&&this.#n}isLocal(){return!this.#t||!this.#n||!this.#e}isDate(){return this.#t&&!this.#n}isTime(){return this.#n&&!this.#t}isValid(){return this.#t||this.#n}toISOString(){let t=super.toISOString();if(this.isDate())return t.slice(0,10);if(this.isTime())return t.slice(11,23);if(this.#e===null)return t.slice(0,-1);if(this.#e==="Z"||this.#e==="z")return t;let n=+this.#e.slice(1,3)*60+ +this.#e.slice(4,6);return n=this.#e[0]==="-"?n:-n,new Date(this.getTime()-n*6e4).toISOString().slice(0,-1)+this.#e}static wrapAsOffsetDateTime(t,n="Z"){let r=new e(t);return r.#e=n,r}static wrapAsLocalDateTime(t){let n=new e(t);return n.#e=null,n}static wrapAsLocalDate(t){let n=new e(t);return n.#n=!1,n.#e=null,n}static wrapAsLocalTime(t){let n=new e(t);return n.#t=!1,n.#e=null,n}};function b(e,t=10){return t===16?e>47&&e<58||e>64&&e<71||e>96&&e<103:e>47&&e<48+t}function Te(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function Y(e,t){let n=e.p,r=e.s.charCodeAt(e.p);if(r===91||r===123){e.d--||f.x("document contains excessively nested structures. aborting.",e);let o=r===91?rt(e):nt(e);return e.d++,o}return r===34||r===39?ue(e):r===116?((e.s.charCodeAt(++e.p)!==114||e.s.charCodeAt(++e.p)!==117||e.s.charCodeAt(++e.p)!==101)&&f.x("invalid value",e,n),e.p++,!0):r===102?((e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==108||e.s.charCodeAt(++e.p)!==115||e.s.charCodeAt(++e.p)!==101)&&f.x("invalid value",e,n),e.p++,!1):r===43||r===45?le(e,e.p,e.s.charCodeAt(++e.p),44-r,t):e.s.charCodeAt(e.p+4)===45&&e.s.charCodeAt(e.p+7)===45?Hn(e,r,t):e.s.charCodeAt(e.p+2)===58?Ln(e,r,t):le(e,e.p,r,0,t)}function le(e,t,n,r,o){let i=n,s=0,l=!1;if(i===105)return(e.s.charCodeAt(++e.p)!==110||e.s.charCodeAt(++e.p)!==102)&&f.x("invalid value",e,t),e.p++,(r||1)/0;if(i===110)return(e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==110)&&f.x("invalid value",e,t),e.p++,NaN;if(i===48){if(++e.p>=e.s.length||Te(i=e.s.charCodeAt(e.p),o))return e.bi===!0?0n:0;if(!r){if(i===120)return Ae(e,t,16,o);if(i===98)return Ae(e,t,2,o);if(i===111)return Ae(e,t,8,o)}i===46?s=2:i===101||i===69?s=4:f.x("illegal leading zero",e,t)}else b(i)||f.x("invalid value",e,t);for(;++e.p<e.s.length&&(i=e.s.charCodeAt(e.p),!Te(i,o));)s||(s=1),i===95?(s&1||f.x("illegal underscore",e),s+=11,l=!0):s===1&&i===46?s=2:(s===1||s===3)&&(i===101||i===69)?s=4:s===4&&(i===43||i===45)||(b(i)?s>9?s-=11:s&1||s++:f.x("illegal character in numeric literal",e));if(!s){let a=(n-48)*(r||1);return e.bi===!0?BigInt(a):a}s&1||f.x("unfinished numeric value",e,t);let u=e.s.slice(t,e.p);return l&&(u=u.replaceAll("_","")),s>1?parseFloat(u):tt(e,u,10,t)}function Ae(e,t,n,r){let o,i=1;for(;++e.p<e.s.length&&(o=e.s.charCodeAt(e.p),!Te(o,r));)o===95?(i&1&&f.x("illegal underscore",e),i=3):b(o,n)?i&1&&i--:f.x("illegal character in numeric literal",e);i&1&&f.x("unfinished numeric value",e);let s=e.s.slice(t+2,e.p);return i&&(s=s.replaceAll("_","")),tt(e,s,n,t)}function tt(e,t,n,r){if(e.bi!==!0)e:{let o=parseInt(t,n);if(!Number.isSafeInteger(o)){if(e.bi)break e;f.x("integer value cannot be represented losslessly",e,r)}return o}return BigInt(n===10?t:(n===2?"0b":n===8?"0o":"0x")+t)}function Hn(e,t,n){let r=e.p++,o;if(!b(t)||!b(e.s.charCodeAt(e.p++))||!b(e.s.charCodeAt(e.p++))||!b(e.s.charCodeAt(e.p++)))return le(e,e.p=r,t,0,n);if(e.p+=5,b(e.s.charCodeAt(e.p++))||f.x("invalid date-time: date part is malformed",e,r),e.p>=e.s.length||((t=e.s.charCodeAt(e.p))!==32||(o=!0,!b(e.s.charCodeAt(e.p+1))))&&t!==84&&t!==116){let s=e.s.slice(r,e.p);return q(e,s,3,!1,r)}if(e.s.charCodeAt(e.p+=3)!==58&&f.x("invalid date-time: time part is malformed",e,r),e.s.charCodeAt(e.p+=3)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;b(e.s.charCodeAt(++e.p)););if(t=e.s.charCodeAt(e.p)){if(t===90||t===122){let s=e.s.slice(r,++e.p);return q(e,s,1,o,r,"[+00:00]")}if(t===43||t===45){let s=e.s.slice(r,e.p+=6);return q(e,s,1,o,r,!e.ld&&"["+e.s.slice(e.p-6,e.p)+"]")}}let i=e.s.slice(r,e.p);return q(e,i,2,o,r)}function Ln(e,t,n){let r=e.p;if(!b(t)||!b(e.s.charCodeAt(++e.p)))return le(e,--e.p,t,0,n);if(e.s.charCodeAt(e.p+=4)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;b(e.s.charCodeAt(++e.p)););let o=e.s.slice(r,e.p);return q(e,o,4,!1,r)}function q(e,t,n,r,o,i){if(e.ld){let s=new K(t,n,r);return s.isValid()||f.x("invalid date",e,o),s}try{switch(i&&(t+=i),n){case 1:return Temporal.ZonedDateTime.from(t);case 2:return Temporal.PlainDateTime.from(t);case 3:return Temporal.PlainDate.from(t);case 4:return Temporal.PlainTime.from(t)}}catch(s){f.x(s instanceof Error?s.message:""+s,e,o)}}function jn(e){for(;e.p<e.s.length;e.p++){let t=e.s.charCodeAt(e.p);if(t===10)break;if(t===13&&e.s.charCodeAt(e.p+1)===10){e.p++;break}(t<32&&t!==9||t===127)&&f.x("control characters are not allowed in comments",e)}}function x(e,t,n){let r;for(;e.p<e.s.length;){for(;e.p<e.s.length&&((r=e.s.charCodeAt(e.p))===32||r===9||!t&&(r===10||r===13&&e.s.charCodeAt(e.p+1)===10));)e.p++;if(n||r!==35)break;jn(e)}}function ae(e,t=61){let n,r=0,o=[],i,s=e.s.charCodeAt(n=e.p);do{if(s===t)return r||f.x("unexpected end of key",e),r===1&&o.push(e.s.slice(i,e.p)),e.p++,o;s===46?(r||f.x("illegal empty bare key",e),r===1&&o.push(e.s.slice(i,e.p)),r=0):!r&&(s===34||s===39)?(s===e.s.charCodeAt(e.p+1)&&s===e.s.charCodeAt(e.p+2)&&f.x("illegal quoted key: multiline strings are not allowed",e),o.push(ue(e)),r=2,e.p--):s===32||s===9?r===1&&(o.push(e.s.slice(i,e.p)),r=2):r===2||s<48&&s!==45||s>57&&s<65||s>90&&s<97&&s!==95||s>122?f.x("illegal character in key",e):r||(r=1,i=e.p)}while(s=e.s.charCodeAt(++e.p));f.x("incomplete key-value: cannot find end of key",e,n)}function nt(e){let t=e.p++,n=Object.create(null),r=new Set,o;for(;e.p<e.s.length;){if(x(e),(o=e.s.charCodeAt(e.p))===125)return e.p++,n;let i,s=n,l=!1,u=e.p,a=ae(e);for(let d=0;d<a.length;d++){d&&(s=l?s[i]:s[i]=Object.create(null)),i=a[d],(l=Object.hasOwn(s,i))&&(typeof s[i]!="object"||r.has(s[i]))&&f.x("trying to redefine an already defined value",e,u);let _=i==="__proto__";if(e.uk&&(_||i==="constructor")){s=e.uk!==1&&f.x("document contains an unsafe property",e,u);break}!l&&_&&Object.defineProperty(s,i,{enumerable:!0,configurable:!0,writable:!0})}l&&f.x("trying to redefine an already defined value",e,u),x(e,!0,!0);let c=Y(e,125);if(s&&typeof(s[i]=c)=="object"&&r.add(c),x(e),(o=e.s.charCodeAt(e.p++))===125)return n;o!==44&&f.x("expected comma or end of structure",e,e.p-1)}f.x("unfinished table",e,t)}function rt(e){let t=e.p++,n=[],r;for(;e.p<e.s.length;){if(x(e),(r=e.s.charCodeAt(e.p))===93)return e.p++,n;if(n.push(Y(e,93)),x(e),(r=e.s.charCodeAt(e.p++))===93)return n;r!==44&&f.x("expected comma or end of structure",e,e.p-1)}f.x("unfinished array",e,t)}function ot(e,t,n,r,o){let i=n,s=r,l,u=!1,a;for(let c=0;c<t.length;c++){if(c){if(i=u?i[l]:i[l]=Object.create(null),s=(a=s[l]).c,o===0&&(a.t===1||a.t===2))return null;if(a.t===2){let d=i.length-1;i=i[d],s=s[d].c}}if(l=t[c],(u=Object.hasOwn(i,l))&&s[l]?.t===0&&s[l]?.d)return null;if(!u){let d=l==="__proto__";if(e.uk&&(d||l==="constructor"))return!1;d&&(Object.defineProperty(i,l,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(s,l,{enumerable:!0,configurable:!0,writable:!0})),s[l]={t:c<t.length-1&&o===2?3:o,d:!1,i:0,c:Object.create(null)}}}if(a=s[l],a.t!==o&&!(o===1&&a.t===3)||(o===2&&(a.d||(a.d=!0,i[l]=[]),i[l].push(i=Object.create(null)),a.c[a.i++]=a={t:1,d:!1,i:0,c:Object.create(null)}),a.d))return null;if(a.d=!0,o===1)i=u?i[l]:i[l]=Object.create(null);else if(o===0&&u)return null;return[l,i,a.c]}function it(e,t,n){(t===null||e.uk===2)&&f.x(t===null?"trying to redefine an already defined table or value":"document contains an unsafe property",e,n)}function Ce(e,t={}){let n={s:e,p:0,d:t.maxDepth??1e3,bi:t.integersAsBigInt??!1,ld:t.useLegacyDate??!0,uk:t.unsafeKeyBehaviour==="throw"?2:t.unsafeKeyBehaviour==="drop"?1:0},r=Object.create(null),o=Object.create(null),i,s=!1,l=r,u=o;for(e.charCodeAt(0)===65279&&n.p++,x(n);n.p<e.length;){if(e.charCodeAt(n.p)===91){let a=e.charCodeAt(++n.p)===91;i=n.p+=+a,s=!1;let c=ae(n,93);a&&(e.charCodeAt(n.p)!==93&&f.x("expected end of table array declaration",n),n.p++);let d=ot(n,c,r,o,a?2:1);d?(u=d[2],l=d[1]):(it(n,d,i),s=!0)}else{i=n.p;let a=ae(n),c=ot(n,a,l,u,0);!c&&!s&&it(n,c,i),x(n,!0,!0);let d=Y(n,void 0);c&&!s&&(c[1][c[0]]=d)}x(n,!0),n.p<e.length&&(i=e.charCodeAt(n.p))!==10&&(i!==13||e.charCodeAt(n.p+1)!==10)&&f.x("each key-value declaration must be followed by an end-of-line",n),x(n)}return r}var Gi=!!"".isWellFormed;import{execFileSync as or}from"node:child_process";import{mkdirSync as ir,readFileSync as ct,renameSync as sr,statSync as ur,writeFileSync as lr}from"node:fs";import{join as ft}from"node:path";import{closeSync as Dn,openSync as Fn,readSync as Mn,readdirSync as Un,readFileSync as zn,statSync as ut}from"node:fs";import{homedir as Jn}from"node:os";import{isAbsolute as Bn,join as ce,resolve as Wn}from"node:path";var Gn=/^[A-Za-z0-9._+@%:,/-]+$/,Zn=new Set(["7f454c46","feedface","feedfacf","cefaedfe","cffaedfe","cafebabe","bebafeca"]),Vn=32,Kn=4*1024*1024;function Ee(e){let t;try{t=Fn(e,"r");let n=Buffer.alloc(4),r=Mn(t,n,0,4,0);return r>=2&&n[0]===35&&n[1]===33?"#!":r===4?n.toString("hex"):null}catch{return null}finally{t!==void 0&&Dn(t)}}function X(e,t=process.platform){try{let n=ut(e);if(!n.isFile())return!1;if(t==="win32")return!0;if((n.mode&73)===0)return!1;let r=Ee(e);return r==="#!"||r!==null&&Zn.has(r)}catch{return!1}}function qn(e){if(/\.[A-Za-z0-9]+$/.test(e))return[e];let t=(process.env.PATHEXT??".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);return[e,...t.map(n=>e+n.toLowerCase())]}function F(e,t,n,r=process.platform){if(!Gn.test(e))return!1;let o=r==="win32";if(e.includes("/"))return X(Wn(t??process.cwd(),e),r);if(!n)return!1;let i=o?qn(e):[e];for(let s of n.split(o?";":":"))if(!(!s||!Bn(s))){for(let l of i)if(X(ce(s,l),r))return!0}return!1}var Yn=/^eval \$'([^\s'()=]+) \(\) /,Xn=/^([^\s'"()=]+) \(\) \{$/,Qn=/^alias -- ([^\s=]+)=(.*)$/,er=/^# (?:Shell Options|Aliases|Shopt|Check for |Shadow )/,tr=/^export PATH=(.*)$/,nr=/^(?:--colou?r(?:=\S+)?|-G)$/;function st(e){return e.length>=2&&e.startsWith("'")&&e.endsWith("'")?e.slice(1,-1).replace(/'\\''/g,"'"):e.length>=2&&e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function rr(e,t){let n="";for(let r of e.split(`
14
+ `)){let o=tr.exec(r);if(o&&n!=="# Functions"){let i=st(o[1].trim());/[$`\\]/.test(i)||t.paths.push(i);continue}if(r.startsWith("# ")&&(n!=="# Functions"||er.test(r))){n=r;continue}if(n==="# Functions"){let i=Yn.exec(r)??Xn.exec(r);i&&t.functions.add(i[1])}else if(n==="# Aliases"){let i=Qn.exec(r);i&&t.aliases.set(i[1],st(i[2].trim()))}}}function ve(e){return e?.code==="ENOENT"}function lt(e){let t={functions:new Set,aliases:new Map,paths:[],uncertain:!1},n=ce(e||ce(Jn(),".claude"),"shell-snapshots"),r=[];try{for(let o of Un(n)){if(!o.startsWith("snapshot-")||!o.endsWith(".sh"))continue;let i=ce(n,o);try{let s=ut(i);s.isFile()&&r.push({path:i,mtime:s.mtimeMs,size:s.size})}catch(s){ve(s)||(t.uncertain=!0)}}}catch(o){return ve(o)||(t.uncertain=!0),t}r=r.sort((o,i)=>i.mtime-o.mtime).slice(0,Vn);for(let o of r)try{if(o.size>Kn)throw new Error("snapshot too large");rr(zn(o.path,"utf8"),t)}catch(i){ve(i)||(t.uncertain=!0)}return t}function at(e,t){if(t.uncertain||t.functions.has(e))return!0;let n=t.aliases.get(e);if(n===void 0)return!1;let r=n.trim().split(/\s+/);return r[0]!==e||!r.slice(1).every(o=>nr.test(o))}var ar="exec-probe.json",cr=6e4;function fr(){return ft(S(),ar)}function dr(e){try{let t=JSON.parse(ct(e,"utf8"));if(t==null||typeof t!="object")return null;let n=t;return typeof n.key!="string"||typeof n.ok!="boolean"?null:{key:n.key,ok:n.ok,at:typeof n.at=="number"?n.at:0,skipped:typeof n.skipped=="number"&&n.skipped>=0?n.skipped:0}}catch{return null}}function pr(e,t){try{ir(ft(e,".."),{recursive:!0,mode:448});let n=`${e}.${process.pid}.tmp`;lr(n,JSON.stringify(t),{mode:384}),sr(n,e)}catch{}}function mr(e){try{return or(e,["--native-check"],{encoding:"utf8",timeout:2e3,maxBuffer:1024,stdio:["ignore","pipe","ignore"],windowsHide:!0}).startsWith("tokmizer-native ")}catch{return!1}}function gr(e,t){try{let r=ct(e,"utf8").split(`
15
+ `,1)[0].slice(2).trim().split(/\s+/),o=r[0]??"";return o==="/usr/bin/env"?F(r[1]??"",void 0,t):X(o)}catch{return!1}}function hr(e,t,n){try{let r=ur(e);return[e,r.size,r.mtimeMs,r.ino,r.mode,t?n??"":""].join("|")}catch{return`${e}|missing`}}function Oe(e,t=process.platform,n=process.env.PATH,r=fr(),o=Date.now()){let i=t!=="win32"&&Ee(e)==="#!",s=hr(e,i,n),l=dr(r);if(l?.key===s&&(l.ok||o-l.at<cr))return l.ok;let u=X(e,t)&&(i?gr(e,n):mr(e));return pr(r,{key:s,ok:u,at:o,skipped:(l?.skipped??0)+(u?0:1)}),u}var yr=new Set(["tkr","tkr-exec","token","claude","cd","export","source","echo","mkdir","rm","mv","cp","chmod","ln","true","false",":","test","[","exit","return","nohup","sudo","doas","env"]),wr=new Set(["for","while","until","if","then","else","elif","fi","do","done","case","esac","select","function","time","coproc","in","!","[[","]]","{","}",".","declare","typeset","local","readonly","unset","set","shift","trap","wait","read","eval","exec","break","continue","pushd","popd","dirs","alias","unalias","hash","ulimit","umask","getopts","let","shopt","builtin","command","compgen","complete","disown","suspend","jobs","fg","bg","kill","history","fc","bind","enable","caller","type","printf","pwd","times","logout","mapfile","readarray","help","which","print","whence","where","autoload","zmodload","setopt","unsetopt","emulate","noglob","rehash","functions","bindkey","zle","vared","sched","limit","unlimit","zstyle","zparseopts","ttyctl"]),dt=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),pt="(?:dev|start|serve|watch|preview)",Sr=new RegExp(`^(?:\\S*/)?(?:bun\\s+(?:install|i|add|remove|rm|update|outdated|audit|test|build|pm|x)(?:\\s|$)|bun\\s+run\\s+(?!${pt}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|deno\\s+(?:test|lint|fmt|check|compile|install|info|doc|bench|outdated)(?:\\s|$)|deno\\s+task\\s+(?!${pt}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|php\\s+-l(?:\\s|$)|php\\s+(?:\\S*/)?(?:phpunit|pest|paratest|phpstan|pint|ecs|php-cs-fixer|psalm|rector|run-tests\\.php)(?:\\s|$)|php\\s+artisan\\s+(?!(?:serve|tinker|queue:work|queue:listen|horizon|octane:start|reverb:start|schedule:work|pail|dev)(?:\\s|$))\\S)`),xr=/(?:^|\s)--watch(?:\s|=|$)/;function $r(e){return Sr.test(e)&&!xr.test(e)}var Ar=/^((?:\S*\/)?(sh|bash|zsh|dash|ksh|fish)\s+(-[elux]*c[elux]*)\s+)(['"])/,Tr=/[()$]|(?:^|[;&|\n]\s*)(?:and|or|not|begin|end|if|else|switch|case|while|for|function|return)(?:\s|;|$)/,yt=3;function wt(e){let t=Ar.exec(e);if(!t)return null;let n=t[2]==="fish";if(n&&t[3]!=="-c")return null;let r=t[4],o=t[1].length+1,i=e.indexOf(r,o);if(i<=o)return null;let s=e.slice(i+1);if(s&&!/^\s/.test(s))return null;let l=e.slice(o,i);return r==='"'&&/[$`\\!]/.test(l)||n&&Tr.test(l)?null:{script:l,start:o,end:i,quote:r}}var Cr=new Set(["cd","export","set","unset","source",".","true",":","pushd","popd"]);function vr(e){return Pe(e).filter(n=>{if(n.kind!=="cmd"||n.unsafe)return!1;let r=xt(n.text);return r!==""&&!Cr.has(r)&&!Ne.test(r)}).length>1}function Er(e,t,n,r,o){if(n>=yt)return null;let i=wt(e);if(!i)return null;let{script:s,start:l,end:u,quote:a}=i,c=[],d=$t(s,t,n+1,r,C=>c.push(C));if(d===s||a==='"'&&/["$`]/.test(d))return null;let _=a==="'"?d.replace(/'/g,"'\\''"):d,m=`${e.slice(0,l)}${_}${e.slice(u)}`,h=vr(s);if(o)for(let C of h?[e,...c]:c)o(C);return h?`${t} ${m}`:m}var mt=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,Or=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]);function Rr(e,t){let n=pe(t);return n==="tail"||n==="journalctl"?mt.test(e):n==="stern"?!0:Or.has(n)?/\blogs?\b/.test(e)&&mt.test(e):!1}var Ne=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,Nr=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,Pr=/(?:^|[;&|\n({])\s*[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/;function pe(e){let t=e.lastIndexOf("/");return t===-1?e:e.slice(t+1)}function St(e){let t=new Array(e.length).fill(!1),n=[],r=0;for(;r<e.length;){let o=e[r],i=e[r+1],s=n[n.length-1];if(s==="'"){o==="'"&&n.pop(),r+=1;continue}if(o==="\\"){if(i===void 0)return null;r+=2;continue}if(s==="$'"){o==="'"&&n.pop(),r+=1;continue}if(o==="$"&&(i==="("||i==="{")){n.push(i==="("?")":"}"),r+=2;continue}if(o==="`"){s==="`"?n.pop():n.push("`"),r+=1;continue}if(s==='"'){o==='"'&&n.pop(),r+=1;continue}if(o==="$"&&i==="'"){n.push("$'"),r+=2;continue}if(o==="'"||o==='"'){n.push(o),r+=1;continue}if(o==="("||o==="{"&&s==="}"){n.push(o==="("?")":"}"),r+=1;continue}if(o===s){n.pop(),r+=1;continue}if(o===")"&&s===void 0)return null;t[r]=s===void 0,r+=1}return n.length===0?t:null}function gt(e){let t=St(e);if(!t)return!0;for(let n=0;n<e.length;n++)if(t[n]&&e[n]===">")return!0;return!1}function Pe(e){let t=St(e);if(!t)return[{kind:"cmd",text:e,unsafe:!0}];let n=[],r="",o=0,i=()=>{r.length>0&&(n.push({kind:"cmd",text:r}),r="")},s=(l,u)=>{i(),n.push({kind:"sep",text:l}),o+=u};for(;o<e.length;){let l=e[o],u=e[o+1];if(t[o]){if(l===">"&&u==="|"){r+=">|",o+=2;continue}if(l==="&"&&u==="&"){s("&&",2);continue}if(l==="&"&&u!==">"){let a=r.replace(/\s+$/,""),c=a[a.length-1];if(c!==">"&&c!=="<"&&c!=="&"){s("&",1);continue}}if(l==="|"&&u==="|"){s("||",2);continue}if(l==="|"&&u==="&"){s("|&",2);continue}if(l===";"&&u===";"){let a=e[o+2]==="&";s(a?";;&":";;",a?3:2);continue}if(l===";"||l===`
16
+ `||l==="|"){s(l,1);continue}}r+=l,o+=1}return i(),n}function xt(e){return e.trim().split(/\s+/)[0]??""}function $(e,t=process.platform){try{let n=bt(_r(import.meta.url)),r=t==="win32",o=e&&e!=="claude-code"&&e!=="codex"&&!r?`TOKMIZER_HOST=${e} `:"";if(r&&(!e||e==="claude-code")){let u=p(n,"..","bin","tkr-exec.exe");if(M(u))return Oe(u,t)?`'${u.replace(/\\/g,"/").replace(/'/g,"'\\''")}'`:null}let i=p(n,"..","bin","tkr-exec"),s=!r&&M(i);if(s&&!Oe(i,t))return null;if(!r&&process.env.TOKMIZER_STABLE_RUN!=="0"){let u=et(p(n,"..","bin","tkr-exec.js"));if(u&&(s||M(p(n,"..","bin","tkr-exec.js"))))return`${o}'${u.replace(/'/g,"'\\''")}'`}if(s)return`${o}'${i.replace(/'/g,"'\\''")}'`;if(Z()){let u=r?process.execPath.replace(/\\/g,"/"):process.execPath;return`${o}'${u.replace(/'/g,"'\\''")}' exec`}let l=p(n,"..","bin","tkr-exec.js");return M(l)?`${o}node '${l.replace(/'/g,"'\\''")}'`:null}catch{return null}}function Ir(e,t="tkr-exec",n=()=>!0,r){return $t(e,t,0,n,r)}function $t(e,t,n,r,o){if(e.includes("<<")||Pr.test(e))return e;let i=Pe(e),s=[];for(let l=0;l<i.length;l++){let u=i[l];if(u.kind==="sep"||u.unsafe){s.push(u.text);continue}let a=u.text.trim();if(!a){s.push(u.text);continue}let c=xt(a),d=i[l+1],_=d?.kind==="sep"&&(d.text==="|"||d.text==="|&"),m=d?.kind==="sep"&&d.text==="&",h=!_&&!m&&!gt(u.text)&&!u.text.includes("<(")&&!u.text.includes(">(")?Er(a,t,n,r,o):null;if(h!==null){s.push(`${u.text.match(/^\s*/)?.[0]??""}${h}${u.text.match(/\s*$/)?.[0]??""}`);continue}if(a===t||a.startsWith(t)&&/^\s/.test(a.slice(t.length))||yr.has(c)||wr.has(c)||(dt.has(c)||dt.has(pe(c)))&&!$r(a)||Ne.test(c)||c.startsWith("(")||c.startsWith("#")||c.startsWith("<")||c.startsWith(">")||Nr.test(a)||Rr(a,c)||c.endsWith(")")||_||m||gt(u.text)||u.text.includes("<(")||u.text.includes(">(")||c==="node"&&a.includes("tkr-exec.js")||!r(c)){s.push(u.text);continue}let C=u.text.match(/^\s*/)?.[0]??"",w=u.text.match(/\s*$/)?.[0]??"";o?.(a),s.push(`${C}${t} ${a}${w}`)}return s.join("")}var Hr=new Set(["command","workdir","timeout_ms","yield_time_ms","max_output_tokens","shell","login","tty","description"]),Lr=new Set(["cd","cat","head","tail","ls","tree","find","grep","rg","wc","nl","sort","cut","diff","stat","file","du","df","ps","jq","yq","pwd","which"]),jr=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),Dr={find:/^-(?:delete|exec|execdir|ok|okdir|fprint|fls)/,sort:/^(?:-[^-]*o|--output|--compress-program)/,rg:/^(?:--pre|--hostname-bin|-[^-]*z|--search-zip)/,yq:/^(?:-[^-]*[is]|--inplace|--split-exp)/,file:/^(?:-C|--compile)/,tree:/^(?:-o|--output|-R$|-H$)/,git:/^(?:--output|--ext-diff|--textconv|-c$|--exec-path|--git-dir|--work-tree)/,eslint:/^--fix/},fe=["test","run test","run build","run lint","run typecheck"],Fr={npm:new Set(fe),pnpm:new Set([...fe,"build","lint","typecheck"]),yarn:new Set([...fe,"build","lint","typecheck"]),bun:new Set(fe),cargo:new Set(["test","build","check","clippy"]),go:new Set(["test","build","vet"]),mvn:new Set(["test","compile","verify"]),gradle:new Set(["test","build","check"]),dotnet:new Set(["test","build"])},Mr=new Set(["pytest","tsc","vitest","jest","eslint","mypy"]);function At(e,t,n=0){if(/\$|`|<\(|>\(|\\\r?\n/.test(e)||/>/.test(e.replace(/2>&1|[12]?>\s*\/dev\/null/g,"")))return!1;for(let r of Pe(e)){if(r.kind==="sep")continue;if(r.unsafe)return!1;let o=n<yt?wt(r.text.trim()):null;if(o){if(!At(o.script,t,n+1))return!1;continue}let i=r.text.trim().split(/\s+/).filter(Boolean).map(a=>a.replace(/['"\\]/g,""));if(i.length===0)continue;if(i.some(a=>Ne.test(a)))return!1;let s=pe(i[0]);if(s!==i[0])return!1;let l=Dr[s];if(l&&i.slice(1).some(a=>l.test(a)))return!1;if((s==="git"?jr.has(i[1]??""):Lr.has(s))||t&&Mr.has(s))continue;let u=t?Fr[s]:void 0;if(!(u&&(u.has(i[1]??"")||i[1]==="run"&&u.has(`run ${i[2]??""}`))))return!1}return!0}function Tt(e,t,n=$(t),r=y,o=me(),i=process.env.PATH,s=Ie){if(!g(e)||e.tool_name!=="Bash"||t==="claude-code"&&zr(s()))return null;let l=e.tool_input;if(!g(l)||l.run_in_background)return null;let u=l.command;if(typeof u!="string"||!u||t==="codex"&&Object.keys(l).some(C=>!Hr.has(C)))return null;let a=typeof e.cwd=="string"&&e.cwd?e.cwd:l.workdir,c=typeof a=="string"&&a?a:void 0,d=typeof e.session_id=="string"&&e.session_id?e.session_id:"unknown",_=typeof e.permission_mode=="string"?e.permission_mode:void 0,m=It(u,{host:t,sessionId:d,cwd:c,claudeDirs:o,pathEnv:i,permissionMode:_},n,r);if(!m)return null;let h={...l,command:m.command};return JSON.stringify({hookSpecificOutput:t==="codex"?{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:h}:m.allowedBy?{hookEventName:"PreToolUse",permissionDecision:"allow",permissionDecisionReason:`Tokmizer: allowed by your rule ${m.allowedBy}`,updatedInput:h}:m.ask?{hookEventName:"PreToolUse",permissionDecision:"ask",permissionDecisionReason:"Tokmizer shortens this command's output; nothing else changes.",updatedInput:h}:{hookEventName:"PreToolUse",updatedInput:h}})}var Ur=/(?:^|\s)--(?:disallowedTools|disallowed-tools|settings|setting-sources)(?:[=\s]|$)/;function Ie(e=process.env,t=process.platform){let n=Number(e.CLAUDE_PID)||process.ppid;if(t==="win32"||!Number.isInteger(n)||n<=1)return null;try{let r=kr("ps",["-ww","-o","args=","-p",String(n)],{encoding:"utf8",timeout:2e3});return r.status===0&&r.stdout.trim()?r.stdout:null}catch{return null}}function zr(e){return e===null||Ur.test(e)}function Jr(e,t){if(!M(e))return"missing";try{let n=Q(e,"utf8");return JSON.parse(t?Ct(n):n)}catch{return"unreadable"}}function Ct(e){let t="",n=!1;for(let r=0;r<e.length;r++){let o=e[r];if(n){t+=o,o==="\\"?t+=e[++r]??"":o==='"'&&(n=!1);continue}if(o==='"')n=!0,t+=o;else if(o==="/"&&e[r+1]==="/"){for(;r<e.length&&e[r]!==`
16
17
  `;)r++;t+=`
17
- `}else if(o==="/"&&e[r+1]==="*"){if(r=e.indexOf("*/",r+2),r===-1)return"";r+=1}else t+=o}return t.replace(/,(\s*[}\]])/g,"$1")}function V(e){let t=[],n=wn(e);for(;;){t.push(n);let r=qe(n);if(r===n)return t;n=r}}function Gn(){let e=process.platform==="darwin"?"/Library/Application Support/ClaudeCode":process.platform==="win32"?"C:\\Program Files\\ClaudeCode":"/etc/claude-code",t=[p(e,"managed-settings.json")];try{for(let n of oe(p(e,"managed-settings.d")))n.endsWith(".json")&&t.push(p(e,"managed-settings.d",n))}catch{return t}return t}function q(e,t,n,r){let o=[];for(let i of e){let s=Wn(i,t);if(s!=="missing"&&(s==="unreadable"||!g(s)||!n(s,o)))return"unreadable"}return{matchers:o,complete:r}}function Z(e){return e===void 0?[]:Array.isArray(e)?e.filter(t=>typeof t=="string"):null}function se(){return{projectDir:process.env.CLAUDE_PROJECT_DIR,configDir:process.env.CLAUDE_CONFIG_DIR}}function Zn(e,t){let n=w=>[p(w,"settings.json"),p(w,"settings.local.json")],r=w=>n(p(w,".claude")),o=p(R(),".claude"),i=t.configDir||o,s=[[Gn(),"managed"],[[p(i,"settings.json")],"loaded"],[[p(i,"settings.local.json")],"loadedLocal"],[t.configDir?n(o):[],"extra"],[t.projectDir?r(t.projectDir):[],"project"],[V(e).flatMap(r),"extra"]],l=[],u={managed:[],loaded:[],loadedLocal:[],project:[],extra:[]},a={managed:!1,loaded:!1,loadedLocal:!1,project:!1,extra:!1},c=!1,d="managed",_=(w,ce)=>{let C=w.permissions;if(d==="managed"&&(w.allowManagedPermissionRulesOnly===!0||g(C)&&C.allowManagedPermissionRulesOnly===!0)&&(c=!0),C===void 0)return!0;if(!g(C))return!1;for(let Ae of["deny","ask","allow"]){let $e=Z(C[Ae]);if(!$e)return!1;for(let Te of $e){let I=/^\s*Bash\s*(?:\(([\s\S]*)\))?\s*$/.exec(Te);if(I)if(Ae!=="allow")ce.push(P((I[1]??"*").replace(/:\*$/," *")));else if(I[1]===void 0||I[1].trim()==="*")a[d]=!0;else{l.push(P(I[1].replace(/:\*$/," *")));let Ce=pr(I[1]);Ce&&u[d].push({rule:Te.trim(),matches:Ce})}}}return!0},m=[];for(let[w,ce]of s){d=ce;let C=q(w,!1,_,!0);if(C==="unreadable")return"unreadable";m.push(...C.matchers)}let h=a.managed||(a.loaded||a.loadedLocal)&&!c,$=[...u.managed,...c?[]:u.loaded];return{matchers:[...m,...h?[]:l],complete:!0,allow:l,allowsEverything:h,guards:m,trustedAllow:$}}function Vn(e){let t=[p(R(),".cursor","cli-config.json"),...V(e).map(n=>p(n,".cursor","cli.json"))];return q(t,!0,(n,r)=>{let o=n.permissions;if(o===void 0)return!0;if(!g(o))return!1;let i=Z(o.deny);if(!i)return!1;for(let s of i){let l=/^\s*Shell\s*(?:\(([\s\S]*)\))?\s*$/.exec(s);if(!l)continue;let u=l[1]??"*",a=u.indexOf(":");r.push(P(a===-1?`${u} *`:`${u.slice(0,a)} ${u.slice(a+1)}`))}return!0},!1)}function qn(){return process.platform==="darwin"?"/Library/Application Support/GeminiCli":process.platform==="win32"?"C:\\ProgramData\\gemini-cli":"/etc/gemini-cli"}var ot=/^\s*(?:run_shell_command|ShellTool)\s*(?:\(([\s\S]*)\))?\s*$/;function Kn(e,t){let n=e.tools;if(n!==void 0&&!g(n))return!1;let r=[Z(e.excludeTools),Z(g(n)?n.exclude:void 0)];for(let o of r){if(!o)return!1;for(let i of o){let s=ot.exec(i);s&&t.push(P(s[1]===void 0?"*":`${s[1]}*`))}}return!0}function Ge(e){try{return JSON.parse(e)}catch{return null}}function Yn(e){let t=e.trim();if(t.startsWith('"""')||t.startsWith("'''"))return null;if(t.startsWith("[")){if(!/\]\s*(?:#.*)?$/.test(t))return null;let n=[];for(let r of t.matchAll(/"((?:\\.|[^"\\])*)"|'([^']*)'/g)){let o=r[2]??Ge(`"${r[1]}"`);if(o===null)return null;n.push(o)}return n}if(t.startsWith('"')){let n=/^"((?:\\.|[^"\\])*)"/.exec(t);return n?Ge(`"${n[1]}"`):null}if(t.startsWith("'")){let n=/^'([^']*)'/.exec(t);return n?n[1]:null}return t.replace(/\s*#.*$/,"")}function Xn(e,t){for(let n of e.split(/^\s*\[\[\s*rule\s*\]\]\s*$/m).slice(1)){let r={};for(let u of n.split(/\r?\n/)){if(/^\s*\[/.test(u))break;let a=/^\s*([A-Za-z_]+)\s*=\s*(.*)$/.exec(u);if(!a)continue;let c=Yn(a[2]);if(c===null)return!1;r[a[1]]=c}let o=r.decision;if(o!=="deny"&&o!=="ask_user"||!(r.toolName===void 0?["*"]:[r.toolName].flat()).some(u=>u==="*"||ot.test(u)))continue;let s=r.commandPrefix===void 0?[]:[r.commandPrefix].flat(),l=[r.commandRegex,r.argsPattern].flat().filter(u=>typeof u=="string");if(s.length===0&&l.length===0){t.push(()=>!0);continue}for(let u of s)t.push(P(`${u}*`));for(let u of l){let a;try{a=new RegExp(u)}catch{return!1}t.push(c=>a.test(JSON.stringify({command:c}))||le(a,c))}}return!0}function Ze(e){try{return oe(e).filter(t=>t.endsWith(".toml")).map(t=>p(e,t))}catch{return[]}}function Qn(e){let t=qn(),n=[p(t,"system-defaults.json"),p(t,"settings.json"),process.env.GEMINI_CLI_SYSTEM_SETTINGS_PATH,process.env.GEMINI_CLI_SYSTEM_DEFAULTS_PATH,p(R(),".gemini","settings.json"),...V(e).map(o=>p(o,".gemini","settings.json"))].filter(o=>!!o),r=q(n,!0,Kn,!1);if(r==="unreadable")return r;for(let o of[...Ze(p(R(),".gemini","policies")),...Ze(p(t,"policies"))]){let i;try{i=G(o,"utf8")}catch{return"unreadable"}if(!Xn(i,r.matchers))return"unreadable"}return r}function ke(e,t){if(e===void 0)return!0;if(typeof e=="string")return e!=="allow"&&t.push(()=>!0),!0;if(!g(e))return!1;for(let n of["bash","shell","*"]){let r=e[n];if(r!==void 0){if(typeof r=="string"){r!=="allow"&&t.push(()=>!0);continue}if(!g(r))return!1;for(let[o,i]of Object.entries(r))i!=="allow"&&t.push(P(o.replace(/\?/g,"*")))}}return!0}function Ve(e,t){if(e.permissions!==void 0||!ke(e.permission,t))return!1;for(let n of["agent","agents","mode"]){let r=e[n];if(r!==void 0){if(!g(r))return!1;for(let o of Object.values(r))if(g(o)&&(o.permissions!==void 0||!ke(o.permission,t)))return!1}}return!0}function er(e){for(let t of e)for(let n of["agent","agents","mode","modes"]){let r;try{r=oe(p(t,n))}catch{continue}for(let o of r)try{if(o.endsWith(".md")&&/permission/i.test(G(p(t,n,o),"utf8")))return!0}catch{return!0}}return!1}function tr(e){let t=p(process.env.XDG_CONFIG_HOME||p(R(),".config"),"opencode"),n=V(e),r=[t,...n.map(l=>p(l,".opencode"))];if(er(r))return"unreadable";let o=["opencode.json","opencode.jsonc","config.json"],i=[...o.map(l=>p(t,l)),process.env.OPENCODE_CONFIG,...n.flatMap(l=>[...o.slice(0,2).map(u=>p(l,u)),...o.slice(0,2).map(u=>p(l,".opencode",u))])].filter(l=>!!l),s=q(i,!0,Ve,!0);if(s==="unreadable")return s;for(let l of[process.env.OPENCODE_CONFIG_CONTENT,process.env.OPENCODE_PERMISSION]){if(!l)continue;let u;try{u=JSON.parse(rt(l))}catch{return"unreadable"}if(!(l===process.env.OPENCODE_PERMISSION?ke(u,s.matchers):g(u)&&Ve(u,s.matchers)))return"unreadable"}return s}function nr(){return q([p(R(),".gemini","antigravity-cli","settings.json")],!0,(e,t)=>{let n=e.permissions;if(n===void 0)return!0;if(!g(n))return!1;for(let r of["deny","ask"]){let o=Z(n[r]);if(!o)return!1;for(let i of o){let s=/^\s*command\s*\(([\s\S]*)\)\s*$/.exec(i);if(!s)continue;let l=s[1].trim();if(!l.startsWith("regex:")){t.push(P(l==="*"?"*":`${l} *`));continue}let u;try{u=new RegExp(l.slice(6))}catch{return!1}t.push(a=>le(u,a))}}return!0},!1)}function rr(e){let t=[],n=/\s+|#[^\n]*|("(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')|([A-Za-z_][A-Za-z0-9_]*|[()[\],=])|(.)/gy;for(let r=n.exec(e);r&&r[0];r=n.exec(e)){if(r[3]!==void 0)return null;(r[1]!==void 0||r[2]!==void 0)&&t.push(r[1]??r[2])}return t}function it(e,t){let n=e[t.i++];if(n===void 0)return;if(/^["']/.test(n))try{return n.startsWith('"')?JSON.parse(n):JSON.parse(`"${n.slice(1,-1).replace(/\\'/g,"'").replace(/"/g,'\\"')}"`)}catch{return}if(n!=="[")return/^[A-Za-z_]/.test(n)?null:void 0;let r=[];for(;e[t.i]!=="]";){let o=it(e,t);if(o===void 0)return;if(r.push(o),e[t.i]===",")t.i++;else if(e[t.i]!=="]")return}return t.i++,r}function st(e){if(!Array.isArray(e)||e.length===0)return null;let t=[];for(let r of e){let o=typeof r=="string"?[r]:Array.isArray(r)?r:null;if(!o||o.length===0||!o.every(i=>typeof i=="string"&&i!==""))return null;t.push(`(?:${o.map(we).join("|")})`)}let n=new RegExp(`^${t.join(" ")}(?= |$)`);return r=>le(n,r)}function or(e,t){let n=rr(e);if(!n)return!1;for(let r=0;r<n.length;r++){if(n[r]!=="prefix_rule"||n[r+1]!=="(")continue;let o={i:r+2},i={};for(;n[o.i]!==")";){let u=n[o.i];if(!u||!/^[A-Za-z_]/.test(u)||n[o.i+1]!=="="||(o.i+=2,i[u]=it(n,o),i[u]===void 0&&(u==="pattern"||u==="decision")))return!1;if(n[o.i]===",")o.i++;else if(n[o.i]!==")")return!1}r=o.i;let s="decision"in i?i.decision:"allow";if(s!=="allow"&&s!=="prompt"&&s!=="forbidden")return!1;let l=st(i.pattern);if(!l)return!1;s!=="allow"&&t.push(l)}return!0}function ir(e){if(!W(e))return[];try{return oe(e).filter(t=>t.endsWith(".rules")).sort().map(t=>p(e,t))}catch{return"unreadable"}}function sr(){return process.platform==="win32"?p(process.env.ProgramData||"C:\\ProgramData","OpenAI","Codex","requirements.toml"):"/etc/codex/requirements.toml"}function lr(e){if(!(!g(e)||Object.keys(e).length!==1)){if(typeof e.token=="string")return e.token;if(Array.isArray(e.any_of)&&e.any_of.every(t=>typeof t=="string"))return e.any_of}}function ur(e,t){let n;try{n=pe(e)}catch{return!1}if(n.rules===void 0)return!0;if(!g(n.rules))return!1;let r=n.rules.prefix_rules;if(r===void 0)return!0;if(!Array.isArray(r))return!1;for(let o of r){if(!g(o)||!Array.isArray(o.pattern)||o.decision!=="prompt"&&o.decision!=="forbidden")return!1;let i=o.pattern.map(lr);if(i.some(l=>l===void 0))return!1;let s=st(i);if(!s)return!1;t.push(s)}return!0}function ar(e){let t=process.env.CODEX_HOME||p(R(),".codex"),n=[p(t,"rules"),...V(e).map(i=>p(i,".codex","rules"))],r=[],o=null;try{o=G(sr(),"utf8")}catch(i){let s=i.code;if(s!=="ENOENT"&&s!=="ENOTDIR")return"unreadable"}if(o!==null&&!ur(o,r))return"unreadable";for(let i of[...new Set(n)]){let s=ir(i);if(s==="unreadable")return"unreadable";for(let l of s){let u;try{u=G(l,"utf8")}catch{return"unreadable"}if(!or(u,r))return"unreadable"}}return{matchers:r,complete:!1}}function g(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function we(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function cr(e){let t=e.trim().replace(/\s+/g," "),n=t.endsWith(" *")&&t.length>2,r=(n?t.slice(0,-2):t).split("*").map(we).join("[\\s\\S]*");return new RegExp(`^${r}${n?"(?: [\\s\\S]*)?":""}(?= |$)`)}var fr=512;function dr(e){let t=e.replace(/['"\\]/g,"").split(/[\s;&|(){}<>`$]+/).filter(Boolean);return[t,t.map(ie)]}function le(e,t){if(e.test(t)||e.test(t.trim().replace(/\s+/g," ")))return!0;for(let n of dr(t)){if(n.length>fr)return!0;for(let r=0;r<n.length;r++)if(e.test(n.slice(r).join(" ")))return!0}return!1}function P(e){let t=cr(e);return n=>le(t,n)}function pr(e){let t=e.trim().replace(/:\*$/," *"),n=t.endsWith(" *"),r=n?t.slice(0,-2):t;if(!r||r.includes("*")||/\s\s|[^\S ]|^ | $/.test(r))return null;let o=new RegExp(`^${we(r)}${n?"(?: [\\s\\S]*)?":""}$`);return i=>o.test(i)}var mr={"claude-code":Zn,cursor:Vn,"gemini-cli":Qn,opencode:tr,antigravity:nr,codex:ar},gr=new Set(["codex"]),lt=/(?:^|[\s=:/~])\.(?:git|claude|vscode|idea|husky)(?=[/\s;|&)]|$)|(?:^|[\s=:/~])\.(?:bashrc|bash_profile|bash_login|bash_logout|profile|zshrc|zprofile|zshenv|zlogin|zlogout|gitconfig|gitmodules|ripgreprc|mcp\.json)(?![A-Za-z0-9_])/;function hr(e,t,n){let r=mr[e];return r?r(t??process.cwd(),n):{matchers:[],complete:!1}}function kr(e,t,n){return e==="unreadable"||lt.test(t.replace(/['"\\]/g,""))||e.matchers.some(r=>r(t))?!1:e.complete||tt(t,!gr.has(n))}var ut=new Set(["default","acceptEdits","dontAsk"]);function at(e,t){return t.host!=="claude-code"||t.permissionMode==="bypassPermissions"?!0:e!=="unreadable"&&e.allowsEverything===!0&&ut.has(t.permissionMode??"")}function _r(e,t){let n="pathEnv"in e?e.pathEnv:process.env.PATH,r;return o=>e.host!=="claude-code"?N(o,e.cwd,n):(r??=je(t.configDir),!N(o,e.cwd,n)&&!r.paths.some(i=>N(o,e.cwd,i))?!1:o.includes("/")||!Fe(o,r))}var br=/^[^\s;&|<>()$`\\{}*?[\]~#!]+(?: [^\s;&|<>()$`\\{}*?[\]~#!]+)*$/;function yr(e,t,n){return n.host!=="claude-code"||e==="unreadable"||at(e,n)||!ut.has(n.permissionMode??"")||!br.test(t)||lt.test(t.replace(/['"]/g,""))||(e.guards??[]).some(r=>r(t))?null:(e.trustedAllow??[]).find(r=>r.matches(t))?.rule??null}function ct(e,t,n,r){if(!n||/["\\$`;&|<>(){}]|'\\''/.test(n))return null;let o=t.claudeDirs??se(),i=hr(t.host,t.cwd,o),s=yr(i,e,t),l=s||kr(i,e,t.host)?Ln(e,n,_r(t,o)):e;return l!==e&&i!=="unreadable"&&(s?(i.guards??[]).some(u=>u(l)):i.matchers.some(u=>u(l))||(i.allow??[]).some(u=>u(l)&&!u(e)))&&(l=e),r(t.sessionId,l!==e),l===e?null:s?{command:l,allowedBy:s}:at(i,t)?{command:l}:null}function O(e,t,n,r){return ct(e,t,n,r)?.command??null}import{rmSync as wr,statSync as Sr}from"node:fs";import{join as xr}from"node:path";function ft(){return xr(E(),"fail-open")}var Ar=24*36e5;function A(e=Date.now()){try{if(e-Sr(ft()).mtimeMs<Ar)return!0;wr(ft(),{force:!0})}catch{}return!1}function k(e,t){let n=e[t];return typeof n=="string"&&n?n:null}function K(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function $r(e){return k(e,"prompt_id")||k(e,"scratchpad_dir")?!0:K(e.effort)}function Tr(e){return k(e,"tool_use_id")?.startsWith("toolu_")===!0||/^claude/i.test(k(e,"model")??"")}var Cr=new Set(["BeforeTool","AfterTool","BeforeAgent","AfterAgent","BeforeModel","AfterModel","BeforeToolSelection"]),Er=new Set(["preToolUse","postToolUse","beforeShellExecution","afterShellExecution","beforeSubmitPrompt","sessionStart","sessionEnd","stop"]),Or=new Set(["pre_tool","post_tool"]),vr=new Set(["before_tool_call","after_tool_call"]),Rr=new Set(["runTerminalCommand","run_in_terminal"]),Pr=[["codex",e=>k(e,"turn_id")!==null],["claude-code",$r],["cursor",e=>k(e,"cursor_version")!==null||k(e,"generation_id")!==null||k(e,"conversation_id")!==null||Array.isArray(e.workspace_roots)||Er.has(k(e,"hook_event_name")??"")],["gemini-cli",e=>Cr.has(k(e,"hook_event_name")??"")],["qwen-code",e=>e.hook_event_name==="PreToolUse"&&e.tool_name==="run_shell_command"],["vibe",e=>Or.has(k(e,"hook_event_name")??"")],["antigravity",e=>K(e.toolCall)],["copilot",e=>k(e,"toolName")!==null&&"toolArgs"in e||Rr.has(k(e,"tool_name")??"")],["grok",e=>e.toolName==="run_terminal_command"||e.tool_name==="run_terminal_command"||K(e.toolInput)&&!("toolArgs"in e)],["droid",e=>e.tool_name==="Execute"],["trae",e=>e.tool_name==="RunCommand"],["crush",e=>e.hook_event_name===void 0&&k(e,"event")!==null&&!vr.has(k(e,"event"))]],Ir=new Set(["codex","antigravity"]);function Nr(e){return K(e)?Pr.filter(([,t])=>t(e)).map(([t])=>t):[]}function dt(e,t){if(!K(e))return null;let n=Nr(e);return n.length>1?null:n.length===1?n[0]:Tr(e)&&Ir.has(t)?"claude-code":t==="codex"?null:t}var Se=JSON.stringify({permission:"allow"});function pt(e,t=x("cursor"),n=y){if(e.tool_name!=="Shell")return Se;let r=e.tool_input??{},o=r.command;if(typeof o!="string"||!o)return Se;let i=typeof r.working_directory=="string"?r.working_directory:void 0,s=O(o,{host:"cursor",sessionId:e.conversation_id??"unknown",cwd:i},A()?null:t,n);return s?JSON.stringify({permission:"allow",updated_input:{...r,command:s}}):Se}function H(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}var zi=String.raw`(?:'(?:(?:[^']|'\\'')*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?'|"(?:[^"]*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?"|(?:[^\s'"]*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?)`;function L(e,t,n="unknown",r=x(t),o=y){return e?O(e,{host:t,sessionId:n},A()?null:r,o):null}var Lr=new Set(["bash","file_system.bash"]),xe=JSON.stringify({decision:"allow"});function mt(e,t=(n,r)=>L(n,"vibe",r)){if(!H(e)||e.hook_event_name!=="pre_tool"||typeof e.tool_name!="string"||!Lr.has(e.tool_name))return"";let n=e.tool_input;if(!H(n)||typeof n.command!="string"||!n.command)return"";let r=t(n.command,typeof e.session_id=="string"?e.session_id:"unknown");return r?JSON.stringify({hook_specific_output:{tool_input:{...n,command:r}}}):""}function gt(e,t=(n,r)=>L(n,"antigravity",r)){if(!H(e)||!H(e.toolCall)||e.toolCall.name!=="run_command")return xe;let n=e.toolCall.args;if(!H(n)||typeof n.CommandLine!="string"||!n.CommandLine)return xe;let r=t(n.CommandLine,typeof e.conversationId=="string"?e.conversationId:"unknown");return r?JSON.stringify({decision:"allow",overwrite:{CommandLine:r}}):xe}var T="{}",Dr=new Set(["runTerminalCommand","run_in_terminal","Bash","bash"]),jr=["run_in_background","is_background","isBackground"];function ue(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function Fr(e){let t=e.session_id??e.sessionId;return typeof t=="string"&&t?t:"unknown"}function Mr(e,t){let n=e.cwd??t.cwd??t.workdir??t.working_directory;return typeof n=="string"&&n?n:void 0}function ae(e,t,n,r,o){if(!ue(t)||jr.some(s=>t[s]===!0))return null;let i=t.command;return typeof i!="string"||!i?null:O(i,{host:e,sessionId:Fr(n),cwd:Mr(n,t)},A()?null:r,o)}function j(e,t){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",updatedInput:{...e,command:t}}})}function Ur(e){if(ue(e))return e;if(typeof e!="string")return null;try{let t=JSON.parse(e);return ue(t)?t:null}catch{return null}}function zr(e,t,n){if(typeof e.tool_name=="string"){if(!Dr.has(e.tool_name))return T;let i=e.tool_input,s=ae("copilot",i,e,t,n);return s?j(i,s):T}if(e.toolName!=="bash")return T;let r=Ur(e.toolArgs),o=ae("copilot",r,e,t,n);return o?JSON.stringify({modifiedArgs:{...r,command:o}}):T}function D(e,t,n){return(r,o,i)=>{if(r.tool_name!==t)return T;let s=r.tool_input,l=ae(e,s,r,o,i);return l?n(s,l):T}}var Jr=new Set(["run_terminal_command","Bash","bash"]);function Br(e,t,n){let r=e.toolName??e.tool_name;if(typeof r!="string"||!Jr.has(r))return T;let o=e.toolInput??e.tool_input,i=ae("grok",o,e,t,n);return i?j(o,i):T}var Wr={copilot:zr,droid:D("droid","Execute",j),trae:D("trae","RunCommand",j),"qwen-code":D("qwen-code","run_shell_command",j),crush:D("crush","bash",(e,t)=>JSON.stringify({updated_input:{command:t}})),junie:D("junie","Bash",(e,t)=>JSON.stringify({updatedInput:{...e,command:t}})),zcode:D("zcode","Bash",j),grok:Br};function ht(e,t,n=x(e),r=y){return ue(t)?Wr[e](t,n,r):T}function F(e){return A()?null:x(e)}function Gr(e,t,n={}){let r=n.recordUsage??y;switch(e){case"claude-code":case"codex":return t.hook_event_name!==void 0&&t.hook_event_name!=="PreToolUse"?"":nt(t,e,F(e),r,n.claudeDirs??se(),n.pathEnv??process.env.PATH,n.launchArgs??ye)??"";case"cursor":return pt(t,F(e),r);case"gemini-cli":return kt(t,F(e),r);case"vibe":return mt(t,(o,i)=>L(o,"vibe",i,F(e),r));case"antigravity":return gt(t,(o,i)=>L(o,"antigravity",i,F(e),r));default:return ht(e,t,F(e),r)}}function Y(e,t,n={}){let r=dt(e,t);return r?Gr(r,e,n):n.fallback??""}var v="{}";function kt(e,t=x("gemini-cli"),n=y){if(e.hook_event_name!=="BeforeTool"||e.tool_name!=="run_shell_command")return v;let r=e.tool_input??{};if(r.is_background)return v;let o=r.command;if(typeof o!="string"||!o)return v;let i=typeof e.cwd=="string"?e.cwd:void 0,s=O(o,{host:"gemini-cli",sessionId:e.session_id??"unknown",cwd:i},A()?null:t,n);return s?JSON.stringify({hookSpecificOutput:{tool_input:{command:s}}}):v}function Zr(e){if(!e)return v;let t;try{t=JSON.parse(e)}catch{return v}return!t||typeof t!="object"?v:Y(t,"gemini-cli",{fallback:v})}async function _t(){process.stdout.write(Zr(await M()))}_t().catch(e=>{process.stderr.write(`tkr-gemini-hook: ${e.message}
18
+ `}else if(o==="/"&&e[r+1]==="*"){if(r=e.indexOf("*/",r+2),r===-1)return"";r+=1}else t+=o}return t.replace(/,(\s*[}\]])/g,"$1")}function te(e){let t=[],n=br(e);for(;;){t.push(n);let r=bt(n);if(r===n)return t;n=r}}function Br(){let e=process.platform==="darwin"?"/Library/Application Support/ClaudeCode":process.platform==="win32"?"C:\\Program Files\\ClaudeCode":"/etc/claude-code",t=[p(e,"managed-settings.json")];try{for(let n of de(p(e,"managed-settings.d")))n.endsWith(".json")&&t.push(p(e,"managed-settings.d",n))}catch{return t}return t}function ne(e,t,n,r){let o=[];for(let i of e){let s=Jr(i,t);if(s!=="missing"&&(s==="unreadable"||!g(s)||!n(s,o)))return"unreadable"}return{matchers:o,complete:r}}function ee(e){return e===void 0?[]:Array.isArray(e)?e.filter(t=>typeof t=="string"):null}function me(){return{projectDir:process.env.CLAUDE_PROJECT_DIR,configDir:process.env.CLAUDE_CONFIG_DIR}}function Wr(e,t){let n=w=>[p(w,"settings.json"),p(w,"settings.local.json")],r=w=>n(p(w,".claude")),o=p(I(),".claude"),i=t.configDir||o,s=[[Br(),"managed"],[[p(i,"settings.json")],"loaded"],[[p(i,"settings.local.json")],"loadedLocal"],[t.configDir?n(o):[],"extra"],[t.projectDir?r(t.projectDir):[],"project"],[te(e).flatMap(r),"extra"]],l=[],u={managed:[],loaded:[],loadedLocal:[],project:[],extra:[]},a={managed:!1,loaded:!1,loadedLocal:!1,project:!1,extra:!1},c=!1,d="managed",_=(w,_e)=>{let E=w.permissions;if(d==="managed"&&(w.allowManagedPermissionRulesOnly===!0||g(E)&&E.allowManagedPermissionRulesOnly===!0)&&(c=!0),E===void 0)return!0;if(!g(E))return!1;for(let De of["deny","ask","allow"]){let Fe=ee(E[De]);if(!Fe)return!1;for(let Me of Fe){let L=/^\s*Bash\s*(?:\(([\s\S]*)\))?\s*$/.exec(Me);if(L)if(De!=="allow")_e.push(H((L[1]??"*").replace(/:\*$/," *")));else if(L[1]===void 0||L[1].trim()==="*")a[d]=!0;else{l.push(H(L[1].replace(/:\*$/," *")));let Ue=fo(L[1]);Ue&&u[d].push({rule:Me.trim(),matches:Ue})}}}return!0},m=[];for(let[w,_e]of s){d=_e;let E=ne(w,!1,_,!0);if(E==="unreadable")return"unreadable";m.push(...E.matchers)}let h=a.managed||(a.loaded||a.loadedLocal)&&!c,C=[...u.managed,...c?[]:u.loaded];return{matchers:[...m,...h?[]:l],complete:!0,allow:l,allowsEverything:h,guards:m,trustedAllow:C}}function Gr(e){let t=[p(I(),".cursor","cli-config.json"),...te(e).map(n=>p(n,".cursor","cli.json"))];return ne(t,!0,(n,r)=>{let o=n.permissions;if(o===void 0)return!0;if(!g(o))return!1;let i=ee(o.deny);if(!i)return!1;for(let s of i){let l=/^\s*Shell\s*(?:\(([\s\S]*)\))?\s*$/.exec(s);if(!l)continue;let u=l[1]??"*",a=u.indexOf(":");r.push(H(a===-1?`${u} *`:`${u.slice(0,a)} ${u.slice(a+1)}`))}return!0},!1)}function Zr(){return process.platform==="darwin"?"/Library/Application Support/GeminiCli":process.platform==="win32"?"C:\\ProgramData\\gemini-cli":"/etc/gemini-cli"}var vt=/^\s*(?:run_shell_command|ShellTool)\s*(?:\(([\s\S]*)\))?\s*$/;function Vr(e,t){let n=e.tools;if(n!==void 0&&!g(n))return!1;let r=[ee(e.excludeTools),ee(g(n)?n.exclude:void 0)];for(let o of r){if(!o)return!1;for(let i of o){let s=vt.exec(i);s&&t.push(H(s[1]===void 0?"*":`${s[1]}*`))}}return!0}function ht(e){try{return JSON.parse(e)}catch{return null}}function Kr(e){let t=e.trim();if(t.startsWith('"""')||t.startsWith("'''"))return null;if(t.startsWith("[")){if(!/\]\s*(?:#.*)?$/.test(t))return null;let n=[];for(let r of t.matchAll(/"((?:\\.|[^"\\])*)"|'([^']*)'/g)){let o=r[2]??ht(`"${r[1]}"`);if(o===null)return null;n.push(o)}return n}if(t.startsWith('"')){let n=/^"((?:\\.|[^"\\])*)"/.exec(t);return n?ht(`"${n[1]}"`):null}if(t.startsWith("'")){let n=/^'([^']*)'/.exec(t);return n?n[1]:null}return t.replace(/\s*#.*$/,"")}function qr(e,t){for(let n of e.split(/^\s*\[\[\s*rule\s*\]\]\s*$/m).slice(1)){let r={};for(let u of n.split(/\r?\n/)){if(/^\s*\[/.test(u))break;let a=/^\s*([A-Za-z_]+)\s*=\s*(.*)$/.exec(u);if(!a)continue;let c=Kr(a[2]);if(c===null)return!1;r[a[1]]=c}let o=r.decision;if(o!=="deny"&&o!=="ask_user"||!(r.toolName===void 0?["*"]:[r.toolName].flat()).some(u=>u==="*"||vt.test(u)))continue;let s=r.commandPrefix===void 0?[]:[r.commandPrefix].flat(),l=[r.commandRegex,r.argsPattern].flat().filter(u=>typeof u=="string");if(s.length===0&&l.length===0){t.push(()=>!0);continue}for(let u of s)t.push(H(`${u}*`));for(let u of l){let a;try{a=new RegExp(u)}catch{return!1}t.push(c=>a.test(JSON.stringify({command:c}))||ge(a,c))}}return!0}function kt(e){try{return de(e).filter(t=>t.endsWith(".toml")).map(t=>p(e,t))}catch{return[]}}function Yr(e){let t=Zr(),n=[p(t,"system-defaults.json"),p(t,"settings.json"),process.env.GEMINI_CLI_SYSTEM_SETTINGS_PATH,process.env.GEMINI_CLI_SYSTEM_DEFAULTS_PATH,p(I(),".gemini","settings.json"),...te(e).map(o=>p(o,".gemini","settings.json"))].filter(o=>!!o),r=ne(n,!0,Vr,!1);if(r==="unreadable")return r;for(let o of[...kt(p(I(),".gemini","policies")),...kt(p(t,"policies"))]){let i;try{i=Q(o,"utf8")}catch{return"unreadable"}if(!qr(i,r.matchers))return"unreadable"}return r}function Re(e,t){if(e===void 0)return!0;if(typeof e=="string")return e!=="allow"&&t.push(()=>!0),!0;if(!g(e))return!1;for(let n of["bash","shell","*"]){let r=e[n];if(r!==void 0){if(typeof r=="string"){r!=="allow"&&t.push(()=>!0);continue}if(!g(r))return!1;for(let[o,i]of Object.entries(r))i!=="allow"&&t.push(H(o.replace(/\?/g,"*")))}}return!0}function _t(e,t){if(e.permissions!==void 0||!Re(e.permission,t))return!1;for(let n of["agent","agents","mode"]){let r=e[n];if(r!==void 0){if(!g(r))return!1;for(let o of Object.values(r))if(g(o)&&(o.permissions!==void 0||!Re(o.permission,t)))return!1}}return!0}function Xr(e){for(let t of e)for(let n of["agent","agents","mode","modes"]){let r;try{r=de(p(t,n))}catch{continue}for(let o of r)try{if(o.endsWith(".md")&&/permission/i.test(Q(p(t,n,o),"utf8")))return!0}catch{return!0}}return!1}function Qr(e){let t=p(process.env.XDG_CONFIG_HOME||p(I(),".config"),"opencode"),n=te(e),r=[t,...n.map(l=>p(l,".opencode"))];if(Xr(r))return"unreadable";let o=["opencode.json","opencode.jsonc","config.json"],i=[...o.map(l=>p(t,l)),process.env.OPENCODE_CONFIG,...n.flatMap(l=>[...o.slice(0,2).map(u=>p(l,u)),...o.slice(0,2).map(u=>p(l,".opencode",u))])].filter(l=>!!l),s=ne(i,!0,_t,!0);if(s==="unreadable")return s;for(let l of[process.env.OPENCODE_CONFIG_CONTENT,process.env.OPENCODE_PERMISSION]){if(!l)continue;let u;try{u=JSON.parse(Ct(l))}catch{return"unreadable"}if(!(l===process.env.OPENCODE_PERMISSION?Re(u,s.matchers):g(u)&&_t(u,s.matchers)))return"unreadable"}return s}function eo(){return ne([p(I(),".gemini","antigravity-cli","settings.json")],!0,(e,t)=>{let n=e.permissions;if(n===void 0)return!0;if(!g(n))return!1;for(let r of["deny","ask"]){let o=ee(n[r]);if(!o)return!1;for(let i of o){let s=/^\s*command\s*\(([\s\S]*)\)\s*$/.exec(i);if(!s)continue;let l=s[1].trim();if(!l.startsWith("regex:")){t.push(H(l==="*"?"*":`${l} *`));continue}let u;try{u=new RegExp(l.slice(6))}catch{return!1}t.push(a=>ge(u,a))}}return!0},!1)}function to(e){let t=[],n=/\s+|#[^\n]*|("(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*')|([A-Za-z_][A-Za-z0-9_]*|[()[\],=])|(.)/gy;for(let r=n.exec(e);r&&r[0];r=n.exec(e)){if(r[3]!==void 0)return null;(r[1]!==void 0||r[2]!==void 0)&&t.push(r[1]??r[2])}return t}function Et(e,t){let n=e[t.i++];if(n===void 0)return;if(/^["']/.test(n))try{return n.startsWith('"')?JSON.parse(n):JSON.parse(`"${n.slice(1,-1).replace(/\\'/g,"'").replace(/"/g,'\\"')}"`)}catch{return}if(n!=="[")return/^[A-Za-z_]/.test(n)?null:void 0;let r=[];for(;e[t.i]!=="]";){let o=Et(e,t);if(o===void 0)return;if(r.push(o),e[t.i]===",")t.i++;else if(e[t.i]!=="]")return}return t.i++,r}function Ot(e){if(!Array.isArray(e)||e.length===0)return null;let t=[];for(let r of e){let o=typeof r=="string"?[r]:Array.isArray(r)?r:null;if(!o||o.length===0||!o.every(i=>typeof i=="string"&&i!==""))return null;t.push(`(?:${o.map(He).join("|")})`)}let n=new RegExp(`^${t.join(" ")}(?= |$)`);return r=>ge(n,r)}function no(e,t){let n=to(e);if(!n)return!1;for(let r=0;r<n.length;r++){if(n[r]!=="prefix_rule"||n[r+1]!=="(")continue;let o={i:r+2},i={};for(;n[o.i]!==")";){let u=n[o.i];if(!u||!/^[A-Za-z_]/.test(u)||n[o.i+1]!=="="||(o.i+=2,i[u]=Et(n,o),i[u]===void 0&&(u==="pattern"||u==="decision")))return!1;if(n[o.i]===",")o.i++;else if(n[o.i]!==")")return!1}r=o.i;let s="decision"in i?i.decision:"allow";if(s!=="allow"&&s!=="prompt"&&s!=="forbidden")return!1;let l=Ot(i.pattern);if(!l)return!1;s!=="allow"&&t.push(l)}return!0}function ro(e){if(!M(e))return[];try{return de(e).filter(t=>t.endsWith(".rules")).sort().map(t=>p(e,t))}catch{return"unreadable"}}function oo(){return process.platform==="win32"?p(process.env.ProgramData||"C:\\ProgramData","OpenAI","Codex","requirements.toml"):"/etc/codex/requirements.toml"}function io(e){if(!(!g(e)||Object.keys(e).length!==1)){if(typeof e.token=="string")return e.token;if(Array.isArray(e.any_of)&&e.any_of.every(t=>typeof t=="string"))return e.any_of}}function so(e,t){let n;try{n=Ce(e)}catch{return!1}if(n.rules===void 0)return!0;if(!g(n.rules))return!1;let r=n.rules.prefix_rules;if(r===void 0)return!0;if(!Array.isArray(r))return!1;for(let o of r){if(!g(o)||!Array.isArray(o.pattern)||o.decision!=="prompt"&&o.decision!=="forbidden")return!1;let i=o.pattern.map(io);if(i.some(l=>l===void 0))return!1;let s=Ot(i);if(!s)return!1;t.push(s)}return!0}function uo(e){let t=process.env.CODEX_HOME||p(I(),".codex"),n=[p(t,"rules"),...te(e).map(i=>p(i,".codex","rules"))],r=[],o=null;try{o=Q(oo(),"utf8")}catch(i){let s=i.code;if(s!=="ENOENT"&&s!=="ENOTDIR")return"unreadable"}if(o!==null&&!so(o,r))return"unreadable";for(let i of[...new Set(n)]){let s=ro(i);if(s==="unreadable")return"unreadable";for(let l of s){let u;try{u=Q(l,"utf8")}catch{return"unreadable"}if(!no(u,r))return"unreadable"}}return{matchers:r,complete:!1}}function g(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function He(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function lo(e){let t=e.trim().replace(/\s+/g," "),n=t.endsWith(" *")&&t.length>2,r=(n?t.slice(0,-2):t).split("*").map(He).join("[\\s\\S]*");return new RegExp(`^${r}${n?"(?: [\\s\\S]*)?":""}(?= |$)`)}var ao=512;function co(e){let t=e.replace(/['"\\]/g,"").split(/[\s;&|(){}<>`$]+/).filter(Boolean);return[t,t.map(pe)]}function ge(e,t){if(e.test(t)||e.test(t.trim().replace(/\s+/g," ")))return!0;for(let n of co(t)){if(n.length>ao)return!0;for(let r=0;r<n.length;r++)if(e.test(n.slice(r).join(" ")))return!0}return!1}function H(e){let t=lo(e);return n=>ge(t,n)}function fo(e){let t=e.trim().replace(/:\*$/," *"),n=t.endsWith(" *"),r=n?t.slice(0,-2):t;if(!r||r.includes("*")||/\s\s|[^\S ]|^ | $/.test(r))return null;let o=new RegExp(`^${He(r)}${n?"(?: [\\s\\S]*)?":""}$`);return i=>o.test(i)}var po={"claude-code":Wr,cursor:Gr,"gemini-cli":Yr,opencode:Qr,antigravity:eo,codex:uo},mo=new Set(["codex"]),Rt=/(?:^|[\s=:/~])\.(?:git|claude|vscode|idea|husky)(?=[/\s;|&)]|$)|(?:^|[\s=:/~])\.(?:bashrc|bash_profile|bash_login|bash_logout|profile|zshrc|zprofile|zshenv|zlogin|zlogout|gitconfig|gitmodules|ripgreprc|mcp\.json)(?![A-Za-z0-9_])/;function go(e,t,n){let r=po[e];return r?r(t??process.cwd(),n):{matchers:[],complete:!1}}function ho(e,t,n){return e==="unreadable"||Rt.test(t.replace(/['"\\]/g,""))||e.matchers.some(r=>r(t))?!1:e.complete||At(t,!mo.has(n))}var Nt=new Set(["default","acceptEdits","dontAsk"]);function Pt(e,t){return t.host!=="claude-code"||t.permissionMode==="bypassPermissions"?!0:e!=="unreadable"&&e.allowsEverything===!0&&Nt.has(t.permissionMode??"")}function ko(e,t){let n="pathEnv"in e?e.pathEnv:process.env.PATH,r;return o=>e.host!=="claude-code"?F(o,e.cwd,n):(r??=lt(t.configDir),!F(o,e.cwd,n)&&!r.paths.some(i=>F(o,e.cwd,i))?!1:o.includes("/")||!at(o,r))}var _o=/^[^\s;&|<>()$`\\{}*?[\]~#!]+(?: [^\s;&|<>()$`\\{}*?[\]~#!]+)*$/;function bo(e,t,n){return n.host!=="claude-code"||e==="unreadable"||Pt(e,n)||!Nt.has(n.permissionMode??"")||!_o.test(t)||Rt.test(t.replace(/['"]/g,""))||(e.guards??[]).some(r=>r(t))?null:(e.trustedAllow??[]).find(r=>r.matches(t))?.rule??null}var yo=/^(?:\S+=\S*\s+)*(?:(?:npx|bunx|pnpm\s+exec|yarn\s+exec|uv\s+run|poetry\s+run)\s+)?(?:\.\/)?(?:ctest|gradlew|gradle|mvnw|mvnd|mvn|make|cmake|sbt|phpstan|phpunit|pest|pytest|py\.test|tox|nox|vitest|jest|mocha|playwright\s+test|tsc|(?:cargo|go)\s+(?:build|test|check|clippy|vet)|(?:bun|deno)\s+(?:test|check|lint|install)|(?:npm|pnpm|yarn)\s+(?:test|t|ci|install|run\s+\S+)|dotnet\s+(?:build|test)|swift\s+(?:build|test)|composer\s+(?:install|update|test))(?:\s|$)/;function wo(e,t){return t.host==="claude-code"&&t.permissionMode==="default"&&yo.test(e.trim())}function It(e,t,n,r){if(!n||/["\\$`;&|<>(){}]|'\\''/.test(n))return null;let o=t.claudeDirs??me(),i=go(t.host,t.cwd,o),s=bo(i,e,t),l=s||ho(i,e,t.host)?Ir(e,n,ko(t,o)):e;return l!==e&&i!=="unreadable"&&(s?(i.guards??[]).some(u=>u(l)):i.matchers.some(u=>u(l))||(i.allow??[]).some(u=>u(l)&&!u(e)))&&(l=e),r(t.sessionId,l!==e),l===e?null:s?{command:l,allowedBy:s}:Pt(i,t)?{command:l}:i!=="unreadable"&&wo(e,t)&&!(i.allow??[]).some(u=>u(e))&&!(i.trustedAllow??[]).some(u=>u.matches(e))?{command:l,ask:!0}:null}function R(e,t,n,r){let o=It(e,t,n,r);return o&&!o.ask?o.command:null}function k(e,t){let n=e[t];return typeof n=="string"&&n?n:null}function re(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function So(e){return k(e,"prompt_id")||k(e,"scratchpad_dir")?!0:re(e.effort)}function xo(e){return k(e,"tool_use_id")?.startsWith("toolu_")===!0||/^claude/i.test(k(e,"model")??"")}var $o=new Set(["BeforeTool","AfterTool","BeforeAgent","AfterAgent","BeforeModel","AfterModel","BeforeToolSelection"]),Ao=new Set(["preToolUse","postToolUse","beforeShellExecution","afterShellExecution","beforeSubmitPrompt","sessionStart","sessionEnd","stop"]),To=new Set(["pre_tool","post_tool"]),Co=new Set(["before_tool_call","after_tool_call"]),vo=new Set(["runTerminalCommand","run_in_terminal"]),Eo=[["codex",e=>k(e,"turn_id")!==null],["claude-code",So],["cursor",e=>k(e,"cursor_version")!==null||k(e,"generation_id")!==null||k(e,"conversation_id")!==null||Array.isArray(e.workspace_roots)||Ao.has(k(e,"hook_event_name")??"")],["gemini-cli",e=>$o.has(k(e,"hook_event_name")??"")],["qwen-code",e=>e.hook_event_name==="PreToolUse"&&e.tool_name==="run_shell_command"],["vibe",e=>To.has(k(e,"hook_event_name")??"")],["antigravity",e=>re(e.toolCall)],["copilot",e=>k(e,"toolName")!==null&&"toolArgs"in e||vo.has(k(e,"tool_name")??"")],["grok",e=>e.toolName==="run_terminal_command"||e.tool_name==="run_terminal_command"||re(e.toolInput)&&!("toolArgs"in e)],["droid",e=>e.tool_name==="Execute"],["trae",e=>e.tool_name==="RunCommand"],["crush",e=>e.hook_event_name===void 0&&k(e,"event")!==null&&!Co.has(k(e,"event"))]],Oo=new Set(["codex","antigravity"]);function Ro(e){return re(e)?Eo.filter(([,t])=>t(e)).map(([t])=>t):[]}function Ht(e,t){if(!re(e))return null;let n=Ro(e);return n.length>1?null:n.length===1?n[0]:xo(e)&&Oo.has(t)?"claude-code":t==="codex"?null:t}var Le=JSON.stringify({permission:"allow"});function Lt(e,t=$("cursor"),n=y){if(e.tool_name!=="Shell")return Le;let r=e.tool_input??{},o=r.command;if(typeof o!="string"||!o)return Le;let i=typeof r.working_directory=="string"?r.working_directory:void 0,s=R(o,{host:"cursor",sessionId:e.conversation_id??"unknown",cwd:i},A()?null:t,n);return s?JSON.stringify({permission:"allow",updated_input:{...r,command:s}}):Le}function U(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}var Us=String.raw`(?:'(?:(?:[^']|'\\'')*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?'|"(?:[^"]*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?"|(?:[^\s'"]*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?)`;function z(e,t,n="unknown",r=$(t),o=y){return e?R(e,{host:t,sessionId:n},A()?null:r,o):null}var No=new Set(["bash","file_system.bash"]),je=JSON.stringify({decision:"allow"});function jt(e,t=(n,r)=>z(n,"vibe",r)){if(!U(e)||e.hook_event_name!=="pre_tool"||typeof e.tool_name!="string"||!No.has(e.tool_name))return"";let n=e.tool_input;if(!U(n)||typeof n.command!="string"||!n.command)return"";let r=t(n.command,typeof e.session_id=="string"?e.session_id:"unknown");return r?JSON.stringify({hook_specific_output:{tool_input:{...n,command:r}}}):""}function Dt(e,t=(n,r)=>z(n,"antigravity",r)){if(!U(e)||!U(e.toolCall)||e.toolCall.name!=="run_command")return je;let n=e.toolCall.args;if(!U(n)||typeof n.CommandLine!="string"||!n.CommandLine)return je;let r=t(n.CommandLine,typeof e.conversationId=="string"?e.conversationId:"unknown");return r?JSON.stringify({decision:"allow",overwrite:{CommandLine:r}}):je}var v="{}",Po=new Set(["runTerminalCommand","run_in_terminal","Bash","bash"]),Io=["run_in_background","is_background","isBackground"];function he(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function Ho(e){let t=e.session_id??e.sessionId;return typeof t=="string"&&t?t:"unknown"}function Lo(e,t){let n=e.cwd??t.cwd??t.workdir??t.working_directory;return typeof n=="string"&&n?n:void 0}function ke(e,t,n,r,o){if(!he(t)||Io.some(s=>t[s]===!0))return null;let i=t.command;return typeof i!="string"||!i?null:R(i,{host:e,sessionId:Ho(n),cwd:Lo(n,t)},A()?null:r,o)}function B(e,t){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",updatedInput:{...e,command:t}}})}function jo(e){if(he(e))return e;if(typeof e!="string")return null;try{let t=JSON.parse(e);return he(t)?t:null}catch{return null}}function Do(e,t,n){if(typeof e.tool_name=="string"){if(!Po.has(e.tool_name))return v;let i=e.tool_input,s=ke("copilot",i,e,t,n);return s?B(i,s):v}if(e.toolName!=="bash")return v;let r=jo(e.toolArgs),o=ke("copilot",r,e,t,n);return o?JSON.stringify({modifiedArgs:{...r,command:o}}):v}function J(e,t,n){return(r,o,i)=>{if(r.tool_name!==t)return v;let s=r.tool_input,l=ke(e,s,r,o,i);return l?n(s,l):v}}var Fo=new Set(["run_terminal_command","Bash","bash"]);function Mo(e,t,n){let r=e.toolName??e.tool_name;if(typeof r!="string"||!Fo.has(r))return v;let o=e.toolInput??e.tool_input,i=ke("grok",o,e,t,n);return i?B(o,i):v}var Uo={copilot:Do,droid:J("droid","Execute",B),trae:J("trae","RunCommand",B),"qwen-code":J("qwen-code","run_shell_command",B),crush:J("crush","bash",(e,t)=>JSON.stringify({updated_input:{command:t}})),junie:J("junie","Bash",(e,t)=>JSON.stringify({updatedInput:{...e,command:t}})),zcode:J("zcode","Bash",B),grok:Mo};function Ft(e,t,n=$(e),r=y){return he(t)?Uo[e](t,n,r):v}function W(e){return A()?null:$(e)}function zo(e,t,n={}){let r=n.recordUsage??y;switch(e){case"claude-code":case"codex":return t.hook_event_name!==void 0&&t.hook_event_name!=="PreToolUse"?"":Tt(t,e,W(e),r,n.claudeDirs??me(),n.pathEnv??process.env.PATH,n.launchArgs??Ie)??"";case"cursor":return Lt(t,W(e),r);case"gemini-cli":return Mt(t,W(e),r);case"vibe":return jt(t,(o,i)=>z(o,"vibe",i,W(e),r));case"antigravity":return Dt(t,(o,i)=>z(o,"antigravity",i,W(e),r));default:return Ft(e,t,W(e),r)}}function oe(e,t,n={}){let r=Ht(e,t);return r?zo(r,e,n):n.fallback??""}var N="{}";function Mt(e,t=$("gemini-cli"),n=y){if(e.hook_event_name!=="BeforeTool"||e.tool_name!=="run_shell_command")return N;let r=e.tool_input??{};if(r.is_background)return N;let o=r.command;if(typeof o!="string"||!o)return N;let i=typeof e.cwd=="string"?e.cwd:void 0,s=R(o,{host:"gemini-cli",sessionId:e.session_id??"unknown",cwd:i},A()?null:t,n);return s?JSON.stringify({hookSpecificOutput:{tool_input:{command:s}}}):N}function Jo(e){if(!e)return N;let t;try{t=JSON.parse(e)}catch{return N}return!t||typeof t!="object"?N:oe(t,"gemini-cli",{fallback:N})}async function Ut(){process.stdout.write(Jo(await G()))}Ut().catch(e=>{process.stderr.write(`tkr-gemini-hook: ${e.message}
18
19
  `),process.stdout.write("{}"),process.exit(0)});
19
20
  /*! Bundled license information:
20
21