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