@tokmizer/plugin 0.9.64 → 0.9.66
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/LICENSES.md +1 -1
- package/README.md +5 -4
- package/dist/bin/tkr-agent-hook.js +10 -10
- package/dist/bin/tkr-codex-hook.js +68 -68
- package/dist/bin/tkr-copilot-hook.js +9 -9
- package/dist/bin/tkr-crush-hook.js +9 -9
- package/dist/bin/tkr-cursor-hook.js +9 -9
- package/dist/bin/tkr-daemon.js +135 -117
- package/dist/bin/tkr-droid-hook.js +9 -9
- package/dist/bin/tkr-exec +78 -73
- package/dist/bin/tkr-exec.js +78 -73
- package/dist/bin/tkr-gemini-hook.js +9 -9
- package/dist/bin/tkr-grok-hook.js +9 -9
- package/dist/bin/tkr-junie-hook.js +9 -9
- package/dist/bin/tkr-processor.js +96 -91
- package/dist/bin/tkr-qwen-hook.js +9 -9
- package/dist/bin/tkr-shim.js +80 -75
- package/dist/bin/tkr-trae-hook.js +9 -9
- package/dist/bin/tkr-zcode-hook.js +9 -9
- package/dist/bin/tkr.js +271 -257
- package/dist/hooks-host/post-tool-use.js +89 -84
- package/dist/hooks-host/pre-tool-use.js +10 -10
- package/dist/hooks-host/reducer-stop.js +27 -24
- package/dist/hooks-host/session-recap.js +1 -1
- package/dist/index.js +96 -83
- 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/hooks/on-session-start.mjs +9 -1
- package/package.json +8 -8
- package/scripts/install-mac-linux.sh +47 -0
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
|
-
|
|
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.
|
package/README.md
CHANGED
|
@@ -232,17 +232,18 @@ The percentages in `tkr gain` measure byte reduction. A byte percentage can diff
|
|
|
232
232
|
|
|
233
233
|
## Restoring shortened output
|
|
234
234
|
|
|
235
|
-
When Tokmizer shortens an output it can add a `[tkr restore <hash>]` hint. `tkr restore <hash>` prints the complete original output when it is at most 8 MB; for a larger output, the entry holds only the part that was left out and `tkr restore` says so. A unique prefix of the hash is enough.
|
|
235
|
+
When Tokmizer shortens an output it can add a `[tkr restore <hash>]` hint. `tkr restore <hash>` prints the complete original output when it is at most 8 MB, except detected secrets, which are masked; for a larger output, the entry holds only the part that was left out and `tkr restore` says so. A unique prefix of the hash is enough.
|
|
236
236
|
|
|
237
237
|
| Command | Effect |
|
|
238
238
|
| --- | --- |
|
|
239
239
|
| `tkr restore <hash>` | Print the cached output |
|
|
240
240
|
| `tkr restore <hash> --lines 120:180` | Print only lines 120 to 180 (`120:`, `:40` and `57` also work) |
|
|
241
241
|
| `tkr restore <hash> --grep <pattern>` | Print matching lines with their line numbers |
|
|
242
|
-
| `tkr restore --grep <pattern>` | Search
|
|
243
|
-
| `tkr restore --
|
|
242
|
+
| `tkr restore --grep <pattern>` | Search the cached outputs of the current project |
|
|
243
|
+
| `tkr restore --grep <pattern> --all-projects` | Search the cached outputs of every project |
|
|
244
|
+
| `tkr restore --list` | List this project's cached outputs with age, size, line count and command (`--all-projects` for every project) |
|
|
244
245
|
|
|
245
|
-
Entries are kept 30 days, up to 8 MB each and 200 MB in total; the oldest go first. `TOKMIZER_CCR_MAX_AGE_MS`, `TOKMIZER_CCR_ENTRY_MAX_BYTES` and `TOKMIZER_CCR_DIR_CAP_BYTES` change these limits, `TOKMIZER_CCR_DISABLED=1` turns copies off. `tkr gain` shows the restored tokens and the cache size.
|
|
246
|
+
Before a copy is saved, private keys, GitHub, npm, AWS, Slack and Stripe live tokens, `Authorization: Bearer` values and passwords in URLs are replaced by `[tkr: secret masked]`; the output your agent sees is unchanged. Entries are kept 30 days, up to 8 MB each and 200 MB in total; the oldest go first. `TOKMIZER_CCR_MAX_AGE_MS`, `TOKMIZER_CCR_ENTRY_MAX_BYTES` and `TOKMIZER_CCR_DIR_CAP_BYTES` change these limits, `TOKMIZER_CCR_DISABLED=1` turns copies off. `tkr gain` shows the restored tokens and the cache size.
|
|
246
247
|
|
|
247
248
|
## Measured comparison
|
|
248
249
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __tkrCreateRequire } from "node:module"; const require = __tkrCreateRequire(import.meta.url);
|
|
3
|
-
function L(
|
|
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=`${
|
|
3
|
+
function L(e=5e3){return new Promise(t=>{let n=[],r=process.stdin,o=!1,s=()=>{o||(o=!0,clearTimeout(c),r.off("data",i),r.pause(),r.unref?.(),t(Buffer.concat(n).toString("utf8")))},i=u=>{n.push(Buffer.isBuffer(u)?u:Buffer.from(u))},c=setTimeout(s,e);r.on("data",i).once("end",s).once("error",s),r.resume()})}function B(){return!1}import rt from"node:os";import{join as ot}from"node:path";function A(){return process.env.TOKMIZER_HOME||ot(rt.homedir(),".tokmizer")}import{rmSync as st,statSync as it}from"node:fs";import{join as ct}from"node:path";function be(){return ct(A(),"fail-open")}var ut=24*36e5;function S(e=Date.now()){try{if(e-it(be()).mtimeMs<ut)return!0;st(be(),{force:!0})}catch{}return!1}function v(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}var so=String.raw`(?:'(?:(?:[^']|'\\'')*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?'|"(?:[^"]*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?"|(?:[^\s'"]*[\\/])?tkr(?:\.(?:exe|cmd|bat|ps1))?)`;import{appendFileSync as mt,chmodSync as gt,mkdirSync as ht,existsSync as kt,readFileSync as ao,rmSync as fo}from"node:fs";import{dirname as _t,join as bt}from"node:path";import{readFileSync as at,renameSync as ft,statSync as dt,writeFileSync as pt}from"node:fs";function Se(e,t,n){try{if(dt(e).size<=t)return;let r=at(e,"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=`${e}.tmp-${process.pid}`;pt(i,o.length?`${o.join(`
|
|
5
5
|
`)}
|
|
6
|
-
`:"",{mode:384}),
|
|
7
|
-
`,{mode:384}),
|
|
8
|
-
`)){let o=
|
|
9
|
-
`,1)[0].slice(2).trim().split(/\s+/),o=r[0]??"";return o==="/usr/bin/env"?
|
|
10
|
-
`||c==="|"){i(c,1);continue}}r+=c,o+=1}return s(),n}function
|
|
11
|
-
`;)r++;
|
|
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=tn(t);for(;;){e.push(n);let r=Ht(n);if(r===n)return e;n=r}}function $n(){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=xn(s,e);if(i!=="missing"&&(i==="unreadable"||!m(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 vn(t,e){let n=_=>[f(_,"settings.json"),f(_,"settings.local.json")],r=_=>n(f(_,".claude")),o=f(C(),".claude"),s=e.configDir||o,i=[[$n(),"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",k=(_,Q)=>{let x=_.permissions;if(d==="managed"&&(_.allowManagedPermissionRulesOnly===!0||m(x)&&x.allowManagedPermissionRulesOnly===!0)&&(a=!0),x===void 0)return!0;if(!m(x))return!1;for(let dt of["deny","ask","allow"]){let pt=F(x[dt]);if(!pt)return!1;for(let mt of pt){let R=/^\s*Bash\s*(?:\(([\s\S]*)\))?\s*$/.exec(mt);if(R)if(dt!=="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 gt=Fn(R[1]);gt&&u[d].push({rule:mt.trim(),matches:gt})}}}return!0},g=[];for(let[_,Q]of i){d=Q;let x=D(_,!1,k,!0);if(x==="unreadable")return"unreadable";g.push(...x.matchers)}let w=l.managed||(l.loaded||l.loadedLocal)&&!a,A=[...u.managed,...a?[]:u.loaded];return{matchers:[...g,...w?[]:c],complete:!0,allow:c,allowsEverything:w,guards:g,trustedAllow:A}}function An(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(!m(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 En(){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 On(t,e){let n=t.tools;if(n!==void 0&&!m(n))return!1;let r=[F(t.excludeTools),F(m(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 Tt(t){try{return JSON.parse(t)}catch{return null}}function Rn(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]??Tt(`"${r[1]}"`);if(o===null)return null;n.push(o)}return n}if(e.startsWith('"')){let n=/^"((?:\\.|[^"\\])*)"/.exec(e);return n?Tt(`"${n[1]}"`):null}if(e.startsWith("'")){let n=/^'([^']*)'/.exec(e);return n?n[1]:null}return e.replace(/\s*#.*$/,"")}function Tn(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=Rn(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}))||ut(l,a))}}return!0}function Ct(t){try{return st(t).filter(e=>e.endsWith(".toml")).map(e=>f(t,e))}catch{return[]}}function Cn(t){let e=En(),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,On,!1);if(r==="unreadable")return r;for(let o of[...Ct(f(C(),".gemini","policies")),...Ct(f(e,"policies"))]){let s;try{s=ot(o,"utf8")}catch{return"unreadable"}if(!Tn(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(!m(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(!m(r))return!1;for(let[o,s]of Object.entries(r))s!=="allow"&&e.push(O(o.replace(/\?/g,"*")))}}return!0}function Pt(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(!m(r))return!1;for(let o of Object.values(r))if(m(o)&&(o.permissions!==void 0||!rt(o.permission,e)))return!1}}return!0}function Pn(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 Hn(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(Pn(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,Pt,!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(Ut(c))}catch{return"unreadable"}if(!(c===process.env.OPENCODE_PERMISSION?rt(u,i.matchers):m(u)&&Pt(u,i.matchers)))return"unreadable"}return i}function Nn(){return D([f(C(),".gemini","antigravity-cli","settings.json")],!0,(t,e)=>{let n=t.permissions;if(n===void 0)return!0;if(!m(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=>ut(u,l))}}return!0},!1)}function m(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}function Jt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function In(t){let e=t.trim().replace(/\s+/g," "),n=e.endsWith(" *")&&e.length>2,r=(n?e.slice(0,-2):e).split("*").map(Jt).join("[\\s\\S]*");return new RegExp(`^${r}${n?"(?: [\\s\\S]*)?":""}(?= |$)`)}var Ln=512;function jn(t){let e=t.replace(/['"\\]/g,"").split(/[\s;&|(){}<>`$]+/).filter(Boolean);return[e,e.map(G)]}function ut(t,e){if(t.test(e)||t.test(e.trim().replace(/\s+/g," ")))return!0;for(let n of jn(e)){if(n.length>Ln)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=In(t);return n=>ut(e,n)}function Fn(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(`^${Jt(r)}${n?"(?: [\\s\\S]*)?":""}$`);return s=>o.test(s)}var Dn={"claude-code":vn,cursor:An,"gemini-cli":Cn,opencode:Hn,antigravity:Nn},Mn=new Set(["codex"]),Bt=/(?:^|[\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 Un(t,e,n){let r=Dn[t];return r?r(e??process.cwd(),n):{matchers:[],complete:!1}}function zn(t,e,n){return t==="unreadable"||Bt.test(e.replace(/['"\\]/g,""))||t.matchers.some(r=>r(e))?!1:t.complete||Dt(e,!Mn.has(n))}var Wt=new Set(["default","acceptEdits","dontAsk"]);function Gt(t,e){return e.host!=="claude-code"||e.permissionMode==="bypassPermissions"?!0:t!=="unreadable"&&t.allowsEverything===!0&&Wt.has(e.permissionMode??"")}function Jn(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??=yt(e.configDir),!T(o,t.cwd,n)&&!r.paths.some(s=>T(o,t.cwd,s))?!1:o.includes("/")||!xt(o,r))}var Bn=/^[^\s;&|<>()$`\\{}*?[\]~#!]+(?: [^\s;&|<>()$`\\{}*?[\]~#!]+)*$/;function Wn(t,e,n){return n.host!=="claude-code"||t==="unreadable"||Gt(t,n)||!Wt.has(n.permissionMode??"")||!Bn.test(e)||Bt.test(e.replace(/['"]/g,""))||(t.guards??[]).some(r=>r(e))?null:(t.trustedAllow??[]).find(r=>r.matches(e))?.rule??null}function Zt(t,e,n,r){if(!n||/["\\$`;&|<>(){}]|'\\''/.test(n))return null;let o=e.claudeDirs??K(),s=Un(e.host,e.cwd,o),i=Wn(s,t,e),c=i||zn(s,t,e.host)?hn(t,n,Jn(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}:Gt(s,e)?{command:c}:null}function v(t,e,n,r){return Zt(t,e,n,r)?.command??null}function P(t,e,n="unknown",r=b(e),o=h){return t?v(t,{host:e,sessionId:n},S()?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 Gn(t){return p(t,"prompt_id")||p(t,"scratchpad_dir")?!0:M(t.effort)}function Zn(t){return p(t,"tool_use_id")?.startsWith("toolu_")===!0||/^claude/i.test(p(t,"model")??"")}var Kn=new Set(["BeforeTool","AfterTool","BeforeAgent","AfterAgent","BeforeModel","AfterModel","BeforeToolSelection"]),qn=new Set(["preToolUse","postToolUse","beforeShellExecution","afterShellExecution","beforeSubmitPrompt","sessionStart","sessionEnd","stop"]),Yn=new Set(["pre_tool","post_tool"]),Vn=new Set(["before_tool_call","after_tool_call"]),Xn=new Set(["runTerminalCommand","run_in_terminal"]),Qn=[["codex",t=>p(t,"turn_id")!==null],["claude-code",Gn],["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=>Kn.has(p(t,"hook_event_name")??"")],["qwen-code",t=>t.hook_event_name==="PreToolUse"&&t.tool_name==="run_shell_command"],["vibe",t=>Yn.has(p(t,"hook_event_name")??"")],["antigravity",t=>M(t.toolCall)],["copilot",t=>p(t,"toolName")!==null&&"toolArgs"in t||Xn.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&&!Vn.has(p(t,"event"))]],tr=new Set(["codex","antigravity"]);function er(t){return M(t)?Qn.filter(([,e])=>e(t)).map(([e])=>e):[]}function Kt(t,e){if(!M(t))return null;let n=er(t);return n.length>1?null:n.length===1?n[0]:Zn(t)&&tr.has(e)?"claude-code":e==="codex"?null:e}var lt=JSON.stringify({permission:"allow"});function qt(t,e=b("cursor"),n=h){if(t.tool_name!=="Shell")return lt;let r=t.tool_input??{},o=r.command;if(typeof o!="string"||!o)return lt;let s=typeof r.working_directory=="string"?r.working_directory:void 0,i=v(o,{host:"cursor",sessionId:t.conversation_id??"unknown",cwd:s},S()?null:e,n);return i?JSON.stringify({permission:"allow",updated_input:{...r,command:i}}):lt}var q="{}";function Yt(t,e=b("gemini-cli"),n=h){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=v(o,{host:"gemini-cli",sessionId:t.session_id??"unknown",cwd:s},S()?null:e,n);return i?JSON.stringify({hookSpecificOutput:{tool_input:{command:i}}}):q}var y="{}",nr=new Set(["runTerminalCommand","run_in_terminal","Bash","bash"]),rr=["run_in_background","is_background","isBackground"];function Y(t){return t!=null&&typeof t=="object"&&!Array.isArray(t)}function or(t){let e=t.session_id??t.sessionId;return typeof e=="string"&&e?e:"unknown"}function sr(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)||rr.some(i=>e[i]===!0))return null;let s=e.command;return typeof s!="string"||!s?null:v(s,{host:t,sessionId:or(n),cwd:sr(n,e)},S()?null:r,o)}function N(t,e){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",updatedInput:{...t,command:e}}})}function ir(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 cr(t,e,n){if(typeof t.tool_name=="string"){if(!nr.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=ir(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 ur=new Set(["run_terminal_command","Bash","bash"]);function lr(t,e,n){let r=t.toolName??t.tool_name;if(typeof r!="string"||!ur.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 ar={copilot:cr,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:lr};function Vt(t,e,n=b(t),r=h){return Y(e)?ar[t](e,n,r):y}function I(t){return S()?null:b(t)}function fr(t,e,n={}){let r=n.recordUsage??h;switch(t){case"claude-code":case"codex":return e.hook_event_name!==void 0&&e.hook_event_name!=="PreToolUse"?"":Mt(e,t,I(t),r,n.claudeDirs??K(),n.pathEnv??process.env.PATH)??"";case"cursor":return qt(e,I(t),r);case"gemini-cli":return Yt(e,I(t),r);case"vibe":return at(e,(o,s)=>P(o,"vibe",s,I(t),r));case"antigravity":return ft(e,(o,s)=>P(o,"antigravity",s,I(t),r));default:return Vt(t,e,I(t),r)}}function U(t,e,n={}){let r=Kt(t,e);return r?fr(r,t,n):n.fallback??""}var dr=new Set(["bash","file_system.bash"]),X=JSON.stringify({decision:"allow"});function at(t,e=(n,r)=>P(n,"vibe",r)){if(!E(t)||t.hook_event_name!=="pre_tool"||typeof t.tool_name!="string"||!dr.has(t.tool_name))return"";let n=t.tool_input;if(!E(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 ft(t,e=(n,r)=>P(n,"antigravity",r)){if(!E(t)||!E(t.toolCall)||t.toolCall.name!=="run_command")return X;let n=t.toolCall.args;if(!E(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 Xt={vibe:{build:t=>at(t),fallback:""},antigravity:{build:t=>ft(t),fallback:X}};function Qt(t){return Xt[t??""]?.fallback??""}function pr(t,e){let n=Xt[t??""];if(!n)return"";let r;try{r=JSON.parse(e.replace(/^/,""))}catch{return n.fallback}return E(r)?U(r,t,{fallback:n.fallback}):n.build(r)}async function te(t){process.stdout.write(pr(t,await L()))}te(process.argv[2]).catch(t=>{process.stderr.write(`tkr-agent-hook: ${t.message}
|
|
13
|
-
`),process.stdout.write(
|
|
6
|
+
`:"",{mode:384}),ft(i,e)}catch{}}var St="usage.jsonl";var we=2*1024*1024;function wt(){return bt(A(),St)}function k(e,t,n=wt()){try{let r=_t(n);kt(r)||ht(r,{recursive:!0,mode:448});let o=e.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";mt(n,`{"t":${Math.floor(Date.now()/1e3)},"s":"${o}","o":${t?1:0}}
|
|
7
|
+
`,{mode:384}),gt(n,384),Se(n,we,we/2)}catch{}}import{spawnSync as tn}from"node:child_process";import{existsSync as F,readFileSync as Z,readdirSync as V}from"node:fs";import{homedir as R}from"node:os";import{fileURLToPath as nn}from"node:url";import{dirname as Ie,join as a,resolve as rn}from"node:path";import{execFileSync as zt}from"node:child_process";import{mkdirSync as Jt,readFileSync as Ee,renameSync as Bt,statSync as Wt,writeFileSync as Gt}from"node:fs";import{join as ve}from"node:path";import{closeSync as yt,openSync as xt,readSync as $t,readdirSync as At,readFileSync as Et,statSync as xe}from"node:fs";import{homedir as vt}from"node:os";import{isAbsolute as Rt,join as W,resolve as Ot}from"node:path";var Tt=/^[A-Za-z0-9._+@%:,/-]+$/,Ct=new Set(["7f454c46","feedface","feedfacf","cefaedfe","cffaedfe","cafebabe","bebafeca"]),Pt=32,Ht=4*1024*1024;function oe(e){let t;try{t=xt(e,"r");let n=Buffer.alloc(4),r=$t(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&&yt(t)}}function j(e,t=process.platform){try{let n=xe(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&&Ct.has(r)}catch{return!1}}function Nt(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 C(e,t,n,r=process.platform){if(!Tt.test(e))return!1;let o=r==="win32";if(e.includes("/"))return j(Ot(t??process.cwd(),e),r);if(!n)return!1;let s=o?Nt(e):[e];for(let i of n.split(o?";":":"))if(!(!i||!Rt(i))){for(let c of s)if(j(W(i,c),r))return!0}return!1}var It=/^eval \$'([^\s'()=]+) \(\) /,Lt=/^([^\s'"()=]+) \(\) \{$/,jt=/^alias -- ([^\s=]+)=(.*)$/,Ft=/^# (?:Shell Options|Aliases|Shopt|Check for |Shadow )/,Dt=/^export PATH=(.*)$/,Mt=/^(?:--colou?r(?:=\S+)?|-G)$/;function ye(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 Ut(e,t){let n="";for(let r of e.split(`
|
|
8
|
+
`)){let o=Dt.exec(r);if(o&&n!=="# Functions"){let s=ye(o[1].trim());/[$`\\]/.test(s)||t.paths.push(s);continue}if(r.startsWith("# ")&&(n!=="# Functions"||Ft.test(r))){n=r;continue}if(n==="# Functions"){let s=It.exec(r)??Lt.exec(r);s&&t.functions.add(s[1])}else if(n==="# Aliases"){let s=jt.exec(r);s&&t.aliases.set(s[1],ye(s[2].trim()))}}}function re(e){return e?.code==="ENOENT"}function $e(e){let t={functions:new Set,aliases:new Map,paths:[],uncertain:!1},n=W(e||W(vt(),".claude"),"shell-snapshots"),r=[];try{for(let o of At(n)){if(!o.startsWith("snapshot-")||!o.endsWith(".sh"))continue;let s=W(n,o);try{let i=xe(s);i.isFile()&&r.push({path:s,mtime:i.mtimeMs,size:i.size})}catch(i){re(i)||(t.uncertain=!0)}}}catch(o){return re(o)||(t.uncertain=!0),t}r=r.sort((o,s)=>s.mtime-o.mtime).slice(0,Pt);for(let o of r)try{if(o.size>Ht)throw new Error("snapshot too large");Ut(Et(o.path,"utf8"),t)}catch(s){re(s)||(t.uncertain=!0)}return t}function Ae(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=>Mt.test(o))}var Zt="exec-probe.json",Vt=6e4;function Kt(){return ve(A(),Zt)}function qt(e){try{let t=JSON.parse(Ee(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 Yt(e,t){try{Jt(ve(e,".."),{recursive:!0,mode:448});let n=`${e}.${process.pid}.tmp`;Gt(n,JSON.stringify(t),{mode:384}),Bt(n,e)}catch{}}function Xt(e){try{return zt(e,["--native-check"],{encoding:"utf8",timeout:2e3,maxBuffer:1024,stdio:["ignore","pipe","ignore"],windowsHide:!0}).startsWith("tokmizer-native ")}catch{return!1}}function Qt(e,t){try{let r=Ee(e,"utf8").split(`
|
|
9
|
+
`,1)[0].slice(2).trim().split(/\s+/),o=r[0]??"";return o==="/usr/bin/env"?C(r[1]??"",void 0,t):j(o)}catch{return!1}}function en(e,t,n){try{let r=Wt(e);return[e,r.size,r.mtimeMs,r.ino,r.mode,t?n??"":""].join("|")}catch{return`${e}|missing`}}function se(e,t=process.platform,n=process.env.PATH,r=Kt(),o=Date.now()){let s=t!=="win32"&&oe(e)==="#!",i=en(e,s,n),c=qt(r);if(c?.key===i&&(c.ok||o-c.at<Vt))return c.ok;let u=j(e,t)&&(s?Qt(e,n):Xt(e));return Yt(r,{key:i,ok:u,at:o,skipped:(c?.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"]),sn=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"]),Re=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),Oe="(?:dev|start|serve|watch|preview)",cn=new RegExp(`^(?:\\S*/)?(?:bun\\s+(?:install|i|add|remove|rm|update|outdated|audit|test|build|pm|x)(?:\\s|$)|bun\\s+run\\s+(?!${Oe}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|deno\\s+(?:test|lint|fmt|check|compile|install|info|doc|bench|outdated)(?:\\s|$)|deno\\s+task\\s+(?!${Oe}(?:\\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)`),un=/(?:^|\s)--watch(?:\s|=|$)/;function ln(e){return cn.test(e)&&!un.test(e)}var an=/^((?:\S*\/)?(sh|bash|zsh|dash|ksh|fish)\s+(-[elux]*c[elux]*)\s+)(['"])/,fn=/[()$]|(?:^|[;&|\n]\s*)(?:and|or|not|begin|end|if|else|switch|case|while|for|function|return)(?:\s|;|$)/,Le=3;function je(e){let t=an.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,s=e.indexOf(r,o);if(s<=o)return null;let i=e.slice(s+1);if(i&&!/^\s/.test(i))return null;let c=e.slice(o,s);return r==='"'&&/[$`\\!]/.test(c)||n&&fn.test(c)?null:{script:c,start:o,end:s,quote:r}}var dn=new Set(["cd","export","set","unset","source",".","true",":","pushd","popd"]);function pn(e){return ue(e).filter(n=>{if(n.kind!=="cmd"||n.unsafe)return!1;let r=De(n.text);return r!==""&&!dn.has(r)&&!ce.test(r)}).length>1}function mn(e,t,n,r,o){if(n>=Le)return null;let s=je(e);if(!s)return null;let{script:i,start:c,end:u,quote:l}=s,f=[],d=Me(i,t,n+1,r,w=>f.push(w));if(d===i||l==='"'&&/["$`]/.test(d))return null;let x=l==="'"?d.replace(/'/g,"'\\''"):d,m=`${e.slice(0,c)}${x}${e.slice(u)}`,h=pn(i);if(o)for(let w of h?[e,...f]:f)o(w);return h?`${t} ${m}`:m}var Te=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,gn=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]);function hn(e,t){let n=K(t);return n==="tail"||n==="journalctl"?Te.test(e):n==="stern"?!0:gn.has(n)?/\blogs?\b/.test(e)&&Te.test(e):!1}var ce=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,kn=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,_n=/(?:^|[;&|\n({])\s*[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/;function K(e){let t=e.lastIndexOf("/");return t===-1?e:e.slice(t+1)}function Fe(e){let t=new Array(e.length).fill(!1),n=[],r=0;for(;r<e.length;){let o=e[r],s=e[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;t[r]=i===void 0,r+=1}return n.length===0?t:null}function Ce(e){let t=Fe(e);if(!t)return!0;for(let n=0;n<e.length;n++)if(t[n]&&e[n]===">")return!0;return!1}function ue(e){let t=Fe(e);if(!t)return[{kind:"cmd",text:e,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<e.length;){let c=e[o],u=e[o+1];if(t[o]){if(c===">"&&u==="|"){r+=">|",o+=2;continue}if(c==="&"&&u==="&"){i("&&",2);continue}if(c==="&"&&u!==">"){let l=r.replace(/\s+$/,""),f=l[l.length-1];if(f!==">"&&f!=="<"&&f!=="&"){i("&",1);continue}}if(c==="|"&&u==="|"){i("||",2);continue}if(c==="|"&&u==="&"){i("|&",2);continue}if(c===";"&&u===";"){let l=e[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 De(e){return e.trim().split(/\s+/)[0]??""}function b(e,t=process.platform){try{let n=Ie(nn(import.meta.url)),r=t==="win32",o=e&&e!=="claude-code"&&e!=="codex"&&!r?`TOKMIZER_HOST=${e} `:"";if(r&&(!e||e==="claude-code")){let c=a(n,"..","bin","tkr-exec.exe");if(F(c))return se(c,t)?`'${c.replace(/\\/g,"/").replace(/'/g,"'\\''")}'`:null}let s=a(n,"..","bin","tkr-exec");if(!r&&F(s))return se(s,t)?`${o}'${s.replace(/'/g,"'\\''")}'`:null;if(B()){let c=r?process.execPath.replace(/\\/g,"/"):process.execPath;return`${o}'${c.replace(/'/g,"'\\''")}' exec`}let i=a(n,"..","bin","tkr-exec.js");return F(i)?`${o}node '${i.replace(/'/g,"'\\''")}'`:null}catch{return null}}function bn(e,t="tkr-exec",n=()=>!0,r){return Me(e,t,0,n,r)}function Me(e,t,n,r,o){if(e.includes("<<")||_n.test(e))return e;let s=ue(e),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 f=De(l),d=s[c+1],x=d?.kind==="sep"&&(d.text==="|"||d.text==="|&"),m=d?.kind==="sep"&&d.text==="&",h=!x&&!m&&!Ce(u.text)&&!u.text.includes("<(")&&!u.text.includes(">(")?mn(l,t,n,r,o):null;if(h!==null){i.push(`${u.text.match(/^\s*/)?.[0]??""}${h}${u.text.match(/\s*$/)?.[0]??""}`);continue}if(l===t||l.startsWith(t)&&/^\s/.test(l.slice(t.length))||on.has(f)||sn.has(f)||(Re.has(f)||Re.has(K(f)))&&!ln(l)||ce.test(f)||f.startsWith("(")||f.startsWith("#")||f.startsWith("<")||f.startsWith(">")||kn.test(l)||hn(l,f)||f.endsWith(")")||x||m||Ce(u.text)||u.text.includes("<(")||u.text.includes(">(")||f==="node"&&l.includes("tkr-exec.js")||!r(f)){i.push(u.text);continue}let w=u.text.match(/^\s*/)?.[0]??"",_=u.text.match(/\s*$/)?.[0]??"";o?.(l),i.push(`${w}${t} ${l}${_}`)}return i.join("")}var Sn=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"]),yn=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),xn={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/},G=["test","run test","run build","run lint","run typecheck"],$n={npm:new Set(G),pnpm:new Set([...G,"build","lint","typecheck"]),yarn:new Set([...G,"build","lint","typecheck"]),bun:new Set(G),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"])},An=new Set(["pytest","tsc","vitest","jest","eslint","mypy"]);function Ue(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 ue(e)){if(r.kind==="sep")continue;if(r.unsafe)return!1;let o=n<Le?je(r.text.trim()):null;if(o){if(!Ue(o.script,t,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=>ce.test(l)))return!1;let i=K(s[0]);if(i!==s[0])return!1;let c=xn[i];if(c&&s.slice(1).some(l=>c.test(l)))return!1;if((i==="git"?yn.has(s[1]??""):wn.has(i))||t&&An.has(i))continue;let u=t?$n[i]:void 0;if(!(u&&(u.has(s[1]??"")||s[1]==="run"&&u.has(`run ${s[2]??""}`))))return!1}return!0}function ze(e,t,n=b(t),r=k,o=q(),s=process.env.PATH,i=le){if(!g(e)||e.tool_name!=="Bash"||t==="claude-code"&&vn(i()))return null;let c=e.tool_input;if(!g(c)||c.run_in_background)return null;let u=c.command;if(typeof u!="string"||!u||t==="codex"&&Object.keys(c).some(w=>!Sn.has(w)))return null;let l=typeof e.cwd=="string"&&e.cwd?e.cwd:c.workdir,f=typeof l=="string"&&l?l:void 0,d=typeof e.session_id=="string"&&e.session_id?e.session_id:"unknown",x=typeof e.permission_mode=="string"?e.permission_mode:void 0,m=Ke(u,{host:t,sessionId:d,cwd:f,claudeDirs:o,pathEnv:s,permissionMode:x},n,r);if(!m)return null;let h={...c,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 En=/(?:^|\s)--(?:disallowedTools|disallowed-tools|settings|setting-sources)(?:[=\s]|$)/;function le(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 vn(e){return e===null||En.test(e)}function Rn(e,t){if(!F(e))return"missing";try{let n=Z(e,"utf8");return JSON.parse(t?Je(n):n)}catch{return"unreadable"}}function Je(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]!==`
|
|
11
|
+
`;)r++;t+=`
|
|
12
|
+
`}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 M(e){let t=[],n=rn(e);for(;;){t.push(n);let r=Ie(n);if(r===n)return t;n=r}}function On(){let e=process.platform==="darwin"?"/Library/Application Support/ClaudeCode":process.platform==="win32"?"C:\\Program Files\\ClaudeCode":"/etc/claude-code",t=[a(e,"managed-settings.json")];try{for(let n of V(a(e,"managed-settings.d")))n.endsWith(".json")&&t.push(a(e,"managed-settings.d",n))}catch{return t}return t}function U(e,t,n,r){let o=[];for(let s of e){let i=Rn(s,t);if(i!=="missing"&&(i==="unreadable"||!g(i)||!n(i,o)))return"unreadable"}return{matchers:o,complete:r}}function D(e){return e===void 0?[]:Array.isArray(e)?e.filter(t=>typeof t=="string"):null}function q(){return{projectDir:process.env.CLAUDE_PROJECT_DIR,configDir:process.env.CLAUDE_CONFIG_DIR}}function Tn(e,t){let n=_=>[a(_,"settings.json"),a(_,"settings.local.json")],r=_=>n(a(_,".claude")),o=a(R(),".claude"),s=t.configDir||o,i=[[On(),"managed"],[[a(s,"settings.json")],"loaded"],[[a(s,"settings.local.json")],"loadedLocal"],[t.configDir?n(o):[],"extra"],[t.projectDir?r(t.projectDir):[],"project"],[M(e).flatMap(r),"extra"]],c=[],u={managed:[],loaded:[],loadedLocal:[],project:[],extra:[]},l={managed:!1,loaded:!1,loadedLocal:!1,project:!1,extra:!1},f=!1,d="managed",x=(_,ne)=>{let $=_.permissions;if(d==="managed"&&(_.allowManagedPermissionRulesOnly===!0||g($)&&$.allowManagedPermissionRulesOnly===!0)&&(f=!0),$===void 0)return!0;if(!g($))return!1;for(let me of["deny","ask","allow"]){let ge=D($[me]);if(!ge)return!1;for(let he of ge){let T=/^\s*Bash\s*(?:\(([\s\S]*)\))?\s*$/.exec(he);if(T)if(me!=="allow")ne.push(O((T[1]??"*").replace(/:\*$/," *")));else if(T[1]===void 0||T[1].trim()==="*")l[d]=!0;else{c.push(O(T[1].replace(/:\*$/," *")));let ke=Vn(T[1]);ke&&u[d].push({rule:he.trim(),matches:ke})}}}return!0},m=[];for(let[_,ne]of i){d=ne;let $=U(_,!1,x,!0);if($==="unreadable")return"unreadable";m.push(...$.matchers)}let h=l.managed||(l.loaded||l.loadedLocal)&&!f,w=[...u.managed,...f?[]:u.loaded];return{matchers:[...m,...h?[]:c],complete:!0,allow:c,allowsEverything:h,guards:m,trustedAllow:w}}function Cn(e){let t=[a(R(),".cursor","cli-config.json"),...M(e).map(n=>a(n,".cursor","cli.json"))];return U(t,!0,(n,r)=>{let o=n.permissions;if(o===void 0)return!0;if(!g(o))return!1;let s=D(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 Pn(){return process.platform==="darwin"?"/Library/Application Support/GeminiCli":process.platform==="win32"?"C:\\ProgramData\\gemini-cli":"/etc/gemini-cli"}var Be=/^\s*(?:run_shell_command|ShellTool)\s*(?:\(([\s\S]*)\))?\s*$/;function Hn(e,t){let n=e.tools;if(n!==void 0&&!g(n))return!1;let r=[D(e.excludeTools),D(g(n)?n.exclude:void 0)];for(let o of r){if(!o)return!1;for(let s of o){let i=Be.exec(s);i&&t.push(O(i[1]===void 0?"*":`${i[1]}*`))}}return!0}function Pe(e){try{return JSON.parse(e)}catch{return null}}function Nn(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]??Pe(`"${r[1]}"`);if(o===null)return null;n.push(o)}return n}if(t.startsWith('"')){let n=/^"((?:\\.|[^"\\])*)"/.exec(t);return n?Pe(`"${n[1]}"`):null}if(t.startsWith("'")){let n=/^'([^']*)'/.exec(t);return n?n[1]:null}return t.replace(/\s*#.*$/,"")}function In(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 l=/^\s*([A-Za-z_]+)\s*=\s*(.*)$/.exec(u);if(!l)continue;let f=Nn(l[2]);if(f===null)return!1;r[l[1]]=f}let o=r.decision;if(o!=="deny"&&o!=="ask_user"||!(r.toolName===void 0?["*"]:[r.toolName].flat()).some(u=>u==="*"||Be.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){t.push(()=>!0);continue}for(let u of i)t.push(O(`${u}*`));for(let u of c){let l;try{l=new RegExp(u)}catch{return!1}t.push(f=>l.test(JSON.stringify({command:f}))||Y(l,f))}}return!0}function He(e){try{return V(e).filter(t=>t.endsWith(".toml")).map(t=>a(e,t))}catch{return[]}}function Ln(e){let t=Pn(),n=[a(t,"system-defaults.json"),a(t,"settings.json"),process.env.GEMINI_CLI_SYSTEM_SETTINGS_PATH,process.env.GEMINI_CLI_SYSTEM_DEFAULTS_PATH,a(R(),".gemini","settings.json"),...M(e).map(o=>a(o,".gemini","settings.json"))].filter(o=>!!o),r=U(n,!0,Hn,!1);if(r==="unreadable")return r;for(let o of[...He(a(R(),".gemini","policies")),...He(a(t,"policies"))]){let s;try{s=Z(o,"utf8")}catch{return"unreadable"}if(!In(s,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(!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,s]of Object.entries(r))s!=="allow"&&t.push(O(o.replace(/\?/g,"*")))}}return!0}function Ne(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(!g(r))return!1;for(let o of Object.values(r))if(g(o)&&(o.permissions!==void 0||!ie(o.permission,t)))return!1}}return!0}function jn(e){for(let t of e)for(let n of["agent","agents","mode","modes"]){let r;try{r=V(a(t,n))}catch{continue}for(let o of r)try{if(o.endsWith(".md")&&/permission/i.test(Z(a(t,n,o),"utf8")))return!0}catch{return!0}}return!1}function Fn(e){let t=a(process.env.XDG_CONFIG_HOME||a(R(),".config"),"opencode"),n=M(e),r=[t,...n.map(c=>a(c,".opencode"))];if(jn(r))return"unreadable";let o=["opencode.json","opencode.jsonc","config.json"],s=[...o.map(c=>a(t,c)),process.env.OPENCODE_CONFIG,...n.flatMap(c=>[...o.slice(0,2).map(u=>a(c,u)),...o.slice(0,2).map(u=>a(c,".opencode",u))])].filter(c=>!!c),i=U(s,!0,Ne,!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(Je(c))}catch{return"unreadable"}if(!(c===process.env.OPENCODE_PERMISSION?ie(u,i.matchers):g(u)&&Ne(u,i.matchers)))return"unreadable"}return i}function Dn(){return U([a(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=D(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:")){t.push(O(c==="*"?"*":`${c} *`));continue}let u;try{u=new RegExp(c.slice(6))}catch{return!1}t.push(l=>Y(u,l))}}return!0},!1)}function Mn(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 We(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=We(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 Un(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(s=>typeof s=="string"&&s!==""))return null;t.push(`(?:${o.map(ae).join("|")})`)}let n=new RegExp(`^${t.join(" ")}(?= |$)`);return r=>Y(n,r)}function zn(e,t){let n=Mn(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},s={};for(;n[o.i]!==")";){let u=n[o.i];if(!u||!/^[A-Za-z_]/.test(u)||n[o.i+1]!=="="||(o.i+=2,s[u]=We(n,o),s[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 i="decision"in s?s.decision:"allow";if(i!=="allow"&&i!=="prompt"&&i!=="forbidden")return!1;let c=Un(s.pattern);if(!c)return!1;i!=="allow"&&t.push(c)}return!0}function Jn(e){if(!F(e))return[];try{return V(e).filter(t=>t.endsWith(".rules")).sort().map(t=>a(e,t))}catch{return"unreadable"}}function Bn(e){let t=process.env.CODEX_HOME||a(R(),".codex"),n=[a(t,"rules"),...M(e).map(o=>a(o,".codex","rules"))],r=[];for(let o of[...new Set(n)]){let s=Jn(o);if(s==="unreadable")return"unreadable";for(let i of s){let c;try{c=Z(i,"utf8")}catch{return"unreadable"}if(!zn(c,r))return"unreadable"}}return{matchers:r,complete:!1}}function g(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function ae(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Wn(e){let t=e.trim().replace(/\s+/g," "),n=t.endsWith(" *")&&t.length>2,r=(n?t.slice(0,-2):t).split("*").map(ae).join("[\\s\\S]*");return new RegExp(`^${r}${n?"(?: [\\s\\S]*)?":""}(?= |$)`)}var Gn=512;function Zn(e){let t=e.replace(/['"\\]/g,"").split(/[\s;&|(){}<>`$]+/).filter(Boolean);return[t,t.map(K)]}function Y(e,t){if(e.test(t)||e.test(t.trim().replace(/\s+/g," ")))return!0;for(let n of Zn(t)){if(n.length>Gn)return!0;for(let r=0;r<n.length;r++)if(e.test(n.slice(r).join(" ")))return!0}return!1}function O(e){let t=Wn(e);return n=>Y(t,n)}function Vn(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(`^${ae(r)}${n?"(?: [\\s\\S]*)?":""}$`);return s=>o.test(s)}var Kn={"claude-code":Tn,cursor:Cn,"gemini-cli":Ln,opencode:Fn,antigravity:Dn,codex:Bn},qn=new Set(["codex"]),Ge=/(?:^|[\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 Yn(e,t,n){let r=Kn[e];return r?r(t??process.cwd(),n):{matchers:[],complete:!1}}function Xn(e,t,n){return e==="unreadable"||Ge.test(t.replace(/['"\\]/g,""))||e.matchers.some(r=>r(t))?!1:e.complete||Ue(t,!qn.has(n))}var Ze=new Set(["default","acceptEdits","dontAsk"]);function Ve(e,t){return t.host!=="claude-code"||t.permissionMode==="bypassPermissions"?!0:e!=="unreadable"&&e.allowsEverything===!0&&Ze.has(t.permissionMode??"")}function Qn(e,t){let n="pathEnv"in e?e.pathEnv:process.env.PATH,r;return o=>e.host!=="claude-code"?C(o,e.cwd,n):(r??=$e(t.configDir),!C(o,e.cwd,n)&&!r.paths.some(s=>C(o,e.cwd,s))?!1:o.includes("/")||!Ae(o,r))}var er=/^[^\s;&|<>()$`\\{}*?[\]~#!]+(?: [^\s;&|<>()$`\\{}*?[\]~#!]+)*$/;function tr(e,t,n){return n.host!=="claude-code"||e==="unreadable"||Ve(e,n)||!Ze.has(n.permissionMode??"")||!er.test(t)||Ge.test(t.replace(/['"]/g,""))||(e.guards??[]).some(r=>r(t))?null:(e.trustedAllow??[]).find(r=>r.matches(t))?.rule??null}function Ke(e,t,n,r){if(!n||/["\\$`;&|<>(){}]|'\\''/.test(n))return null;let o=t.claudeDirs??q(),s=Yn(t.host,t.cwd,o),i=tr(s,e,t),c=i||Xn(s,e,t.host)?bn(e,n,Qn(t,o)):e;return c!==e&&s!=="unreadable"&&(i?(s.guards??[]).some(u=>u(c)):s.matchers.some(u=>u(c))||(s.allow??[]).some(u=>u(c)&&!u(e)))&&(c=e),r(t.sessionId,c!==e),c===e?null:i?{command:c,allowedBy:i}:Ve(s,t)?{command:c}:null}function E(e,t,n,r){return Ke(e,t,n,r)?.command??null}function P(e,t,n="unknown",r=b(t),o=k){return e?E(e,{host:t,sessionId:n},S()?null:r,o):null}function p(e,t){let n=e[t];return typeof n=="string"&&n?n:null}function z(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function nr(e){return p(e,"prompt_id")||p(e,"scratchpad_dir")?!0:z(e.effort)}function rr(e){return p(e,"tool_use_id")?.startsWith("toolu_")===!0||/^claude/i.test(p(e,"model")??"")}var or=new Set(["BeforeTool","AfterTool","BeforeAgent","AfterAgent","BeforeModel","AfterModel","BeforeToolSelection"]),sr=new Set(["preToolUse","postToolUse","beforeShellExecution","afterShellExecution","beforeSubmitPrompt","sessionStart","sessionEnd","stop"]),ir=new Set(["pre_tool","post_tool"]),cr=new Set(["before_tool_call","after_tool_call"]),ur=new Set(["runTerminalCommand","run_in_terminal"]),lr=[["codex",e=>p(e,"turn_id")!==null],["claude-code",nr],["cursor",e=>p(e,"cursor_version")!==null||p(e,"generation_id")!==null||p(e,"conversation_id")!==null||Array.isArray(e.workspace_roots)||sr.has(p(e,"hook_event_name")??"")],["gemini-cli",e=>or.has(p(e,"hook_event_name")??"")],["qwen-code",e=>e.hook_event_name==="PreToolUse"&&e.tool_name==="run_shell_command"],["vibe",e=>ir.has(p(e,"hook_event_name")??"")],["antigravity",e=>z(e.toolCall)],["copilot",e=>p(e,"toolName")!==null&&"toolArgs"in e||ur.has(p(e,"tool_name")??"")],["grok",e=>e.toolName==="run_terminal_command"||e.tool_name==="run_terminal_command"||z(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&&p(e,"event")!==null&&!cr.has(p(e,"event"))]],ar=new Set(["codex","antigravity"]);function fr(e){return z(e)?lr.filter(([,t])=>t(e)).map(([t])=>t):[]}function qe(e,t){if(!z(e))return null;let n=fr(e);return n.length>1?null:n.length===1?n[0]:rr(e)&&ar.has(t)?"claude-code":t==="codex"?null:t}var fe=JSON.stringify({permission:"allow"});function Ye(e,t=b("cursor"),n=k){if(e.tool_name!=="Shell")return fe;let r=e.tool_input??{},o=r.command;if(typeof o!="string"||!o)return fe;let s=typeof r.working_directory=="string"?r.working_directory:void 0,i=E(o,{host:"cursor",sessionId:e.conversation_id??"unknown",cwd:s},S()?null:t,n);return i?JSON.stringify({permission:"allow",updated_input:{...r,command:i}}):fe}var X="{}";function Xe(e,t=b("gemini-cli"),n=k){if(e.hook_event_name!=="BeforeTool"||e.tool_name!=="run_shell_command")return X;let r=e.tool_input??{};if(r.is_background)return X;let o=r.command;if(typeof o!="string"||!o)return X;let s=typeof e.cwd=="string"?e.cwd:void 0,i=E(o,{host:"gemini-cli",sessionId:e.session_id??"unknown",cwd:s},S()?null:t,n);return i?JSON.stringify({hookSpecificOutput:{tool_input:{command:i}}}):X}var y="{}",dr=new Set(["runTerminalCommand","run_in_terminal","Bash","bash"]),pr=["run_in_background","is_background","isBackground"];function Q(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 gr(e,t){let n=e.cwd??t.cwd??t.workdir??t.working_directory;return typeof n=="string"&&n?n:void 0}function ee(e,t,n,r,o){if(!Q(t)||pr.some(i=>t[i]===!0))return null;let s=t.command;return typeof s!="string"||!s?null:E(s,{host:e,sessionId:mr(n),cwd:gr(n,t)},S()?null:r,o)}function N(e,t){return JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",updatedInput:{...e,command:t}}})}function hr(e){if(Q(e))return e;if(typeof e!="string")return null;try{let t=JSON.parse(e);return Q(t)?t:null}catch{return null}}function kr(e,t,n){if(typeof e.tool_name=="string"){if(!dr.has(e.tool_name))return y;let s=e.tool_input,i=ee("copilot",s,e,t,n);return i?N(s,i):y}if(e.toolName!=="bash")return y;let r=hr(e.toolArgs),o=ee("copilot",r,e,t,n);return o?JSON.stringify({modifiedArgs:{...r,command:o}}):y}function H(e,t,n){return(r,o,s)=>{if(r.tool_name!==t)return y;let i=r.tool_input,c=ee(e,i,r,o,s);return c?n(i,c):y}}var _r=new Set(["run_terminal_command","Bash","bash"]);function br(e,t,n){let r=e.toolName??e.tool_name;if(typeof r!="string"||!_r.has(r))return y;let o=e.toolInput??e.tool_input,s=ee("grok",o,e,t,n);return s?N(o,s):y}var Sr={copilot:kr,droid:H("droid","Execute",N),trae:H("trae","RunCommand",N),"qwen-code":H("qwen-code","run_shell_command",N),crush:H("crush","bash",(e,t)=>JSON.stringify({updated_input:{command:t}})),junie:H("junie","Bash",(e,t)=>JSON.stringify({updatedInput:{...e,command:t}})),zcode:H("zcode","Bash",N),grok:br};function Qe(e,t,n=b(e),r=k){return Q(t)?Sr[e](t,n,r):y}function I(e){return S()?null:b(e)}function wr(e,t,n={}){let r=n.recordUsage??k;switch(e){case"claude-code":case"codex":return t.hook_event_name!==void 0&&t.hook_event_name!=="PreToolUse"?"":ze(t,e,I(e),r,n.claudeDirs??q(),n.pathEnv??process.env.PATH,n.launchArgs??le)??"";case"cursor":return Ye(t,I(e),r);case"gemini-cli":return Xe(t,I(e),r);case"vibe":return de(t,(o,s)=>P(o,"vibe",s,I(e),r));case"antigravity":return pe(t,(o,s)=>P(o,"antigravity",s,I(e),r));default:return Qe(e,t,I(e),r)}}function J(e,t,n={}){let r=qe(e,t);return r?wr(r,e,n):n.fallback??""}var yr=new Set(["bash","file_system.bash"]),te=JSON.stringify({decision:"allow"});function de(e,t=(n,r)=>P(n,"vibe",r)){if(!v(e)||e.hook_event_name!=="pre_tool"||typeof e.tool_name!="string"||!yr.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 pe(e,t=(n,r)=>P(n,"antigravity",r)){if(!v(e)||!v(e.toolCall)||e.toolCall.name!=="run_command")return te;let n=e.toolCall.args;if(!v(n)||typeof n.CommandLine!="string"||!n.CommandLine)return te;let r=t(n.CommandLine,typeof e.conversationId=="string"?e.conversationId:"unknown");return r?JSON.stringify({decision:"allow",overwrite:{CommandLine:r}}):te}var et={vibe:{build:e=>de(e),fallback:""},antigravity:{build:e=>pe(e),fallback:te}};function tt(e){return et[e??""]?.fallback??""}function xr(e,t){let n=et[e??""];if(!n)return"";let r;try{r=JSON.parse(t.replace(/^/,""))}catch{return n.fallback}return v(r)?J(r,e,{fallback:n.fallback}):n.build(r)}async function nt(e){process.stdout.write(xr(e,await L()))}nt(process.argv[2]).catch(e=>{process.stderr.write(`tkr-agent-hook: ${e.message}
|
|
13
|
+
`),process.stdout.write(tt(process.argv[2])),process.exit(0)});
|