#!/bin/sh # revnu-agent-installer: 2 # Revnu agent setup: # # curl -fsSL https://revnu.com/install | sh # # Connects Revnu's MCP server (https://revnu.com/api/mcp) to Claude Code, Codex, Gemini CLI and Cursor # when they're installed, and adds the Revnu skills so your coding agent knows # when Revnu can get you customers. Nothing is created or paid for here: you # sign in and choose a plan later, in your browser. set -u # One function, called on the last line: sh reads it all before running anything, and # every command gets /dev/null as stdin, so none can swallow the rest of a piped script. main() { URL="https://revnu.com/api/mcp" NAME="revnu" tools=0 skill_agents="" failed=0 say() { printf '%s\n' "$*"; } have() { command -v "$1" >/dev/null 2>&1; } if ! have node || ! have npx; then say "Setup incomplete. Install Node.js 22.20 or later, then rerun: curl -fsSL https://revnu.com/install | sh" return 1 fi if ! node -e 'const [major, minor] = process.versions.node.split(".").map(Number); process.exit(major > 22 || (major === 22 && minor >= 20) ? 0 : 1)' >/dev/null 2>&1; then say "Setup incomplete. The skills installer requires Node.js 22.20 or later. Upgrade Node.js, then rerun: curl -fsSL https://revnu.com/install | sh" return 1 fi state_file="${XDG_CONFIG_HOME:-$HOME/.config}/revnu/agent-tools.json" if [ -f "$state_file" ] && [ "${REVNU_AGENT_SKILLS_MODE:-}" != "external" ]; then say "Repairing the managed bundle while preserving local skill edits" npx -y @revnu/cli setup agent return $? fi # Merge only Revnu's entry into the user's file, preserving other settings. configure_json() { node - "$1" "$2" "$NAME" "$3" <<'NODE' const fs = require("node:fs"); const path = require("node:path"); const [configuredFile, key, name, encoded] = process.argv.slice(2); let file = configuredFile; const object = value => value !== null && typeof value === "object" && !Array.isArray(value); let temporary; try { if (fs.lstatSync(file, { throwIfNoEntry: false })) file = fs.realpathSync(file); const root = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, "utf8")) : {}; if (!object(root) || (root[key] !== undefined && !object(root[key]))) throw Error("Expected an object"); root[key] = { ...root[key], [name]: JSON.parse(encoded) }; fs.mkdirSync(path.dirname(file), { recursive: true }); temporary = file + ".revnu-" + process.pid; const mode = fs.existsSync(file) ? fs.statSync(file).mode & 0o777 : 0o600; fs.writeFileSync(temporary, JSON.stringify(root, null, 2) + "\n", { mode, flag: "wx" }); fs.renameSync(temporary, file); } catch { if (temporary) { try { fs.unlinkSync(temporary); } catch {} } console.error("Could not update " + file + ". Existing settings were preserved; fix the file and rerun."); process.exit(1); } NODE } if have claude || [ -d "${CLAUDE_CONFIG_DIR:-$HOME/.claude}" ] || [ -f "$HOME/.claude.json" ]; then skill_agents="$skill_agents claude-code" tools=1 claude_config="$HOME/.claude.json" if [ -n "${CLAUDE_CONFIG_DIR:-}" ]; then claude_config="$CLAUDE_CONFIG_DIR/.claude.json"; fi if configure_json "$claude_config" mcpServers '{"type":"http","url":"https://revnu.com/api/mcp"}'; then say "Claude Code: Revnu configured globally" else failed=1; fi fi if have codex; then skill_agents="$skill_agents codex" tools=1 # Resolve config outside the caller's project so a local server cannot pass as global. scope_dir=$(mktemp -d) || return 1 codex_global() { (cd "$scope_dir" && codex "$@"); } codex_configured() { codex_global mcp get "$NAME" --json 2>/dev/null | node -e ' let input=""; process.stdin.on("data", c => input += c); process.stdin.on("end", () => { try { const s=JSON.parse(input); process.exit(s.enabled !== false && s.transport.url === process.argv[1] ? 0 : 1); } catch { process.exit(1); } }); ' "$URL" } if codex_configured; then say "Codex: Revnu already configured globally" else (cd "$scope_dir" && exec codex mcp add "$NAME" --url "$URL") >/dev/null 2>&1 & pid=$! trap 'kill "$pid" 2>/dev/null; rm -rf "$scope_dir"; exit 1' HUP INT TERM i=0 while [ "$i" -lt 15 ] && ! codex_configured; do sleep 1; i=$((i + 1)); done kill "$pid" 2>/dev/null wait "$pid" 2>/dev/null trap - HUP INT TERM if codex_configured; then say "Codex: Revnu configured globally. Sign in with: codex mcp login $NAME" else failed=1; say "Codex: couldn't configure globally. Run: codex mcp add $NAME --url $URL"; fi fi rm -rf "$scope_dir" elif [ -d "${CODEX_HOME:-$HOME/.codex}" ]; then say "Skipping Codex: its CLI is missing. Other detected hosts will still be configured. Install Codex CLI and rerun to include it." fi if have gemini || [ -d "${GEMINI_CLI_HOME:-$HOME}/.gemini" ]; then skill_agents="$skill_agents gemini-cli" tools=1 if configure_json "${GEMINI_CLI_HOME:-$HOME}/.gemini/settings.json" mcpServers '{"httpUrl":"https://revnu.com/api/mcp"}'; then say "Gemini CLI: Revnu configured globally. Sign in with: /mcp auth revnu" else failed=1; fi fi if have cursor || [ -d "$HOME/.cursor" ]; then skill_agents="$skill_agents cursor" tools=1 if configure_json "$HOME/.cursor/mcp.json" mcpServers '{"url":"https://revnu.com/api/mcp"}'; then say "Cursor: Revnu configured globally" else failed=1; fi fi if [ "$tools" -eq 0 ]; then say "Setup incomplete. No supported coding host found. Install Claude Code, Codex, Gemini CLI or Cursor, then rerun." say "For web connectors and native plugins: https://revnu.com/agents" return 1 fi skill_revision="" if [ "${REVNU_AGENT_SKILLS_MODE:-}" != "external" ]; then skill_revision=$(node -e 'fetch("https://api.github.com/repos/revnu-app/revnu-plugin/commits/main", {signal: AbortSignal.timeout(5000), headers: {Accept: "application/vnd.github+json"}}).then(async r => { if (!r.ok) throw Error("Revision lookup failed"); const body = await r.json(); if (!/^[a-f0-9]{40}$/.test(body.sha)) throw Error("Invalid revision"); process.stdout.write(body.sha); }).catch(() => process.exit(1))') || { say "Setup incomplete. Could not resolve the growth skill revision. Rerun this installer." return 1 } fi # Explicit hosts also work when the installer is launched from inside one agent. set -- if [ -n "$skill_agents" ]; then set -- --agent $skill_agents; fi if have npx; then if [ "${REVNU_AGENT_SKILLS_MODE:-}" = "external" ]; then say "Verifying CLI-managed global skills" elif npx -y skills@latest add "https://github.com/revnu-app/revnu-plugin/tree/$skill_revision" --global --yes "$@" >/dev/null 2>&1; then say "Revnu skills installed" else failed=1; say "Revnu skills: couldn't install. Run: npx -y skills@latest add revnu-app/revnu-plugin --global --yes"; fi else failed=1 say "Revnu skills: need Node.js. Then run: npx -y skills@latest add revnu-app/revnu-plugin --global --yes" fi if [ "$failed" -eq 0 ]; then if ! node - "$skill_agents" "$skill_revision" <<'NODE' const fs = require("node:fs"); const path = require("node:path"); const names = ["revnu", "first-customers", "find-leads", "cold-email", "linkedin-outreach", "ads", "seo-ai-answers", "results"]; const managed = {}; const seen = new Set(); function collect(file, output) { const real = fs.realpathSync(file); if (seen.has(real)) return; seen.add(real); if (seen.size > 500) throw Error("Skill tree too large"); const stat = fs.statSync(real); if (stat.isDirectory()) { for (const child of fs.readdirSync(real)) collect(path.join(real, child), output); } else if (stat.isFile()) { if (stat.size > 5000000) throw Error("Skill file too large"); output[real] = require("node:crypto").createHash("sha256").update(fs.readFileSync(real)).digest("hex"); } } try { for (const agent of process.argv[2].trim().split(/\s+/)) { const directory = agent === "claude-code" ? path.join(process.env.CLAUDE_CONFIG_DIR || path.join(process.env.HOME, ".claude"), "skills") : path.join(process.env.HOME, ".agents", "skills"); for (const name of names) { if (!fs.readFileSync(path.join(directory, name, "SKILL.md"), "utf8").trim()) throw Error("Empty skill"); managed[name] ||= {}; collect(path.join(directory, name), managed[name]); } } if (process.env.REVNU_AGENT_SKILLS_MODE !== "external") { const state = path.join(process.env.XDG_CONFIG_HOME || path.join(process.env.HOME, ".config"), "revnu", "agent-tools.json"); fs.mkdirSync(path.dirname(state), { recursive: true, mode: 0o700 }); if (!fs.existsSync(state)) fs.writeFileSync(state, JSON.stringify({ files: managed, revision: process.argv[3], latestRevision: process.argv[3], skillRevisions: Object.fromEntries(names.map(name => [name, process.argv[3]])), checkedAt: Date.now() }) + "\n", { mode: 0o600, flag: "wx" }); } } catch { console.error("Global skill files are missing or unreadable. Rerun the installer to repair them."); process.exit(1); } NODE then failed=1; fi fi if [ "$failed" -ne 0 ]; then say "Setup incomplete. Fix the steps above, then rerun this installer." return 1 fi say "" say "Skills installed globally and MCP configured globally. Restart your coding agent, sign in to Revnu, then say: \"Set me up with revnu.com\"" } main