Files
plugins/packages/raccoon
MYCF711 04b4438955 raccoon 0.1.5: the card names the account by its phone, not by Raccoon-pu-<uuid> (#486)
The card names a Raccoon account by its masked phone (cardName), read from
user_info, instead of Raccoon-pu-<uuid>; accountId stays the identity, and a
desktop seat is named by its phone too. A renewal never changes accountId, and
a desktop seat's refresh still gives nothing, as on main.

Reviewed at ac0d84e (round 4). Run on mote (macOS, Bun 1.4.2) in a sandbox
HOME, at that head:
- bun test packages/raccoon: 43 pass / 0 fail
- bun scripts/check.mjs raccoon: ok
Broken by hand: dropping `|| auth.source === "desktop"` from refresh's guard
(index.mjs:1047) turns "a desktop seat's refresh gives nothing, even when
user_info answers a phone" red (42/1), now that its record carries
refresh: "D1". Earlier rounds' breaks (usage's cardName, 0.1.4 record) were
red too.
CI (test, on-npm) green at ac0d84e. Version 0.1.4 -> 0.1.5.
Not changed: a test for the desktop seat picking up a new phone when the
app's token changes (index.mjs:337), optional in the review.
Not tried: a real Raccoon account.
2026-10-29 21:35:33 +08:00
..

@magpie-community/opencode-raccoon-auth

OpenCode & Magpie provider plugin for SenseTime Raccoon (商汤小浣熊, xiaohuanxiong.com).

Features

  • Sign-in methods:
    1. Browser OAuth with automatic loopback return: confirm authorization in the browser; no desktop client or pasted code is needed.
    2. Manual callback URL / token fallback (paste office-raccoon://auth/callback?code=..., or raw JWT access_token / JSON token pair).
    3. Raccoon desktop live session reuse (strictly read-only, reading the auth.json the desktop app keeps — <profile>/agent/config/auth.json in current builds, where the profile is ~/Library/Application Support/office-raccoon on macOS and %USERPROFILE%\.office-raccoon on Windows, and ~/.box-agent/config/auth.json in older ones — without writing or spending desktop refresh tokens). A desktop seat keeps the token it was signed in with on its own record, so it is never answered with, and never reports, another account's credentials or credits; once its own token is refused or runs out it asks to be signed in again. The app's own refresh token is still never spent.
  • Token renewal: single-flight proactive refresh 5 minutes before expiration for browser logins.
  • Dynamic model catalog & credit rates: real-time synchronization from /api/web/llm/v2/model_catalog with context window, output limit, vision/reasoning tags, credit multipliers, and limited-free markers.
  • Usage & allowances: reports available credits, unexpired grant bills, daily expiration timestamps, and Pro/Free subscription plans.
  • Daily check-in & desktop onboarding grant: supports Magpie automatic daily check-in (+300 credits/day) and one-time desktop onboarding grant (+3000 credits).
  • SSE model rewrite: transparently rewrites internal upstream model names back to requested downstream models for client compatibility.
  • The card's name: the account's own phone number (138****8000), read once per token from /api/web/auth/v1/user_info with the JWT the sign-in holds. accountId stays the account's identity (the JWT's Raccoon-pu-<uuid>, or the desktop app's name) — magpie keys the user's own name for the account, its proxy, model picks and a gateway key's list by it, so it never changes. The card shows usage's user, which is the phone once a sign-in or renewal has read it. A failed read changes nothing and never costs a sign-in.

中文

商汤小浣熊(SenseTime Raccoon / xiaohuanxiong.com)OpenCode & Magpie 提供商插件。

功能特性

  • 多种登录方式:
    1. 浏览器 OAuth 授权登录:确认授权后自动返回,无需安装官方桌面客户端,也无需输入短信验证码或粘贴网页地址。
    2. 手动回调 / Token 备用入口:粘贴 office-raccoon://auth/callback?code=... 完整回调链接,或 access_token / JSON;普通授权网页地址和单独授权码不能代替完整回调。
    3. 直接只读复用本机商汤小浣熊客户端实时登录态(客户端保存的 auth.json:新版在客户端配置目录下的 agent/config/auth.json(macOS 为 ~/Library/Application Support/office-raccoon,Windows 为 %USERPROFILE%\.office-raccoon),旧版在 ~/.box-agent/config/auth.json)。桌面端席位会把登录时读到的 token 保存在自己的账号记录里,因此它不会拿到、也不会上报另一个账号的凭据或积分;一旦自己的 token 被拒或用尽,就提示重新登录(客户端自身的 refresh token 依旧不会被动用)。
  • Token 自动续期:浏览器登录账号过期前 5 分钟自动单飞刷新。
  • 动态模型目录与积分倍率:实时同步 /api/web/llm/v2/model_catalog,展示模型上下文、最大输出、视觉/思考能力、积分倍率与限免(Free)标识。
  • 积分余额与套餐查询:展示可用积分、未过期发放额度、每日积分过期时间与 Pro/Free 套餐状态。
  • 每日签到与桌面端登录奖励:支持 Magpie 每日自动签到(+300 积分/天)及首次桌面端 +3000 积分登录奖励领取。
  • SSE 模型名重写:将上游响应中的内部模型名重写为下游请求的 model,确保 Claude Code / Codex / OpenCode 等客户端兼容。

Browser callback lifecycle

The browser flow uses the authorize page's desktop_callback=loopback contract, a random 64-character hex state and http://127.0.0.1:<port>/auth/callback. The listener accepts only the matching host, GET path and state. Invalid callbacks leave the pending login intact; success, authorization refusal, exchange failure or the ten-minute deadline close it. A browser page says success only after the code exchange succeeds; response pages contain no code or token and disable caching. Closing/cancelling the host UI does not notify this plugin through the OpenCode callback contract, so an abandoned listener expires at that deadline. When a remote browser cannot reach that machine's loopback, Magpie can forward a pasted final callback URL; the separate manual method remains available as well.

Desktop seats

The desktop app is signed in to one account at a time and keeps only that account's JWT in auth.json. A desktop seat therefore saves the token it was signed in with on its own record and uses it for every request, reading the app only to pick up a newer token for that same account. A seat whose account the app no longer holds is never answered with the app's current token: it keeps using its own until that token is refused, and then asks to be signed in again, rather than being billed to an account it does not name. Adding a seat takes only the account the app holds at that moment.

Note that signing in to a second account in the desktop app revokes the first account's session on the vendor's side, so the first seat's token stops being accepted then — its exp notwithstanding — and is answered 401 {"code":200003} by the credits and check-in endpoints, with every refresh endpoint answering 404 for it (#166, measured on a real pair of accounts). Two desktop seats are therefore one live account plus one seat waiting to be signed in again, never two working seats. For two accounts that both work, sign in twice through the browser method.