UNPKG

grix-connector

Version:

Connect local AI coding agents (Claude, Codex, Gemini, Qwen, DeepSeek, Cursor, OpenCode, Pi, OpenHuman, Reasonix) to the Grix scheduling platform. Also serves as an OpenClaw plugin for Grix channel transport.

3 lines (2 loc) 2.38 kB
import{execFile as u}from"node:child_process";import{existsSync as w}from"node:fs";import{join as h,dirname as x,delimiter as m}from"node:path";import{promisify as f}from"node:util";import{log as d}from"../log/logger.js";const g=3e3;function y(t,r){const e=[".cmd",".bat",".exe",""];for(const o of t)if(o)for(const i of e){const n=h(o,`${r}${i}`);if(w(n))return n}return null}let c=null;const v=1e4;function M(){c=null}async function P(){if(c&&Date.now()-c.at<v)return c.dirs;const t=f(u),r=async o=>{try{const{stdout:i}=await t("powershell",["-NoProfile","-NonInteractive","-Command",`[Environment]::GetEnvironmentVariable('Path','${o}')`],{timeout:5e3,encoding:"utf-8",windowsHide:!0});return i.split(";").map(n=>n.trim()).filter(Boolean)}catch(i){return d.warn("cli-probe",`\u8BFB\u53D6\u6CE8\u518C\u8868 ${o} PATH \u5931\u8D25: ${i instanceof Error?i.message:String(i)}`),[]}},e=[...await r("User"),...await r("Machine")];return c={dirs:e,at:Date.now()},e}async function p(t){if(process.platform!=="win32")return null;const r=await P(),e=y(r,t);return e&&$(x(e)),e}function $(t){const r=process.env.PATH??"";r.split(m).some(o=>o.toLowerCase()===t.toLowerCase())||(process.env.PATH=r?`${t}${m}${r}`:t,d.info("cli-probe",`\u5DF2\u5C06 ${t} \u6CE8\u5165\u5F53\u524D\u8FDB\u7A0B PATH\uFF08\u5B89\u88C5\u540E\u81EA\u6108\uFF09`))}async function S(t){const r=f(u),e=process.platform==="win32",o=e?"where":"which";try{const{stdout:i}=await r(o,[t],{timeout:3e3,encoding:"utf-8"}),n=i.trim().split(/\r?\n/).map(s=>s.trim()).filter(Boolean);if(n.length>0){if(e){const s=n.find(l=>/\.(cmd|bat)$/i.test(l));if(s)return s;const a=n.find(l=>/\.exe$/i.test(l));return a||n[0]}return n[0]}return e?await p(t):null}catch{return e?await p(t):null}}async function W(t,r=["--version"],e=g){const o=f(u),i=process.platform==="win32";try{const n=i&&/\s/.test(t)&&!t.startsWith('"')?`"${t}"`:t,{stdout:s,stderr:a}=await o(n,r,{timeout:e,encoding:"utf-8",...i?{shell:!0}:{}});return{version:(s||a||"").trim().split(` `)[0]?.trim()||null||null}}catch(n){const s=n;return s.killed||s.code==="ETIMEDOUT"?{version:null,error:{code:"version_timeout",message:"version check timed out"}}:{version:null,error:{code:"cli_error",message:s.message??String(n)}}}}export{y as findWindowsExecutableInDirs,W as getCliVersion,M as invalidateWindowsRegistryPathCache,S as resolveCliPath,p as resolveWindowsInstalledCli};