Commit Graph
3 Commits
Author SHA1 Message Date
yetone 03a800ac69 agent: OpenCode 2's config in its own words (kaising00 on X)
For an OpenCode 2 magpie wrote OpenCode 1's opencode.json: its provider
under `provider`, the small model as `small_model`, and `reasoning: true`
on models that reason. OpenCode 2 converts the first two in memory, but
it doesn't read `reasoning` and logged a WARN for each such model on
every load ("configuration normalization diagnostic ... omitted
unsupported legacy setting", reproduced with a real OpenCode 2.2.6).

Now the OpenCode that reads the file decides its words (openCodeTwo in
opencode_v2.go: the opencode on PATH, or a WSL distro's probed version,
now asked for opencode too). For 2.x magpie writes `providers.magpie` in
OpenCode 2's shape (openCodeNative), `agents.title.model`, and no
`reasoning`. A file written for OpenCode 1 moves over on the next sync:
openCodeFromV1 ports migrateStandardProvider (v2.2.6) so the user's keys
in magpie's provider (headers, timeout, setCacheKey, their own variants,
limit.output) go along; an empty `provider` is dropped; a small_model
that isn't magpie's stays. OpenCode 1, or an unknown version, gets the
same output as before. OpenChamber writes the same file and takes the
same decision, so the two syncs don't undo each other. mimocode, DevEco
Code and Air keep OpenCode 1's words.

Run:
- gofmt; go vet ./internal/agent for darwin, linux (-tags nogui) and
  windows (mote): clean.
- go test -count=1 ./internal/agent on mote: ok, at the rebased head.
- win-run go test -run 'OpenCode|OpenChamber|WSL' ./internal/agent: ok.
- Real binaries on mote, sandbox HOMEs, `opencode debug config
  --print-logs`: the file magpie now writes for OpenCode 2 loads in
  OpenCode 2.2.6 with no WARN/ERROR, and resolves (model, agents,
  providers) exactly as 2.2.6 resolves the OpenCode 1 file it replaces;
  the OpenCode 1 file loads in 1.19.5 with no WARN, small_model and
  reasoning intact. The old file in 2.2.6 still shows the reasoning WARN.

Broken by hand:
- openCodeTwo always false: TestOpenCode2WritesItsOwnWords,
  TestOpenCode2MovesAnOpenCode1File, TestOpenChamberAndOpenCode2AgreeOnWords
  and TestOpenCodeTwo red.
- moveProvider not carrying the v1 block over: the move test red on the
  user's timeout.
- moveSmall off: the move test red on agents.title.model.

Not tried: a real OpenCode 1 desktop app reading a file written for an
OpenCode 2 CLI on PATH (it would see no magpie provider; 1.19.5 logs
`providers` as not representable); Air's bundled OpenCode version; a real
WSL distro with OpenCode 2.
2026-11-10 14:52:01 +08:00
yetone 6bc5702cd4 agent: magpie's OpenCode provider sets setCacheKey, so OpenCode sends its session's prompt_cache_key (#5468)
mariamatrix (#5468) and mahiro233 on Discord: magpie writes OpenCode's
magpie provider with @ai-sdk/openai-compatible and only baseURL/apiKey, so
OpenCode sends no prompt_cache_key and an upstream that caches by it misses.
Checked against OpenCode's source and real runs (sandbox HOME on mote, a
recording Chat server):
- 2.2.5: v1/config/migrate.ts maps options.setCacheKey to
  compatibility.supportsPromptCacheKey, and openai-chat.ts sends
  prompt_cache_key only then. Without it: no key; with it:
  "prompt_cache_key":"ses_…" on the turn and the title request. A config
  with magpie's provider under providers, compatibility.supportsPromptCacheKey
  true, sends it too; without, none.
- 1.19.5: setCacheKey true sends camelCase promptCacheKey (the previous
  commit sends it on as prompt_cache_key).
- 2.0.25: ignores the option; the run answers as before, no error.

Now:
- the "opencode" shape's options have setCacheKey: true. Every writer of
  provider.magpie goes through it and openCodeKept: OpenCode, its
  OPENCODE_CONFIG_DIR copies, MiMo Code, DevEco, Air's OpenCode and
  OpenChamber's.
- openCodeNative writes it as OpenCode 2 does: compatibility
  .supportsPromptCacheKey, not a setting.
- a setCacheKey the file has already under provider.magpie.options, or a
  supportsPromptCacheKey under providers.magpie.compatibility, is the
  user's (false too) and stays, through a sync and a pick.
Kilo has no wiring in magpie; no other agent's config has this option.
TestAirProviderWritesKeepCustomFields compared every option as a string;
it now compares a bool as its JSON.

Run on mote: go test ./internal/agent (full package) ok; go test -run
'OpenCode|CacheKey|Air|OpenChamber|Deveco|Mimo|KeepTheir' ./internal/agent
./internal/gateway ok; go vet on darwin, GOOS=linux, GOOS=windows; go
build ./... (darwin, windows); gofmt clean.
Broken by hand, each failing TestOpenCodeSetsCacheKey: no setCacheKey in
the shape ("no setCacheKey"); no keep under provider ("the user's false not
kept"); no keep under providers (same); no move out of settings
("setCacheKey in OpenCode 2's settings").
Not tried: a config written by a running magpie fed to a real OpenCode
(the real runs used configs of the same shape, written by hand); a real
upstream's cache hit rate before and after.

Reported-by: mariamatrix
Reported-by: mahiro233
2026-11-06 15:02:53 +08:00
JoeyWu-techandyetone 0ed9891de0 agent: magpie's provider under OpenCode 2's providers is kept current (#3883)
Murciee (#3883, OpenCode 2.1.4 as OpenChamber bundles it, Windows): a
model added in magpie never reached OpenCode 2, though magpie said it
was exposed. ~/.config/opencode/opencode.json held magpie's provider
twice, provider.magpie with 43 models and providers.magpie with 38, and
opencode models listed the 38. OpenCode 2 keeps a provider under
providers, in words of its own, and still reads OpenCode 1's provider:
a provider named under both is the one under providers, whole, and the
other only a WARN in its log, "retained native value over legacy value"
(packages/core/src/config/normalize.ts, mergeMaps, at v2.1.4).
OpenChamber's provider form saves a provider under providers and takes
it out of provider (packages/web/server/lib/opencode/config-v2.js,
writeSectionEntry). Once it had saved magpie's, magpie's next sync put
provider.magpie back, as a model of magpie's was picked, and from then
on brought only that one up to date.

Where an OpenCode config keeps magpie's provider under providers, each
sync and model pick now write it there too, and the wiring check reads
it there (opencode_providers.go). It is written as OpenCode 2 reads
magpie's provider.magpie (packages/core/src/v1/config/migrate.ts,
migrateStandardProvider and migrateModel): npm as package
"aisdk:<npm>", options as settings, a model's modalities as
capabilities beside tools, its variants a list of {id, settings, body}
with the options OpenCode 2 reads itself in settings and the rest in
body (provider-options.ts, COMPATIBLE_KEYS: a fast variant's
service_tier), and reasoning, which it doesn't read, left out. As under
provider (theirsKept, openCodeKept), magpie's models are written whole,
a key of the user's in the block stays, and so does a variant the user
put on a model of magpie's. A variant is magpie's when it says what
magpie's of its name says, split as OpenCode 2 splits it or all in
settings, as OpenChamber carries one over from provider
(toModelVariants). A config without providers.magpie doesn't get one:
provider.magpie is still what magpie writes, and OpenCode 1 and 2 both
read it. Taking magpie out of OpenCode or OpenChamber takes out both
blocks, as OpenChamber's own delete does. agent-wiring.md says so
beside #2379's variants.

Old data: a config already in the reporter's state is brought up to
date by the next sync, which SyncCatalog runs over every agent at each
start and update of magpie. A providers.magpie an older magpie left
behind when taking magpie out (it took out provider.magpie alone) is
kept up to date from now on, and goes the next time magpie is taken
out.

Not changed:
- Air: its magpie-opencode.json is magpie's own and holds
  provider.magpie alone. With OpenChamber's providers.magpie in the
  global config and nothing else of magpie's there, OpenCode 2.1.4
  handed Air's file as OPENCODE_CONFIG still listed the model only
  Air's file had.
- MiMo Code and DevEco Code go through the same code. Their configs
  hold no providers block unless something of theirs writes one; not
  checked against their source.
- A provider of the user's own at magpie's gateway kept under providers
  isn't read by openCodeSpelled and ownGatewayProvider, which read
  provider alone: #3915, filed with this.
- What else OpenChamber's form puts on a model of magpie's under
  providers (a modelID, a cost) goes with the rest of the model at the
  next sync, as a key on one under provider does today.

What was run (tree 61b3fff7, on origin/main e056779a, go1.26.8,
linux/amd64, Linux 5.15), outside graftcp, umask 077:
- TestOpenCodeNativeIsOpenCode2s, new: openCodeNative of a block with
  levels, fast variants, an image model and one without levels is what
  OpenCode 2.1.4's opencode debug config printed under providers.magpie
  for that block in an opencode.json (its apiKey, shown as ***, put
  back).
- TestOpenCodeProvidersKeptCurrent and
  TestOpenChamberProvidersKeptCurrent, new: a config as OpenChamber's
  form leaves it, provider.magpie gone and providers.magpie from before
  think/new (a stale baseURL and key, a header and a timeout of the
  user's, a modelID, magpie's variants of levels deep no longer has,
  one of them in OpenChamber's form, one the user wrote over, one of
  their own, and a model the catalog dropped). A sync, and a model
  picked, bring it to the models under provider with the user's keys
  and two variants kept; a second sync writes nothing; stepping off
  magpie takes out both. A config without providers gets none.
  TestOpenCodeCheckReadsProviders, new: a providers.magpie at another
  address is off until a sync.
- The 21 tests named TestOpenCode*, TestOpenChamber* and TestDevEco*:
  ok. -race -count=5 over the four new ones: ok.
- Broken by hand, one at a time, each red where it says: no sync under
  providers in OpenCode's Sync, in a pick, in OpenChamber's Sync; no
  delete there for OpenCode or for OpenChamber; the check reading
  provider alone; no theirsKept; the user's variants dropped; no
  variant taken for magpie's; only OpenCode 2's split taken for
  magpie's (OpenChamber's high-fast stayed); providers written into a
  config without it; a write on every sync; every option in settings;
  no capabilities. The sync, pick, delete and check breaks at once,
  which is what e056779a does: three of the four new tests red.
- The reporter's case with the real binaries, in a sandbox HOME: magpie
  at e056779a wired OpenCode to think/deep; OpenChamber's own
  toProviderEntity (openchamber main 6b48aecb, its zod import stubbed
  so the module loads) turned that provider.magpie into the
  providers.magpie its form saves, and provider.magpie was taken out,
  as its form does; think/new was added, and magpie at e056779a synced.
  OpenCode 2.1.4's opencode models (npm @opencode/cli-linux-x64,
  integrity checked) listed magpie/think/deep alone, and its log had
  two "retained native value over legacy value" lines. The same file
  synced by this commit: magpie/think/deep and magpie/think/new, no
  such line, and a second sync left the file as it was, mtime too.
- go test -tags nogui -count=1 -timeout 45m ./... (log kept), Bun
  1.4.2: 69 packages ok and 7 red, none in what this changes; in
  internal/agent every test this adds or touches passes. The reds: agent
  TestFolderVarsAreListed (#3884, main's CI red), TestInstalledVersion,
  TestCursorFolderFromTheEditorIsNotTheCLI,
  TestCopilotFolderFromAnIDEPluginIsNotTheCLI,
  TestQoderSettingsFromAnIDEPluginIsNotTheCLI, TestOmpDetectedWithPiDir
  and TestZedAppPath (#3141: alone at -count=40, TestZedAppPath is red
  37 and 35 times at e056779a, 35 and 38 here),
  TestReasonixCLIRequiresSupportedNativeVersion and
  TestReasonixCLIRecoversAfterProbeTimeout (#3641); davsync TestSync
  (#3420: alone at -count=20, red 3 times at e056779a and 2 here); edit
  TestWriteAtomicReadOnlyHardLink and testenv TestProgram (umask 077,
  #3640); gateway TestPluginToldWhereTheAgentWorks (#3675); gui
  TestGatewayHeldByAContainer and TestGatewayFixQuitsOnlyAMagpie
  (#3649); provider TestCodexAppServersOnHome (#3906, main's CI red),
  then "close of synctest channel from outside bubble" from
  TestUnreadLoginsWriteErrorsKeepCredentials (#3632, main's CI red).
- gofmt -l clean. go vet -tags nogui and go build -tags nogui for linux,
  windows and darwin, and go vet and go build for windows without the
  tag: exit 0 each. go vet and go build without the tag on linux: exit 1
  (this box has no GTK or WebKitGTK dev packages).

Not tried: Windows, the reporter's system, and OpenChamber's app
itself: its converter alone was run.

Ported onto main by yetone. Since this was written, cdd470ce9 (#4575)
made the models of magpie's provider under provider an ordered list
(orderedJSON) instead of a map, so the block under providers came out
with no models at all (TestOpenCodeProvidersKeptCurrent and
TestOpenChamberProvidersKeptCurrent red on main with the patch as it
was), and #4575 added a model's cost. openCodeNative now reads that list
and writes the models under providers in the same order, and a cost in
OpenCode 2's words: a list of tiers, cache prices under cache
(migrateModel's costs in packages/core/src/v1/config/migrate.ts).
OpenCode's source read at v2.1.4 (68bc26b7) and v2.2.5: in both,
normalize.ts merges provider into providers (mergeMaps), and a name
under both is the one under providers, taken whole, so the fix holds
on the current 2.2.x too. TestOpenCodeNativeKeepsOrderAndCost is new,
and providersCurrent checks the order.

Run for the port (mote-run, macOS, go1.26.8): go test -tags nogui
-count=1 -run 'OpenCode|OpenChamber|MiMo|DevEco|Spelled|Wiring'
./internal/agent: ok.

Batch run, at tree 104d75f0a (the twelve coffemon ports together, on
origin/main 7d022bdb6), mote, macOS, go1.26.8:
- go test -tags nogui -count=1 -timeout 45m on the packages the batch
  changes (agent, autostart, daemon, gateway, library, proc, provider,
  sessions, testenv, tui, gui): ok each.
- GUI, node --test with Playwright 1.62.0, Chromium and WebKit:
  library-*.test.cjs and i18n-keys.test.cjs, 1044 of 1044 pass.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... and go build ./...: ok at cdd7c8e46, the same
  batch on origin/main 00098f12b one rebase before.
- The whole go test ./... at cdd7c8e46: 86 packages ok, one red,
  internal/cli TestEveryRouteHasACommandOrIsNamed (GET
  /api/context/reply has no command), red on main too (#5026).
- Linux (wsl-run, Ubuntu 24.04, at 339055896, the batch on f4c664a09):
  proc, autostart, testenv, tui ok; agent: only TestGrokInstalled red
  (#3548); #4033's proc.Look reds (Zed, Copilot, Qoder, Cursor, Omp)
  pass.
- Windows (win-run, Windows 11, at 339055896): proc, autostart, testenv,
  tui ok; library and agent red in the same tests as on origin/main
  f4c664a09 (#4115, #1827, #4786; #5068, #5069, #5070 filed now).
- Rebased onto origin/main fb1f4856a (three commits, no file in
  common with the batch) and run again at the pushed tree: gofmt -l
  nothing, go build ./... and go vet ./... ok; go test -tags nogui
  sessions, agent, autostart, tui, proc, testenv ok; i18n-keys and
  library-* 1044 of 1044 pass.
- Not run before the push: the whole GUI suite (a run at cdd7c8e46 was
  cut off at 1170 of ~1174 tests when mote rebooted; it runs again after
  the tag and any red is filed).

Co-authored-by: yetone <9rqwv2ak@gmail.com>
2026-11-03 20:38:11 +08:00