Files
plugins/packages/agnes-code
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-agnes-code-auth

把 Agnes Code 桌面端 的账号额度接入 magpie 与 OpenCode:复用桌面端登录态(会话文件解密),直连云端 OpenAI 兼容网关,agent 以 agnes-code/<model> 使用它的模型;支持「每日登录送积分」自动观测与积分余额显示。

与 agnes(Agnes AI 国际版)的区别

Agnes 在 registry 里有两个入口,都保留(#614):

本包(agnes-code) agnes(agnes)
登录 读 Agnes Code 桌面端已保存的会话(Windows,DPAPI + safeStorage),或粘贴 accessToken 在 Chrome 里登录 Agnes AI 国际版网页(agnes-ai.com),不需要桌面端
服务 Agnes Code 编码产品:api-agnes-code.agnes-ai.com/v1(chat completions,编码模型目录) Agnes AI 国际版的文本模型、Token/Agent Plan 用量与美元余额
每日额度 本产品的每日积分(api/v2/subscription/credits-balance) 该产品自己的套餐与余额读数
平台 桌面端解密仅 Windows,其余平台走粘贴 有 Chrome 即可

两者是 Agnes 同一个账号体系下的两个不同产品:各自读各自产品的余额读数,装的模型与端点也不同,装两个不会重复也不会互相替代。

English: two entries serve Agnes. This one reuses the Agnes Code desktop's saved session (Windows) or a pasted accessToken and calls the Agnes Code gateway; the agnes entry signs in to Agnes AI international in Chrome and meters that product's plans and USD balance. Same account system, different products: neither entry replaces the other.

登录什么

两种方式(登录时二选一):

  1. 读取 Agnes Code 桌面端登录态(推荐,仅 Windows)——本机装有 Agnes Code 桌面版并登录过即可,不用填任何东西。没装/没登录时这一步会给出 Agnes Code 官网页 链接并自动等待:装好登录后自动完成,不用回来点按钮。本机已有数据但读不出来(登录已过期、DPAPI 解不开、会话里没有 accessToken)会直接说明原因,打开桌面端登录或修好后同样自动完成。插件按 Chrome 同款方案解出会话(Local State 的 DPAPI 包裹 AES 主密钥 → 解 code-auth-session.v1 的 AES-256-GCM),只在本机、当前 Windows 用户下可解,凭据不外传:
    • 会话目录:%APPDATA%\AgnesCode\。macOS/Linux 下桌面端解密不可用,会明确提示改用粘贴方式。
    • 会话 JWT 过期会提示打开 Agnes Code 重新登录后重试(桌面端负责续期)。
  2. 粘贴 accessToken——从桌面端会话里复制 JWT(eyJ…);可选填用户名便于区分账号。

每个账号登录一次即得一个 magpie 账号,可多账号故障切换。凭据保存在 magpie 的 plugin-auth.json(权限 600),不上传。

模型

供应商 id agnes-code。目录按账号实时拉取(GET /v1/models,读取不计费)。2026-11 实测目录:

modelId context 备注
agnes-3.0-flash 512k 免费,思考
agnes-2.5-flash 512k 免费,思考
agnes-2.5-pro 512k 免费,思考
gpt-6.1-sol 1M 会员
gpt-6-astra 1M 会员
grok-4.7 500k 会员
claude-opus-5-5 1M 会员
deepseek-v4.1-flash 1M 会员,思考
deepseek-v4-pro 1M 会员,思考
glm-5.3 1M 会员
kimi-k3 1M 会员

带 thinking_toggle 的模型标为推理模型;会员专属模型照常列出,免费账号调用会得到上游透明的 403(subscription_required),不影响登录态。

每日签到

免费档「每日登录送 600 积分」由服务端随当日会话自动发放,没有领取接口——插件的 auth.checkin 每天做一次账号会话活跃(只读请求)并观测发放前后的余额差:涨了记已领取(+600);没涨不谎称已签,如实报「未观测到新发放」(发放可能挂靠桌面端登录)。

用量

显示真实积分余额(GET /api/v2/subscription/credits-balance,读取不计费):积分总额、限时积分、永久积分(有则显示)。401/403 会把账号标记为需要重新登录。

协议与上游

  • 模型调用:POST https://api-agnes-code.agnes-ai.com/v1/chat/completions(OpenAI chat 协议,Authorization: Bearer <accessToken>,思考在 reasoning_content)。
  • 模型目录:GET https://api-agnes-code.agnes-ai.com/v1/models。
  • 积分:GET https://api.agnes-ai.com/api/v2/subscription/credits-balance。

风险提示

非官方集成,凭据与协议来自桌面客户端逆向,上游随时可能变更;共享登录态的自动化使用可能违反 Agnes Code 服务条款,账号风险自担。请勿用于批量/滥用场景。

安装与开发

magpie plugin add @magpie-community/opencode-agnes-code-auth
magpie plugin login agnes-code              # 选「读取 Agnes Code 桌面端登录态」或「粘贴 accessToken」
magpie provider test agnes-code agnes-3.0-flash

测试(零依赖,Node ≥18 或 Bun):

npm test          # = node --test
# 或 bun test