UNPKG

@sellable/install

Version:

One-command installer for Sellable MCP in Claude Code, Codex, and Hermes

260 lines (244 loc) • 9.45 kB
// Admin only: run the Admin on the Google Antigravity subscription (Gemini 4 // Neon through Google's agy CLI) ahead of its Codex and OpenRouter chain. // Owner, 2026-11-19: "agy -> codex -> openrouter just for admin machines". // // The Admin image bakes agy and the Hermes provider plugin that drives it (see // fly-admin-image/Dockerfile). Signing in is agy's own Google flow, run once on // the Admin as the hermes user with HOME=/opt/data (`sellable-admin-antigravity // login`), so the token lives on the Admin volume and agy refreshes it there. // Nothing here writes the token. While no valid sign-in is present the Admin // keeps the Codex-first chain that Customer runtimes use, so this module // changes nothing until someone signs in. // // Google's Antigravity terms forbid driving the service from third-party // software; the owner accepted that risk for the Admin only. Never use this on // Customer runtimes. import { accessSync, constants, lstatSync, readFileSync, statSync, } from "node:fs"; import { join } from "node:path"; import { MODEL_AUTH_DEFAULT_MODEL, MODEL_AUTH_PROVIDER, modelAuthConfigOverlay, modelOrderFor, withModelOrder, withSigninTimeouts, } from "../model-auth-reconciler.mjs"; import { CLAUDE_SIGNIN_MODEL, CLAUDE_SIGNIN_PROVIDER, MODEL_SIGNIN_REQUEST_TIMEOUT_SECONDS, } from "../model-signins.mjs"; export const ADMIN_ANTIGRAVITY_PROVIDER = "antigravity-subscription-directsdk"; export const ADMIN_ANTIGRAVITY_MODEL = "gemini-4-neon"; // The plugin caps Hermes' xhigh at high. export const ADMIN_ANTIGRAVITY_REASONING_EFFORT = "high"; // A turn waits for agy to start and think, so this leg gets a longer ceiling // than the HTTP providers' 60 seconds. export const ADMIN_ANTIGRAVITY_REQUEST_TIMEOUT_SECONDS = 120; export const ADMIN_ANTIGRAVITY_COMMAND = "/usr/local/bin/agy"; export const ADMIN_ANTIGRAVITY_PLUGIN_ROOT = "/opt/hermes/plugins/model-providers/antigravity-subscription-directsdk"; // Each idle agy worker holds about 250 MB; release them after two minutes. export const ADMIN_ANTIGRAVITY_WORKER_IDLE_SECONDS = 120; const TOKEN_FILE = "antigravity-oauth-token"; const MAX_TOKEN_BYTES = 64 * 1024; export function adminAntigravityConfigDir(dataRoot) { return join(dataRoot, ".gemini", "antigravity-cli"); } /** * True only when the image has agy and the plugin and a private agy sign-in * with a refresh token is on the volume. Any doubt answers false, which keeps * the Codex-first chain. The token is read only to check its shape. */ export function adminAntigravitySignedIn({ dataRoot, command = ADMIN_ANTIGRAVITY_COMMAND, pluginRoot = ADMIN_ANTIGRAVITY_PLUGIN_ROOT, }) { try { accessSync(command, constants.X_OK); if (!statSync(join(pluginRoot, "__init__.py")).isFile()) return false; const path = join(adminAntigravityConfigDir(dataRoot), TOKEN_FILE); const stat = lstatSync(path); if ( stat.isSymbolicLink() || !stat.isFile() || (stat.mode & 0o077) !== 0 || stat.size < 16 || stat.size > MAX_TOKEN_BYTES ) { return false; } const token = JSON.parse(readFileSync(path, "utf8"))?.token; return Boolean( token && typeof token === "object" && typeof token.refresh_token === "string" && token.refresh_token.length > 0 ); } catch { return false; } } // Scheduled jobs stay on Codex while Slack chat runs on Neon. agy delivers a // long prompt cut short from the tail (soyelmismo/hermes-antigravity- // subscription#29, still open upstream at plugin v1.0.29), so a cron turn that // grows past the cut stops seeing its newest tool results and repeats them // until a guardrail halts it. From Nov 20, when Neon went first, every "Sales // cracks" run ended that way after 28 to 137 minutes and posted only "stopped // early" to #team-chat-sales. On Codex the same runs took 5 to 9 minutes. // Hermes' cron.model only changes a job's first model: unpinned jobs keep the // global fallback chain, and a job's delegate_task children inherit its model. export const ADMIN_CRON_MODEL = Object.freeze({ model: MODEL_AUTH_DEFAULT_MODEL, model_provider: MODEL_AUTH_PROVIDER, }); // Unset: scheduled jobs follow the main model (the Codex-first chain). const FOLLOW_MAIN_MODEL = Object.freeze({ model: "", model_provider: "" }); /** The cron.model/cron.model_provider pair a model config asks for. */ export function adminCronModel(modelConfig) { return modelConfig?.cron ?? FOLLOW_MAIN_MODEL; } // Delegated workers stay on Codex while Slack chat runs on Neon. A worker // that drafts a Message Testing template must load the whole generate-messages // skill (about 180,000 characters) plus its references. Neon holds about // 75,000 tokens here, so the worker lost the start of the skill and looped, // and the chat agent wrote the message itself instead (2026-11-30, a // create-campaign run in our own Slack: the samples were not written by the // message skill). Hermes: a child with delegation.provider/model set runs on // that model and does not borrow the parent's fallback chain, so the pin // carries the Codex and OpenRouter chain as its own. export function adminDelegationModel(base) { return Object.freeze({ provider: MODEL_AUTH_PROVIDER, model: MODEL_AUTH_DEFAULT_MODEL, fallback_providers: base.fallback_providers, }); } // Unset: delegated workers inherit the chat model and its fallback chain. const INHERIT_CHAT_MODEL = Object.freeze({ provider: "", model: "", fallback_providers: null, }); /** The delegation.provider/model/fallback_providers a model config asks for. */ export function adminDelegationPin(modelConfig) { return modelConfig?.delegation ?? INHERIT_CHAT_MODEL; } /** Antigravity first, then the unchanged Codex and OpenRouter chain. */ export function adminAntigravityConfigOverlay(credential) { const base = modelAuthConfigOverlay(credential); return Object.freeze({ ...base, cron: ADMIN_CRON_MODEL, delegation: adminDelegationModel(base), providers: Object.freeze({ ...base.providers, [ADMIN_ANTIGRAVITY_PROVIDER]: Object.freeze({ request_timeout_seconds: ADMIN_ANTIGRAVITY_REQUEST_TIMEOUT_SECONDS, }), }), model: Object.freeze({ ...base.model, default: ADMIN_ANTIGRAVITY_MODEL, provider: ADMIN_ANTIGRAVITY_PROVIDER, reasoning_effort: ADMIN_ANTIGRAVITY_REASONING_EFFORT, }), fallback_providers: Object.freeze([ Object.freeze({ provider: MODEL_AUTH_PROVIDER, model: MODEL_AUTH_DEFAULT_MODEL, }), ...base.fallback_providers, ]), }); } /** * The Admin's model config: Antigravity first only while agy is signed in, or * the staff's order when there is a valid one. agy counts as a leg only while * it is signed in. Scheduled jobs and workers stay on Codex while agy leads. * * @param {any} credential * @param {{ signedIn: boolean, claudeSignedIn?: boolean, order?: unknown }} options */ export function adminModelConfigOverlay( credential, { signedIn, claudeSignedIn = false, order } ) { const base = modelAuthConfigOverlay(credential); const agy = Object.freeze({ provider: ADMIN_ANTIGRAVITY_PROVIDER, model: ADMIN_ANTIGRAVITY_MODEL, }); const claude = Object.freeze({ provider: CLAUDE_SIGNIN_PROVIDER, model: CLAUDE_SIGNIN_MODEL, }); // Claude is used only when the staff's order names it. const chain = modelOrderFor(base, order, [ ...(signedIn === true ? [agy] : []), ...(claudeSignedIn === true ? [claude] : []), ]); if (!chain) return signedIn === true ? adminAntigravityConfigOverlay(credential) : base; const usesAgy = chain.some((entry) => entry.provider === agy.provider); const ordered = withModelOrder( chain[0].provider === agy.provider ? adminAntigravityConfigOverlay(credential) : usesAgy ? { ...base, providers: { ...base.providers, [agy.provider]: { request_timeout_seconds: ADMIN_ANTIGRAVITY_REQUEST_TIMEOUT_SECONDS, }, }, } : base, chain ); return withSigninTimeouts( ordered, chain, [claude], MODEL_SIGNIN_REQUEST_TIMEOUT_SECONDS ); } /** * Environment for the Admin gateway. The gateway's HOME is the profile, so the * plugin is told where the volume's sign-in lives. Strict mode passes agy only * a minimal environment, never the gateway's Sellable credentials. */ /** The Claude Code and login the hosted writing service already uses. */ export function adminClaudeSignin(dataRoot) { const root = join(dataRoot, "private-opener"); return Object.freeze({ command: join(root, "cli", "node_modules", ".bin", "claude"), configDir: join(root, "claude"), }); } export function adminClaudeGatewayEnvironment(dataRoot) { const { command, configDir } = adminClaudeSignin(dataRoot); return Object.freeze({ CLAUDE_SUBSCRIPTION_DIRECTSDK_COMMAND: command, CLAUDE_SUBSCRIPTION_DIRECTSDK_CONFIG_DIR: configDir, }); } export function adminAntigravityGatewayEnvironment(dataRoot) { return Object.freeze({ ANTIGRAVITY_CONFIG_DIR: adminAntigravityConfigDir(dataRoot), ANTIGRAVITY_COMMAND: ADMIN_ANTIGRAVITY_COMMAND, ANTIGRAVITY_ENV_STRICT: "1", ANTIGRAVITY_WORKER_IDLE_SECONDS: String( ADMIN_ANTIGRAVITY_WORKER_IDLE_SECONDS ), }); }