Files
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-nous-auth

Signs in to Nous Portal with its OAuth Device Authorization flow and sends model requests in magpie and OpenCode. Provider id: nous-portal. This is separate from magpie's nous API-key preset.

Signing in

Once the package is available from magpie's plugin registry:

magpie plugin add @magpie-community/opencode-nous-auth
magpie plugin login nous-portal

Magpie displays a verification URL and a code. Open the page, sign in and approve the code there; finish any CAPTCHA in your browser. The plugin polls for approval and completes sign-in without a local callback server. Hermes Agent does not need to be installed or running.

In OpenCode, add "@magpie-community/opencode-nous-auth" to the plugin array in opencode.json, then run opencode auth login.

The flow uses Nous Portal's /api/oauth/device/code and /api/oauth/token with public client hermes-cli, scope inference:invoke, and no client secret. Device polling follows RFC 8628, including the server's interval and slow_down responses. Nous has not confirmed whether independent clients may use the public hermes-cli OAuth client ID.

For ChatGPT plan sharing, see Nous Portal's documentation.

Where the sign-in is kept

Magpie keeps the account in its plugin credential store; OpenCode uses its own sign-in store. The saved OAuth fields are access (inference JWT), expires (epoch milliseconds) and refresh (versioned JSON containing the refresh token, scope, token type and inference endpoint). The entire refresh value is secret, even though it looks like JSON.

Expiry uses the earlier of the token response's lifetime and the JWT's exp. If both are absent, renewal is scheduled one hour after the exchange, with the same two-minute lead. This is a local fallback, not a Nous lifetime guarantee; a 401 can still trigger renewal sooner. Explicitly expired or malformed lifetimes are not extended.

Nothing is read from or written to ~/.hermes/auth.json. A separate device sign-in is intentional: Nous refresh tokens are single-use, and copying one from Hermes could invalidate Hermes's session when either program renews it.

Magpie uses auth.refresh with a two-minute lead and saves the rotated tokens. OpenCode does not call that hook, so the plugin also checks before each request and persists renewals through client.auth.set. Concurrent refreshes within one plugin instance share one exchange. A rotated pair is kept in memory before a save is attempted, so a failed save does not cause that instance to reuse the old refresh token.

Do not run multiple hosts against the same saved account. The per-request save is not an atomic cross-process operation; a crash during an unsaved rotation may require signing in again. Only explicit invalid_grant, invalid_token or refresh_token_reused errors mark the grant expired. Other refresh refusals, including HTML or empty 401/403 responses, keep the credentials and allow a later retry.

Requests

Models use OpenAI Chat Completions (@ai-sdk/openai-compatible) at https://inference-api.nousresearch.com/v1. Magpie translates requests from other agent protocols. Every request uses the current inference JWT as a Bearer token; the refresh token is sent only to Portal's token endpoint in x-nous-refresh-token, never to inference.

The plugin accepts only known inference paths (/models, /chat/completions, /completions, /embeddings) at the production Nous inference or welcome host. A Portal response cannot redirect Bearer tokens to an arbitrary host; HTTP redirects are refused. Caller-supplied credentials and magpie-internal headers are removed before forwarding.

A 401 triggers at most one refresh and retry. Other upstream errors keep their status, and streaming responses pass through without buffering or rewriting their content. The upstream content-encoding and content-length headers are removed because fetch may already have decoded the body.

Models

After sign-in, the account's live /v1/models list replaces the single bootstrap entry (Hermes-4-70B). Model ids are preserved, including the vendor prefix such as openai/gpt-6-luna. In magpie an exposed model is addressed as nous-portal/openai/gpt-6-luna.

Magpie may initially expose only part of the catalog. To choose a model listed for your account and test it:

magpie provider refresh nous-portal
magpie provider models nous-portal +openai/gpt-6-luna
magpie provider test nous-portal openai/gpt-6-luna

The provider test command takes the upstream id (openai/gpt-6-luna), not the magpie-prefixed id. Model availability and billing depend on the account; a model appearing in /models does not guarantee access. The plugin does not guess model prices, context limits or vision/reasoning capabilities when the catalog does not provide them. A failed catalog read does not become an empty entitlement list.

Not included

  • Nous Portal API keys (nous remains magpie's separate built-in preset).
  • Importing Hermes credentials or running Hermes's subscription proxy.
  • Direct ChatGPT/Codex OAuth, billing or quota reporting, or daily check-in.
  • An arbitrary inference URL override or cross-process token coordination.

Test

Run the offline checks from the repository root with a temporary HOME:

h=$(mktemp -d)
HOME="$h" node --test packages/nous/index.test.mjs
HOME="$h" bun test
rm -rf "$h"
bun scripts/check.mjs

Before publication, try the local package with magpie's isolated test script:

export MAGPIE=/absolute/path/to/magpie
sh scripts/try.sh nous
sh scripts/try.sh nous login nous-portal
sh scripts/try.sh nous provider refresh nous-portal
sh scripts/try.sh nous provider test nous-portal openai/gpt-6-luna

try.sh uses .sandbox/nous rather than your real magpie sign-ins. It clears ordinary environment variables, including proxy settings; configure a proxy inside the sandbox if needed. Do not use a portable Windows magpie binary that ignores HOME isolation. Sign-in and provider test contact Nous Portal; the latter may consume account credits. Test a model your account can use, and never share the sandbox's credential files.

Protocol reference: Hermes Agent's device flow, refresh handling and Nous Portal proxy adapter.