@tokmizer/plugin 0.9.56 → 0.9.58
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/README.md +168 -9
- package/agent-plugins/amp.js +38 -0
- package/agent-plugins/hermes/__init__.py +39 -0
- package/agent-plugins/hermes/plugin.yaml +5 -0
- package/agent-plugins/kilo.js +40 -0
- package/agent-plugins/omp.js +32 -0
- package/agent-plugins/openclaw/index.js +39 -0
- package/agent-plugins/openclaw/openclaw.plugin.json +12 -0
- package/agent-plugins/openclaw/package.json +11 -0
- package/agent-plugins/opencode.js +40 -0
- package/agent-plugins/pi.js +30 -0
- package/codex-plugin/plugin.json +1 -1
- package/command-templates/tkr-gain.md +7 -2
- package/command-templates/tkr-link.md +1 -1
- package/command-templates/tkr-status.md +5 -3
- package/command-templates/tkr-telemetry.md +3 -3
- package/command-templates/tkr-unlink.md +2 -2
- package/dist/bin/tkr-agent-hook.js +11 -0
- package/dist/bin/tkr-codex-hook.js +131 -40
- package/dist/bin/tkr-copilot-hook.js +11 -0
- package/dist/bin/tkr-crush-hook.js +11 -0
- package/dist/bin/tkr-cursor-hook.js +11 -0
- package/dist/bin/tkr-daemon.js +161 -55
- package/dist/bin/tkr-droid-hook.js +11 -0
- package/dist/bin/tkr-exec +135 -42
- package/dist/bin/tkr-exec.js +135 -42
- package/dist/bin/tkr-gemini-hook.js +11 -0
- package/dist/bin/tkr-grok-hook.js +11 -0
- package/dist/bin/tkr-junie-hook.js +11 -0
- package/dist/bin/tkr-processor.js +162 -0
- package/dist/bin/tkr-qwen-hook.js +11 -0
- package/dist/bin/tkr-shim.js +131 -38
- package/dist/bin/tkr-trae-hook.js +11 -0
- package/dist/bin/tkr-zcode-hook.js +11 -0
- package/dist/bin/tkr.js +356 -152
- package/dist/hooks-host/post-tool-use.js +144 -48
- package/dist/hooks-host/pre-tool-use.js +8 -7
- package/dist/hooks-host/reducer-prompt-submit.js +1 -1
- package/dist/hooks-host/reducer-session-start.js +1 -1
- package/dist/hooks-host/reducer-stop.js +25 -16
- package/dist/hooks-host/session-recap.js +4 -3
- package/dist/index.js +125 -39
- package/dist/native/manifest.json +18 -8
- package/dist/native/single.json +38 -0
- 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.d.mts +1 -0
- package/hooks/on-session-start.mjs +25 -8
- package/package.json +24 -2
- package/scripts/README-INSTALL.md +13 -5
- package/scripts/install-mac-linux.sh +72 -6
- package/scripts/install-native.mjs +164 -25
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: Unlink this machine from your Tokmizer account (
|
|
2
|
+
description: Unlink this machine from your Tokmizer account (it keeps working without an account).
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
Unlink the local plugin from the user's Tokmizer account.
|
|
@@ -10,6 +10,6 @@ Run the bundled CLI:
|
|
|
10
10
|
node "${CLAUDE_PLUGIN_ROOT}/dist/bin/tkr.js" unlink
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Print the output as is. After unlinking, the plugin
|
|
13
|
+
Print the output as is. After unlinking, the plugin keeps working without an account; a new install token is created on the next online run. To link another account, the user runs `tkr link` with the key from their dashboard.
|
|
14
14
|
|
|
15
15
|
If the command fails because the plugin files are missing, tokmizer was uninstalled. Offer to clean up: delete the tokmizer-managed `tkr*.md` copies (they end with a `managed-by: tokmizer` marker) from `~/.claude/commands/`.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __tkrCreateRequire } from "node:module"; const require = __tkrCreateRequire(import.meta.url);
|
|
3
|
+
async function j(){let e=[];for await(let n of process.stdin)e.push(n);return Buffer.concat(e).toString("utf8")}function E(){return!1}function d(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}import{appendFileSync as me,chmodSync as he,mkdirSync as ke,existsSync as Se,readFileSync as At,rmSync as Ct}from"node:fs";import{dirname as be,join as xe}from"node:path";import le from"node:os";import{join as ae}from"node:path";function D(){return process.env.TOKMIZER_HOME||ae(le.homedir(),".tokmizer")}import{readFileSync as fe,renameSync as pe,statSync as de,writeFileSync as ge}from"node:fs";function H(e,n,t){try{if(de(e).size<=n)return;let r=fe(e,"utf8").split(`
|
|
4
|
+
`).filter(i=>i.trim()!==""),o=[],c=0;for(let i=r.length-1;i>=0;i-=1){let u=r[i],l=Buffer.byteLength(u)+1;if(c+l>t)break;o.push(u),c+=l}o.reverse();let s=`${e}.tmp-${process.pid}`;ge(s,o.length?`${o.join(`
|
|
5
|
+
`)}
|
|
6
|
+
`:"",{mode:384}),pe(s,e)}catch{}}var ye="usage.jsonl";var L=2*1024*1024;function we(){return xe(D(),ye)}function R(e,n,t=we()){try{let r=be(t);Se(r)||ke(r,{recursive:!0,mode:448});let o=e.replace(/[^A-Za-z0-9._-]/g,"").slice(0,64)||"unknown";me(t,`{"t":${Math.floor(Date.now()/1e3)},"s":"${o}","o":${n?1:0}}
|
|
7
|
+
`,{mode:384}),he(t,384),H(t,L,L/2)}catch{}}import{existsSync as x,readFileSync as O,readdirSync as A}from"node:fs";import{homedir as g}from"node:os";import{fileURLToPath as _e}from"node:url";import{dirname as G,join as a,resolve as Ee}from"node:path";var Re=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"]),$e=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"]),P=new Set(["sh","bash","zsh","dash","ksh","fish","python","python3","python2","node","ruby","perl","php","awk","sed","deno","bun"]),F="(?:dev|start|serve|watch|preview)",Oe=new RegExp(`^(?:\\S*/)?(?:bun\\s+(?:install|i|add|remove|rm|update|outdated|audit|test|build|pm|x)(?:\\s|$)|bun\\s+run\\s+(?!${F}(?:\\s|$))[A-Za-z0-9:_-]+(?:\\s|$)|deno\\s+(?:test|lint|fmt|check|compile|install|info|doc|bench|outdated)(?:\\s|$)|deno\\s+task\\s+(?!${F}(?:\\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)`),Ae=/(?:^|\s)--watch(?:\s|=|$)/;function Ce(e){return Oe.test(e)&&!Ae.test(e)}var ve=/^((?:\S*\/)?(sh|bash|zsh|dash|ksh|fish)\s+(-[elux]*c[elux]*)\s+)(['"])/,Ie=/[()$]|(?:^|[;&|\n]\s*)(?:and|or|not|begin|end|if|else|switch|case|while|for|function|return)(?:\s|;|$)/,B=3;function Z(e){let n=ve.exec(e);if(!n)return null;let t=n[2]==="fish";if(t&&n[3]!=="-c")return null;let r=n[4],o=n[1].length+1,c=e.indexOf(r,o);if(c<=o)return null;let s=e.slice(c+1);if(s&&!/^\s/.test(s))return null;let i=e.slice(o,c);return r==='"'&&/[$`\\!]/.test(i)||t&&Ie.test(i)?null:{script:i,start:o,end:c,quote:r}}var Te=new Set(["cd","export","set","unset","source",".","true",":","pushd","popd"]);function Ne(e){return v(e).filter(t=>{if(t.kind!=="cmd"||t.unsafe)return!1;let r=K(t.text);return r!==""&&!Te.has(r)&&!C.test(r)}).length>1}function je(e,n,t){if(t>=B)return null;let r=Z(e);if(!r)return null;let{script:o,start:c,end:s,quote:i}=r,u=V(o,n,t+1);if(u===o||i==='"'&&/["$`]/.test(u))return null;let l=i==="'"?u.replace(/'/g,"'\\''"):u,f=`${e.slice(0,c)}${l}${e.slice(s)}`;return Ne(o)?`${n} ${f}`:f}var M=/(?:^|\s)(?:--follow|-[0-9a-zA-Z]*f[a-zA-Z]*)(?:\s|=|$)/,De=new Set(["docker","podman","kubectl","nerdctl","docker-compose","stern","flyctl"]);function He(e,n){let t=y(n);return t==="tail"||t==="journalctl"?M.test(e):t==="stern"?!0:De.has(t)?/\blogs?\b/.test(e)&&M.test(e):!1}var C=/^[A-Za-z_][A-Za-z0-9_]*\+?=/,Le=/^[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/,Pe=/(?:^|[;&|\n({])\s*[A-Za-z_][A-Za-z0-9_-]*\s*\(\s*\)/;function y(e){let n=e.lastIndexOf("/");return n===-1?e:e.slice(n+1)}function q(e){let n=new Array(e.length).fill(!1),t=[],r=0;for(;r<e.length;){let o=e[r],c=e[r+1],s=t[t.length-1];if(s==="'"){o==="'"&&t.pop(),r+=1;continue}if(o==="\\"){if(c===void 0)return null;r+=2;continue}if(s==="$'"){o==="'"&&t.pop(),r+=1;continue}if(o==="$"&&(c==="("||c==="{")){t.push(c==="("?")":"}"),r+=2;continue}if(o==="`"){s==="`"?t.pop():t.push("`"),r+=1;continue}if(s==='"'){o==='"'&&t.pop(),r+=1;continue}if(o==="$"&&c==="'"){t.push("$'"),r+=2;continue}if(o==="'"||o==='"'){t.push(o),r+=1;continue}if(o==="("||o==="{"&&s==="}"){t.push(o==="("?")":"}"),r+=1;continue}if(o===s){t.pop(),r+=1;continue}if(o===")"&&s===void 0)return null;n[r]=s===void 0,r+=1}return t.length===0?n:null}function U(e){let n=q(e);if(!n)return!0;for(let t=0;t<e.length;t++)if(n[t]&&e[t]===">")return!0;return!1}function v(e){let n=q(e);if(!n)return[{kind:"cmd",text:e,unsafe:!0}];let t=[],r="",o=0,c=()=>{r.length>0&&(t.push({kind:"cmd",text:r}),r="")},s=(i,u)=>{c(),t.push({kind:"sep",text:i}),o+=u};for(;o<e.length;){let i=e[o],u=e[o+1];if(n[o]){if(i===">"&&u==="|"){r+=">|",o+=2;continue}if(i==="&"&&u==="&"){s("&&",2);continue}if(i==="&"&&u!==">"){let l=r.replace(/\s+$/,""),f=l[l.length-1];if(f!==">"&&f!=="<"&&f!=="&"){s("&",1);continue}}if(i==="|"&&u==="|"){s("||",2);continue}if(i==="|"&&u==="&"){s("|&",2);continue}if(i===";"&&u===";"){let l=e[o+2]==="&";s(l?";;&":";;",l?3:2);continue}if(i===";"||i===`
|
|
8
|
+
`||i==="|"){s(i,1);continue}}r+=i,o+=1}return c(),t}function K(e){return e.trim().split(/\s+/)[0]??""}function Y(e,n=process.platform){try{let t=G(_e(import.meta.url)),r=n==="win32",o=e&&e!=="claude-code"&&e!=="codex"&&!r?`TOKMIZER_HOST=${e} `:"";if(r&&(!e||e==="claude-code")){let i=a(t,"..","bin","tkr-exec.exe");if(x(i))return`'${i.replace(/\\/g,"/").replace(/'/g,"'\\''")}'`}let c=a(t,"..","bin","tkr-exec");if(!r&&x(c))return`${o}'${c.replace(/'/g,"'\\''")}'`;if(E()){let i=r?process.execPath.replace(/\\/g,"/"):process.execPath;return`${o}'${i.replace(/'/g,"'\\''")}' exec`}let s=a(t,"..","bin","tkr-exec.js");return x(s)?`${o}node '${s.replace(/'/g,"'\\''")}'`:null}catch{return null}}function Fe(e,n="tkr-exec"){return V(e,n,0)}function V(e,n,t){if(e.includes("<<")||Pe.test(e))return e;let r=v(e),o=[];for(let c=0;c<r.length;c++){let s=r[c];if(s.kind==="sep"||s.unsafe){o.push(s.text);continue}let i=s.text.trim();if(!i){o.push(s.text);continue}let u=K(i),l=r[c+1],f=l?.kind==="sep"&&(l.text==="|"||l.text==="|&"),h=l?.kind==="sep"&&l.text==="&",N=!f&&!h&&!U(s.text)&&!s.text.includes("<(")&&!s.text.includes(">(")?je(i,n,t):null;if(N!==null){o.push(`${s.text.match(/^\s*/)?.[0]??""}${N}${s.text.match(/\s*$/)?.[0]??""}`);continue}if(i===n||i.startsWith(n)&&/^\s/.test(i.slice(n.length))||Re.has(u)||$e.has(u)||(P.has(u)||P.has(y(u)))&&!Ce(i)||C.test(u)||u.startsWith("(")||u.startsWith("#")||u.startsWith("<")||u.startsWith(">")||Le.test(i)||He(i,u)||u.endsWith(")")||f||h||U(s.text)||s.text.includes("<(")||s.text.includes(">(")||u==="node"&&i.includes("tkr-exec.js")){o.push(s.text);continue}let ie=s.text.match(/^\s*/)?.[0]??"",ce=s.text.match(/\s*$/)?.[0]??"";o.push(`${ie}${n} ${i}${ce}`)}return o.join("")}var Me=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"]),Ue=new Set(["log","diff","show","status","blame","ls-files","rev-parse","describe","shortlog"]),ze={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"],We={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"])},Je=new Set(["pytest","tsc","vitest","jest","eslint","mypy"]);function X(e,n,t=0){if(/\$|`|<\(|>\(|\\\r?\n/.test(e)||/>/.test(e.replace(/2>&1|[12]?>\s*\/dev\/null/g,"")))return!1;for(let r of v(e)){if(r.kind==="sep")continue;if(r.unsafe)return!1;let o=t<B?Z(r.text.trim()):null;if(o){if(!X(o.script,n,t+1))return!1;continue}let c=r.text.trim().split(/\s+/).filter(Boolean).map(l=>l.replace(/['"\\]/g,""));if(c.length===0)continue;if(c.some(l=>C.test(l)))return!1;let s=y(c[0]);if(s!==c[0])return!1;let i=ze[s];if(i&&c.slice(1).some(l=>i.test(l)))return!1;if((s==="git"?Ue.has(c[1]??""):Me.has(s))||n&&Je.has(s))continue;let u=n?We[s]:void 0;if(!(u&&(u.has(c[1]??"")||c[1]==="run"&&u.has(`run ${c[2]??""}`))))return!1}return!0}function Ge(e,n){if(!x(e))return"missing";try{let t=O(e,"utf8");return JSON.parse(n?Q(t):t)}catch{return"unreadable"}}function Q(e){let n="",t=!1;for(let r=0;r<e.length;r++){let o=e[r];if(t){n+=o,o==="\\"?n+=e[++r]??"":o==='"'&&(t=!1);continue}if(o==='"')t=!0,n+=o;else if(o==="/"&&e[r+1]==="/"){for(;r<e.length&&e[r]!==`
|
|
9
|
+
`;)r++;n+=`
|
|
10
|
+
`}else if(o==="/"&&e[r+1]==="*"){if(r=e.indexOf("*/",r+2),r===-1)return"";r+=1}else n+=o}return n.replace(/,(\s*[}\]])/g,"$1")}function w(e){let n=[],t=Ee(e);for(;;){n.push(t);let r=G(t);if(r===t)return n;t=r}}function Be(){let e=process.platform==="darwin"?"/Library/Application Support/ClaudeCode":process.platform==="win32"?"C:\\Program Files\\ClaudeCode":"/etc/claude-code",n=[a(e,"managed-settings.json")];try{for(let t of A(a(e,"managed-settings.d")))t.endsWith(".json")&&n.push(a(e,"managed-settings.d",t))}catch{return n}return n}function S(e,n,t,r){let o=[];for(let c of e){let s=Ge(c,n);if(s!=="missing"&&(s==="unreadable"||!p(s)||!t(s,o)))return"unreadable"}return{matchers:o,complete:r}}function k(e){return e===void 0?[]:Array.isArray(e)?e.filter(n=>typeof n=="string"):null}function ee(){return{projectDir:process.env.CLAUDE_PROJECT_DIR,configDir:process.env.CLAUDE_CONFIG_DIR}}function Ze(e,n){let t=[a(g(),".claude"),n.configDir].filter(c=>!!c),r=[n.projectDir,...w(e)].filter(c=>!!c),o=[...Be(),...t.flatMap(c=>[a(c,"settings.json"),a(c,"settings.local.json")]),...r.flatMap(c=>[a(c,".claude","settings.json"),a(c,".claude","settings.local.json")])];return S(o,!1,(c,s)=>{let i=c.permissions;if(i===void 0)return!0;if(!p(i))return!1;for(let u of["deny","ask"]){let l=k(i[u]);if(!l)return!1;for(let f of l){let h=/^\s*Bash\s*(?:\(([\s\S]*)\))?\s*$/.exec(f);h&&s.push(m((h[1]??"*").replace(/:\*$/," *")))}}return!0},!0)}function qe(e){let n=[a(g(),".cursor","cli-config.json"),...w(e).map(t=>a(t,".cursor","cli.json"))];return S(n,!0,(t,r)=>{let o=t.permissions;if(o===void 0)return!0;if(!p(o))return!1;let c=k(o.deny);if(!c)return!1;for(let s of c){let i=/^\s*Shell\s*(?:\(([\s\S]*)\))?\s*$/.exec(s);if(!i)continue;let u=i[1]??"*",l=u.indexOf(":");r.push(m(l===-1?`${u} *`:`${u.slice(0,l)} ${u.slice(l+1)}`))}return!0},!1)}function Ke(){return process.platform==="darwin"?"/Library/Application Support/GeminiCli":process.platform==="win32"?"C:\\ProgramData\\gemini-cli":"/etc/gemini-cli"}var te=/^\s*(?:run_shell_command|ShellTool)\s*(?:\(([\s\S]*)\))?\s*$/;function Ye(e,n){let t=e.tools;if(t!==void 0&&!p(t))return!1;let r=[k(e.excludeTools),k(p(t)?t.exclude:void 0)];for(let o of r){if(!o)return!1;for(let c of o){let s=te.exec(c);s&&n.push(m(s[1]===void 0?"*":`${s[1]}*`))}}return!0}function z(e){try{return JSON.parse(e)}catch{return null}}function Ve(e){let n=e.trim();if(n.startsWith('"""')||n.startsWith("'''"))return null;if(n.startsWith("[")){if(!/\]\s*(?:#.*)?$/.test(n))return null;let t=[];for(let r of n.matchAll(/"((?:\\.|[^"\\])*)"|'([^']*)'/g)){let o=r[2]??z(`"${r[1]}"`);if(o===null)return null;t.push(o)}return t}if(n.startsWith('"')){let t=/^"((?:\\.|[^"\\])*)"/.exec(n);return t?z(`"${t[1]}"`):null}if(n.startsWith("'")){let t=/^'([^']*)'/.exec(n);return t?t[1]:null}return n.replace(/\s*#.*$/,"")}function Xe(e,n){for(let t of e.split(/^\s*\[\[\s*rule\s*\]\]\s*$/m).slice(1)){let r={};for(let u of t.split(/\r?\n/)){if(/^\s*\[/.test(u))break;let l=/^\s*([A-Za-z_]+)\s*=\s*(.*)$/.exec(u);if(!l)continue;let f=Ve(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==="*"||te.test(u)))continue;let s=r.commandPrefix===void 0?[]:[r.commandPrefix].flat(),i=[r.commandRegex,r.argsPattern].flat().filter(u=>typeof u=="string");if(s.length===0&&i.length===0){n.push(()=>!0);continue}for(let u of s)n.push(m(`${u}*`));for(let u of i){let l;try{l=new RegExp(u)}catch{return!1}n.push(f=>l.test(JSON.stringify({command:f}))||I(l,f))}}return!0}function W(e){try{return A(e).filter(n=>n.endsWith(".toml")).map(n=>a(e,n))}catch{return[]}}function Qe(e){let n=Ke(),t=[a(n,"system-defaults.json"),a(n,"settings.json"),process.env.GEMINI_CLI_SYSTEM_SETTINGS_PATH,process.env.GEMINI_CLI_SYSTEM_DEFAULTS_PATH,a(g(),".gemini","settings.json"),...w(e).map(o=>a(o,".gemini","settings.json"))].filter(o=>!!o),r=S(t,!0,Ye,!1);if(r==="unreadable")return r;for(let o of[...W(a(g(),".gemini","policies")),...W(a(n,"policies"))]){let c;try{c=O(o,"utf8")}catch{return"unreadable"}if(!Xe(c,r.matchers))return"unreadable"}return r}function $(e,n){if(e===void 0)return!0;if(typeof e=="string")return e!=="allow"&&n.push(()=>!0),!0;if(!p(e))return!1;for(let t of["bash","shell","*"]){let r=e[t];if(r!==void 0){if(typeof r=="string"){r!=="allow"&&n.push(()=>!0);continue}if(!p(r))return!1;for(let[o,c]of Object.entries(r))c!=="allow"&&n.push(m(o.replace(/\?/g,"*")))}}return!0}function J(e,n){if(e.permissions!==void 0||!$(e.permission,n))return!1;for(let t of["agent","agents","mode"]){let r=e[t];if(r!==void 0){if(!p(r))return!1;for(let o of Object.values(r))if(p(o)&&(o.permissions!==void 0||!$(o.permission,n)))return!1}}return!0}function et(e){for(let n of e)for(let t of["agent","agents","mode","modes"]){let r;try{r=A(a(n,t))}catch{continue}for(let o of r)try{if(o.endsWith(".md")&&/permission/i.test(O(a(n,t,o),"utf8")))return!0}catch{return!0}}return!1}function tt(e){let n=a(process.env.XDG_CONFIG_HOME||a(g(),".config"),"opencode"),t=w(e),r=[n,...t.map(i=>a(i,".opencode"))];if(et(r))return"unreadable";let o=["opencode.json","opencode.jsonc","config.json"],c=[...o.map(i=>a(n,i)),process.env.OPENCODE_CONFIG,...t.flatMap(i=>[...o.slice(0,2).map(u=>a(i,u)),...o.slice(0,2).map(u=>a(i,".opencode",u))])].filter(i=>!!i),s=S(c,!0,J,!0);if(s==="unreadable")return s;for(let i of[process.env.OPENCODE_CONFIG_CONTENT,process.env.OPENCODE_PERMISSION]){if(!i)continue;let u;try{u=JSON.parse(Q(i))}catch{return"unreadable"}if(!(i===process.env.OPENCODE_PERMISSION?$(u,s.matchers):p(u)&&J(u,s.matchers)))return"unreadable"}return s}function nt(){return S([a(g(),".gemini","antigravity-cli","settings.json")],!0,(e,n)=>{let t=e.permissions;if(t===void 0)return!0;if(!p(t))return!1;for(let r of["deny","ask"]){let o=k(t[r]);if(!o)return!1;for(let c of o){let s=/^\s*command\s*\(([\s\S]*)\)\s*$/.exec(c);if(!s)continue;let i=s[1].trim();if(!i.startsWith("regex:")){n.push(m(i==="*"?"*":`${i} *`));continue}let u;try{u=new RegExp(i.slice(6))}catch{return!1}n.push(l=>I(u,l))}}return!0},!1)}function p(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function rt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ot(e){let n=e.trim().replace(/\s+/g," "),t=n.endsWith(" *")&&n.length>2,r=(t?n.slice(0,-2):n).split("*").map(rt).join("[\\s\\S]*");return new RegExp(`^${r}${t?"(?: [\\s\\S]*)?":""}(?= |$)`)}var st=512;function it(e){let n=e.replace(/['"\\]/g,"").split(/[\s;&|(){}<>`$]+/).filter(Boolean);return[n,n.map(y)]}function I(e,n){if(e.test(n)||e.test(n.trim().replace(/\s+/g," ")))return!0;for(let t of it(n)){if(t.length>st)return!0;for(let r=0;r<t.length;r++)if(e.test(t.slice(r).join(" ")))return!0}return!1}function m(e){let n=ot(e);return t=>I(n,t)}var ct={"claude-code":Ze,cursor:qe,"gemini-cli":Qe,opencode:tt,antigravity:nt},ut=new Set(["codex"]);function lt(e,n,t,r=ee()){let o=ct[n],c=o?o(t??process.cwd(),r):{matchers:[],complete:!1};return c==="unreadable"||c.matchers.some(s=>s(e))?!1:c.complete||X(e,!ut.has(n))}function ne(e,n,t,r){if(!t)return null;let o=lt(e,n.host,n.cwd,n.claudeDirs??ee())?Fe(e,t):e;return r(n.sessionId,o!==e),o===e?null:o}function T(e,n,t="unknown",r=Y(n),o=R){return e?ne(e,{host:n,sessionId:t},r,o):null}var at=new Set(["bash","file_system.bash"]),_=JSON.stringify({decision:"allow"});function ft(e,n=(t,r)=>T(t,"vibe",r)){if(!d(e)||e.hook_event_name!=="pre_tool"||typeof e.tool_name!="string"||!at.has(e.tool_name))return"";let t=e.tool_input;if(!d(t)||typeof t.command!="string"||!t.command)return"";let r=n(t.command,typeof e.session_id=="string"?e.session_id:"unknown");return r?JSON.stringify({hook_specific_output:{tool_input:{...t,command:r}}}):""}function pt(e,n=(t,r)=>T(t,"antigravity",r)){if(!d(e)||!d(e.toolCall)||e.toolCall.name!=="run_command")return _;let t=e.toolCall.args;if(!d(t)||typeof t.CommandLine!="string"||!t.CommandLine)return _;let r=n(t.CommandLine,typeof e.conversationId=="string"?e.conversationId:"unknown");return r?JSON.stringify({decision:"allow",overwrite:{CommandLine:r}}):_}var re={vibe:{build:e=>ft(e),fallback:""},antigravity:{build:e=>pt(e),fallback:_}};function oe(e){return re[e??""]?.fallback??""}function dt(e,n){let t=re[e??""];if(!t)return"";let r;try{r=JSON.parse(n.replace(/^/,""))}catch{return t.fallback}return t.build(r)}async function se(e){process.stdout.write(dt(e,await j()))}se(process.argv[2]).catch(e=>{process.stderr.write(`tkr-agent-hook: ${e.message}
|
|
11
|
+
`),process.stdout.write(oe(process.argv[2])),process.exit(0)});
|