@tokmizer/plugin 0.9.70 → 0.9.72

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokmizer",
3
- "version": "0.9.70",
3
+ "version": "0.9.72",
4
4
  "description": "Tokmizer reduces token consumption for AI agents.",
5
5
  "author": {
6
6
  "name": "Tokmizer",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokmizer",
3
- "version": "0.9.70",
3
+ "version": "0.9.72",
4
4
  "description": "Tokmizer reduces token consumption for OpenAI Codex.",
5
5
  "author": {
6
6
  "name": "Tokmizer",
@@ -1,22 +1,22 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __tkrCreateRequire } from "node:module"; const require = __tkrCreateRequire(import.meta.url);
3
- function Z(e=5e3){return new Promise(t=>{let n=[],r=process.stdin,o=!1,i=()=>{o||(o=!0,clearTimeout(u),r.off("data",s),r.pause(),r.unref?.(),t(Buffer.concat(n).toString("utf8")))},s=l=>{n.push(Buffer.isBuffer(l)?l:Buffer.from(l))},u=setTimeout(i,e);r.on("data",s).once("end",i).once("error",i),r.resume()})}import{basename as Kt}from"node:path";var qt={exec:"tkr-exec",processor:"tkr-processor",daemon:"tkr-daemon","shim-run":"tkr-shim"},Yt={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 se(e){let t=Kt(e).replace(/\.(m?js|ts)$/,"");if(t==="tkr")return[];for(let[n,r]of Object.entries(qt))if(r===t)return[n];for(let[n,r]of Object.entries(Yt))if(r===t)return["hook",n];return null}import{realpathSync as Ge}from"node:fs";import{delimiter as Xt,join as j}from"node:path";import Qt from"node:os";function V(){return!1}function Ze(e,t){try{return Ge(e)===Ge(t)}catch{return!1}}function we(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"?";":Xt)){if(!o||o.includes("node_modules"))continue;let i=j(o,r);if(Ze(i,n))return i}if(t!=="win32"){let o=Qt.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(Ze(i,n))return i}return n}import{accessSync as sn,chmodSync as un,constants as ln,existsSync as ue,mkdirSync as an,readdirSync as cn,readFileSync as fn,realpathSync as Xe,renameSync as dn,unlinkSync as pn,writeFileSync as mn}from"node:fs";import{basename as xe,dirname as O,join as C,sep as D}from"node:path";import gn from"node:os";import en from"node:os";import{join as tn}from"node:path";function S(){return process.env.TOKMIZER_HOME||tn(en.homedir(),".tokmizer")}import{rmSync as nn,statSync as rn}from"node:fs";import{join as Ve}from"node:path";function Ke(){return Ve(S(),"shims")}function ye(){return Ve(S(),"fail-open")}var on=24*36e5;function T(e=Date.now()){try{if(e-rn(ye()).mtimeMs<on)return!0;nn(ye(),{force:!0})}catch{}return!1}function qe(){return`[ -f ${N(ye())} ]`}function N(e){return`'${e.replace(/'/g,"'\\''")}'`}function Ye(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 et=1,K="tkr-shim.stable",tt=/^(?:0|[1-9]\d{0,5})\.(?:0|[1-9]\d{0,5})\.(?:0|[1-9]\d{0,5})$/;function hn(){return C(S(),"bin","tkr-shim-launch")}function kn(){return C(S(),"bin","tkr-run")}function Qe(){return C(process.env.CLAUDE_CONFIG_DIR||C(gn.homedir(),".claude"),"plugins","cache","tokmizer","tokmizer")}function _n(e){let t=O(O(O(e)));return tt.test(xe(t))&&xe(O(t))==="tokmizer"?O(t):null}function $e(e){return/[\n\r]/.test(e)||e.includes(`${D}_npx${D}`)||e.includes(`${D}.bun${D}install${D}cache${D}`)}function Ae(e){let t=e.match(/^(.*)[\\/]Cellar[\\/]([^\\/]+)[\\/][^\\/]+[\\/](.*)$/);if(!t)return e;let n=C(t[1],"opt",t[2],t[3]);try{return Xe(n)===Xe(e)?n:e}catch{return e}}function bn(e=process.execPath){return $e(e)?"":Ae(e)}function wn(e,t=V()){if(t&&se(e)){let o=we();return{single:$e(o)?"":Ae(o),js:"",cache:Qe(),node:""}}let n=bn(),r=_n(e);return r?{single:"",js:"",cache:r,node:n}:{single:"",js:$e(e)?"":Ae(e),cache:Qe(),node:n}}function yn(e){try{return sn(e,ln.X_OK),!0}catch{return!1}}function Sn(e){let t=null,n=-1,r;try{r=cn(e)}catch{return null}for(let o of r){if(!tt.test(o))continue;let i=C(e,o);if(!ue(C(i,"dist","bin","tkr-shim.js"))||!ue(C(i,"dist","bin",K)))continue;let[s,u,l]=o.split(".").map(Number),a=s*1e6+u*1e3+l;a>n&&(n=a,t=i)}return t}function Se(e){return e.single&&yn(e.single)||e.js&&ue(e.js)&&(xe(e.js)!=="tkr-shim.js"||ue(C(O(e.js),K)))?!0:e.cache!==""&&Sn(e.cache)!==null}function xn(e,t){return["_tk_t=",`if [ -n "$_tk_j" ] && [ -f "${t}" ] && { [ "\${_tk_j##*/}" != tkr-shim.js ] || [ -f "\${_tk_j%/*}/${K}" ]; }; 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/${K}" ] || 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=${N(Ke())}`," 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/${K}" ] && [ -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 $n(e){return["#!/bin/sh",`_tk_f=${et}`,`_tk_s=${N(e.single)}`,`_tk_j=${N(e.js)}`,`_tk_k=${N(e.cache)}`,`_tk_n=${N(e.node)}`,'[ "$#" -gt 0 ] || exit 0',`if ! ${qe()}; then`,' if [ -n "$_tk_s" ] && [ -x "$_tk_s" ]; then exec "$_tk_s" exec "$@"; fi',...xn("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(`
4
- `)}function nt(e){let t=kn(),n=wn(C(O(e),"tkr-shim.js")),r=Tn(t);if(r&&r.format===et&&Se(r.target)&&JSON.stringify(r.target)===JSON.stringify(n))return t;if(!Se(n))return r&&Se(r.target)?t:null;let o=`${t}.${process.pid}.tmp`;try{return an(O(t),{recursive:!0,mode:448}),mn(o,$n(n),{mode:493}),un(o,493),dn(o,t),t}catch{try{pn(o)}catch{}return null}}function An(e){let t=u=>{let l=e.match(new RegExp(`^${u}=(.*)$`,"m"));return l?u==="_tk_f"?l[1]:Ye(l[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 Tn(e=hn()){try{return An(fn(e,"utf8"))}catch{return null}}function Cn(e){return e.charCodeAt(0)===65279?e.slice(1):e}function Te(e){return JSON.parse(Cn(e))}function P(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}import{appendFileSync as Nn,chmodSync as Pn,mkdirSync as In,existsSync as Hn,readFileSync as Qi,rmSync as es}from"node:fs";import{dirname as Ln,join as jn}from"node:path";import{readFileSync as En,renameSync as vn,statSync as On,writeFileSync as Rn}from"node:fs";function rt(e,t,n){try{if(On(e).size<=t)return;let r=En(e,"utf8").split(`
5
- `).filter(u=>u.trim()!==""),o=[],i=0;for(let u=r.length-1;u>=0;u-=1){let l=r[u],a=Buffer.byteLength(l)+1;if(i+a>n)break;o.push(l),i+=a}o.reverse();let s=`${e}.tmp-${process.pid}`;Rn(s,o.length?`${o.join(`
3
+ function V(e=5e3){return new Promise(t=>{let n=[],r=process.stdin,o=!1,i=()=>{o||(o=!0,clearTimeout(u),r.off("data",s),r.pause(),r.unref?.(),t(Buffer.concat(n).toString("utf8")))},s=l=>{n.push(Buffer.isBuffer(l)?l:Buffer.from(l))},u=setTimeout(i,e);r.on("data",s).once("end",i).once("error",i),r.resume()})}import{basename as Xt}from"node:path";var Qt={exec:"tkr-exec",processor:"tkr-processor",daemon:"tkr-daemon","shim-run":"tkr-shim"},en={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 se(e){let t=Xt(e).replace(/\.(m?js|ts)$/,"");if(t==="tkr")return[];for(let[n,r]of Object.entries(Qt))if(r===t)return[n];for(let[n,r]of Object.entries(en))if(r===t)return["hook",n];return null}import{realpathSync as Ze}from"node:fs";import{delimiter as tn,join as D}from"node:path";import nn from"node:os";function K(){return!1}function Ve(e,t){try{return Ze(e)===Ze(t)}catch{return!1}}function ye(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"?";":tn)){if(!o||o.includes("node_modules"))continue;let i=D(o,r);if(Ve(i,n))return i}if(t!=="win32"){let o=nn.homedir();for(let i of[D(o,".local","bin",r),D(o,".local","share","tokmizer","current","dist","bin",r),D("/opt/homebrew/bin",r),D("/usr/local/bin",r),D("/home/linuxbrew/.linuxbrew/bin",r)])if(Ve(i,n))return i}return n}import rn from"node:os";import{isAbsolute as on,join as Ke,resolve as qe}from"node:path";function ue(e=process.env,t=rn.homedir()){let n=e.CLAUDE_CONFIG_DIR?.trim();if(!n)return Ke(t,".claude");let r=n;return r==="~"?r=t:(r.startsWith("~/")||r.startsWith("~\\"))&&(r=Ke(t,r.slice(2))),on(r)?qe(r):qe(r)}import{accessSync as fn,chmodSync as dn,constants as pn,existsSync as le,mkdirSync as mn,readdirSync as gn,readFileSync as hn,realpathSync as tt,renameSync as kn,unlinkSync as _n,writeFileSync as bn}from"node:fs";import{basename as $e,dirname as O,join as T,sep as F}from"node:path";import sn from"node:os";import{join as un}from"node:path";function S(){return process.env.TOKMIZER_HOME||un(sn.homedir(),".tokmizer")}import{rmSync as ln,statSync as an}from"node:fs";import{join as Ye}from"node:path";function Xe(){return Ye(S(),"shims")}function Se(){return Ye(S(),"fail-open")}var cn=24*36e5;function C(e=Date.now()){try{if(e-an(Se()).mtimeMs<cn)return!0;ln(Se(),{force:!0})}catch{}return!1}function Qe(){return`[ -f ${N(Se())} ]`}function N(e){return`'${e.replace(/'/g,"'\\''")}'`}function et(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 rt=1,q="tkr-shim.stable",ot=/^(?: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 yn(){return T(S(),"bin","tkr-run")}function nt(){return T(ue(),"plugins","cache","tokmizer","tokmizer")}function Sn(e){let t=O(O(O(e)));return ot.test($e(t))&&$e(O(t))==="tokmizer"?O(t):null}function Ae(e){return/[\n\r]/.test(e)||e.includes(`${F}_npx${F}`)||e.includes(`${F}.bun${F}install${F}cache${F}`)}function Ce(e){let t=e.match(/^(.*)[\\/]Cellar[\\/]([^\\/]+)[\\/][^\\/]+[\\/](.*)$/);if(!t)return e;let n=T(t[1],"opt",t[2],t[3]);try{return tt(n)===tt(e)?n:e}catch{return e}}function xn(e=process.execPath){return Ae(e)?"":Ce(e)}function $n(e,t=K()){if(t&&se(e)){let o=ye();return{single:Ae(o)?"":Ce(o),js:"",cache:nt(),node:""}}let n=xn(),r=Sn(e);return r?{single:"",js:"",cache:r,node:n}:{single:"",js:Ae(e)?"":Ce(e),cache:nt(),node:n}}function An(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(!ot.test(o))continue;let i=T(e,o);if(!le(T(i,"dist","bin","tkr-shim.js"))||!le(T(i,"dist","bin",q)))continue;let[s,u,l]=o.split(".").map(Number),a=s*1e6+u*1e3+l;a>n&&(n=a,t=i)}return t}function xe(e){return e.single&&An(e.single)||e.js&&le(e.js)&&($e(e.js)!=="tkr-shim.js"||le(T(O(e.js),q)))?!0:e.cache!==""&&Cn(e.cache)!==null}function Tn(e,t){return["_tk_t=",`if [ -n "$_tk_j" ] && [ -f "${t}" ] && { [ "\${_tk_j##*/}" != tkr-shim.js ] || [ -f "\${_tk_j%/*}/${q}" ]; }; 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/${q}" ] || 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=${N(Xe())}`," 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/${q}" ] && [ -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=${rt}`,`_tk_s=${N(e.single)}`,`_tk_j=${N(e.js)}`,`_tk_k=${N(e.cache)}`,`_tk_n=${N(e.node)}`,'[ "$#" -gt 0 ] || exit 0',`if ! ${Qe()}; then`,' if [ -n "$_tk_s" ] && [ -x "$_tk_s" ]; then exec "$_tk_s" exec "$@"; fi',...Tn("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(`
4
+ `)}function it(e){let t=yn(),n=$n(T(O(e),"tkr-shim.js")),r=On(t);if(r&&r.format===rt&&xe(r.target)&&JSON.stringify(r.target)===JSON.stringify(n))return t;if(!xe(n))return r&&xe(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 vn(e){let t=u=>{let l=e.match(new RegExp(`^${u}=(.*)$`,"m"));return l?u==="_tk_f"?l[1]:et(l[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 On(e=wn()){try{return vn(hn(e,"utf8"))}catch{return null}}function Rn(e){return e.charCodeAt(0)===65279?e.slice(1):e}function Te(e){return JSON.parse(Rn(e))}function P(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}import{appendFileSync as Ln,chmodSync as jn,mkdirSync as Dn,existsSync as Fn,readFileSync as as,rmSync as cs}from"node:fs";import{dirname as Mn,join as zn}from"node:path";import{readFileSync as Nn,renameSync as Pn,statSync as In,writeFileSync as Hn}from"node:fs";function st(e,t,n){try{if(In(e).size<=t)return;let r=Nn(e,"utf8").split(`
5
+ `).filter(u=>u.trim()!==""),o=[],i=0;for(let u=r.length-1;u>=0;u-=1){let l=r[u],a=Buffer.byteLength(l)+1;if(i+a>n)break;o.push(l),i+=a}o.reverse();let s=`${e}.tmp-${process.pid}`;Hn(s,o.length?`${o.join(`
6
6
  `)}
7
- `:"",{mode:384}),vn(s,e)}catch{}}var Dn="usage.jsonl";var ot=2*1024*1024;function Fn(){return jn(S(),Dn)}function w(e,t,n=Fn()){try{let r=Ln(n);Hn(r)||In(r,{recursive:!0,mode:448});let o=e.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";Nn(n,`{"t":${Math.floor(Date.now()/1e3)},"s":"${o}","o":${t?1:0}}
8
- `,{mode:384}),Pn(n,384),rt(n,ot,ot/2)}catch{}}import{spawnSync as Ar}from"node:child_process";import{existsSync as M,readFileSync as ee,readdirSync as pe}from"node:fs";import{homedir as I}from"node:os";import{fileURLToPath as Tr}from"node:url";import{dirname as Tt,join as p,resolve as Cr}from"node:path";function Mn(e,t){let n=e.slice(0,t).split(/\r?\n/);return[n.length,n.pop().length+1]}function zn(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 u=r[s-1];u&&(o+=s.toString().padEnd(i," "),o+=": ",o+=u,o+=`
7
+ `:"",{mode:384}),Pn(s,e)}catch{}}var Un="usage.jsonl";var ut=2*1024*1024;function Jn(){return zn(S(),Un)}function w(e,t,n=Jn()){try{let r=Mn(n);Fn(r)||Dn(r,{recursive:!0,mode:448});let o=e.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";Ln(n,`{"t":${Math.floor(Date.now()/1e3)},"s":"${o}","o":${t?1:0}}
8
+ `,{mode:384}),jn(n,384),st(n,ut,ut/2)}catch{}}import{spawnSync as vr}from"node:child_process";import{existsSync as I,readFileSync as te,readdirSync as me,statSync as Or}from"node:fs";import{homedir as H}from"node:os";import{fileURLToPath as Rr}from"node:url";import{dirname as vt,join as p,resolve as Nr}from"node:path";function Wn(e,t){let n=e.slice(0,t).split(/\r?\n/);return[n.length,n.pop().length+1]}function Bn(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 u=r[s-1];u&&(o+=s.toString().padEnd(i," "),o+=": ",o+=u,o+=`
9
9
  `,s===t&&(o+=" ".repeat(i+n+2),o+=`^
10
- `))}return o}var f=class e extends Error{line;column;codeblock;constructor(t,n){let[r,o]=Mn(n.toml,n.ptr),i=zn(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]=Wn(n.toml,n.ptr),i=Bn(n.toml,r,o);super(`Invalid TOML document: ${t}
11
11
 
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 le(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="",u=e.p,l=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))l=l&&3;else if(n<32&&n!==9||n===127)f.x("control characters are not allowed in strings",e);else if((!l||l===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++),!l){let a=e.s.slice(u,e.p);s=s?s+a:a}return e.p+=i?3:1,s}else if(!l)!o&&n===92&&(s+=e.s.slice(u,u=e.p),l=1);else if(l===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 g=0;g<d;g++,e.p++){let m=e.s.charCodeAt(e.p),k=m>=48&&m<=57?m-48:m>=65&&m<=70?m-65+10:m>=97&&m<=102?m-97+10:-1;k<0&&f.x("invalid non-hex character in unicode escape",e),c=c<<4|k}(c<0||c>1114111||c>=55296&&c<=57343)&&f.x("invalid unicode escape",e,a),s+=String.fromCodePoint(c),u=e.p--,l=0}else i&&(n===32||n===9)?l=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),u=e.p+1,l=0);else n!==32&&n!==9&&(l===2&&f.x("invalid escape: only line-ending whitespace may be escaped",e,u),l=!o&&n===92?1:0,u=e.p);f.x("unfinished string",e,t)}var Un=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i,q=class e extends Date{#t=!1;#n=!1;#e=null;constructor(t,n,r){let o=!0,i=!0,s="Z",u;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"):(u=t.charCodeAt(t.length-1))!==90&&u!==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 l=t.match(Un);l?(l[1]||(o=!1,t=`0000-01-01T${t}`),i=!!l[2],i&&t[10]===" "&&(t=t.replace(" ","T")),l[2]&&+l[2]>23?t="":(s=l[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 Ee(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function X(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?ut(e):st(e);return e.d++,o}return r===34||r===39?le(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?ae(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?Jn(e,r,t):e.s.charCodeAt(e.p+2)===58?Wn(e,r,t):ae(e,e.p,r,0,t)}function ae(e,t,n,r,o){let i=n,s=0,u=!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||Ee(i=e.s.charCodeAt(e.p),o))return e.bi===!0?0n:0;if(!r){if(i===120)return Ce(e,t,16,o);if(i===98)return Ce(e,t,2,o);if(i===111)return Ce(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),!Ee(i,o));)s||(s=1),i===95?(s&1||f.x("illegal underscore",e),s+=11,u=!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 l=e.s.slice(t,e.p);return u&&(l=l.replaceAll("_","")),s>1?parseFloat(l):it(e,l,10,t)}function Ce(e,t,n,r){let o,i=1;for(;++e.p<e.s.length&&(o=e.s.charCodeAt(e.p),!Ee(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("_","")),it(e,s,n,t)}function it(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 Jn(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 ae(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 Y(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 Y(e,s,1,o,r,"[+00:00]")}if(t===43||t===45){let s=e.s.slice(r,e.p+=6);return Y(e,s,1,o,r,!e.ld&&"["+e.s.slice(e.p-6,e.p)+"]")}}let i=e.s.slice(r,e.p);return Y(e,i,2,o,r)}function Wn(e,t,n){let r=e.p;if(!b(t)||!b(e.s.charCodeAt(++e.p)))return ae(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 Y(e,o,4,!1,r)}function Y(e,t,n,r,o,i){if(e.ld){let s=new q(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 Bn(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;Bn(e)}}function ce(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(le(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 st(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,u=!1,l=e.p,a=ce(e);for(let d=0;d<a.length;d++){d&&(s=u?s[i]:s[i]=Object.create(null)),i=a[d],(u=Object.hasOwn(s,i))&&(typeof s[i]!="object"||r.has(s[i]))&&f.x("trying to redefine an already defined value",e,l);let g=i==="__proto__";if(e.uk&&(g||i==="constructor")){s=e.uk!==1&&f.x("document contains an unsafe property",e,l);break}!u&&g&&Object.defineProperty(s,i,{enumerable:!0,configurable:!0,writable:!0})}u&&f.x("trying to redefine an already defined value",e,l),x(e,!0,!0);let c=X(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 ut(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(X(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 lt(e,t,n,r,o){let i=n,s=r,u,l=!1,a;for(let c=0;c<t.length;c++){if(c){if(i=l?i[u]:i[u]=Object.create(null),s=(a=s[u]).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(u=t[c],(l=Object.hasOwn(i,u))&&s[u]?.t===0&&s[u]?.d)return null;if(!l){let d=u==="__proto__";if(e.uk&&(d||u==="constructor"))return!1;d&&(Object.defineProperty(i,u,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(s,u,{enumerable:!0,configurable:!0,writable:!0})),s[u]={t:c<t.length-1&&o===2?3:o,d:!1,i:0,c:Object.create(null)}}}if(a=s[u],a.t!==o&&!(o===1&&a.t===3)||(o===2&&(a.d||(a.d=!0,i[u]=[]),i[u].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=l?i[u]:i[u]=Object.create(null);else if(o===0&&l)return null;return[u,i,a.c]}function at(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 ve(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,u=r,l=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=ce(n,93);a&&(e.charCodeAt(n.p)!==93&&f.x("expected end of table array declaration",n),n.p++);let d=lt(n,c,r,o,a?2:1);d?(l=d[2],u=d[1]):(at(n,d,i),s=!0)}else{i=n.p;let a=ce(n),c=lt(n,a,u,l,0);!c&&!s&&at(n,c,i),x(n,!0,!0);let d=X(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 Ts=!!"".isWellFormed;import{execFileSync as dr}from"node:child_process";import{mkdirSync as pr,readFileSync as mt,renameSync as mr,statSync as gr,writeFileSync as hr}from"node:fs";import{join as gt}from"node:path";import{closeSync as Gn,openSync as Zn,readSync as Vn,readdirSync as Kn,readFileSync as qn,statSync as ft}from"node:fs";import{homedir as Yn}from"node:os";import{isAbsolute as Xn,join as fe,resolve as Qn}from"node:path";var er=/^[A-Za-z0-9._+@%:,/-]+$/,tr=new Set(["7f454c46","feedface","feedfacf","cefaedfe","cffaedfe","cafebabe","bebafeca"]),nr=32,rr=4*1024*1024;function Re(e){let t;try{t=Zn(e,"r");let n=Buffer.alloc(4),r=Vn(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&&Gn(t)}}function Q(e,t=process.platform){try{let n=ft(e);if(!n.isFile())return!1;if(t==="win32")return!0;if((n.mode&73)===0)return!1;let r=Re(e);return r==="#!"||r!==null&&tr.has(r)}catch{return!1}}function or(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(!er.test(e))return!1;let o=r==="win32";if(e.includes("/"))return Q(Qn(t??process.cwd(),e),r);if(!n)return!1;let i=o?or(e):[e];for(let s of n.split(o?";":":"))if(!(!s||!Xn(s))){for(let u of i)if(Q(fe(s,u),r))return!0}return!1}var ir=/^eval \$'([^\s'()=]+) \(\) /,sr=/^([^\s'"()=]+) \(\) \{$/,ur=/^alias -- ([^\s=]+)=(.*)$/,lr=/^# (?:Shell Options|Aliases|Shopt|Check for |Shadow )/,ar=/^export PATH=(.*)$/,cr=/^(?:--colou?r(?:=\S+)?|-G)$/;function ct(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 fr(e,t){let n="";for(let r of e.split(`
14
- `)){let o=ar.exec(r);if(o&&n!=="# Functions"){let i=ct(o[1].trim());/[$`\\]/.test(i)||t.paths.push(i);continue}if(r.startsWith("# ")&&(n!=="# Functions"||lr.test(r))){n=r;continue}if(n==="# Functions"){let i=ir.exec(r)??sr.exec(r);i&&t.functions.add(i[1])}else if(n==="# Aliases"){let i=ur.exec(r);i&&t.aliases.set(i[1],ct(i[2].trim()))}}}function Oe(e){return e?.code==="ENOENT"}function dt(e){let t={functions:new Set,aliases:new Map,paths:[],uncertain:!1},n=fe(e||fe(Yn(),".claude"),"shell-snapshots"),r=[];try{for(let o of Kn(n)){if(!o.startsWith("snapshot-")||!o.endsWith(".sh"))continue;let i=fe(n,o);try{let s=ft(i);s.isFile()&&r.push({path:i,mtime:s.mtimeMs,size:s.size})}catch(s){Oe(s)||(t.uncertain=!0)}}}catch(o){return Oe(o)||(t.uncertain=!0),t}r=r.sort((o,i)=>i.mtime-o.mtime).slice(0,nr);for(let o of r)try{if(o.size>rr)throw new Error("snapshot too large");fr(qn(o.path,"utf8"),t)}catch(i){Oe(i)||(t.uncertain=!0)}return t}function pt(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=>cr.test(o))}var kr="exec-probe.json",_r=6e4;function br(){return gt(S(),kr)}function wr(e){try{let t=Te(mt(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 yr(e,t){try{pr(gt(e,".."),{recursive:!0,mode:448});let n=`${e}.${process.pid}.tmp`;hr(n,JSON.stringify(t),{mode:384}),mr(n,e)}catch{}}function Sr(e){try{return dr(e,["--native-check"],{encoding:"utf8",timeout:2e3,maxBuffer:1024,stdio:["ignore","pipe","ignore"],windowsHide:!0}).startsWith("tokmizer-native ")}catch{return!1}}function xr(e,t){try{let r=mt(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):Q(o)}catch{return!1}}function $r(e,t,n){try{let r=gr(e);return[e,r.size,r.mtimeMs,r.ino,r.mode,t?n??"":""].join("|")}catch{return`${e}|missing`}}function Ne(e,t=process.platform,n=process.env.PATH,r=br(),o=Date.now()){let i=t!=="win32"&&Re(e)==="#!",s=$r(e,i,n),u=wr(r);if(u?.key===s&&(u.ok||o-u.at<_r))return u.ok;let l=Q(e,t)&&(i?xr(e,n):Sr(e));return yr(r,{key:s,ok:l,at:o,skipped:(u?.skipped??0)+(l?0:1)}),l}var Er=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"]),vr=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"]),ht=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),kt="(?:dev|start|serve|watch|preview)",Or=new RegExp(`^(?:\\S*/)?(?:bun\\s+(?:install|i|add|remove|rm|update|outdated|audit|test|build|pm|x)(?:\\s|$)|bun\\s+run\\s+(?!${kt}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|deno\\s+(?:test|lint|fmt|check|compile|install|info|doc|bench|outdated)(?:\\s|$)|deno\\s+task\\s+(?!${kt}(?:\\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)`),Rr=/(?:^|\s)--watch(?:\s|=|$)/;function Nr(e){return Or.test(e)&&!Rr.test(e)}var Pr=/^((?:\S*\/)?(sh|bash|zsh|dash|ksh|fish)\s+(-[elux]*c[elux]*)\s+)(['"])/,Ir=/[()$]|(?:^|[;&|\n]\s*)(?:and|or|not|begin|end|if|else|switch|case|while|for|function|return)(?:\s|;|$)/,Ct=3;function Et(e){let t=Pr.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 u=e.slice(o,i);return r==='"'&&/[$`\\!]/.test(u)||n&&Ir.test(u)?null:{script:u,start:o,end:i,quote:r}}var Hr=new Set(["cd","export","set","unset","source",".","true",":","pushd","popd"]);function Lr(e){return Le(e).filter(n=>{if(n.kind!=="cmd"||n.unsafe)return!1;let r=Ot(n.text);return r!==""&&!Hr.has(r)&&!He.test(r)}).length>1}function jr(e,t,n,r,o){if(n>=Ct)return null;let i=Et(e);if(!i)return null;let{script:s,start:u,end:l,quote:a}=i,c=[],d=Rt(s,t,n+1,r,A=>c.push(A));if(d===s||a==='"'&&/["$`]/.test(d))return null;let g=a==="'"?d.replace(/'/g,"'\\''"):d,m=`${e.slice(0,u)}${g}${e.slice(l)}`,k=Lr(s);if(o)for(let A of k?[e,...c]:c)o(A);return k?`${t} ${m}`:m}var _t=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,Dr=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*[fF][a-zA-Z]*)(?:\s|=|$)/,Fr=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]),bt=new Set(["npm","pnpm","yarn","bun"]),wt=/^(?:dev|start|serve|preview|watch)(?::\S*)?$/,Mr=new Set(["--filter","-F","--dir","-C","--prefix","--workspace","-w","--cwd"]),yt=new Set(["npx","pnpx","bunx"]),zr=new Set(["nodemon","top","htop","btop","watch"]),Ur=new Set(["tsc","vitest","jest","webpack","rollup","esbuild","tsup","babel","sass","tailwindcss","mocha","swc","parcel","nest"]),Jr=/(?:^|\s)--watch(?:All)?(?:\s|=(?!false(?:\s|$))|$)/,St=/(?:^|\s)-w(?:\s|$)/;function Wr(e){let t=e.map(s=>s.replace(/['"]/g,""));for(;t.length>1&&(t[0]==="env"||/^[A-Za-z_][A-Za-z0-9_]*=/.test(t[0]));)t=t.slice(1);let n=z(t[0]??"");if(yt.has(n)||bt.has(n)&&(t[1]==="exec"||t[1]==="dlx"))t=t.slice(yt.has(n)?1:2).filter((s,u,l)=>!(s.startsWith("-")&&l.slice(0,u).every(a=>a.startsWith("-")))),n=z(t[0]??"");else if(bt.has(n)){let s=t.slice(1).filter((l,a,c)=>!l.startsWith("-")&&!Mr.has(c[a-1]??""));s[0]==="workspace"&&s.splice(0,2);let u=s[0]==="run"||s[0]==="run-script"?s[1]:s[0];return u!==void 0&&wt.test(u)}let r=t.slice(1),o=r.join(" "),i=r.find(s=>!s.startsWith("-"));if(zr.has(n)||Jr.test(o)||Ur.has(n)&&St.test(o))return!0;switch(n){case"next":return i==="dev"||i==="start";case"vite":return!r.includes("build")&&!r.includes("optimize");case"vitest":return i==="watch"||i==="dev";case"cargo":case"dotnet":return i==="watch";case"turbo":{let s=i==="run"?r.filter(u=>!u.startsWith("-"))[1]:i;return s!==void 0&&wt.test(s)}case"nx":{let s=i==="run"?r.filter(u=>!u.startsWith("-"))[1]?.split(":")[1]:i;return s!==void 0&&/^(?:serve|dev|start|watch)$/.test(s)}case"ping":return!r.some(s=>/^-[a-zA-Z]*c/.test(s));case"docker":case"podman":case"nerdctl":case"docker-compose":{let s=n==="docker-compose"?r:i==="compose"?r.slice(r.indexOf("compose")+1):null;return s?s.includes("up")&&!s.some(u=>u==="--detach"||/^-[a-zA-Z]*d[a-zA-Z]*$/.test(u)):i==="stats"&&!r.includes("--no-stream")||i==="events"}case"kubectl":return i==="port-forward"||(i==="get"||i==="rollout")&&St.test(o)||/(?:^|\s)--watch-only(?:\s|=|$)/.test(o);default:return!1}}function Br(e,t){let n=z(t);return n==="tail"?Dr.test(e):n==="journalctl"?_t.test(e):n==="stern"||Fr.has(n)&&/\blogs?\b/.test(e)&&_t.test(e)?!0:Wr(e.split(/\s+/))}var He=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,Gr=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,Zr=/(?:^|[;&|\n({])\s*[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/;function z(e){let t=e.lastIndexOf("/");return t===-1?e:e.slice(t+1)}function vt(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 Pe(e){let t=vt(e);if(!t)return!0;for(let n=0;n<e.length;n++)if(t[n]&&e[n]===">")return!0;return!1}function Le(e){let t=vt(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=(u,l)=>{i(),n.push({kind:"sep",text:u}),o+=l};for(;o<e.length;){let u=e[o],l=e[o+1];if(t[o]){if(u===">"&&l==="|"){r+=">|",o+=2;continue}if(u==="&"&&l==="&"){s("&&",2);continue}if(u==="&"&&l!==">"){let a=r.replace(/\s+$/,""),c=a[a.length-1];if(c!==">"&&c!=="<"&&c!=="&"){s("&",1);continue}}if(u==="|"&&l==="|"){s("||",2);continue}if(u==="|"&&l==="&"){s("|&",2);continue}if(u===";"&&l===";"){let a=e[o+2]==="&";s(a?";;&":";;",a?3:2);continue}if(u===";"||u===`
16
- `||u==="|"){s(u,1);continue}}r+=u,o+=1}return i(),n}function Ot(e){return e.trim().split(/\s+/)[0]??""}function $(e,t=process.platform){try{let n=Tt(Tr(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(M(l))return Ne(l,t)?`'${l.replace(/\\/g,"/").replace(/'/g,"'\\''")}'`:null}let i=p(n,"..","bin","tkr-exec"),s=!r&&M(i);if(s&&!Ne(i,t))return null;if(!r&&process.env.TOKMIZER_STABLE_RUN!=="0"){let l=nt(p(n,"..","bin","tkr-exec.js"));if(l&&(s||M(p(n,"..","bin","tkr-exec.js"))))return`${o}'${l.replace(/'/g,"'\\''")}'`}if(s)return`${o}'${i.replace(/'/g,"'\\''")}'`;if(V()){let l=r?process.execPath.replace(/\\/g,"/"):process.execPath;return`${o}'${l.replace(/'/g,"'\\''")}' exec`}let u=p(n,"..","bin","tkr-exec.js");return M(u)?`${o}node '${u.replace(/'/g,"'\\''")}'`:null}catch{return null}}function Vr(e,t="tkr-exec",n=()=>!0,r){return Rt(e,t,0,n,r)}var Kr=new Set(["{","for","while","until","if","case","select"]),qr=new Set(["}","done","fi","esac"]),Yr=new Set(["then","do","else","elif","!","time","{","if","while","until"]);function Xr(e,t){let n=e[t+1];return Pe(e[t].text)||n?.kind==="sep"&&(n.text==="|"||n.text==="|&")}function Qr(e){let t=new Set,n=[];for(let r=0;r<e.length;r++){let o=e[r];if(!(o.kind!=="cmd"||o.unsafe))for(let i of o.text.trim().split(/\s+/)){if(qr.has(i)){let s=n.pop();if(s!==void 0&&Xr(e,r))for(let u=s;u<=r;u++)t.add(u);continue}if(Kr.has(i)&&n.push(r),!Yr.has(i))break}}return t}function Rt(e,t,n,r,o){if(e.includes("<<")||Zr.test(e))return e;let i=Le(e),s=Qr(i),u=[];for(let l=0;l<i.length;l++){let a=i[l];if(a.kind==="sep"||a.unsafe||s.has(l)){u.push(a.text);continue}let c=a.text.trim();if(!c){u.push(a.text);continue}let d=Ot(c),g=i[l+1],m=g?.kind==="sep"&&(g.text==="|"||g.text==="|&"),k=g?.kind==="sep"&&g.text==="&",A=!m&&!k&&!Pe(a.text)&&!a.text.includes("<(")&&!a.text.includes(">(")?jr(c,t,n,r,o):null;if(A!==null){u.push(`${a.text.match(/^\s*/)?.[0]??""}${A}${a.text.match(/\s*$/)?.[0]??""}`);continue}if(c===t||c.startsWith(t)&&/^\s/.test(c.slice(t.length))||Er.has(d)||vr.has(d)||(ht.has(d)||ht.has(z(d)))&&!Nr(c)||He.test(d)||d.startsWith("(")||d.startsWith("#")||d.startsWith("<")||d.startsWith(">")||Gr.test(c)||Br(c,d)||d.endsWith(")")||m||k||Pe(a.text)||a.text.includes("<(")||a.text.includes(">(")||d==="node"&&c.includes("tkr-exec.js")||!r(d)){u.push(a.text);continue}let y=a.text.match(/^\s*/)?.[0]??"",G=a.text.match(/\s*$/)?.[0]??"";o?.(c),u.push(`${y}${t} ${c}${G}`)}return u.join("")}var eo=new Set(["command","workdir","timeout_ms","yield_time_ms","max_output_tokens","shell","login","tty","description"]),to=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"]),no=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),ro={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/},de=["test","run test","run build","run lint","run typecheck"],oo={npm:new Set(de),pnpm:new Set([...de,"build","lint","typecheck"]),yarn:new Set([...de,"build","lint","typecheck"]),bun:new Set(de),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"])},io=new Set(["pytest","tsc","vitest","jest","eslint","mypy"]);function Nt(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 Le(e)){if(r.kind==="sep")continue;if(r.unsafe)return!1;let o=n<Ct?Et(r.text.trim()):null;if(o){if(!Nt(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=>He.test(a)))return!1;let s=z(i[0]);if(s!==i[0])return!1;let u=ro[s];if(u&&i.slice(1).some(a=>u.test(a)))return!1;if((s==="git"?no.has(i[1]??""):to.has(s))||t&&io.has(s))continue;let l=t?oo[s]:void 0;if(!(l&&(l.has(i[1]??"")||i[1]==="run"&&l.has(`run ${i[2]??""}`))))return!1}return!0}function Pt(e,t,n=$(t),r=w,o=me(),i=process.env.PATH,s=je){if(!h(e)||e.tool_name!=="Bash"||t==="claude-code"&&uo(s()))return null;let u=e.tool_input;if(!h(u)||u.run_in_background)return null;let l=u.command;if(typeof l!="string"||!l||t==="codex"&&Object.keys(u).some(A=>!eo.has(A)))return null;let a=typeof e.cwd=="string"&&e.cwd?e.cwd:u.workdir,c=typeof a=="string"&&a?a:void 0,d=typeof e.session_id=="string"&&e.session_id?e.session_id:"unknown",g=typeof e.permission_mode=="string"?e.permission_mode:void 0,m=zt(l,{host:t,sessionId:d,cwd:c,claudeDirs:o,pathEnv:i,permissionMode:g},n,r);if(!m)return null;let k={...u,command:m.command};return JSON.stringify({hookSpecificOutput:t==="codex"?{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:k}:m.allowedBy?{hookEventName:"PreToolUse",permissionDecision:"allow",permissionDecisionReason:`Tokmizer: allowed by your rule ${m.allowedBy}`,updatedInput:k}:m.ask?{hookEventName:"PreToolUse",permissionDecision:"ask",permissionDecisionReason:"Tokmizer shortens this command's output; nothing else changes.",updatedInput:k}:{hookEventName:"PreToolUse",updatedInput:k}})}var so=/(?:^|\s)--(?:disallowedTools|disallowed-tools|settings|setting-sources)(?:[=\s]|$)/;function je(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=Ar("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 uo(e){return e===null||so.test(e)}function lo(e,t){if(!M(e))return"missing";try{let n=ee(e,"utf8").replace(/^\uFEFF/,"");return n.trim()===""?{}:JSON.parse(t?It(n):n)}catch{return"unreadable"}}function It(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 ae(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="",u=e.p,l=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))l=l&&3;else if(n<32&&n!==9||n===127)f.x("control characters are not allowed in strings",e);else if((!l||l===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++),!l){let a=e.s.slice(u,e.p);s=s?s+a:a}return e.p+=i?3:1,s}else if(!l)!o&&n===92&&(s+=e.s.slice(u,u=e.p),l=1);else if(l===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 g=0;g<d;g++,e.p++){let m=e.s.charCodeAt(e.p),k=m>=48&&m<=57?m-48:m>=65&&m<=70?m-65+10:m>=97&&m<=102?m-97+10:-1;k<0&&f.x("invalid non-hex character in unicode escape",e),c=c<<4|k}(c<0||c>1114111||c>=55296&&c<=57343)&&f.x("invalid unicode escape",e,a),s+=String.fromCodePoint(c),u=e.p--,l=0}else i&&(n===32||n===9)?l=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),u=e.p+1,l=0);else n!==32&&n!==9&&(l===2&&f.x("invalid escape: only line-ending whitespace may be escaped",e,u),l=!o&&n===92?1:0,u=e.p);f.x("unfinished string",e,t)}var Gn=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i,Y=class e extends Date{#t=!1;#n=!1;#e=null;constructor(t,n,r){let o=!0,i=!0,s="Z",u;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"):(u=t.charCodeAt(t.length-1))!==90&&u!==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 l=t.match(Gn);l?(l[1]||(o=!1,t=`0000-01-01T${t}`),i=!!l[2],i&&t[10]===" "&&(t=t.replace(" ","T")),l[2]&&+l[2]>23?t="":(s=l[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 ve(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function Q(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?ct(e):at(e);return e.d++,o}return r===34||r===39?ae(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?ce(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?Zn(e,r,t):e.s.charCodeAt(e.p+2)===58?Vn(e,r,t):ce(e,e.p,r,0,t)}function ce(e,t,n,r,o){let i=n,s=0,u=!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||ve(i=e.s.charCodeAt(e.p),o))return e.bi===!0?0n:0;if(!r){if(i===120)return Ee(e,t,16,o);if(i===98)return Ee(e,t,2,o);if(i===111)return Ee(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),!ve(i,o));)s||(s=1),i===95?(s&1||f.x("illegal underscore",e),s+=11,u=!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 l=e.s.slice(t,e.p);return u&&(l=l.replaceAll("_","")),s>1?parseFloat(l):lt(e,l,10,t)}function Ee(e,t,n,r){let o,i=1;for(;++e.p<e.s.length&&(o=e.s.charCodeAt(e.p),!ve(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("_","")),lt(e,s,n,t)}function lt(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 Zn(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 ce(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 X(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 X(e,s,1,o,r,"[+00:00]")}if(t===43||t===45){let s=e.s.slice(r,e.p+=6);return X(e,s,1,o,r,!e.ld&&"["+e.s.slice(e.p-6,e.p)+"]")}}let i=e.s.slice(r,e.p);return X(e,i,2,o,r)}function Vn(e,t,n){let r=e.p;if(!b(t)||!b(e.s.charCodeAt(++e.p)))return ce(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 X(e,o,4,!1,r)}function X(e,t,n,r,o,i){if(e.ld){let s=new Y(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 Kn(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;Kn(e)}}function fe(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(ae(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 at(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,u=!1,l=e.p,a=fe(e);for(let d=0;d<a.length;d++){d&&(s=u?s[i]:s[i]=Object.create(null)),i=a[d],(u=Object.hasOwn(s,i))&&(typeof s[i]!="object"||r.has(s[i]))&&f.x("trying to redefine an already defined value",e,l);let g=i==="__proto__";if(e.uk&&(g||i==="constructor")){s=e.uk!==1&&f.x("document contains an unsafe property",e,l);break}!u&&g&&Object.defineProperty(s,i,{enumerable:!0,configurable:!0,writable:!0})}u&&f.x("trying to redefine an already defined value",e,l),x(e,!0,!0);let c=Q(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 ct(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(Q(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 ft(e,t,n,r,o){let i=n,s=r,u,l=!1,a;for(let c=0;c<t.length;c++){if(c){if(i=l?i[u]:i[u]=Object.create(null),s=(a=s[u]).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(u=t[c],(l=Object.hasOwn(i,u))&&s[u]?.t===0&&s[u]?.d)return null;if(!l){let d=u==="__proto__";if(e.uk&&(d||u==="constructor"))return!1;d&&(Object.defineProperty(i,u,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(s,u,{enumerable:!0,configurable:!0,writable:!0})),s[u]={t:c<t.length-1&&o===2?3:o,d:!1,i:0,c:Object.create(null)}}}if(a=s[u],a.t!==o&&!(o===1&&a.t===3)||(o===2&&(a.d||(a.d=!0,i[u]=[]),i[u].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=l?i[u]:i[u]=Object.create(null);else if(o===0&&l)return null;return[u,i,a.c]}function dt(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 Oe(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,u=r,l=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=fe(n,93);a&&(e.charCodeAt(n.p)!==93&&f.x("expected end of table array declaration",n),n.p++);let d=ft(n,c,r,o,a?2:1);d?(l=d[2],u=d[1]):(dt(n,d,i),s=!0)}else{i=n.p;let a=fe(n),c=ft(n,a,u,l,0);!c&&!s&&dt(n,c,i),x(n,!0,!0);let d=Q(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 Ls=!!"".isWellFormed;import{execFileSync as hr}from"node:child_process";import{mkdirSync as kr,readFileSync as kt,renameSync as _r,statSync as br,writeFileSync as wr}from"node:fs";import{join as _t}from"node:path";import{closeSync as qn,openSync as Yn,readSync as Xn,readdirSync as Qn,readFileSync as er,statSync as mt}from"node:fs";import{homedir as tr}from"node:os";import{isAbsolute as nr,join as de,resolve as rr}from"node:path";var or=/^[A-Za-z0-9._+@%:,/-]+$/,ir=new Set(["7f454c46","feedface","feedfacf","cefaedfe","cffaedfe","cafebabe","bebafeca"]),sr=32,ur=4*1024*1024;function Ne(e){let t;try{t=Yn(e,"r");let n=Buffer.alloc(4),r=Xn(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&&qn(t)}}function ee(e,t=process.platform){try{let n=mt(e);if(!n.isFile())return!1;if(t==="win32")return!0;if((n.mode&73)===0)return!1;let r=Ne(e);return r==="#!"||r!==null&&ir.has(r)}catch{return!1}}function lr(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 M(e,t,n,r=process.platform){if(!or.test(e))return!1;let o=r==="win32";if(e.includes("/"))return ee(rr(t??process.cwd(),e),r);if(!n)return!1;let i=o?lr(e):[e];for(let s of n.split(o?";":":"))if(!(!s||!nr(s))){for(let u of i)if(ee(de(s,u),r))return!0}return!1}var ar=/^eval \$'([^\s'()=]+) \(\) /,cr=/^([^\s'"()=]+) \(\) \{$/,fr=/^alias -- ([^\s=]+)=(.*)$/,dr=/^# (?:Shell Options|Aliases|Shopt|Check for |Shadow )/,pr=/^export PATH=(.*)$/,mr=/^(?:--colou?r(?:=\S+)?|-G)$/;function pt(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 gr(e,t){let n="";for(let r of e.split(`
14
+ `)){let o=pr.exec(r);if(o&&n!=="# Functions"){let i=pt(o[1].trim());/[$`\\]/.test(i)||t.paths.push(i);continue}if(r.startsWith("# ")&&(n!=="# Functions"||dr.test(r))){n=r;continue}if(n==="# Functions"){let i=ar.exec(r)??cr.exec(r);i&&t.functions.add(i[1])}else if(n==="# Aliases"){let i=fr.exec(r);i&&t.aliases.set(i[1],pt(i[2].trim()))}}}function Re(e){return e?.code==="ENOENT"}function gt(e){let t={functions:new Set,aliases:new Map,paths:[],uncertain:!1},n=de(e||de(tr(),".claude"),"shell-snapshots"),r=[];try{for(let o of Qn(n)){if(!o.startsWith("snapshot-")||!o.endsWith(".sh"))continue;let i=de(n,o);try{let s=mt(i);s.isFile()&&r.push({path:i,mtime:s.mtimeMs,size:s.size})}catch(s){Re(s)||(t.uncertain=!0)}}}catch(o){return Re(o)||(t.uncertain=!0),t}r=r.sort((o,i)=>i.mtime-o.mtime).slice(0,sr);for(let o of r)try{if(o.size>ur)throw new Error("snapshot too large");gr(er(o.path,"utf8"),t)}catch(i){Re(i)||(t.uncertain=!0)}return t}function ht(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=>mr.test(o))}var yr="exec-probe.json",Sr=6e4;function xr(){return _t(S(),yr)}function $r(e){try{let t=Te(kt(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 Ar(e,t){try{kr(_t(e,".."),{recursive:!0,mode:448});let n=`${e}.${process.pid}.tmp`;wr(n,JSON.stringify(t),{mode:384}),_r(n,e)}catch{}}function Cr(e){try{return hr(e,["--native-check"],{encoding:"utf8",timeout:2e3,maxBuffer:1024,stdio:["ignore","pipe","ignore"],windowsHide:!0}).startsWith("tokmizer-native ")}catch{return!1}}function Tr(e,t){try{let r=kt(e,"utf8").split(`
15
+ `,1)[0].slice(2).trim().split(/\s+/),o=r[0]??"";return o==="/usr/bin/env"?M(r[1]??"",void 0,t):ee(o)}catch{return!1}}function Er(e,t,n){try{let r=br(e);return[e,r.size,r.mtimeMs,r.ino,r.mode,t?n??"":""].join("|")}catch{return`${e}|missing`}}function Pe(e,t=process.platform,n=process.env.PATH,r=xr(),o=Date.now()){let i=t!=="win32"&&Ne(e)==="#!",s=Er(e,i,n),u=$r(r);if(u?.key===s&&(u.ok||o-u.at<Sr))return u.ok;let l=ee(e,t)&&(i?Tr(e,n):Cr(e));return Ar(r,{key:s,ok:l,at:o,skipped:(u?.skipped??0)+(l?0:1)}),l}var Pr=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"]),Ir=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"]),bt=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),wt="(?:dev|start|serve|watch|preview)",Hr=new RegExp(`^(?:\\S*/)?(?:bun\\s+(?:install|i|add|remove|rm|update|outdated|audit|test|build|pm|x)(?:\\s|$)|bun\\s+run\\s+(?!${wt}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|deno\\s+(?:test|lint|fmt|check|compile|install|info|doc|bench|outdated)(?:\\s|$)|deno\\s+task\\s+(?!${wt}(?:\\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)`),Lr=/(?:^|\s)--watch(?:\s|=|$)/;function jr(e){return Hr.test(e)&&!Lr.test(e)}var Dr=/^((?:\S*\/)?(sh|bash|zsh|dash|ksh|fish)\s+(-[elux]*c[elux]*)\s+)(['"])/,Fr=/[()$]|(?:^|[;&|\n]\s*)(?:and|or|not|begin|end|if|else|switch|case|while|for|function|return)(?:\s|;|$)/,Ot=3;function Rt(e){let t=Dr.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 u=e.slice(o,i);return r==='"'&&/[$`\\!]/.test(u)||n&&Fr.test(u)?null:{script:u,start:o,end:i,quote:r}}var Mr=new Set(["cd","export","set","unset","source",".","true",":","pushd","popd"]);function zr(e){return je(e).filter(n=>{if(n.kind!=="cmd"||n.unsafe)return!1;let r=Pt(n.text);return r!==""&&!Mr.has(r)&&!Le.test(r)}).length>1}function Ur(e,t,n,r,o){if(n>=Ot)return null;let i=Rt(e);if(!i)return null;let{script:s,start:u,end:l,quote:a}=i,c=[],d=It(s,t,n+1,r,A=>c.push(A));if(d===s||a==='"'&&/["$`]/.test(d))return null;let g=a==="'"?d.replace(/'/g,"'\\''"):d,m=`${e.slice(0,u)}${g}${e.slice(l)}`,k=zr(s);if(o)for(let A of k?[e,...c]:c)o(A);return k?`${t} ${m}`:m}var yt=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,Jr=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*[fF][a-zA-Z]*)(?:\s|=|$)/,Wr=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]),St=new Set(["npm","pnpm","yarn","bun"]),xt=/^(?:dev|start|serve|preview|watch)(?::\S*)?$/,Br=new Set(["--filter","-F","--dir","-C","--prefix","--workspace","-w","--cwd"]),$t=new Set(["npx","pnpx","bunx"]),Gr=new Set(["nodemon","top","htop","btop","watch"]),Zr=new Set(["tsc","vitest","jest","webpack","rollup","esbuild","tsup","babel","sass","tailwindcss","mocha","swc","parcel","nest"]),Vr=/(?:^|\s)--watch(?:All)?(?:\s|=(?!false(?:\s|$))|$)/,At=/(?:^|\s)-w(?:\s|$)/;function Kr(e){let t=e.map(s=>s.replace(/['"]/g,""));for(;t.length>1&&(t[0]==="env"||/^[A-Za-z_][A-Za-z0-9_]*=/.test(t[0]));)t=t.slice(1);let n=z(t[0]??"");if($t.has(n)||St.has(n)&&(t[1]==="exec"||t[1]==="dlx"))t=t.slice($t.has(n)?1:2).filter((s,u,l)=>!(s.startsWith("-")&&l.slice(0,u).every(a=>a.startsWith("-")))),n=z(t[0]??"");else if(St.has(n)){let s=t.slice(1).filter((l,a,c)=>!l.startsWith("-")&&!Br.has(c[a-1]??""));s[0]==="workspace"&&s.splice(0,2);let u=s[0]==="run"||s[0]==="run-script"?s[1]:s[0];return u!==void 0&&xt.test(u)}let r=t.slice(1),o=r.join(" "),i=r.find(s=>!s.startsWith("-"));if(Gr.has(n)||Vr.test(o)||Zr.has(n)&&At.test(o))return!0;switch(n){case"next":return i==="dev"||i==="start";case"vite":return!r.includes("build")&&!r.includes("optimize");case"vitest":return i==="watch"||i==="dev";case"cargo":case"dotnet":return i==="watch";case"turbo":{let s=i==="run"?r.filter(u=>!u.startsWith("-"))[1]:i;return s!==void 0&&xt.test(s)}case"nx":{let s=i==="run"?r.filter(u=>!u.startsWith("-"))[1]?.split(":")[1]:i;return s!==void 0&&/^(?:serve|dev|start|watch)$/.test(s)}case"ping":return!r.some(s=>/^-[a-zA-Z]*c/.test(s));case"docker":case"podman":case"nerdctl":case"docker-compose":{let s=n==="docker-compose"?r:i==="compose"?r.slice(r.indexOf("compose")+1):null;return s?s.includes("up")&&!s.some(u=>u==="--detach"||/^-[a-zA-Z]*d[a-zA-Z]*$/.test(u)):i==="stats"&&!r.includes("--no-stream")||i==="events"}case"kubectl":return i==="port-forward"||(i==="get"||i==="rollout")&&At.test(o)||/(?:^|\s)--watch-only(?:\s|=|$)/.test(o);default:return!1}}function qr(e,t){let n=z(t);return n==="tail"?Jr.test(e):n==="journalctl"?yt.test(e):n==="stern"||Wr.has(n)&&/\blogs?\b/.test(e)&&yt.test(e)?!0:Kr(e.split(/\s+/))}var Le=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,Yr=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,Xr=/(?:^|[;&|\n({])\s*[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/;function z(e){let t=e.lastIndexOf("/");return t===-1?e:e.slice(t+1)}function Nt(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 Ie(e){let t=Nt(e);if(!t)return!0;for(let n=0;n<e.length;n++)if(t[n]&&e[n]===">")return!0;return!1}function je(e){let t=Nt(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=(u,l)=>{i(),n.push({kind:"sep",text:u}),o+=l};for(;o<e.length;){let u=e[o],l=e[o+1];if(t[o]){if(u===">"&&l==="|"){r+=">|",o+=2;continue}if(u==="&"&&l==="&"){s("&&",2);continue}if(u==="&"&&l!==">"){let a=r.replace(/\s+$/,""),c=a[a.length-1];if(c!==">"&&c!=="<"&&c!=="&"){s("&",1);continue}}if(u==="|"&&l==="|"){s("||",2);continue}if(u==="|"&&l==="&"){s("|&",2);continue}if(u===";"&&l===";"){let a=e[o+2]==="&";s(a?";;&":";;",a?3:2);continue}if(u===";"||u===`
16
+ `||u==="|"){s(u,1);continue}}r+=u,o+=1}return i(),n}function Pt(e){return e.trim().split(/\s+/)[0]??""}function $(e,t=process.platform){try{let n=vt(Rr(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(I(l))return Pe(l,t)?`'${l.replace(/\\/g,"/").replace(/'/g,"'\\''")}'`:null}let i=p(n,"..","bin","tkr-exec"),s=!r&&I(i);if(s&&!Pe(i,t))return null;if(!r&&process.env.TOKMIZER_STABLE_RUN!=="0"){let l=it(p(n,"..","bin","tkr-exec.js"));if(l&&(s||I(p(n,"..","bin","tkr-exec.js"))))return`${o}'${l.replace(/'/g,"'\\''")}'`}if(s)return`${o}'${i.replace(/'/g,"'\\''")}'`;if(K()){let l=r?process.execPath.replace(/\\/g,"/"):process.execPath;return`${o}'${l.replace(/'/g,"'\\''")}' exec`}let u=p(n,"..","bin","tkr-exec.js");return I(u)?`${o}node '${u.replace(/'/g,"'\\''")}'`:null}catch{return null}}function Qr(e,t="tkr-exec",n=()=>!0,r){return It(e,t,0,n,r)}var eo=new Set(["{","for","while","until","if","case","select"]),to=new Set(["}","done","fi","esac"]),no=new Set(["then","do","else","elif","!","time","{","if","while","until"]);function ro(e,t){let n=e[t+1];return Ie(e[t].text)||n?.kind==="sep"&&(n.text==="|"||n.text==="|&")}function oo(e){let t=new Set,n=[];for(let r=0;r<e.length;r++){let o=e[r];if(!(o.kind!=="cmd"||o.unsafe))for(let i of o.text.trim().split(/\s+/)){if(to.has(i)){let s=n.pop();if(s!==void 0&&ro(e,r))for(let u=s;u<=r;u++)t.add(u);continue}if(eo.has(i)&&n.push(r),!no.has(i))break}}return t}function It(e,t,n,r,o){if(e.includes("<<")||Xr.test(e))return e;let i=je(e),s=oo(i),u=[];for(let l=0;l<i.length;l++){let a=i[l];if(a.kind==="sep"||a.unsafe||s.has(l)){u.push(a.text);continue}let c=a.text.trim();if(!c){u.push(a.text);continue}let d=Pt(c),g=i[l+1],m=g?.kind==="sep"&&(g.text==="|"||g.text==="|&"),k=g?.kind==="sep"&&g.text==="&",A=!m&&!k&&!Ie(a.text)&&!a.text.includes("<(")&&!a.text.includes(">(")?Ur(c,t,n,r,o):null;if(A!==null){u.push(`${a.text.match(/^\s*/)?.[0]??""}${A}${a.text.match(/\s*$/)?.[0]??""}`);continue}if(c===t||c.startsWith(t)&&/^\s/.test(c.slice(t.length))||Pr.has(d)||Ir.has(d)||(bt.has(d)||bt.has(z(d)))&&!jr(c)||Le.test(d)||d.startsWith("(")||d.startsWith("#")||d.startsWith("<")||d.startsWith(">")||Yr.test(c)||qr(c,d)||d.endsWith(")")||m||k||Ie(a.text)||a.text.includes("<(")||a.text.includes(">(")||d==="node"&&c.includes("tkr-exec.js")||!r(d,c)){u.push(a.text);continue}let y=a.text.match(/^\s*/)?.[0]??"",Z=a.text.match(/\s*$/)?.[0]??"";o?.(c),u.push(`${y}${t} ${c}${Z}`)}return u.join("")}var io=new Set(["command","workdir","timeout_ms","yield_time_ms","max_output_tokens","shell","login","tty","description"]),so=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"]),uo=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),lo={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/},pe=["test","run test","run build","run lint","run typecheck"],ao={npm:new Set(pe),pnpm:new Set([...pe,"build","lint","typecheck"]),yarn:new Set([...pe,"build","lint","typecheck"]),bun:new Set(pe),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"])},co=new Set(["pytest","tsc","vitest","jest","eslint","mypy"]);function Ht(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 je(e)){if(r.kind==="sep")continue;if(r.unsafe)return!1;let o=n<Ot?Rt(r.text.trim()):null;if(o){if(!Ht(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=>Le.test(a)))return!1;let s=z(i[0]);if(s!==i[0])return!1;let u=lo[s];if(u&&i.slice(1).some(a=>u.test(a)))return!1;if((s==="git"?uo.has(i[1]??""):so.has(s))||t&&co.has(s))continue;let l=t?ao[s]:void 0;if(!(l&&(l.has(i[1]??"")||i[1]==="run"&&l.has(`run ${i[2]??""}`))))return!1}return!0}function Lt(e,t,n=$(t),r=w,o=ge(),i=process.env.PATH,s=De){if(!h(e)||e.tool_name!=="Bash"||t==="claude-code"&&po(s()))return null;let u=e.tool_input;if(!h(u)||u.run_in_background)return null;let l=u.command;if(typeof l!="string"||!l||t==="codex"&&Object.keys(u).some(A=>!io.has(A)))return null;let a=typeof e.cwd=="string"&&e.cwd?e.cwd:u.workdir,c=typeof a=="string"&&a?a:void 0,d=typeof e.session_id=="string"&&e.session_id?e.session_id:"unknown",g=typeof e.permission_mode=="string"?e.permission_mode:void 0,m=Wt(l,{host:t,sessionId:d,cwd:c,claudeDirs:o,pathEnv:i,permissionMode:g},n,r);if(!m)return null;let k={...u,command:m.command};return JSON.stringify({hookSpecificOutput:t==="codex"?{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:k}:m.allowedBy?{hookEventName:"PreToolUse",permissionDecision:"allow",permissionDecisionReason:`Tokmizer: allowed by your rule ${m.allowedBy}`,updatedInput:k}:m.ask?{hookEventName:"PreToolUse",permissionDecision:"ask",permissionDecisionReason:"Tokmizer shortens this command's output; nothing else changes.",updatedInput:k}:{hookEventName:"PreToolUse",updatedInput:k}})}var fo=/(?:^|\s)--(?:disallowedTools|disallowed-tools|settings|setting-sources)(?:[=\s]|$)/;function De(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=vr("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 po(e){return e===null||fo.test(e)}function mo(e,t){if(!I(e))return"missing";try{let n=te(e,"utf8").replace(/^\uFEFF/,"");return n.trim()===""?{}:JSON.parse(t?jt(n):n)}catch{return"unreadable"}}function jt(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]!==`
17
17
  `;)r++;t+=`
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 ne(e){let t=[],n=Cr(e);for(;;){t.push(n);let r=Tt(n);if(r===n)return t;n=r}}function ao(){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 pe(p(e,"managed-settings.d")))n.endsWith(".json")&&t.push(p(e,"managed-settings.d",n))}catch{return t}return t}function re(e,t,n,r){let o=[];for(let i of e){let s=lo(i,t);if(s!=="missing"&&(s==="unreadable"||!h(s)||!n(s,o)))return"unreadable"}return{matchers:o,complete:r}}function te(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 co(e,t){let n=y=>[p(y,"settings.json"),p(y,"settings.local.json")],r=y=>n(p(y,".claude")),o=p(I(),".claude"),i=t.configDir||o,s=[[ao(),"managed"],[[p(i,"settings.json")],"loaded"],[[p(i,"settings.local.json")],"loadedLocal"],[t.configDir?n(o):[],"extra"],[t.projectDir?r(t.projectDir):[],"project"],[ne(e).flatMap(r),"extra"]],u=[],l={managed:[],loaded:[],loadedLocal:[],project:[],extra:[]},a={managed:!1,loaded:!1,loadedLocal:!1,project:!1,extra:!1},c=!1,d="managed",g=(y,G)=>{let v=y.permissions;if(d==="managed"&&(y.allowManagedPermissionRulesOnly===!0||h(v)&&v.allowManagedPermissionRulesOnly===!0)&&(c=!0),v===void 0)return!0;if(!h(v))return!1;for(let Ue of["deny","ask","allow"]){let Je=te(v[Ue]);if(!Je)return!1;for(let We of Je){let L=/^\s*Bash\s*(?:\(([\s\S]*)\))?\s*$/.exec(We);if(L)if(Ue!=="allow")G.push(H((L[1]??"*").replace(/:\*$/," *")));else if(L[1]===void 0||L[1].trim()==="*")a[d]=!0;else{u.push(H(L[1].replace(/:\*$/," *")));let Be=Ro(L[1]);Be&&l[d].push({rule:We.trim(),matches:Be})}}}return!0},m=[];for(let[y,G]of s){d=G;let v=re(y,!1,g,!0);if(v==="unreadable")return"unreadable";m.push(...v.matchers)}let k=a.managed||(a.loaded||a.loadedLocal)&&!c,A=[...l.managed,...c?[]:l.loaded];return{matchers:[...m,...k?[]:u],complete:!0,allow:u,allowsEverything:k,guards:m,trustedAllow:A}}function fo(e){let t=[p(I(),".cursor","cli-config.json"),...ne(e).map(n=>p(n,".cursor","cli.json"))];return re(t,!0,(n,r)=>{let o=n.permissions;if(o===void 0)return!0;if(!h(o))return!1;let i=te(o.deny);if(!i)return!1;for(let s of i){let u=/^\s*Shell\s*(?:\(([\s\S]*)\))?\s*$/.exec(s);if(!u)continue;let l=u[1]??"*",a=l.indexOf(":");r.push(H(a===-1?`${l} *`:`${l.slice(0,a)} ${l.slice(a+1)}`))}return!0},!1)}function po(){return process.platform==="darwin"?"/Library/Application Support/GeminiCli":process.platform==="win32"?"C:\\ProgramData\\gemini-cli":"/etc/gemini-cli"}var Ht=/^\s*(?:run_shell_command|ShellTool)\s*(?:\(([\s\S]*)\))?\s*$/;function mo(e,t){let n=e.tools;if(n!==void 0&&!h(n))return!1;let r=[te(e.excludeTools),te(h(n)?n.exclude:void 0)];for(let o of r){if(!o)return!1;for(let i of o){let s=Ht.exec(i);s&&t.push(H(s[1]===void 0?"*":`${s[1]}*`))}}return!0}function xt(e){try{return JSON.parse(e)}catch{return null}}function go(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]??xt(`"${r[1]}"`);if(o===null)return null;n.push(o)}return n}if(t.startsWith('"')){let n=/^"((?:\\.|[^"\\])*)"/.exec(t);return n?xt(`"${n[1]}"`):null}if(t.startsWith("'")){let n=/^'([^']*)'/.exec(t);return n?n[1]:null}return t.replace(/\s*#.*$/,"")}function ho(e,t){for(let n of e.split(/^\s*\[\[\s*rule\s*\]\]\s*$/m).slice(1)){let r={};for(let l of n.split(/\r?\n/)){if(/^\s*\[/.test(l))break;let a=/^\s*([A-Za-z_]+)\s*=\s*(.*)$/.exec(l);if(!a)continue;let c=go(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(l=>l==="*"||Ht.test(l)))continue;let s=r.commandPrefix===void 0?[]:[r.commandPrefix].flat(),u=[r.commandRegex,r.argsPattern].flat().filter(l=>typeof l=="string");if(s.length===0&&u.length===0){t.push(()=>!0);continue}for(let l of s)t.push(H(`${l}*`));for(let l of u){let a;try{a=new RegExp(l)}catch{return!1}t.push(c=>a.test(JSON.stringify({command:c}))||ge(a,c))}}return!0}function $t(e){try{return pe(e).filter(t=>t.endsWith(".toml")).map(t=>p(e,t))}catch{return[]}}function ko(e){let t=po(),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"),...ne(e).map(o=>p(o,".gemini","settings.json"))].filter(o=>!!o),r=re(n,!0,mo,!1);if(r==="unreadable")return r;for(let o of[...$t(p(I(),".gemini","policies")),...$t(p(t,"policies"))]){let i;try{i=ee(o,"utf8")}catch{return"unreadable"}if(!ho(i,r.matchers))return"unreadable"}return r}function Ie(e,t){if(e===void 0)return!0;if(typeof e=="string")return e!=="allow"&&t.push(()=>!0),!0;if(!h(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(!h(r))return!1;for(let[o,i]of Object.entries(r))i!=="allow"&&t.push(H(o.replace(/\?/g,"*")))}}return!0}function At(e,t){if(e.permissions!==void 0||!Ie(e.permission,t))return!1;for(let n of["agent","agents","mode"]){let r=e[n];if(r!==void 0){if(!h(r))return!1;for(let o of Object.values(r))if(h(o)&&(o.permissions!==void 0||!Ie(o.permission,t)))return!1}}return!0}function _o(e){for(let t of e)for(let n of["agent","agents","mode","modes"]){let r;try{r=pe(p(t,n))}catch{continue}for(let o of r)try{if(o.endsWith(".md")&&/permission/i.test(ee(p(t,n,o),"utf8")))return!0}catch{return!0}}return!1}function bo(e){let t=p(process.env.XDG_CONFIG_HOME||p(I(),".config"),"opencode"),n=ne(e),r=[t,...n.map(u=>p(u,".opencode"))];if(_o(r))return"unreadable";let o=["opencode.json","opencode.jsonc","config.json"],i=[...o.map(u=>p(t,u)),process.env.OPENCODE_CONFIG,...n.flatMap(u=>[...o.slice(0,2).map(l=>p(u,l)),...o.slice(0,2).map(l=>p(u,".opencode",l))])].filter(u=>!!u),s=re(i,!0,At,!0);if(s==="unreadable")return s;for(let u of[process.env.OPENCODE_CONFIG_CONTENT,process.env.OPENCODE_PERMISSION]){if(!u)continue;let l;try{l=JSON.parse(It(u))}catch{return"unreadable"}if(!(u===process.env.OPENCODE_PERMISSION?Ie(l,s.matchers):h(l)&&At(l,s.matchers)))return"unreadable"}return s}function wo(){return re([p(I(),".gemini","antigravity-cli","settings.json")],!0,(e,t)=>{let n=e.permissions;if(n===void 0)return!0;if(!h(n))return!1;for(let r of["deny","ask"]){let o=te(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 u=s[1].trim();if(!u.startsWith("regex:")){t.push(H(u==="*"?"*":`${u} *`));continue}let l;try{l=new RegExp(u.slice(6))}catch{return!1}t.push(a=>ge(l,a))}}return!0},!1)}function yo(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 Lt(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=Lt(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 jt(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(De).join("|")})`)}let n=new RegExp(`^${t.join(" ")}(?= |$)`);return r=>ge(n,r)}function So(e,t){let n=yo(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 l=n[o.i];if(!l||!/^[A-Za-z_]/.test(l)||n[o.i+1]!=="="||(o.i+=2,i[l]=Lt(n,o),i[l]===void 0&&(l==="pattern"||l==="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 u=jt(i.pattern);if(!u)return!1;s!=="allow"&&t.push(u)}return!0}function xo(e){if(!M(e))return[];try{return pe(e).filter(t=>t.endsWith(".rules")).sort().map(t=>p(e,t))}catch{return"unreadable"}}function $o(){return process.platform==="win32"?p(process.env.ProgramData||"C:\\ProgramData","OpenAI","Codex","requirements.toml"):"/etc/codex/requirements.toml"}function Ao(e){if(!(!h(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 To(e,t){let n;try{n=ve(e)}catch{return!1}if(n.rules===void 0)return!0;if(!h(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(!h(o)||!Array.isArray(o.pattern)||o.decision!=="prompt"&&o.decision!=="forbidden")return!1;let i=o.pattern.map(Ao);if(i.some(u=>u===void 0))return!1;let s=jt(i);if(!s)return!1;t.push(s)}return!0}function Co(e){let t=process.env.CODEX_HOME||p(I(),".codex"),n=[p(t,"rules"),...ne(e).map(i=>p(i,".codex","rules"))],r=[],o=null;try{o=ee($o(),"utf8")}catch(i){let s=i.code;if(s!=="ENOENT"&&s!=="ENOTDIR")return"unreadable"}if(o!==null&&!To(o,r))return"unreadable";for(let i of[...new Set(n)]){let s=xo(i);if(s==="unreadable")return"unreadable";for(let u of s){let l;try{l=ee(u,"utf8")}catch{return"unreadable"}if(!So(l,r))return"unreadable"}}return{matchers:r,complete:!1}}function h(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function De(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Eo(e){let t=e.trim().replace(/\s+/g," "),n=t.endsWith(" *")&&t.length>2,r=(n?t.slice(0,-2):t).split("*").map(De).join("[\\s\\S]*");return new RegExp(`^${r}${n?"(?: [\\s\\S]*)?":""}(?= |$)`)}var vo=512;function Oo(e){let t=e.replace(/['"\\]/g,"").split(/[\s;&|(){}<>`$]+/).filter(Boolean);return[t,t.map(z)]}function ge(e,t){if(e.test(t)||e.test(t.trim().replace(/\s+/g," ")))return!0;for(let n of Oo(t)){if(n.length>vo)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=Eo(e);return n=>ge(t,n)}function Ro(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(`^${De(r)}${n?"(?: [\\s\\S]*)?":""}$`);return i=>o.test(i)}var No={"claude-code":co,cursor:fo,"gemini-cli":ko,opencode:bo,antigravity:wo,codex:Co},Po=new Set(["codex"]),Dt=/(?:^|[\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 Io(e,t,n){let r=No[e];return r?r(t??process.cwd(),n):{matchers:[],complete:!1}}function Ho(e,t,n){return e==="unreadable"||Dt.test(t.replace(/['"\\]/g,""))||e.matchers.some(r=>r(t))?!1:e.complete||Nt(t,!Po.has(n))}var Ft=new Set(["default","acceptEdits","dontAsk"]);function Mt(e,t){return t.host!=="claude-code"||t.permissionMode==="bypassPermissions"?!0:e!=="unreadable"&&e.allowsEverything===!0&&Ft.has(t.permissionMode??"")}function Lo(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??=dt(t.configDir),!F(o,e.cwd,n)&&!r.paths.some(i=>F(o,e.cwd,i))?!1:o.includes("/")||!pt(o,r))}var jo=/^[^\s;&|<>()$`\\{}*?[\]~#!]+(?: [^\s;&|<>()$`\\{}*?[\]~#!]+)*$/;function Do(e,t,n){return n.host!=="claude-code"||e==="unreadable"||Mt(e,n)||!Ft.has(n.permissionMode??"")||!jo.test(t)||Dt.test(t.replace(/['"]/g,""))||(e.guards??[]).some(r=>r(t))?null:(e.trustedAllow??[]).find(r=>r.matches(t))?.rule??null}var Fo=/^(?:\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 Mo(e,t){return t.host==="claude-code"&&t.permissionMode==="default"&&Fo.test(e.trim())}function zt(e,t,n,r){if(!n||/["\\$`;&|<>(){}]|'\\''/.test(n))return null;let o=t.claudeDirs??me(),i=Io(t.host,t.cwd,o),s=Do(i,e,t),u=s||Ho(i,e,t.host)?Vr(e,n,Lo(t,o)):e;return u!==e&&i!=="unreadable"&&(s?(i.guards??[]).some(l=>l(u)):i.matchers.some(l=>l(u))||(i.allow??[]).some(l=>l(u)&&!l(e)))&&(u=e),r(t.sessionId,u!==e),u===e?null:s?{command:u,allowedBy:s}:Mt(i,t)?{command:u}:i!=="unreadable"&&Mo(e,t)&&!(i.allow??[]).some(l=>l(e))&&!(i.trustedAllow??[]).some(l=>l.matches(e))?{command:u,ask:!0}:null}function R(e,t,n,r){let o=zt(e,t,n,r);return o&&!o.ask?o.command:null}function U(e,t,n="unknown",r=$(t),o=w){return e?R(e,{host:t,sessionId:n},T()?null:r,o):null}function _(e,t){let n=e[t];return typeof n=="string"&&n?n:null}function oe(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function zo(e){return _(e,"prompt_id")||_(e,"scratchpad_dir")?!0:oe(e.effort)}function Uo(e){return _(e,"tool_use_id")?.startsWith("toolu_")===!0||/^claude/i.test(_(e,"model")??"")}var Jo=new Set(["BeforeTool","AfterTool","BeforeAgent","AfterAgent","BeforeModel","AfterModel","BeforeToolSelection"]),Wo=new Set(["preToolUse","postToolUse","beforeShellExecution","afterShellExecution","beforeSubmitPrompt","sessionStart","sessionEnd","stop"]),Bo=new Set(["pre_tool","post_tool"]),Go=new Set(["before_tool_call","after_tool_call"]),Zo=new Set(["runTerminalCommand","run_in_terminal"]),Vo=[["codex",e=>_(e,"turn_id")!==null],["claude-code",zo],["cursor",e=>_(e,"cursor_version")!==null||_(e,"generation_id")!==null||_(e,"conversation_id")!==null||Array.isArray(e.workspace_roots)||Wo.has(_(e,"hook_event_name")??"")],["gemini-cli",e=>Jo.has(_(e,"hook_event_name")??"")],["qwen-code",e=>e.hook_event_name==="PreToolUse"&&e.tool_name==="run_shell_command"],["vibe",e=>Bo.has(_(e,"hook_event_name")??"")],["antigravity",e=>oe(e.toolCall)],["copilot",e=>_(e,"toolName")!==null&&"toolArgs"in e||Zo.has(_(e,"tool_name")??"")],["grok",e=>e.toolName==="run_terminal_command"||e.tool_name==="run_terminal_command"||oe(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&&_(e,"event")!==null&&!Go.has(_(e,"event"))]],Ko=new Set(["codex","antigravity"]);function qo(e){return oe(e)?Vo.filter(([,t])=>t(e)).map(([t])=>t):[]}function Ut(e,t){if(!oe(e))return null;let n=qo(e);return n.length>1?null:n.length===1?n[0]:Uo(e)&&Ko.has(t)?"claude-code":t==="codex"?null:t}var Fe=JSON.stringify({permission:"allow"});function Jt(e,t=$("cursor"),n=w){if(e.tool_name!=="Shell")return Fe;let r=e.tool_input??{},o=r.command;if(typeof o!="string"||!o)return Fe;let i=typeof r.working_directory=="string"?r.working_directory:void 0,s=R(o,{host:"cursor",sessionId:e.conversation_id??"unknown",cwd:i},T()?null:t,n);return s?JSON.stringify({permission:"allow",updated_input:{...r,command:s}}):Fe}var he="{}";function Wt(e,t=$("gemini-cli"),n=w){if(e.hook_event_name!=="BeforeTool"||e.tool_name!=="run_shell_command")return he;let r=e.tool_input??{};if(r.is_background)return he;let o=r.command;if(typeof o!="string"||!o)return he;let i=typeof e.cwd=="string"?e.cwd:void 0,s=R(o,{host:"gemini-cli",sessionId:e.session_id??"unknown",cwd:i},T()?null:t,n);return s?JSON.stringify({hookSpecificOutput:{tool_input:{command:s}}}):he}var E="{}",Yo=new Set(["runTerminalCommand","run_in_terminal","Bash","bash"]),Xo=["run_in_background","is_background","isBackground"];function ke(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function Qo(e){let t=e.session_id??e.sessionId;return typeof t=="string"&&t?t:"unknown"}function ei(e,t){let n=e.cwd??t.cwd??t.workdir??t.working_directory;return typeof n=="string"&&n?n:void 0}function _e(e,t,n,r,o){if(!ke(t)||Xo.some(s=>t[s]===!0))return null;let i=t.command;return typeof i!="string"||!i?null:R(i,{host:e,sessionId:Qo(n),cwd:ei(n,t)},T()?null:r,o)}function W(e,t){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",updatedInput:{...e,command:t}}})}function ti(e){if(ke(e))return e;if(typeof e!="string")return null;try{let t=JSON.parse(e);return ke(t)?t:null}catch{return null}}function ni(e,t,n){if(typeof e.tool_name=="string"){if(!Yo.has(e.tool_name))return E;let i=e.tool_input,s=_e("copilot",i,e,t,n);return s?W(i,s):E}if(e.toolName!=="bash")return E;let r=ti(e.toolArgs),o=_e("copilot",r,e,t,n);return o?JSON.stringify({modifiedArgs:{...r,command:o}}):E}function J(e,t,n){return(r,o,i)=>{if(r.tool_name!==t)return E;let s=r.tool_input,u=_e(e,s,r,o,i);return u?n(s,u):E}}var ri=new Set(["run_terminal_command","Bash","bash"]);function oi(e,t,n){let r=e.toolName??e.tool_name;if(typeof r!="string"||!ri.has(r))return E;let o=e.toolInput??e.tool_input,i=_e("grok",o,e,t,n);return i?W(o,i):E}var ii={copilot:ni,droid:J("droid","Execute",W),trae:J("trae","RunCommand",W),"qwen-code":J("qwen-code","run_shell_command",W),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",W),grok:oi};function Bt(e,t,n=$(e),r=w){return ke(t)?ii[e](t,n,r):E}function B(e){return T()?null:$(e)}function si(e,t,n={}){let r=n.recordUsage??w;switch(e){case"claude-code":case"codex":return t.hook_event_name!==void 0&&t.hook_event_name!=="PreToolUse"?"":Pt(t,e,B(e),r,n.claudeDirs??me(),n.pathEnv??process.env.PATH,n.launchArgs??je)??"";case"cursor":return Jt(t,B(e),r);case"gemini-cli":return Wt(t,B(e),r);case"vibe":return Me(t,(o,i)=>U(o,"vibe",i,B(e),r));case"antigravity":return ze(t,(o,i)=>U(o,"antigravity",i,B(e),r));default:return Bt(e,t,B(e),r)}}function ie(e,t,n={}){let r=Ut(e,t);return r?si(r,e,n):n.fallback??""}var ui=new Set(["bash","file_system.bash"]),be=JSON.stringify({decision:"allow"});function Me(e,t=(n,r)=>U(n,"vibe",r)){if(!P(e)||e.hook_event_name!=="pre_tool"||typeof e.tool_name!="string"||!ui.has(e.tool_name))return"";let n=e.tool_input;if(!P(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 ze(e,t=(n,r)=>U(n,"antigravity",r)){if(!P(e)||!P(e.toolCall)||e.toolCall.name!=="run_command")return be;let n=e.toolCall.args;if(!P(n)||typeof n.CommandLine!="string"||!n.CommandLine)return be;let r=t(n.CommandLine,typeof e.conversationId=="string"?e.conversationId:"unknown");return r?JSON.stringify({decision:"allow",overwrite:{CommandLine:r}}):be}var Gt={vibe:{build:e=>Me(e),fallback:""},antigravity:{build:e=>ze(e),fallback:be}};function Zt(e){return Gt[e??""]?.fallback??""}function li(e,t){let n=Gt[e??""];if(!n)return"";let r;try{r=JSON.parse(t.replace(/^/,""))}catch{return n.fallback}return P(r)?ie(r,e,{fallback:n.fallback}):n.build(r)}async function Vt(e){process.stdout.write(li(e,await Z()))}Vt(process.argv[2]).catch(e=>{process.stderr.write(`tkr-agent-hook: ${e.message}
19
- `),process.stdout.write(Zt(process.argv[2])),process.exit(0)});
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 U(e){let t=[],n=Nr(e);for(;;){t.push(n);let r=vt(n);if(r===n)return t;n=r}}function go(){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 me(p(e,"managed-settings.d")))n.endsWith(".json")&&t.push(p(e,"managed-settings.d",n))}catch{return t}return t}function re(e,t,n,r){let o=[];for(let i of e){let s=mo(i,t);if(s!=="missing"&&(s==="unreadable"||!h(s)||!n(s,o)))return"unreadable"}return{matchers:o,complete:r}}function ne(e){return e===void 0?[]:Array.isArray(e)?e.filter(t=>typeof t=="string"):null}function ge(){return{projectDir:process.env.CLAUDE_PROJECT_DIR,configDir:process.env.CLAUDE_CONFIG_DIR?.trim()?ue():void 0}}function ho(e,t){let n=y=>[p(y,"settings.json"),p(y,"settings.local.json")],r=y=>n(p(y,".claude")),o=p(H(),".claude"),i=t.configDir||o,s=[[go(),"managed"],[[p(i,"settings.json")],"loaded"],[[p(i,"settings.local.json")],"loadedLocal"],[t.configDir?n(o):[],"extra"],[t.projectDir?r(t.projectDir):[],"project"],[U(e).flatMap(r),"extra"]],u=[],l={managed:[],loaded:[],loadedLocal:[],project:[],extra:[]},a={managed:!1,loaded:!1,loadedLocal:!1,project:!1,extra:!1},c=!1,d="managed",g=(y,Z)=>{let v=y.permissions;if(d==="managed"&&(y.allowManagedPermissionRulesOnly===!0||h(v)&&v.allowManagedPermissionRulesOnly===!0)&&(c=!0),v===void 0)return!0;if(!h(v))return!1;for(let Je of["deny","ask","allow"]){let We=ne(v[Je]);if(!We)return!1;for(let Be of We){let j=/^\s*Bash\s*(?:\(([\s\S]*)\))?\s*$/.exec(Be);if(j)if(Je!=="allow")Z.push(L((j[1]??"*").replace(/:\*$/," *")));else if(j[1]===void 0||j[1].trim()==="*")a[d]=!0;else{u.push(L(j[1].replace(/:\*$/," *")));let Ge=Lo(j[1]);Ge&&l[d].push({rule:Be.trim(),matches:Ge})}}}return!0},m=[];for(let[y,Z]of s){d=Z;let v=re(y,!1,g,!0);if(v==="unreadable")return"unreadable";m.push(...v.matchers)}let k=a.managed||(a.loaded||a.loadedLocal)&&!c,A=[...l.managed,...c?[]:l.loaded];return{matchers:[...m,...k?[]:u],complete:!0,allow:u,allowsEverything:k,guards:m,trustedAllow:A}}function ko(e){let t=[p(H(),".cursor","cli-config.json"),...U(e).map(n=>p(n,".cursor","cli.json"))];return re(t,!0,(n,r)=>{let o=n.permissions;if(o===void 0)return!0;if(!h(o))return!1;let i=ne(o.deny);if(!i)return!1;for(let s of i){let u=/^\s*Shell\s*(?:\(([\s\S]*)\))?\s*$/.exec(s);if(!u)continue;let l=u[1]??"*",a=l.indexOf(":");r.push(L(a===-1?`${l} *`:`${l.slice(0,a)} ${l.slice(a+1)}`))}return!0},!1)}function _o(){return process.platform==="darwin"?"/Library/Application Support/GeminiCli":process.platform==="win32"?"C:\\ProgramData\\gemini-cli":"/etc/gemini-cli"}var Dt=/^\s*(?:run_shell_command|ShellTool)\s*(?:\(([\s\S]*)\))?\s*$/;function bo(e,t){let n=e.tools;if(n!==void 0&&!h(n))return!1;let r=[ne(e.excludeTools),ne(h(n)?n.exclude:void 0)];for(let o of r){if(!o)return!1;for(let i of o){let s=Dt.exec(i);s&&t.push(L(s[1]===void 0?"*":`${s[1]}*`))}}return!0}function Ct(e){try{return JSON.parse(e)}catch{return null}}function wo(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]??Ct(`"${r[1]}"`);if(o===null)return null;n.push(o)}return n}if(t.startsWith('"')){let n=/^"((?:\\.|[^"\\])*)"/.exec(t);return n?Ct(`"${n[1]}"`):null}if(t.startsWith("'")){let n=/^'([^']*)'/.exec(t);return n?n[1]:null}return t.replace(/\s*#.*$/,"")}function yo(e,t){for(let n of e.split(/^\s*\[\[\s*rule\s*\]\]\s*$/m).slice(1)){let r={};for(let l of n.split(/\r?\n/)){if(/^\s*\[/.test(l))break;let a=/^\s*([A-Za-z_]+)\s*=\s*(.*)$/.exec(l);if(!a)continue;let c=wo(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(l=>l==="*"||Dt.test(l)))continue;let s=r.commandPrefix===void 0?[]:[r.commandPrefix].flat(),u=[r.commandRegex,r.argsPattern].flat().filter(l=>typeof l=="string");if(s.length===0&&u.length===0){t.push(()=>!0);continue}for(let l of s)t.push(L(`${l}*`));for(let l of u){let a;try{a=new RegExp(l)}catch{return!1}t.push(c=>a.test(JSON.stringify({command:c}))||he(a,c))}}return!0}function Tt(e){try{return me(e).filter(t=>t.endsWith(".toml")).map(t=>p(e,t))}catch{return[]}}function So(e){let t=_o(),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(H(),".gemini","settings.json"),...U(e).map(o=>p(o,".gemini","settings.json"))].filter(o=>!!o),r=re(n,!0,bo,!1);if(r==="unreadable")return r;for(let o of[...Tt(p(H(),".gemini","policies")),...Tt(p(t,"policies"))]){let i;try{i=te(o,"utf8")}catch{return"unreadable"}if(!yo(i,r.matchers))return"unreadable"}return r}function He(e,t){if(e===void 0)return!0;if(typeof e=="string")return e!=="allow"&&t.push(()=>!0),!0;if(!h(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(!h(r))return!1;for(let[o,i]of Object.entries(r))i!=="allow"&&t.push(L(o.replace(/\?/g,"*")))}}return!0}function Et(e,t){if(e.permissions!==void 0||!He(e.permission,t))return!1;for(let n of["agent","agents","mode"]){let r=e[n];if(r!==void 0){if(!h(r))return!1;for(let o of Object.values(r))if(h(o)&&(o.permissions!==void 0||!He(o.permission,t)))return!1}}return!0}function xo(e){for(let t of e)for(let n of["agent","agents","mode","modes"]){let r;try{r=me(p(t,n))}catch{continue}for(let o of r)try{if(o.endsWith(".md")&&/permission/i.test(te(p(t,n,o),"utf8")))return!0}catch{return!0}}return!1}function $o(e){let t=p(process.env.XDG_CONFIG_HOME||p(H(),".config"),"opencode"),n=U(e),r=[t,...n.map(u=>p(u,".opencode"))];if(xo(r))return"unreadable";let o=["opencode.json","opencode.jsonc","config.json"],i=[...o.map(u=>p(t,u)),process.env.OPENCODE_CONFIG,...n.flatMap(u=>[...o.slice(0,2).map(l=>p(u,l)),...o.slice(0,2).map(l=>p(u,".opencode",l))])].filter(u=>!!u),s=re(i,!0,Et,!0);if(s==="unreadable")return s;for(let u of[process.env.OPENCODE_CONFIG_CONTENT,process.env.OPENCODE_PERMISSION]){if(!u)continue;let l;try{l=JSON.parse(jt(u))}catch{return"unreadable"}if(!(u===process.env.OPENCODE_PERMISSION?He(l,s.matchers):h(l)&&Et(l,s.matchers)))return"unreadable"}return s}function Ao(){return re([p(H(),".gemini","antigravity-cli","settings.json")],!0,(e,t)=>{let n=e.permissions;if(n===void 0)return!0;if(!h(n))return!1;for(let r of["deny","ask"]){let o=ne(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 u=s[1].trim();if(!u.startsWith("regex:")){t.push(L(u==="*"?"*":`${u} *`));continue}let l;try{l=new RegExp(u.slice(6))}catch{return!1}t.push(a=>he(l,a))}}return!0},!1)}function Co(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 Ft(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=Ft(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 Mt(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(Fe).join("|")})`)}let n=new RegExp(`^${t.join(" ")}(?= |$)`);return r=>he(n,r)}function To(e,t){let n=Co(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 l=n[o.i];if(!l||!/^[A-Za-z_]/.test(l)||n[o.i+1]!=="="||(o.i+=2,i[l]=Ft(n,o),i[l]===void 0&&(l==="pattern"||l==="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 u=Mt(i.pattern);if(!u)return!1;s!=="allow"&&t.push(u)}return!0}function Eo(e){if(!I(e))return[];try{return me(e).filter(t=>t.endsWith(".rules")).sort().map(t=>p(e,t))}catch{return"unreadable"}}function vo(){return process.platform==="win32"?p(process.env.ProgramData||"C:\\ProgramData","OpenAI","Codex","requirements.toml"):"/etc/codex/requirements.toml"}function Oo(e){if(!(!h(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 Ro(e,t){let n;try{n=Oe(e)}catch{return!1}if(n.rules===void 0)return!0;if(!h(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(!h(o)||!Array.isArray(o.pattern)||o.decision!=="prompt"&&o.decision!=="forbidden")return!1;let i=o.pattern.map(Oo);if(i.some(u=>u===void 0))return!1;let s=Mt(i);if(!s)return!1;t.push(s)}return!0}function No(e){let t=process.env.CODEX_HOME||p(H(),".codex"),n=[p(t,"rules"),...U(e).map(i=>p(i,".codex","rules"))],r=[],o=null;try{o=te(vo(),"utf8")}catch(i){let s=i.code;if(s!=="ENOENT"&&s!=="ENOTDIR")return"unreadable"}if(o!==null&&!Ro(o,r))return"unreadable";for(let i of[...new Set(n)]){let s=Eo(i);if(s==="unreadable")return"unreadable";for(let u of s){let l;try{l=te(u,"utf8")}catch{return"unreadable"}if(!To(l,r))return"unreadable"}}return{matchers:r,complete:!1}}function h(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function Fe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Po(e){let t=e.trim().replace(/\s+/g," "),n=t.endsWith(" *")&&t.length>2,r=(n?t.slice(0,-2):t).split("*").map(Fe).join("[\\s\\S]*");return new RegExp(`^${r}${n?"(?: [\\s\\S]*)?":""}(?= |$)`)}var Io=512;function Ho(e){let t=e.replace(/['"\\]/g,"").split(/[\s;&|(){}<>`$]+/).filter(Boolean);return[t,t.map(z)]}function he(e,t){if(e.test(t)||e.test(t.trim().replace(/\s+/g," ")))return!0;for(let n of Ho(t)){if(n.length>Io)return!0;for(let r=0;r<n.length;r++)if(e.test(n.slice(r).join(" ")))return!0}return!1}function L(e){let t=Po(e);return n=>he(t,n)}function Lo(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(`^${Fe(r)}${n?"(?: [\\s\\S]*)?":""}$`);return i=>o.test(i)}var jo={"claude-code":ho,cursor:ko,"gemini-cli":So,opencode:$o,antigravity:Ao,codex:No},Do=new Set(["codex"]),zt=/(?:^|[\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 Fo(e,t,n){let r=jo[e];return r?r(t??process.cwd(),n):{matchers:[],complete:!1}}function Mo(e,t,n){return e==="unreadable"||zt.test(t.replace(/['"\\]/g,""))||e.matchers.some(r=>r(t))?!1:e.complete||Ht(t,!Do.has(n))}var Ut=new Set(["default","acceptEdits","dontAsk"]);function Jt(e,t){return t.host!=="claude-code"||t.permissionMode==="bypassPermissions"?!0:e!=="unreadable"&&e.allowsEverything===!0&&Ut.has(t.permissionMode??"")}var zo=/(?:^|[\s/])git(?:\.exe|\.real|-[a-z][\w-]*)?(?=\s|$)/;function Uo(e){if(!e)return!1;try{for(let t of U(e)){let n=p(t,".git");if(I(n))return Or(n).isFile()}}catch{return!0}return!1}function Jo(e,t){let n="pathEnv"in e?e.pathEnv:process.env.PATH,r,o;return(i,s)=>e.host!=="claude-code"?M(i,e.cwd,n):s!==void 0&&zo.test(s)&&(o??=Uo(e.cwd))||(r??=gt(t.configDir),!M(i,e.cwd,n)&&!r.paths.some(u=>M(i,e.cwd,u)))?!1:i.includes("/")||!ht(i,r)}var Wo=/^[^\s;&|<>()$`\\{}*?[\]~#!]+(?: [^\s;&|<>()$`\\{}*?[\]~#!]+)*$/;function Bo(e,t,n){return n.host!=="claude-code"||e==="unreadable"||Jt(e,n)||!Ut.has(n.permissionMode??"")||!Wo.test(t)||zt.test(t.replace(/['"]/g,""))||(e.guards??[]).some(r=>r(t))?null:(e.trustedAllow??[]).find(r=>r.matches(t))?.rule??null}var Go=/^(?:\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 Zo(e,t){return t.host==="claude-code"&&t.permissionMode==="default"&&Go.test(e.trim())}function Wt(e,t,n,r){if(!n||/["\\$`;&|<>(){}]|'\\''/.test(n))return null;let o=t.claudeDirs??ge(),i=Fo(t.host,t.cwd,o),s=Bo(i,e,t),u=s||Mo(i,e,t.host)?Qr(e,n,Jo(t,o)):e;return u!==e&&i!=="unreadable"&&(s?(i.guards??[]).some(l=>l(u)):i.matchers.some(l=>l(u))||(i.allow??[]).some(l=>l(u)&&!l(e)))&&(u=e),r(t.sessionId,u!==e),u===e?null:s?{command:u,allowedBy:s}:Jt(i,t)?{command:u}:i!=="unreadable"&&Zo(e,t)&&!(i.allow??[]).some(l=>l(e))&&!(i.trustedAllow??[]).some(l=>l.matches(e))?{command:u,ask:!0}:null}function R(e,t,n,r){let o=Wt(e,t,n,r);return o&&!o.ask?o.command:null}function J(e,t,n="unknown",r=$(t),o=w){return e?R(e,{host:t,sessionId:n},C()?null:r,o):null}function _(e,t){let n=e[t];return typeof n=="string"&&n?n:null}function oe(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function Vo(e){return _(e,"prompt_id")||_(e,"scratchpad_dir")?!0:oe(e.effort)}function Ko(e){return _(e,"tool_use_id")?.startsWith("toolu_")===!0||/^claude/i.test(_(e,"model")??"")}var qo=new Set(["BeforeTool","AfterTool","BeforeAgent","AfterAgent","BeforeModel","AfterModel","BeforeToolSelection"]),Yo=new Set(["preToolUse","postToolUse","beforeShellExecution","afterShellExecution","beforeSubmitPrompt","sessionStart","sessionEnd","stop"]),Xo=new Set(["pre_tool","post_tool"]),Qo=new Set(["before_tool_call","after_tool_call"]),ei=new Set(["runTerminalCommand","run_in_terminal"]),ti=[["codex",e=>_(e,"turn_id")!==null],["claude-code",Vo],["cursor",e=>_(e,"cursor_version")!==null||_(e,"generation_id")!==null||_(e,"conversation_id")!==null||Array.isArray(e.workspace_roots)||Yo.has(_(e,"hook_event_name")??"")],["gemini-cli",e=>qo.has(_(e,"hook_event_name")??"")],["qwen-code",e=>e.hook_event_name==="PreToolUse"&&e.tool_name==="run_shell_command"],["vibe",e=>Xo.has(_(e,"hook_event_name")??"")],["antigravity",e=>oe(e.toolCall)],["copilot",e=>_(e,"toolName")!==null&&"toolArgs"in e||ei.has(_(e,"tool_name")??"")],["grok",e=>e.toolName==="run_terminal_command"||e.tool_name==="run_terminal_command"||oe(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&&_(e,"event")!==null&&!Qo.has(_(e,"event"))]],ni=new Set(["codex","antigravity"]);function ri(e){return oe(e)?ti.filter(([,t])=>t(e)).map(([t])=>t):[]}function Bt(e,t){if(!oe(e))return null;let n=ri(e);return n.length>1?null:n.length===1?n[0]:Ko(e)&&ni.has(t)?"claude-code":t==="codex"?null:t}var Me=JSON.stringify({permission:"allow"});function Gt(e,t=$("cursor"),n=w){if(e.tool_name!=="Shell")return Me;let r=e.tool_input??{},o=r.command;if(typeof o!="string"||!o)return Me;let i=typeof r.working_directory=="string"?r.working_directory:void 0,s=R(o,{host:"cursor",sessionId:e.conversation_id??"unknown",cwd:i},C()?null:t,n);return s?JSON.stringify({permission:"allow",updated_input:{...r,command:s}}):Me}var ke="{}";function Zt(e,t=$("gemini-cli"),n=w){if(e.hook_event_name!=="BeforeTool"||e.tool_name!=="run_shell_command")return ke;let r=e.tool_input??{};if(r.is_background)return ke;let o=r.command;if(typeof o!="string"||!o)return ke;let i=typeof e.cwd=="string"?e.cwd:void 0,s=R(o,{host:"gemini-cli",sessionId:e.session_id??"unknown",cwd:i},C()?null:t,n);return s?JSON.stringify({hookSpecificOutput:{tool_input:{command:s}}}):ke}var E="{}",oi=new Set(["runTerminalCommand","run_in_terminal","Bash","bash"]),ii=["run_in_background","is_background","isBackground"];function _e(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function si(e){let t=e.session_id??e.sessionId;return typeof t=="string"&&t?t:"unknown"}function ui(e,t){let n=e.cwd??t.cwd??t.workdir??t.working_directory;return typeof n=="string"&&n?n:void 0}function be(e,t,n,r,o){if(!_e(t)||ii.some(s=>t[s]===!0))return null;let i=t.command;return typeof i!="string"||!i?null:R(i,{host:e,sessionId:si(n),cwd:ui(n,t)},C()?null:r,o)}function B(e,t){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",updatedInput:{...e,command:t}}})}function li(e){if(_e(e))return e;if(typeof e!="string")return null;try{let t=JSON.parse(e);return _e(t)?t:null}catch{return null}}function ai(e,t,n){if(typeof e.tool_name=="string"){if(!oi.has(e.tool_name))return E;let i=e.tool_input,s=be("copilot",i,e,t,n);return s?B(i,s):E}if(e.toolName!=="bash")return E;let r=li(e.toolArgs),o=be("copilot",r,e,t,n);return o?JSON.stringify({modifiedArgs:{...r,command:o}}):E}function W(e,t,n){return(r,o,i)=>{if(r.tool_name!==t)return E;let s=r.tool_input,u=be(e,s,r,o,i);return u?n(s,u):E}}var ci=new Set(["run_terminal_command","Bash","bash"]);function fi(e,t,n){let r=e.toolName??e.tool_name;if(typeof r!="string"||!ci.has(r))return E;let o=e.toolInput??e.tool_input,i=be("grok",o,e,t,n);return i?B(o,i):E}var di={copilot:ai,droid:W("droid","Execute",B),trae:W("trae","RunCommand",B),"qwen-code":W("qwen-code","run_shell_command",B),crush:W("crush","bash",(e,t)=>JSON.stringify({updated_input:{command:t}})),junie:W("junie","Bash",(e,t)=>JSON.stringify({updatedInput:{...e,command:t}})),zcode:W("zcode","Bash",B),grok:fi};function Vt(e,t,n=$(e),r=w){return _e(t)?di[e](t,n,r):E}function G(e){return C()?null:$(e)}function pi(e,t,n={}){let r=n.recordUsage??w;switch(e){case"claude-code":case"codex":return t.hook_event_name!==void 0&&t.hook_event_name!=="PreToolUse"?"":Lt(t,e,G(e),r,n.claudeDirs??ge(),n.pathEnv??process.env.PATH,n.launchArgs??De)??"";case"cursor":return Gt(t,G(e),r);case"gemini-cli":return Zt(t,G(e),r);case"vibe":return ze(t,(o,i)=>J(o,"vibe",i,G(e),r));case"antigravity":return Ue(t,(o,i)=>J(o,"antigravity",i,G(e),r));default:return Vt(e,t,G(e),r)}}function ie(e,t,n={}){let r=Bt(e,t);return r?pi(r,e,n):n.fallback??""}var mi=new Set(["bash","file_system.bash"]),we=JSON.stringify({decision:"allow"});function ze(e,t=(n,r)=>J(n,"vibe",r)){if(!P(e)||e.hook_event_name!=="pre_tool"||typeof e.tool_name!="string"||!mi.has(e.tool_name))return"";let n=e.tool_input;if(!P(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 Ue(e,t=(n,r)=>J(n,"antigravity",r)){if(!P(e)||!P(e.toolCall)||e.toolCall.name!=="run_command")return we;let n=e.toolCall.args;if(!P(n)||typeof n.CommandLine!="string"||!n.CommandLine)return we;let r=t(n.CommandLine,typeof e.conversationId=="string"?e.conversationId:"unknown");return r?JSON.stringify({decision:"allow",overwrite:{CommandLine:r}}):we}var Kt={vibe:{build:e=>ze(e),fallback:""},antigravity:{build:e=>Ue(e),fallback:we}};function qt(e){return Kt[e??""]?.fallback??""}function gi(e,t){let n=Kt[e??""];if(!n)return"";let r;try{r=JSON.parse(t.replace(/^/,""))}catch{return n.fallback}return P(r)?ie(r,e,{fallback:n.fallback}):n.build(r)}async function Yt(e){process.stdout.write(gi(e,await V()))}Yt(process.argv[2]).catch(e=>{process.stderr.write(`tkr-agent-hook: ${e.message}
19
+ `),process.stdout.write(qt(process.argv[2])),process.exit(0)});
20
20
  /*! Bundled license information:
21
21
 
22
22
  smol-toml/dist/error.js: