@tokmizer/plugin 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.codex-plugin/plugin.json +1 -1
- package/README.md +3 -1
- package/dist/bin/tkr-agent-hook.js +13 -13
- package/dist/bin/tkr-codex-hook.js +74 -74
- package/dist/bin/tkr-context-hook.js +1 -1
- package/dist/bin/tkr-copilot-hook.js +12 -12
- package/dist/bin/tkr-crush-hook.js +12 -12
- package/dist/bin/tkr-cursor-hook.js +12 -12
- package/dist/bin/tkr-daemon.js +131 -131
- package/dist/bin/tkr-droid-hook.js +12 -12
- package/dist/bin/tkr-exec +0 -0
- package/dist/bin/tkr-exec.js +74 -74
- package/dist/bin/tkr-gemini-hook.js +12 -12
- package/dist/bin/tkr-grok-hook.js +12 -12
- package/dist/bin/tkr-junie-hook.js +12 -12
- package/dist/bin/tkr-processor.js +103 -103
- package/dist/bin/tkr-qwen-hook.js +12 -12
- package/dist/bin/tkr-shim.js +66 -66
- package/dist/bin/tkr-trae-hook.js +12 -12
- package/dist/bin/tkr-zcode-hook.js +12 -12
- package/dist/bin/tkr.js +275 -260
- package/dist/hooks-host/post-tool-use.js +88 -88
- package/dist/hooks-host/pre-tool-use.js +13 -13
- package/dist/hooks-host/reducer-prompt-submit.js +1 -1
- package/dist/hooks-host/reducer-session-start.js +1 -1
- package/dist/hooks-host/reducer-stop.js +1 -1
- package/dist/hooks-host/session-recap.js +7 -5
- package/dist/index.js +46 -46
- package/dist/native/manifest.json +12 -12
- package/dist/native/single.json +2 -32
- package/dist/native/tkr-exec-darwin-arm64 +0 -0
- package/dist/native/tkr-exec-darwin-x64 +0 -0
- package/dist/native/tkr-exec-linux-arm64 +0 -0
- package/dist/native/tkr-exec-linux-x64 +0 -0
- package/dist/native/tkr-exec-win32-arm64.exe +0 -0
- package/dist/native/tkr-exec-win32-x64.exe +0 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -214,7 +214,9 @@ Your deny and ask rules, `--disallowedTools`, `--settings`, managed policies and
|
|
|
214
214
|
| `/tkr-unlink` | `tkr unlink` | detach this machine from the account |
|
|
215
215
|
| `/tkr-update` | npm, brew or auto-update | latest version |
|
|
216
216
|
|
|
217
|
-
Also in the terminal: `tkr restore`, `tkr doctor [--fix]`, `tkr discover`, `tkr session`, `tkr network`, `tkr filters`, `tkr migrate rtk`, `tkr setup`, `tkr uninstall`. `tkr help` lists everything.
|
|
217
|
+
Also in the terminal: `tkr restore`, `tkr doctor [--fix]`, `tkr discover`, `tkr session`, `tkr learn`, `tkr gain --watch`, `tkr network`, `tkr filters`, `tkr migrate rtk`, `tkr setup`, `tkr uninstall`. `tkr help` lists everything.
|
|
218
|
+
|
|
219
|
+
`tkr learn` reads this project's Claude Code history and lists commands the agent got wrong, then fixed (a wrong flag, a missing module, a zsh quirk). `tkr learn --write` saves them to `.claude/rules/tkr-command-corrections.md` so the agent runs the working form first. Nothing leaves your machine. `tkr gain --watch` keeps the savings view open and refreshes it every 2 seconds.
|
|
218
220
|
|
|
219
221
|
## Compression modes
|
|
220
222
|
|
|
@@ -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
|
|
4
|
-
`)}function
|
|
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}`;
|
|
3
|
+
function K(e=3e3){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 sn}from"node:path";var un={exec:"tkr-exec",processor:"tkr-processor",daemon:"tkr-daemon","shim-run":"tkr-shim"},ln={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 q(e){let t=sn(e).replace(/\.(m?js|ts)$/,"");if(t==="tkr")return[];for(let[n,r]of Object.entries(un))if(r===t)return[n];for(let[n,r]of Object.entries(ln))if(r===t)return["hook",n];return null}import{realpathSync as Ke}from"node:fs";import{delimiter as an,join as M}from"node:path";import cn from"node:os";function I(){return!1}function Ye(e,t=process.execPath){let n=I()?q(e):null;return n?[process.execPath,...n]:[t,e]}function qe(e,t){try{return Ke(e)===Ke(t)}catch{return!1}}function Se(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"?";":an)){if(!o||o.includes("node_modules"))continue;let i=M(o,r);if(qe(i,n))return i}if(t!=="win32"){let o=cn.homedir();for(let i of[M(o,".local","bin",r),M(o,".local","share","tokmizer","current","dist","bin",r),M("/opt/homebrew/bin",r),M("/usr/local/bin",r),M("/home/linuxbrew/.linuxbrew/bin",r)])if(qe(i,n))return i}return n}import fn from"node:os";import{isAbsolute as dn,join as Xe,resolve as Qe}from"node:path";function ue(e=process.env,t=fn.homedir()){let n=e.CLAUDE_CONFIG_DIR?.trim();if(!n)return Xe(t,".claude");let r=n;return r==="~"?r=t:(r.startsWith("~/")||r.startsWith("~\\"))&&(r=Xe(t,r.slice(2))),dn(r)?Qe(r):Qe(r)}import{accessSync as _n,chmodSync as bn,constants as wn,existsSync as le,mkdirSync as yn,readdirSync as Sn,readFileSync as xn,realpathSync as ot,renameSync as $n,unlinkSync as An,writeFileSync as Cn}from"node:fs";import{basename as Ae,dirname as P,join as T,sep as z}from"node:path";import pn from"node:os";import{join as mn}from"node:path";function x(){return process.env.TOKMIZER_HOME||mn(pn.homedir(),".tokmizer")}import{rmSync as gn,statSync as hn}from"node:fs";import{join as et}from"node:path";function tt(){return et(x(),"shims")}function xe(){return et(x(),"fail-open")}var kn=24*36e5;function C(e=Date.now()){try{if(e-hn(xe()).mtimeMs<kn)return!0;gn(xe(),{force:!0})}catch{}return!1}function nt(){return`[ -f ${E(xe())} ]`}function E(e){return`'${e.replace(/'/g,"'\\''")}'`}function rt(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 st=1,Y="tkr-shim.stable",ut=/^(?:0|[1-9]\d{0,5})\.(?:0|[1-9]\d{0,5})\.(?:0|[1-9]\d{0,5})$/;function En(){return T(x(),"bin","tkr-shim-launch")}function Tn(){return T(x(),"bin","tkr-run")}function it(){return T(ue(),"plugins","cache","tokmizer","tokmizer")}function vn(e){let t=P(P(P(e)));return ut.test(Ae(t))&&Ae(P(t))==="tokmizer"?P(t):null}function Ce(e){return/[\n\r]/.test(e)||e.includes(`${z}_npx${z}`)||e.includes(`${z}.bun${z}install${z}cache${z}`)}function Ee(e){let t=e.match(/^(.*)[\\/]Cellar[\\/]([^\\/]+)[\\/][^\\/]+[\\/](.*)$/);if(!t)return e;let n=T(t[1],"opt",t[2],t[3]);try{return ot(n)===ot(e)?n:e}catch{return e}}function On(e=process.execPath){return Ce(e)?"":Ee(e)}function Rn(e,t=I()){if(t&&q(e)){let o=Se();return{single:Ce(o)?"":Ee(o),js:"",cache:it(),node:""}}let n=On(),r=vn(e);return r?{single:"",js:"",cache:r,node:n}:{single:"",js:Ce(e)?"":Ee(e),cache:it(),node:n}}function Pn(e){try{return _n(e,wn.X_OK),!0}catch{return!1}}function Nn(e){let t=null,n=-1,r;try{r=Sn(e)}catch{return null}for(let o of r){if(!ut.test(o))continue;let i=T(e,o);if(!le(T(i,"dist","bin","tkr-shim.js"))||!le(T(i,"dist","bin",Y)))continue;let[s,u,l]=o.split(".").map(Number),a=s*1e6+u*1e3+l;a>n&&(n=a,t=i)}return t}function $e(e){return e.single&&Pn(e.single)||e.js&&le(e.js)&&(Ae(e.js)!=="tkr-shim.js"||le(T(P(e.js),Y)))?!0:e.cache!==""&&Nn(e.cache)!==null}function In(e,t){return["_tk_t=",`if [ -n "$_tk_j" ] && [ -f "${t}" ] && { [ "\${_tk_j##*/}" != tkr-shim.js ] || [ -f "\${_tk_j%/*}/${Y}" ]; }; 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/${Y}" ] || 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=${E(tt())}`," 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/${Y}" ] && [ -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 Hn(e){return["#!/bin/sh",`_tk_f=${st}`,`_tk_s=${E(e.single)}`,`_tk_j=${E(e.js)}`,`_tk_k=${E(e.cache)}`,`_tk_n=${E(e.node)}`,'[ "$#" -gt 0 ] || exit 0',`if ! ${nt()}; then`,' if [ -n "$_tk_s" ] && [ -x "$_tk_s" ]; then exec "$_tk_s" exec "$@"; fi',...In("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 lt(e){let t=Tn(),n=Rn(T(P(e),"tkr-shim.js")),r=jn(t);if(r&&r.format===st&&$e(r.target)&&JSON.stringify(r.target)===JSON.stringify(n))return t;if(!$e(n))return r&&$e(r.target)?t:null;let o=`${t}.${process.pid}.tmp`;try{return yn(P(t),{recursive:!0,mode:448}),Cn(o,Hn(n),{mode:493}),bn(o,493),$n(o,t),t}catch{try{An(o)}catch{}return null}}function Ln(e){let t=u=>{let l=e.match(new RegExp(`^${u}=(.*)$`,"m"));return l?u==="_tk_f"?l[1]:rt(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 jn(e=En()){try{return Ln(xn(e,"utf8"))}catch{return null}}function Dn(e){return e.charCodeAt(0)===65279?e.slice(1):e}function Te(e){return JSON.parse(Dn(e))}function H(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}import{appendFileSync as Wn,chmodSync as Jn,mkdirSync as Bn,existsSync as Gn,readFileSync as As,rmSync as Cs}from"node:fs";import{dirname as Zn,join as Vn}from"node:path";import{readFileSync as Fn,renameSync as Mn,statSync as zn,writeFileSync as Un}from"node:fs";function at(e,t,n){try{if(zn(e).size<=t)return;let r=Fn(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}`;Un(s,o.length?`${o.join(`
|
|
6
6
|
`)}
|
|
7
|
-
`:"",{mode:384}),
|
|
8
|
-
`,{mode:384}),
|
|
7
|
+
`:"",{mode:384}),Mn(s,e)}catch{}}var Kn="usage.jsonl";var ct=2*1024*1024;function qn(){return Vn(x(),Kn)}function y(e,t,n=qn()){try{let r=Zn(n);Gn(r)||Bn(r,{recursive:!0,mode:448});let o=e.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";Wn(n,`{"t":${Math.floor(Date.now()/1e3)},"s":"${o}","o":${t?1:0}}
|
|
8
|
+
`,{mode:384}),Jn(n,384),at(n,ct,ct/2)}catch{}}import{spawnSync as It}from"node:child_process";import{existsSync as v,readFileSync as ne,readdirSync as me,statSync as Lr}from"node:fs";import{homedir as j,userInfo as jr}from"node:os";import{fileURLToPath as Ht}from"node:url";import{dirname as je,join as p,resolve as Dr,win32 as Fr}from"node:path";function Yn(e,t){let n=e.slice(0,t).split(/\r?\n/);return[n.length,n.pop().length+1]}function Xn(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]=
|
|
10
|
+
`))}return o}var f=class e extends Error{line;column;codeblock;constructor(t,n){let[r,o]=Yn(n.toml,n.ptr),i=Xn(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
|
|
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 Yn=/^(\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(Yn);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 Oe(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?ft(e):ct(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?Xn(e,r,t):e.s.charCodeAt(e.p+2)===58?Qn(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||Oe(i=e.s.charCodeAt(e.p),o))return e.bi===!0?0n:0;if(!r){if(i===120)return ve(e,t,16,o);if(i===98)return ve(e,t,2,o);if(i===111)return ve(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),!Oe(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):at(e,l,10,t)}function ve(e,t,n,r){let o,i=1;for(;++e.p<e.s.length&&(o=e.s.charCodeAt(e.p),!Oe(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("_","")),at(e,s,n,t)}function at(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 Xn(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 Qn(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 er(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 A(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;er(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 ct(e){let t=e.p++,n=Object.create(null),r=new Set,o;for(;e.p<e.s.length;){if(A(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),A(e,!0,!0);let c=X(e,125);if(s&&typeof(s[i]=c)=="object"&&r.add(c),A(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 ft(e){let t=e.p++,n=[],r;for(;e.p<e.s.length;){if(A(e),(r=e.s.charCodeAt(e.p))===93)return e.p++,n;if(n.push(X(e,93)),A(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 dt(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 pt(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 Re(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++,A(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=dt(n,c,r,o,a?2:1);d?(l=d[2],u=d[1]):(pt(n,d,i),s=!0)}else{i=n.p;let a=ce(n),c=dt(n,a,u,l,0);!c&&!s&&pt(n,c,i),A(n,!0,!0);let d=X(n,void 0);c&&!s&&(c[1][c[0]]=d)}A(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),A(n)}return r}var Ks=!!"".isWellFormed;import{execFileSync as yr}from"node:child_process";import{mkdirSync as Sr,readFileSync as _t,renameSync as xr,statSync as Ar,writeFileSync as $r}from"node:fs";import{join as bt}from"node:path";import{closeSync as tr,openSync as nr,readSync as rr,readdirSync as or,readFileSync as ir,statSync as gt}from"node:fs";import{homedir as sr}from"node:os";import{isAbsolute as ur,join as fe,resolve as lr}from"node:path";var ar=/^[A-Za-z0-9._+@%:,/-]+$/,cr=new Set(["7f454c46","feedface","feedfacf","cefaedfe","cffaedfe","cafebabe","bebafeca"]),fr=32,dr=4*1024*1024;function Ne(e){let t;try{t=nr(e,"r");let n=Buffer.alloc(4),r=rr(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&&tr(t)}}function Q(e,t=process.platform){try{let n=gt(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&&cr.has(r)}catch{return!1}}function pr(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(!ar.test(e))return!1;let o=r==="win32";if(e.includes("/"))return Q(lr(t??process.cwd(),e),r);if(!n)return!1;let i=o?pr(e):[e];for(let s of n.split(o?";":":"))if(!(!s||!ur(s))){for(let u of i)if(Q(fe(s,u),r))return!0}return!1}var mr=/^eval \$'([^\s'()=]+) \(\) /,gr=/^([^\s'"()=]+) \(\) \{$/,hr=/^alias -- ([^\s=]+)=(.*)$/,kr=/^# (?:Shell Options|Aliases|Shopt|Check for |Shadow )/,_r=/^export PATH=(.*)$/,br=/^(?:--colou?r(?:=\S+)?|-G)$/;function mt(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 wr(e,t){let n="";for(let r of e.split(`
|
|
14
|
-
`)){let o=
|
|
15
|
-
`,1)[0].slice(2).trim().split(/\s+/),o=r[0]??"";return o==="/usr/bin/env"?
|
|
16
|
-
`||u==="|"){s(u,1);continue}}r+=u,o+=1}return i(),n}function
|
|
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 m=0;m<d;m++,e.p++){let g=e.s.charCodeAt(e.p),h=g>=48&&g<=57?g-48:g>=65&&g<=70?g-65+10:g>=97&&g<=102?g-97+10:-1;h<0&&f.x("invalid non-hex character in unicode escape",e),c=c<<4|h}(c<0||c>1114111||c>=55296&&c<=57343)&&f.x("invalid unicode escape",e,a),s+=String.fromCodePoint(c),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 Qn=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i,X=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(Qn);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 w(e,t=10){return t===16?e>47&&e<58||e>64&&e<71||e>96&&e<103:e>47&&e<48+t}function Oe(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function ee(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?pt(e):dt(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?er(e,r,t):e.s.charCodeAt(e.p+2)===58?tr(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||Oe(i=e.s.charCodeAt(e.p),o))return e.bi===!0?0n:0;if(!r){if(i===120)return ve(e,t,16,o);if(i===98)return ve(e,t,2,o);if(i===111)return ve(e,t,8,o)}i===46?s=2:i===101||i===69?s=4:f.x("illegal leading zero",e,t)}else w(i)||f.x("invalid value",e,t);for(;++e.p<e.s.length&&(i=e.s.charCodeAt(e.p),!Oe(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)||(w(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):ft(e,l,10,t)}function ve(e,t,n,r){let o,i=1;for(;++e.p<e.s.length&&(o=e.s.charCodeAt(e.p),!Oe(o,r));)o===95?(i&1&&f.x("illegal underscore",e),i=3):w(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("_","")),ft(e,s,n,t)}function ft(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 er(e,t,n){let r=e.p++,o;if(!w(t)||!w(e.s.charCodeAt(e.p++))||!w(e.s.charCodeAt(e.p++))||!w(e.s.charCodeAt(e.p++)))return ce(e,e.p=r,t,0,n);if(e.p+=5,w(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,!w(e.s.charCodeAt(e.p+1))))&&t!==84&&t!==116){let s=e.s.slice(r,e.p);return Q(e,s,3,!1,r)}if(e.s.charCodeAt(e.p+=3)!==58&&f.x("invalid date-time: time part is malformed",e,r),e.s.charCodeAt(e.p+=3)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;w(e.s.charCodeAt(++e.p)););if(t=e.s.charCodeAt(e.p)){if(t===90||t===122){let s=e.s.slice(r,++e.p);return Q(e,s,1,o,r,"[+00:00]")}if(t===43||t===45){let s=e.s.slice(r,e.p+=6);return Q(e,s,1,o,r,!e.ld&&"["+e.s.slice(e.p-6,e.p)+"]")}}let i=e.s.slice(r,e.p);return Q(e,i,2,o,r)}function tr(e,t,n){let r=e.p;if(!w(t)||!w(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(;w(e.s.charCodeAt(++e.p)););let o=e.s.slice(r,e.p);return Q(e,o,4,!1,r)}function Q(e,t,n,r,o,i){if(e.ld){let s=new X(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 nr(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 $(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;nr(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 dt(e){let t=e.p++,n=Object.create(null),r=new Set,o;for(;e.p<e.s.length;){if($(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 m=i==="__proto__";if(e.uk&&(m||i==="constructor")){s=e.uk!==1&&f.x("document contains an unsafe property",e,l);break}!u&&m&&Object.defineProperty(s,i,{enumerable:!0,configurable:!0,writable:!0})}u&&f.x("trying to redefine an already defined value",e,l),$(e,!0,!0);let c=ee(e,125);if(s&&typeof(s[i]=c)=="object"&&r.add(c),$(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 pt(e){let t=e.p++,n=[],r;for(;e.p<e.s.length;){if($(e),(r=e.s.charCodeAt(e.p))===93)return e.p++,n;if(n.push(ee(e,93)),$(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 mt(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 gt(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 Re(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++,$(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=mt(n,c,r,o,a?2:1);d?(l=d[2],u=d[1]):(gt(n,d,i),s=!0)}else{i=n.p;let a=fe(n),c=mt(n,a,u,l,0);!c&&!s&>(n,c,i),$(n,!0,!0);let d=ee(n,void 0);c&&!s&&(c[1][c[0]]=d)}$(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),$(n)}return r}var Xs=!!"".isWellFormed;import{execFileSync as xr}from"node:child_process";import{mkdirSync as $r,readFileSync as wt,renameSync as Ar,statSync as Cr,writeFileSync as Er}from"node:fs";import{join as yt}from"node:path";import{closeSync as rr,openSync as or,readSync as ir,readdirSync as sr,readFileSync as ur,statSync as kt}from"node:fs";import{homedir as lr}from"node:os";import{isAbsolute as ar,join as de,resolve as cr}from"node:path";var fr=/^[A-Za-z0-9._+@%:,/-]+$/,dr=new Set(["7f454c46","feedface","feedfacf","cefaedfe","cffaedfe","cafebabe","bebafeca"]),pr=32,mr=4*1024*1024;function Ne(e){let t;try{t=or(e,"r");let n=Buffer.alloc(4),r=ir(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&&rr(t)}}function te(e,t=process.platform){try{let n=kt(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&&dr.has(r)}catch{return!1}}function gr(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 L(e,t,n,r=process.platform){if(!fr.test(e))return!1;let o=r==="win32";if(e.includes("/"))return te(cr(t??process.cwd(),e),r);if(!n)return!1;let i=o?gr(e):[e];for(let s of n.split(o?";":":"))if(!(!s||!ar(s))){for(let u of i)if(te(de(s,u),r))return!0}return!1}var hr=/^eval \$'([^\s'()=]+) \(\) /,kr=/^([^\s'"()=]+) \(\) \{$/,_r=/^alias -- ([^\s=]+)=(.*)$/,br=/^# (?:Shell Options|Aliases|Shopt|Check for |Shadow )/,wr=/^export PATH=(.*)$/,yr=/^(?:--colou?r(?:=\S+)?|-G)$/;function ht(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 Sr(e,t){let n="";for(let r of e.split(`
|
|
14
|
+
`)){let o=wr.exec(r);if(o&&n!=="# Functions"){let i=ht(o[1].trim());/[$`\\]/.test(i)||t.paths.push(i);continue}if(r.startsWith("# ")&&(n!=="# Functions"||br.test(r))){n=r;continue}if(n==="# Functions"){let i=hr.exec(r)??kr.exec(r);i&&t.functions.add(i[1])}else if(n==="# Aliases"){let i=_r.exec(r);i&&t.aliases.set(i[1],ht(i[2].trim()))}}}function Pe(e){return e?.code==="ENOENT"}function _t(e){let t={functions:new Set,aliases:new Map,paths:[],uncertain:!1},n=de(e||de(lr(),".claude"),"shell-snapshots"),r=[];try{for(let o of sr(n)){if(!o.startsWith("snapshot-")||!o.endsWith(".sh"))continue;let i=de(n,o);try{let s=kt(i);s.isFile()&&r.push({path:i,mtime:s.mtimeMs,size:s.size})}catch(s){Pe(s)||(t.uncertain=!0)}}}catch(o){return Pe(o)||(t.uncertain=!0),t}r=r.sort((o,i)=>i.mtime-o.mtime).slice(0,pr);for(let o of r)try{if(o.size>mr)throw new Error("snapshot too large");Sr(ur(o.path,"utf8"),t)}catch(i){Pe(i)||(t.uncertain=!0)}return t}function bt(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=>yr.test(o))}var Tr="exec-probe.json",vr=6e4;function Or(){return yt(x(),Tr)}function Rr(e){try{let t=Te(wt(e,"utf8"));if(t==null||typeof t!="object")return null;let n=t;return typeof n.key!="string"||typeof n.ok!="boolean"?null:{key:n.key,ok:n.ok,at:typeof n.at=="number"?n.at:0,skipped:typeof n.skipped=="number"&&n.skipped>=0?n.skipped:0}}catch{return null}}function Pr(e,t){try{$r(yt(e,".."),{recursive:!0,mode:448});let n=`${e}.${process.pid}.tmp`;Er(n,JSON.stringify(t),{mode:384}),Ar(n,e)}catch{}}function Nr(e){try{return xr(e,["--native-check"],{encoding:"utf8",timeout:2e3,maxBuffer:1024,stdio:["ignore","pipe","ignore"],windowsHide:!0}).startsWith("tokmizer-native ")}catch{return!1}}function Ir(e,t){try{let r=wt(e,"utf8").split(`
|
|
15
|
+
`,1)[0].slice(2).trim().split(/\s+/),o=r[0]??"";return o==="/usr/bin/env"?L(r[1]??"",void 0,t):te(o)}catch{return!1}}function Hr(e,t,n){try{let r=Cr(e);return[e,r.size,r.mtimeMs,r.ino,r.mode,t?n??"":""].join("|")}catch{return`${e}|missing`}}function Ie(e,t=process.platform,n=process.env.PATH,r=Or(),o=Date.now()){let i=t!=="win32"&&Ne(e)==="#!",s=Hr(e,i,n),u=Rr(r);if(u?.key===s&&(u.ok||o-u.at<vr))return u.ok;let l=te(e,t)&&(i?Ir(e,n):Nr(e));return Pr(r,{key:s,ok:l,at:o,skipped:(u?.skipped??0)+(l?0:1)}),l}var Mr=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"]),zr=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"]),St=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),xt="(?:dev|start|serve|watch|preview)",Ur=new RegExp(`^(?:\\S*/)?(?:bun\\s+(?:install|i|add|remove|rm|update|outdated|audit|test|build|pm|x)(?:\\s|$)|bun\\s+run\\s+(?!${xt}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|deno\\s+(?:test|lint|fmt|check|compile|install|info|doc|bench|outdated)(?:\\s|$)|deno\\s+task\\s+(?!${xt}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|python[0-9.]*\\s+-m\\s+(?:pytest|unittest|mypy|ruff|pylint|flake8|black|tox|nox)(?:\\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)`),Wr=/(?:^|\s)--watch(?:\s|=|$)/;function Jr(e){return Ur.test(e)&&!Wr.test(e)}var Br=/^((?:\S*\/)?(sh|bash|zsh|dash|ksh|fish)\s+(-[elux]*c[elux]*)\s+)(['"])/,Gr=/[()$]|(?:^|[;&|\n]\s*)(?:and|or|not|begin|end|if|else|switch|case|while|for|function|return)(?:\s|;|$)/,Lt=3;function jt(e){let t=Br.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&&Gr.test(u)?null:{script:u,start:o,end:i,quote:r}}var Zr=new Set(["cd","export","set","unset","source",".","true",":","pushd","popd"]);function Vr(e){return Fe(e).filter(n=>{if(n.kind!=="cmd"||n.unsafe)return!1;let r=Ft(n.text);return r!==""&&!Zr.has(r)&&!De.test(r)}).length>1}function Kr(e,t,n,r,o){if(n>=Lt)return null;let i=jt(e);if(!i)return null;let{script:s,start:u,end:l,quote:a}=i,c=[],d=Mt(s,t,n+1,r,b=>c.push(b));if(d===s||a==='"'&&/["$`]/.test(d))return null;let m=a==="'"?d.replace(/'/g,"'\\''"):d,g=`${e.slice(0,u)}${m}${e.slice(l)}`,h=Vr(s);if(o)for(let b of h?[e,...c]:c)o(b);return h?`${t} ${g}`:g}var $t=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,qr=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*[fF][a-zA-Z]*)(?:\s|=|$)/,Yr=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]),At=new Set(["npm","pnpm","yarn","bun"]),Ct=/^(?:dev|start|serve|preview|watch)(?::\S*)?$/,Xr=new Set(["--filter","-F","--dir","-C","--prefix","--workspace","-w","--cwd"]),Et=new Set(["npx","pnpx","bunx"]),Qr=new Set(["nodemon","top","htop","btop","watch"]),eo=new Set(["tsc","vitest","jest","webpack","rollup","esbuild","tsup","babel","sass","tailwindcss","mocha","swc","parcel","nest"]),to=/(?:^|\s)--watch(?:All)?(?:\s|=(?!false(?:\s|$))|$)/,Tt=/(?:^|\s)-w(?:\s|$)/;function no(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=U(t[0]??"");if(Et.has(n)||At.has(n)&&(t[1]==="exec"||t[1]==="dlx"))t=t.slice(Et.has(n)?1:2).filter((s,u,l)=>!(s.startsWith("-")&&l.slice(0,u).every(a=>a.startsWith("-")))),n=U(t[0]??"");else if(At.has(n)){let s=t.slice(1).filter((l,a,c)=>!l.startsWith("-")&&!Xr.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&&Ct.test(u)}let r=t.slice(1),o=r.join(" "),i=r.find(s=>!s.startsWith("-"));if(Qr.has(n)||to.test(o)||eo.has(n)&&Tt.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&&Ct.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")&&Tt.test(o)||/(?:^|\s)--watch-only(?:\s|=|$)/.test(o);default:return!1}}function ro(e,t){let n=U(t);return n==="tail"?qr.test(e):n==="journalctl"?$t.test(e):n==="stern"||Yr.has(n)&&/\blogs?\b/.test(e)&&$t.test(e)?!0:no(e.split(/\s+/))}var De=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,oo=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,io=/(?:^|[;&|\n({])\s*(?:[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)|function\s+[A-Za-z_])/;function U(e){let t=e.lastIndexOf("/");return t===-1?e:e.slice(t+1)}function Dt(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 He(e){let t=Dt(e);if(!t)return!0;for(let n=0;n<e.length;n++)if(t[n]&&e[n]===">")return!0;return!1}function Fe(e){let t=Dt(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.trimEnd(),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 Ft(e){return e.trim().split(/\s+/)[0]??""}function A(e,t=process.platform){try{let n=je(Ht(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(v(l))return Ie(l,t)?`'${l.replace(/\\/g,"/").replace(/'/g,"'\\''")}'`:null}let i=p(n,"..","bin","tkr-exec"),s=!r&&v(i);if(s&&!Ie(i,t))return null;if(!r&&process.env.TOKMIZER_STABLE_RUN!=="0"){let l=lt(p(n,"..","bin","tkr-exec.js"));if(l&&(s||v(p(n,"..","bin","tkr-exec.js"))))return`${o}'${l.replace(/'/g,"'\\''")}'`}if(s)return`${o}'${i.replace(/'/g,"'\\''")}'`;if(I()){let l=r?process.execPath.replace(/\\/g,"/"):process.execPath;return`${o}'${l.replace(/'/g,"'\\''")}' exec`}let u=p(n,"..","bin","tkr-exec.js");return v(u)?`${o}node '${u.replace(/'/g,"'\\''")}'`:null}catch{return null}}function so(e,t="tkr-exec",n=()=>!0,r){return Mt(e,t,0,n,r)}var uo=new Set(["{","for","while","until","if","case","select"]),lo=new Set(["}","done","fi","esac"]),ao=new Set(["then","do","else","elif","!","time","{","if","while","until"]);function co(e,t){let n=e[t+1];return He(e[t].text)||n?.kind==="sep"&&(n.text==="|"||n.text==="|&")}function fo(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(lo.has(i)){let s=n.pop();if(s!==void 0&&co(e,r))for(let u=s;u<=r;u++)t.add(u);continue}if(uo.has(i)&&n.push(r),!ao.has(i))break}}return t}function Mt(e,t,n,r,o){if(e.includes("<<")||io.test(e))return e;let i=Fe(e),s=fo(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=Ft(c),m=i[l+1],g=m?.kind==="sep"&&(m.text==="|"||m.text==="|&"),h=m?.kind==="sep"&&m.text==="&",b=!g&&!h&&!He(a.text)&&!a.text.includes("<(")&&!a.text.includes(">(")?Kr(c,t,n,r,o):null;if(b!==null){u.push(`${a.text.match(/^\s*/)?.[0]??""}${b}${a.text.slice(a.text.trimEnd().length)}`);continue}if(c===t||c.startsWith(t)&&/^\s/.test(c.slice(t.length))||Mr.has(d)||zr.has(d)||(St.has(d)||St.has(U(d)))&&!Jr(c)||De.test(d)||d.startsWith("(")||d.startsWith("#")||d.startsWith("<")||d.startsWith(">")||oo.test(c)||ro(c,d)||d.endsWith(")")||g||h||He(a.text)||a.text.includes("<(")||a.text.includes(">(")||d==="node"&&c.includes("tkr-exec.js")||!r(d,c)){u.push(a.text);continue}let V=a.text.match(/^\s*/)?.[0]??"",S=a.text.slice(a.text.trimEnd().length);o?.(c),u.push(`${V}${t} ${c}${S}`)}return u.join("")}var po=new Set(["command","workdir","timeout_ms","yield_time_ms","max_output_tokens","shell","login","tty","description"]),mo=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"]),go=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),ho={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"],ko={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"])},_o=new Set(["pytest","tsc","vitest","jest","eslint","mypy"]);function zt(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 Fe(e)){if(r.kind==="sep")continue;if(r.unsafe)return!1;let o=n<Lt?jt(r.text.trim()):null;if(o){if(!zt(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=>De.test(a)))return!1;let s=U(i[0]);if(s!==i[0])return!1;let u=ho[s];if(u&&i.slice(1).some(a=>u.test(a)))return!1;if((s==="git"?go.has(i[1]??""):mo.has(s))||t&&_o.has(s))continue;let l=t?ko[s]:void 0;if(!(l&&(l.has(i[1]??"")||i[1]==="run"&&l.has(`run ${i[2]??""}`))))return!1}return!0}function Ut(e,t,n=A(t),r=y,o=ge(),i=process.env.PATH,s=Me){if(!k(e)||e.tool_name!=="Bash"||t==="claude-code"&&So(s()))return null;let u=e.tool_input;if(!k(u)||u.run_in_background)return null;let l=u.command;if(typeof l!="string"||!l||t==="codex"&&Object.keys(u).some(V=>!po.has(V)))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",m=typeof e.permission_mode=="string"?e.permission_mode:void 0,g=t==="claude-code"?wo(l,c,i):null;if(g)return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",updatedInput:{...u,command:g}}});let h=Yt(l,{host:t,sessionId:d,cwd:c,claudeDirs:o,pathEnv:i,permissionMode:m},n,r);if(!h)return null;let b={...u,command:h.command};return JSON.stringify({hookSpecificOutput:t==="codex"?{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:b}:h.allowedBy?{hookEventName:"PreToolUse",permissionDecision:"allow",permissionDecisionReason:`Tokmizer: allowed by your rule ${h.allowedBy}`,updatedInput:b}:h.ask?{hookEventName:"PreToolUse",permissionDecision:"ask",permissionDecisionReason:"Tokmizer shortens this command's output; nothing else changes.",updatedInput:b}:{hookEventName:"PreToolUse",updatedInput:b}})}var bo=/^tkr\s+restore\s+([0-9a-f]{8,64}(?:\s+--lines\s+\d+:\d+)?|--list)\s*$/;function wo(e,t,n,r=p(je(Ht(import.meta.url)),"..","bin","tkr.js")){let o=bo.exec(e.trim());return!o||L("tkr",t,n)||!I()&&!v(r)?null:`${Ye(r).map(E).join(" ")} restore ${o[1].trim()}`}var yo=/(?:^|\s)--(?:disallowedTools|disallowed-tools|settings|setting-sources)(?:[=\s]|$)/;function Me(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=It("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 So(e){return e===null||yo.test(e)}function xo(e,t){if(!v(e))return"missing";try{let n=ne(e,"utf8").replace(/^\uFEFF/,"");return n.trim()===""?{}:JSON.parse(t?Wt(n):n)}catch{return"unreadable"}}function Wt(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 U(e){let t=[],n=jr(e);for(;;){t.push(n);let r=Nt(n);if(r===n)return t;n=r}}function yo(){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 So(){try{return Hr().username}catch{return""}}function xo(e){return e.error?e.error.code==="ETIMEDOUT":e.status!==1}var Ao=5*6e4,Et=new Map;function Ut(e,t){let n=Et.get(e);if(n&&Date.now()-n.at<Ao)return n.value;let r=["HKLM","HKCU"].some(o=>xo(Pt(e,["query",`${o}\\SOFTWARE\\Policies\\ClaudeCode`,"/v","Settings"],{cwd:t,stdio:"ignore",timeout:2e3,windowsHide:!0})));return Et.set(e,{at:Date.now(),value:r}),r}function $o(){let e=process.env.SystemRoot||"C:\\Windows";return Ut(Dr.join(e,"System32","reg.exe"),e)}var Tt="/mnt/c/Windows/System32/reg.exe";function Co(e){return!process.env.WSL_DISTRO_NAME&&!e("/proc/sys/fs/binfmt_misc/WSLInterop")?!1:e("/mnt/c/Program Files/ClaudeCode")?!0:e(Tt)&&Ut(Tt,"/mnt/c/Windows")}function Eo(e=process.platform,t=R,n=$o,r=So(),o=()=>Co(t)){if(e==="darwin"){let i="/Library/Managed Preferences";return t(p(i,"com.anthropic.claudecode.plist"))||r!==""&&t(p(i,r,"com.anthropic.claudecode.plist"))}return e==="win32"?n():e==="linux"&&o()}function ne(e,t,n,r){let o=[];for(let i of e){let s=wo(i,t);if(s!=="missing"&&(s==="unreadable"||!k(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?.trim()?se():void 0}}function To(e,t){let n=S=>[p(S,"settings.json"),p(S,"settings.local.json")],r=S=>n(p(S,".claude")),o=p(H(),".claude"),i=t.configDir||o;if(Eo())return"unreadable";let u=[[[...[...new Set([p(i,"remote-settings.json"),p(o,"remote-settings.json")])],...yo()],"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"]],l=[],a={managed:[],loaded:[],loadedLocal:[],project:[],extra:[]},c={managed:!1,loaded:!1,loadedLocal:!1,project:!1,extra:!1},d=!1,g="managed",m=(S,ye)=>{let v=S.permissions;if(g==="managed"&&(S.allowManagedPermissionRulesOnly===!0||k(v)&&v.allowManagedPermissionRulesOnly===!0)&&(d=!0),v===void 0)return!0;if(!k(v))return!1;for(let Je of["deny","ask","allow"]){let Be=te(v[Je]);if(!Be)return!1;for(let Ge of Be){let j=/^\s*Bash\s*(?:\(([\s\S]*)\))?\s*$/.exec(Ge);if(j)if(Je!=="allow")ye.push(L((j[1]??"*").replace(/:\*$/," *")));else if(j[1]===void 0||j[1].trim()==="*")c[g]=!0;else{l.push(L(j[1].replace(/:\*$/," *")));let Ze=Vo(j[1]);Ze&&a[g].push({rule:Ge.trim(),matches:Ze})}}}return!0},h=[];for(let[S,ye]of u){g=ye;let v=ne(S,!1,m,!0);if(v==="unreadable")return"unreadable";h.push(...v.matchers)}let y=c.managed||(c.loaded||c.loadedLocal)&&!d,we=[...a.managed,...d?[]:a.loaded];return{matchers:[...h,...y?[]:l],complete:!0,allow:l,allowsEverything:y,guards:h,trustedAllow:we}}function vo(e){let t=[p(H(),".cursor","cli-config.json"),...U(e).map(n=>p(n,".cursor","cli.json"))];return ne(t,!0,(n,r)=>{let o=n.permissions;if(o===void 0)return!0;if(!k(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(L(a===-1?`${l} *`:`${l.slice(0,a)} ${l.slice(a+1)}`))}return!0},!1)}function Oo(){return process.platform==="darwin"?"/Library/Application Support/GeminiCli":process.platform==="win32"?"C:\\ProgramData\\gemini-cli":"/etc/gemini-cli"}var Wt=/^\s*(?:run_shell_command|ShellTool)\s*(?:\(([\s\S]*)\))?\s*$/;function Ro(e,t){let n=e.tools;if(n!==void 0&&!k(n))return!1;let r=[te(e.excludeTools),te(k(n)?n.exclude:void 0)];for(let o of r){if(!o)return!1;for(let i of o){let s=Wt.exec(i);s&&t.push(L(s[1]===void 0?"*":`${s[1]}*`))}}return!0}function vt(e){try{return JSON.parse(e)}catch{return null}}function Po(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]??vt(`"${r[1]}"`);if(o===null)return null;n.push(o)}return n}if(t.startsWith('"')){let n=/^"((?:\\.|[^"\\])*)"/.exec(t);return n?vt(`"${n[1]}"`):null}if(t.startsWith("'")){let n=/^'([^']*)'/.exec(t);return n?n[1]:null}return t.replace(/\s*#.*$/,"")}function No(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=Po(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==="*"||Wt.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}))||ge(a,c))}}return!0}function Ot(e){try{return pe(e).filter(t=>t.endsWith(".toml")).map(t=>p(e,t))}catch{return[]}}function Io(e){let t=Oo(),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=ne(n,!0,Ro,!1);if(r==="unreadable")return r;for(let o of[...Ot(p(H(),".gemini","policies")),...Ot(p(t,"policies"))]){let i;try{i=ee(o,"utf8")}catch{return"unreadable"}if(!No(i,r.matchers))return"unreadable"}return r}function Le(e,t){if(e===void 0)return!0;if(typeof e=="string")return e!=="allow"&&t.push(()=>!0),!0;if(!k(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(!k(r))return!1;for(let[o,i]of Object.entries(r))i!=="allow"&&t.push(L(o.replace(/\?/g,"*")))}}return!0}function Rt(e,t){if(e.permissions!==void 0||!Le(e.permission,t))return!1;for(let n of["agent","agents","mode"]){let r=e[n];if(r!==void 0){if(!k(r))return!1;for(let o of Object.values(r))if(k(o)&&(o.permissions!==void 0||!Le(o.permission,t)))return!1}}return!0}function Ho(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 Lo(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(Ho(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=ne(i,!0,Rt,!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(zt(u))}catch{return"unreadable"}if(!(u===process.env.OPENCODE_PERMISSION?Le(l,s.matchers):k(l)&&Rt(l,s.matchers)))return"unreadable"}return s}function jo(){return ne([p(H(),".gemini","antigravity-cli","settings.json")],!0,(e,t)=>{let n=e.permissions;if(n===void 0)return!0;if(!k(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(L(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 Do(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 Jt(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=Jt(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 Bt(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(Me).join("|")})`)}let n=new RegExp(`^${t.join(" ")}(?= |$)`);return r=>ge(n,r)}function Fo(e,t){let n=Do(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]=Jt(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=Bt(i.pattern);if(!u)return!1;s!=="allow"&&t.push(u)}return!0}function Mo(e){if(!R(e))return[];try{return pe(e).filter(t=>t.endsWith(".rules")).sort().map(t=>p(e,t))}catch{return"unreadable"}}function zo(){return process.platform==="win32"?p(process.env.ProgramData||"C:\\ProgramData","OpenAI","Codex","requirements.toml"):"/etc/codex/requirements.toml"}function Uo(e){if(!(!k(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 Wo(e,t){let n;try{n=Re(e)}catch{return!1}if(n.rules===void 0)return!0;if(!k(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(!k(o)||!Array.isArray(o.pattern)||o.decision!=="prompt"&&o.decision!=="forbidden")return!1;let i=o.pattern.map(Uo);if(i.some(u=>u===void 0))return!1;let s=Bt(i);if(!s)return!1;t.push(s)}return!0}function Jo(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=ee(zo(),"utf8")}catch(i){let s=i.code;if(s!=="ENOENT"&&s!=="ENOTDIR")return"unreadable"}if(o!==null&&!Wo(o,r))return"unreadable";for(let i of[...new Set(n)]){let s=Mo(i);if(s==="unreadable")return"unreadable";for(let u of s){let l;try{l=ee(u,"utf8")}catch{return"unreadable"}if(!Fo(l,r))return"unreadable"}}return{matchers:r,complete:!1}}function k(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function Me(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Bo(e){let t=e.trim().replace(/\s+/g," "),n=t.endsWith(" *")&&t.length>2,r=(n?t.slice(0,-2):t).split("*").map(Me).join("[\\s\\S]*");return new RegExp(`^${r}${n?"(?: [\\s\\S]*)?":""}(?= |$)`)}var Go=512;function Zo(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 Zo(t)){if(n.length>Go)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=Bo(e);return n=>ge(t,n)}function Vo(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(`^${Me(r)}${n?"(?: [\\s\\S]*)?":""}$`);return i=>o.test(i)}var Ko={"claude-code":To,cursor:vo,"gemini-cli":Io,opencode:Lo,antigravity:jo,codex:Jo},qo=new Set(["codex"]),Gt=/(?:^|[\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 Yo(e,t,n){let r=Ko[e];return r?r(t??process.cwd(),n):{matchers:[],complete:!1}}function Xo(e,t,n){return e==="unreadable"||Gt.test(t.replace(/['"\\]/g,""))||e.matchers.some(r=>r(t))?!1:e.complete||Ft(t,!qo.has(n))}var Zt=new Set(["default","acceptEdits","dontAsk"]);function Vt(e,t){return t.host!=="claude-code"||t.permissionMode==="bypassPermissions"?!0:e!=="unreadable"&&e.allowsEverything===!0&&Zt.has(t.permissionMode??"")}var Qo=/(?:^|[\s/])git(?:\.exe|\.real|-[a-z][\w-]*)?(?=\s|$)/;function ei(e){if(!e)return!1;try{for(let t of U(e)){let n=p(t,".git");if(R(n))return Ir(n).isFile()}}catch{return!0}return!1}function ti(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&&Qo.test(s)&&(o??=ei(e.cwd))||(r??=ht(t.configDir),!M(i,e.cwd,n)&&!r.paths.some(u=>M(i,e.cwd,u)))?!1:i.includes("/")||!kt(i,r)}var ni=/^[^\s;&|<>()$`\\{}*?[\]~#!]+(?: [^\s;&|<>()$`\\{}*?[\]~#!]+)*$/;function ri(e,t,n){return n.host!=="claude-code"||e==="unreadable"||Vt(e,n)||!Zt.has(n.permissionMode??"")||!ni.test(t)||Gt.test(t.replace(/['"]/g,""))||(e.guards??[]).some(r=>r(t))?null:(e.trustedAllow??[]).find(r=>r.matches(t))?.rule??null}var oi=65536,ii=/^(?:[A-Za-z_][A-Za-z0-9_]*=\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 si(e,t){return t.host==="claude-code"&&t.permissionMode==="default"&&ii.test(e.trim())}function Kt(e,t,n,r){if(!n||e.length>oi||/["\\$`;&|<>(){}]|'\\''/.test(n))return null;let o=t.claudeDirs??me(),i=Yo(t.host,t.cwd,o),s=ri(i,e,t),u=s||Xo(i,e,t.host)?io(e,n,ti(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}:Vt(i,t)?{command:u}:i!=="unreadable"&&si(e,t)&&!(i.allow??[]).some(l=>l(e))&&!(i.trustedAllow??[]).some(l=>l.matches(e))?{command:u,ask:!0}:null}function P(e,t,n,r){let o=Kt(e,t,n,r);return o&&!o.ask?o.command:null}function W(e,t,n="unknown",r=$(t),o=w){return e?P(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 re(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function ui(e){return _(e,"prompt_id")||_(e,"scratchpad_dir")?!0:re(e.effort)}function li(e){return _(e,"tool_use_id")?.startsWith("toolu_")===!0||/^claude/i.test(_(e,"model")??"")}var ai=new Set(["BeforeTool","AfterTool","BeforeAgent","AfterAgent","BeforeModel","AfterModel","BeforeToolSelection"]),ci=new Set(["preToolUse","postToolUse","beforeShellExecution","afterShellExecution","beforeSubmitPrompt","sessionStart","sessionEnd","stop"]),fi=new Set(["pre_tool","post_tool"]),di=new Set(["before_tool_call","after_tool_call"]),pi=new Set(["runTerminalCommand","run_in_terminal"]),mi=[["codex",e=>_(e,"turn_id")!==null],["claude-code",ui],["cursor",e=>_(e,"cursor_version")!==null||_(e,"generation_id")!==null||_(e,"conversation_id")!==null||Array.isArray(e.workspace_roots)||ci.has(_(e,"hook_event_name")??"")],["gemini-cli",e=>ai.has(_(e,"hook_event_name")??"")],["qwen-code",e=>e.hook_event_name==="PreToolUse"&&e.tool_name==="run_shell_command"],["vibe",e=>fi.has(_(e,"hook_event_name")??"")],["antigravity",e=>re(e.toolCall)],["copilot",e=>_(e,"toolName")!==null&&"toolArgs"in e||pi.has(_(e,"tool_name")??"")],["grok",e=>e.toolName==="run_terminal_command"||e.tool_name==="run_terminal_command"||re(e.toolInput)&&!("toolArgs"in e)],["droid",e=>e.tool_name==="Execute"],["trae",e=>e.tool_name==="RunCommand"],["crush",e=>e.hook_event_name===void 0&&_(e,"event")!==null&&!di.has(_(e,"event"))]],gi=new Set(["codex","antigravity"]);function hi(e){return re(e)?mi.filter(([,t])=>t(e)).map(([t])=>t):[]}function qt(e,t){if(!re(e))return null;let n=hi(e);return n.length>1?null:n.length===1?n[0]:li(e)&&gi.has(t)?"claude-code":t==="codex"?null:t}var ze=JSON.stringify({permission:"allow"});function Yt(e,t=$("cursor"),n=w){if(e.tool_name!=="Shell")return ze;let r=e.tool_input??{},o=r.command;if(typeof o!="string"||!o)return ze;let i=typeof r.working_directory=="string"?r.working_directory:void 0,s=P(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}}):ze}var he="{}";function Xt(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=P(o,{host:"gemini-cli",sessionId:e.session_id??"unknown",cwd:i},C()?null:t,n);return s?JSON.stringify({hookSpecificOutput:{tool_input:{command:s}}}):he}var T="{}",ki=new Set(["runTerminalCommand","run_in_terminal","Bash","bash"]),_i=["run_in_background","is_background","isBackground"];function ke(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function bi(e){let t=e.session_id??e.sessionId;return typeof t=="string"&&t?t:"unknown"}function wi(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)||_i.some(s=>t[s]===!0))return null;let i=t.command;return typeof i!="string"||!i?null:P(i,{host:e,sessionId:bi(n),cwd:wi(n,t)},C()?null:r,o)}function B(e,t){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",updatedInput:{...e,command:t}}})}function yi(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 Si(e,t,n){if(typeof e.tool_name=="string"){if(!ki.has(e.tool_name))return T;let i=e.tool_input,s=_e("copilot",i,e,t,n);return s?B(i,s):T}if(e.toolName!=="bash")return T;let r=yi(e.toolArgs),o=_e("copilot",r,e,t,n);return o?JSON.stringify({modifiedArgs:{...r,command:o}}):T}function J(e,t,n){return(r,o,i)=>{if(r.tool_name!==t)return T;let s=r.tool_input,u=_e(e,s,r,o,i);return u?n(s,u):T}}var xi=new Set(["run_terminal_command","Bash","bash"]);function Ai(e,t,n){let r=e.toolName??e.tool_name;if(typeof r!="string"||!xi.has(r))return T;let o=e.toolInput??e.tool_input,i=_e("grok",o,e,t,n);return i?B(o,i):T}var $i={copilot:Si,droid:J("droid","Execute",B),trae:J("trae","RunCommand",B),"qwen-code":J("qwen-code","run_shell_command",B),crush:J("crush","bash",(e,t)=>JSON.stringify({updated_input:{command:t}})),junie:J("junie","Bash",(e,t)=>JSON.stringify({updatedInput:{...e,command:t}})),zcode:J("zcode","Bash",B),grok:Ai};function Qt(e,t,n=$(e),r=w){return ke(t)?$i[e](t,n,r):T}function G(e){return C()?null:$(e)}function Ci(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"?"":Mt(t,e,G(e),r,n.claudeDirs??me(),n.pathEnv??process.env.PATH,n.launchArgs??Fe)??"";case"cursor":return Yt(t,G(e),r);case"gemini-cli":return Xt(t,G(e),r);case"vibe":return Ue(t,(o,i)=>W(o,"vibe",i,G(e),r));case"antigravity":return We(t,(o,i)=>W(o,"antigravity",i,G(e),r));default:return Qt(e,t,G(e),r)}}function oe(e,t,n={}){let r=qt(e,t);return r?Ci(r,e,n):n.fallback??""}var Ei=new Set(["bash","file_system.bash"]),be=JSON.stringify({decision:"allow"});function Ue(e,t=(n,r)=>W(n,"vibe",r)){if(!I(e)||e.hook_event_name!=="pre_tool"||typeof e.tool_name!="string"||!Ei.has(e.tool_name))return"";let n=e.tool_input;if(!I(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 We(e,t=(n,r)=>W(n,"antigravity",r)){if(!I(e)||!I(e.toolCall)||e.toolCall.name!=="run_command")return be;let n=e.toolCall.args;if(!I(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 en={vibe:{build:e=>Ue(e),fallback:""},antigravity:{build:e=>We(e),fallback:be}};function tn(e){return en[e??""]?.fallback??""}function Ti(e,t){let n=en[e??""];if(!n)return"";let r;try{r=JSON.parse(t.replace(/^/,""))}catch{return n.fallback}return I(r)?oe(r,e,{fallback:n.fallback}):n.build(r)}async function nn(e){process.stdout.write(Ti(e,await Z()))}nn(process.argv[2]).catch(e=>{process.stderr.write(`tkr-agent-hook: ${e.message}
|
|
19
|
-
`),process.stdout.write(
|
|
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 W(e){let t=[],n=Dr(e);for(;;){t.push(n);let r=je(n);if(r===n)return t;n=r}}function $o(){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 Ao(){try{return jr().username}catch{return""}}function Co(e){return e.error?e.error.code==="ETIMEDOUT":e.status!==1}var Eo=5*6e4,vt=new Map;function Jt(e,t){let n=vt.get(e);if(n&&Date.now()-n.at<Eo)return n.value;let r=["HKLM","HKCU"].some(o=>Co(It(e,["query",`${o}\\SOFTWARE\\Policies\\ClaudeCode`,"/v","Settings"],{cwd:t,stdio:"ignore",timeout:2e3,windowsHide:!0})));return vt.set(e,{at:Date.now(),value:r}),r}function To(){let e=process.env.SystemRoot||"C:\\Windows";return Jt(Fr.join(e,"System32","reg.exe"),e)}var Ot="/mnt/c/Windows/System32/reg.exe";function vo(e){return!process.env.WSL_DISTRO_NAME&&!e("/proc/sys/fs/binfmt_misc/WSLInterop")?!1:e("/mnt/c/Program Files/ClaudeCode")?!0:e(Ot)&&Jt(Ot,"/mnt/c/Windows")}function Oo(e=process.platform,t=v,n=To,r=Ao(),o=()=>vo(t)){if(e==="darwin"){let i="/Library/Managed Preferences";return t(p(i,"com.anthropic.claudecode.plist"))||r!==""&&t(p(i,r,"com.anthropic.claudecode.plist"))}return e==="win32"?n():e==="linux"&&o()}function oe(e,t,n,r){let o=[];for(let i of e){let s=xo(i,t);if(s!=="missing"&&(s==="unreadable"||!k(s)||!n(s,o)))return"unreadable"}return{matchers:o,complete:r}}function re(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 Ro(e,t){let n=S=>[p(S,"settings.json"),p(S,"settings.local.json")],r=S=>n(p(S,".claude")),o=p(j(),".claude"),i=t.configDir||o;if(Oo())return"unreadable";let u=[[[...[...new Set([p(i,"remote-settings.json"),p(o,"remote-settings.json")])],...$o()],"managed"],[[p(i,"settings.json")],"loaded"],[[p(i,"settings.local.json")],"loadedLocal"],[t.configDir?n(o):[],"extra"],[t.projectDir?r(t.projectDir):[],"project"],[W(e).flatMap(r),"extra"]],l=[],a={managed:[],loaded:[],loadedLocal:[],project:[],extra:[]},c={managed:!1,loaded:!1,loadedLocal:!1,project:!1,extra:!1},d=!1,m="managed",g=(S,ye)=>{let R=S.permissions;if(m==="managed"&&(S.allowManagedPermissionRulesOnly===!0||k(R)&&R.allowManagedPermissionRulesOnly===!0)&&(d=!0),R===void 0)return!0;if(!k(R))return!1;for(let Be of["deny","ask","allow"]){let Ge=re(R[Be]);if(!Ge)return!1;for(let Ze of Ge){let F=/^\s*Bash\s*(?:\(([\s\S]*)\))?\s*$/.exec(Ze);if(F)if(Be!=="allow")ye.push(D((F[1]??"*").replace(/:\*$/," *")));else if(F[1]===void 0||F[1].trim()==="*")c[m]=!0;else{l.push(D(F[1].replace(/:\*$/," *")));let Ve=Yo(F[1]);Ve&&a[m].push({rule:Ze.trim(),matches:Ve})}}}return!0},h=[];for(let[S,ye]of u){m=ye;let R=oe(S,!1,g,!0);if(R==="unreadable")return"unreadable";h.push(...R.matchers)}let b=c.managed||(c.loaded||c.loadedLocal)&&!d,V=[...a.managed,...d?[]:a.loaded];return{matchers:[...h,...b?[]:l],complete:!0,allow:l,allowsEverything:b,guards:h,trustedAllow:V}}function Po(e){let t=[p(j(),".cursor","cli-config.json"),...W(e).map(n=>p(n,".cursor","cli.json"))];return oe(t,!0,(n,r)=>{let o=n.permissions;if(o===void 0)return!0;if(!k(o))return!1;let i=re(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(D(a===-1?`${l} *`:`${l.slice(0,a)} ${l.slice(a+1)}`))}return!0},!1)}function No(){return process.platform==="darwin"?"/Library/Application Support/GeminiCli":process.platform==="win32"?"C:\\ProgramData\\gemini-cli":"/etc/gemini-cli"}var Bt=/^\s*(?:run_shell_command|ShellTool)\s*(?:\(([\s\S]*)\))?\s*$/;function Io(e,t){let n=e.tools;if(n!==void 0&&!k(n))return!1;let r=[re(e.excludeTools),re(k(n)?n.exclude:void 0)];for(let o of r){if(!o)return!1;for(let i of o){let s=Bt.exec(i);s&&t.push(D(s[1]===void 0?"*":`${s[1]}*`))}}return!0}function Rt(e){try{return JSON.parse(e)}catch{return null}}function Ho(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]??Rt(`"${r[1]}"`);if(o===null)return null;n.push(o)}return n}if(t.startsWith('"')){let n=/^"((?:\\.|[^"\\])*)"/.exec(t);return n?Rt(`"${n[1]}"`):null}if(t.startsWith("'")){let n=/^'([^']*)'/.exec(t);return n?n[1]:null}return t.replace(/\s*#.*$/,"")}function Lo(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=Ho(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==="*"||Bt.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(D(`${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 Pt(e){try{return me(e).filter(t=>t.endsWith(".toml")).map(t=>p(e,t))}catch{return[]}}function jo(e){let t=No(),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(j(),".gemini","settings.json"),...W(e).map(o=>p(o,".gemini","settings.json"))].filter(o=>!!o),r=oe(n,!0,Io,!1);if(r==="unreadable")return r;for(let o of[...Pt(p(j(),".gemini","policies")),...Pt(p(t,"policies"))]){let i;try{i=ne(o,"utf8")}catch{return"unreadable"}if(!Lo(i,r.matchers))return"unreadable"}return r}function Le(e,t){if(e===void 0)return!0;if(typeof e=="string")return e!=="allow"&&t.push(()=>!0),!0;if(!k(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(!k(r))return!1;for(let[o,i]of Object.entries(r))i!=="allow"&&t.push(D(o.replace(/\?/g,"*")))}}return!0}function Nt(e,t){if(e.permissions!==void 0||!Le(e.permission,t))return!1;for(let n of["agent","agents","mode"]){let r=e[n];if(r!==void 0){if(!k(r))return!1;for(let o of Object.values(r))if(k(o)&&(o.permissions!==void 0||!Le(o.permission,t)))return!1}}return!0}function Do(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(ne(p(t,n,o),"utf8")))return!0}catch{return!0}}return!1}function Fo(e){let t=p(process.env.XDG_CONFIG_HOME||p(j(),".config"),"opencode"),n=W(e),r=[t,...n.map(u=>p(u,".opencode"))];if(Do(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=oe(i,!0,Nt,!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(Wt(u))}catch{return"unreadable"}if(!(u===process.env.OPENCODE_PERMISSION?Le(l,s.matchers):k(l)&&Nt(l,s.matchers)))return"unreadable"}return s}function Mo(){return oe([p(j(),".gemini","antigravity-cli","settings.json")],!0,(e,t)=>{let n=e.permissions;if(n===void 0)return!0;if(!k(n))return!1;for(let r of["deny","ask"]){let o=re(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(D(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 zo(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 Gt(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=Gt(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 Zt(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(ze).join("|")})`)}let n=new RegExp(`^${t.join(" ")}(?= |$)`);return r=>he(n,r)}function Uo(e,t){let n=zo(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]=Gt(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=Zt(i.pattern);if(!u)return!1;s!=="allow"&&t.push(u)}return!0}function Wo(e){if(!v(e))return[];try{return me(e).filter(t=>t.endsWith(".rules")).sort().map(t=>p(e,t))}catch{return"unreadable"}}function Jo(){return process.platform==="win32"?p(process.env.ProgramData||"C:\\ProgramData","OpenAI","Codex","requirements.toml"):"/etc/codex/requirements.toml"}function Bo(e){if(!(!k(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 Go(e,t){let n;try{n=Re(e)}catch{return!1}if(n.rules===void 0)return!0;if(!k(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(!k(o)||!Array.isArray(o.pattern)||o.decision!=="prompt"&&o.decision!=="forbidden")return!1;let i=o.pattern.map(Bo);if(i.some(u=>u===void 0))return!1;let s=Zt(i);if(!s)return!1;t.push(s)}return!0}function Zo(e){let t=process.env.CODEX_HOME||p(j(),".codex"),n=[p(t,"rules"),...W(e).map(i=>p(i,".codex","rules"))],r=[],o=null;try{o=ne(Jo(),"utf8")}catch(i){let s=i.code;if(s!=="ENOENT"&&s!=="ENOTDIR")return"unreadable"}if(o!==null&&!Go(o,r))return"unreadable";for(let i of[...new Set(n)]){let s=Wo(i);if(s==="unreadable")return"unreadable";for(let u of s){let l;try{l=ne(u,"utf8")}catch{return"unreadable"}if(!Uo(l,r))return"unreadable"}}return{matchers:r,complete:!1}}function k(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function ze(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Vo(e){let t=e.trim().replace(/\s+/g," "),n=t.endsWith(" *")&&t.length>2,r=(n?t.slice(0,-2):t).split("*").map(ze).join("[\\s\\S]*");return new RegExp(`^${r}${n?"(?: [\\s\\S]*)?":""}(?= |$)`)}var Ko=512;function qo(e){let t=e.replace(/['"\\]/g,"").split(/[\s;&|(){}<>`$]+/).filter(Boolean);return[t,t.map(U)]}function he(e,t){if(e.test(t)||e.test(t.trim().replace(/\s+/g," ")))return!0;for(let n of qo(t)){if(n.length>Ko)return!0;for(let r=0;r<n.length;r++)if(e.test(n.slice(r).join(" ")))return!0}return!1}function D(e){let t=Vo(e);return n=>he(t,n)}function Yo(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(`^${ze(r)}${n?"(?: [\\s\\S]*)?":""}$`);return i=>o.test(i)}var Xo={"claude-code":Ro,cursor:Po,"gemini-cli":jo,opencode:Fo,antigravity:Mo,codex:Zo},Qo=new Set(["codex"]),Vt=/(?:^|[\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 ei(e,t,n){let r=Xo[e];return r?r(t??process.cwd(),n):{matchers:[],complete:!1}}function ti(e,t,n){return e==="unreadable"||Vt.test(t.replace(/['"\\]/g,""))||e.matchers.some(r=>r(t))?!1:e.complete||zt(t,!Qo.has(n))}var Kt=new Set(["default","acceptEdits","dontAsk"]);function qt(e,t){return t.host!=="claude-code"||t.permissionMode==="bypassPermissions"?!0:e!=="unreadable"&&e.allowsEverything===!0&&Kt.has(t.permissionMode??"")}var ni=/(?:^|[\s/])git(?:\.exe|\.real|-[a-z][\w-]*)?(?=\s|$)/;function ri(e){if(!e)return!1;try{for(let t of W(e)){let n=p(t,".git");if(v(n))return Lr(n).isFile()}}catch{return!0}return!1}function oi(e,t){let n="pathEnv"in e?e.pathEnv:process.env.PATH,r,o;return(i,s)=>e.host!=="claude-code"?L(i,e.cwd,n):s!==void 0&&ni.test(s)&&(o??=ri(e.cwd))||(r??=_t(t.configDir),!L(i,e.cwd,n)&&!r.paths.some(u=>L(i,e.cwd,u)))?!1:i.includes("/")||!bt(i,r)}var ii=/^[^\s;&|<>()$`\\{}*?[\]~#!]+(?: [^\s;&|<>()$`\\{}*?[\]~#!]+)*$/;function si(e,t,n){return n.host!=="claude-code"||e==="unreadable"||qt(e,n)||!Kt.has(n.permissionMode??"")||!ii.test(t)||Vt.test(t.replace(/['"]/g,""))||(e.guards??[]).some(r=>r(t))?null:(e.trustedAllow??[]).find(r=>r.matches(t))?.rule??null}var ui=65536,li=/^(?:[A-Za-z_][A-Za-z0-9_]*=\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 ai(e,t){return t.host==="claude-code"&&t.permissionMode==="default"&&li.test(e.trim())}function Yt(e,t,n,r){if(!n||e.length>ui||/["\\$`;&|<>(){}]|'\\''/.test(n))return null;let o=t.claudeDirs??ge(),i=ei(t.host,t.cwd,o),s=si(i,e,t),u=s||ti(i,e,t.host)?so(e,n,oi(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}:qt(i,t)?{command:u}:i!=="unreadable"&&ai(e,t)&&!(i.allow??[]).some(l=>l(e))&&!(i.trustedAllow??[]).some(l=>l.matches(e))?{command:u,ask:!0}:null}function N(e,t,n,r){let o=Yt(e,t,n,r);return o&&!o.ask?o.command:null}function J(e,t,n="unknown",r=A(t),o=y){return e?N(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 ie(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function ci(e){return _(e,"prompt_id")||_(e,"scratchpad_dir")?!0:ie(e.effort)}function fi(e){return _(e,"tool_use_id")?.startsWith("toolu_")===!0||/^claude/i.test(_(e,"model")??"")}var di=new Set(["BeforeTool","AfterTool","BeforeAgent","AfterAgent","BeforeModel","AfterModel","BeforeToolSelection"]),pi=new Set(["preToolUse","postToolUse","beforeShellExecution","afterShellExecution","beforeSubmitPrompt","sessionStart","sessionEnd","stop"]),mi=new Set(["pre_tool","post_tool"]),gi=new Set(["before_tool_call","after_tool_call"]),hi=new Set(["runTerminalCommand","run_in_terminal"]),ki=[["codex",e=>_(e,"turn_id")!==null],["claude-code",ci],["cursor",e=>_(e,"cursor_version")!==null||_(e,"generation_id")!==null||_(e,"conversation_id")!==null||Array.isArray(e.workspace_roots)||pi.has(_(e,"hook_event_name")??"")],["gemini-cli",e=>di.has(_(e,"hook_event_name")??"")],["qwen-code",e=>e.hook_event_name==="PreToolUse"&&e.tool_name==="run_shell_command"],["vibe",e=>mi.has(_(e,"hook_event_name")??"")],["antigravity",e=>ie(e.toolCall)],["copilot",e=>_(e,"toolName")!==null&&"toolArgs"in e||hi.has(_(e,"tool_name")??"")],["grok",e=>e.toolName==="run_terminal_command"||e.tool_name==="run_terminal_command"||ie(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&&!gi.has(_(e,"event"))]],_i=new Set(["codex","antigravity"]);function bi(e){return ie(e)?ki.filter(([,t])=>t(e)).map(([t])=>t):[]}function Xt(e,t){if(!ie(e))return null;let n=bi(e);return n.length>1?null:n.length===1?n[0]:fi(e)&&_i.has(t)?"claude-code":t==="codex"?null:t}var Ue=JSON.stringify({permission:"allow"});function Qt(e,t=A("cursor"),n=y){if(e.tool_name!=="Shell")return Ue;let r=e.tool_input??{},o=r.command;if(typeof o!="string"||!o)return Ue;let i=typeof r.working_directory=="string"?r.working_directory:void 0,s=N(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}}):Ue}var ke="{}";function en(e,t=A("gemini-cli"),n=y){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=N(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 O="{}",wi=new Set(["runTerminalCommand","run_in_terminal","Bash","bash"]),yi=["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 xi(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)||yi.some(s=>t[s]===!0))return null;let i=t.command;return typeof i!="string"||!i?null:N(i,{host:e,sessionId:Si(n),cwd:xi(n,t)},C()?null:r,o)}function G(e,t){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",updatedInput:{...e,command:t}}})}function $i(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(!wi.has(e.tool_name))return O;let i=e.tool_input,s=be("copilot",i,e,t,n);return s?G(i,s):O}if(e.toolName!=="bash")return O;let r=$i(e.toolArgs),o=be("copilot",r,e,t,n);return o?JSON.stringify({modifiedArgs:{...r,command:o}}):O}function B(e,t,n){return(r,o,i)=>{if(r.tool_name!==t)return O;let s=r.tool_input,u=be(e,s,r,o,i);return u?n(s,u):O}}var Ci=new Set(["run_terminal_command","Bash","bash"]);function Ei(e,t,n){let r=e.toolName??e.tool_name;if(typeof r!="string"||!Ci.has(r))return O;let o=e.toolInput??e.tool_input,i=be("grok",o,e,t,n);return i?G(o,i):O}var Ti={copilot:Ai,droid:B("droid","Execute",G),trae:B("trae","RunCommand",G),"qwen-code":B("qwen-code","run_shell_command",G),crush:B("crush","bash",(e,t)=>JSON.stringify({updated_input:{command:t}})),junie:B("junie","Bash",(e,t)=>JSON.stringify({updatedInput:{...e,command:t}})),zcode:B("zcode","Bash",G),grok:Ei};function tn(e,t,n=A(e),r=y){return _e(t)?Ti[e](t,n,r):O}function Z(e){return C()?null:A(e)}function vi(e,t,n={}){let r=n.recordUsage??y;switch(e){case"claude-code":case"codex":return t.hook_event_name!==void 0&&t.hook_event_name!=="PreToolUse"?"":Ut(t,e,Z(e),r,n.claudeDirs??ge(),n.pathEnv??process.env.PATH,n.launchArgs??Me)??"";case"cursor":return Qt(t,Z(e),r);case"gemini-cli":return en(t,Z(e),r);case"vibe":return We(t,(o,i)=>J(o,"vibe",i,Z(e),r));case"antigravity":return Je(t,(o,i)=>J(o,"antigravity",i,Z(e),r));default:return tn(e,t,Z(e),r)}}function se(e,t,n={}){let r=Xt(e,t);return r?vi(r,e,n):n.fallback??""}var Oi=new Set(["bash","file_system.bash"]),we=JSON.stringify({decision:"allow"});function We(e,t=(n,r)=>J(n,"vibe",r)){if(!H(e)||e.hook_event_name!=="pre_tool"||typeof e.tool_name!="string"||!Oi.has(e.tool_name))return"";let n=e.tool_input;if(!H(n)||typeof n.command!="string"||!n.command)return"";let r=t(n.command,typeof e.session_id=="string"?e.session_id:"unknown");return r?JSON.stringify({hook_specific_output:{tool_input:{...n,command:r}}}):""}function Je(e,t=(n,r)=>J(n,"antigravity",r)){if(!H(e)||!H(e.toolCall)||e.toolCall.name!=="run_command")return we;let n=e.toolCall.args;if(!H(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 nn={vibe:{build:e=>We(e),fallback:""},antigravity:{build:e=>Je(e),fallback:we}};function rn(e){return nn[e??""]?.fallback??""}function Ri(e,t){let n=nn[e??""];if(!n)return"";let r;try{r=JSON.parse(t.replace(/^/,""))}catch{return n.fallback}return H(r)?se(r,e,{fallback:n.fallback}):n.build(r)}async function on(e){process.stdout.write(Ri(e,await K()))}on(process.argv[2]).catch(e=>{process.stderr.write(`tkr-agent-hook: ${e.message}
|
|
19
|
+
`),process.stdout.write(rn(process.argv[2])),process.exit(0)});
|
|
20
20
|
/*! Bundled license information:
|
|
21
21
|
|
|
22
22
|
smol-toml/dist/error.js:
|