Files
plugins/packages/raccoon
yetone 0135b7b0ea agy-cli 0.1.32: the first model list after warming has agy's Claude and GPT models (#1064)
On a signed-in agy, `agy models` takes about 4.4s and `agy acp`'s
session/new about 3s. provider.models() needed three calls before
claude-opus-5-5, claude-sonnet-5-5 and gpt-oss-120b showed up, and
OpenCode 2.x calls it once.

What changed:
- packages/agy-cli/index.mjs:
  - The offered-model probe now starts in listAgyModels' .then, as soon as
    a non-empty list arrives and a caller asked for probeOffered. It no
    longer waits for the next models() call. A hung or failed `agy models`
    still never spawns the probe.
  - probeSignedIn reuses the `agy models` stdout it already has. The same
    parser (parseAgyModels, split out of listAgyModels) fills
    cachedModelCatalog, and the probe starts. Sign-in waits for the probe
    for at most 3s.
  - The offer (acpOfferedModels, acpOfferedKey, offeredProbeAt and any
    in-flight probe) is forgotten when agyPath changes and after a new
    sign-in finishes. A generation counter drops the answer of a probe
    that started before the reset.
  - provider.warming() returns a promise while a list or probe is still
    running, and null when nothing is.
- scripts/opencode2.mjs, copied byte for byte to every
  packages/*/opencode2.mjs: after the first background refresh, the
  adapter awaits hooks.provider.warming() once, for at most 60s, and then
  refreshes once more. It does not loop. Plugins without warming() behave
  as before.
- Not done: the issue's on-disk catalog cache (point 3), skipped as asked.

Known gap: agy-cli has no `config` hook, so under OpenCode 2.x the adapter
lists no provider for it. refresh() returns before it calls
provider.models(), so the follow-up refresh can't add agy's models on 2.x
until agy-cli gets a config hook.

Tests: test/testkit.mjs's fake agy takes a sessionNewDelayMs. The new
tests in test/catalog.mjs set 1.5s on both `agy models` and session/new
and wait for state through warming(), with no fixed sleeps:
- On a slow cold start, the first models() after warming lists Claude and
  GPT, from one probe spawn.
- authorize() on a signed-in agy fills the catalog, and the next models()
  runs no second `agy models`.
- The sign-in wait is bounded: with a 6s session/new, sign-in returns in
  about 4.5s.
- Changing agyPath probes again.
The hang test now awaits warming() before it counts acp spawns.
scripts/opencode2.test.mjs: the warming list is read a second time when
warming ends, and only once when nothing is warming.

Run on Linux (a separate test Mac was over its load limit):
- packages/agy-cli bun test: 17 pass, 0 fail.
- bun scripts/check.mjs agy-cli: ok.
- bun scripts/check.mjs (all packages): ok.
- Root bun test in a temp HOME: 8530 pass, 19 skip, 0 fail.

Broken by hand on Linux, each red, then restored green:
- No probe in the .then: the slow cold-start test.
- probeSignedIn drops the list: the authorize and bounded-wait tests.
- agyPath change keeps the old offer: the agyPath test.
- Unbounded sign-in wait: the bounded-wait test (7514ms).
- Probe also on a failed listing: the hang test.
- origin/main's index.mjs with the new tests: all four #1064 tests.
- Adapter reads the list once: the warming adapter test, and the
  copy-identity check.

Not tried: a real agy (no Google sign-in, no network). The reset after
login.finish has no unit test of its own.

Reported-by: hiee3
2026-11-13 10:59:13 +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 套餐状态。积分余额接口 /api/web/points/v1/balance 拒绝时(403),改从 /api/web/office/v3/setting_info 读可用积分;套餐接口读不到时不显示套餐,而不是当作 Free。余额比账单里未过期的发放额度略多时(10% 以内),以这批发放下见过的最高余额作总额,之后用掉的积分记为已用;有新的发放或发放过期时重新计。
  • 每日签到与桌面端登录奖励:支持 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.