"factory" joins retiredBuiltins: every Factory account is served by
@magpie-community/opencode-factory-auth, and the hourly MoveRetiring
moves the ones still on the built-in.
Removed: the built-in's sign-in (factory_signin.go, WorkOS's device
flow), keeping the sign-in (renew, lapse, org reconcile and mend,
headers, factoryGet), its provider and account (factoryProvider,
factoryAccount, factoryAlsoOn), its login list, switch, on/off and
forget, its usage card (factoryLoginQuota), droid's prompt and body
rewriting (factory_client.go), and its rows in signin.go, logins.go,
logins_on.go, login_usage.go, subscription_usage.go and account.go.
zcodeDecode/Encode, kept in zcode.go only for factory_client.go, go
with it. An API key always goes to the plugin now (factoryAddKey), and
`magpie accounts import factory` keeps saying to add it with accounts
add factory; its dead import branches are gone.
Kept: the mover and what it reads (factoryLogins, factorySaved,
factoryCreds, factoryMu); ImportFactoryKeys, factory_key.go and
factoryWhoami, for "Use an API key instead"; droid's model table with
factoryAPIs and factoryCore, since the plugin's provider is named
"factory" (account.go APIs, FactoryGemini and servedByFactory still
answer for it); factoryAPI for the moved provider's host
(builtinHost); factory_usage.go's limits reader behind
FactoryAllowanceForTest, which the gateway's pool tests use; the
gateway's "factory" lists (estimatedMoved, the account check), as the
Zed commit kept zed's; the parity tests.
Tests:
- git rm'd, built-in only: factory_test.go (sign-in, refresh, accounts,
orgs), factory_client_test.go, gateway factory_agents_test.go
(droid's line on every wire, the generate route to chat) and
factory_think_off_test.go (TestPluginThinkingOff covers the plugin);
TestFactoryAPIKey, TestFactoryKeyAgainReadsUsageAfresh,
TestFactoryServesModelsAddedSinceItsFetch, TestUserAgentAccountUntouched
(TestUserAgentFor still covers an account's User-Agent).
- Changed meaning: TestGeminiEmptyReplyIsAnError,
TestGeminiEmptyRepliesAskedAgain and TestGeminiImageModelReturnsItsImage
used Factory's generate route as a fake-able Gemini upstream; they now
use a Gemini API of the user's own (saveGem), the same decoder, and the
image test checks :streamGenerateContent instead of /api/llm/g/v1/generate.
TestMovedShowsBuiltinHost's first check is now a plain plugin
(fakeco), and a retired Factory with no migration record shows
api.factory.ai. TestFactoryAPIKeyMoved checks factoryLogins() is empty
instead of the removed factoryLookup. factorySite/factoryJSON moved
into factory_key_test.go.
Run in this worktree:
gofmt -l internal: nothing
go vet -tags nogui ./internal/provider ./internal/gateway ./internal/cli
./internal/gui, GOOS=darwin, linux, windows: clean
staticcheck -checks U1000 -tests=false (darwin, windows) on
internal/provider: nothing new
go test -tags nogui -count=1 -run 'Factory|Gemini|PaymentRequired|
ResetsInWords|UserAgent|UsedWindow|Vertex|PayloadTooLarge|UsageCache|
AnthropicImage|ThinkingOff|Moved|Retired|Mover|Migrat|Move|
SayTheirPlugin|Allowance|Discovery|ClaudeModels|GrokPrice|
LoopbackSignIns|AsksOwnBackend|SideLogin|Import|Accounts|ZCode|MiMo'
on the four packages: ok (all four); TestFactoryAPIKeyMoved ran with
Bun (PASS), not skipped.
Not run: whole packages, the full suite, the GUI suite (machine load
~300). Not tried with a real Factory account. docs/subsystems not
changed, as for Zed.
Factory answered every model 403 "Forbidden" to requests that named an
older droid version. The built-in now sends factoryVersion 0.242.0, and
the mover's min is 0.1.30, the plugin release with the same headers
(magpie-community/plugins b8717aa), so keepMovedCurrent updates every
moved user's plugin.
npm view @magpie-community/opencode-factory-auth@0.1.30 --prefer-online
answers 0.1.30.
Run: gofmt; go vet -tags nogui ./internal/provider for darwin, linux and
windows; go test -run 'Factory|Moved|Mover|Migrat' ./internal/provider ok.
Not tried: a real Factory account through the built-in.
Full suite: SUITE_LINE
droid 0.241.1's picker has Gemini 4 Argon (provider google, 1M total
context, 65536 output, low/medium/high, images); the built-in's table
stopped at Gemini 3.1 Pro. It goes to /api/llm/g like the other Gemini
models. In droid it is behind a Factory feature flag (Gemini4Argon,
unreleased), so an account it isn't on for may be refused it.
TestFactoryDroid0241Gemini reads droid 0.241.1's picker and Gemini
entries (testdata, byte for byte from @factory/cli-darwin-arm64@0.241.1
bin/droid, the same fixture as the plugin's) and checks every Gemini
model there is offered with droid's name, limits, efforts and images,
on Gemini, in standard's pool.
Moved users get it from plugin 0.1.26 (the next commit raises the
mover's min).
Run: gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows on
internal/provider and internal/gateway; go test ./internal/provider
./internal/gateway -count=1 (ok, under load average ~260). Broken by
hand: without the row the new test fails. Not tried: a real Factory
account (none here).
JL (Windows, droid 0.240.0, Factory desktop 0.197.1, magpie 0.1.1226,
opencode-factory-auth 0.1.24): droid and Factory desktop offer
claude-haiku-5-5; droid through magpie couldn't pick it.
droid's models are the registry bundled in its npm binary
(@factory/cli-<platform> 0.240.0, bin/droid). Against 0.233.0's registry,
0.240.0 adds claude-haiku-5-5, mistral-large-4 and gpt-6-astra-ultrafast.
The plugin (magpie-community/plugins e4023d9, published as 0.1.25, npm view
checked) now offers Haiku 5.5 (Anthropic Messages, 872000/128000, efforts
low..max) and Mistral Large 4 (chat completions, x-api-provider mistral,
Droid Core, 524288/64000, images). GPT-6 Astra Ultra Fast stays out: droid
offers it only once the user accepts Factory's high-cost terms.
- migrate_factory.go: the mover's min is 0.1.25, so keepMovedCurrent
updates moved users (JL is on the plugin).
- factory.go: the built-in had the same gap; its table gets the same two
rows for users who haven't moved.
- factory_pool_rest_test.go: the plugin's Core list, copied from its
usage, gains Mistral Large 4.
- TestFactoryDroid0240Models is new; its fixture is droid 0.240.0's
registry bytes (the same as the plugin's models.test.mjs). It fails with
the Haiku 5.5 row removed.
Run, under a temp HOME: go test -tags nogui ./... with the machine at load
35-190 (other sessions). Every package passed except five that hit the
10m timeout mid-test (agent, gateway, library, plugin, provider, in
tests that don't touch Factory). Rerun with -timeout 40m: provider ok;
gateway still timed out at load ~130 (TestCodexHeardWithinItsIdleTimeout
failed on its timing, unrelated); -run 'Factory|Moved' on gateway ok.
agent, library and plugin were not rerun to the end; this change
doesn't touch them. gofmt -l clean; GOOS=linux and GOOS=windows go vet
-tags nogui on internal/provider and internal/gateway ok.
Not tried against Factory itself (no Factory account here); droid was read,
not run.
The Claude subscription's models are magpie's own list, the models.dev
catalog's anthropic rows. Its fetch kept a copy of that list in
models/claude.json, and available() served that copy over the catalog
from then on. FetchNew fetches an account only while it has no list, so
the copy was never taken again unless the user pressed Refresh: the
hourly models.dev sync brought Claude Haiku 5.5 (listed from 2026-10-07)
into the catalog, while the Claude account kept offering the list as it
was at its first fetch. The owner's own copy is from 2026-10-03 and has
no claude-haiku-5-5, though the synced catalog beside it has.
An account whose fetch asks no vendor (magpieList: Claude's, and
Factory's compiled-in droid list, which had the same hold-out after an
update) is now always served its list as it is now. A vendor's own list
(Codex, Copilot, Kiro, ...) is served as fetched, as before.
Haiku 5.5's facts come from the catalog: models.dev's row (1M context,
128K output, low..max efforts, $0.10/$0.50 with $0.50/$2.50 over 100K)
matches Claude Code 2.1.296's own model catalog (window 1e6, native 1M,
max_output 128000, effort/xhigh_effort/max_effort, default medium). So
no static table needed a row: claudeEffortsFor gives an unknown newer
Claude all five levels, and claudeTopEffort rightly leaves it out
(2.1.296 reads the top effortLevel only for the models up to Fable 5.1).
With the model listed, the haiku tier follows the newest Haiku
(claudeLight), as Claude Code's own default haiku on the Anthropic API
is claude-haiku-5-5 since 2.1.293.
Verified:
- TestClaudeAccountServesModelsListedSinceItsFetch (models.dev's real
rows) fails without the models.go change: "Haiku 5.5 not served on the
Claude account: [claude-opus-5-5]". TestFactoryServesModelsAddedSince
ItsFetch fails without Factory's flag. Both pass with the change.
- gofmt -l clean; go vet, GOOS=linux and GOOS=windows go vet -tags nogui
./internal/provider; go build, GOOS=linux and windows build -tags nogui.
- go test -tags nogui ./internal/provider ./internal/agent
./internal/catalog ./internal/gateway ./internal/gui under a temp HOME:
all ok.
- Not tried against a running magpie with a real Claude sign-in: the
owner's gateway on 3425 wasn't running. The stale models/claude.json
and synced models.json were read from the owner's cache (read only).
* fix(factory): open Anthropic requests with Droid's line
Factory only accepts a subscription request whose body opens as Droid
(#242, #506). Responses and chat completions already do. Anthropic
Messages now puts that line in the first system block, as droid2api
does, and keeps the agent's own prompt after it.
* fix(factory): serve Gemini on Factory's generate route
Every agent already reaches Factory's Claude, GPT and open models:
the gateway translates its own API into the model's, and the body
opens with Droid's line. Gemini was the wire still missing.
droid2api posts those models to /api/llm/g/v1/generate and prepends
the same line to systemInstruction. Factory now does that too.
The models are the ones droid 0.232.0's CLI registry still offers
(gemini-3.1-pro-preview, 3.8/3.7/3.6/3.5 Flash, gemini-3-flash-preview).
2.5 and Gemini 3 Pro Image are availableInCLI false there and stay out.
They are not Droid Core. A streamed Gemini reply comes back in the
client's own API.
TestFactoryFromEveryAgentWire posts Claude Code, Codex, Pi, OpenCode
and Gemini CLI at Claude, GPT, GLM and Gemini. TestFactoryGeminiStreamsToChat
reads a Gemini SSE chunk back as chat completions. Not tried against
a real Factory account.
* fix(factory): open other agents with droid2api's system prompt
droid2api's config.json system_prompt is Droid's line and a blank line,
written in front of the agent's own prompt on Responses, chat, Messages,
and Gemini generate. A body that already opens with the line is unchanged.
* fix(factory): answer non-streaming Gemini clients with JSON
Factory's generate route always returns SSE and droid sends no stream
field. A generateContent call is translated into JSON; a relayed
streamGenerateContent drops stream before it goes upstream. The provider
Test probes generate instead of failing the protocol, and a Gemini model
is tested on that route. The system prompt is joined into the one
systemInstruction part droid sends.
* fix(factory): join Droid's opening with one newline
droid writes the line and one newline in front of the agent's prompt.
The extra blank line from droid2api's system_prompt is dropped.
Anthropic still keeps the line as its own first block.
* fix(factory): send Droid's line alone when there is no prompt
droid joins blocks with "\n", so a request with no system prompt is
the line and nothing after it. Responses, chat and Gemini were
sending the line plus a trailing newline. Anthropic already sent
the line alone.
droid (0.229.0, still the latest) asks /api/cli/whoami about each token it holds and sends the orgId it answers as X-Factory-Org-Id on every request (its auth's Do → _r → Pr/Ar, Ci() spread into xc). Accounts signed in with v0.1.432, or whose org had been dropped after a refusal, kept none, and magpie never asked whoami again after renewing a token, so their requests went with no org and Factory answered its generic 403 {detail:"Forbidden"}. Now an account with no org asks whoami before its request (at most every 10 minutes per account), each renewal asks again, an org whoami refuses is left off and whoami asked without it, and the org, region and whoami's premBaseHostV2 (an org's own host, where droid sends model requests) are kept. whoami goes with droid's three headers only (Authorization, X-Factory-Whoami-Extended, the org). Claude requests carry X-Api-Key: placeholder, as droid's Anthropic client does. A 403 on an account that sent no org asks whoami and retries once; one that stays tells the user to check droid on the same account and model and to sign in again (Provider.Explain, in the gateway's three error paths). Tested with TestFactoryForbiddenWithoutOrg against a fake Factory refusing requests without the org header, the account saved as v0.1.432 did: glm-5.2 succeeds with the exact headers, whoami asked once with droid's headers, a 403 while whoami was down asks again and retries, the enterprise host used, the explanation on 403s only; it fails with the lookup off. The existing Factory tests are updated for the headers and org. go vet, go build -tags nogui (and GOOS=linux, GOOS=windows) and go test -tags nogui ./... pass. Not tried against Factory's real server or tasselx's account.