@tokmizer/plugin 0.9.65 → 0.9.67

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.codex-plugin/plugin.json +1 -1
  3. package/LICENSES.md +1 -1
  4. package/dist/bin/tkr-agent-hook.js +54 -10
  5. package/dist/bin/tkr-codex-hook.js +72 -70
  6. package/dist/bin/tkr-copilot-hook.js +54 -10
  7. package/dist/bin/tkr-crush-hook.js +54 -10
  8. package/dist/bin/tkr-cursor-hook.js +53 -9
  9. package/dist/bin/tkr-daemon.js +139 -121
  10. package/dist/bin/tkr-droid-hook.js +54 -10
  11. package/dist/bin/tkr-exec +79 -74
  12. package/dist/bin/tkr-exec.js +79 -74
  13. package/dist/bin/tkr-gemini-hook.js +53 -9
  14. package/dist/bin/tkr-grok-hook.js +54 -10
  15. package/dist/bin/tkr-junie-hook.js +54 -10
  16. package/dist/bin/tkr-processor.js +98 -93
  17. package/dist/bin/tkr-qwen-hook.js +54 -10
  18. package/dist/bin/tkr-shim.js +80 -75
  19. package/dist/bin/tkr-trae-hook.js +54 -10
  20. package/dist/bin/tkr-zcode-hook.js +54 -10
  21. package/dist/bin/tkr.js +270 -253
  22. package/dist/hooks-host/post-tool-use.js +92 -87
  23. package/dist/hooks-host/pre-tool-use.js +54 -10
  24. package/dist/hooks-host/reducer-stop.js +26 -23
  25. package/dist/hooks-host/session-recap.js +5 -4
  26. package/dist/index.js +98 -83
  27. package/dist/native/manifest.json +12 -12
  28. package/dist/native/single.json +12 -12
  29. package/dist/native/tkr-exec-darwin-arm64 +0 -0
  30. package/dist/native/tkr-exec-darwin-x64 +0 -0
  31. package/dist/native/tkr-exec-linux-arm64 +0 -0
  32. package/dist/native/tkr-exec-linux-x64 +0 -0
  33. package/dist/native/tkr-exec-win32-arm64.exe +0 -0
  34. package/dist/native/tkr-exec-win32-x64.exe +0 -0
  35. package/hooks/on-session-start.mjs +9 -1
  36. package/package.json +7 -7
  37. package/scripts/install-mac-linux.sh +47 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokmizer",
3
- "version": "0.9.65",
3
+ "version": "0.9.67",
4
4
  "description": "Tokmizer reduces token consumption for AI agents.",
5
5
  "author": {
6
6
  "name": "Tokmizer",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokmizer",
3
- "version": "0.9.65",
3
+ "version": "0.9.67",
4
4
  "description": "Tokmizer reduces token consumption for OpenAI Codex.",
5
5
  "author": {
6
6
  "name": "Tokmizer",
package/LICENSES.md CHANGED
@@ -26,4 +26,4 @@ Rules you write yourself, in your project or user configuration, are yours. Writ
26
26
 
27
27
  ## Contributions
28
28
 
29
- Contributions are accepted under the Tokmizer Contributor License Agreement, which grants Impulse Creation the right to distribute them under the licence of the directory they change and under other licences, including commercial ones. The agreement is `CLA.md` at the root of the public repository; the process is described in its `CONTRIBUTING.md`.
29
+ The source is published to be read, built and checked. Bug reports and suggested fixes are welcome as issues; pull requests are closed and the maintainer applies changes himself. A suggested fix may be used, changed and published under the licences above, see `CONTRIBUTING.md` at the root of the public repository.
@@ -1,13 +1,57 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __tkrCreateRequire } from "node:module"; const require = __tkrCreateRequire(import.meta.url);
3
- function L(t=5e3){return new Promise(e=>{let n=[],r=process.stdin,o=!1,s=()=>{o||(o=!0,clearTimeout(c),r.off("data",i),r.pause(),r.unref?.(),e(Buffer.concat(n).toString("utf8")))},i=u=>{n.push(Buffer.isBuffer(u)?u:Buffer.from(u))},c=setTimeout(s,t);r.on("data",i).once("end",s).once("error",s),r.resume()})}function J(){return!1}import ne from"node:os";import{join as re}from"node:path";function A(){return process.env.TOKMIZER_HOME||re(ne.homedir(),".tokmizer")}import{rmSync as oe,statSync as se}from"node:fs";import{join as ie}from"node:path";function _t(){return ie(A(),"fail-open")}var ce=24*36e5;function w(t=Date.now()){try{if(t-se(_t()).mtimeMs<ce)return!0;oe(_t(),{force:!0})}catch{}return!1}function v(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}var Qr=String.raw`(?:'(?:(?:[^']|'\\'')*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?'|"(?:[^"]*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?"|(?:[^\s'"]*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?)`;import{appendFileSync as pe,chmodSync as me,mkdirSync as ge,existsSync as he,readFileSync as oo,rmSync as so}from"node:fs";import{dirname as ke,join as _e}from"node:path";import{readFileSync as le,renameSync as ae,statSync as fe,writeFileSync as de}from"node:fs";function bt(t,e,n){try{if(fe(t).size<=e)return;let r=le(t,"utf8").split(`
4
- `).filter(c=>c.trim()!==""),o=[],s=0;for(let c=r.length-1;c>=0;c-=1){let u=r[c],l=Buffer.byteLength(u)+1;if(s+l>n)break;o.push(u),s+=l}o.reverse();let i=`${t}.tmp-${process.pid}`;de(i,o.length?`${o.join(`
3
+ function F(e=5e3){return new Promise(t=>{let n=[],r=process.stdin,o=!1,i=()=>{o||(o=!0,clearTimeout(l),r.off("data",s),r.pause(),r.unref?.(),t(Buffer.concat(n).toString("utf8")))},s=u=>{n.push(Buffer.isBuffer(u)?u:Buffer.from(u))},l=setTimeout(i,e);r.on("data",s).once("end",i).once("error",i),r.resume()})}function Y(){return!1}import wt from"node:os";import{join as St}from"node:path";function E(){return process.env.TOKMIZER_HOME||St(wt.homedir(),".tokmizer")}import{rmSync as xt,statSync as At}from"node:fs";import{join as $t}from"node:path";function Re(){return $t(E(),"fail-open")}var Tt=24*36e5;function A(e=Date.now()){try{if(e-At(Re()).mtimeMs<Tt)return!0;xt(Re(),{force:!0})}catch{}return!1}function v(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}var Po=String.raw`(?:'(?:(?:[^']|'\\'')*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?'|"(?:[^"]*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?"|(?:[^\s'"]*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?)`;import{appendFileSync as Pt,chmodSync as It,mkdirSync as Nt,existsSync as Ht,readFileSync as Do,rmSync as jo}from"node:fs";import{dirname as Lt,join as Dt}from"node:path";import{readFileSync as Et,renameSync as Ot,statSync as vt,writeFileSync as Rt}from"node:fs";function Pe(e,t,n){try{if(vt(e).size<=t)return;let r=Et(e,"utf8").split(`
4
+ `).filter(l=>l.trim()!==""),o=[],i=0;for(let l=r.length-1;l>=0;l-=1){let u=r[l],a=Buffer.byteLength(u)+1;if(i+a>n)break;o.push(u),i+=a}o.reverse();let s=`${e}.tmp-${process.pid}`;Rt(s,o.length?`${o.join(`
5
5
  `)}
6
- `:"",{mode:384}),ae(i,t)}catch{}}var be="usage.jsonl";var wt=2*1024*1024;function we(){return _e(A(),be)}function k(t,e,n=we()){try{let r=ke(n);he(r)||ge(r,{recursive:!0,mode:448});let o=t.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";pe(n,`{"t":${Math.floor(Date.now()/1e3)},"s":"${o}","o":${e?1:0}}
7
- `,{mode:384}),me(n,384),bt(n,wt,wt/2)}catch{}}import{spawnSync as tn}from"node:child_process";import{existsSync as W,readFileSync as ot,readdirSync as st}from"node:fs";import{homedir as C}from"node:os";import{fileURLToPath as en}from"node:url";import{dirname as Nt,join as f,resolve as nn}from"node:path";import{execFileSync as Ue}from"node:child_process";import{mkdirSync as Je,readFileSync as At,renameSync as ze,statSync as Be,writeFileSync as We}from"node:fs";import{join as Et}from"node:path";import{closeSync as Se,openSync as ye,readSync as xe,readdirSync as $e,readFileSync as Ae,statSync as yt}from"node:fs";import{homedir as Ee}from"node:os";import{isAbsolute as ve,join as z,resolve as Oe}from"node:path";var Re=/^[A-Za-z0-9._+@%:,/-]+$/,Te=new Set(["7f454c46","feedface","feedfacf","cefaedfe","cffaedfe","cafebabe","bebafeca"]),Ce=32,Pe=4*1024*1024;function et(t){let e;try{e=ye(t,"r");let n=Buffer.alloc(4),r=xe(e,n,0,4,0);return r>=2&&n[0]===35&&n[1]===33?"#!":r===4?n.toString("hex"):null}catch{return null}finally{e!==void 0&&Se(e)}}function j(t,e=process.platform){try{let n=yt(t);if(!n.isFile())return!1;if(e==="win32")return!0;if((n.mode&73)===0)return!1;let r=et(t);return r==="#!"||r!==null&&Te.has(r)}catch{return!1}}function He(t){if(/\.[A-Za-z0-9]+$/.test(t))return[t];let e=(process.env.PATHEXT??".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);return[t,...e.map(n=>t+n.toLowerCase())]}function T(t,e,n,r=process.platform){if(!Re.test(t))return!1;let o=r==="win32";if(t.includes("/"))return j(Oe(e??process.cwd(),t),r);if(!n)return!1;let s=o?He(t):[t];for(let i of n.split(o?";":":"))if(!(!i||!ve(i))){for(let c of s)if(j(z(i,c),r))return!0}return!1}var Ne=/^eval \$'([^\s'()=]+) \(\) /,Ie=/^([^\s'"()=]+) \(\) \{$/,Le=/^alias -- ([^\s=]+)=(.*)$/,je=/^# (?:Shell Options|Aliases|Shopt|Check for |Shadow )/,Fe=/^export PATH=(.*)$/,De=/^(?:--colou?r(?:=\S+)?|-G)$/;function St(t){return t.length>=2&&t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1).replace(/'\\''/g,"'"):t.length>=2&&t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t}function Me(t,e){let n="";for(let r of t.split(`
8
- `)){let o=Fe.exec(r);if(o&&n!=="# Functions"){let s=St(o[1].trim());/[$`\\]/.test(s)||e.paths.push(s);continue}if(r.startsWith("# ")&&(n!=="# Functions"||je.test(r))){n=r;continue}if(n==="# Functions"){let s=Ne.exec(r)??Ie.exec(r);s&&e.functions.add(s[1])}else if(n==="# Aliases"){let s=Le.exec(r);s&&e.aliases.set(s[1],St(s[2].trim()))}}}function tt(t){return t?.code==="ENOENT"}function xt(t){let e={functions:new Set,aliases:new Map,paths:[],uncertain:!1},n=z(t||z(Ee(),".claude"),"shell-snapshots"),r=[];try{for(let o of $e(n)){if(!o.startsWith("snapshot-")||!o.endsWith(".sh"))continue;let s=z(n,o);try{let i=yt(s);i.isFile()&&r.push({path:s,mtime:i.mtimeMs,size:i.size})}catch(i){tt(i)||(e.uncertain=!0)}}}catch(o){return tt(o)||(e.uncertain=!0),e}r=r.sort((o,s)=>s.mtime-o.mtime).slice(0,Ce);for(let o of r)try{if(o.size>Pe)throw new Error("snapshot too large");Me(Ae(o.path,"utf8"),e)}catch(s){tt(s)||(e.uncertain=!0)}return e}function $t(t,e){if(e.uncertain||e.functions.has(t))return!0;let n=e.aliases.get(t);if(n===void 0)return!1;let r=n.trim().split(/\s+/);return r[0]!==t||!r.slice(1).every(o=>De.test(o))}var Ge="exec-probe.json",Ze=6e4;function Ke(){return Et(A(),Ge)}function qe(t){try{let e=JSON.parse(At(t,"utf8"));if(e==null||typeof e!="object")return null;let n=e;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 Ye(t,e){try{Je(Et(t,".."),{recursive:!0,mode:448});let n=`${t}.${process.pid}.tmp`;We(n,JSON.stringify(e),{mode:384}),ze(n,t)}catch{}}function Ve(t){try{return Ue(t,["--native-check"],{encoding:"utf8",timeout:2e3,maxBuffer:1024,stdio:["ignore","pipe","ignore"],windowsHide:!0}).startsWith("tokmizer-native ")}catch{return!1}}function Xe(t,e){try{let r=At(t,"utf8").split(`
9
- `,1)[0].slice(2).trim().split(/\s+/),o=r[0]??"";return o==="/usr/bin/env"?T(r[1]??"",void 0,e):j(o)}catch{return!1}}function Qe(t,e,n){try{let r=Be(t);return[t,r.size,r.mtimeMs,r.ino,r.mode,e?n??"":""].join("|")}catch{return`${t}|missing`}}function nt(t,e=process.platform,n=process.env.PATH,r=Ke(),o=Date.now()){let s=e!=="win32"&&et(t)==="#!",i=Qe(t,s,n),c=qe(r);if(c?.key===i&&(c.ok||o-c.at<Ze))return c.ok;let u=j(t,e)&&(s?Xe(t,n):Ve(t));return Ye(r,{key:i,ok:u,at:o,skipped:(c?.skipped??0)+(u?0:1)}),u}var rn=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"]),on=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"]),vt=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),Ot="(?:dev|start|serve|watch|preview)",sn=new RegExp(`^(?:\\S*/)?(?:bun\\s+(?:install|i|add|remove|rm|update|outdated|audit|test|build|pm|x)(?:\\s|$)|bun\\s+run\\s+(?!${Ot}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|deno\\s+(?:test|lint|fmt|check|compile|install|info|doc|bench|outdated)(?:\\s|$)|deno\\s+task\\s+(?!${Ot}(?:\\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)`),cn=/(?:^|\s)--watch(?:\s|=|$)/;function un(t){return sn.test(t)&&!cn.test(t)}var ln=/^((?:\S*\/)?(sh|bash|zsh|dash|ksh|fish)\s+(-[elux]*c[elux]*)\s+)(['"])/,an=/[()$]|(?:^|[;&|\n]\s*)(?:and|or|not|begin|end|if|else|switch|case|while|for|function|return)(?:\s|;|$)/,It=3;function Lt(t){let e=ln.exec(t);if(!e)return null;let n=e[2]==="fish";if(n&&e[3]!=="-c")return null;let r=e[4],o=e[1].length+1,s=t.indexOf(r,o);if(s<=o)return null;let i=t.slice(s+1);if(i&&!/^\s/.test(i))return null;let c=t.slice(o,s);return r==='"'&&/[$`\\!]/.test(c)||n&&an.test(c)?null:{script:c,start:o,end:s,quote:r}}var fn=new Set(["cd","export","set","unset","source",".","true",":","pushd","popd"]);function dn(t){return ct(t).filter(n=>{if(n.kind!=="cmd"||n.unsafe)return!1;let r=Ft(n.text);return r!==""&&!fn.has(r)&&!it.test(r)}).length>1}function pn(t,e,n,r,o){if(n>=It)return null;let s=Lt(t);if(!s)return null;let{script:i,start:c,end:u,quote:l}=s,a=[],d=Dt(i,e,n+1,r,S=>a.push(S));if(d===i||l==='"'&&/["$`]/.test(d))return null;let x=l==="'"?d.replace(/'/g,"'\\''"):d,m=`${t.slice(0,c)}${x}${t.slice(u)}`,h=dn(i);if(o)for(let S of h?[t,...a]:a)o(S);return h?`${e} ${m}`:m}var Rt=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,mn=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]);function gn(t,e){let n=G(e);return n==="tail"||n==="journalctl"?Rt.test(t):n==="stern"?!0:mn.has(n)?/\blogs?\b/.test(t)&&Rt.test(t):!1}var it=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,hn=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,kn=/(?:^|[;&|\n({])\s*[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/;function G(t){let e=t.lastIndexOf("/");return e===-1?t:t.slice(e+1)}function jt(t){let e=new Array(t.length).fill(!1),n=[],r=0;for(;r<t.length;){let o=t[r],s=t[r+1],i=n[n.length-1];if(i==="'"){o==="'"&&n.pop(),r+=1;continue}if(o==="\\"){if(s===void 0)return null;r+=2;continue}if(i==="$'"){o==="'"&&n.pop(),r+=1;continue}if(o==="$"&&(s==="("||s==="{")){n.push(s==="("?")":"}"),r+=2;continue}if(o==="`"){i==="`"?n.pop():n.push("`"),r+=1;continue}if(i==='"'){o==='"'&&n.pop(),r+=1;continue}if(o==="$"&&s==="'"){n.push("$'"),r+=2;continue}if(o==="'"||o==='"'){n.push(o),r+=1;continue}if(o==="("||o==="{"&&i==="}"){n.push(o==="("?")":"}"),r+=1;continue}if(o===i){n.pop(),r+=1;continue}if(o===")"&&i===void 0)return null;e[r]=i===void 0,r+=1}return n.length===0?e:null}function Tt(t){let e=jt(t);if(!e)return!0;for(let n=0;n<t.length;n++)if(e[n]&&t[n]===">")return!0;return!1}function ct(t){let e=jt(t);if(!e)return[{kind:"cmd",text:t,unsafe:!0}];let n=[],r="",o=0,s=()=>{r.length>0&&(n.push({kind:"cmd",text:r}),r="")},i=(c,u)=>{s(),n.push({kind:"sep",text:c}),o+=u};for(;o<t.length;){let c=t[o],u=t[o+1];if(e[o]){if(c===">"&&u==="|"){r+=">|",o+=2;continue}if(c==="&"&&u==="&"){i("&&",2);continue}if(c==="&"&&u!==">"){let l=r.replace(/\s+$/,""),a=l[l.length-1];if(a!==">"&&a!=="<"&&a!=="&"){i("&",1);continue}}if(c==="|"&&u==="|"){i("||",2);continue}if(c==="|"&&u==="&"){i("|&",2);continue}if(c===";"&&u===";"){let l=t[o+2]==="&";i(l?";;&":";;",l?3:2);continue}if(c===";"||c===`
10
- `||c==="|"){i(c,1);continue}}r+=c,o+=1}return s(),n}function Ft(t){return t.trim().split(/\s+/)[0]??""}function b(t,e=process.platform){try{let n=Nt(en(import.meta.url)),r=e==="win32",o=t&&t!=="claude-code"&&t!=="codex"&&!r?`TOKMIZER_HOST=${t} `:"";if(r&&(!t||t==="claude-code")){let c=f(n,"..","bin","tkr-exec.exe");if(W(c))return nt(c,e)?`'${c.replace(/\\/g,"/").replace(/'/g,"'\\''")}'`:null}let s=f(n,"..","bin","tkr-exec");if(!r&&W(s))return nt(s,e)?`${o}'${s.replace(/'/g,"'\\''")}'`:null;if(J()){let c=r?process.execPath.replace(/\\/g,"/"):process.execPath;return`${o}'${c.replace(/'/g,"'\\''")}' exec`}let i=f(n,"..","bin","tkr-exec.js");return W(i)?`${o}node '${i.replace(/'/g,"'\\''")}'`:null}catch{return null}}function _n(t,e="tkr-exec",n=()=>!0,r){return Dt(t,e,0,n,r)}function Dt(t,e,n,r,o){if(t.includes("<<")||kn.test(t))return t;let s=ct(t),i=[];for(let c=0;c<s.length;c++){let u=s[c];if(u.kind==="sep"||u.unsafe){i.push(u.text);continue}let l=u.text.trim();if(!l){i.push(u.text);continue}let a=Ft(l),d=s[c+1],x=d?.kind==="sep"&&(d.text==="|"||d.text==="|&"),m=d?.kind==="sep"&&d.text==="&",h=!x&&!m&&!Tt(u.text)&&!u.text.includes("<(")&&!u.text.includes(">(")?pn(l,e,n,r,o):null;if(h!==null){i.push(`${u.text.match(/^\s*/)?.[0]??""}${h}${u.text.match(/\s*$/)?.[0]??""}`);continue}if(l===e||l.startsWith(e)&&/^\s/.test(l.slice(e.length))||rn.has(a)||on.has(a)||(vt.has(a)||vt.has(G(a)))&&!un(l)||it.test(a)||a.startsWith("(")||a.startsWith("#")||a.startsWith("<")||a.startsWith(">")||hn.test(l)||gn(l,a)||a.endsWith(")")||x||m||Tt(u.text)||u.text.includes("<(")||u.text.includes(">(")||a==="node"&&l.includes("tkr-exec.js")||!r(a)){i.push(u.text);continue}let S=u.text.match(/^\s*/)?.[0]??"",_=u.text.match(/\s*$/)?.[0]??"";o?.(l),i.push(`${S}${e} ${l}${_}`)}return i.join("")}var bn=new Set(["command","workdir","timeout_ms","yield_time_ms","max_output_tokens","shell","login","tty","description"]),wn=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"]),Sn=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),yn={find:/^-(?:delete|exec|execdir|ok|okdir|fprint|fls)/,sort:/^(?:-[^-]*o|--output|--compress-program)/,rg:/^(?:--pre|-[^-]*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/},B=["test","run test","run build","run lint","run typecheck"],xn={npm:new Set(B),pnpm:new Set([...B,"build","lint","typecheck"]),yarn:new Set([...B,"build","lint","typecheck"]),bun:new Set(B),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"])},$n=new Set(["pytest","tsc","vitest","jest","eslint","mypy"]);function Mt(t,e,n=0){if(/\$|`|<\(|>\(|\\\r?\n/.test(t)||/>/.test(t.replace(/2>&1|[12]?>\s*\/dev\/null/g,"")))return!1;for(let r of ct(t)){if(r.kind==="sep")continue;if(r.unsafe)return!1;let o=n<It?Lt(r.text.trim()):null;if(o){if(!Mt(o.script,e,n+1))return!1;continue}let s=r.text.trim().split(/\s+/).filter(Boolean).map(l=>l.replace(/['"\\]/g,""));if(s.length===0)continue;if(s.some(l=>it.test(l)))return!1;let i=G(s[0]);if(i!==s[0])return!1;let c=yn[i];if(c&&s.slice(1).some(l=>c.test(l)))return!1;if((i==="git"?Sn.has(s[1]??""):wn.has(i))||e&&$n.has(i))continue;let u=e?xn[i]:void 0;if(!(u&&(u.has(s[1]??"")||s[1]==="run"&&u.has(`run ${s[2]??""}`))))return!1}return!0}function Ut(t,e,n=b(e),r=k,o=K(),s=process.env.PATH,i=ut){if(!g(t)||t.tool_name!=="Bash"||e==="claude-code"&&En(i()))return null;let c=t.tool_input;if(!g(c)||c.run_in_background)return null;let u=c.command;if(typeof u!="string"||!u||e==="codex"&&Object.keys(c).some(S=>!bn.has(S)))return null;let l=typeof t.cwd=="string"&&t.cwd?t.cwd:c.workdir,a=typeof l=="string"&&l?l:void 0,d=typeof t.session_id=="string"&&t.session_id?t.session_id:"unknown",x=typeof t.permission_mode=="string"?t.permission_mode:void 0,m=Kt(u,{host:e,sessionId:d,cwd:a,claudeDirs:o,pathEnv:s,permissionMode:x},n,r);if(!m)return null;let h={...c,command:m.command};return JSON.stringify({hookSpecificOutput:e==="codex"?{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:h}:m.allowedBy?{hookEventName:"PreToolUse",permissionDecision:"allow",permissionDecisionReason:`Tokmizer: allowed by your rule ${m.allowedBy}`,updatedInput:h}:{hookEventName:"PreToolUse",updatedInput:h}})}var An=/(?:^|\s)--(?:disallowedTools|disallowed-tools|settings|setting-sources)(?:[=\s]|$)/;function ut(t=process.env,e=process.platform){let n=Number(t.CLAUDE_PID)||process.ppid;if(e==="win32"||!Number.isInteger(n)||n<=1)return null;try{let r=tn("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 En(t){return t===null||An.test(t)}function vn(t,e){if(!W(t))return"missing";try{let n=ot(t,"utf8");return JSON.parse(e?Jt(n):n)}catch{return"unreadable"}}function Jt(t){let e="",n=!1;for(let r=0;r<t.length;r++){let o=t[r];if(n){e+=o,o==="\\"?e+=t[++r]??"":o==='"'&&(n=!1);continue}if(o==='"')n=!0,e+=o;else if(o==="/"&&t[r+1]==="/"){for(;r<t.length&&t[r]!==`
11
- `;)r++;e+=`
12
- `}else if(o==="/"&&t[r+1]==="*"){if(r=t.indexOf("*/",r+2),r===-1)return"";r+=1}else e+=o}return e.replace(/,(\s*[}\]])/g,"$1")}function Z(t){let e=[],n=nn(t);for(;;){e.push(n);let r=Nt(n);if(r===n)return e;n=r}}function On(){let t=process.platform==="darwin"?"/Library/Application Support/ClaudeCode":process.platform==="win32"?"C:\\Program Files\\ClaudeCode":"/etc/claude-code",e=[f(t,"managed-settings.json")];try{for(let n of st(f(t,"managed-settings.d")))n.endsWith(".json")&&e.push(f(t,"managed-settings.d",n))}catch{return e}return e}function D(t,e,n,r){let o=[];for(let s of t){let i=vn(s,e);if(i!=="missing"&&(i==="unreadable"||!g(i)||!n(i,o)))return"unreadable"}return{matchers:o,complete:r}}function F(t){return t===void 0?[]:Array.isArray(t)?t.filter(e=>typeof e=="string"):null}function K(){return{projectDir:process.env.CLAUDE_PROJECT_DIR,configDir:process.env.CLAUDE_CONFIG_DIR}}function Rn(t,e){let n=_=>[f(_,"settings.json"),f(_,"settings.local.json")],r=_=>n(f(_,".claude")),o=f(C(),".claude"),s=e.configDir||o,i=[[On(),"managed"],[[f(s,"settings.json")],"loaded"],[[f(s,"settings.local.json")],"loadedLocal"],[e.configDir?n(o):[],"extra"],[e.projectDir?r(e.projectDir):[],"project"],[Z(t).flatMap(r),"extra"]],c=[],u={managed:[],loaded:[],loadedLocal:[],project:[],extra:[]},l={managed:!1,loaded:!1,loadedLocal:!1,project:!1,extra:!1},a=!1,d="managed",x=(_,Q)=>{let $=_.permissions;if(d==="managed"&&(_.allowManagedPermissionRulesOnly===!0||g($)&&$.allowManagedPermissionRulesOnly===!0)&&(a=!0),$===void 0)return!0;if(!g($))return!1;for(let pt of["deny","ask","allow"]){let mt=F($[pt]);if(!mt)return!1;for(let gt of mt){let R=/^\s*Bash\s*(?:\(([\s\S]*)\))?\s*$/.exec(gt);if(R)if(pt!=="allow")Q.push(O((R[1]??"*").replace(/:\*$/," *")));else if(R[1]===void 0||R[1].trim()==="*")l[d]=!0;else{c.push(O(R[1].replace(/:\*$/," *")));let ht=Jn(R[1]);ht&&u[d].push({rule:gt.trim(),matches:ht})}}}return!0},m=[];for(let[_,Q]of i){d=Q;let $=D(_,!1,x,!0);if($==="unreadable")return"unreadable";m.push(...$.matchers)}let h=l.managed||(l.loaded||l.loadedLocal)&&!a,S=[...u.managed,...a?[]:u.loaded];return{matchers:[...m,...h?[]:c],complete:!0,allow:c,allowsEverything:h,guards:m,trustedAllow:S}}function Tn(t){let e=[f(C(),".cursor","cli-config.json"),...Z(t).map(n=>f(n,".cursor","cli.json"))];return D(e,!0,(n,r)=>{let o=n.permissions;if(o===void 0)return!0;if(!g(o))return!1;let s=F(o.deny);if(!s)return!1;for(let i of s){let c=/^\s*Shell\s*(?:\(([\s\S]*)\))?\s*$/.exec(i);if(!c)continue;let u=c[1]??"*",l=u.indexOf(":");r.push(O(l===-1?`${u} *`:`${u.slice(0,l)} ${u.slice(l+1)}`))}return!0},!1)}function Cn(){return process.platform==="darwin"?"/Library/Application Support/GeminiCli":process.platform==="win32"?"C:\\ProgramData\\gemini-cli":"/etc/gemini-cli"}var zt=/^\s*(?:run_shell_command|ShellTool)\s*(?:\(([\s\S]*)\))?\s*$/;function Pn(t,e){let n=t.tools;if(n!==void 0&&!g(n))return!1;let r=[F(t.excludeTools),F(g(n)?n.exclude:void 0)];for(let o of r){if(!o)return!1;for(let s of o){let i=zt.exec(s);i&&e.push(O(i[1]===void 0?"*":`${i[1]}*`))}}return!0}function Ct(t){try{return JSON.parse(t)}catch{return null}}function Hn(t){let e=t.trim();if(e.startsWith('"""')||e.startsWith("'''"))return null;if(e.startsWith("[")){if(!/\]\s*(?:#.*)?$/.test(e))return null;let n=[];for(let r of e.matchAll(/"((?:\\.|[^"\\])*)"|'([^']*)'/g)){let o=r[2]??Ct(`"${r[1]}"`);if(o===null)return null;n.push(o)}return n}if(e.startsWith('"')){let n=/^"((?:\\.|[^"\\])*)"/.exec(e);return n?Ct(`"${n[1]}"`):null}if(e.startsWith("'")){let n=/^'([^']*)'/.exec(e);return n?n[1]:null}return e.replace(/\s*#.*$/,"")}function Nn(t,e){for(let n of t.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 l=/^\s*([A-Za-z_]+)\s*=\s*(.*)$/.exec(u);if(!l)continue;let a=Hn(l[2]);if(a===null)return!1;r[l[1]]=a}let o=r.decision;if(o!=="deny"&&o!=="ask_user"||!(r.toolName===void 0?["*"]:[r.toolName].flat()).some(u=>u==="*"||zt.test(u)))continue;let i=r.commandPrefix===void 0?[]:[r.commandPrefix].flat(),c=[r.commandRegex,r.argsPattern].flat().filter(u=>typeof u=="string");if(i.length===0&&c.length===0){e.push(()=>!0);continue}for(let u of i)e.push(O(`${u}*`));for(let u of c){let l;try{l=new RegExp(u)}catch{return!1}e.push(a=>l.test(JSON.stringify({command:a}))||lt(l,a))}}return!0}function Pt(t){try{return st(t).filter(e=>e.endsWith(".toml")).map(e=>f(t,e))}catch{return[]}}function In(t){let e=Cn(),n=[f(e,"system-defaults.json"),f(e,"settings.json"),process.env.GEMINI_CLI_SYSTEM_SETTINGS_PATH,process.env.GEMINI_CLI_SYSTEM_DEFAULTS_PATH,f(C(),".gemini","settings.json"),...Z(t).map(o=>f(o,".gemini","settings.json"))].filter(o=>!!o),r=D(n,!0,Pn,!1);if(r==="unreadable")return r;for(let o of[...Pt(f(C(),".gemini","policies")),...Pt(f(e,"policies"))]){let s;try{s=ot(o,"utf8")}catch{return"unreadable"}if(!Nn(s,r.matchers))return"unreadable"}return r}function rt(t,e){if(t===void 0)return!0;if(typeof t=="string")return t!=="allow"&&e.push(()=>!0),!0;if(!g(t))return!1;for(let n of["bash","shell","*"]){let r=t[n];if(r!==void 0){if(typeof r=="string"){r!=="allow"&&e.push(()=>!0);continue}if(!g(r))return!1;for(let[o,s]of Object.entries(r))s!=="allow"&&e.push(O(o.replace(/\?/g,"*")))}}return!0}function Ht(t,e){if(t.permissions!==void 0||!rt(t.permission,e))return!1;for(let n of["agent","agents","mode"]){let r=t[n];if(r!==void 0){if(!g(r))return!1;for(let o of Object.values(r))if(g(o)&&(o.permissions!==void 0||!rt(o.permission,e)))return!1}}return!0}function Ln(t){for(let e of t)for(let n of["agent","agents","mode","modes"]){let r;try{r=st(f(e,n))}catch{continue}for(let o of r)try{if(o.endsWith(".md")&&/permission/i.test(ot(f(e,n,o),"utf8")))return!0}catch{return!0}}return!1}function jn(t){let e=f(process.env.XDG_CONFIG_HOME||f(C(),".config"),"opencode"),n=Z(t),r=[e,...n.map(c=>f(c,".opencode"))];if(Ln(r))return"unreadable";let o=["opencode.json","opencode.jsonc","config.json"],s=[...o.map(c=>f(e,c)),process.env.OPENCODE_CONFIG,...n.flatMap(c=>[...o.slice(0,2).map(u=>f(c,u)),...o.slice(0,2).map(u=>f(c,".opencode",u))])].filter(c=>!!c),i=D(s,!0,Ht,!0);if(i==="unreadable")return i;for(let c of[process.env.OPENCODE_CONFIG_CONTENT,process.env.OPENCODE_PERMISSION]){if(!c)continue;let u;try{u=JSON.parse(Jt(c))}catch{return"unreadable"}if(!(c===process.env.OPENCODE_PERMISSION?rt(u,i.matchers):g(u)&&Ht(u,i.matchers)))return"unreadable"}return i}function Fn(){return D([f(C(),".gemini","antigravity-cli","settings.json")],!0,(t,e)=>{let n=t.permissions;if(n===void 0)return!0;if(!g(n))return!1;for(let r of["deny","ask"]){let o=F(n[r]);if(!o)return!1;for(let s of o){let i=/^\s*command\s*\(([\s\S]*)\)\s*$/.exec(s);if(!i)continue;let c=i[1].trim();if(!c.startsWith("regex:")){e.push(O(c==="*"?"*":`${c} *`));continue}let u;try{u=new RegExp(c.slice(6))}catch{return!1}e.push(l=>lt(u,l))}}return!0},!1)}function g(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}function Bt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Dn(t){let e=t.trim().replace(/\s+/g," "),n=e.endsWith(" *")&&e.length>2,r=(n?e.slice(0,-2):e).split("*").map(Bt).join("[\\s\\S]*");return new RegExp(`^${r}${n?"(?: [\\s\\S]*)?":""}(?= |$)`)}var Mn=512;function Un(t){let e=t.replace(/['"\\]/g,"").split(/[\s;&|(){}<>`$]+/).filter(Boolean);return[e,e.map(G)]}function lt(t,e){if(t.test(e)||t.test(e.trim().replace(/\s+/g," ")))return!0;for(let n of Un(e)){if(n.length>Mn)return!0;for(let r=0;r<n.length;r++)if(t.test(n.slice(r).join(" ")))return!0}return!1}function O(t){let e=Dn(t);return n=>lt(e,n)}function Jn(t){let e=t.trim().replace(/:\*$/," *"),n=e.endsWith(" *"),r=n?e.slice(0,-2):e;if(!r||r.includes("*")||/\s\s|[^\S ]|^ | $/.test(r))return null;let o=new RegExp(`^${Bt(r)}${n?"(?: [\\s\\S]*)?":""}$`);return s=>o.test(s)}var zn={"claude-code":Rn,cursor:Tn,"gemini-cli":In,opencode:jn,antigravity:Fn},Bn=new Set(["codex"]),Wt=/(?:^|[\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 Wn(t,e,n){let r=zn[t];return r?r(e??process.cwd(),n):{matchers:[],complete:!1}}function Gn(t,e,n){return t==="unreadable"||Wt.test(e.replace(/['"\\]/g,""))||t.matchers.some(r=>r(e))?!1:t.complete||Mt(e,!Bn.has(n))}var Gt=new Set(["default","acceptEdits","dontAsk"]);function Zt(t,e){return e.host!=="claude-code"||e.permissionMode==="bypassPermissions"?!0:t!=="unreadable"&&t.allowsEverything===!0&&Gt.has(e.permissionMode??"")}function Zn(t,e){let n="pathEnv"in t?t.pathEnv:process.env.PATH,r;return o=>t.host!=="claude-code"?T(o,t.cwd,n):(r??=xt(e.configDir),!T(o,t.cwd,n)&&!r.paths.some(s=>T(o,t.cwd,s))?!1:o.includes("/")||!$t(o,r))}var Kn=/^[^\s;&|<>()$`\\{}*?[\]~#!]+(?: [^\s;&|<>()$`\\{}*?[\]~#!]+)*$/;function qn(t,e,n){return n.host!=="claude-code"||t==="unreadable"||Zt(t,n)||!Gt.has(n.permissionMode??"")||!Kn.test(e)||Wt.test(e.replace(/['"]/g,""))||(t.guards??[]).some(r=>r(e))?null:(t.trustedAllow??[]).find(r=>r.matches(e))?.rule??null}function Kt(t,e,n,r){if(!n||/["\\$`;&|<>(){}]|'\\''/.test(n))return null;let o=e.claudeDirs??K(),s=Wn(e.host,e.cwd,o),i=qn(s,t,e),c=i||Gn(s,t,e.host)?_n(t,n,Zn(e,o)):t;return c!==t&&s!=="unreadable"&&(i?(s.guards??[]).some(u=>u(c)):s.matchers.some(u=>u(c))||(s.allow??[]).some(u=>u(c)&&!u(t)))&&(c=t),r(e.sessionId,c!==t),c===t?null:i?{command:c,allowedBy:i}:Zt(s,e)?{command:c}:null}function E(t,e,n,r){return Kt(t,e,n,r)?.command??null}function P(t,e,n="unknown",r=b(e),o=k){return t?E(t,{host:e,sessionId:n},w()?null:r,o):null}function p(t,e){let n=t[e];return typeof n=="string"&&n?n:null}function M(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}function Yn(t){return p(t,"prompt_id")||p(t,"scratchpad_dir")?!0:M(t.effort)}function Vn(t){return p(t,"tool_use_id")?.startsWith("toolu_")===!0||/^claude/i.test(p(t,"model")??"")}var Xn=new Set(["BeforeTool","AfterTool","BeforeAgent","AfterAgent","BeforeModel","AfterModel","BeforeToolSelection"]),Qn=new Set(["preToolUse","postToolUse","beforeShellExecution","afterShellExecution","beforeSubmitPrompt","sessionStart","sessionEnd","stop"]),tr=new Set(["pre_tool","post_tool"]),er=new Set(["before_tool_call","after_tool_call"]),nr=new Set(["runTerminalCommand","run_in_terminal"]),rr=[["codex",t=>p(t,"turn_id")!==null],["claude-code",Yn],["cursor",t=>p(t,"cursor_version")!==null||p(t,"generation_id")!==null||p(t,"conversation_id")!==null||Array.isArray(t.workspace_roots)||Qn.has(p(t,"hook_event_name")??"")],["gemini-cli",t=>Xn.has(p(t,"hook_event_name")??"")],["qwen-code",t=>t.hook_event_name==="PreToolUse"&&t.tool_name==="run_shell_command"],["vibe",t=>tr.has(p(t,"hook_event_name")??"")],["antigravity",t=>M(t.toolCall)],["copilot",t=>p(t,"toolName")!==null&&"toolArgs"in t||nr.has(p(t,"tool_name")??"")],["grok",t=>t.toolName==="run_terminal_command"||t.tool_name==="run_terminal_command"||M(t.toolInput)&&!("toolArgs"in t)],["droid",t=>t.tool_name==="Execute"],["trae",t=>t.tool_name==="RunCommand"],["crush",t=>t.hook_event_name===void 0&&p(t,"event")!==null&&!er.has(p(t,"event"))]],or=new Set(["codex","antigravity"]);function sr(t){return M(t)?rr.filter(([,e])=>e(t)).map(([e])=>e):[]}function qt(t,e){if(!M(t))return null;let n=sr(t);return n.length>1?null:n.length===1?n[0]:Vn(t)&&or.has(e)?"claude-code":e==="codex"?null:e}var at=JSON.stringify({permission:"allow"});function Yt(t,e=b("cursor"),n=k){if(t.tool_name!=="Shell")return at;let r=t.tool_input??{},o=r.command;if(typeof o!="string"||!o)return at;let s=typeof r.working_directory=="string"?r.working_directory:void 0,i=E(o,{host:"cursor",sessionId:t.conversation_id??"unknown",cwd:s},w()?null:e,n);return i?JSON.stringify({permission:"allow",updated_input:{...r,command:i}}):at}var q="{}";function Vt(t,e=b("gemini-cli"),n=k){if(t.hook_event_name!=="BeforeTool"||t.tool_name!=="run_shell_command")return q;let r=t.tool_input??{};if(r.is_background)return q;let o=r.command;if(typeof o!="string"||!o)return q;let s=typeof t.cwd=="string"?t.cwd:void 0,i=E(o,{host:"gemini-cli",sessionId:t.session_id??"unknown",cwd:s},w()?null:e,n);return i?JSON.stringify({hookSpecificOutput:{tool_input:{command:i}}}):q}var y="{}",ir=new Set(["runTerminalCommand","run_in_terminal","Bash","bash"]),cr=["run_in_background","is_background","isBackground"];function Y(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}function ur(t){let e=t.session_id??t.sessionId;return typeof e=="string"&&e?e:"unknown"}function lr(t,e){let n=t.cwd??e.cwd??e.workdir??e.working_directory;return typeof n=="string"&&n?n:void 0}function V(t,e,n,r,o){if(!Y(e)||cr.some(i=>e[i]===!0))return null;let s=e.command;return typeof s!="string"||!s?null:E(s,{host:t,sessionId:ur(n),cwd:lr(n,e)},w()?null:r,o)}function N(t,e){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",updatedInput:{...t,command:e}}})}function ar(t){if(Y(t))return t;if(typeof t!="string")return null;try{let e=JSON.parse(t);return Y(e)?e:null}catch{return null}}function fr(t,e,n){if(typeof t.tool_name=="string"){if(!ir.has(t.tool_name))return y;let s=t.tool_input,i=V("copilot",s,t,e,n);return i?N(s,i):y}if(t.toolName!=="bash")return y;let r=ar(t.toolArgs),o=V("copilot",r,t,e,n);return o?JSON.stringify({modifiedArgs:{...r,command:o}}):y}function H(t,e,n){return(r,o,s)=>{if(r.tool_name!==e)return y;let i=r.tool_input,c=V(t,i,r,o,s);return c?n(i,c):y}}var dr=new Set(["run_terminal_command","Bash","bash"]);function pr(t,e,n){let r=t.toolName??t.tool_name;if(typeof r!="string"||!dr.has(r))return y;let o=t.toolInput??t.tool_input,s=V("grok",o,t,e,n);return s?N(o,s):y}var mr={copilot:fr,droid:H("droid","Execute",N),trae:H("trae","RunCommand",N),"qwen-code":H("qwen-code","run_shell_command",N),crush:H("crush","bash",(t,e)=>JSON.stringify({updated_input:{command:e}})),junie:H("junie","Bash",(t,e)=>JSON.stringify({updatedInput:{...t,command:e}})),zcode:H("zcode","Bash",N),grok:pr};function Xt(t,e,n=b(t),r=k){return Y(e)?mr[t](e,n,r):y}function I(t){return w()?null:b(t)}function gr(t,e,n={}){let r=n.recordUsage??k;switch(t){case"claude-code":case"codex":return e.hook_event_name!==void 0&&e.hook_event_name!=="PreToolUse"?"":Ut(e,t,I(t),r,n.claudeDirs??K(),n.pathEnv??process.env.PATH,n.launchArgs??ut)??"";case"cursor":return Yt(e,I(t),r);case"gemini-cli":return Vt(e,I(t),r);case"vibe":return ft(e,(o,s)=>P(o,"vibe",s,I(t),r));case"antigravity":return dt(e,(o,s)=>P(o,"antigravity",s,I(t),r));default:return Xt(t,e,I(t),r)}}function U(t,e,n={}){let r=qt(t,e);return r?gr(r,t,n):n.fallback??""}var hr=new Set(["bash","file_system.bash"]),X=JSON.stringify({decision:"allow"});function ft(t,e=(n,r)=>P(n,"vibe",r)){if(!v(t)||t.hook_event_name!=="pre_tool"||typeof t.tool_name!="string"||!hr.has(t.tool_name))return"";let n=t.tool_input;if(!v(n)||typeof n.command!="string"||!n.command)return"";let r=e(n.command,typeof t.session_id=="string"?t.session_id:"unknown");return r?JSON.stringify({hook_specific_output:{tool_input:{...n,command:r}}}):""}function dt(t,e=(n,r)=>P(n,"antigravity",r)){if(!v(t)||!v(t.toolCall)||t.toolCall.name!=="run_command")return X;let n=t.toolCall.args;if(!v(n)||typeof n.CommandLine!="string"||!n.CommandLine)return X;let r=e(n.CommandLine,typeof t.conversationId=="string"?t.conversationId:"unknown");return r?JSON.stringify({decision:"allow",overwrite:{CommandLine:r}}):X}var Qt={vibe:{build:t=>ft(t),fallback:""},antigravity:{build:t=>dt(t),fallback:X}};function te(t){return Qt[t??""]?.fallback??""}function kr(t,e){let n=Qt[t??""];if(!n)return"";let r;try{r=JSON.parse(e.replace(/^/,""))}catch{return n.fallback}return v(r)?U(r,t,{fallback:n.fallback}):n.build(r)}async function ee(t){process.stdout.write(kr(t,await L()))}ee(process.argv[2]).catch(t=>{process.stderr.write(`tkr-agent-hook: ${t.message}
13
- `),process.stdout.write(te(process.argv[2])),process.exit(0)});
6
+ `:"",{mode:384}),Ot(s,e)}catch{}}var jt="usage.jsonl";var Ie=2*1024*1024;function Ft(){return Dt(E(),jt)}function y(e,t,n=Ft()){try{let r=Lt(n);Ht(r)||Nt(r,{recursive:!0,mode:448});let o=e.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";Pt(n,`{"t":${Math.floor(Date.now()/1e3)},"s":"${o}","o":${t?1:0}}
7
+ `,{mode:384}),It(n,384),Pe(n,Ie,Ie/2)}catch{}}import{spawnSync as Tn}from"node:child_process";import{existsSync as B,readFileSync as W,readdirSync as re}from"node:fs";import{homedir as R}from"node:os";import{fileURLToPath as Cn}from"node:url";import{dirname as Xe,join as p,resolve as En}from"node:path";function Mt(e,t){let n=e.slice(0,t).split(/\r?\n/);return[n.length,n.pop().length+1]}function Ut(e,t,n){let r=e.split(/\r?\n/),o="",i=(Math.log10(t+1)|0)+1;for(let s=t-1;s<=t+1;s++){let l=r[s-1];l&&(o+=s.toString().padEnd(i," "),o+=": ",o+=l,o+=`
8
+ `,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]=Mt(n.toml,n.ptr),i=Ut(n.toml,r,o);super(`Invalid TOML document: ${t}
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 X(e){let t=e.p,n=e.s.charCodeAt(e.p++),r=n,o=n===39,i=n===e.s.charCodeAt(e.p)&&n===e.s.charCodeAt(e.p+1);i&&((n=e.s.charCodeAt(e.p+=2))===10?e.p++:n===13&&e.s.charCodeAt(e.p+1)===10&&(e.p+=2));let s="",l=e.p,u=0;for(;e.p<e.s.length;e.p++)if(n=e.s.charCodeAt(e.p),i&&(n===10||n===13&&e.s.charCodeAt(e.p+1)===10))u=u&&3;else if(n<32&&n!==9||n===127)f.x("control characters are not allowed in strings",e);else if((!u||u===3)&&n===r&&(!i||e.s.charCodeAt(e.p+1)===r&&e.s.charCodeAt(e.p+2)===r)){if(i&&(e.s.charCodeAt(e.p+3)===r&&e.p++,e.s.charCodeAt(e.p+3)===r&&e.p++),!u){let a=e.s.slice(l,e.p);s=s?s+a:a}return e.p+=i?3:1,s}else if(!u)!o&&n===92&&(s+=e.s.slice(l,l=e.p),u=1);else if(u===1)if(n===120||n===117||n===85){let a=e.p++-1,c=0,d=n===120?2:n===117?4:8;for(let _=0;_<d;_++,e.p++){let m=e.s.charCodeAt(e.p),h=m>=48&&m<=57?m-48:m>=65&&m<=70?m-65+10:m>=97&&m<=102?m-97+10:-1;h<0&&f.x("invalid non-hex character in unicode escape",e),c=c<<4|h}(c<0||c>1114111||c>=55296&&c<=57343)&&f.x("invalid unicode escape",e,a),s+=String.fromCodePoint(c),l=e.p--,u=0}else i&&(n===32||n===9)?u=2:(n===98?s+="\b":n===116?s+=" ":n===110?s+=`
12
+ `:n===102?s+="\f":n===114?s+="\r":n===101?s+="\x1B":n===34?s+='"':n===92?s+="\\":f.x("unrecognised escape sequence",e),l=e.p+1,u=0);else n!==32&&n!==9&&(u===2&&f.x("invalid escape: only line-ending whitespace may be escaped",e,l),u=!o&&n===92?1:0,l=e.p);f.x("unfinished string",e,t)}var zt=/^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i,M=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(zt);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 pe(e,t){return e===32||e===9||e===10||e===13||t&&(e===t||e===44)||e===35}function z(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?Le(e):He(e);return e.d++,o}return r===34||r===39?X(e):r===116?((e.s.charCodeAt(++e.p)!==114||e.s.charCodeAt(++e.p)!==117||e.s.charCodeAt(++e.p)!==101)&&f.x("invalid value",e,n),e.p++,!0):r===102?((e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==108||e.s.charCodeAt(++e.p)!==115||e.s.charCodeAt(++e.p)!==101)&&f.x("invalid value",e,n),e.p++,!1):r===43||r===45?Q(e,e.p,e.s.charCodeAt(++e.p),44-r,t):e.s.charCodeAt(e.p+4)===45&&e.s.charCodeAt(e.p+7)===45?Jt(e,r,t):e.s.charCodeAt(e.p+2)===58?Bt(e,r,t):Q(e,e.p,r,0,t)}function Q(e,t,n,r,o){let i=n,s=0,l=!1;if(i===105)return(e.s.charCodeAt(++e.p)!==110||e.s.charCodeAt(++e.p)!==102)&&f.x("invalid value",e,t),e.p++,(r||1)/0;if(i===110)return(e.s.charCodeAt(++e.p)!==97||e.s.charCodeAt(++e.p)!==110)&&f.x("invalid value",e,t),e.p++,NaN;if(i===48){if(++e.p>=e.s.length||pe(i=e.s.charCodeAt(e.p),o))return e.bi===!0?0n:0;if(!r){if(i===120)return de(e,t,16,o);if(i===98)return de(e,t,2,o);if(i===111)return de(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),!pe(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):Ne(e,u,10,t)}function de(e,t,n,r){let o,i=1;for(;++e.p<e.s.length&&(o=e.s.charCodeAt(e.p),!pe(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("_","")),Ne(e,s,n,t)}function Ne(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 Jt(e,t,n){let r=e.p++,o;if(!b(t)||!b(e.s.charCodeAt(e.p++))||!b(e.s.charCodeAt(e.p++))||!b(e.s.charCodeAt(e.p++)))return Q(e,e.p=r,t,0,n);if(e.p+=5,b(e.s.charCodeAt(e.p++))||f.x("invalid date-time: date part is malformed",e,r),e.p>=e.s.length||((t=e.s.charCodeAt(e.p))!==32||(o=!0,!b(e.s.charCodeAt(e.p+1))))&&t!==84&&t!==116){let s=e.s.slice(r,e.p);return U(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 U(e,s,1,o,r,"[+00:00]")}if(t===43||t===45){let s=e.s.slice(r,e.p+=6);return U(e,s,1,o,r,!e.ld&&"["+e.s.slice(e.p-6,e.p)+"]")}}let i=e.s.slice(r,e.p);return U(e,i,2,o,r)}function Bt(e,t,n){let r=e.p;if(!b(t)||!b(e.s.charCodeAt(++e.p)))return Q(e,--e.p,t,0,n);if(e.s.charCodeAt(e.p+=4)===58&&(e.p+=3),e.s.charCodeAt(e.p)===46)for(;b(e.s.charCodeAt(++e.p)););let o=e.s.slice(r,e.p);return U(e,o,4,!1,r)}function U(e,t,n,r,o,i){if(e.ld){let s=new M(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 Wt(e){for(;e.p<e.s.length;e.p++){let t=e.s.charCodeAt(e.p);if(t===10)break;if(t===13&&e.s.charCodeAt(e.p+1)===10){e.p++;break}(t<32&&t!==9||t===127)&&f.x("control characters are not allowed in comments",e)}}function S(e,t,n){let r;for(;e.p<e.s.length;){for(;e.p<e.s.length&&((r=e.s.charCodeAt(e.p))===32||r===9||!t&&(r===10||r===13&&e.s.charCodeAt(e.p+1)===10));)e.p++;if(n||r!==35)break;Wt(e)}}function ee(e,t=61){let n,r=0,o=[],i,s=e.s.charCodeAt(n=e.p);do{if(s===t)return r||f.x("unexpected end of key",e),r===1&&o.push(e.s.slice(i,e.p)),e.p++,o;s===46?(r||f.x("illegal empty bare key",e),r===1&&o.push(e.s.slice(i,e.p)),r=0):!r&&(s===34||s===39)?(s===e.s.charCodeAt(e.p+1)&&s===e.s.charCodeAt(e.p+2)&&f.x("illegal quoted key: multiline strings are not allowed",e),o.push(X(e)),r=2,e.p--):s===32||s===9?r===1&&(o.push(e.s.slice(i,e.p)),r=2):r===2||s<48&&s!==45||s>57&&s<65||s>90&&s<97&&s!==95||s>122?f.x("illegal character in key",e):r||(r=1,i=e.p)}while(s=e.s.charCodeAt(++e.p));f.x("incomplete key-value: cannot find end of key",e,n)}function He(e){let t=e.p++,n=Object.create(null),r=new Set,o;for(;e.p<e.s.length;){if(S(e),(o=e.s.charCodeAt(e.p))===125)return e.p++,n;let i,s=n,l=!1,u=e.p,a=ee(e);for(let d=0;d<a.length;d++){d&&(s=l?s[i]:s[i]=Object.create(null)),i=a[d],(l=Object.hasOwn(s,i))&&(typeof s[i]!="object"||r.has(s[i]))&&f.x("trying to redefine an already defined value",e,u);let _=i==="__proto__";if(e.uk&&(_||i==="constructor")){s=e.uk!==1&&f.x("document contains an unsafe property",e,u);break}!l&&_&&Object.defineProperty(s,i,{enumerable:!0,configurable:!0,writable:!0})}l&&f.x("trying to redefine an already defined value",e,u),S(e,!0,!0);let c=z(e,125);if(s&&typeof(s[i]=c)=="object"&&r.add(c),S(e),(o=e.s.charCodeAt(e.p++))===125)return n;o!==44&&f.x("expected comma or end of structure",e,e.p-1)}f.x("unfinished table",e,t)}function Le(e){let t=e.p++,n=[],r;for(;e.p<e.s.length;){if(S(e),(r=e.s.charCodeAt(e.p))===93)return e.p++,n;if(n.push(z(e,93)),S(e),(r=e.s.charCodeAt(e.p++))===93)return n;r!==44&&f.x("expected comma or end of structure",e,e.p-1)}f.x("unfinished array",e,t)}function De(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 je(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 me(e,t={}){let n={s:e,p:0,d:t.maxDepth??1e3,bi:t.integersAsBigInt??!1,ld:t.useLegacyDate??!0,uk:t.unsafeKeyBehaviour==="throw"?2:t.unsafeKeyBehaviour==="drop"?1:0},r=Object.create(null),o=Object.create(null),i,s=!1,l=r,u=o;for(e.charCodeAt(0)===65279&&n.p++,S(n);n.p<e.length;){if(e.charCodeAt(n.p)===91){let a=e.charCodeAt(++n.p)===91;i=n.p+=+a,s=!1;let c=ee(n,93);a&&(e.charCodeAt(n.p)!==93&&f.x("expected end of table array declaration",n),n.p++);let d=De(n,c,r,o,a?2:1);d?(u=d[2],l=d[1]):(je(n,d,i),s=!0)}else{i=n.p;let a=ee(n),c=De(n,a,l,u,0);!c&&!s&&je(n,c,i),S(n,!0,!0);let d=z(n,void 0);c&&!s&&(c[1][c[0]]=d)}S(n,!0),n.p<e.length&&(i=e.charCodeAt(n.p))!==10&&(i!==13||e.charCodeAt(n.p+1)!==10)&&f.x("each key-value declaration must be followed by an end-of-line",n),S(n)}return r}var ci=!!"".isWellFormed;import{execFileSync as pn}from"node:child_process";import{mkdirSync as mn,readFileSync as Je,renameSync as gn,statSync as hn,writeFileSync as kn}from"node:fs";import{join as Be}from"node:path";import{closeSync as Gt,openSync as Zt,readSync as Vt,readdirSync as qt,readFileSync as Kt,statSync as Me}from"node:fs";import{homedir as Yt}from"node:os";import{isAbsolute as Xt,join as te,resolve as Qt}from"node:path";var en=/^[A-Za-z0-9._+@%:,/-]+$/,tn=new Set(["7f454c46","feedface","feedfacf","cefaedfe","cffaedfe","cafebabe","bebafeca"]),nn=32,rn=4*1024*1024;function he(e){let t;try{t=Zt(e,"r");let n=Buffer.alloc(4),r=Vt(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&&Gt(t)}}function J(e,t=process.platform){try{let n=Me(e);if(!n.isFile())return!1;if(t==="win32")return!0;if((n.mode&73)===0)return!1;let r=he(e);return r==="#!"||r!==null&&tn.has(r)}catch{return!1}}function on(e){if(/\.[A-Za-z0-9]+$/.test(e))return[e];let t=(process.env.PATHEXT??".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);return[e,...t.map(n=>e+n.toLowerCase())]}function N(e,t,n,r=process.platform){if(!en.test(e))return!1;let o=r==="win32";if(e.includes("/"))return J(Qt(t??process.cwd(),e),r);if(!n)return!1;let i=o?on(e):[e];for(let s of n.split(o?";":":"))if(!(!s||!Xt(s))){for(let l of i)if(J(te(s,l),r))return!0}return!1}var sn=/^eval \$'([^\s'()=]+) \(\) /,ln=/^([^\s'"()=]+) \(\) \{$/,un=/^alias -- ([^\s=]+)=(.*)$/,an=/^# (?:Shell Options|Aliases|Shopt|Check for |Shadow )/,cn=/^export PATH=(.*)$/,fn=/^(?:--colou?r(?:=\S+)?|-G)$/;function Fe(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 dn(e,t){let n="";for(let r of e.split(`
13
+ `)){let o=cn.exec(r);if(o&&n!=="# Functions"){let i=Fe(o[1].trim());/[$`\\]/.test(i)||t.paths.push(i);continue}if(r.startsWith("# ")&&(n!=="# Functions"||an.test(r))){n=r;continue}if(n==="# Functions"){let i=sn.exec(r)??ln.exec(r);i&&t.functions.add(i[1])}else if(n==="# Aliases"){let i=un.exec(r);i&&t.aliases.set(i[1],Fe(i[2].trim()))}}}function ge(e){return e?.code==="ENOENT"}function Ue(e){let t={functions:new Set,aliases:new Map,paths:[],uncertain:!1},n=te(e||te(Yt(),".claude"),"shell-snapshots"),r=[];try{for(let o of qt(n)){if(!o.startsWith("snapshot-")||!o.endsWith(".sh"))continue;let i=te(n,o);try{let s=Me(i);s.isFile()&&r.push({path:i,mtime:s.mtimeMs,size:s.size})}catch(s){ge(s)||(t.uncertain=!0)}}}catch(o){return ge(o)||(t.uncertain=!0),t}r=r.sort((o,i)=>i.mtime-o.mtime).slice(0,nn);for(let o of r)try{if(o.size>rn)throw new Error("snapshot too large");dn(Kt(o.path,"utf8"),t)}catch(i){ge(i)||(t.uncertain=!0)}return t}function ze(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=>fn.test(o))}var _n="exec-probe.json",bn=6e4;function yn(){return Be(E(),_n)}function wn(e){try{let t=JSON.parse(Je(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 Sn(e,t){try{mn(Be(e,".."),{recursive:!0,mode:448});let n=`${e}.${process.pid}.tmp`;kn(n,JSON.stringify(t),{mode:384}),gn(n,e)}catch{}}function xn(e){try{return pn(e,["--native-check"],{encoding:"utf8",timeout:2e3,maxBuffer:1024,stdio:["ignore","pipe","ignore"],windowsHide:!0}).startsWith("tokmizer-native ")}catch{return!1}}function An(e,t){try{let r=Je(e,"utf8").split(`
14
+ `,1)[0].slice(2).trim().split(/\s+/),o=r[0]??"";return o==="/usr/bin/env"?N(r[1]??"",void 0,t):J(o)}catch{return!1}}function $n(e,t,n){try{let r=hn(e);return[e,r.size,r.mtimeMs,r.ino,r.mode,t?n??"":""].join("|")}catch{return`${e}|missing`}}function ke(e,t=process.platform,n=process.env.PATH,r=yn(),o=Date.now()){let i=t!=="win32"&&he(e)==="#!",s=$n(e,i,n),l=wn(r);if(l?.key===s&&(l.ok||o-l.at<bn))return l.ok;let u=J(e,t)&&(i?An(e,n):xn(e));return Sn(r,{key:s,ok:u,at:o,skipped:(l?.skipped??0)+(u?0:1)}),u}var On=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"]),vn=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"]),We=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),Ge="(?:dev|start|serve|watch|preview)",Rn=new RegExp(`^(?:\\S*/)?(?:bun\\s+(?:install|i|add|remove|rm|update|outdated|audit|test|build|pm|x)(?:\\s|$)|bun\\s+run\\s+(?!${Ge}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|deno\\s+(?:test|lint|fmt|check|compile|install|info|doc|bench|outdated)(?:\\s|$)|deno\\s+task\\s+(?!${Ge}(?:\\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)`),Pn=/(?:^|\s)--watch(?:\s|=|$)/;function In(e){return Rn.test(e)&&!Pn.test(e)}var Nn=/^((?:\S*\/)?(sh|bash|zsh|dash|ksh|fish)\s+(-[elux]*c[elux]*)\s+)(['"])/,Hn=/[()$]|(?:^|[;&|\n]\s*)(?:and|or|not|begin|end|if|else|switch|case|while|for|function|return)(?:\s|;|$)/,Qe=3;function et(e){let t=Nn.exec(e);if(!t)return null;let n=t[2]==="fish";if(n&&t[3]!=="-c")return null;let r=t[4],o=t[1].length+1,i=e.indexOf(r,o);if(i<=o)return null;let s=e.slice(i+1);if(s&&!/^\s/.test(s))return null;let l=e.slice(o,i);return r==='"'&&/[$`\\!]/.test(l)||n&&Hn.test(l)?null:{script:l,start:o,end:i,quote:r}}var Ln=new Set(["cd","export","set","unset","source",".","true",":","pushd","popd"]);function Dn(e){return ye(e).filter(n=>{if(n.kind!=="cmd"||n.unsafe)return!1;let r=nt(n.text);return r!==""&&!Ln.has(r)&&!be.test(r)}).length>1}function jn(e,t,n,r,o){if(n>=Qe)return null;let i=et(e);if(!i)return null;let{script:s,start:l,end:u,quote:a}=i,c=[],d=rt(s,t,n+1,r,$=>c.push($));if(d===s||a==='"'&&/["$`]/.test(d))return null;let _=a==="'"?d.replace(/'/g,"'\\''"):d,m=`${e.slice(0,l)}${_}${e.slice(u)}`,h=Dn(s);if(o)for(let $ of h?[e,...c]:c)o($);return h?`${t} ${m}`:m}var Ze=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,Fn=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]);function Mn(e,t){let n=oe(t);return n==="tail"||n==="journalctl"?Ze.test(e):n==="stern"?!0:Fn.has(n)?/\blogs?\b/.test(e)&&Ze.test(e):!1}var be=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,Un=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,zn=/(?:^|[;&|\n({])\s*[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/;function oe(e){let t=e.lastIndexOf("/");return t===-1?e:e.slice(t+1)}function tt(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 Ve(e){let t=tt(e);if(!t)return!0;for(let n=0;n<e.length;n++)if(t[n]&&e[n]===">")return!0;return!1}function ye(e){let t=tt(e);if(!t)return[{kind:"cmd",text:e,unsafe:!0}];let n=[],r="",o=0,i=()=>{r.length>0&&(n.push({kind:"cmd",text:r}),r="")},s=(l,u)=>{i(),n.push({kind:"sep",text:l}),o+=u};for(;o<e.length;){let l=e[o],u=e[o+1];if(t[o]){if(l===">"&&u==="|"){r+=">|",o+=2;continue}if(l==="&"&&u==="&"){s("&&",2);continue}if(l==="&"&&u!==">"){let a=r.replace(/\s+$/,""),c=a[a.length-1];if(c!==">"&&c!=="<"&&c!=="&"){s("&",1);continue}}if(l==="|"&&u==="|"){s("||",2);continue}if(l==="|"&&u==="&"){s("|&",2);continue}if(l===";"&&u===";"){let a=e[o+2]==="&";s(a?";;&":";;",a?3:2);continue}if(l===";"||l===`
15
+ `||l==="|"){s(l,1);continue}}r+=l,o+=1}return i(),n}function nt(e){return e.trim().split(/\s+/)[0]??""}function x(e,t=process.platform){try{let n=Xe(Cn(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(B(l))return ke(l,t)?`'${l.replace(/\\/g,"/").replace(/'/g,"'\\''")}'`:null}let i=p(n,"..","bin","tkr-exec");if(!r&&B(i))return ke(i,t)?`${o}'${i.replace(/'/g,"'\\''")}'`:null;if(Y()){let l=r?process.execPath.replace(/\\/g,"/"):process.execPath;return`${o}'${l.replace(/'/g,"'\\''")}' exec`}let s=p(n,"..","bin","tkr-exec.js");return B(s)?`${o}node '${s.replace(/'/g,"'\\''")}'`:null}catch{return null}}function Jn(e,t="tkr-exec",n=()=>!0,r){return rt(e,t,0,n,r)}function rt(e,t,n,r,o){if(e.includes("<<")||zn.test(e))return e;let i=ye(e),s=[];for(let l=0;l<i.length;l++){let u=i[l];if(u.kind==="sep"||u.unsafe){s.push(u.text);continue}let a=u.text.trim();if(!a){s.push(u.text);continue}let c=nt(a),d=i[l+1],_=d?.kind==="sep"&&(d.text==="|"||d.text==="|&"),m=d?.kind==="sep"&&d.text==="&",h=!_&&!m&&!Ve(u.text)&&!u.text.includes("<(")&&!u.text.includes(">(")?jn(a,t,n,r,o):null;if(h!==null){s.push(`${u.text.match(/^\s*/)?.[0]??""}${h}${u.text.match(/\s*$/)?.[0]??""}`);continue}if(a===t||a.startsWith(t)&&/^\s/.test(a.slice(t.length))||On.has(c)||vn.has(c)||(We.has(c)||We.has(oe(c)))&&!In(a)||be.test(c)||c.startsWith("(")||c.startsWith("#")||c.startsWith("<")||c.startsWith(">")||Un.test(a)||Mn(a,c)||c.endsWith(")")||_||m||Ve(u.text)||u.text.includes("<(")||u.text.includes(">(")||c==="node"&&a.includes("tkr-exec.js")||!r(c)){s.push(u.text);continue}let $=u.text.match(/^\s*/)?.[0]??"",w=u.text.match(/\s*$/)?.[0]??"";o?.(a),s.push(`${$}${t} ${a}${w}`)}return s.join("")}var Bn=new Set(["command","workdir","timeout_ms","yield_time_ms","max_output_tokens","shell","login","tty","description"]),Wn=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"]),Gn=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),Zn={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/},ne=["test","run test","run build","run lint","run typecheck"],Vn={npm:new Set(ne),pnpm:new Set([...ne,"build","lint","typecheck"]),yarn:new Set([...ne,"build","lint","typecheck"]),bun:new Set(ne),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"])},qn=new Set(["pytest","tsc","vitest","jest","eslint","mypy"]);function ot(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 ye(e)){if(r.kind==="sep")continue;if(r.unsafe)return!1;let o=n<Qe?et(r.text.trim()):null;if(o){if(!ot(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=>be.test(a)))return!1;let s=oe(i[0]);if(s!==i[0])return!1;let l=Zn[s];if(l&&i.slice(1).some(a=>l.test(a)))return!1;if((s==="git"?Gn.has(i[1]??""):Wn.has(s))||t&&qn.has(s))continue;let u=t?Vn[s]:void 0;if(!(u&&(u.has(i[1]??"")||i[1]==="run"&&u.has(`run ${i[2]??""}`))))return!1}return!0}function it(e,t,n=x(t),r=y,o=ie(),i=process.env.PATH,s=we){if(!g(e)||e.tool_name!=="Bash"||t==="claude-code"&&Yn(s()))return null;let l=e.tool_input;if(!g(l)||l.run_in_background)return null;let u=l.command;if(typeof u!="string"||!u||t==="codex"&&Object.keys(l).some($=>!Bn.has($)))return null;let a=typeof e.cwd=="string"&&e.cwd?e.cwd:l.workdir,c=typeof a=="string"&&a?a:void 0,d=typeof e.session_id=="string"&&e.session_id?e.session_id:"unknown",_=typeof e.permission_mode=="string"?e.permission_mode:void 0,m=pt(u,{host:t,sessionId:d,cwd:c,claudeDirs:o,pathEnv:i,permissionMode:_},n,r);if(!m)return null;let h={...l,command:m.command};return JSON.stringify({hookSpecificOutput:t==="codex"?{hookEventName:"PreToolUse",permissionDecision:"allow",updatedInput:h}:m.allowedBy?{hookEventName:"PreToolUse",permissionDecision:"allow",permissionDecisionReason:`Tokmizer: allowed by your rule ${m.allowedBy}`,updatedInput:h}:{hookEventName:"PreToolUse",updatedInput:h}})}var Kn=/(?:^|\s)--(?:disallowedTools|disallowed-tools|settings|setting-sources)(?:[=\s]|$)/;function we(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=Tn("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 Yn(e){return e===null||Kn.test(e)}function Xn(e,t){if(!B(e))return"missing";try{let n=W(e,"utf8");return JSON.parse(t?st(n):n)}catch{return"unreadable"}}function st(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
+ `;)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 Z(e){let t=[],n=En(e);for(;;){t.push(n);let r=Xe(n);if(r===n)return t;n=r}}function Qn(){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 re(p(e,"managed-settings.d")))n.endsWith(".json")&&t.push(p(e,"managed-settings.d",n))}catch{return t}return t}function V(e,t,n,r){let o=[];for(let i of e){let s=Xn(i,t);if(s!=="missing"&&(s==="unreadable"||!g(s)||!n(s,o)))return"unreadable"}return{matchers:o,complete:r}}function G(e){return e===void 0?[]:Array.isArray(e)?e.filter(t=>typeof t=="string"):null}function ie(){return{projectDir:process.env.CLAUDE_PROJECT_DIR,configDir:process.env.CLAUDE_CONFIG_DIR}}function er(e,t){let n=w=>[p(w,"settings.json"),p(w,"settings.local.json")],r=w=>n(p(w,".claude")),o=p(R(),".claude"),i=t.configDir||o,s=[[Qn(),"managed"],[[p(i,"settings.json")],"loaded"],[[p(i,"settings.local.json")],"loadedLocal"],[t.configDir?n(o):[],"extra"],[t.projectDir?r(t.projectDir):[],"project"],[Z(e).flatMap(r),"extra"]],l=[],u={managed:[],loaded:[],loadedLocal:[],project:[],extra:[]},a={managed:!1,loaded:!1,loadedLocal:!1,project:!1,extra:!1},c=!1,d="managed",_=(w,fe)=>{let C=w.permissions;if(d==="managed"&&(w.allowManagedPermissionRulesOnly===!0||g(C)&&C.allowManagedPermissionRulesOnly===!0)&&(c=!0),C===void 0)return!0;if(!g(C))return!1;for(let Te of["deny","ask","allow"]){let Ce=G(C[Te]);if(!Ce)return!1;for(let Ee of Ce){let I=/^\s*Bash\s*(?:\(([\s\S]*)\))?\s*$/.exec(Ee);if(I)if(Te!=="allow")fe.push(P((I[1]??"*").replace(/:\*$/," *")));else if(I[1]===void 0||I[1].trim()==="*")a[d]=!0;else{l.push(P(I[1].replace(/:\*$/," *")));let Oe=yr(I[1]);Oe&&u[d].push({rule:Ee.trim(),matches:Oe})}}}return!0},m=[];for(let[w,fe]of s){d=fe;let C=V(w,!1,_,!0);if(C==="unreadable")return"unreadable";m.push(...C.matchers)}let h=a.managed||(a.loaded||a.loadedLocal)&&!c,$=[...u.managed,...c?[]:u.loaded];return{matchers:[...m,...h?[]:l],complete:!0,allow:l,allowsEverything:h,guards:m,trustedAllow:$}}function tr(e){let t=[p(R(),".cursor","cli-config.json"),...Z(e).map(n=>p(n,".cursor","cli.json"))];return V(t,!0,(n,r)=>{let o=n.permissions;if(o===void 0)return!0;if(!g(o))return!1;let i=G(o.deny);if(!i)return!1;for(let s of i){let l=/^\s*Shell\s*(?:\(([\s\S]*)\))?\s*$/.exec(s);if(!l)continue;let u=l[1]??"*",a=u.indexOf(":");r.push(P(a===-1?`${u} *`:`${u.slice(0,a)} ${u.slice(a+1)}`))}return!0},!1)}function nr(){return process.platform==="darwin"?"/Library/Application Support/GeminiCli":process.platform==="win32"?"C:\\ProgramData\\gemini-cli":"/etc/gemini-cli"}var lt=/^\s*(?:run_shell_command|ShellTool)\s*(?:\(([\s\S]*)\))?\s*$/;function rr(e,t){let n=e.tools;if(n!==void 0&&!g(n))return!1;let r=[G(e.excludeTools),G(g(n)?n.exclude:void 0)];for(let o of r){if(!o)return!1;for(let i of o){let s=lt.exec(i);s&&t.push(P(s[1]===void 0?"*":`${s[1]}*`))}}return!0}function qe(e){try{return JSON.parse(e)}catch{return null}}function or(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]??qe(`"${r[1]}"`);if(o===null)return null;n.push(o)}return n}if(t.startsWith('"')){let n=/^"((?:\\.|[^"\\])*)"/.exec(t);return n?qe(`"${n[1]}"`):null}if(t.startsWith("'")){let n=/^'([^']*)'/.exec(t);return n?n[1]:null}return t.replace(/\s*#.*$/,"")}function ir(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=or(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==="*"||lt.test(u)))continue;let s=r.commandPrefix===void 0?[]:[r.commandPrefix].flat(),l=[r.commandRegex,r.argsPattern].flat().filter(u=>typeof u=="string");if(s.length===0&&l.length===0){t.push(()=>!0);continue}for(let u of s)t.push(P(`${u}*`));for(let u of l){let a;try{a=new RegExp(u)}catch{return!1}t.push(c=>a.test(JSON.stringify({command:c}))||se(a,c))}}return!0}function Ke(e){try{return re(e).filter(t=>t.endsWith(".toml")).map(t=>p(e,t))}catch{return[]}}function sr(e){let t=nr(),n=[p(t,"system-defaults.json"),p(t,"settings.json"),process.env.GEMINI_CLI_SYSTEM_SETTINGS_PATH,process.env.GEMINI_CLI_SYSTEM_DEFAULTS_PATH,p(R(),".gemini","settings.json"),...Z(e).map(o=>p(o,".gemini","settings.json"))].filter(o=>!!o),r=V(n,!0,rr,!1);if(r==="unreadable")return r;for(let o of[...Ke(p(R(),".gemini","policies")),...Ke(p(t,"policies"))]){let i;try{i=W(o,"utf8")}catch{return"unreadable"}if(!ir(i,r.matchers))return"unreadable"}return r}function _e(e,t){if(e===void 0)return!0;if(typeof e=="string")return e!=="allow"&&t.push(()=>!0),!0;if(!g(e))return!1;for(let n of["bash","shell","*"]){let r=e[n];if(r!==void 0){if(typeof r=="string"){r!=="allow"&&t.push(()=>!0);continue}if(!g(r))return!1;for(let[o,i]of Object.entries(r))i!=="allow"&&t.push(P(o.replace(/\?/g,"*")))}}return!0}function Ye(e,t){if(e.permissions!==void 0||!_e(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||!_e(o.permission,t)))return!1}}return!0}function lr(e){for(let t of e)for(let n of["agent","agents","mode","modes"]){let r;try{r=re(p(t,n))}catch{continue}for(let o of r)try{if(o.endsWith(".md")&&/permission/i.test(W(p(t,n,o),"utf8")))return!0}catch{return!0}}return!1}function ur(e){let t=p(process.env.XDG_CONFIG_HOME||p(R(),".config"),"opencode"),n=Z(e),r=[t,...n.map(l=>p(l,".opencode"))];if(lr(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=V(i,!0,Ye,!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(st(l))}catch{return"unreadable"}if(!(l===process.env.OPENCODE_PERMISSION?_e(u,s.matchers):g(u)&&Ye(u,s.matchers)))return"unreadable"}return s}function ar(){return V([p(R(),".gemini","antigravity-cli","settings.json")],!0,(e,t)=>{let n=e.permissions;if(n===void 0)return!0;if(!g(n))return!1;for(let r of["deny","ask"]){let o=G(n[r]);if(!o)return!1;for(let i of o){let s=/^\s*command\s*\(([\s\S]*)\)\s*$/.exec(i);if(!s)continue;let l=s[1].trim();if(!l.startsWith("regex:")){t.push(P(l==="*"?"*":`${l} *`));continue}let u;try{u=new RegExp(l.slice(6))}catch{return!1}t.push(a=>se(u,a))}}return!0},!1)}function cr(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 ut(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=ut(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 at(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(Se).join("|")})`)}let n=new RegExp(`^${t.join(" ")}(?= |$)`);return r=>se(n,r)}function fr(e,t){let n=cr(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]=ut(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=at(i.pattern);if(!l)return!1;s!=="allow"&&t.push(l)}return!0}function dr(e){if(!B(e))return[];try{return re(e).filter(t=>t.endsWith(".rules")).sort().map(t=>p(e,t))}catch{return"unreadable"}}function pr(){return process.platform==="win32"?p(process.env.ProgramData||"C:\\ProgramData","OpenAI","Codex","requirements.toml"):"/etc/codex/requirements.toml"}function mr(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 gr(e,t){let n;try{n=me(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(mr);if(i.some(l=>l===void 0))return!1;let s=at(i);if(!s)return!1;t.push(s)}return!0}function hr(e){let t=process.env.CODEX_HOME||p(R(),".codex"),n=[p(t,"rules"),...Z(e).map(i=>p(i,".codex","rules"))],r=[],o=null;try{o=W(pr(),"utf8")}catch(i){let s=i.code;if(s!=="ENOENT"&&s!=="ENOTDIR")return"unreadable"}if(o!==null&&!gr(o,r))return"unreadable";for(let i of[...new Set(n)]){let s=dr(i);if(s==="unreadable")return"unreadable";for(let l of s){let u;try{u=W(l,"utf8")}catch{return"unreadable"}if(!fr(u,r))return"unreadable"}}return{matchers:r,complete:!1}}function g(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function Se(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function kr(e){let t=e.trim().replace(/\s+/g," "),n=t.endsWith(" *")&&t.length>2,r=(n?t.slice(0,-2):t).split("*").map(Se).join("[\\s\\S]*");return new RegExp(`^${r}${n?"(?: [\\s\\S]*)?":""}(?= |$)`)}var _r=512;function br(e){let t=e.replace(/['"\\]/g,"").split(/[\s;&|(){}<>`$]+/).filter(Boolean);return[t,t.map(oe)]}function se(e,t){if(e.test(t)||e.test(t.trim().replace(/\s+/g," ")))return!0;for(let n of br(t)){if(n.length>_r)return!0;for(let r=0;r<n.length;r++)if(e.test(n.slice(r).join(" ")))return!0}return!1}function P(e){let t=kr(e);return n=>se(t,n)}function yr(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(`^${Se(r)}${n?"(?: [\\s\\S]*)?":""}$`);return i=>o.test(i)}var wr={"claude-code":er,cursor:tr,"gemini-cli":sr,opencode:ur,antigravity:ar,codex:hr},Sr=new Set(["codex"]),ct=/(?:^|[\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 xr(e,t,n){let r=wr[e];return r?r(t??process.cwd(),n):{matchers:[],complete:!1}}function Ar(e,t,n){return e==="unreadable"||ct.test(t.replace(/['"\\]/g,""))||e.matchers.some(r=>r(t))?!1:e.complete||ot(t,!Sr.has(n))}var ft=new Set(["default","acceptEdits","dontAsk"]);function dt(e,t){return t.host!=="claude-code"||t.permissionMode==="bypassPermissions"?!0:e!=="unreadable"&&e.allowsEverything===!0&&ft.has(t.permissionMode??"")}function $r(e,t){let n="pathEnv"in e?e.pathEnv:process.env.PATH,r;return o=>e.host!=="claude-code"?N(o,e.cwd,n):(r??=Ue(t.configDir),!N(o,e.cwd,n)&&!r.paths.some(i=>N(o,e.cwd,i))?!1:o.includes("/")||!ze(o,r))}var Tr=/^[^\s;&|<>()$`\\{}*?[\]~#!]+(?: [^\s;&|<>()$`\\{}*?[\]~#!]+)*$/;function Cr(e,t,n){return n.host!=="claude-code"||e==="unreadable"||dt(e,n)||!ft.has(n.permissionMode??"")||!Tr.test(t)||ct.test(t.replace(/['"]/g,""))||(e.guards??[]).some(r=>r(t))?null:(e.trustedAllow??[]).find(r=>r.matches(t))?.rule??null}function pt(e,t,n,r){if(!n||/["\\$`;&|<>(){}]|'\\''/.test(n))return null;let o=t.claudeDirs??ie(),i=xr(t.host,t.cwd,o),s=Cr(i,e,t),l=s||Ar(i,e,t.host)?Jn(e,n,$r(t,o)):e;return l!==e&&i!=="unreadable"&&(s?(i.guards??[]).some(u=>u(l)):i.matchers.some(u=>u(l))||(i.allow??[]).some(u=>u(l)&&!u(e)))&&(l=e),r(t.sessionId,l!==e),l===e?null:s?{command:l,allowedBy:s}:dt(i,t)?{command:l}:null}function O(e,t,n,r){return pt(e,t,n,r)?.command??null}function H(e,t,n="unknown",r=x(t),o=y){return e?O(e,{host:t,sessionId:n},A()?null:r,o):null}function k(e,t){let n=e[t];return typeof n=="string"&&n?n:null}function q(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function Er(e){return k(e,"prompt_id")||k(e,"scratchpad_dir")?!0:q(e.effort)}function Or(e){return k(e,"tool_use_id")?.startsWith("toolu_")===!0||/^claude/i.test(k(e,"model")??"")}var vr=new Set(["BeforeTool","AfterTool","BeforeAgent","AfterAgent","BeforeModel","AfterModel","BeforeToolSelection"]),Rr=new Set(["preToolUse","postToolUse","beforeShellExecution","afterShellExecution","beforeSubmitPrompt","sessionStart","sessionEnd","stop"]),Pr=new Set(["pre_tool","post_tool"]),Ir=new Set(["before_tool_call","after_tool_call"]),Nr=new Set(["runTerminalCommand","run_in_terminal"]),Hr=[["codex",e=>k(e,"turn_id")!==null],["claude-code",Er],["cursor",e=>k(e,"cursor_version")!==null||k(e,"generation_id")!==null||k(e,"conversation_id")!==null||Array.isArray(e.workspace_roots)||Rr.has(k(e,"hook_event_name")??"")],["gemini-cli",e=>vr.has(k(e,"hook_event_name")??"")],["qwen-code",e=>e.hook_event_name==="PreToolUse"&&e.tool_name==="run_shell_command"],["vibe",e=>Pr.has(k(e,"hook_event_name")??"")],["antigravity",e=>q(e.toolCall)],["copilot",e=>k(e,"toolName")!==null&&"toolArgs"in e||Nr.has(k(e,"tool_name")??"")],["grok",e=>e.toolName==="run_terminal_command"||e.tool_name==="run_terminal_command"||q(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&&!Ir.has(k(e,"event"))]],Lr=new Set(["codex","antigravity"]);function Dr(e){return q(e)?Hr.filter(([,t])=>t(e)).map(([t])=>t):[]}function mt(e,t){if(!q(e))return null;let n=Dr(e);return n.length>1?null:n.length===1?n[0]:Or(e)&&Lr.has(t)?"claude-code":t==="codex"?null:t}var xe=JSON.stringify({permission:"allow"});function gt(e,t=x("cursor"),n=y){if(e.tool_name!=="Shell")return xe;let r=e.tool_input??{},o=r.command;if(typeof o!="string"||!o)return xe;let i=typeof r.working_directory=="string"?r.working_directory:void 0,s=O(o,{host:"cursor",sessionId:e.conversation_id??"unknown",cwd:i},A()?null:t,n);return s?JSON.stringify({permission:"allow",updated_input:{...r,command:s}}):xe}var le="{}";function ht(e,t=x("gemini-cli"),n=y){if(e.hook_event_name!=="BeforeTool"||e.tool_name!=="run_shell_command")return le;let r=e.tool_input??{};if(r.is_background)return le;let o=r.command;if(typeof o!="string"||!o)return le;let i=typeof e.cwd=="string"?e.cwd:void 0,s=O(o,{host:"gemini-cli",sessionId:e.session_id??"unknown",cwd:i},A()?null:t,n);return s?JSON.stringify({hookSpecificOutput:{tool_input:{command:s}}}):le}var T="{}",jr=new Set(["runTerminalCommand","run_in_terminal","Bash","bash"]),Fr=["run_in_background","is_background","isBackground"];function ue(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function Mr(e){let t=e.session_id??e.sessionId;return typeof t=="string"&&t?t:"unknown"}function Ur(e,t){let n=e.cwd??t.cwd??t.workdir??t.working_directory;return typeof n=="string"&&n?n:void 0}function ae(e,t,n,r,o){if(!ue(t)||Fr.some(s=>t[s]===!0))return null;let i=t.command;return typeof i!="string"||!i?null:O(i,{host:e,sessionId:Mr(n),cwd:Ur(n,t)},A()?null:r,o)}function D(e,t){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",updatedInput:{...e,command:t}}})}function zr(e){if(ue(e))return e;if(typeof e!="string")return null;try{let t=JSON.parse(e);return ue(t)?t:null}catch{return null}}function Jr(e,t,n){if(typeof e.tool_name=="string"){if(!jr.has(e.tool_name))return T;let i=e.tool_input,s=ae("copilot",i,e,t,n);return s?D(i,s):T}if(e.toolName!=="bash")return T;let r=zr(e.toolArgs),o=ae("copilot",r,e,t,n);return o?JSON.stringify({modifiedArgs:{...r,command:o}}):T}function L(e,t,n){return(r,o,i)=>{if(r.tool_name!==t)return T;let s=r.tool_input,l=ae(e,s,r,o,i);return l?n(s,l):T}}var Br=new Set(["run_terminal_command","Bash","bash"]);function Wr(e,t,n){let r=e.toolName??e.tool_name;if(typeof r!="string"||!Br.has(r))return T;let o=e.toolInput??e.tool_input,i=ae("grok",o,e,t,n);return i?D(o,i):T}var Gr={copilot:Jr,droid:L("droid","Execute",D),trae:L("trae","RunCommand",D),"qwen-code":L("qwen-code","run_shell_command",D),crush:L("crush","bash",(e,t)=>JSON.stringify({updated_input:{command:t}})),junie:L("junie","Bash",(e,t)=>JSON.stringify({updatedInput:{...e,command:t}})),zcode:L("zcode","Bash",D),grok:Wr};function kt(e,t,n=x(e),r=y){return ue(t)?Gr[e](t,n,r):T}function j(e){return A()?null:x(e)}function Zr(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"?"":it(t,e,j(e),r,n.claudeDirs??ie(),n.pathEnv??process.env.PATH,n.launchArgs??we)??"";case"cursor":return gt(t,j(e),r);case"gemini-cli":return ht(t,j(e),r);case"vibe":return Ae(t,(o,i)=>H(o,"vibe",i,j(e),r));case"antigravity":return $e(t,(o,i)=>H(o,"antigravity",i,j(e),r));default:return kt(e,t,j(e),r)}}function K(e,t,n={}){let r=mt(e,t);return r?Zr(r,e,n):n.fallback??""}var Vr=new Set(["bash","file_system.bash"]),ce=JSON.stringify({decision:"allow"});function Ae(e,t=(n,r)=>H(n,"vibe",r)){if(!v(e)||e.hook_event_name!=="pre_tool"||typeof e.tool_name!="string"||!Vr.has(e.tool_name))return"";let n=e.tool_input;if(!v(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 $e(e,t=(n,r)=>H(n,"antigravity",r)){if(!v(e)||!v(e.toolCall)||e.toolCall.name!=="run_command")return ce;let n=e.toolCall.args;if(!v(n)||typeof n.CommandLine!="string"||!n.CommandLine)return ce;let r=t(n.CommandLine,typeof e.conversationId=="string"?e.conversationId:"unknown");return r?JSON.stringify({decision:"allow",overwrite:{CommandLine:r}}):ce}var _t={vibe:{build:e=>Ae(e),fallback:""},antigravity:{build:e=>$e(e),fallback:ce}};function bt(e){return _t[e??""]?.fallback??""}function qr(e,t){let n=_t[e??""];if(!n)return"";let r;try{r=JSON.parse(t.replace(/^/,""))}catch{return n.fallback}return v(r)?K(r,e,{fallback:n.fallback}):n.build(r)}async function yt(e){process.stdout.write(qr(e,await F()))}yt(process.argv[2]).catch(e=>{process.stderr.write(`tkr-agent-hook: ${e.message}
18
+ `),process.stdout.write(bt(process.argv[2])),process.exit(0)});
19
+ /*! Bundled license information:
20
+
21
+ smol-toml/dist/error.js:
22
+ smol-toml/dist/primitive.js:
23
+ smol-toml/dist/date.js:
24
+ smol-toml/dist/extract.js:
25
+ smol-toml/dist/util.js:
26
+ smol-toml/dist/struct.js:
27
+ smol-toml/dist/parse.js:
28
+ smol-toml/dist/stringify.js:
29
+ smol-toml/dist/index.js:
30
+ (*!
31
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
32
+ * SPDX-License-Identifier: BSD-3-Clause
33
+ *
34
+ * Redistribution and use in source and binary forms, with or without
35
+ * modification, are permitted provided that the following conditions are met:
36
+ *
37
+ * 1. Redistributions of source code must retain the above copyright notice, this
38
+ * list of conditions and the following disclaimer.
39
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
40
+ * this list of conditions and the following disclaimer in the
41
+ * documentation and/or other materials provided with the distribution.
42
+ * 3. Neither the name of the copyright holder nor the names of its contributors
43
+ * may be used to endorse or promote products derived from this software without
44
+ * specific prior written permission.
45
+ *
46
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
47
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
48
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
49
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
50
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
52
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
53
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56
+ *)
57
+ */