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.

4 lines (3 loc) 5.7 kB
import{spawn as f}from"node:child_process";import{log as d}from"../log/logger.js";import{checkPrerequisite as b}from"./preflight.js";const u=64*1024,h={node:{id:"node",label:"Node.js",macos:"NONINTERACTIVE=1 CI=1 brew install node 2>&1 && brew link node --overwrite 2>/dev/null; command -v node >/dev/null 2>&1 || (npm install -g n 2>&1 && n lts 2>&1)",linux:'curl -fsSL https://fnm.vercel.app/install | bash -s -- --install-latest-lts --skip-shell 2>&1 && eval "$(fnm env)" && fnm install --lts 2>&1 && fnm use --lts 2>&1',windows:"winget install Schniz.fnm --accept-source-agreements --accept-package-agreements",mode:"shell",timeoutMs:18e4},npm:{id:"npm",label:"npm",macos:null,linux:null,windows:null,mode:"exec",timeoutMs:6e4},curl:{id:"curl",label:"curl",macos:null,linux:'sudo apt-get install -y -qq curl 2>/dev/null || sudo dnf install -y curl 2>/dev/null || sudo pacman -S --noconfirm curl 2>/dev/null || echo "curl install skipped: no supported package manager"',windows:null,mode:"shell",timeoutMs:6e4},gh:{id:"gh",label:"GitHub CLI",macos:"NONINTERACTIVE=1 brew install gh 2>/dev/null",linux:`(command -v apt-get >/dev/null 2>&1 && (sudo mkdir -p /etc/apt/keyrings 2>/dev/null; wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg 2>/dev/null | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg >/dev/null 2>&1; echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list >/dev/null 2>&1; sudo apt-get update -qq 2>/dev/null; sudo apt-get install -y -qq gh 2>/dev/null)) || (command -v dnf >/dev/null 2>&1 && sudo dnf install -y 'dnf-command(config-manager)' 2>/dev/null && sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo 2>/dev/null && sudo dnf install -y gh 2>/dev/null) || echo "gh install skipped: no supported package manager"`,windows:"winget install GitHub.cli --accept-source-agreements --accept-package-agreements",mode:"shell",timeoutMs:18e4},brew:{id:"brew",label:"Homebrew",macos:'NONINTERACTIVE=1 CI=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',linux:'NONINTERACTIVE=1 CI=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',windows:null,mode:"shell",timeoutMs:3e5}};async function w(e,t){const i=h[e.id];if(!i)return{ok:!1,output:`No install spec for ${e.id}`};const n=i[t];if(!n){const l=g(e.id,t);return{ok:!1,output:`${e.label} cannot be auto-installed on ${t}.${l?` Please install manually: ${l}`:""}`}}d.info("installer",`Installing prerequisite ${e.label}: ${n}`);try{const l=await k(n,i.timeoutMs);return d.info("installer",`Prerequisite ${e.label} installed successfully`),{ok:!0,output:l}}catch(l){const a=l instanceof Error?l.message:String(l);d.error("installer",`Failed to install prerequisite ${e.label}: ${a}`);const c=g(e.id,t),o=e.id==="brew"&&(a.includes("code 1")||a.includes("sudo"))?` Note: Homebrew installation may require administrator (sudo) password. Try running: NONINTERACTIVE=1 CI=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" in your terminal.`:"";return{ok:!1,output:`${a}${o}${c?` Manual install: ${c}`:""}`}}}async function T(e,t){const i=[];for(const n of e){const l=await w(n,t);if(i.push({prereq:n,ok:l.ok,output:l.output}),!l.ok)return{allOk:!1,results:i};if(!(await b(n.id,t)).met)return i.push({prereq:{...n,met:!1},ok:!1,output:`${n.label} install command succeeded but verification failed. This usually means you need to open a new terminal or run: source ~/.bashrc (or ~/.zshrc)`}),{allOk:!1,results:i}}return{allOk:!0,results:i}}function E(e,t){return h[e]?.[t]??null}function g(e,t){switch(e){case"node":return t==="windows"?"Install Node.js LTS from https://nodejs.org or run: winget install OpenJS.NodeJS.LTS":"Install Node.js LTS from https://nodejs.org or run: brew install node (macOS) / follow instructions at https://fnm.vercel.app (Linux)";case"npm":return"npm comes bundled with Node.js. Install Node.js first.";case"curl":return t==="windows"?"curl is built into Windows 10+. For older versions, install from https://curl.se/windows/":t==="macos"?"curl is pre-installed on macOS. If missing, install Xcode Command Line Tools: xcode-select --install":"Install curl: sudo apt install curl (Debian/Ubuntu) or sudo dnf install curl (Fedora/RHEL)";case"gh":return"Install GitHub CLI from https://cli.github.com or follow instructions at https://github.com/cli/cli#installation";case"brew":return'Install Homebrew from https://brew.sh or run: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"';default:return null}}function k(e,t){return new Promise((i,n)=>{const l=process.platform==="win32",o=f(l?"cmd.exe":"sh",l?["/d","/s","/c",e]:["-c",e],{timeout:t,stdio:["ignore","pipe","pipe"],env:{...process.env,NONINTERACTIVE:"1",DEBIAN_FRONTEND:"noninteractive"}});let s="",m=!1;const p=setTimeout(()=>{m=!0,o.kill("SIGTERM"),setTimeout(()=>{try{o.kill("SIGKILL")}catch{}},5e3).unref()},t);o.stdout?.on("data",r=>{s+=r.toString("utf-8"),s.length>u&&(s=s.slice(-u))}),o.stderr?.on("data",r=>{s+=r.toString("utf-8"),s.length>u&&(s=s.slice(-u))}),o.on("error",r=>{clearTimeout(p),n(r)}),o.on("close",r=>{if(clearTimeout(p),s.length>u&&(s=s.slice(-u)),m){n(new Error(`Timed out after ${t/1e3}s`));return}if(r!==0){n(new Error(`Process exited with code ${r}: ${s.slice(-1024)}`));return}i(s.trim())})})}export{E as getPrereqInstallCommand,g as getPrereqManualInstructions,T as installMissingPrerequisites,w as installPrerequisite};