@golproductions/check 3.2.14 → 3.2.22

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 (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{readFileSync as e,writeFileSync as o,mkdirSync as n,existsSync as t,createWriteStream as s,chmodSync as r,unlinkSync as c,rmSync as i}from"node:fs";import{spawnSync as l}from"node:child_process";import{join as a}from"node:path";import{homedir as h,platform as u,arch as d}from"node:os";import{pipeline as m}from"node:stream/promises";import{Readable as p}from"node:stream";const f="3.2.14",k="https://triage.golproductions.com/preflight",g=process.env.GOL_CLIENT_ID||"";function y(){if(g)return g;try{const o=e(a(h(),".check","key"),"utf8").trim();if(o)return o}catch{}try{const o=JSON.parse(e(a(h(),".claude","settings.json"),"utf8"));return o.env?.GOL_CLIENT_ID||""}catch{return""}}function v(e){return e&&(e.includes(".check")||e.includes("truth-gate"))}function C(e){return!!v(e.command)||!!e.args?.some(e=>v(e))}function w(){console.log(`\n Check v${f} — Anti-hallucination layer for AI coding agents\n\n Usage:\n\n npx @golproductions/check --install <key> Install Check with your Client ID\n npx @golproductions/check --uninstall Remove Check from all tools\n npx @golproductions/check --status Show what is installed and active\n npx @golproductions/check --credits Check your usage and balance\n npx @golproductions/check --docs View documentation\n npx @golproductions/check --help Show this help\n\n Get your key: https://golproductions.com/check\n Pricing: 120 free/day, then $0.0068 AUD per check\n`),process.exit(0)}const T=process.argv.slice(2);function P(e,o,n){if(o){const o={cursor:{permission:"allow"},gemini:{decision:"allow"},claude:{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow"}}};process.stdout.write(JSON.stringify(o[e]||o.claude)),process.exit(0)}"gemini"===e&&(process.stdout.write(JSON.stringify({decision:"deny",reason:n})),process.exit(2));const t={cursor:{permission:"deny",agent_message:n},claude:{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:n}}};process.stdout.write(JSON.stringify(t[e]||t.claude)),process.exit(0)}function S(e,s){let r=!0;try{const e=a(h(),".check","credits-warned-"+(new Date).toISOString().slice(0,10));r=t(e),r||(n(a(h(),".check"),{recursive:!0}),o(e,"1"))}catch{r=!1}const c=r?void 0:s;if("gemini"===e&&(process.stdout.write(JSON.stringify({decision:"allow"})),c&&process.stderr.write(c),process.exit(0)),"cursor"===e){const e={permission:"allow"};c&&(e.user_message=c),process.stdout.write(JSON.stringify(e)),process.exit(0)}const i={hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow"}};c&&(i.systemMessage=c),process.stdout.write(JSON.stringify(i)),process.exit(0)}T.includes("--install")&&await async function(){let c=process.argv[3]||process.env.GOL_CLIENT_ID||"";c&&"your_key"!==c||(console.log("\n Activating Check (free, no signup)...\n"),c=await async function(){try{const e=await async function(){const{createHash:e}=await import("node:crypto"),{hostname:o,userInfo:n}=await import("node:os");let t="";try{t=n().username||""}catch{}const s=[o(),u(),d(),t].join("|");return e("sha256").update(s).digest("hex")}(),o=await fetch(k.replace("/preflight","/instant-key"),{method:"POST",headers:{"Content-Type":"application/json","User-Agent":"c/"+f},body:JSON.stringify({fingerprint:e,channel:"npm"}),signal:AbortSignal.timeout(1e4)});if(!o.ok)return null;const n=await o.json();return n&&n.client_id?n.client_id:null}catch{return null}}(),c||(console.log(" Could not activate automatically (offline, or this network hit its daily limit).\n"),console.log(" Get a key the manual way: https://golproductions.com/check\n"),console.log(" Then run: npx @golproductions/check --install YOUR_KEY\n"),process.exit(1)),console.log(" Activated. 120 free checks per day.\n"));const i=await async function(e){try{const o=await fetch(k,{method:"POST",headers:{"Content-Type":"application/json","X-GOL-CLIENT-ID":e,"User-Agent":"c/"+f},body:JSON.stringify({command:"echo check-install-verify",cwd:process.cwd(),v:f}),signal:AbortSignal.timeout(1e4)});if(o.ok)return{valid:!0,expired:!1};let n={};try{n=await o.json()}catch{}return{valid:!1,expired:/expir/i.test(n.reason||n.error||n.message||"")}}catch{return{valid:!1,expired:!1}}}(c);i.valid||(i.expired?(console.log("\n Your Client ID has expired: "+c),console.log("\n Renew your key at: https://golproductions.com/check\n")):(console.log("\n Invalid Client ID: "+c),console.log("\n Get a valid key at: https://golproductions.com/check\n")),process.exit(1)),console.log("\n Key verified. Installing Check...\n");const l=h();let g=0;const y=e(new URL(import.meta.url),"utf8"),w=a(l,".check");n(w,{recursive:!0});const T=a(w,"check.mjs").replace(/\\/g,"/");o(T,y,"utf8"),o(a(w,"key"),c,"utf8");const P="win32"===u()?".exe":"",S=a(w,"truth-gate"+P).replace(/\\/g,"/");await async function(e){const o="win32"===u()?"win":"darwin"===u()?"macos":"linux",n=`https://pub-e55366a7f5994be9be04f0e205179f4a.r2.dev/releases/truth-gate-v3.0.0-${o}-${"arm64"===d()?"arm64":"x64"}${"win"===o?".exe":""}`,t=await fetch(n);if(!t.ok)throw new Error(`Download failed: ${t.status}`);if(await m(p.fromWeb(t.body),s(e)),"win"!==o)try{r(e,493)}catch{}}(S);const b={command:"npx",args:["@golproductions/check","--mcp"],env:{GOL_CLIENT_ID:c}},x=[{name:"Claude Code",dir:a(l,".claude"),file:"settings.json",config:e=>(e.hooks=e.hooks||{},e.hooks.PreToolUse=(e.hooks.PreToolUse||[]).filter(e=>!e.hooks?.some(C)),e.hooks.PreToolUse.push({matcher:"Bash|PowerShell",hooks:[{type:"command",command:"node",args:[T]}]}),e.hooks.PostToolUse=(e.hooks.PostToolUse||[]).filter(e=>!e.hooks?.some(C)),e.hooks.PostToolUse.push({matcher:"Bash|PowerShell",hooks:[{type:"command",command:S}]},{matcher:"Edit|Write|NotebookEdit",hooks:[{type:"command",command:S}]}),e.env=e.env||{},e.env.GOL_CLIENT_ID=c,e)},{name:"Gemini CLI / Antigravity",dir:a(l,".gemini"),file:"settings.json",config:e=>{e.hooks=e.hooks||{},e.hooks.BeforeTool=e.hooks.BeforeTool||[];const o=e.hooks.BeforeTool;return o.find(e=>e.hooks?.some(e=>"check-gate"===e.name))||o.push({matcher:".*",hooks:[{type:"command",command:"node "+T,name:"check-gate"}]}),e}},{name:"Cursor",dir:a(l,".cursor"),file:"hooks.json",config:e=>(e.version=e.version||1,e.hooks=e.hooks||{},e.hooks.beforeShellExecution=(e.hooks.beforeShellExecution||[]).filter(e=>!v(e.command)),e.hooks.beforeShellExecution.push({command:"node "+T}),e)},{name:"Homebase",dir:a(l,".homebase"),file:"hooks.json",config:e=>(e.hooks=e.hooks||{},e.hooks.PreToolUse=(e.hooks.PreToolUse||[]).filter(e=>!e.hooks?.some(C)),e.hooks.PreToolUse.push({matcher:"Bash|PowerShell",hooks:[{type:"command",command:"node",args:[T]}]}),e.hooks.PostToolUse=(e.hooks.PostToolUse||[]).filter(e=>!e.hooks?.some(C)),e.hooks.PostToolUse.push({matcher:"Bash|PowerShell",hooks:[{type:"command",command:S}]}),e.env=e.env||{},e.env.GOL_CLIENT_ID=c,e)},{name:"Windsurf (MCP)",dir:a(l,".codeium","windsurf"),file:"mcp_config.json",config:e=>(e.mcpServers=e.mcpServers||{},e.mcpServers.Check=b,e)},{name:"Continue (MCP)",dir:a(process.cwd(),".continue","mcpServers"),file:"check.json",config:()=>({mcpServers:{Check:b}})},{name:"Amazon Q Developer (MCP)",dir:a(l,".aws","amazonq"),file:"mcp.json",config:e=>(e.mcpServers=e.mcpServers||{},e.mcpServers.Check={type:"stdio",...b},e)},{name:"Roo Code (project MCP)",dir:a(process.cwd(),".roo"),file:"mcp.json",config:e=>(e.mcpServers=e.mcpServers||{},e.mcpServers.Check=b,e)},{name:"Project MCP (shared)",dir:process.cwd(),file:".mcp.json",config:e=>(e.mcpServers=e.mcpServers||{},e.mcpServers.Check=b,e)}],U=["Windsurf (MCP)","Continue (MCP)","Amazon Q Developer (MCP)","Roo Code (project MCP)","Project MCP (shared)"];let j=!1;for(const s of x){const r=U.includes(s.name);if(!r&&!t(s.dir))continue;r&&n(s.dir,{recursive:!0});const c=a(s.dir,s.file);let i={};try{i=JSON.parse(e(c,"utf8"))}catch{}const l=s.config(i);o(c,JSON.stringify(l,null,2)+"\n","utf8"),g++,"Claude Code"===s.name&&(j=!0)}if(0===g){n(a(l,".claude"),{recursive:!0});const t=a(l,".claude","settings.json");let s={};try{s=JSON.parse(e(t,"utf8"))}catch{}const r=x[0].config(s);o(t,JSON.stringify(r,null,2)+"\n","utf8"),j=!0}const O=j?"CLAUDE.md":"AGENTS.md",_=a(process.cwd(),O);try{const n=t(_)?e(_,"utf8"):"";if(!n.includes("Never fabricate")){const e=n.length>0?n.trimEnd()+"\n\n":"";o(_,e+"Never fabricate, hallucinate, or invent values. If you don't have it, say you don't have it. No fake keys, no fake IDs, no fake paths, no fake URLs. If unsure, ask. Never guess and present it as fact.\n","utf8")}}catch{}console.log(`\n Your free GOL Client ID (this machine): ${c}`),console.log(" Shared by every editor on this machine. 120 free checks/day."),console.log(" Need more? Get a GOL API Key (paid, prepaid balance) at"),console.log(" https://www.golproductions.com/console"),console.log("\n By using Check you agree to the Terms and Privacy Policy:"),console.log(" golproductions.com/terms | golproductions.com/privacy"),console.log("\nSafe travels wanderer..\n"),process.exit(0)}(),T.includes("--uninstall")&&await async function(){const n=h();let s=0;console.log("\n Removing Check...\n");let r=Promise.resolve();try{const e=y();e&&(r=fetch(k.replace("/preflight","/log"),{method:"POST",headers:{"Content-Type":"application/json","X-GOL-CLIENT-ID":e,"User-Agent":"c/"+f},body:JSON.stringify({verdict:"uninstall",channel:"npm",os:u(),arch:d(),version:f}),signal:AbortSignal.timeout(3e3)}).catch(()=>{}))}catch{}const l=[{name:"Claude Code",path:a(n,".claude","settings.json"),clean:e=>(e.hooks?.PreToolUse&&(e.hooks.PreToolUse=e.hooks.PreToolUse.filter(e=>!e.hooks?.some(C)),0===e.hooks.PreToolUse.length&&delete e.hooks.PreToolUse),e.hooks?.PostToolUse&&(e.hooks.PostToolUse=e.hooks.PostToolUse.filter(e=>!e.hooks?.some(C)),0===e.hooks.PostToolUse.length&&delete e.hooks.PostToolUse),e.hooks&&0===Object.keys(e.hooks).length&&delete e.hooks,e.env&&(delete e.env.GOL_CLIENT_ID,0===Object.keys(e.env).length&&delete e.env),e)},{name:"Gemini CLI",path:a(n,".gemini","settings.json"),clean:e=>(e.hooks?.BeforeTool&&(e.hooks.BeforeTool=e.hooks.BeforeTool.filter(e=>!e.hooks?.some(e=>"check-gate"===e.name)),0===e.hooks.BeforeTool.length&&delete e.hooks.BeforeTool,0===Object.keys(e.hooks).length&&delete e.hooks),e)},{name:"Cursor",path:a(n,".cursor","hooks.json"),clean:e=>(e.hooks?.beforeShellExecution&&(e.hooks.beforeShellExecution=e.hooks.beforeShellExecution.filter(e=>!v(e.command)),0===e.hooks.beforeShellExecution.length&&delete e.hooks.beforeShellExecution,0===Object.keys(e.hooks).length&&delete e.hooks),e)},{name:"Homebase",path:a(n,".homebase","hooks.json"),clean:e=>(e.hooks?.PreToolUse&&(e.hooks.PreToolUse=e.hooks.PreToolUse.filter(e=>!e.hooks?.some(C)),0===e.hooks.PreToolUse.length&&delete e.hooks.PreToolUse),e.hooks?.PostToolUse&&(e.hooks.PostToolUse=e.hooks.PostToolUse.filter(e=>!e.hooks?.some(C)),0===e.hooks.PostToolUse.length&&delete e.hooks.PostToolUse),e.hooks&&0===Object.keys(e.hooks).length&&delete e.hooks,e.env&&(delete e.env.GOL_CLIENT_ID,0===Object.keys(e.env).length&&delete e.env),e)}],m=[{name:"Windsurf",path:a(n,".codeium","windsurf","mcp_config.json")},{name:"Amazon Q",path:a(n,".aws","amazonq","mcp.json")}],p=[{name:"Continue",path:a(process.cwd(),".continue","mcpServers","check.json"),deleteFile:!0},{name:"Roo Code",path:a(process.cwd(),".roo","mcp.json")},{name:"Project MCP",path:a(process.cwd(),".mcp.json")}];for(const n of l)if(t(n.path))try{const t=JSON.parse(e(n.path,"utf8")),r=n.clean(t);o(n.path,JSON.stringify(r,null,2)+"\n","utf8"),console.log(" removed "+n.name),s++}catch{}for(const n of[...m,...p])if(t(n.path))try{if(n.deleteFile)c(n.path),console.log(" removed "+n.name),s++;else{const t=JSON.parse(e(n.path,"utf8"));t.mcpServers?.Check&&(delete t.mcpServers.Check,0===Object.keys(t.mcpServers).length&&delete t.mcpServers,o(n.path,JSON.stringify(t,null,2)+"\n","utf8"),console.log(" removed "+n.name),s++)}}catch{}const g=a(n,".check");if(t(g))try{i(g,{recursive:!0,force:!0}),console.log(" removed ~/.check/")}catch{}0===s?console.log(" No Check installations found.\n"):(console.log(`\n Removed from ${s} tool${1!==s?"s":""}.`),console.log(" CLAUDE.md / AGENTS.md rules were left in place.\n"));try{await r}catch{}process.exit(0)}(),T.includes("--status")&&await async function(){const o=h(),n=a(o,".check"),s="win32"===u()?".exe":"",r=y();if(console.log(`\n Check v${f}\n`),r){const e=r.length>12?r.slice(0,8)+"..."+r.slice(-4):r;console.log(" Client ID: "+e)}else console.log(" Client ID: not set");const c=a(n,"truth-gate"+s);console.log(" Binary: "+(t(c)?"installed":"not found"));const i=a(n,"check.mjs");console.log(" Script: "+(t(i)?"installed":"not found")),console.log("\n Integrations:\n");const l=[{name:"Claude Code",path:a(o,".claude","settings.json"),test:e=>e.hooks?.PreToolUse?.some(e=>e.hooks?.some(C))||e.hooks?.PostToolUse?.some(e=>e.hooks?.some(C)),detail:e=>{const o=[];return e.hooks?.PreToolUse?.some(e=>e.hooks?.some(C))&&o.push("PreToolUse"),e.hooks?.PostToolUse?.some(e=>e.hooks?.some(C))&&o.push("PostToolUse"),o.join(", ")}},{name:"Gemini CLI",path:a(o,".gemini","settings.json"),test:e=>e.hooks?.BeforeTool?.some(e=>e.hooks?.some(e=>"check-gate"===e.name)),detail:()=>"BeforeTool"},{name:"Cursor",path:a(o,".cursor","hooks.json"),test:e=>e.hooks?.beforeShellExecution?.some(e=>v(e.command)),detail:()=>"beforeShellExecution"},{name:"Homebase",path:a(o,".homebase","hooks.json"),test:e=>e.hooks?.PreToolUse?.some(e=>e.hooks?.some(C))||e.hooks?.PostToolUse?.some(e=>e.hooks?.some(C)),detail:e=>{const o=[];return e.hooks?.PreToolUse?.some(e=>e.hooks?.some(C))&&o.push("PreToolUse"),e.hooks?.PostToolUse?.some(e=>e.hooks?.some(C))&&o.push("PostToolUse"),o.join(", ")}},{name:"Windsurf",path:a(o,".codeium","windsurf","mcp_config.json"),test:e=>!!e.mcpServers?.Check,detail:()=>"MCP"},{name:"Continue",path:a(process.cwd(),".continue","mcpServers","check.json"),test:e=>!!e.mcpServers?.Check,detail:()=>"MCP (project)"},{name:"Amazon Q",path:a(o,".aws","amazonq","mcp.json"),test:e=>!!e.mcpServers?.Check,detail:()=>"MCP"},{name:"Roo Code",path:a(process.cwd(),".roo","mcp.json"),test:e=>!!e.mcpServers?.Check,detail:()=>"MCP (project)"},{name:"Project MCP",path:a(process.cwd(),".mcp.json"),test:e=>!!e.mcpServers?.Check,detail:()=>"MCP (project)"}];for(const o of l)if(t(o.path))try{const n=JSON.parse(e(o.path,"utf8"));o.test(n)?console.log(" + "+o.name.padEnd(14)+" active ("+o.detail(n)+")"):console.log(" - "+o.name.padEnd(14)+" tool installed, Check not configured")}catch{console.log(" ? "+o.name.padEnd(14)+" config unreadable")}else console.log(" - "+o.name.padEnd(14)+" not detected");console.log(""),process.exit(0)}(),T.includes("--credits")&&await async function(){const e=y();e||(console.log("\n No Client ID found. Set GOL_CLIENT_ID or run --install first.\n"),process.exit(1));try{const o=await fetch(k.replace("/preflight","/credits"),{method:"GET",headers:{"X-GOL-CLIENT-ID":e,"User-Agent":"c/"+f},signal:AbortSignal.timeout(1e4)});o.ok||(console.log("\n Could not fetch credits (HTTP "+o.status+").\n"),process.exit(1));const n=await o.json();console.log(`\n Check v${f} — Credits\n`),void 0!==n.free_remaining&&console.log(" Free today: "+n.free_remaining+" / "+(n.free_daily||120)),void 0!==n.calls_today&&console.log(" Calls today: "+n.calls_today),void 0!==n.balance&&console.log(" Balance: $"+n.balance+" AUD"),void 0!==n.total_calls&&console.log(" Total calls: "+n.total_calls),n.plan&&console.log(" Plan: "+n.plan),0===Object.keys(n).length&&console.log(" "+JSON.stringify(n)),console.log("")}catch(e){console.log("\n Could not reach API: "+e.message+"\n")}process.exit(0)}(),T.includes("--docs")&&await async function(){console.log(`\n Check v${f} — Documentation\n\n Install: npx @golproductions/check --install <key>\n Uninstall: npx @golproductions/check --uninstall\n Status: npx @golproductions/check --status\n Credits: npx @golproductions/check --credits\n\n How it works:\n\n Check installs hooks into your AI coding tools. Every time\n the AI runs a command or edits a file, Check verifies it\n before or after execution.\n\n PreToolUse Validates commands before they run.\n PostToolUse Verifies results after execution.\n MCP Server Provides Check and CheckAndExecute tools.\n CLAUDE.md Adds anti-fabrication instructions.\n\n Supported tools:\n\n Claude Code, Gemini CLI, Cursor, Windsurf, Continue,\n Amazon Q Developer, Roo Code, Homebase\n\n Pricing:\n\n 120 free checks per day. Then $0.0068 AUD per check.\n Credits never expire. Pay as you go.\n\n Links:\n\n Website: https://golproductions.com/check\n Docs: https://github.com/golproductions/check\n Support: support@golproductions.com\n`);try{const{execSync:e}=await import("node:child_process"),o="https://github.com/golproductions/check";"win32"===u()?e(`start "" "${o}"`,{stdio:"ignore",shell:!0}):"darwin"===u()?e(`open "${o}"`,{stdio:"ignore"}):e(`xdg-open "${o}"`,{stdio:"ignore"})}catch{}process.exit(0)}(),(T.includes("--help")||T.includes("-h"))&&w(),T.includes("--mcp")&&(await import("./mcp.js"),process.exit(0)),!T.some(e=>e.startsWith("-"))&&process.stdin.isTTY&&w();const b=new Set(["sudo","nohup","nice","time","timeout","env"]),x=new Set(["cd","echo","printf","pwd","export","set","unset","alias","unalias","true","false","test","[","[[","exit","return","break","continue","shift","source",".","eval","exec","trap","wait","jobs","fg","bg","read","readonly","local","declare","typeset","let","getopts","hash","type","command","builtin","ulimit","umask","times","dirs","pushd","popd","for","while","until","if","then","else","elif","fi","do","done","case","esac","in","function","select","{","}","!"]);function U(){if("win32"!==u())return"bash";const e=[process.env.CLAUDE_CODE_GIT_BASH_PATH,"C:/Program Files/Git/bin/bash.exe","C:/Program Files/Git/usr/bin/bash.exe","C:/Program Files (x86)/Git/bin/bash.exe"].filter(Boolean);for(const o of e)try{if(t(o))return o}catch{}return null}function j(e,o){if(!e)return null;const n=e.split(/\r?\n/).find(e=>e.includes(o));if(!n)return null;let t=n.slice(n.indexOf(o)+o.length);return t=t.replace(/^['"\s:]+/,"").replace(/\s+$/,""),t?o+": "+t:null}function O(e,o,n){try{if("powershell"===n){const n=l("powershell",["-NoProfile","-NonInteractive","-Command","try { $null = Get-Command $env:CHECK_PROBE -ErrorAction Stop; exit 0 } catch { [Console]::Error.WriteLine($_.Exception.Message); exit 1 }"],{cwd:o,timeout:4e3,encoding:"utf8",env:{...process.env,CHECK_PROBE:e}});return n.error?null:{known:0===n.status,why:0===n.status?null:j(n.stderr,e)}}const t=U();if(!t)return null;const s=l(t,["-c",'type -- "$1"',"check",e],{cwd:o,timeout:4e3,encoding:"utf8"});return s.error?null:{known:0===s.status,why:0===s.status?null:j(s.stderr,e)}}catch{return null}}!async function(){let e="claude";try{let o,n="";for await(const e of process.stdin)n+=e;n=n.replace(/^/,"").trim(),n||(process.stderr.write("check: no hook input on stdin. This entrypoint is for tool hooks; run --help for CLI usage.\n"),process.exit(1));try{o=JSON.parse(n)}catch{return void P("claude",!1,"check: unreadable hook input (not JSON), command blocked")}if("PostToolUse"===o.hook_event_name)return void process.exit(0);e=function(e){return"string"!=typeof e.command||e.tool_input?"BeforeTool"===e.hook_event_name||e.toolCall?.argumentsJson?"gemini":"claude":"cursor"}(o);const t=function(e,o){if("cursor"===o)return e.command;if("gemini"===o){if(e.tool_input?.command)return e.tool_input.command;if(e.toolCall?.argumentsJson)try{const o="string"==typeof e.toolCall.argumentsJson?JSON.parse(e.toolCall.argumentsJson):e.toolCall.argumentsJson;return o.command||o.CommandLine||o.command_line}catch{return null}return null}return e.tool_input?.command}(o,e);if(!t)return void P(e,!0);const s=y();if(!s)return void P(e,!1,"check: GOL_CLIENT_ID not set. Get your key at https://golproductions.com/check");if("Bash"===o.tool_name){const o=await async function(e){try{const o=U();if(!o)return null;const n=l(o,["-n"],{input:e,timeout:4e3,encoding:"utf8"});if(n.error)return null;if(0===n.status){const e=(n.stderr||"").split("\n").find(e=>/here-document.*end-of-file/i.test(e));return!!e&&e.replace(/^[^:]*bash[^:]*:\s*/i,"").trim()}return((n.stderr||"").split("\n").find(e=>e.trim())||"syntax error").replace(/^[^:]*bash[^:]*:\s*/i,"").trim()}catch{return null}}(t);if("string"==typeof o)return void P(e,!1,`check: syntax error — ${o}`)}const r=new AbortController,c=setTimeout(()=>r.abort(),5e3),i=[],a=function(e,o,n,t){try{let s=function(e){const o=[[]];let n="",t=null;for(let s=0;s<e.length;s++){const r=e[s];t?r===t?t=null:n+=r:'"'!==r&&"'"!==r?"|"!==r&&"&"!==r&&";"!==r&&"\n"!==r?/\s/.test(r)?n&&(o[o.length-1].push(n),n=""):n+=r:(n&&(o[o.length-1].push(n),n=""),o[o.length-1].length&&o.push([]),"|"!==r&&"&"!==r||e[s+1]!==r||s++):t=r}n&&o[o.length-1].push(n);const s=new Set(["do","then","else","elif","if","while","until","!","{"]),r=[];for(const e of o){let o=null;for(const n of e)if(n&&!b.has(n)&&!s.has(n)&&!/^[\d.]+[smhd]?$/.test(n)&&(!n.includes("=")||n.startsWith("-"))&&!n.startsWith("-")){o=n;break}o&&r.push(o)}return r}(function(e){const o=e.split("\n"),n=[],t=[];for(const e of o){if(t.length){const{delim:o,dashed:n}=t[0];(n?e.replace(/^\t+/,""):e)===o&&t.shift();continue}n.push(e);for(const o of e.matchAll(/<<(-?)(?!<)\s*(?:'([^']+)'|"([^"]+)"|(\w+))/g))t.push({delim:o[2]||o[3]||o[4],dashed:"-"===o[1]})}return n.join("\n")}(e).replace(/\\\r?\n/g," "));if("powershell"!==n&&(s=s.filter(e=>!x.has(e))),0===s.length)return!0;if(s.some(e=>!/^[A-Za-z0-9_.\/\\~:@+=-]+$/.test(e)))return null;let r=!0;for(const e of s){const s=O(e,o,n);if(null===s)return null;!1===s.known&&(r=!1,t&&t.push(s.why||e+": not found"))}return r}catch{return null}}(t,o.cwd,"PowerShell"===o.tool_name?"powershell":"bash",i);if(!1===a&&i.length)return void P(e,!1,"denied by the shell that would run it. "+i.join("; "));const h={command:t,cwd:o.cwd||process.cwd(),platform:e,channel:"npm",tool_name:o.tool_name,v:f};null!==a&&(h.binary_exists=a);const u=await fetch(k,{method:"POST",headers:{"Content-Type":"application/json","X-GOL-CLIENT-ID":s,"User-Agent":"c/"+f},body:JSON.stringify(h),signal:r.signal});clearTimeout(c);const d=await u.json();if(!u.ok){if(429===u.status||/rate limit/i.test(d.reason||d.error||""))return void S(e,"check: rate limited (60 checks/min), command ran unverified. Check resumes automatically.");if(u.status>=500)return void S(e,"check: validation service error (HTTP "+u.status+"), command ran unverified. Check resumes automatically.");if(402===u.status){return void S(e,`check: you've used all ${d.daily_free||120} free checks for today and your balance is empty. Check is off until tomorrow — commands run unverified. Credits you buy never expire. ${d.upgrade||"Top up at https://www.golproductions.com/console.html"}`)}return void P(e,!1,d.reason||d.error||"check: request not authorized, command blocked")}"runnable"===d.verdict?P(e,!0):P(e,!1,(i.length?"denied by the shell that would run it. "+i.join("; "):null)||d.reason||"denied. Address the issue before continuing.")}catch{S(e,"check: validation service unreachable, command ran unverified. Check resumes automatically.")}}();
2
+ import{readFileSync as e,writeFileSync as o,mkdirSync as s,existsSync as n,createWriteStream as t,chmodSync as c,unlinkSync as r,rmSync as i}from"node:fs";import{spawnSync as l}from"node:child_process";import{join as a}from"node:path";import{homedir as h,platform as d,arch as m}from"node:os";import{pipeline as u}from"node:stream/promises";import{Readable as p}from"node:stream";const f="3.2.22",k="https://triage.golproductions.com/preflight",g=process.env.GOL_CLIENT_ID||"";function y(){if(g)return g;try{const o=e(a(h(),".check","key"),"utf8").trim();if(o)return o}catch{}try{const o=JSON.parse(e(a(h(),".claude","settings.json"),"utf8"));return o.env?.GOL_CLIENT_ID||""}catch{return""}}function v(e){return e&&(e.includes(".check")||e.includes("truth-gate"))}function C(e){return!!v(e.command)||!!e.args?.some(e=>v(e))}function T(){console.log(`\n Check v${f} — Anti-hallucination layer for AI coding agents\n\n Usage:\n\n npx @golproductions/check --install <key> Install Check with your Client ID\n npx @golproductions/check --uninstall Remove Check from all tools\n npx @golproductions/check --status Show what is installed and active\n npx @golproductions/check --credits Check your usage and balance\n npx @golproductions/check --docs View documentation\n npx @golproductions/check --help Show this help\n\n Get your key: https://golproductions.com/check\n Pricing: 120 free/day, then $0.0068 AUD per check\n`),process.exit(0)}const w=process.argv.slice(2);function P(e,o,s){if(o){const o={cursor:{permission:"allow"},gemini:{decision:"allow"},claude:{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow"}}};process.stdout.write(JSON.stringify(o[e]||o.claude)),process.exit(0)}"gemini"===e&&(process.stdout.write(JSON.stringify({decision:"deny",reason:s})),process.exit(2));const n={cursor:{permission:"deny",agent_message:s},claude:{hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:s}}};process.stdout.write(JSON.stringify(n[e]||n.claude)),process.exit(0)}function S(e,t){let c=!0;try{const e=a(h(),".check","credits-warned-"+(new Date).toISOString().slice(0,10));c=n(e),c||(s(a(h(),".check"),{recursive:!0}),o(e,"1"))}catch{c=!1}const r=c?void 0:t;if("gemini"===e&&(process.stdout.write(JSON.stringify({decision:"allow"})),r&&process.stderr.write(r),process.exit(0)),"cursor"===e){const e={permission:"allow"};r&&(e.user_message=r),process.stdout.write(JSON.stringify(e)),process.exit(0)}const i={hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"allow"}};r&&(i.systemMessage=r),process.stdout.write(JSON.stringify(i)),process.exit(0)}w.includes("--install")&&await async function(){let r=process.argv[3]||process.env.GOL_CLIENT_ID||"";r&&"your_key"!==r||(console.log("\n Activating Check (free, no signup)...\n"),r=await async function(){try{const e=await async function(){const{createHash:e}=await import("node:crypto"),{hostname:o,userInfo:s}=await import("node:os");let n="";try{n=s().username||""}catch{}const t=[o(),d(),m(),n].join("|");return e("sha256").update(t).digest("hex")}(),o=await fetch(k.replace("/preflight","/instant-key"),{method:"POST",headers:{"Content-Type":"application/json","User-Agent":"c/"+f},body:JSON.stringify({fingerprint:e,channel:"npm"}),signal:AbortSignal.timeout(1e4)});if(!o.ok)return null;const s=await o.json();return s&&s.client_id?s.client_id:null}catch{return null}}(),r||(console.log(" Could not activate automatically (offline, or this network hit its daily limit).\n"),console.log(" Get a key the manual way: https://golproductions.com/check\n"),console.log(" Then run: npx @golproductions/check --install YOUR_KEY\n"),process.exit(1)),console.log(" Activated. 120 free checks per day.\n"));const i=await async function(e){try{const o=await fetch(k,{method:"POST",headers:{"Content-Type":"application/json","X-GOL-CLIENT-ID":e,"User-Agent":"c/"+f},body:JSON.stringify({command:"echo check-install-verify",cwd:process.cwd(),v:f}),signal:AbortSignal.timeout(1e4)});if(o.ok)return{valid:!0,expired:!1};let s={};try{s=await o.json()}catch{}return{valid:!1,expired:/expir/i.test(s.reason||s.error||s.message||"")}}catch{return{valid:!1,expired:!1}}}(r);i.valid||(i.expired?(console.log("\n Your Client ID has expired: "+r),console.log("\n Renew your key at: https://golproductions.com/check\n")):(console.log("\n Invalid Client ID: "+r),console.log("\n Get a valid key at: https://golproductions.com/check\n")),process.exit(1)),console.log("\n Key verified. Installing Check...\n");const l=h();let g=0;const y=e(new URL(import.meta.url),"utf8"),T=a(l,".check");s(T,{recursive:!0});const w=a(T,"check.mjs").replace(/\\/g,"/");o(w,y,"utf8"),o(a(T,"key"),r,"utf8");const P="win32"===d()?".exe":"",S=a(T,"truth-gate"+P).replace(/\\/g,"/");await async function(e){const o="win32"===d()?"win":"darwin"===d()?"macos":"linux",s=`https://pub-e55366a7f5994be9be04f0e205179f4a.r2.dev/releases/truth-gate-v3.0.0-${o}-${"arm64"===m()?"arm64":"x64"}${"win"===o?".exe":""}`,n=await fetch(s);if(!n.ok)throw new Error(`Download failed: ${n.status}`);if(await u(p.fromWeb(n.body),t(e)),"win"!==o)try{c(e,493)}catch{}}(S);const b={command:"npx",args:["@golproductions/check","--mcp"],env:{GOL_CLIENT_ID:r}},U=[{name:"Claude Code",dir:a(l,".claude"),file:"settings.json",config:e=>(e.hooks=e.hooks||{},e.hooks.PreToolUse=(e.hooks.PreToolUse||[]).filter(e=>!e.hooks?.some(C)),e.hooks.PreToolUse.push({matcher:"Bash|PowerShell",hooks:[{type:"command",command:"node",args:[w]}]}),e.hooks.PostToolUse=(e.hooks.PostToolUse||[]).filter(e=>!e.hooks?.some(C)),e.hooks.PostToolUse.push({matcher:"Bash|PowerShell",hooks:[{type:"command",command:S}]},{matcher:"Edit|Write|NotebookEdit",hooks:[{type:"command",command:S}]}),e.env=e.env||{},e.env.GOL_CLIENT_ID=r,e)},{name:"Gemini CLI / Antigravity",dir:a(l,".gemini"),file:"settings.json",config:e=>{e.hooks=e.hooks||{},e.hooks.BeforeTool=e.hooks.BeforeTool||[];const o=e.hooks.BeforeTool;return o.find(e=>e.hooks?.some(e=>"check-gate"===e.name))||o.push({matcher:".*",hooks:[{type:"command",command:"node "+w,name:"check-gate"}]}),e}},{name:"Cursor",dir:a(l,".cursor"),file:"hooks.json",config:e=>(e.version=e.version||1,e.hooks=e.hooks||{},e.hooks.beforeShellExecution=(e.hooks.beforeShellExecution||[]).filter(e=>!v(e.command)),e.hooks.beforeShellExecution.push({command:"node "+w}),e)},{name:"Homebase",dir:a(l,".homebase"),file:"hooks.json",config:e=>(e.hooks=e.hooks||{},e.hooks.PreToolUse=(e.hooks.PreToolUse||[]).filter(e=>!e.hooks?.some(C)),e.hooks.PreToolUse.push({matcher:"Bash|PowerShell",hooks:[{type:"command",command:"node",args:[w]}]}),e.hooks.PostToolUse=(e.hooks.PostToolUse||[]).filter(e=>!e.hooks?.some(C)),e.hooks.PostToolUse.push({matcher:"Bash|PowerShell",hooks:[{type:"command",command:S}]}),e.env=e.env||{},e.env.GOL_CLIENT_ID=r,e)},{name:"Windsurf (MCP)",dir:a(l,".codeium","windsurf"),file:"mcp_config.json",config:e=>(e.mcpServers=e.mcpServers||{},e.mcpServers.Check=b,e)},{name:"Continue (MCP)",dir:a(process.cwd(),".continue","mcpServers"),file:"check.json",config:()=>({mcpServers:{Check:b}})},{name:"Amazon Q Developer (MCP)",dir:a(l,".aws","amazonq"),file:"mcp.json",config:e=>(e.mcpServers=e.mcpServers||{},e.mcpServers.Check={type:"stdio",...b},e)},{name:"Roo Code (project MCP)",dir:a(process.cwd(),".roo"),file:"mcp.json",config:e=>(e.mcpServers=e.mcpServers||{},e.mcpServers.Check=b,e)},{name:"Project MCP (shared)",dir:process.cwd(),file:".mcp.json",config:e=>(e.mcpServers=e.mcpServers||{},e.mcpServers.Check=b,e)}],x=["Windsurf (MCP)","Continue (MCP)","Amazon Q Developer (MCP)","Roo Code (project MCP)","Project MCP (shared)"];let j=!1;for(const t of U){const c=x.includes(t.name);if(!c&&!n(t.dir))continue;c&&s(t.dir,{recursive:!0});const r=a(t.dir,t.file);let i={};try{i=JSON.parse(e(r,"utf8"))}catch{}const l=t.config(i);o(r,JSON.stringify(l,null,2)+"\n","utf8"),g++,"Claude Code"===t.name&&(j=!0)}if(0===g){s(a(l,".claude"),{recursive:!0});const n=a(l,".claude","settings.json");let t={};try{t=JSON.parse(e(n,"utf8"))}catch{}const c=U[0].config(t);o(n,JSON.stringify(c,null,2)+"\n","utf8"),j=!0}const O=j?"CLAUDE.md":"AGENTS.md",I=a(process.cwd(),O);try{const s=n(I)?e(I,"utf8"):"";if(!s.includes("Never fabricate")){const e=s.length>0?s.trimEnd()+"\n\n":"";o(I,e+"Never fabricate, hallucinate, or invent values. If you don't have it, say you don't have it. No fake keys, no fake IDs, no fake paths, no fake URLs. If unsure, ask. Never guess and present it as fact.\n","utf8")}}catch{}console.log(`\n Your free GOL Client ID (this machine): ${r}`),console.log(" Shared by every editor on this machine. 120 free checks/day."),console.log(" Need more? Get a GOL API Key (paid, prepaid balance) at"),console.log(" https://www.golproductions.com/console"),console.log("\n By using Check you agree to the Terms and Privacy Policy:"),console.log(" golproductions.com/terms | golproductions.com/privacy"),console.log("\nSafe travels wanderer..\n"),process.exit(0)}(),w.includes("--uninstall")&&await async function(){const s=h();let t=0;console.log("\n Removing Check...\n");let c=Promise.resolve();try{const e=y();e&&(c=fetch(k.replace("/preflight","/log"),{method:"POST",headers:{"Content-Type":"application/json","X-GOL-CLIENT-ID":e,"User-Agent":"c/"+f},body:JSON.stringify({verdict:"uninstall",channel:"npm",os:d(),arch:m(),version:f}),signal:AbortSignal.timeout(3e3)}).catch(()=>{}))}catch{}const l=[{name:"Claude Code",path:a(s,".claude","settings.json"),clean:e=>(e.hooks?.PreToolUse&&(e.hooks.PreToolUse=e.hooks.PreToolUse.filter(e=>!e.hooks?.some(C)),0===e.hooks.PreToolUse.length&&delete e.hooks.PreToolUse),e.hooks?.PostToolUse&&(e.hooks.PostToolUse=e.hooks.PostToolUse.filter(e=>!e.hooks?.some(C)),0===e.hooks.PostToolUse.length&&delete e.hooks.PostToolUse),e.hooks&&0===Object.keys(e.hooks).length&&delete e.hooks,e.env&&(delete e.env.GOL_CLIENT_ID,0===Object.keys(e.env).length&&delete e.env),e)},{name:"Gemini CLI",path:a(s,".gemini","settings.json"),clean:e=>(e.hooks?.BeforeTool&&(e.hooks.BeforeTool=e.hooks.BeforeTool.filter(e=>!e.hooks?.some(e=>"check-gate"===e.name)),0===e.hooks.BeforeTool.length&&delete e.hooks.BeforeTool,0===Object.keys(e.hooks).length&&delete e.hooks),e)},{name:"Cursor",path:a(s,".cursor","hooks.json"),clean:e=>(e.hooks?.beforeShellExecution&&(e.hooks.beforeShellExecution=e.hooks.beforeShellExecution.filter(e=>!v(e.command)),0===e.hooks.beforeShellExecution.length&&delete e.hooks.beforeShellExecution,0===Object.keys(e.hooks).length&&delete e.hooks),e)},{name:"Homebase",path:a(s,".homebase","hooks.json"),clean:e=>(e.hooks?.PreToolUse&&(e.hooks.PreToolUse=e.hooks.PreToolUse.filter(e=>!e.hooks?.some(C)),0===e.hooks.PreToolUse.length&&delete e.hooks.PreToolUse),e.hooks?.PostToolUse&&(e.hooks.PostToolUse=e.hooks.PostToolUse.filter(e=>!e.hooks?.some(C)),0===e.hooks.PostToolUse.length&&delete e.hooks.PostToolUse),e.hooks&&0===Object.keys(e.hooks).length&&delete e.hooks,e.env&&(delete e.env.GOL_CLIENT_ID,0===Object.keys(e.env).length&&delete e.env),e)}],u=[{name:"Windsurf",path:a(s,".codeium","windsurf","mcp_config.json")},{name:"Amazon Q",path:a(s,".aws","amazonq","mcp.json")}],p=[{name:"Continue",path:a(process.cwd(),".continue","mcpServers","check.json"),deleteFile:!0},{name:"Roo Code",path:a(process.cwd(),".roo","mcp.json")},{name:"Project MCP",path:a(process.cwd(),".mcp.json")}];for(const s of l)if(n(s.path))try{const n=JSON.parse(e(s.path,"utf8")),c=s.clean(n);o(s.path,JSON.stringify(c,null,2)+"\n","utf8"),console.log(" removed "+s.name),t++}catch{}for(const s of[...u,...p])if(n(s.path))try{if(s.deleteFile)r(s.path),console.log(" removed "+s.name),t++;else{const n=JSON.parse(e(s.path,"utf8"));n.mcpServers?.Check&&(delete n.mcpServers.Check,0===Object.keys(n.mcpServers).length&&delete n.mcpServers,o(s.path,JSON.stringify(n,null,2)+"\n","utf8"),console.log(" removed "+s.name),t++)}}catch{}const g=a(s,".check");if(n(g))try{i(g,{recursive:!0,force:!0}),console.log(" removed ~/.check/")}catch{}0===t?console.log(" No Check installations found.\n"):(console.log(`\n Removed from ${t} tool${1!==t?"s":""}.`),console.log(" CLAUDE.md / AGENTS.md rules were left in place.\n"));try{await c}catch{}process.exit(0)}(),w.includes("--status")&&await async function(){const o=h(),s=a(o,".check"),t="win32"===d()?".exe":"",c=y();if(console.log(`\n Check v${f}\n`),c){const e=c.length>12?c.slice(0,8)+"..."+c.slice(-4):c;console.log(" Client ID: "+e)}else console.log(" Client ID: not set");const r=a(s,"truth-gate"+t);console.log(" Binary: "+(n(r)?"installed":"not found"));const i=a(s,"check.mjs");console.log(" Script: "+(n(i)?"installed":"not found")),console.log("\n Integrations:\n");const l=[{name:"Claude Code",path:a(o,".claude","settings.json"),test:e=>e.hooks?.PreToolUse?.some(e=>e.hooks?.some(C))||e.hooks?.PostToolUse?.some(e=>e.hooks?.some(C)),detail:e=>{const o=[];return e.hooks?.PreToolUse?.some(e=>e.hooks?.some(C))&&o.push("PreToolUse"),e.hooks?.PostToolUse?.some(e=>e.hooks?.some(C))&&o.push("PostToolUse"),o.join(", ")}},{name:"Gemini CLI",path:a(o,".gemini","settings.json"),test:e=>e.hooks?.BeforeTool?.some(e=>e.hooks?.some(e=>"check-gate"===e.name)),detail:()=>"BeforeTool"},{name:"Cursor",path:a(o,".cursor","hooks.json"),test:e=>e.hooks?.beforeShellExecution?.some(e=>v(e.command)),detail:()=>"beforeShellExecution"},{name:"Homebase",path:a(o,".homebase","hooks.json"),test:e=>e.hooks?.PreToolUse?.some(e=>e.hooks?.some(C))||e.hooks?.PostToolUse?.some(e=>e.hooks?.some(C)),detail:e=>{const o=[];return e.hooks?.PreToolUse?.some(e=>e.hooks?.some(C))&&o.push("PreToolUse"),e.hooks?.PostToolUse?.some(e=>e.hooks?.some(C))&&o.push("PostToolUse"),o.join(", ")}},{name:"Windsurf",path:a(o,".codeium","windsurf","mcp_config.json"),test:e=>!!e.mcpServers?.Check,detail:()=>"MCP"},{name:"Continue",path:a(process.cwd(),".continue","mcpServers","check.json"),test:e=>!!e.mcpServers?.Check,detail:()=>"MCP (project)"},{name:"Amazon Q",path:a(o,".aws","amazonq","mcp.json"),test:e=>!!e.mcpServers?.Check,detail:()=>"MCP"},{name:"Roo Code",path:a(process.cwd(),".roo","mcp.json"),test:e=>!!e.mcpServers?.Check,detail:()=>"MCP (project)"},{name:"Project MCP",path:a(process.cwd(),".mcp.json"),test:e=>!!e.mcpServers?.Check,detail:()=>"MCP (project)"}];for(const o of l)if(n(o.path))try{const s=JSON.parse(e(o.path,"utf8"));o.test(s)?console.log(" + "+o.name.padEnd(14)+" active ("+o.detail(s)+")"):console.log(" - "+o.name.padEnd(14)+" tool installed, Check not configured")}catch{console.log(" ? "+o.name.padEnd(14)+" config unreadable")}else console.log(" - "+o.name.padEnd(14)+" not detected");console.log(""),process.exit(0)}(),w.includes("--credits")&&await async function(){const e=y();e||(console.log("\n No Client ID found. Set GOL_CLIENT_ID or run --install first.\n"),process.exit(1));try{const o=await fetch(k.replace("/preflight","/credits"),{method:"GET",headers:{"X-GOL-CLIENT-ID":e,"User-Agent":"c/"+f},signal:AbortSignal.timeout(1e4)});o.ok||(console.log("\n Could not fetch credits (HTTP "+o.status+").\n"),process.exit(1));const s=await o.json();console.log(`\n Check v${f} — Credits\n`),void 0!==s.free_remaining&&console.log(" Free today: "+s.free_remaining+" / "+(s.free_daily||120)),void 0!==s.calls_today&&console.log(" Calls today: "+s.calls_today),void 0!==s.balance&&console.log(" Balance: $"+s.balance+" AUD"),void 0!==s.total_calls&&console.log(" Total calls: "+s.total_calls),s.plan&&console.log(" Plan: "+s.plan),0===Object.keys(s).length&&console.log(" "+JSON.stringify(s)),console.log("")}catch(e){console.log("\n Could not reach API: "+e.message+"\n")}process.exit(0)}(),w.includes("--docs")&&await async function(){console.log(`\n Check v${f} — Documentation\n\n Install: npx @golproductions/check --install <key>\n Uninstall: npx @golproductions/check --uninstall\n Status: npx @golproductions/check --status\n Credits: npx @golproductions/check --credits\n\n How it works:\n\n Check installs hooks into your AI coding tools. Every time\n the AI runs a command or edits a file, Check verifies it\n before or after execution.\n\n PreToolUse Validates commands before they run.\n PostToolUse Verifies results after execution.\n MCP Server Provides Check and CheckAndExecute tools.\n CLAUDE.md Adds anti-fabrication instructions.\n\n Supported tools:\n\n Claude Code, Gemini CLI, Cursor, Windsurf, Continue,\n Amazon Q Developer, Roo Code, Homebase\n\n Pricing:\n\n 120 free checks per day. Then $0.0068 AUD per check.\n Credits never expire. Pay as you go.\n\n Links:\n\n Website: https://golproductions.com/check\n Docs: https://github.com/golproductions/check\n Support: support@golproductions.com\n`);try{const{execSync:e}=await import("node:child_process"),o="https://github.com/golproductions/check";"win32"===d()?e(`start "" "${o}"`,{stdio:"ignore",shell:!0}):"darwin"===d()?e(`open "${o}"`,{stdio:"ignore"}):e(`xdg-open "${o}"`,{stdio:"ignore"})}catch{}process.exit(0)}(),(w.includes("--help")||w.includes("-h"))&&T(),w.includes("--mcp")&&(await import("./mcp.js"),process.exit(0)),!w.some(e=>e.startsWith("-"))&&process.stdin.isTTY&&T(),async function(){let e="claude";try{let o,s="";for await(const e of process.stdin)s+=e;s=s.replace(/^/,"").trim(),s||(process.stderr.write("check: no hook input on stdin. This entrypoint is for tool hooks; run --help for CLI usage.\n"),process.exit(1));try{o=JSON.parse(s)}catch{return void P("claude",!1,"check: unreadable hook input (not JSON), command blocked")}if("PostToolUse"===o.hook_event_name)return void process.exit(0);e=function(e){return"string"!=typeof e.command||e.tool_input?"BeforeTool"===e.hook_event_name||e.toolCall?.argumentsJson?"gemini":"claude":"cursor"}(o);const t=function(e,o){if("cursor"===o)return e.command;if("gemini"===o){if(e.tool_input?.command)return e.tool_input.command;if(e.toolCall?.argumentsJson)try{const o="string"==typeof e.toolCall.argumentsJson?JSON.parse(e.toolCall.argumentsJson):e.toolCall.argumentsJson;return o.command||o.CommandLine||o.command_line}catch{return null}return null}return e.tool_input?.command}(o,e);if(!t)return void P(e,!0);const c=y();if(!c)return void P(e,!1,"check: GOL_CLIENT_ID not set. Get your key at https://golproductions.com/check");if("Bash"===o.tool_name){const o=await async function(e){try{const o=function(){if("win32"!==d())return"bash";const e=[process.env.CLAUDE_CODE_GIT_BASH_PATH,"C:/Program Files/Git/bin/bash.exe","C:/Program Files/Git/usr/bin/bash.exe","C:/Program Files (x86)/Git/bin/bash.exe"].filter(Boolean);for(const o of e)try{if(n(o))return o}catch{}return null}();if(!o)return null;const s=l(o,["-n"],{input:e,timeout:4e3,encoding:"utf8"});if(s.error)return null;if(0===s.status){const e=(s.stderr||"").split("\n").find(e=>/here-document.*end-of-file/i.test(e));return!!e&&e.replace(/^[^:]*bash[^:]*:\s*/i,"").trim()}return((s.stderr||"").split("\n").find(e=>e.trim())||"syntax error").replace(/^[^:]*bash[^:]*:\s*/i,"").trim()}catch{return null}}(t);if("string"==typeof o)return void P(e,!1,`check: syntax error — ${o}`)}const r=new AbortController,i=setTimeout(()=>r.abort(),5e3),a={command:t,cwd:o.cwd||process.cwd(),platform:e,channel:"npm",tool_name:o.tool_name,v:f},h=await fetch(k,{method:"POST",headers:{"Content-Type":"application/json","X-GOL-CLIENT-ID":c,"User-Agent":"c/"+f},body:JSON.stringify(a),signal:r.signal});clearTimeout(i);const m=await h.json();if(!h.ok){if(429===h.status||/rate limit/i.test(m.reason||m.error||""))return void S(e,"check: rate limited (60 checks/min), command ran unverified. Check resumes automatically.");if(h.status>=500)return void S(e,"check: validation service error (HTTP "+h.status+"), command ran unverified. Check resumes automatically.");if(402===h.status){return void S(e,`check: you've used all ${m.daily_free||120} free checks for today and your balance is empty. Check is off until tomorrow — commands run unverified. Credits you buy never expire. ${m.upgrade||"Top up at https://www.golproductions.com/console.html"}`)}return void P(e,!1,m.reason||m.error||"check: request not authorized, command blocked")}"runnable"===m.verdict?P(e,!0):P(e,!1,m.reason||"denied. Address the issue before continuing.")}catch{S(e,"check: validation service unreachable, command ran unverified. Check resumes automatically.")}}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@golproductions/check",
3
- "version": "3.2.14",
3
+ "version": "3.2.22",
4
4
  "description": "Less hallucinations. A command firewall for AI agents: validates every shell command before execution, so fabricated commands are denied before they run.",
5
5
  "bin": {
6
6
  "check": "dist/index.js",