${esc(title)}
${esc(text)}
// Devin subscriptions for OpenCode and magpie: the devin CLI's own sign-in // (a PKCE round through app.devin.ai to a callback on 127.0.0.1), and each // chat completion sent whole to the API the CLI talks to, Windsurf's // GetChatMessage (a Connect RPC in protobuf), its reply streamed back as // chat completion chunks. Ported from magpie's built-in Devin account // (internal/provider/devin*.go, internal/gateway/devin.go). import { Buffer } from "node:buffer" import { createHash, randomBytes, randomUUID } from "node:crypto" import { createServer, STATUS_CODES } from "node:http" import { gunzipSync } from "node:zlib" import { spawn } from "node:child_process" import { existsSync, readFileSync, realpathSync, statSync } from "node:fs" import { mkdir, readFile, writeFile } from "node:fs/promises" import { homedir } from "node:os" import { isAbsolute, join, relative, resolve } from "node:path" const ID = "devin" const CHAT = "@ai-sdk/openai-compatible" const SERVER = "https://server.codeium.com" const AUTHORIZE = "https://app.devin.ai/auth/cli/continue" const EXCHANGE = "/exa.seat_management_pb.SeatManagementService/ExchangeDevinCLIPKCECode" const CHAT_RPC = "/exa.api_server_pb.ApiServerService/GetChatMessage" // the CLI the requests say they come from const CLI_VERSION = "3000.11.3" // the AI SDK is given a chat completions URL; the loader's fetch answers // every request itself, so nothing is ever sent here const BASE = SERVER + "/devin/v1" const SIGN_IN_TIMEOUT = 10 * 60 * 1000 // how long the CLI's model list is kept, and how long a failed read waits const FRESH = 5 * 60 * 1000 const RETRY = 60 * 1000 // ---- models --------------------------------------------------------------------- // Devin's list as `devin models list --format json` gave it (2026-10-14), // less Adaptive and Fusion, which route between models inside Devin's own // agent and aren't served by the API: family id, label, aliases, and each // variant's id, label, context and output. Inkling and Claude Sonnet 4.5, // gone from that list, stay for the accounts still offered them. The // account's own list, from Devin (GetCliModelConfigs) or else the CLI, // replaces it. const SNAPSHOT = [ ["swe-2","SWE-2",["swe"],[["swe-2-high","SWE-2 High",262000,128000],["swe-2-medium","SWE-2 Medium",262000,128000],["swe-2-max","SWE-2 Max",262000,128000]]], ["swe-1.7-lightning","SWE-1.7 Lightning",[],[["swe-1-7-lightning","SWE-1.7 Lightning Max",202752,96000],["swe-1-7-lightning-medium","SWE-1.7 Lightning Medium",202752,96000]]], ["claude-fable-5-1","Claude Fable 5.1",["fable"],[["claude-fable-5-1-medium","Claude Fable 5.1 Medium",1000000,128000],["claude-fable-5-1-low","Claude Fable 5.1 Low",1000000,128000],["claude-fable-5-1-high","Claude Fable 5.1 High",1000000,128000],["claude-fable-5-1-xhigh","Claude Fable 5.1 XHigh",1000000,128000],["claude-fable-5-1-max","Claude Fable 5.1 Max",1000000,128000]]], ["claude-opus-5-5","Claude Opus 5.5",[],[["claude-opus-5-5-medium","Claude Opus 5.5 Medium",1000000,128000],["claude-opus-5-5-low","Claude Opus 5.5 Low",1000000,128000],["claude-opus-5-5-high","Claude Opus 5.5 High",1000000,128000],["claude-opus-5-5-xhigh","Claude Opus 5.5 XHigh",1000000,128000],["claude-opus-5-5-max","Claude Opus 5.5 Max",1000000,128000],["claude-opus-5-5-low-fast","Claude Opus 5.5 Low Fast",1000000,128000],["claude-opus-5-5-medium-fast","Claude Opus 5.5 Medium Fast",1000000,128000],["claude-opus-5-5-high-fast","Claude Opus 5.5 High Fast",1000000,128000],["claude-opus-5-5-xhigh-fast","Claude Opus 5.5 XHigh Fast",1000000,128000],["claude-opus-5-5-max-fast","Claude Opus 5.5 Max Fast",1000000,128000]]], ["gpt-6-astra","GPT-6 Astra",[],[["gpt-6-astra-medium","GPT-6 Astra Medium Thinking",1000000,128000],["gpt-6-astra-low","GPT-6 Astra Low Thinking",1000000,128000],["gpt-6-astra-high","GPT-6 Astra High Thinking",1000000,128000],["gpt-6-astra-xhigh","GPT-6 Astra XHigh Thinking",1000000,128000],["gpt-6-astra-max","GPT-6 Astra Max Thinking",1000000,128000],["gpt-6-astra-low-priority","GPT-6 Astra Low Thinking Fast",1000000,128000],["gpt-6-astra-medium-priority","GPT-6 Astra Medium Thinking Fast",1000000,128000],["gpt-6-astra-high-priority","GPT-6 Astra High Thinking Fast",1000000,128000],["gpt-6-astra-xhigh-priority","GPT-6 Astra XHigh Thinking Fast",1000000,128000],["gpt-6-astra-max-priority","GPT-6 Astra Max Thinking Fast",1000000,128000]]], ["gpt-6-sol","GPT-6 Sol",[],[["gpt-6-sol-medium","GPT-6 Sol Medium Thinking",1000000,128000],["gpt-6-sol-none","GPT-6 Sol No Thinking",1000000,128000],["gpt-6-sol-low","GPT-6 Sol Low Thinking",1000000,128000],["gpt-6-sol-high","GPT-6 Sol High Thinking",1000000,128000],["gpt-6-sol-xhigh","GPT-6 Sol XHigh Thinking",1000000,128000],["gpt-6-sol-max","GPT-6 Sol Max Thinking",1000000,128000],["gpt-6-sol-none-priority","GPT-6 Sol No Thinking Fast",1000000,128000],["gpt-6-sol-low-priority","GPT-6 Sol Low Thinking Fast",1000000,128000],["gpt-6-sol-medium-priority","GPT-6 Sol Medium Thinking Fast",1000000,128000],["gpt-6-sol-high-priority","GPT-6 Sol High Thinking Fast",1000000,128000],["gpt-6-sol-xhigh-priority","GPT-6 Sol XHigh Thinking Fast",1000000,128000],["gpt-6-sol-max-priority","GPT-6 Sol Max Thinking Fast",1000000,128000]]], ["gpt-6-luna","GPT-6 Luna",[],[["gpt-6-luna-medium","GPT-6 Luna Medium Thinking",1000000,128000],["gpt-6-luna-none","GPT-6 Luna No Thinking",1000000,128000],["gpt-6-luna-low","GPT-6 Luna Low Thinking",1000000,128000],["gpt-6-luna-high","GPT-6 Luna High Thinking",1000000,128000],["gpt-6-luna-xhigh","GPT-6 Luna XHigh Thinking",1000000,128000],["gpt-6-luna-max","GPT-6 Luna Max Thinking",1000000,128000],["gpt-6-luna-none-priority","GPT-6 Luna No Thinking Fast",1000000,128000],["gpt-6-luna-low-priority","GPT-6 Luna Low Thinking Fast",1000000,128000],["gpt-6-luna-medium-priority","GPT-6 Luna Medium Thinking Fast",1000000,128000],["gpt-6-luna-high-priority","GPT-6 Luna High Thinking Fast",1000000,128000],["gpt-6-luna-xhigh-priority","GPT-6 Luna XHigh Thinking Fast",1000000,128000],["gpt-6-luna-max-priority","GPT-6 Luna Max Thinking Fast",1000000,128000]]], ["gemini-4-argon","Gemini 4 Argon",[],[["gemini-4-argon-medium","Gemini 4 Argon Medium",1048576,1000000],["gemini-4-argon-low","Gemini 4 Argon Low",1048576,1000000],["gemini-4-argon-high","Gemini 4 Argon High",1048576,1000000]]], ["kimi-k3","Kimi K3",[],[["kimi-k3-high","Kimi K3 High",1048576,131072],["kimi-k3-low","Kimi K3 Low",1048576,131072],["kimi-k3-max","Kimi K3 Max",1048576,131072]]], ["glm-5.2","GLM-5.2",[],[["glm-5-2","GLM-5.2 High",200000,128000],["glm-5-2-max","GLM-5.2 Max",200000,128000],["glm-5-2-1m","GLM-5.2 High 1M",1000000,128000],["glm-5-2-max-1m","GLM-5.2 Max 1M",1000000,128000],["glm-5-2-none","GLM-5.2 No Thinking",200000,128000],["glm-5-2-none-1m","GLM-5.2 No Thinking 1M",1000000,128000]]], ["glm-5-3","GLM-5.3",[],[["glm-5-3-low","GLM-5.3 Low",1048576,128000],["glm-5-3-high","GLM-5.3 High",1048576,128000],["glm-5-3-max","GLM-5.3 Max",1048576,128000]]], ["claude-sonnet-5-5","Claude Sonnet 5.5",[],[["claude-sonnet-5-5-medium","Claude Sonnet 5.5 Medium",1000000,128000],["claude-sonnet-5-5-low","Claude Sonnet 5.5 Low",1000000,128000],["claude-sonnet-5-5-high","Claude Sonnet 5.5 High",1000000,128000],["claude-sonnet-5-5-xhigh","Claude Sonnet 5.5 XHigh",1000000,128000],["claude-sonnet-5-5-max","Claude Sonnet 5.5 Max",1000000,128000]]], ["gemini-3-8-flash","Gemini 3.8 Flash",["gemini"],[["gemini-3-8-flash-medium","Gemini 3.8 Flash Medium",1048576,65535],["gemini-3-8-flash-low","Gemini 3.8 Flash Low",1048576,65535],["gemini-3-8-flash-high","Gemini 3.8 Flash High",1048576,65535]]], ["claude-opus-4.7","Claude Opus 4.7",[],[["claude-opus-4-7-medium","Claude Opus 4.7 Medium",1000000,128000],["claude-opus-4-7-low","Claude Opus 4.7 Low",1000000,128000],["claude-opus-4-7-high","Claude Opus 4.7 High",1000000,128000],["claude-opus-4-7-xhigh","Claude Opus 4.7 XHigh",1000000,128000],["claude-opus-4-7-max","Claude Opus 4.7 Max",1000000,128000]]], ["claude-opus-4.8","Claude Opus 4.8",[],[["claude-opus-4-8-medium","Claude Opus 4.8 Medium",1000000,128000],["claude-opus-4-8-low","Claude Opus 4.8 Low",1000000,128000],["claude-opus-4-8-high","Claude Opus 4.8 High",1000000,128000],["claude-opus-4-8-xhigh","Claude Opus 4.8 XHigh",1000000,128000],["claude-opus-4-8-max","Claude Opus 4.8 Max",1000000,128000],["claude-opus-4-8-low-fast","Claude Opus 4.8 Low Fast",1000000,128000],["claude-opus-4-8-medium-fast","Claude Opus 4.8 Medium Fast",1000000,128000],["claude-opus-4-8-high-fast","Claude Opus 4.8 High Fast",1000000,128000],["claude-opus-4-8-xhigh-fast","Claude Opus 4.8 XHigh Fast",1000000,128000],["claude-opus-4-8-max-fast","Claude Opus 4.8 Max Fast",1000000,128000]]], ["claude-opus-5","Claude Opus 5",["opus"],[["claude-opus-5-medium","Claude Opus 5 Medium",1000000,128000],["claude-opus-5-low","Claude Opus 5 Low",1000000,128000],["claude-opus-5-high","Claude Opus 5 High",1000000,128000],["claude-opus-5-xhigh","Claude Opus 5 XHigh",1000000,128000],["claude-opus-5-max","Claude Opus 5 Max",1000000,128000],["claude-opus-5-low-fast","Claude Opus 5 Low Fast",1000000,128000],["claude-opus-5-medium-fast","Claude Opus 5 Medium Fast",1000000,128000],["claude-opus-5-high-fast","Claude Opus 5 High Fast",1000000,128000],["claude-opus-5-xhigh-fast","Claude Opus 5 XHigh Fast",1000000,128000],["claude-opus-5-max-fast","Claude Opus 5 Max Fast",1000000,128000]]], ["claude-5-fable","Claude Fable 5",[],[["claude-5-fable-low","Claude Fable 5 Low",1000000,128000],["claude-5-fable-medium","Claude Fable 5 Medium",1000000,128000],["claude-5-fable-high","Claude Fable 5 High",1000000,128000],["claude-5-fable-xhigh","Claude Fable 5 XHigh",1000000,128000],["claude-5-fable-max","Claude Fable 5 Max",1000000,128000]]], ["claude-sonnet-5","Claude Sonnet 5",["claude","sonnet"],[["claude-sonnet-5-low","Claude Sonnet 5 Low",1000000,128000],["claude-sonnet-5-medium","Claude Sonnet 5 Medium",1000000,128000],["claude-sonnet-5-high","Claude Sonnet 5 High",1000000,128000],["claude-sonnet-5-xhigh","Claude Sonnet 5 XHigh",1000000,128000],["claude-sonnet-5-max","Claude Sonnet 5 Max",1000000,128000]]], ["claude-haiku-5-5","Claude Haiku 5.5",[],[["claude-haiku-5-5-low","Claude Haiku 5.5 Low",1000000,128000],["claude-haiku-5-5-medium","Claude Haiku 5.5 Medium",1000000,128000],["claude-haiku-5-5-high","Claude Haiku 5.5 High",1000000,128000],["claude-haiku-5-5-xhigh","Claude Haiku 5.5 XHigh",1000000,128000],["claude-haiku-5-5-max","Claude Haiku 5.5 Max",1000000,128000]]], ["gemini-3.5-flash","Gemini 3.5 Flash",[],[["gemini-3-5-flash-minimal","Gemini 3.5 Flash Minimal",1048576,65535],["gemini-3-5-flash-low","Gemini 3.5 Flash Low",1048576,65535],["gemini-3-5-flash-medium","Gemini 3.5 Flash Medium",1048576,65535],["gemini-3-5-flash-high","Gemini 3.5 Flash High",1048576,65535]]], ["gemini-3.6-flash","Gemini 3.6 Flash",[],[["gemini-3-6-flash-minimal","Gemini 3.6 Flash Minimal",1048576,65535],["gemini-3-6-flash-low","Gemini 3.6 Flash Low",1048576,65535],["gemini-3-6-flash-medium","Gemini 3.6 Flash Medium",1048576,65535],["gemini-3-6-flash-high","Gemini 3.6 Flash High",1048576,65535]]], ["gemini-3-7-flash","Gemini 3.7 Flash",[],[["gemini-3-7-flash-low","Gemini 3.7 Flash Low",1048576,65535],["gemini-3-7-flash-medium","Gemini 3.7 Flash Medium",1048576,65535],["gemini-3-7-flash-high","Gemini 3.7 Flash High",1048576,65535]]], ["gpt-5.6-sol","GPT-5.6 Sol",[],[["gpt-5-6-sol-none","GPT-5.6 Sol No Thinking",1000000,128000],["gpt-5-6-sol-low","GPT-5.6 Sol Low Thinking",1000000,128000],["gpt-5-6-sol-medium","GPT-5.6 Sol Medium Thinking",1000000,128000],["gpt-5-6-sol-high","GPT-5.6 Sol High Thinking",1000000,128000],["gpt-5-6-sol-xhigh","GPT-5.6 Sol XHigh Thinking",1000000,128000],["gpt-5-6-sol-max","GPT-5.6 Sol Max Thinking",1000000,128000],["gpt-5-6-sol-none-priority","GPT-5.6 Sol No Thinking Fast",1000000,128000],["gpt-5-6-sol-low-priority","GPT-5.6 Sol Low Thinking Fast",1000000,128000],["gpt-5-6-sol-medium-priority","GPT-5.6 Sol Medium Thinking Fast",1000000,128000],["gpt-5-6-sol-high-priority","GPT-5.6 Sol High Thinking Fast",1000000,128000],["gpt-5-6-sol-xhigh-priority","GPT-5.6 Sol XHigh Thinking Fast",1000000,128000],["gpt-5-6-sol-max-priority","GPT-5.6 Sol Max Thinking Fast",1000000,128000]]], ["gpt-5.6-terra","GPT-5.6 Terra",[],[["gpt-5-6-terra-none","GPT-5.6 Terra No Thinking",1000000,128000],["gpt-5-6-terra-low","GPT-5.6 Terra Low Thinking",1000000,128000],["gpt-5-6-terra-medium","GPT-5.6 Terra Medium Thinking",1000000,128000],["gpt-5-6-terra-high","GPT-5.6 Terra High Thinking",1000000,128000],["gpt-5-6-terra-xhigh","GPT-5.6 Terra XHigh Thinking",1000000,128000],["gpt-5-6-terra-max","GPT-5.6 Terra Max Thinking",1000000,128000],["gpt-5-6-terra-none-priority","GPT-5.6 Terra No Thinking Fast",1000000,128000],["gpt-5-6-terra-low-priority","GPT-5.6 Terra Low Thinking Fast",1000000,128000],["gpt-5-6-terra-medium-priority","GPT-5.6 Terra Medium Thinking Fast",1000000,128000],["gpt-5-6-terra-high-priority","GPT-5.6 Terra High Thinking Fast",1000000,128000],["gpt-5-6-terra-xhigh-priority","GPT-5.6 Terra XHigh Thinking Fast",1000000,128000],["gpt-5-6-terra-max-priority","GPT-5.6 Terra Max Thinking Fast",1000000,128000]]], ["gpt-5.6-luna","GPT-5.6 Luna",[],[["gpt-5-6-luna-none","GPT-5.6 Luna No Thinking",1000000,128000],["gpt-5-6-luna-low","GPT-5.6 Luna Low Thinking",1000000,128000],["gpt-5-6-luna-medium","GPT-5.6 Luna Medium Thinking",1000000,128000],["gpt-5-6-luna-high","GPT-5.6 Luna High Thinking",1000000,128000],["gpt-5-6-luna-xhigh","GPT-5.6 Luna XHigh Thinking",1000000,128000],["gpt-5-6-luna-max","GPT-5.6 Luna Max Thinking",1000000,128000],["gpt-5-6-luna-none-priority","GPT-5.6 Luna No Thinking Fast",1000000,128000],["gpt-5-6-luna-low-priority","GPT-5.6 Luna Low Thinking Fast",1000000,128000],["gpt-5-6-luna-medium-priority","GPT-5.6 Luna Medium Thinking Fast",1000000,128000],["gpt-5-6-luna-high-priority","GPT-5.6 Luna High Thinking Fast",1000000,128000],["gpt-5-6-luna-xhigh-priority","GPT-5.6 Luna XHigh Thinking Fast",1000000,128000],["gpt-5-6-luna-max-priority","GPT-5.6 Luna Max Thinking Fast",1000000,128000]]], ["gpt-6-1-sol","GPT-6.1 Sol",[],[["gpt-6-1-sol-low","GPT-6.1 Sol Low Thinking",1000000,128000],["gpt-6-1-sol-medium","GPT-6.1 Sol Medium Thinking",1000000,128000],["gpt-6-1-sol-high","GPT-6.1 Sol High Thinking",1000000,128000],["gpt-6-1-sol-xhigh","GPT-6.1 Sol XHigh Thinking",1000000,128000],["gpt-6-1-sol-max","GPT-6.1 Sol Max Thinking",1000000,128000],["gpt-6-1-sol-low-priority","GPT-6.1 Sol Low Thinking Fast",1000000,128000],["gpt-6-1-sol-medium-priority","GPT-6.1 Sol Medium Thinking Fast",1000000,128000],["gpt-6-1-sol-high-priority","GPT-6.1 Sol High Thinking Fast",1000000,128000],["gpt-6-1-sol-xhigh-priority","GPT-6.1 Sol XHigh Thinking Fast",1000000,128000],["gpt-6-1-sol-max-priority","GPT-6.1 Sol Max Thinking Fast",1000000,128000]]], ["grok-4.5","Grok 4.5",[],[["grok-4-5-low","Grok 4.5 Low",500000,100000],["grok-4-5-medium","Grok 4.5 Medium",500000,100000],["grok-4-5-high","Grok 4.5 High",500000,100000]]], ["grok-4-6","Grok 4.6",[],[["grok-4-6-low","Grok 4.6 Low",500000,100000],["grok-4-6-medium","Grok 4.6 Medium",500000,100000],["grok-4-6-high","Grok 4.6 High",500000,100000],["grok-4-6-xhigh","Grok 4.6 XHigh",500000,100000]]], ["grok-4-7","Grok 4.7",[],[["grok-4-7-low","Grok 4.7 Low",500000,100000],["grok-4-7-medium","Grok 4.7 Medium",500000,100000],["grok-4-7-high","Grok 4.7 High",500000,100000],["grok-4-7-xhigh","Grok 4.7 XHigh",500000,100000]]], ["inkling","Inkling",[],[["inkling-none","Inkling None",1048576,131072],["inkling-low","Inkling Low",1048576,131072],["inkling-medium","Inkling Medium",1048576,131072],["inkling-high","Inkling High",1048576,131072],["inkling-xhigh","Inkling X-High",1048576,131072],["inkling-max","Inkling Max",1048576,131072]]], ["glm-5-3-flash","GLM-5.3 Flash",[],[["glm-5-3-flash-low","GLM-5.3 Flash Low",1000000,128000],["glm-5-3-flash-high","GLM-5.3 Flash High",1000000,128000],["glm-5-3-flash-max","GLM-5.3 Flash Max",1000000,128000]]], ["deepseek-v4-flash","DeepSeek V4 Flash",[],[["deepseek-v4-flash-high","DeepSeek V4 Flash High",1048576,384000],["deepseek-v4-flash-max","DeepSeek V4 Flash Max",1048576,384000]]], ["deepseek-v4-1-flash","DeepSeek V4.1 Flash",[],[["deepseek-v4-1-flash-high","DeepSeek V4.1 Flash High",1048576,384000],["deepseek-v4-1-flash-max","DeepSeek V4.1 Flash Max",1048576,384000]]], ["swe-1.7","SWE-1.7",[],[["swe-1-7","SWE-1.7 Max",262000,128000],["swe-1-7-medium","SWE-1.7 Medium",262000,128000]]], ["claude-opus-4.6","Claude Opus 4.6",[],[["claude-opus-4-6","Claude Opus 4.6",200000,128000],["claude-opus-4-6-thinking","Claude Opus 4.6 Thinking",200000,128000],["claude-opus-4-6-1m","Claude Opus 4.6 1M",1000000,128000],["claude-opus-4-6-thinking-1m","Claude Opus 4.6 Thinking 1M",1000000,128000]]], ["gpt-5.4","GPT-5.4",[],[["gpt-5-4-none","GPT-5.4 No Thinking",272000,128000],["gpt-5-4-low","GPT-5.4 Low Thinking",272000,128000],["gpt-5-4-medium","GPT-5.4 Medium Thinking",272000,128000],["gpt-5-4-high","GPT-5.4 High Thinking",272000,128000],["gpt-5-4-xhigh","GPT-5.4 XHigh Thinking",272000,128000],["gpt-5-4-none-priority","GPT-5.4 No Thinking Fast",272000,128000],["gpt-5-4-low-priority","GPT-5.4 Low Thinking Fast",272000,128000],["gpt-5-4-medium-priority","GPT-5.4 Medium Thinking Fast",272000,128000],["gpt-5-4-high-priority","GPT-5.4 High Thinking Fast",272000,128000],["gpt-5-4-xhigh-priority","GPT-5.4 XHigh Thinking Fast",272000,128000]]], ["gpt-5.5","GPT-5.5",["gpt"],[["gpt-5-5-none","GPT-5.5 No Thinking",272000,128000],["gpt-5-5-low","GPT-5.5 Low Thinking",272000,128000],["gpt-5-5-medium","GPT-5.5 Medium Thinking",272000,128000],["gpt-5-5-high","GPT-5.5 High Thinking",272000,128000],["gpt-5-5-xhigh","GPT-5.5 XHigh Thinking",272000,128000],["gpt-5-5-none-priority","GPT-5.5 No Thinking Fast",272000,128000],["gpt-5-5-low-priority","GPT-5.5 Low Thinking Fast",272000,128000],["gpt-5-5-medium-priority","GPT-5.5 Medium Thinking Fast",272000,128000],["gpt-5-5-high-priority","GPT-5.5 High Thinking Fast",272000,128000],["gpt-5-5-xhigh-priority","GPT-5.5 XHigh Thinking Fast",272000,128000]]], ["gpt-5.4-mini","GPT-5.4 Mini",[],[["gpt-5-4-mini-low","GPT-5.4 Mini Low Thinking",400000,128000],["gpt-5-4-mini-medium","GPT-5.4 Mini Medium Thinking",400000,128000],["gpt-5-4-mini-high","GPT-5.4 Mini High Thinking",400000,128000],["gpt-5-4-mini-xhigh","GPT-5.4 Mini XHigh Thinking",400000,128000]]], ["claude-sonnet-4.6","Claude Sonnet 4.6",[],[["claude-sonnet-4-6","Claude Sonnet 4.6",200000,128000],["claude-sonnet-4-6-thinking","Claude Sonnet 4.6 Thinking",200000,128000],["claude-sonnet-4-6-1m","Claude Sonnet 4.6 1M",1000000,128000],["claude-sonnet-4-6-thinking-1m","Claude Sonnet 4.6 Thinking 1M",1000000,128000]]], ["gpt-5.2","GPT-5.2",[],[["MODEL_GPT_5_2_LOW","GPT-5.2 Low Thinking",384000,128000],["MODEL_GPT_5_2_MEDIUM","GPT-5.2 Medium Thinking",384000,128000],["MODEL_GPT_5_2_NONE","GPT-5.2 No Thinking",384000,128000],["MODEL_GPT_5_2_HIGH","GPT-5.2 High Thinking",384000,128000],["MODEL_GPT_5_2_XHIGH","GPT-5.2 XHigh Thinking",384000,128000]]], ["claude-opus-4.5","Claude Opus 4.5",[],[["MODEL_CLAUDE_4_5_OPUS","Claude Opus 4.5",200000,64000],["MODEL_CLAUDE_4_5_OPUS_THINKING","Claude Opus 4.5 Thinking",200000,64000]]], ["Claude Haiku 4.5","Claude Haiku 4.5",[],[["MODEL_PRIVATE_11","Claude Haiku 4.5",200000,64000]]], ["claude-sonnet-4.5","Claude Sonnet 4.5",[],[["MODEL_PRIVATE_2","Claude Sonnet 4.5",200000,64000],["MODEL_PRIVATE_3","Claude Sonnet 4.5 Thinking",200000,64000]]], ["GPT-4.1","GPT-4.1",[],[["MODEL_CHAT_GPT_4_1_2025_04_14","GPT-4.1",1047576,32768]]], ["gpt-5.1","GPT-5.1",[],[["MODEL_PRIVATE_12","GPT-5.1 No Thinking",272000,128000],["MODEL_PRIVATE_13","GPT-5.1 Low Thinking",272000,128000],["MODEL_PRIVATE_14","GPT-5.1 Medium Thinking",272000,128000],["MODEL_PRIVATE_15","GPT-5.1 High Thinking",272000,128000]]], ["gpt-5.3-codex","GPT-5.3-Codex",["codex"],[["gpt-5-3-codex-low","GPT-5.3-Codex Low",400000,128000],["gpt-5-3-codex-medium","GPT-5.3-Codex Medium",400000,128000],["gpt-5-3-codex-high","GPT-5.3-Codex High",400000,128000],["gpt-5-3-codex-xhigh","GPT-5.3-Codex X-High",400000,128000],["gpt-5-3-codex-low-priority","GPT-5.3-Codex Low Fast",400000,128000],["gpt-5-3-codex-medium-priority","GPT-5.3-Codex Medium Fast",400000,128000],["gpt-5-3-codex-high-priority","GPT-5.3-Codex High Fast",400000,128000],["gpt-5-3-codex-xhigh-priority","GPT-5.3-Codex XHigh Fast",400000,128000]]], ["kimi-k2.6","Kimi K2.6",[],[["kimi-k2-6","Kimi K2.6",262144,8192]]], ["kimi-k2.7","Kimi K2.7",[],[["kimi-k2-7","Kimi K2.7",262144,16000]]], ["nemotron-3-ultra","Nemotron 3 Ultra",[],[["nemotron-3-ultra-none","Nemotron 3 Ultra None",1000000,32768],["nemotron-3-ultra-medium","Nemotron 3 Ultra Medium",1000000,32768],["nemotron-3-ultra-high","Nemotron 3 Ultra High",1000000,32768]]], ["swe-1.6","SWE-1.6",[],[["swe-1-6","SWE-1.6",200000,128000]]], ["swe-1.6-fast","SWE-1.6 Fast",[],[["swe-1-6-fast","SWE-1.6 Fast",200000,128000]]], ["gemini-3.1-pro","Gemini 3.1 Pro",[],[["gemini-3-1-pro-low","Gemini 3.1 Pro Low Thinking",1048576,65535],["gemini-3-1-pro-high","Gemini 3.1 Pro High Thinking",1048576,65535]]], ["gemini-3.0-flash","Gemini 3 Flash",[],[["MODEL_GOOGLE_GEMINI_3_0_FLASH_MINIMAL","Gemini 3 Flash Minimal",1048576,65535],["MODEL_GOOGLE_GEMINI_3_0_FLASH_LOW","Gemini 3 Flash Low",1048576,65535],["MODEL_GOOGLE_GEMINI_3_0_FLASH_MEDIUM","Gemini 3 Flash Medium",1048576,65535],["MODEL_GOOGLE_GEMINI_3_0_FLASH_HIGH","Gemini 3 Flash High",1048576,65535]]], ["deepseek-v4-pro","DeepSeek V4 Pro",[],[["deepseek-v4-pro-high","DeepSeek V4 Pro High",1048576,384000],["deepseek-v4-pro-max","DeepSeek V4 Pro Max",1048576,384000]]], ] const familiesOf = (rows) => rows.map(([uid, label, aliases, vs]) => ({ uid, label, aliases, models: vs.map(([id, name, context, output]) => ({ id, name, context, output })) })) // parseFamilies reads `devin models list --format json`. function parseFamilies(text) { let list try { list = JSON.parse(text) } catch { return [] } const out = [] for (const f of list?.families ?? []) { if (!f?.family_uid) continue const low = String(f.family_uid).toLowerCase() if (low === "adaptive" || low === "fusion") continue out.push({ uid: f.family_uid, label: f.family_label || f.family_uid, aliases: f.aliases ?? [], models: (f.variants ?? []) .filter((v) => v?.model_uid) .map((v) => ({ id: v.model_uid, name: v.label || v.model_uid, context: v.max_context_tokens || 0, output: v.max_output_tokens || 0 })), }) } return out } const LEVEL_RANK = ["none", "minimal", "low", "medium", "high", "xhigh", "max"] // the effort words Devin's variant ids end in (swe-2-high, …_HIGH, // gpt-6-sol-none), and the level each is const LEVELS = [["none", "none"], ["xhigh", "xhigh"], ["minimal", "minimal"], ["min", "minimal"], ["low", "low"], ["medium", "medium"], ["high", "high"], ["max", "max"]] // the words a variant id may end in after its effort, for a quicker run of // the same model at it (claude-opus-5-5-high-fast) const TIERS = [["fast", "Fast"], ["priority", "Priority"]] // levelOf is the effort an id says it runs at, "" when it says none. function levelOf(id) { const low = id.toLowerCase() for (const [word, level] of LEVELS) if (low.endsWith("-" + word) || low.endsWith("_" + word)) return level return "" } // tierOf is the tier an id is in and its effort: claude-opus-5-5-high-fast // is ["fast", "high"], swe-2-high ["", "high"]; a tier word with no effort // before it (swe-1-6-fast) is no tier. function tierOf(id) { const low = id.toLowerCase() for (const [word] of TIERS) for (const sep of ["-", "_"]) if (low.endsWith(sep + word)) { const l = levelOf(low.slice(0, -(sep + word).length)) if (l) return [word, l] } return ["", levelOf(id)] } const named = (f, id) => f.uid === id || f.aliases.includes(id) // byLevel is the family's variant at each effort, in the tier, the first // at each. function byLevel(f, tier) { const out = {} for (const m of f.models) { const [t, l] = tierOf(m.id) if (t === tier && l && m.id !== f.uid && !out[l]) out[l] = m.id } return out } const efforts = (f, tier) => { const by = byLevel(f, tier) return LEVEL_RANK.filter((l) => by[l]) } const tiers = (f) => TIERS.map(([w]) => w).filter((t) => Object.keys(byLevel(f, t)).length > 0) // defaultLevel is the effort of the variant the family's id asks for when // none is asked (its first), medium when that names none. function defaultLevel(f) { if (f.models.length) { const [t, l] = tierOf(f.models[0].id) if (!t && l) return l } return "medium" } // nearest is the one of levels nearest the one asked for, a tie going up. function nearest(want, levels) { const at = LEVEL_RANK.indexOf(want) if (at < 0 || !levels.length || levels.includes(want)) return want let best = want let dist = LEVEL_RANK.length for (const l of levels) { const i = LEVEL_RANK.indexOf(l) const d = Math.abs(i - at) if (d < dist || (d === dist && i > at)) [best, dist] = [l, d] } return best } // variantFor is the model to ask the API for: a family's id follows its // newest model, which the API takes only as one of its variants — the one // at the effort asked for, or the nearest the family has; with none asked, // the family's default. A family's fast run is its fast variant at that // effort. Any other id (a variant's own) goes as it is. function variantFor(families, model, effort) { for (const f of families) { if (!named(f, model) || !f.models.length) continue if (effort) { const id = byLevel(f, "")[nearest(effort, efforts(f, ""))] if (id) return id } return f.models[0].id } for (const f of families) for (const tier of tiers(f)) { if (!model.endsWith("-" + tier) || !named(f, model.slice(0, -(tier.length + 1)))) continue const by = byLevel(f, tier) const levels = efforts(f, tier) return by[nearest(effort || defaultLevel(f), levels)] || by[levels[0]] } return model } // listed is Devin's list as it is offered: each family one model, with // the efforts its variants are at (picked as any model's effort is, and // turned into the variant by variantFor), its fast run likewise, and the // variants at no effort (glm-5-2-1m); a family's only variant is its id. // A variant in keep (one the user picked: swe-2-medium) stays, at the one // effort its id is at, and goes to Devin as it is, as magpie's built-in // keeps it (devinCollapse). // Each entry says whether it takes images (image) as images, Devin's word // for each variant id, gives it: a variant its own, a family (and its fast // run) what all its variants Devin named say; undefined when Devin said // nothing of it or its variants disagree. An entry is free (free: true) when // every variant of Devin's it stands for is in free, the ids Devin says its // quota doesn't count (parseFree). A family stands for the variants // variantFor sends it as, those at an effort and its default, not every // model Devin files under it: Devin gives SWE-2 three -lightning variants // at the High cost tier (2026-10-15), which no effort of swe-2 is sent as, // and with them in, swe-2 was no longer free. An entry's price (cost) is // what Devin lists for the variants it stands for when they all list the // same (parsePrices); none when they differ or Devin lists none. function listed(families, keep = [], images = {}, free = new Set(), prices = new Map()) { const all = (ids) => ids.length > 0 && ids.every((id) => free.has(id)) const priced = (ids) => { const ps = ids.map((id) => prices.get(id)) if (!ps.length || !ps[0] || ps.some((p) => JSON.stringify(p) !== JSON.stringify(ps[0]))) return undefined return ps[0] } const own = (f, t) => { const ids = Object.values(byLevel(f, t)) if (!t && f.models.length && !ids.includes(f.models[0].id)) ids.push(f.models[0].id) return ids } const out = [] const seen = new Set() const add = ({ free, cost, ...m }) => { if (seen.has(m.id)) return seen.add(m.id) out.push({ ...m, ...(free ? { free } : cost ? { cost } : {}) }) } for (const f of families) { const context = f.models.find((m) => m.context)?.context ?? 0 const output = f.models.find((m) => m.output)?.output ?? 0 const image = familyImages(f, images) add({ id: f.uid, name: f.label, context, output, efforts: efforts(f, ""), image, free: all(own(f, "")), cost: priced(own(f, "")) }) for (const t of tiers(f)) { const id = f.uid + "-" + t if (families.some((g) => named(g, id))) continue add({ id, name: f.label + " " + TIERS.find(([w]) => w === t)[1], context, output, efforts: efforts(f, t), image, free: all(own(f, t)), cost: priced(own(f, t)) }) } if (f.models.length === 1) continue for (const m of f.models) { if (m.id === f.uid || tierOf(m.id)[1]) continue add({ id: m.id, name: m.name, context: m.context || context, output: m.output || output, efforts: [], image: images[m.id], free: free.has(m.id), cost: prices.get(m.id) }) } } for (const id of keep) { if (seen.has(id)) continue const f = families.find((g) => g.models.some((m) => m.id === id)) const m = f?.models.find((m) => m.id === id) const level = tierOf(id)[1] if (!m && !level) continue add({ id, name: m?.name || id, context: m?.context ?? 0, output: m?.output ?? 0, efforts: level ? [level] : [], image: images[id], free: free.has(id), cost: prices.get(id) }) } return out } // familyImages is what a family's variants Devin named all say of images. function familyImages(f, images) { let said for (const m of f.models) { const v = images[m.id] if (typeof v !== "boolean") continue if (said !== undefined && said !== v) return undefined said = v } return said } // Which of Devin's models take images is what Devin tells its CLI's model // picker (GetCliModelConfigs: each ClientModelConfig's supports_images), as // magpie's built-in asks it (devin_images.go): `devin models list` says // nothing of images and models.dev doesn't know Devin's own ids, so swe-2 // was said to take none and agents dropped its images (面条 on magpie's // Discord). NO_IMAGES are the ids Devin said take none, as of 2026-10-05; // every other id in SNAPSHOT takes them, which is what a list is told // before Devin is asked, or when it can't be. const NO_IMAGES = new Set([ "glm-5-2", "glm-5-2-max", "glm-5-2-1m", "glm-5-2-max-1m", "glm-5-2-none", "glm-5-2-none-1m", "glm-5-3-low", "glm-5-3-high", "glm-5-3-max", "inkling-none", "inkling-low", "inkling-medium", "inkling-high", "inkling-xhigh", "inkling-max", "deepseek-v4-flash-high", "deepseek-v4-flash-max", "deepseek-v4-pro-high", "deepseek-v4-pro-max", "nemotron-3-ultra-none", "nemotron-3-ultra-medium", "nemotron-3-ultra-high", ]) const SNAPSHOT_IMAGES = Object.fromEntries(SNAPSHOT.flatMap(([, , , vs]) => vs.map(([id]) => [id, !NO_IMAGES.has(id)]))) const MODEL_CONFIGS_RPC = "/exa.api_server_pb.ApiServerService/GetCliModelConfigs" // parseModelConfigs reads GetCliModelConfigsResponse: its // client_model_configs (1), each with its model_uid (22) and // supports_images (5), a bool proto3 leaves out when false. function parseModelConfigs(b) { const out = {} for (const f of fields(b)) { if (f.num !== 1 || f.wire !== 2) continue let uid = "" let images = false for (const g of fields(f.data)) { if (g.num === 22 && g.wire === 2) uid = dec.decode(g.data) else if (g.num === 5 && g.wire === 0) images = g.n !== 0 } if (uid) out[uid] = images } return Object.keys(out).length ? out : null } // FREE_TIER is the model_cost_tier (ClientModelConfig's 24) of a model the // account's quota doesn't count: the CLI's picker labels its tiers "Low // cost", "Med cost", "High cost" and "Free", 1 to 4. On 2026-10-14 Devin // gave SWE-2's three variants 4 and no other model of its 262 (太陽と向日葵 // on magpie's Discord: with the quota used up, SWE-2 still answered, but // magpie held the account for it as for every other model). const FREE_TIER = 4 // parseFree reads the same response for the ids of the models that are // free: each config's model_uid (22) whose model_cost_tier (24) is // FREE_TIER. A config that says no tier is not free. function parseFree(b) { const out = new Set() for (const f of fields(b)) { if (f.num !== 1 || f.wire !== 2) continue let uid = "" let tier = 0 for (const g of fields(f.data)) { if (g.num === 22 && g.wire === 2) uid = dec.decode(g.data) else if (g.num === 24 && g.wire === 0) tier = g.n } if (uid && tier === FREE_TIER) out.add(uid) } return out } // parsePrices reads the same response for what Devin lists each model at, // in USD per 1M tokens: a config's model_uid (22) and its prices (32, one // each), each a label (1: "Input", "Cached input", "Output"), a fixed32 // float (2) and its unit (3: "1M tokens"). A model in the Free tier lists // none. Only a price per 1M tokens is taken, and a model is priced only // when it lists input or output above 0. function parsePrices(b) { const out = new Map() const words = { Input: "input", "Cached input": "read", Output: "output" } for (const f of fields(b)) { if (f.num !== 1 || f.wire !== 2) continue let uid = "" const p = {} for (const g of fields(f.data)) { if (g.num === 22 && g.wire === 2) uid = dec.decode(g.data) else if (g.num === 32 && g.wire === 2) { let label = "" let unit = "" let v = NaN for (const h of fields(g.data)) { if (h.num === 1 && h.wire === 2) label = dec.decode(h.data) else if (h.num === 3 && h.wire === 2) unit = dec.decode(h.data) else if (h.num === 2 && h.wire === 5) v = new DataView(h.data.buffer, h.data.byteOffset, 4).getFloat32(0, true) } // a float32's 1.4 is 1.39999997…: the price as Devin wrote it if (words[label] && unit === "1M tokens" && Number.isFinite(v) && v >= 0) p[words[label]] = +v.toPrecision(6) } } if (uid && (p.input > 0 || p.output > 0)) out.set(uid, { input: p.input ?? 0, output: p.output ?? 0, cache: { read: p.read ?? 0 } }) } return out } // parseConfigFamilies reads the same response as the families `devin // models list` makes of it, in its order: each config's label (1), context // (18), and model_info (23) with its output (13) and family uid (23); the // family's label is its family_metadata's (30) first field. A config that // names no family is a family of its own under its label, as the CLI makes // MODEL_PRIVATE_11 "Claude Haiku 4.5". The aliases are the CLI's own, so // they are taken from SNAPSHOT's family of the same id. function parseConfigFamilies(b) { const fams = new Map() for (const f of fields(b)) { if (f.num !== 1 || f.wire !== 2) continue let uid = "" let name = "" let context = 0 let output = 0 let fam = "" let famLabel = "" for (const g of fields(f.data)) { if (g.num === 22 && g.wire === 2) uid = dec.decode(g.data) else if (g.num === 1 && g.wire === 2) name = dec.decode(g.data) else if (g.num === 18 && g.wire === 0) context = g.n else if (g.num === 23 && g.wire === 2) { for (const h of fields(g.data)) { if (h.num === 13 && h.wire === 0) output = h.n else if (h.num === 23 && h.wire === 2) fam = dec.decode(h.data) } } else if (g.num === 30 && g.wire === 2) { for (const h of fields(g.data)) if (h.num === 1 && h.wire === 2) famLabel = dec.decode(h.data) } } if (!uid) continue const id = fam || famLabel || name || uid const low = id.toLowerCase() if (low === "adaptive" || low === "fusion") continue let e = fams.get(id) if (!e) { const known = SNAPSHOT.find(([u]) => u === id) fams.set(id, (e = { uid: id, label: famLabel || name || id, aliases: known ? known[2] : [], models: [] })) } e.models.push({ id: uid, name: name || uid, context, output }) } return [...fams.values()] } // Each account's word on images and its list, kept and asked again as the // CLI's list is. const said = new Map() // configsFor is what Devin last said of key's account's models // ({images, families}, each null until it has said); with wait false, a // first ask isn't waited for. async function configsFor(key, server, wait = true) { let c = said.get(key) if (!c) said.set(key, (c = { images: null, families: null, free: new Set(), prices: new Map(), at: 0, failed: 0, asking: null })) const ask = () => (c.asking ??= (async () => { try { const res = await fetch(server + MODEL_CONFIGS_RPC, { method: "POST", headers: { "Content-Type": "application/proto", "Connect-Protocol-Version": "1" }, body: new PB().bytes(1, metadata(key)).done(), signal: AbortSignal.timeout(15_000), }) if (!res.ok) throw new Error(`GetCliModelConfigs: ${res.status}`) const b = new Uint8Array(await res.arrayBuffer()) const images = parseModelConfigs(b) if (!images) throw new Error("GetCliModelConfigs: no models") const families = parseConfigFamilies(b) Object.assign(c, { images, families: families.length ? families : null, free: parseFree(b), prices: parsePrices(b), at: Date.now(), failed: 0 }) } catch { c.failed = Date.now() } finally { c.asking = null } })()) if (!c.images || Date.now() - c.at >= FRESH) { if (Date.now() - c.failed >= RETRY) { const p = ask() if (wait && !c.images) await p } } return c } // imagesFor is what Devin says of each model id's images for key's // account, SNAPSHOT_IMAGES under it; with wait false, a first ask isn't // waited for. async function imagesFor(key, server, wait = true) { const c = await configsFor(key, server, wait) return { ...SNAPSHOT_IMAGES, ...(c.images ?? {}) } } // seesImages is whether a model Devin said nothing of takes images, as // magpie's built-in tells it (models.go: m.Images || catalog.SeesImages): // models.dev's word for the id — most of the providers listing it taking // images — from the catalog magpie's `magpie sync` or OpenCode keeps, and // no when neither has it. let seen = null function seesImages(id) { if (!seen) { seen = new Set() const cache = process.env.XDG_CACHE_HOME || join(homedir(), ".cache") for (const p of [join(cache, "magpie", "models.json"), join(homedir(), ".cache", "opencode", "models.json")]) { let m try { m = JSON.parse(readFileSync(p, "utf8")) } catch { continue } if (!m || typeof m !== "object" || !Object.keys(m).length) continue const votes = new Map() for (const pr of Object.values(m)) for (const [mid, x] of Object.entries(pr?.models ?? {})) { const b = bare(mid) votes.set(b, (votes.get(b) ?? 0) + ((x?.modalities?.input ?? []).includes("image") ? 1 : -1)) } for (const [b, v] of votes) if (v > 0) seen.add(b) break } } return seen.has(bare(id)) } const bare = (id) => String(id).toLowerCase().split("/").pop() function configModel(m) { const image = m.image ?? seesImages(m.id) return { id: m.id, name: m.name, tool_call: true, reasoning: m.efforts.length > 0, attachment: image, temperature: true, modalities: { input: image ? ["text", "image"] : ["text"], output: ["text"] }, limit: { context: m.context, output: m.output }, ...(m.efforts.length ? { variants: Object.fromEntries(m.efforts.map((e) => [e, { reasoningEffort: e }])) } : {}), } } function runtimeModel(m) { const image = m.image ?? seesImages(m.id) return { id: m.id, providerID: ID, name: m.name, api: { id: m.id, url: BASE, npm: CHAT }, status: "active", headers: {}, options: {}, cost: { input: m.cost?.input ?? 0, output: m.cost?.output ?? 0, cache: { read: m.cost?.cache?.read ?? 0, write: 0 } }, limit: { context: m.context, output: m.output }, capabilities: { temperature: true, reasoning: m.efforts.length > 0, attachment: image, toolcall: true, input: { text: true, image, audio: false, video: false, pdf: false }, output: { text: true, image: false, audio: false, video: false, pdf: false }, interleaved: false, }, release_date: "", variants: Object.fromEntries(m.efforts.map((e) => [e, { reasoningEffort: e }])), // magpie's: a model the account's quota doesn't count ...(m.free ? { free: true } : {}), } } // withImages is a list of models with what entries (listed's) say of their // images on them; a model they say nothing of is left as it was. function withImages(models, entries) { const by = new Map(entries.map((m) => [m.id, m.image])) return Object.fromEntries( Object.entries(models ?? {}).map(([id, m]) => { const image = by.get(id) if (typeof image !== "boolean") return [id, m] const caps = m?.capabilities ?? {} return [id, { ...m, capabilities: { ...caps, attachment: image, input: { ...(caps.input ?? { text: true }), image } } }] }), ) } // ---- the devin CLI ----------------------------------------------------------------- // cliPath finds the devin CLI, "" without one. function cliPath() { const exe = process.platform === "win32" ? "devin.exe" : "devin" for (const dir of (process.env.PATH ?? "").split(process.platform === "win32" ? ";" : ":")) if (dir && isFile(join(dir, exe))) return join(dir, exe) for (const p of [join(homedir(), ".local", "bin", "devin"), "/usr/local/bin/devin", "/opt/homebrew/bin/devin"]) if (isFile(p)) return p return "" } function isFile(p) { try { return statSync(p).isFile() } catch { return false } } // cliCredentialsPath is where the CLI keeps its own sign-in. function cliCredentialsPath() { if (process.platform === "win32" && process.env.APPDATA) return join(process.env.APPDATA, "devin", "credentials.toml") return join(process.env.XDG_DATA_HOME || join(homedir(), ".local", "share"), "devin", "credentials.toml") } const tomlString = (s) => '"' + String(s).replaceAll("\\", "\\\\").replaceAll('"', '\\"') + '"' // credentials is credentials.toml as `devin auth login` writes it. function credentials(key, server, webapp, api) { return [ ["windsurf_api_key", key], ["api_server_url", server || SERVER], ["devin_webapp_host", webapp || "app.devin.ai"], ["devin_api_url", api || "https://api.devin.ai"], ] .map(([k, v]) => `${k} = ${tomlString(v)}\n`) .join("") } // readCredentials reads the keys of a credentials.toml the CLI wrote. function readCredentials(text) { const out = {} for (const line of text.split(/\r?\n/)) { const m = /^\s*([A-Za-z0-9_]+)\s*=\s*(?:"((?:[^"\\]|\\.)*)"|'([^']*)')\s*$/.exec(line) if (m) out[m[1]] = m[2] !== undefined ? m[2].replace(/\\(.)/g, "$1") : m[3] } return out } // homeFor is a data folder of this plugin's own, laid out as the CLI's, // with the account's credentials in it: the CLI run with it as its data // folder answers for that account, and its own sign-in is never touched. async function homeFor(key, server) { const base = join(process.env.XDG_CACHE_HOME || join(homedir(), ".cache"), "opencode-devin-auth") const home = join(base, createHash("sha256").update(key).digest("hex").slice(0, 16)) const file = join(home, "devin", "credentials.toml") if (!existsSync(file)) { await mkdir(join(home, "devin"), { recursive: true, mode: 0o700 }) await writeFile(file, credentials(key, server), { mode: 0o600 }) } return home } // runCLI runs the devin CLI, for the account in home ("" for its own), // with its output; it asks Devin's servers, so it has 30 seconds. function runCLI(home, ...args) { const path = cliPath() if (!path) return Promise.reject(new Error("devin is not installed")) const env = { ...process.env } if (home) { for (const k of Object.keys(env)) if (["XDG_DATA_HOME", "APPDATA"].includes(k.toUpperCase())) delete env[k] env.XDG_DATA_HOME = home env.APPDATA = home } return new Promise((resolve, reject) => { const p = spawn(path, args, { env, stdio: ["ignore", "pipe", "ignore"] }) let out = "" p.stdout.on("data", (b) => (out += b)) const timer = setTimeout(() => p.kill(), 30_000) p.on("error", (e) => { clearTimeout(timer) reject(e) }) p.on("close", (code) => { clearTimeout(timer) resolve({ out, code }) }) }) } // signedOut says the CLI's report is one of nobody signed in: it says so, // or Devin's servers refused the account's token. const signedOut = (out) => ["Not logged in", "Authentication required", "Invalid token", "try logging out and logging in again"].some((s) => out.includes(s)) // statusField is a field of `devin auth status`'s report, "" without it. function statusField(out, key) { for (const l of out.split(/\r?\n/)) { const t = l.trim() if (t.startsWith(key + ":")) return t.slice(key.length + 1).trim() } return "" } // parseStatus reads `devin auth status`'s report: its User's Email (or // Name), its Account's Tier (or Plan). function parseStatus(out) { if (!out.includes("Logged in")) return null const field = (key) => statusField(out, key) return { user: field("Email") || field("Name"), plan: field("Tier") || field("Plan") } } // inside says file is in dir, whichever way either is spelled. function inside(file, dir) { const real = (p) => { let r try { r = realpathSync(p) } catch { r = resolve(p) } return process.platform === "win32" ? r.toLowerCase() : r } const rel = relative(real(dir), real(file)) return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel) } // readsHome says the CLI's report is of the credentials.toml in home: the // devin CLI on Windows reads %APPDATA%\devin\ whatever APPDATA it is run // with (#17), and so answers for its own account, not home's. A report that // names no file is taken at its word. function readsHome(out, home) { const file = statusField(out, "File") return !home || !file || inside(file, home) } // identity is who the CLI says is signed in in home: {user, plan}, null // when it says nobody is, undefined when it can't tell (no CLI, no answer, // a CLI that read another credentials.toml than home's). async function identity(home) { try { const { out } = await runCLI(home, "auth", "status") if (!readsHome(out, home)) return undefined const st = parseStatus(out) if (st?.user) return st if (signedOut(out)) return null } catch {} return undefined } // tierName words a teamsTier as `devin auth status` says it: // TEAMS_TIER_DEVIN_PRO is "Devin Pro", TEAMS_TIER_DEVIN_TEAMS_V2 "Devin // Teams" (the CLI leaves the tier's version out). const tierName = (t) => String(t ?? "") .replace(/^TEAMS_TIER_/, "") .split("_") .filter((w) => w && w !== "UNSPECIFIED" && !/^V\d+$/.test(w)) .map((w) => w[0] + w.slice(1).toLowerCase()) .join(" ") // whoByKey is whose key it is, as GetUserStatus (usage's) says, asked with // the key itself: {user, plan}, null when Devin refuses the key, undefined // when it can't tell. async function whoByKey(key, server) { let res, text try { res = await userStatus(key, server || SERVER) text = await res.text() } catch { return undefined } if (res.status === 401 || failure(res.status, text).status === 401) return null if (!res.ok) return undefined let u try { u = JSON.parse(text || "{}")?.userStatus ?? {} } catch { return undefined } const user = u.email || u.name if (!user) return undefined const info = u.planStatus?.planInfo ?? {} return { user, plan: tierName(u.teamsTier || info.teamsTier) || info.planName || "" } } // cliAnswersFor says whether the CLI, run with home as its data folder, // answers for key's account: the account it names is the one Devin says // the key is. A CLI that reads another credentials.toml than home's (on // Windows it reads %APPDATA%\devin\ whatever APPDATA it is given, #17) // answers only when it names that account; one that reads home's is taken // at its word when Devin can't tell. undefined when it can't tell. async function cliAnswersFor(key, server, home) { let out try { ;({ out } = await runCLI(home, "auth", "status")) } catch { return undefined } const own = readsHome(out, home) const cli = parseStatus(out)?.user if (!cli) return own const who = await whoByKey(key, server) if (!who?.user) return own return who.user.toLowerCase() === cli.toLowerCase() } // Each account's model list as the CLI last gave it, kept FRESH; one past // its time is served while it is read again, one that failed is asked // again after RETRY. A CLI that doesn't answer for the account (#17: on // Windows it lists its own account's) is never asked for it. const lists = new Map() // familiesFor is key's account's list: what Devin tells the CLI's model // picker for the key (GetCliModelConfigs, the list `devin models list` // prints, asked with the key itself, so on any system and for every // account), else the CLI's when it answers for the account, else Devin's // list as of SNAPSHOT. On Windows the CLI answered for no account added // in the browser, and an account without the CLI had only SNAPSHOT, so // neither got Gemini 4 Argon (plugins #115). async function familiesFor(key, server, wait = true) { return (await ownFamilies(key, server, wait)) ?? familiesOf(SNAPSHOT) } // ownFamilies is familiesFor's list when Devin or the CLI gave one, null // when neither has. async function ownFamilies(key, server, wait = true) { const told = (await configsFor(key, server, wait)).families if (told) return told let c = lists.get(key) if (!c) lists.set(key, (c = { families: null, at: 0, failed: 0, asking: null, cli: undefined })) const ask = () => (c.asking ??= (async () => { try { const home = await homeFor(key, server) if (c.cli === undefined) c.cli = await cliAnswersFor(key, server, home) if (c.cli === false) return const { out } = await runCLI(home, "models", "list", "--format", "json") const fams = parseFamilies(out) if (!fams.length) throw new Error("devin models list: no models") Object.assign(c, { families: fams, at: Date.now(), failed: 0 }) } catch { c.failed = Date.now() } finally { c.asking = null } })()) if (c.families) { if (Date.now() - c.at >= FRESH && Date.now() - c.failed >= RETRY && c.cli !== false && cliPath()) ask() return c.families } if (c.cli !== false && cliPath() && Date.now() - c.failed >= RETRY) { const p = ask() if (wait) await p } return c.families } // ---- signing in ---------------------------------------------------------------------- function page(ok, title, text) { const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]) return `
${esc(text)}