Commit Graph
131 Commits
Author SHA1 Message Date
yetone 087985c778 usage, gui: a Codex turn of one call too short to time tells its whole-turn floor only at 1,000 tokens or more, as Claude Code's does (Fallmonkey on Discord)
Fallmonkey's report: an 11-token gpt-6-astra answer in 2.75 s, too short
after its first token to be measured, showed "≥4 tok/s" from the
whole-turn fallback (def3a41e3), while an 815-token Claude Code reply,
told by the same formula (all output over the whole time, the wait for the
first token in it), showed nothing, because that floor needs 1,000 tokens.
The gate now follows the formula: a Codex turn of one call that is neither
measured nor tells its answer's floor (the answer over the time after the
first token, still held to 1 s and 100 tokens) tells its output over the
whole turn only when that is 1,000 tokens or more over a second or more,
the rule every other whole-time floor has (Row.Floor; app.js ledFloor_).
Under that, the wait is too much of the time to tell anything.

Changed: internal/usage/ledger.go (Row.Floor drops the Codex-only
any-size fallback and falls through to the shared 1,000-token rule),
internal/gui/assets/app.js (ledFloor_ the same), docs/reference.md.

Tests:
- TestCodexWholeTurnFloorNeedsAThousandTokens (new): Fallmonkey's 11
  tokens in 2.75 s tell no floor, as Claude Code's 815 in 18 s; 1,000 in
  12 s tell one for both. TestCodexRowsTellAFloor and
  TestCodexTurnMeasuredOnlyOverASecondAndAHundredTokens updated (380 in
  7 s, 496/224 in 11 s, 60, 99, 400 tokens now tell none; 1,200 and 1,300
  token one-push turns and a 1,000-token one at 999 ms still do).
  With the old ledger.go: FAIL, "astra's 11 tokens over 2.75 s: floor
  11/2750 ms, want none", and 8 more cases in the two older tests.
- usage-speed-count.test.cjs: the 496-token and 380-token rows and
  Fallmonkey's 11-token astra row show "—", a 1,200-token one-push turn
  "≥120 tok/s" with the whole-turn tooltip; in en, zh, zh-TW, ja, de at
  five widths. With the old app.js: FAIL "496 tokens over the whole turn
  tell nothing".

Ran: go test -tags nogui ./internal/usage; gofmt -l; go vet (darwin,
GOOS=linux -tags nogui, GOOS=windows) on internal/usage; GUI suites
usage-speed-count, reasoning-speed, usage-ledger-detail, usage-ledger-fit,
usage-ledger, usage-session-speed, usage-speed, usage-sum-whole,
panel-usage, i18n-keys in Chromium and WebKit. No strings changed. Not
tried on Fallmonkey's own session files.
2026-10-13 12:08:10 +08:00
yetone e528aeb3ce agent: DevEco Code, Huawei's OpenCode, as an agent (#1885)
foobra asked for DevEco Code (npm @deveco/deveco-code), Huawei's
HarmonyOS coding agent. It is OpenCode underneath, so it joins through
openCodeLike as MiMo Code did (03a01a548):

- Config in ~/.config/deveco. magpie writes the first of deveco.jsonc,
  deveco.json, config.json there (the one DevEco reads last wins its
  merge), or DEVECO_CONFIG_DIR when that is an absolute folder; agentenv
  carries DEVECO_CONFIG_DIR. Auth at ~/.local/share/deveco/auth.json.
- Its provider block carries the key magpie-deveco, not the plain one.
  0.2.3 sends "deveco/0.2.3 ai-sdk/provider-utils/4.0.23 runtime/bun/1.4.2"
  on chat, but parts of its code still send opencode/<version>, so the key
  keeps its usage DevEco's whichever it sends. Check flags the plain key,
  and Sync writes DevEco's back. OpenCode's own key is unchanged.
- The user's own provider, small_model, $schema and comments stay; the
  model they were on comes back on Disconnect.
- Library: AGENTS.md instructions (with the "reads Claude Code's
  CLAUDE.md" note, as OpenCode and MiMo Code), MCP in OpenCode's shape,
  skills. No WSL folder.
- Install/update: npm @deveco/deveco-code on macOS and Windows only, as the
  package has no Linux binary (new cliSpec.only); the self installer under
  ~/.local/share/deveco/versions updates with `deveco upgrade`.
- Icon: DevEco's own logo, byte for byte from its IntelliJ plugin's
  pluginIcon.svg. Model picker /models. Route hue, READMEs (en, zh), site
  agent lists (en, zh, ja), docs/reference.md, subsystem pages, CLI help.

What was run
- gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
- go test -tags nogui: internal/library, agentenv, proc, cli, gui, usage
  pass; internal/agent passes in 559s with -timeout 40m;
  its first run, at the default 10m with load average ~40 from other
  sessions, was cut off by the timeout (no test had failed).
- New deveco_test.go: config lookup and DEVECO_CONFIG_DIR, the key, and
  Connect/Check/Sync/Disconnect against a deveco.jsonc holding the user's
  own model, provider, small_model, $schema and a comment. Made
  openCodeKeyAt return the plain key by hand: TestDevEcoKeyNamesIt and
  TestDevEcoConnectKeepsTheUsersOwn go red.
- GUI: new library-deveco.test.cjs (the note in en, zh, zh-TW, ja, de,
  and the icon draws), chromium and webkit; red with deveco taken out of
  library.js's note. library-instr-sets, library-instr-busy,
  panel-routing, agent-connect, library-desktop-skills, getting-started,
  filter-ime, routing-account-identity pass in both engines.
- Real use, sandbox HOME: npm-installed @deveco/deveco-code 0.2.3,
  `deveco auth consent --accept` (sandbox only, no Huawei sign-in). magpie
  serve on 127.0.0.1:3592 with a fake upstream; `magpie deveco fake/fake-1`
  wrote provider magpie (magpie-deveco, http://127.0.0.1:3592/v1) beside
  the user's own and kept the file's comment; `deveco run "Reply with one
  word: ping"` answered from the fake, and `magpie usage today` counted it
  under DevEco Code. The User-Agent above is what it sent.

Not tried
- Windows, and DevEco Studio's plugin mode; a Huawei-signed-in DevEco.
- `magpie deveco <model>` then `magpie deveco default` doesn't bring back
  the model the user was on before: the CLI set path doesn't stash. It is
  the same for OpenCode today; Connect/Disconnect in the GUI does.

Reported-by: foobra
2026-10-13 10:57:32 +08:00
yetone b0e3177d9d provider: Ollama Cloud shows its plan's included allowance and its bought credits in Usage and magpie quota (#1888)
What: an ollama-cloud key (any provider whose base is on ollama.com) is
read at GET https://ollama.com/api/balance with Authorization: Bearer
<key>. included.{balance_usd, allowance_usd, period} becomes a plan card
(PlanQuotas, planQuotaSourceOf) with one window in USD: spent of the
allowance, named Month when the period is a month long, resetting at
period.until. purchased.balance_usd becomes the key's balance card
(KeyBalances, balanceSourceOf). Routing weighs the key by that window as
it does other plan keys (keyWindows), and the window is Aside while bought
credits are left, since spending past the allowance draws on them.

Absent fields are unknown, never $0: no included, no allowance, an
allowance of 0 or no balance_usd gives no window (and, as for MiniMax and
Command Code, no plan card); no purchased gives no balance card (new
errNoBalance, which KeyBalances leaves out instead of showing an error);
null period gives a window with no reset. A reply with neither object
says its shape. A refused key's balance card says Ollama's reason.

Why: #1888 asked for Ollama Cloud's balance and plan quota beside the
other key-bought plans.

Run:
- go test ./internal/provider -run 'Ollama|TestPlanQuotaSource|TestBalanceSourceByHost|TestKeyBalances'
  in a sandbox HOME: pass. Broken by hand five ways, each red:
  no ollama.com plan source (TestOllamaCloudCards, TestPlanQuotaSource),
  missing purchased read as $0.00 (TestReadOllamaBalanceMissing,
  TestOllamaCloudCards), KeyBalances not skipping errNoBalance
  (TestOllamaCloudCards), missing included.balance_usd read as 0
  (TestReadOllamaBalanceMissing: a $20 allowance shown 100% used), Aside
  dropped (TestReadOllamaBalance).
- The built binary in a sandbox HOME with an ollama-cloud provider and a
  fake key: `magpie quota` asked the real ollama.com and showed
  `ollama-cloud balance 401 Unauthorized: {"error":"invalid credentials"}`,
  no plan card.
- gofmt -l, go vet (darwin), GOOS=linux go vet -tags nogui, GOOS=windows
  go vet, go build for darwin, linux (nogui) and windows: clean.
- go test -tags nogui ./... in a sandbox HOME at load ~27: 48 packages
  ok; internal/agent and internal/gateway hit the 10m timeout, and in
  gateway TestIntentClassifierGroup (#1813, 3.63s against its 3s bound)
  and TestHistoryKeepsDaysAndDropsOld (filed #1892) failed. Rerun with
  -timeout 40m both packages pass (1032s, 1138s). Neither package reads
  ollama.com or these readers.

Not tried against the real API with a real key: the owner's magpie has
no ollama-cloud provider, so the fixtures are the issue's literal JSON
and the free-plan and missing-field shapes are guesses from it. Whether a
spent allowance really falls through to bought credits (Aside) is not
verified either.

Reported-by: yangmingyuan380
2026-10-13 10:53:25 +08:00
congee949 b6831d83e1 gateway, gui: Codex's thread descriptions go to a model picked in Settings, apart from its titles (#1198, congee949)
Codex asks its own model, through its ChatGPT sign-in, for each thread's
description (thread_description), even while the conversation runs on
magpie's models. Settings › General gets "Codex thread descriptions"
beside "Codex thread titles". It defaults to Codex's own, which sends the
request as Codex sent it, or it can name one of magpie's models or a
routing group. The answer is wrapped as description-only JSON. The titles
setting is untouched. Usage and Routing show these requests under their
own Description purpose. The setting is kept across unrelated Settings
saves. There is no Off yet, because Codex's handling of an empty
description hasn't been checked. This is a first slice of #742.

Squashed from the PR and merged onto current main. Conflicts resolved:
- codex_backend.go: the description branch comes after the title branch,
  ahead of main's subagent pick.
- gateway.go: main's CC Switch #1301 comment above the compaction block is
  kept; the PR had shortened it.
- app.js: the gateway-mode list of hidden rows takes the new row.
- i18n.js and settings_keep_test.go: both sides kept.
- purposes.js: regenerated with go generate ./internal/usage.

Run on the merged tree:
- gofmt -l is clean.
- go vet passes on darwin, linux -tags nogui and windows; the builds on
  all three succeed.
- go test -tags nogui passes for ./internal/gateway, ./internal/gui,
  ./internal/settings and ./internal/usage.
- GUI, chromium and webkit: codex-titles, gateway-mode, purpose-filter,
  routing-purpose-state, gui-de, gui-ja, gui-zh-tw, i18n-keys,
  settings-general/-groups/-sections/-search and click-scroll: 118/118.

Broken by hand: with the description branch removed from codexBackend and
handle, TestCodexDescriptionsSetting, TestCodexDescriptionFallbackOnMagpie
and TestNoDescription fail.

Not tried: a real Codex thread_description request, and whether Codex's
sidebar takes the answer.
2026-10-13 10:13:15 +08:00
wei 4419ebf7d6 cli, agent: magpie <agent> <field> shows that field and a field's name or DEFAULT is no longer written as the agent's model (#1129, waitingsnow)
What: `magpie codex model` wrote model = "model" into config.toml (and
applied.json, stash.json); any agent's field name given alone, or as a
value, was set as its model, and `magpie codex DEFAULT` wrote
model = "DEFAULT". Now:
- `magpie <agent> <field>` (any case) prints that one field and writes
  nothing;
- a field's name given as a value is refused with a hint
  (`magpie claude effort Ultracode`);
- DEFAULT in any case takes magpie out, as `default` does;
- Claude Code's tier names (opus/sonnet/haiku/fable) still set the model,
  since agent.ModelAliases marks them, and the agent's help says so.
agent.Field matches key and label in any case; agent.Running is a var
so the cli tests can say Codex isn't open.

Why: ported from waitingsnow's #1129 (commits bbe75c91f, 00bb38581,
244b24a67) onto internal/cli, where the CLI moved after the PR was
opened. The PR's --help part landed earlier as 76db4c6c2 (#1457).

Run: the five new internal/cli tests fail on origin/main without the
cli change (TestAgentFieldNameShowsIt: "✓ Codex model model" and
model = "model" written; TestAgentDefaultInAnyCase: "✓ Codex model
DEFAULT"; the tier-name help line and the Ultracode hint missing) and
pass with it. gofmt -l clean; go vet darwin, GOOS=linux -tags nogui,
GOOS=windows clean; go build for all three; go test -tags nogui ./...
green (an earlier run's internal/agent 10m timeout was a stuck open()
in TestWSLStoppedDistro under a 100%-full disk and load ~44; the WSL
tests pass alone and the full rerun passed).
2026-10-13 09:47:25 +08:00
yetoneandMonkeyLeeT dfbe001ff9 usage, gui: re-land def3a41e3, a Codex one-call turn timed only over a second and 100 tokens after its first token
2c30e5cee held def3a41e3 back "until Fallmonkey says what context it
missed". Fallmonkey answered on Discord: no objection, ship it. This
reverts the revert. app.js conflicted with aabdd6126 (larger sample
first); the resolution keeps aabdd6126's first_text_ms > 0 guard on the
reasoning check and adds back the Codex window check below it.

Run: go test -tags nogui ./internal/usage; usage-speed-count (52),
usage-speed, usage-ttft-rounding, i18n-keys green in chromium and
webkit; gofmt -l clean; go vet darwin, linux nogui, windows.

Reported-by: Fallmonkey (Discord)
Co-authored-by: MonkeyLeeT <MonkeyLeeT@users.noreply.github.com>
2026-10-13 09:10:14 +08:00
yetoneandMonkeyLeeT aabdd6126a gui: a model's speed leads with the figure from more replies, counts written out, TTFT on its own line
Fallmonkey (Discord) read "75 tok/s (3) · ≥54 tok/s (289)" on the Output
speed card and the Usage ranking as the 3-reply figure being the model's
speed, with the 289-reply floor tucked behind it, and "(3)" not saying
what was counted.

Now, everywhere a group's speed shows (the Output speed card, the
overview lists and the Usage ranking by speed):
- the figure from more replies comes first and is the big one; a tie
  keeps the measured one first. The ranking orders and bars by it.
- counts are written out, without parentheses:
  "≥54 tok/s · 289 replies; 75 tok/s · 3 timed replies"
  zh "≥54 token/秒 · 289 次回复;75 token/秒 · 3 次计时",
  with zh-TW, ja and de strings of their own.
- on the card the second figure is its own line, and the average wait
  for the first token is a line of its own with its count
  ("first token in 1.2 s on average · 3 timed replies"), wrapping rather
  than cut off. In the big figure the count is a muted caption without
  the dot, so a wrapped count never starts a line with "·".
- the tooltips are unchanged; the threshold for the floor is unchanged.

What was run:
- usage-speed and usage-ttft-rounding now expect the TTFT line's
  count; green in both engines.
- usage-speed-count.test.cjs (rewritten for the new rule) in Chromium
  and WebKit, 5 languages x widths 1400/983/789/700/560: 26/26 each.
  On origin/main's assets it fails ("125 tok/s (1) · ≥50 tok/s (259)").
- 55 related suites (usage-*, ledger-*, reasoning-speed, routing-*-speed/
  metrics, panel-usage, gui-de/ja/zh-tw, i18n-keys, click-scroll,
  tray-usages) in both engines: all green.
- gofmt -l, go vet darwin, GOOS=linux -tags nogui, GOOS=windows on
  internal/gui; go test -tags nogui ./internal/gui: ok.
- Screenshots of the card and ranking at 560 and 1400 in en, zh, de.

Reported-by: Fallmonkey (GitHub MonkeyLeeT)
Co-authored-by: MonkeyLeeT <MonkeyLeeT@users.noreply.github.com>
2026-10-13 08:19:28 +08:00
yetone d4c2512d2d usage: apps report their own calls with POST /v1/magpie/usage/requests, backfill included (#1874)
What changed
- POST /v1/magpie/usage/requests (internal/gateway/usage_ingest.go) takes
  one record or an array, in usage.jsonl's shape:
  - the post may carry up to 5000 records and 32 MiB;
  - t, agent, provider, model and rid are required.
  Each field is checked: unknown fields, quoted numbers, negative or absurd
  counts, a status outside 100-599, a cost over 10000 USD, and a t more
  than an hour ahead or before 2000-01-01T00:00:00Z. Any fault refuses the
  whole post with a 400 that names error.index and error.param, and nothing
  is written. A past t is otherwise taken as given, so history can be
  backfilled. The reply gives accepted and skipped counts and each
  record's index, rid and status.
- Access: lanGuard's rule (this machine, or another with a key while
  shared, behind the Host check). A browser page also needs a key, since
  corsGuard lets localhost pages and Origin null through. A held key is
  refused.
- usage.IngestReported writes under usage.mu to the same file as
  usage.Append. Rows carry source "reported" and no caller key. A rid
  already reported is skipped, as is one repeated in the post. The set of
  reported rids is read back from the log: one scan after a restart (lines
  without the reported mark aren't parsed), then only what was appended.
- Pricing: a record with cost keeps it (Record.OwnCost, the rowOwnCost
  flag; packed flags widened to uint16). Otherwise it is priced at
  magpie's prices.
- Display:
  - SourceReported is a source of its own: RequestPage.Reported,
    ?via=reported, and Ledger now honours via.
  - The Requests tab gains a fourth cell "reported by apps", shown once
    there are some, and a "Reported" badge (en, zh, zh-TW, ja, de).
- Nothing live: Record.IsReported keeps reported rows out of:
  - a key's budget/spend limit (budget.counts);
  - window holds, and the log start that decides whether a window can be
    reckoned (logSnapshot.firstOwn);
  - gateway sessions and Vias;
  - Codex's sealed answers and remembered model.
  There is no OTel span, rate limit, rest or alert for them.
- Docs: gateway-sessions.md, reference.md (with a curl), integrating.md,
  site integrate.html (en, zh).

Why: the reporter's apps call vendors directly, and their usage (and
history) should show on the Usage page without becoming live traffic.

Run, in a worktree with sandbox HOME and a private GOCACHE
- gofmt -l: clean.
- go vet ./...: darwin, GOOS=linux -tags nogui, and GOOS=windows.
- go test internal/usage, usageapi, budget, gateway, gui: ok.
- -race -count=3 of the new usage/gateway tests: ok.
- GUI with playwright 1.62.0:
  - usage-ledger-reported.test.cjs, 26/26 in chromium and webkit (5
    languages, 1180 and 420 wide, light and dark);
  - usage-ledger*.test.cjs, ledger-*.test.cjs, usage-sum-whole,
    usage-unpriced-sum and i18n-keys: all pass.
- Timings with 200k reported rows (47 MB log, darwin):
  - 40 posts of 5000 took 0.40 s (worst batch 18 ms);
  - the first post after a restart took 0.45 s (rid rescan), a later one
    1.6 ms;
  - the cold index build took 2.1 s (as for gateway rows);
  - page all took 27 ms warm, page 30d 39 ms, all via=reported 0.53 s;
  - summary all took 215 ms, 30d 20 ms.

Broken by hand, each went red, then restored
- Go: dedupe against stored rids; the restart scan; CostAt ignoring own
  cost; the block pricer overwriting own cost; the Reported split;
  fromBrowser's key rule; skipping bad records instead of refusing; the
  max-records and body limits; the ingest lock (race); both locks;
  firstOwn -> first; the IsReported guards in windowHolds,
  buildGatewaySessions, buildVias, budget.counts and loggedAnswers.
- GUI: the fourth cell, the --vias column count and the badge class.

Not shown red on its own: the remote-no-key and evil.example refusals come
from lanGuard and corsGuard before the handler, so breaking only the
handler's own check stays green. The codex_memory guard is not tested
alone: a reported row has no Requested there anyway. Not tried: a real
client against a live gateway, Windows/Linux runs of the tests, the full
GUI suite.
2026-10-13 06:32:03 +08:00
yetoneandfjrtdk 1f0ff81dfc agent: Grok App's own route picked in magpie is taken, and Disconnect can put one back; a sync that isn't connected writes nothing (#1625)
Follow-up to fjrtdk's commit before this one, which this keeps: magpie never names
itself as Grok App's route.

- Set refused every own route (errGrokAppRoute) while Options still
  offered them, so the picker showed choices that only errored. It also
  broke Disconnect: when unwire leaves no route (Use set it to magpie,
  nothing stashed), Disconnect sets connect.was's route back through Set,
  got the error and stopped half done. An own route now takes magpie's
  channel out and is written as [models] default, the way picking
  another provider leaves magpie on other agents. That route can't be
  magpie, so the App's sign-in is never touched.
- Sync ran rememberRoute/releaseRoute before checking for the channel,
  so every user with Grok App installed but not connected got stash
  entries. Now it returns before them unless the channel is there or
  the route is still magpie (an older magpie's takeover to put back).
- Check again warns when the route is magpie and the channel is gone,
  which that commit dropped.
- The notice uses the App's own labels (Settings › Account, Use; ja
  「使う」, de Einstellungen › Konto / Verwenden, from grok-app 0.2.40's
  settings.nav.account and prov.useThis) and says a chat can pick
  magpie's models in its model picker (composer_prefs_set, which
  doesn't move the route).
- Sibling: rtk init has no grok agent for Grok Build either (rtk 311ebcb
  agents: claude codex copilot cursor droid gemini hermes opencode pi
  trae vibe antigravity), so Grok Build is in rtkNoHook too.

Run: gofmt -l clean; go vet ./... on darwin, GOOS=linux -tags nogui and
GOOS=windows clean; go test ./internal/gateway ./internal/agent
./internal/library -count=1 pass; node --test i18n-keys and
agent-notice-lang pass. Broken by hand: that commit's grokapp.go fails
TestGrokAppOwnRouteStays, TestGrokAppDisconnectPutsTheRouteBack and
TestGrokAppSyncUnconnected; dropping the Check branch fails
TestGrokAppSyncUnconnected; dropping rtkNoHook["grok"] fails
TestRTKNoHookGrokBuild. Not tried: the Grok App GUI itself; the config
format and behaviour are from grok-app 0.2.40's source.

Co-authored-by: fjrtdk <fjrtdk@gmail.com>
2026-10-13 05:09:18 +08:00
fjrtdk ea3d480edf agent: Grok App keeps its own route; magpie is a custom provider under Accounts, and the Library writes instructions, MCP and skills on agent-home (#1625) 2026-10-13 05:09:18 +08:00
yetone 8b9d63f58a usage: a cost total says how many calls it couldn't price, never reads them as free (#1856)
cnlove7777777-art's Kimi K3 Auto and GLM-5.3 Max calls had "no price",
and Usage's sum counted them as $0 with nothing beside it but a "+" and a
tooltip. Now every total that sums cost says the count:

- GUI: Overview's and Requests' heads read "≈$0.001+  2 calls unpriced";
  with nothing priced, the count alone (Requests showed nothing at all
  before). Overview's calls tile adds "2 unpriced". Sessions, which prices
  by model, says "1 model unpriced" in its head and cost tile. The count
  stays at every width: the narrow and .tight rules no longer hide it,
  and the head goes tight when the count would be cut, sum or not.
  "no price for these models" is no longer shown, its key removed.
- CLI `magpie usage`: "≈$0.001+ (2 calls unpriced)". TUI Usage page: the
  same after its cost.
- docs/reference.md: unpriced calls are left out, said beside the total;
  magpie doesn't guess a variant's price from a similar name.

No variant price is mapped: models.dev lists neither "Kimi K3 Auto" nor
"GLM-5.3 Max", Zhipu's "Max" is a Coding Plan tier, and -fast variants
are 1.5x their base, so a suffix strip would be a guess. The existing
per-model price override (provider editor, `magpie model price`) covers it.

Run: go test ./internal/cli ./internal/tui ./internal/gui (ok);
TestUsageSaysCallsUnpriced and TestUsagePageSaysCallsUnpriced fail with
the fix taken out. usage-unpriced-sum.test.cjs (new) passes in Chromium
and WebKit, en/zh/zh-TW/ja/de, 360-1240px, and fails 5 of 5 on
origin/main's assets. Related GUI files (every test naming usageCost,
unpriced, effective prices, usage-head or "{n} failed", plus i18n-keys,
gui-zh-tw/ja/de, number-units, text-size, usage-ledger, ledger-protocol,
usage-range, mobile-web, phone-web, view-no-sideways): 655 pass; the
WebKit text-size foot case and routing-sessions fail the same run alone
on origin/main 5c82e6880 (filed #1672, #1307). gofmt -l clean; go vet
darwin, GOOS=linux -tags nogui, GOOS=windows clean. Not tried in the
real app window.
2026-10-13 04:31:07 +08:00
yetone 2c30e5cee7 usage, gui: revert def3a41e3 until Fallmonkey says what context it missed
Fallmonkey asked on Discord (#feedback, 10-12 19:55) to hold the
single-call Codex threshold: "先别做?感觉你漏掉context了". It is not in a
release yet, so take it off main until the rule is agreed, rather than
ship a speed rule its own requester has paused.

This reverts commit def3a41e36.

Run: gofmt -l, go vet, go test ./internal/usage.
2026-10-13 04:07:30 +08:00
yetone def3a41e36 usage, gui: a Codex turn of one call is measured only over a second and 100 tokens after its first token, else told as the least it wrote over the whole turn (Fallmonkey on Discord)
Fallmonkey's repro: a Codex turn whose first token came at 6.8 s (the
model working) and the rest 0.2 s later in one network push read as
thousands of tok/s from its session file. The promised rule, now in:

- A Codex turn of one call read from its session file (source "log",
  turn TTFT known) tells a measured speed only when the window after its
  first token is 1 s or more and its body 100 tokens or more
  (usage.CodexWindowMs, CodexBodyTokens; Row.Decode, app.js ledDecode).
- The floor from e5b82cf38 for such a turn that reasoned (its answer over
  the time after the first token, "②") is held to the same threshold:
  827 ms after a 10.2 s first token no longer reads ≥329, as that window
  can be one push too.
- A turn that tells neither tells its output over the whole turn
  (Row.Floor, ledFloor_ "turn"), the wait in it, of any size: everything
  it wrote was written in that time, so it is a true floor. 380 tokens in
  6.8 + 0.2 s read ≥54 tok/s. Its tooltip says the whole turn was used and
  why, with the time after the first token (new string in en, zh, zh-TW,
  ja, de).

Gateway rows and other agents' rows keep DecodeOf as before; Codex calls
in turns of several keep the 1,000-token rule. The ledger's period sum
now adds each row after it is built (Totals.addFrom) so it uses
Row.Decode too. docs/reference.md says the rule.

Tests: TestCodexTurnMeasuredOnlyOverASecondAndAHundredTokens (new: 380
over 0.2 s after 6.8 s, 60 over 2 s, the 1 s/100 edges, gateway and
Claude rows unchanged, group, ledgerWith sum, Part) and
TestCodexRowsTellAFloor (updated cases) fail on the old ledger.go and
usage.go; the sum check fails with only the ledger closure reverted.
usage-speed-count.test.cjs: the 496/224 row now ≥45 with the whole-turn
tooltip, a 1,000-token answer over 10 s ≥100, Fallmonkey's row ≥54;
fails on the old app.js.

Ran: go test -tags nogui ./internal/usage ./internal/gui ./internal/cli;
gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows on
internal/usage and internal/gui; 50 GUI suites (usage-*, ledger-*,
reasoning-speed, routing-burst-speed, routing-request-metrics,
panel-usage, gui-de/ja/zh-tw, i18n-keys) in Chromium and WebKit: 506/507,
the one red usage-sum-whole chromium ja at 780px under load, reproduced
on origin/main 5c82e6880 and filed as #1864. On copies of the owner's
recent Codex rollouts (955 calls), 2 were turns of one call; one, 13
tokens 315 ms after a 4.3 s first token, moves from 41 tok/s to a floor.
Not tried with Fallmonkey's own sessions.
2026-10-13 03:51:38 +08:00
yetone 248a68598c gateway, provider, gui, cli: a key+URL provider may be sent the agent's own User-Agent in place of magpie's (#1851)
Every forward went with User-Agent magpie/<version>. A coding plan that
serves only the agents it names (pi, OpenCode, Claude Code…) knows them by
their User-Agent, so it turned magpie away.

What changed
- provider: PassUserAgent (passUserAgent in providers.json), off by
  default. PassesUserAgent takes it only for a key+URL provider: never a
  signed-in account, a plugin's, or a vendor whose own client magpie goes
  as (OwnClient: OpenCode, Cline, Kilo, another magpie). A copy keeps it.
- gateway: userAgentFor in forwardOnce (chat, Anthropic, Responses,
  Gemini, count_tokens) sends the inbound User-Agent unchanged where the
  provider passes it on. It sends magpie's where it doesn't, where the
  agent sent none, and on magpie's own requests (magpiesOwn: magpie/…,
  magpie-router/vision/search, the image tool's "<client> magpie-image/1",
  which is built from MCP clientInfo, not a User-Agent). magpie never
  invents another client's. The claude-cli/Codex header copies, the
  OpenCode/Cline/Kilo overrides and account signing run after it as
  before, and the user's header.User-Agent is put on at signing, so it
  wins.
- gateway: embeddings, images and videos (retrieveFrom, sendWith,
  remoteVideoContent) now stamp the same for a key+URL provider through
  stampUA, from the caller's User-Agent kept on the request ctx
  (caller.ua, withCaller). Before, they went with Go's default
  (Go-http-client/1.1). Account and remote-magpie paths are untouched.
- cli: `magpie provider set <id> user-agent=agent|magpie`, refused for a
  signed-in account; `magpie provider <id>` shows it.
- gui: the provider editor's User-Agent row, "Send the agent's own
  User-Agent", with an explanation, for a provider with a key only (the
  JSON says ownClient for presets and providers); en/zh/zh-TW/ja/de.
  The TUI only adds presets, so it has no field for this.
- docs: reference.md (provider set) and subsystems/gateway-routing.md.

What was run
- gofmt -l clean; go vet ./... on darwin, GOOS=linux -tags nogui and
  GOOS=windows.
- go test -count=1 ./internal/gateway ./internal/provider ./internal/cli
  ./internal/gui: all ok (sandbox HOME, private GOCACHE).
- TestUserAgentPassedOn covers 7 routes (messages, count_tokens, chat,
  responses, gemini, embeddings, images) x off / on / on with no UA / on
  with magpie-router/1 / on with the image tool's UA / the user's header
  with it on and off. TestUserAgentAccountUntouched: a Factory account
  with passUserAgent in providers.json is still asked as factory-cli/.
  Also TestUserAgentClaudeCodeAsBefore, TestUserAgentFor,
  TestPassesUserAgent, TestAddCopyPassUserAgent, TestProviderUserAgentPair.
- Broken by hand, each went red: forwardOnce back to magpie's UA (5
  routes red); stampUA removed from embeddings/draw (both red, seen as
  Go-http-client/1.1); PassesUserAgent ignoring accounts/OwnClient;
  magpiesOwn dropped (the internal UAs leaked on all 7 routes); the GUI
  row shown for OpenCode and Save not posting it.
- provider-user-agent.test.cjs: 60/60 in chromium and webkit, en, zh,
  zh-TW, ja, de, at 900 and 440 wide. The provider/editor/add/i18n GUI
  tests in chromium: 244/244.

Not run
- Not tried against a real coding plan that checks User-Agent, nor with a
  real agent through a live gateway. Videos have no test of their own
  (they go through sendWith, which the images test covers).
- The GUI suite was not run in full; the Windows box was not used.
2026-10-13 02:56:34 +08:00
yetone e08902e79d agent, library: Hermes Agent's folder is %LOCALAPPDATA%\hermes on Windows, and rtk's installer is told it (新v学员 on Discord)
新v学员 runs magpie on native Windows. Library -> RTK -> Hermes Agent
failed with "rtk's installer didn't add its hook to Hermes Agent:
Config: C:\Users\admin\AppData\Local\hermes\config.yaml ...". magpie
hard-coded ~/.hermes. Hermes' own default
(hermes_constants._get_platform_default_hermes_home) is
$LOCALAPPDATA\hermes on win32 (~/AppData/Local/hermes when LOCALAPPDATA
is empty) and ~/.hermes elsewhere, with $HERMES_HOME overriding it.
rtk 0.51's resolve_hermes_home knows only $HERMES_HOME and ~/.hermes,
on every OS.

What changed:
- appdir.HermesHome / HermesHomeIn / HermesDefaultIn: $HERMES_HOME,
  else Hermes' per-OS default. This is the one place that resolves it.
- agent: hermesIn (Agents-page model wiring) and hermesProfiles use it
  through place.hermesHome / hermesDefault. A WSL distro keeps
  ~/.hermes (Linux paths, Windows env not read). The Agents-page wiring
  was wrong on native Windows too: without HERMES_HOME it wrote
  %USERPROFILE%\.hermes\config.yaml, which Hermes never reads.
- sessions.HermesDir uses it, so Windows sessions are found.
- library/rtk: the hermes spec reads and writes the agent's own folder
  (a.Dir), and rtkSpec.env passes HERMES_HOME=<that folder> to
  `rtk init -g --agent hermes --auto-patch`.
- Tests resolve the folder through appdir instead of home/.hermes. New
  TestHermesDefault/TestHermesHome (appdir), TestHermesFolder (agent:
  Windows default, profiles under it, WSL unchanged), and
  TestRTKHermesHome (library, a fake rtk that behaves like 0.51).
- docs/reference.md and docs/subsystems/library.md describe the
  Windows folder and the env.

Run:
- gofmt -l clean. go vet ./... on darwin, GOOS=linux -tags nogui and
  GOOS=windows.
- darwin: go test ./internal/appdir ./internal/library
  ./internal/sessions ./internal/agent ./internal/tui.
- TestRTKHermesHome against the old rtk.go fails with the reporter's
  exact message ("didn't add its hook ... AppData/Local/hermes/
  config.yaml"), and its default subtest fails with HERMES_HOME="".
- Windows box (cross-compiled test binaries, testenv sandbox
  USERPROFILE/LOCALAPPDATA): appdir Hermes tests, agent
  Hermes|Reseat|Effort (incl. TestHermesFolder) and library Hermes|RTK
  pass. TestRTKHermesHome skips there (shell fake). The sessions binary
  failed only TestHermesMessageVisibility, because its testdata wasn't
  copied to the box.
- Real rtk.exe 0.51.0 on the Windows box: with
  HERMES_HOME=<sandbox>\AppData\Local\hermes it wrote the plugin there
  and patched that config.yaml. Without HERMES_HOME it wrote
  C:\Users\<user>\.hermes, ignoring a sandbox USERPROFILE (rtk asks
  Windows for the home folder). That confirms the cause and the fix.
  The stray folder it made on the test box was removed.

Not run: real Hermes on Windows (no install, and running hermes under
a temp HERMES_HOME rewrites the live launcher); the GUI suite; the full
go test ./... ; the reporter's own machine.
2026-10-13 00:01:46 +08:00
yetone 7d9382db23 gateway, settings: an unreadable settings.json keeps the allow list read last, or lets in only this computer, never every address
Follow-up to 7a9490638. AllowIPs read settings.Load().AllowIPs, and Load
returns the defaults when settings.json can't be read or doesn't parse with
no good backup, so for those requests the allow list read as empty and
every address was let in (fail-open). A failed read is unknown, never
empty (LESSONS.md).

- settings: LoadChecked() returns Load's settings and an error when the
  file is there but can't be read, or doesn't parse with no last good
  generation, the same cases Save already refuses. No file, or an empty
  one, is not an error. Load is unchanged and now goes through the same
  reader.
- gateway: the Settings list is read with LoadChecked. On an unknown read
  the list read last in this process stays in force; with none read yet,
  only loopback and this computer's own addresses pass, and the 403 says
  settings.json in <dir> couldn't be read. Logged once until a read
  succeeds. MAGPIE_ALLOW_IPS is unaffected. AllowIPs returns the list in
  force (the last one read on an unknown read).
- gui: POST /api/settings and POST /api/settings/allowips read with
  LoadChecked and refuse on an unknown read. settings.Save already
  refused to write over such a file, so this didn't write an empty list
  before either; the handlers now refuse before building on defaults.
- docs: reference.md and gateway-routing.md say so.

Run (darwin, sandbox HOME/XDG via the tests' own setup, private GOCACHE):
- gofmt -l on the changed packages: empty.
- go vet ./...; GOOS=linux go vet -tags nogui ./...; GOOS=windows go vet ./...: clean.
- go test -count=1 ./internal/settings ./internal/gui ./internal/gateway: ok.
- Broken by hand: allowList reading settings.Load() with no error makes
  TestAllowListUnreadableSettings fail (garbled after a read: 203.0.113.9
  got 200, want 403; never read: remote got 200, want 403 saying
  settings.json). LoadChecked never erroring on a parse failure makes
  TestLoadChecked fail ("garbled with no backup read as good") and the
  gateway test fail at its precondition.
- TestAllowIPsUnreadableSettingsNotSavedOver passes on the old GUI code
  too (Save refused already); it guards that path.

Not run: the Windows box, Linux tests, the GUI Playwright suite (no
assets changed), the full go test ./... . Not covered: an empty
settings.json with no .bak still reads as no list, matching Save, so a
file truncated to zero bytes before any second save opens a freshly
started magpie.
2026-10-12 23:38:50 +08:00
yetone 7a9490638d gateway, gui, settings: an IP / CIDR allow list for the gateway, from MAGPIE_ALLOW_IPS or Settings beside Share on local network (lc on Discord)
What changed: lc runs magpie in Docker on a public host and asked that
only some addresses reach it at all. With a list set, a request from an
address outside it is refused 403 ("magpie answers only the addresses on
its allow list ..., and this request came from <addr>: add it there to
let it in") before its gateway key is looked at, so a leaked key is no use from
elsewhere. No list is as before.
- internal/settings/allowips.go: SplitAllowIPs, ParseAllowIP (an IP or a
  CIDR range, v4 or v6; zones dropped, v4-mapped unmapped), CleanAllowIPs.
  Settings gets AllowIPs (allowIPs).
- internal/gateway/allow.go: MAGPIE_ALLOW_IPS (comma or space separated)
  sets the list in place of Settings'. The address judged is the
  connection's own (r.RemoteAddr); X-Forwarded-For and the rest are never
  believed (magpie has no trusted-proxy list; MAGPIE_TRUST_PROXY never
  reads forwarding headers, and this follows it). Loopback and this
  computer's own interface addresses always pass. An entry that doesn't
  read lets nothing in and is logged once, so a typo never opens magpie
  to every address. lanGuard checks it after the OAuth callback and
  before the rebound-Host and key checks; `magpie web` is wrapped with
  AllowGuard too.
- GUI: Settings > Network shows an "Allowed addresses" row under Share on local
  network when sharing is on, the page is open from another computer, or
  the env var is set (then read-only, saying so). POST
  /api/settings/allowips saves it, refuses it while the env var is set,
  refuses an entry that doesn't read, and refuses a list that would shut
  out the address the page itself is open from (KeepsOut). The generic
  settings save keeps AllowIPs. Strings in zh, zh-TW, ja and de.
- Docs: the Docker page (en, zh, ja) lists MAGPIE_ALLOW_IPS with a note
  that a request from the host itself arrives from the bridge's gateway
  (172.17.0.1), that Docker Desktop and rootless Docker show clients as
  one address of their own, and that behind a proxy every request comes
  from the proxy; docs/reference.md and docs/subsystems/gateway-routing.md
  describe it. The READMEs list no env vars, so they are unchanged.

Why: a gateway key is the only lock on a public host; an allow list keeps
everyone else from even trying it.

Run (machine load average 75-140 from other sessions, so the large
packages ran in slices of their top-level tests, each slice
-timeout 9m, private GOCACHE, sandbox HOME):
- New tests: internal/gateway/allow_test.go TestAllowList (allowed,
  denied, CIDR v4/v6, IPv6 literal, link-local with zone, v4-mapped,
  loopback and own address always in, on the list still needs a key,
  a typo shuts everything out, env over settings), TestAllowListServed
  (a real connection from loopback passes lanGuard under a list naming
  nothing of this computer's; a request from elsewhere is 403 naming its
  address and MAGPIE_ALLOW_IPS), TestKeepsOut; internal/settings/allowips_test.go
  TestCleanAllowIPs; internal/gui/allowips_settings_test.go
  TestAllowIPsSetting; internal/gui/tests/allow-ips.test.cjs (14/14 in
  chromium and webkit, at a 390px panel, en and zh, keys in zh, zh-TW,
  ja and de). Broken by
  hand: with lanGuard's check removed TestAllowList and TestAllowListServed
  FAIL; with KeepsOut skipped TestAllowIPsSetting FAILs; with renderAllow
  not called the GUI test has 5 failures. Restored, all pass.
- internal/gui/settings_keep_test.go gains AllowIPs:
  TestSettingsSaveKeepsWhatItDoesNotSend failed without it, as it should
  for a new field.
- go test -tags nogui: every package ok. internal/gateway (4 slices),
  internal/agent (4), internal/provider (3), internal/gui (2),
  internal/plugin (2), the rest whole. GUI Network-settings test files
  (11) 98/98 and i18n-keys ok, both engines.
- gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./... ok; linux and windows builds ok.
- Not tried: a real Docker container on a public host (the bridge note
  is from Docker's docs, not checked here); behind a real reverse proxy.
2026-10-12 23:21:41 +08:00
yetone 908c910931 gateway, gui: Stays: Strict keeps a conversation on the account or key that answered it, even past its cap, and passes its error on rather than moving it (#1797)
miniers asked that a conversation never move to another account: a
move changes the account a vendor sees mid-conversation and loses its
prompt cache. Session affinity keeps the account while it can answer,
then moves on.

The new affinity mode "strict" (Stays: Strict) does what session does
for a new conversation. Once one has an account, strictKeep asks that
account alone (its other models too) and no other account, key or
provider:
- one resting or spent is still asked, and its error (429, 402, 5xx)
  goes to the agent rather than to the next candidate;
- one over a user cap is asked past it (plan's capped candidates,
  capHeldOnly);
- one held for credits answers 429 naming Stays: Strict rather than
  moving;
- one removed, turned off, barred or not allowed for the key counts as
  gone, and the conversation is routed as usual.
A last try that fails verification is not rested for a strict
conversation that had nowhere else to go.

Set in the provider editor and the Routing page's pool row (GUI, all
five languages), `magpie groups ... stays=strict` (strict-session,
never-move), and the TUI ("stays strictly"). Documented in
gateway-routing.md, reference.md and the site's start pages (en, zh,
ja).

Run:
- go test -tags nogui ./internal/gateway (-timeout 30m under load ~150),
  ./internal/provider ./internal/tui ./internal/cli: ok. The three
  TestStrictAffinity* tests fail on the code before this commit (200
  where 429 was expected, acct-2 answering).
- GUI: stays-strict.test.cjs, chromium and webkit, 900 and 560px, en,
  zh, zh-TW, ja, de: 30 of 30. On the assets before this commit it
  fails 15 of 15 in chromium. routing-*.test.cjs pass but for
  routing-steady's webkit 1.69px shift, which fails on the old assets
  too: filed as #1804.
- gofmt -l, go vet (darwin, linux, windows), full go test ./... before
  the push.

Not tried: a real agent conversation held on a real rate-limited
account.

Known and left: planLevel doesn't merge a nested group's sub.held, as
before this commit.
2026-10-12 23:16:54 +08:00
yetone 50eeaae6ce gateway: a turn that names no reply limit is sent the model's own as max_tokens on Anthropic's API, not a flat 16384 (#1792, tensornull)
Anthropic's Messages API needs max_tokens. A request that names none
(Codex's Responses turns, a Chat client's) was always sent 16384, so a
long thinking and tool turn on a Claude-shaped relay hit the limit, and
Codex showed "Incomplete response returned, reason: max_output_tokens".

Now such a request is sent askedOutput(p, model). That is the plain
Served entry's PublishedOutput(), the same number the agents are told:
the user's Max output first, else the vendor's list or models.dev,
within the window. 16384 (defaultMaxTokens) is used only when nobody
knows the limit. A limit the client names still goes as it is. The
thinking budget is still fitted under max_tokens (anthropicBody),
whatever the limit is.

Both places that build an Anthropic body are covered:
forwardTranslated, for every translated route, and serveZed for a Zed
subscription's Claude models.

The provider editor's Max output hint now says this number is also
sent as max_tokens (en, zh, zh-TW, ja, de). docs/reference.md and
docs/subsystems/gateway-routing.md no longer say the gateway never uses
the limit.

Run:
- TestAnthropicMaxTokensIsTheModels covers: the user's 65536 (Responses
  plain and streamed, and Chat), models.dev's 64000, a 500000 limit
  held to the 100000 window, an unknown model at 16384, the client's
  own 1000, and thinking under 8192.
- TestZedClaudeMaxTokensIsTheModels expects 40000 when the client names
  no limit and 1000 when it does.
- Both tests fail on the old code: 16384 where the model's number was
  expected.
- go test ./internal/gateway/ passed (1270s, under load).
- provider-max-output.test.cjs passes 28/28 in chromium and webkit:
  5 languages at 900 and 420px. The hint names max_tokens and
  Anthropic, is translated, and doesn't overflow.
- gofmt -l is clean. go vet passes on darwin, on linux with -tags
  nogui, and on windows.

Not tried against a real Anthropic-compatible relay with a real Codex
session.
2026-10-12 22:44:26 +08:00
yetone c533499446 provider, gui, cli: a group can keep its models out of the lists agents see, offered through the group alone (#1783)
cybershape asked for a client's model list to show only a group, not
every model behind it. A provider could already be kept for routing
groups (Provider.Unlisted), but that hides the whole provider, and the
models a group names may come from providers used elsewhere too.

Group.Unlists (json "unlists"): the models a group names (a member fixed
at an effort counts as its model) and those its patterns match leave
Catalog(), so `magpie models`, /v1/models and every agent's list
(CatalogFor) show the group without them. They stay in Served(), so a
group routes over them and a request naming one as provider/model is
still answered, and Unlisted() returns them for the GUI as it does an
unlisted provider's. A nested group keeps its own setting; a group
switched off or hidden keeps nothing out. With no group unlisting,
Catalog() takes a fast path and is unchanged.

- Routing view: the group editor's "Model lists" (Its models too / The
  group alone, segmented, with a hint), saved with Save; the card shows
  "Its models unlisted". Both group Save paths send unlists. zh, zh-TW,
  ja, de.
- CLI: `magpie group set <id> listed=no|yes`; `magpie group <id>` shows
  listed: no.
- TUI: the group member picker offered Catalog(), so models kept out of
  the lists (an unlisted provider's, before this too) couldn't be put in
  a group from the TUI. It offers Served(), as the GUI's picker does.
- docs/reference.md, Routing groups: listed=no.

Product call: a per-group switch, off by default, rather than hiding
members of every group, so existing lists don't change under anyone.

Run:
- go test ./internal/provider -run 'Group|Catalog|Unlisted|Served',
  ./internal/gui, root package, ./internal/tui: ok.
  TestGroupUnlistsItsModels fails with the Catalog filter removed;
  TestMemberOptionsOfferUnlistedModels fails with the picker on
  Catalog(); TestApplyGroupPairs covers listed=no/YES/maybe.
- GUI group-unlists.test.cjs, Chromium and WebKit, en zh zh-TW ja de, at
  1100px and 420px: 20/20. i18n-keys: ok.
- gofmt; go vet darwin, windows, linux (-tags nogui): clean.

Not tried: with the reporter's own client; a real agent's model file
written after toggling (CatalogFor is covered by the test).
2026-10-12 19:38:18 +08:00
yetone 0d58ec8dcb davsync: a write a server without conditional PUTs let another go over is merged again at the next sync (#1776)
On an S3 server that refuses If-Match (Aliyun OSS answers 400
NotImplemented), put falls back to HEAD then an unconditional PUT. Two
computers writing in the moment between both pass the HEAD, both are
told they wrote, and the later file is kept. Worse, the loser's next sync
then took the winner's file as having seen its own: its st.Remote was the
file it wrote, so its changed parts looked unchanged here and changed
there, and the old parts were brought in over its own changes. The edit
was lost on the server and on the computer that made it.

- version.Blind marks a write the server didn't check (s3.go's fallback).
- state.Blind keeps, for such a write, the file's sum and the remote and
  local part hashes from before it. The next sync that reads another
  file than that one merges from before the write. What this computer
  changed counts as changed again and goes back up beside the other's.
  A 304 or the same file clears it. Restore and Upload clear it.
- docs/reference.md says what happens on such a server.

No compare-and-swap exists on OSS, so the race itself isn't closed: the
other computer's file is kept for up to one sync interval (3 minutes)
before this computer's change is merged back. The reporter's AppendObject
journal would close it but needs every computer upgraded and OSS-only
signing. If the other computer saw this one's write and then changed the
same part again, the next sync can't tell that from a write that went
over it. It counts the part as changed on both sides: the newer stays,
the other is saved, and a notice says so. Nothing is lost.

Run:
- TestS3BlindWriteGoneOverIsMergedAgain (fake S3 with no conditional
  writes, two computers): A renames a provider and B sets the theme, B's
  PUT goes over A's, then A's next sync puts both on the server with no
  conflict notice, B brings in the rename, and nothing more is written.
  With the reset taken out (broken by hand), it fails: "A's rename here
  after its next sync: \"DeepSeek\"".
- go test ./internal/davsync whole.

Not tried against real Aliyun OSS: the fake answers conditional PUTs the
way the reporter quotes OSS (NotImplemented).
2026-10-12 19:38:15 +08:00
yetone 446bffcac7 gateway, gui: a Routing row's share used renews with its own window, not the biggest one (#1778)
Vigilans' Factory account showed "32% used · renews in 27 days": the
week's 32% beside the month's reset. Allowance.For gives the fullest
window's share and the renewals biggest first, and routing.js paired the
share with renews[0], so for any account of more than one window the row
mixed two windows.

- provider.Allowance.Fullest(model, now): the reset of the window For's
  share is of (the later of two as full; a window whose reset has passed
  counts as empty, as For does).
- The trace's Weighed gains usedRenews (from weighRouted's left.fullest);
  routing.js's usedRenews(w) uses it in both the story rows and the
  account rows, and falls back to renews[0] only for an account of one
  window (a route recorded before this commit).
- Smart's order is unchanged on purpose: it goes by the biggest window,
  and Factory's month holds less than its weeks add up to, so what a week
  leaves isn't lost at the week's reset. docs/reference.md says so, and
  gateway-routing.md names Fullest/usedRenews.

Run:
- go test ./internal/provider ./internal/gateway -run
  'Fullest|UsedRenews|Weigh|Routing|Smart' and the packages whole.
- TestUsedRenewsWithItsOwnWindow fails with left.fullest set to the
  biggest window's reset (broken by hand, then restored).
- routing-key-windows.test.cjs: 44/44 in Chromium and WebKit, all
  languages and widths; it fails on HEAD's routing.js.
- Every routing-*.test.cjs plus panel-routing in both engines: 594/601.
  The 7 WebKit failures are clicks waiting for an element to be "stable"
  under load average ~44, in routing-group-fold (#1612, #1672),
  routing-sessions (#1307) and routing-days-fit. routing-days-fit passes
  run alone. The other two fail the same alone with HEAD's routing.js.

Not tried against a real Factory account: the windows are those the
Factory plugin's limitWindows reports (5h/7d/30d with resetsAt).
2026-10-12 19:38:13 +08:00
yetone bfaedf1830 gui, profile: the profile in use is ticked and named on the panel's Profiles button, not a count read as its name (superhtoooth on X)
superhtoooth (macOS): 保存方案设置了方案名字,但是应用方案没有用这个名字。
menu 里面变成了方案 1,方案 2。而且在应用里面没有显示当前使用的方案.

The bug: the tray panel's Profiles button showed the number of saved
profiles next to its label ("方案" + "2"), which reads as a profile
named 方案 2. Profiles were saved and applied under the typed name all
along; nothing anywhere said which profile was in use.

What changed:
- profile.InUse: a profile is in use while applying it would change
  nothing on this computer - every detected agent's saved field is as
  the profile has it (compared with the same renamed-ref spelling Apply
  writes), its model lists are held (provider.ModelListsHeld, a dry run
  of SetModelLists via the extracted putModelLists) and its library
  setup is as saved (library.Holds, the mirror of Restore). A profile
  that touches no agent here is not in use.
- Why not "last applied": that would stay ticked after the user changes
  a model by hand, a tick that lies. With this definition a profile
  saved from the current setup is in use at once, a hand change clears
  the tick, and applying puts it back. Two identical profiles are both
  ticked; the button names the first.
- GUI: /api/state carries inUse. The panel's button names the profile
  in use (a pop-up button showing what is picked), else counts them as
  before; its chip gets a check mark and aria-current, in panel and
  window; the chip's tooltip and its details say "In use" (string
  already in every language). CLI `magpie profiles` marks it, the TUI
  notes "in use". Docs (reference, start en/zh/ja) say so.

What was run:
- go test ./internal/profile (new TestProfileInUse: save, hand change,
  apply, hidden model list, library instructions, absent agents) and
  ./internal/gui (new TestStateProfileInUse through the HTTP handler),
  scratch HOME. Broken by hand: field compare, ModelListsHeld,
  library.Holds and state's InUse each turned a test red.
- go test -tags nogui ./... in a scratch HOME (the four slow packages
  rerun with -timeout 40m under load ~45).
- GUI: new profile-in-use.test.cjs (reporter's steps in the panel at
  360px, every language, plus the window) and panel-profiles,
  profile-confirm, profile-details, old-webkit, i18n-keys, gui-zh-tw,
  gui-ja, gui-de in chromium and webkit: all pass. Old app.js fails the
  new test.
- Real CLI in a sandbox HOME with a codex config: save/use/profiles
  show the mark, and it goes after a hand edit.
- gofmt; go vet darwin, linux (nogui), windows.
Not tried: the real tray app with real agents, and Windows/Linux at
runtime.
2026-10-12 19:14:54 +08:00
yetone ee7a9b24a6 agent: Grok App is an agent magpie connects: a magpie provider channel with magpie's models and their efforts (#1625, fjrtdk)
fjrtdk asked for Grok App (RongleCat/grok-app, a desktop GUI over the Grok
Build CLI) as a full agent: MCP, skills, RTK, models and effort.

What was already there, read in the App's source:
- MCP: the App reads ~/.grok/config.toml's [mcp_servers] in both of its
  modes and hands them to the CLI it starts, so the Grok Build row's MCP
  sync already reaches it.
- Skills: Grok Build's ~/.agents/skills, synced from the Grok Build row.
- RTK: rtk has no installer for Grok Build, so there is nothing to wire.

What was missing is models, and that is what changed:
- internal/agent/grokapp.go: a new agent, "grok-app" (alias grokapp), for
  the App's agent-home/config.toml under its data folder: GROK_APP_HOME,
  else ~/Library/Application Support/com.grokapp.grok-app or ~/.grok-app
  on a Mac, %APPDATA%\grokapp\grok-app\data (and two older places) on
  Windows, $XDG_DATA_HOME/grok-app or ~/.grok-app on Linux; the first
  that exists.
  - Connecting writes a [model.magpie] channel in the App's own format
    (its custom routes): model, base_url = the gateway's /v1, name,
    api_key (magpie-grok-app, so usage says the App), api_backend =
    "chat_completions", app_provider_mode = "generic", app_models and
    app_efforts as JSON strings (the App unquotes them with serde_json),
    supports_reasoning_effort, app_supports_vision for a model that takes
    images, and context_window when magpie knows it. app_models lists
    magpie's models with their effort levels ("none" left out), so the
    App's model and effort pickers show them.
  - It sets [models] default = "magpie"; what was there is stashed, and
    Disconnect puts it back and drops the channel: the file is
    byte-identical to before (TestGrokApp).
  - A sync keeps the model and the default effort the user picked in the
    App while magpie still serves them, and writes nothing when nothing
    changed.
  - Picking one of the App's own routes (the official "grok", or a
    channel of the user's with a base_url) takes magpie out.
  - The notice says to start a new chat or restart the App, which reads
    its providers when it starts an agent; translated in i18n.js (zh-CN,
    zh-TW, ja, de) and listed in NOTICES.
- agents.go, agentenv.go (GROK_APP_HOME), docs/reference.md,
  docs/subsystems/agent-wiring.md, both READMEs' agent lists.

Picking magpie in the App is a custom route, so the App runs that agent in
its independent mode (its own #557): it clears agent-home's auth.json
rather than syncing the official sign-in. ~/.grok is never written.

What was run:
- go test -tags nogui ./internal/agent ./internal/agentenv ./internal/gui:
  ok. Full go test -tags nogui ./... under a temp HOME: ok.
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui: ok.
- Broken by hand, each red: context_window written quoted (TestGrokApp);
  the user's picked model ignored (TestGrokAppSyncKeepsTheirs); their
  default effort dropped (SyncKeepsTheirs); Disconnect not unstashing
  (TestGrokApp); a no-op sync writing (SyncKeepsTheirs); "none" listed
  as an effort (TestGrokApp).
- Real use in a sandbox HOME: a built magpie on 127.0.0.1:3681 with a
  fake upstream; `magpie grok-app magpie/fake/echo-1` wrote the channel;
  the real grok 1.0.50, started as the App starts it on a custom route
  (GROK_HOME=agent-home, --model magpie), answered through magpie, the
  upstream saw echo-1 and usage.jsonl counted agent "grok-app". `magpie
  grok-app default` restored the file (the only difference was grok's own
  [marketplace] line written while it ran). ~/.grok/config.toml untouched.

Not tried: the real Grok App GUI (it would sign in through the keychain
and ~/.grok), a model with effort levels end to end, Windows and Linux
paths beyond TestGrokAppDir.
2026-10-12 01:55:04 +08:00
yetone cec9647a2a access: a default gateway key the user removed isn't made again when sharing is turned off and on (#1655, GradientLive)
Turning on Settings -> Share on local network makes a default gateway key
named "Magpie". A user who wants only their own, stronger key could remove
it from Gateway -> Gateway keys, but configureLAN looked for the default key
by LANKeyID, found none, and made a fresh enabled "Magpie" key the next time
sharing was turned on. That reads as a default key that is always there.

configureLAN now leaves a removed default key removed: when its id is
recorded (LANKeyID), or an older magpie dropped the id and kept only the
revoked mirror, sharing is turned on with the keys there are. Asking for a
new sharing key (newKey / rotate) still makes one, as
TestLANSettingSharesCallerKeyStore expects. A disabled default key already
stayed disabled; the test now holds that too. First-time sharing is
unchanged. docs/reference.md says so.

Run: go test ./internal/access ./internal/gui ./internal/agent (ok);
TestRemovedDefaultKeyStaysRemovedOnReshare goes red with the new check
disabled by hand (a second "Magpie" key appears). gofmt -l clean; GOOS=linux
and GOOS=windows go vet ./internal/access clean. Not tried in the real GUI.
2026-10-12 00:47:10 +08:00
yetone 6f1b432759 provider, gui: smart routing spends WorkBuddy credits that expire soonest first (cdredfox on X)
WorkBuddy's Credits window had no reset, so in a Smart group every
WorkBuddy account ranked alike. workbuddy plugin 0.1.14 (plugins f0274d6)
reads WorkBuddy's own package lists (billing/meter/get-user-resource-paid-
packages and -free-packages, the calls WorkBuddy's client makes) and reports
on the Credits window when the soonest-ending package that still has credits
ends (runsOutAt) and how many credits it holds (runsOut). The daily Free
Plan slice (CapacityType 4) and code 001 aren't counted: they renew daily.

magpie carries runsOutAt from the plugin's usage window into QuotaWindow and
the routing Limit. Allowance.Renewal, which only Smart ranks on, treats it
as the window's reset when it is sooner than the real one. Pace, the tiers,
For, Full and resting are unchanged. The mover's min is raised to 0.1.14 so
moved users get the plugin. The usage card and account meter say "232.4
expire in 5h" in every language.

Run:
- plugin: bun test, 63 pass; 2 of the 3 new tests fail on 0.1.13's
  index.mjs. Verified live on a workbuddy-ai account in a sandbox HOME:
  Bonus Pack 232.4 left ending 10-12T16:39Z ranked before Pro (10-28).
- TestWorkBuddyCreditsRunOutForRouting and
  TestSmartSpendsWorkBuddyCreditsRunningOutFirst: both fail with the
  Renewal change removed by hand.
- GUI: credits-run-out.test.cjs in webkit and chromium, 5 languages, at
  360/440/1000px, red on the old app.js; with i18n-keys, quota-*,
  panel-usage, reset-each-title, usage-fold: 117 pass.
- go test ./... green (agent and gateway rerun with -timeout 30m after the
  default 10m ran out under load from other sessions; 378s and 492s).
- gofmt -l clean; GOOS=linux and windows go vet of provider, plugin,
  gateway clean.

Not tried: the CN workbuddy site (its token was stale, 401), so the CN
package list is assumed to have the same shape. The built-in WorkBuddy
(not moved users) doesn't get this. The account-line tooltip has no GUI
test of its own.
2026-10-11 20:07:19 +08:00
yetone 642bea3a99 gui, tui, provider: Remote magpie has a heading of its own in the Add sheet, Another computer's magpie, after On this machine, not among the Relays (Avalon on Discord)
Avalon on Discord (v0.1.1168): "供应商添加中没有Remote magpie 的选项". It was
there, filed under Relays (中转), where nobody looks for another computer's
magpie, since it isn't a relay.

The preset is now of its own kind, KindRemote ("remote"), declared after the
local presets. Kind only groups presets for display: the GUI's add sheet,
`magpie presets` and the TUI's add list; makerCatalogs (vendors only) and
the import matcher (skips local) are unchanged for it, as it has no URL.
- GUI: a fourth section after On this machine, "Another computer's magpie"
  / "shared on its network" (zh 另一台电脑上的 magpie / 在它的局域网上共享,
  zh-TW, ja, de too). A preset's note is now also found in the words it is
  shown in, and the zh/zh-TW/ja note begins with 远程/遠端/リモート, so 远程
  finds it as remote and magpie do.
- TUI: the add list says "Remote magpie · another computer's magpie, shared
  on its network" instead of "· relay" (kindNote).
- CLI: `magpie presets` lists it under "another computer's magpie".
- Docs: reference.md, subsystems/providers-accounts.md and the site's
  remote page (en, zh, ja) say where the tile is.

Run:
- remote-magpie.test.cjs gains "Remote magpie has its own heading in the
  add sheet" (420px, en and zh, Chromium and WebKit): the heading and hint,
  right after On this machine, Remote magpie under no other heading, no
  sideways scroll, and remote / magpie / 远程 each find it alone under its
  heading. With the old app.js it fails "no heading of its own" in both
  engines and languages; with only the note search taken out, zh fails on
  远程. Its older test now wheels the sheet to the tile (now the last row;
  a scroll from code is put back by the page's guard, which made it flaky
  in WebKit at 700px): 8 of 8 WebKit runs green.
- TestTUIAddListSaysRemoteMagpieIsAnotherComputers fails on the old note
  with `listed as "Remote magpie · remote"` (and "· relay" before the kind).
- Every GUI test that opens the add sheet (40 files) plus gui-de, gui-ja,
  gui-zh-tw and i18n-keys, in Chromium and WebKit: all pass.
- site worker.test.mjs passes.
- gofmt -l clean; go vet -tags nogui on ., internal/provider, internal/tui,
  internal/gui for darwin, GOOS=linux and GOOS=windows.
- go test -tags nogui -timeout 40m ./... under a temp HOME: all 48 packages ok.
Not tried in the real Wails window.
2026-10-11 15:21:18 +08:00
yetone 47269f448f usage, gateway, gui: the Requests card counts requests once, a try handed on to the next isn't a failure, and says how many were answered on a retry (小一 on Discord)
小一's Codex-on-credits ledger read "5,482 · 1,094 failed" while many rows
said "2 tries/3 tries" and had been answered. "Failed" counted usage rows,
not requests: besides each request's final row, the gateway writes a row
for every try a vendor refused or turned away (hw.refused/hw.turnedAway),
and each of those was counted as a call and a failure even when a later
member answered. (Ordinary failovers write no row; 499 cancels and the
agent's own client-side retries are separate requests.) In the owner's own
usage.jsonl, 24 of the 71 "failed" rows were such refusals a later member
answered.

Now a request counts once, by how it ended:
- usage.Record gains `tries` (final row, when the route took more than one)
  and `handed_on` (the row of a try that failed and handed the request on).
  Totals.count skips handed-on rows; a failure is a request whose agent got
  an error (LostRequest); one answered after a failed try is Totals.Retried
  (RetriedRequest), with a `retried=1` filter.
- Logs written before this are read the same way: the log index marks a
  failed, non-rejected row followed by another of the same route id as
  handed on and raises the later row's tries (routeRows); the packed row
  and its snapshot carry both.
- Panel card, Usage overview tile, ledger card, rankings and group rows,
  `magpie usage` and the TUI say "N answered on a retry"; the CSV adds
  `tries` and `handed_on` at the end. A row says "· handed on" (with why
  in its title) or "· N tries".
- On the ledger's Requests card "N failed" and "N answered on a retry" are
  buttons that switch the list to the Failed / new Retried filter, and back
  when pressed again. The lines wrap rather than cut a button off (German).
  zh, zh-TW, ja, de strings added.
- Docs: reference.md (counting, filter, CSV columns), gateway-routing.md.

Run:
- go test -tags nogui ./internal/usage ./internal/usageapi ./internal/tui
  ./internal/gateway . : ok. New TestRequestsCountedOnceWithTheirRetries
  (JSONL fixture: legacy refused row + 200, handed_on + 200 tries 3, 502
  tries 2, plain 200, routeless 429 → 5 calls, 2 failed, 2 retried, across
  Ledger, QueryPage, Summarize, heatmap, filters, CSV) and
  TestRetriedRequestCountsOnce (group a refuses, b 500s, c answers → 1
  call, 0 errors, 1 retried; a lone 400 → 1 error).
- Broke each by hand (count without the HandedOn skip, gateway without
  HandedOn, log index without routeRows): each test went red; restored.
- go test -tags nogui -timeout 40m ./... under the gotest lock, rebased on origin/main de1ba9f12: all ok
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on ., the
  usage, usageapi, tui, gateway and gui packages: clean.
- Playwright ledger-retried.test.cjs, Chromium and WebKit, en zh zh-TW ja
  de, 420 and 1100 wide: 20/20 (German first failed on the cut-off line,
  fixed by letting the button lines wrap). usage-*, api-key-usage,
  purpose-filter (Failed is now the 2nd of 3 options), panel-usage,
  click-scroll, request-archive-usage, both engines: all green except
  purpose-filter's Routing case (1px focus scroll), which fails the same
  on 909d76747 and de1ba9f12, in Chromium too; it is #1291 (commented)
2026-10-11 12:58:03 +08:00
yetone 310991d78f gui: a group with measured replies and floors shows both, the measured speed first, "125 tok/s (1) · ≥50 tok/s (259)" (Fallmonkey on Discord)
A group's speed showed its measured speed when it had one and dropped
its floors. With the commits before this one, a Codex model can have
one measured reply and hundreds of floors, and "125 tok/s (1)" stood
for all of them. Fallmonkey asked to see both.

ledGroupSpeed now joins the two, the measured one first:
"125 tok/s (1) · ≥50 tok/s (259)". Its tooltip has a line for each,
and the measured line drops "the others tell no speed" when the others
tell a floor (new strings in zh, zh-TW, ja and de). The Output speed
card keeps the measured speed as its figure, so a narrow card isn't
clipped, and puts the floor in its sub line. A ranking by speed still
orders and bars a group by its measured speed, or by its floor when it
has none. docs/reference.md says so.

Tests: usage-speed-count.test.cjs adds floors to sol and a new
measured-only group (astra, 62). It checks the joined text and the two
tooltip lines, the card's figure and sub line, and the ranking order
and bar, in en, zh, zh-TW, ja and de, in Chromium and WebKit, at 1400
and 560 px, with no clipping. It fails on the old app.js.

Ran: usage-speed-count, usage-session-speed, usage-ledger-detail,
usage-speed, reasoning-speed, usage-ledger-fit, usage-model-at-provider,
routing-request-metrics, gui-ja, gui-de, gui-zh-tw and i18n-keys in
both engines; go test ./internal/gui; gofmt -l; GOOS=linux/windows go
vet.
2026-10-11 12:49:27 +08:00
yetone e5b82cf38a usage, gui: Codex rows tell the least they wrote at: a call in a turn of several over its whole time, a turn of one call that reasoned by its answer after the first token (Fallmonkey on Discord)
Codex's session rows told no floor. A call in a turn of several could be
timed from inside itself; the commit before this one times it from what
asked for it, before its first output item, to its last, as Claude Code's
is. So Codex joins usage.FloorAgents and app.js's LED_FLOOR_AGENTS, and
such a call tells its output over its whole time, by the same 1,000-token
rule. On 622 stripped recent rollouts only 4 of 1,367 such calls have
1,000 tokens or more, so the floors will be few, but they are true.

A Codex turn of one call that reasoned has its first token (the turn's
time_to_first_token_ms) but not its first text, so DecodeOf tells no
speed. Fallmonkey asked for its whole output, reasoning too, over the
time after the first token. That reads high: OpenAI's reasoning is
written before the first content, so it isn't in that time. On a gateway
reply of 496 tokens, 224 of them reasoning, 827 ms after a 10.2 s first
token, that is 600 tok/s against a measured answer speed of 415 (the
bug e6dd5d20b fixed). Instead the answer, its output less the reasoning,
which all came after the first token, over that time: 329, a true floor
of the answer's speed. Any size tells one, as the wait isn't in it;
DecodeWindow's bounds still hold. The Requests row's tooltip says so, and
a group's floor tooltip now says the file doesn't say when the answer
began, true of both kinds, in en, zh, zh-TW, ja and de.

The 1,000-token rule stays (Fallmonkey asked for 5 s instead): it bounds
the share of the time the wait for the first token can be, which a
duration doesn't (a 5 s reply can be 4 s of wait). On the owner's
gateway rows, where both are known, a floor of 1,000 tokens or more read
0.40 of the measured speed (n=25), one of 5 s or more 0.18 (n=550). The
reason is in Row.Floor's comment and docs/reference.md.

Tests: TestCodexRowsTellAFloor (new) and TestGroupSpeedSaysHowManyRepliesItIsOf
(sol's 259 calls in turns of several now tell 259 floors at 50) fail on
the old ledger.go. usage-speed-count.test.cjs gains a turn-of-several row
(≥50) and the 496/224 row (≥329, its tooltip) and fails on the old app.js;
usage-session-speed.test.cjs's Codex row now tells its floor.

Ran: go test ./internal/usage ./internal/gui; usage-speed-count,
usage-session-speed, usage-ledger-detail, usage-speed, reasoning-speed,
usage-ledger-fit, usage-model-at-provider, routing-request-metrics,
gui-ja, gui-de, gui-zh-tw and i18n-keys in Chromium and WebKit, at 1400
and 560 px; gofmt -l; GOOS=linux/windows go vet.
2026-10-11 12:49:27 +08:00
yetone 909d767472 gui: with MAGPIE_PUBLIC_URL set, Gateway's Connect starts at it until the user picks an address, and magpie web shows it as the gateway's address (#1551, everpcpc)
everpcpc runs magpie web in Docker behind a reverse proxy with
MAGPIE_PUBLIC_URL=https://magpie.example.com. The page is opened from
other machines, yet Connect's Base URL, the copied shell/curl/Python/Node
snippets and the gateway's address on the Gateway page started at
http://127.0.0.1:3425. v0.1.1174 kept a picked address; the public one
still had to be picked once on every browser.

- /api/providers' gateway carries publicURL: MAGPIE_PUBLIC_URL when it is
  among the addresses Connect offers (shared, or MAGPIE_ADDR on the
  network). With no address kept in magpie.connectAddress, Connect starts
  there, so the snippets and the gateway key picked for it follow. An
  address the user picked, this computer's included, still wins.
- The option is labelled "Public address" instead of "Local network".
- /api/settings carries publicURL under the same condition, and Settings >
  About lists it beside the local Gateway URL, which stays the address
  agents here are pointed at.
- In magpie web, a page served to other machines, the Gateway page's
  address and Settings' web-search MCP server show the public URL; in the
  app they stay local. Agents' own config wiring is unchanged (#373).
- New strings in zh, zh-TW, ja, de; docs/reference.md says where it shows.

Run: public-url-default.test.cjs (new) on chromium and webkit, en, zh,
zh-TW, ja, de, at 1100 and 420 wide, 26 pass; on the old app.js 12 of 13
chromium cases fail. Making the public URL override a kept pick turns it
red too. TestPublicURLInConsole and the new TestPublicURLOnlyWhereOffered
pass. Sibling GUI tests (connect-address-kept, the gateway-key-* and
gateway-connect/caller-keys tests, api-key-theme, public-url, lan-docker,
phone-web, search-mcp, settings-sections/groups, gui-ja/de/zh-tw): 192
pass; phone-web failed once under the parallel run and passes alone on
both engines. gofmt, GOOS=linux and GOOS=windows go vet -tags nogui
./internal/gui, go test -tags nogui ./... under the queue lock: its one red
is TestAccountDiscoveryOffReadsNoSignIn (internal/provider, from 8c5b9f928),
which fails on main without this change too (1 in ~20 runs alone).

Found on the way, not changed here: in magpie web at phone width, an
open Connect menu closes at once (a scroll of #view-gateway right after
it opens), with or without MAGPIE_PUBLIC_URL.
2026-10-11 11:04:21 +08:00
yetone 3964ea656c usage, gui: a group's speed says how many replies it is of, "125 tok/s (1)", and one with only floors says "≥100 tok/s (30)" (Fallmonkey on Discord)
Fallmonkey: the Usage ranking and the Output speed card showed
gpt-6.1-sol's tok/s from the one reply of its 260 that used no tool (the
only Codex turn its session file times) beside "260 requests", while
Claude Code, whose Requests rows say "≥N tok/s" by the dozen since
0192edf1, showed none. Asked for one rule for every source: measured
replies give "N tok/s (k)", only floors give "≥N tok/s (k)", neither
gives nothing.

usage.Totals now counts DecodeN, the replies its DecodeMs/DecodeOut are
of (add and addRow), and FloorOut/FloorMs/FloorN, the floors of rows read
from Claude Code's and Claude Desktop's session files (Row.Floor, the
same rule as app.js's ledFloorSpeed: source "log", not failed, no
measured speed, 1,000+ tokens over 1 s+, under 10,000 tok/s). Floors are
never in Speed(); the Speed trend and `magpie usage` are unchanged.
app.js's ledGroupSpeed applies the rule to the ranking's rows (main page
and tray panel; the "Other" row sums the new fields), the Output speed
card and the overview's agent/model lists, with a tooltip saying which
it is and how many replies; a ranking by speed orders and bars a
floor-only group by its floor. Strings in en, zh, zh-TW, ja, de;
docs/reference.md says the rule.

Run: TestGroupSpeedSaysHowManyRepliesItIsOf (sol 260 calls, 1 measured
at 125 tok/s; Claude Code 42 calls, 30 floors at 100, a short, a failed
and a gateway row telling none; the page sums; summarize) fails to build
on the old code and goes red with the agent check taken out of
Row.Floor. usage-speed-count.test.cjs (overview, Requests rows, ranking
by tokens and by speed with order, titles and bars, the card for all and
for Claude Code's model alone, no clipping, no sideways scroll) passes in
Chromium and WebKit, en/zh/zh-TW/ja/de at 1400 and 560 px, and fails
against origin/main's assets. Related GUI suites (click-scroll, gui-de,
gui-ja, gui-zh-tw, i18n-keys, ledger-*, panel-usage, reasoning-speed,
routing-burst-speed, usage-*): 389/389 in both engines. go test -tags
nogui ./... (temp HOME) passes; gofmt -l clean; go vet nogui for darwin,
linux and windows on internal/usage and internal/gui. Not tried with
Fallmonkey's own data.
2026-10-11 10:04:15 +08:00
yetone 1c9747f611 usage: a Remote magpie provider's gateway keys each show their own limit, used and left, period and reset on the Usage page (#1547, PennyVibe)
A computer that uses another magpie through gateway keys that magpie gave
it saw the other magpie's subscription cards, but not what each key may
still spend there.

What changed:
- provider/remote_key_limits.go: each key of a remote-magpie provider
  gets a section on one card, "<remote>/~keys", read from the remote's
  existing GET /v1/magpie/limit asked with that key alone (the endpoint
  answers only the calling key, from access.Caller; nothing in the
  request picks another key, so a key never sees another's numbers).
  A window per cap (tokens, spend) named for its period (today / this
  week / this month / this cycle), used against the cap, with its
  reset; SubscriptionQuota.GatewayKey carries what is left, calls, the
  cycle's days, used up and unpriced calls. A key with no limit shows
  one "Limit: Unlimited" window. Kept for remoteCardsFor like the
  remote's cards; the card's refresh reads the named key again.
- A failed read keeps the last numbers, dated (AsOf); with nothing read
  the section says why, never zero and never "no limit". A remote from
  before /v1/magpie/limit (404) says it is too old to tell.
- GUI: the card is named "Gateway keys · <remote>" (main page and the
  tray panel), a line under each key says the cycle, calls and "used
  up", and the two new errors are said plainly; strings in zh, zh-TW,
  ja, de.
- magpie quota (CLI) shows the same cards; a window with no cap now
  reads "Limit unlimited" there, not "Limit 0%" (quotaCell).
- docs: providers-accounts (Allowance), gateway-routing (Remote magpie
  APIs, verification), reference (/v1/magpie/limit).

Run:
- New tests fail on the old code: TestRemoteMagpieKeyLimits (provider)
  and TestRemoteMagpieKeyLimitCards (gateway, a real Handler, real chat
  requests moving the numbers) with the key cards taken out of
  RemoteCards; usage-remote-key-limits.test.cjs on HEAD's app.js.
  TestKeyLimitTellsOnlyTheCaller guards what was already so (key A can't
  read key B by query, header or no key from the LAN), so it passes on
  both. TestQuotaCell's unlimited case reads "Limit 0%" on the old code.
- provider, gateway -count=3; go test -tags nogui ./... (full suite).
- GUI: the new test in chromium and webkit x en/zh/zh-TW/ja/de x
  900/400px (20 pass); the whole GUI suite.
- gofmt -l clean; go vet -tags nogui darwin, linux, windows.
- Real two-magpie run, both this build, sandbox HOMEs, 127.0.0.1:38461
  (remote) and :38471 (local); the upstream was a fake OpenAI server
  (fixed 175 tokens a reply). Remote keys laptop (1000 tokens/day), desk
  (5000/week), spare (no limit); local "office" Remote magpie with all
  three, routing rotate. After 17 chats through the local gateway,
  magpie quota on the local read laptop 1050/1000 (100%), desk
  1050/5000 (21%), spare unlimited (in --json; the text line read
  "Limit 0%", which the quotaCell change above fixes), matching the remote's own
  gateway-key list; laptop's spent key was passed over (every chat
  200). With the remote stopped each key said it couldn't be reached,
  never 0. Not run against a real vendor, nor a real magpie older than
  /v1/magpie/limit (unit-tested with a 404).
2026-10-11 09:10:44 +08:00
yetoneandTed Li 0192edf133 gui: a long Claude Code reply read from its session file shows the least it wrote at (≥98 tok/s), and a short one no longer says it wasn't streamed (Fallmonkey on Discord)
Claude Code's session file has no first token, only when the line that
asked for a reply and its last line were written, so every Claude Code and
Claude Desktop call that didn't go through the gateway showed no speed,
with "Not streamed" though it was streamed. A reply of 1,000 output tokens
or more over a second or more now shows its tokens over that whole time as
a floor (ledFloorSpeed, "≥" in the cell, "At least: …" in its tooltip and
the row's details); the wait for the first token is inside it, so the
speed after the first token is never under it. Gateway rows and timed
session rows are unchanged, and the period's speed counts timed calls only.

Only Claude Code's and Claude Desktop's rows tell one. The contributed
version gave every session-file row a floor; a Codex call in a turn of
several is timed from the last tool output before its token count, and in
a month of real rollouts (4,588 multi-call calls) 2,968 were timed from the
output of a tool that same call asked for, written before its count, so
the window begins inside the call and a floor from it could read high.
Those rows keep "—" with "The session file has no first token". OpenCode's
created→completed time isn't checked against real sessions, so it tells
none either.

Checked against the shape of real Claude Code files (read-only, 30 days,
~198k messages, 2,011 files incl. subagents): block lines are stamped at
each block's end (single-line 1,000+ token text replies read a median 110
tok/s, not the thousands a start stamp would give); no sidechain lines in
main files; no assistant line out of clock order; a message's later lines
keep the time its first was asked (Began), so the 15,779 tool results
written between one message's blocks don't shorten it. Floors shown: 23,518,
p50 102, p99 141, max 156 tok/s for claude-opus-5-5.

Run: usage-session-speed.test.cjs (now also a Codex multi-call row, a
Claude Desktop row, and a 560px window) in Chromium and WebKit, en and zh;
red with the agent check taken out ('≥500 tok/s' !== '—'). The related
suites (gui-de/ja/zh-tw, i18n-keys, ledger-*, usage-ledger*, usage-speed,
reasoning-speed, routing-burst-speed, usage-ttft-rounding,
usage-computers): 146/146 in both engines. go test -tags nogui ./...,
gofmt, and go vet for darwin/linux/windows on internal/gui.

Co-authored-by: Ted Li <tl2493@columbia.edu>
2026-10-11 06:27:17 +08:00
yetone cb25d3861b gateway: a Claude subscription's tool calls reach their run on a MAGPIE_ADDR that isn't loopback (#1546, jiayeZhu)
With MAGPIE_ADDR pinned to a concrete address outside 127/8 and gateway
keys on, the Claude subscription bridge's MCP helper posted its tool
calls to http://<that address>/_magpie/claude-mcp/<token> with no key.
lanGuard answered 401, the call never reached the run, and every turn
of tool results found "no run waiting" and started a new Claude Code
told the whole conversation; the reporter's cache hits fell from ~95%
to ~30%.

- lanGuard lets that callback in by its run's own token: a POST to
  /_magpie/claude-mcp/<token> whose token (24 random bytes) is one a
  live run registered (addCallback in startRun, dropCallback in
  removeRun), compared in constant time. No path is exempt on its own:
  an unknown, ended, truncated, extended, percent-encoded or GET form
  is still asked for a key, and so is every other route.
- The helper is handed the callback URL in a 0600 file in the run's
  own temp dir rather than as an argument; RunMCP reads a path as that
  file. The test fakes read it from there.
- docs: claude-subscription-bridge, gateway-routing's HTTP surface and
  reference.md's network section say how the callback is let in.

Run:
- TestClaudeToolCallbackOnANonLoopbackAddress (new): a gateway behind
  lanGuard on this machine's own non-loopback IP, MAGPIE_ADDR set to
  it, fake Claude Code making a real helper call; red on the old guard
  with the reporter's "refused POST /_magpie/claude-mcp/... no API key
  was sent" line, green now.
- TestOnlyALiveRunsCallbackSkipsTheKey (new) and
  TestNetworkGatewayGuardsEveryRoute (now also tried with a live run's
  token as a Bearer key): red with a blanket path exemption put in by
  hand, green now.
- Real use: sandbox HOME, magpie serve on MAGPIE_ADDR=10.0.0.111:3561
  with a gateway key, a fake claude driving the real claude-mcp-helper.
  origin/main: callback refused, "tool results no run waiting", a new
  Claude Code told the whole conversation. This build: the result
  reached the same process (pid unchanged), nothing refused, a made-up
  token still 401.
- go test -tags nogui ./... (full suite), gofmt -l, GOOS=linux and
  GOOS=windows go vet -tags nogui on internal/gateway and
  internal/claudebridge.
2026-10-11 05:50:04 +08:00
yetone 99fcddeeba usage: the Requests tab, its filters and refresh, the charts, the TUI and magpie usage answer at once over a long history (Vantiboo1ean)
Vantiboo1ean (Discord, macOS M2, v0.1.1157) has ~750,000 requests in
usage.jsonl. On Usage > Requests every filter, model pick and refresh
spun forever and the page never updated.

Reproduced in a sandbox HOME with 750k generated records in the real
format (400 MB usage.jsonl, ~84k sessions), on magpie web and in process.
The cause: the #563 budget dropped the index's blocks once they passed
24 MB (60 MB here), so every read, of any period, parsed the whole file
again (6 s CPU) and priced every call again; All took 12 s of CPU, the
heatmap 13 s, and the page read both at once.

What changed:
- log_index: the gateway's blocks are always kept (about 80 bytes a call,
  S2-compressed instead of flate); the file is parsed once, then only
  what was appended.
- block_price: the gateway's blocks are priced per query, once per set of
  provider/model/served/effort names rather than per call, into pooled
  buffers; range loops go by pointer (a packed row is 264 bytes).
- request_page: pages are always cached (16 at most), session-file chunks
  stay in the budget, and a page asked again while it is worked out (the
  refresh button, the timer) waits for that one instead of starting a
  second scan.
- Siblings that read the same history:
  - The heatmap names each day once.
  - A day filter no longer allocates per call.
  - The ledger behind the TUI, magpie usage, the CSV export and sync
    (LedgerOf, OwnDays) reads the gateway's calls from the index instead
    of Load parsing the whole file.
  - Direct/Summaries matches the session files' calls against the index's
    blocks without pricing all 750k gateway calls.
  - A summary of more than 1024 sessions is now cached with its top 1024
    (it was not cached at all). The Usage page's /api/usage gets the top
    100 (it was sent all 84k, 19 MB, which it never draws) plus a new
    sessionCount. /v1/magpie/usage still lists every session, and magpie
    usage says "top 10 of <sessionCount>".

Timings, CPU (the box was at load 130-190 on 14 cores, so wall is
inflated; min of repeated runs), before -> after:
  Requests today            6.0 s  -> 20 ms
  Requests 7d               5.8 s  -> 93 ms
  Requests 30d              ~6 s   -> 362 ms
  Requests all              12.4 s -> 2.4 s first, ~8 ms again
  all, model filter         12.3 s -> 1.5 s
  all, agent filter         11.3 s -> 1.8 s
  30d, search "opus"        6.7 s  -> 353 ms
  day filter                6.0 s  -> ~0.1 s
  heatmap                   13.7 s -> ~2.3 s first
  summary today / all       6.0 / 9.2 s -> 25 ms / 1.6 s first, <1 ms again
  /api/usage?period=all     1.6 s + 19 MB JSON each time -> <1 ms, 53 KB
  TUI Summaries(all)        ~8.5 s (Load + ledger) -> 1.1 s first, <1 ms again
  TUI Summaries(today)      ~6 s   -> 29 ms
  Visit 7d (budget, codex)  5.9 s  -> 10 ms
The first read of the file after start costs ~5 s of CPU, once.

Tests (each seen red with its guarantee broken by hand):
- TestUsageOverBudgetHistoryIsReadOnce
- TestUsageSessionChunksStayInBudget
- TestUsageOverBudgetPageIsCached
- TestUsagePageAskedTwiceIsWorkedOutOnce
- TestUsageLedgerReadsTheIndexNotTheFile
- TestUsageLargeSummaryIsCompleteAndKeptTrimmed (was ...ButNotCached)
- TestDirectCountsOnlySessionFileCalls, now with a request-id match,
  checks that Direct/Summaries equal the ledger's.

Run: go test -tags nogui ./... (temp HOME), gofmt -l, GOOS=linux and
GOOS=windows go vet on the touched packages.
2026-10-11 04:44:13 +08:00
yetone 9c11abbd00 agent: jcode is an agent magpie connects: a magpie profile with magpie's models, jcode started on the one picked (wani on Discord)
wani asked on Discord for jcode (1jehuang/jcode, a coding agent in Rust)
as an agent magpie connects. There was no earlier request in issues or
history.

What changed:
- internal/agent/jcode.go: a new agent for jcode's config.toml in
  $JCODE_HOME, else ~/.jcode (jcode-storage's jcode_dir). Detected by the
  file, the folder, or `jcode` on PATH.
  - Connecting adds a named profile, [providers.magpie], with the keys
    `jcode provider add` writes: type "openai-compatible", the gateway's
    /v1, an inline api_key naming jcode (magpie-jcode; jcode's requests
    carry nothing else that tells it apart) and requires_api_key = true.
    Without that key, jcode sends no key to a loopback base URL.
  - Its models list has one entry per model of magpie's: context_window
    (128000 when magpie doesn't know it; jcode would assume 200k), input
    text/image, and reasoning = true for a model with effort levels, so
    jcode's /effort offers them.
  - It sets [provider] default_provider = "magpie" and default_model, the
    model picked. What was there is stashed, and Disconnect puts it back.
  - Picking a model of jcode's own while it is on magpie takes magpie
    out: the profile goes and the user's provider comes back with that
    model.
  - Each key is set alone, so the user's other keys and tables stay, as
    do their own keys in magpie's profile (headers, extra_body) and a
    reasoning_effort they set on one of its models while the model has
    that level.
  - jcode writes a profile's models as [[providers.magpie.models]]
    tables when it rewrites the file itself (Config::save,
    to_string_pretty). Those are replaced by the one list.
  - A sync with nothing to change doesn't write.
  - Disconnect drops the profile whole, sub-tables included.
  - Check says when the profile is gone while jcode still starts on it,
    or when its base_url or key is off.
  - While jcode runs, the notice says to restart open jcode sessions,
    since it reads the file when it starts. The notice is a newNotice
    template, translated in i18n.js (zh-CN, zh-TW, ja, de) and listed in
    NOTICES, as TestEveryNoticeIsTranslated asks.
- agents.go, agentenv.go: registers it; JCODE_HOME joins the agent env.
- icons/jcode.svg: jcode's halftone mark (jcode.sh/favicon.svg) as a
  mask icon, every other dot of its lattice.
- docs/reference.md, docs/subsystems/agent-wiring.md, README.md,
  README.zh-CN.md: jcode's row and its place in the agent list.
- WSL isn't covered: jcodeAt reads the place's home and JCODE_HOME, but
  it isn't added to the WSL agent list (another session has wsl.go open).

What was run:
- go test -tags nogui ./internal/agent -run '^TestJcode'. The fixture is
  the bytes jcode 0.94.0 wrote for `jcode provider add`. The tests went
  red when, by hand, I:
  - made a no-op sync write;
  - dropped the user's reasoning_effort;
  - skipped the stash, so Disconnect wasn't byte-identical;
  - left jcode's [[providers.magpie.models]] tables in, which makes
    invalid TOML;
  - dropped requires_api_key.
- Real use:
  - jcode v0.94.0 (release binary, sha256 checked) ran under a sandbox
    HOME with JCODE_HOME set and JCODE_NO_TELEMETRY=1. Its config.toml
    was the one jcode wrote for its own "probe" profile.
  - A sandbox magpie (MAGPIE_ADDR 127.0.0.1:3671) with a fake OpenAI
    upstream on 3672 ran `magpie jcode magpie/fake/org/echo-1`, a model id
    with two slashes.
  - `jcode run 'Say hello in one word.'` answered with the upstream's
    reply, streamed. The upstream saw model org/echo-1, and usage.jsonl
    recorded the turn under agent "jcode".
  - `jcode provider add two …` while connected appended its own profile
    and left magpie's as it was.
  - `magpie jcode default` then gave back the file jcode wrote,
    byte-identical, with jcode's new [providers.two] kept.
- The icon rendered as a mask in Chromium and WebKit. The only GUI
  change is the notice's translations; TestEveryNoticeIsTranslated and
  internal/gui pass, and node --check accepts i18n.js.
- gofmt -l; go vet (darwin, GOOS=linux, GOOS=windows) on internal/agent
  and internal/agentenv; go test -tags nogui ./internal/agent
  ./internal/agentenv ./internal/gui; go test -tags nogui ./... under a
  temp HOME (load ~80): every package passed. After rebasing on
  origin/main, internal/agent and internal/agentenv were run again,
  along with internal/gui, gofmt and the linux/windows vet.
2026-10-11 04:33:53 +08:00
yetoneandBUKOWSKIREAL 8b393938f5 agent: StepCode can be connected to magpie, and Disconnect puts back its own model (#1526, BUKOWSKIREAL)
StepCode (StepFun's coding CLI, `step`) is a Pi fork that keeps Pi's
settings as TOML in ~/.stepcode/config.toml and Pi's models.json beside
it. It is now an agent target: Connect sets defaultProvider/defaultModel
to magpie, appends the magpie pattern to enabledModels when the user
scopes models, and writes providers.magpie into models.json with the
per-agent key. Disconnect puts back the user's own provider, model and
scope (only the patterns magpie added are taken out if the user changed
the scope since), restores or removes providers.magpie, and removes a
models.json magpie created. STEP_CODING_AGENT_DIR and STEPCODE_CONFIG_DIR
move the folder as StepCode's own resolveStepConfigRoot does; WSL is
covered.

The patch is BUKOWSKIREAL's (7cc88463 in their fork), reviewed line by
line: no network, telemetry or credential reads, writes only to the two
StepCode files and magpie's stash. Added here: a test that StepCode's
real User-Agent, "step (darwin 25.2.0; arm64)", counts as StepCode, and
the real-CLI test now looks for a "magpie" row in `step --list-models`
rather than the word anywhere (the docs path step prints can contain it).

Run:
- Config format checked against stepfun-ai/Step-Code at 3d70bae5 and the
  official 0.1.3 darwin-arm64 binary (sha256 matches latest.json):
  `step config path --json` names ~/.stepcode/config.toml and models.json.
- Sandbox HOME, sandbox gateway on 127.0.0.1:3647: a user config with
  defaultProvider "step", step-3.7-flash, thinking high, two scoped
  models, telemetry off. `magpie stepcode magpie/deepseek/deepseek-flash`,
  then `step -p` answered PONG through the gateway (usage record: agent
  stepcode, deepseek-flash, 200). `magpie stepcode default` put
  config.toml back value for value, removed models.json, and
  `step --list-models` no longer listed magpie.
- The same round trip from the real web page (sandbox `magpie web`),
  switch on, then off through the disconnect preview, which listed the
  three values it puts back; config.toml came back byte-identical. The
  row and icon checked in Chromium and WebKit, en and zh; no GUI assets
  change.
- Broke the guarantee: with unwire never restoring the defaults,
  TestStepCodeLifecycle, ...NativeChangedAndPreexisting and
  ...StrictValidationAndRollback go red. Without the "step" alias the
  new UA check goes red.
- MAGPIE_TEST_STEPCODE_BIN=<0.1.3> go test -run TestStepCodeRealCLISandbox
  passes (it failed before the row check above).
- go test -tags nogui ./... ; gofmt -l; go vet (darwin, GOOS=linux,
  GOOS=windows) on internal/agent and internal/agentenv; go build for
  darwin, linux (nogui) and windows.
Not tried on a real Windows, Linux or WSL machine.

Co-authored-by: BUKOWSKIREAL <233685554+BUKOWSKIREAL@users.noreply.github.com>
2026-10-11 04:03:29 +08:00
yetone cd93bbec0e provider, gui: a signed-in account can be given a name of the user's own, and a GLM seat's account card keeps the key plan's name and no longer flickers back to two cards (#1515, aindijrncom)
The same GLM Coding Plan team seat was added twice: as a key provider the
user had named, and as a ZCode plugin account. The Usage page kept only the
account's card, which read "31****36@qq.com" or just "ZCode", and whenever
either read failed ("BigModel API keys: not JSON") or a window had no reset
yet, the key's card came back beside it.

Seat (the flicker): the old check returned "different" on any error. It
now returns same, different or unknown (seatMatch). A match is remembered in
seats.json beside quotas.json; while the remembered account is signed in an
unknown check keeps the key card hidden, windows that disagree forget it,
and a signed-out account brings the key card back (seatCards, used by
quotas, Allotted and CachedCards). A failed read is "unknown", never "not
the same".

Names: providers.json gains accountNames (by the account in lower case,
like accountCaps), set by provider.SetAccountName. They are magpie's own
and never written into the vendor's or a plugin's sign-in. Built-in and
plugin accounts both take one; key providers are refused. Each card carries
Alias (the user's name, else the seat) and Seat (the key provider's name,
and the key's when it has several).
- GUI: the editor's account row shows the name with the address beside
  it, or the address with "≡ <key plan>"; a click or Enter renames it in
  place (posted once to provider/accountname; Escape leaves it, empty
  clears it). The name stays selectable text: dragging across it renames
  nothing.
  The Usage page's cards and the tray panel name the account the same way.
  Hide accounts hides the name too. Strings in zh, zh-TW, ja, de.
- The tray tooltip says "ZCode · <name>".
- CLI: `magpie accounts alias <agent> <email> [<name>|--clear]`.
  `magpie accounts` and `magpie quota` show the name; quota also matches
  on it.
- /v1/magpie/quotas carries alias and seat.

Run:
- account_seats_test TestSeatKeptThroughAFailedRead fails on the old code
  ("a failed read brought the key's card back") and passes now.
  TestAccountNameOfAPluginAccount uses the fake plugin and checks that
  plugin-auth.json and logins.json are byte-for-byte unchanged.
  TestAccountsAlias checks that Codex's auth.json is unchanged.
  TestTrayNamesTheAccountByItsAlias.
- account-alias.test.cjs: Chromium and WebKit; en, zh, zh-TW, ja, de;
  900 and 360px; 20/20 pass. It covers no scroll on a click, keyboard,
  selectable text, no select, no stripe, no sideways scroll and masking.
  With the post-once guard removed it goes red. account-arrange (text
  selection) passes in both engines.
- Sandbox HOME, built binary, vendors behind a dead proxy:
  - `magpie accounts alias codex Me@Example.com 某某·GLM高级版`, then
    `magpie accounts` and `magpie quota` showed the name.
  - An unknown account was refused.
  - `magpie web` on spare ports: POST /api/provider/accountname saved
    "Team seat" (whitespace folded), and an unknown account got an error.
  - Gateway /v1/magpie/quotas and /api/usage/quotas carried the alias.
  - auth.json's sha was unchanged throughout.
- go test -tags nogui ./... (temp HOME, load ~200): all ok except
  TestSetAnswersWhileDevinAndProvidersHang (15.5s under load), which
  passes alone 3/3 at ~250ms.
- gofmt -l; GOOS=linux and GOOS=windows go vet on internal/provider,
  internal/gui and the root package.
- The whole GUI suite in Chromium and WebKit, each failed file rerun
  alone. These are red on the parent commit 472b36cec as well:
  mobile-web (9), usage-heatmap (11), old-webkit (Safari 15 :has and
  :focus-visible rules), usage-alert on WebKit (2), and routing-proxy,
  which flakes 2 of 3 runs on the base. Every other file passes alone.
Not run: a real GLM key plus a real ZCode account. The seat match against
real BigModel/ZCode answers is covered only by the fake-upstream tests.
2026-10-11 03:42:35 +08:00
yetone 64262a19f0 agent: Prime Agent is an Agents-page row, wired like Pi into ~/.prime/agent, and Disconnect puts its files back (#1528, takltc)
What changed
- internal/agent/primeagent.go: Prime Agent (PrimeIntellect-ai/prime-agent,
  CLI prime-agent) through the piLike path, as OmO was added. Its folder is
  ~/.prime/agent or PRIME_AGENT_CODING_AGENT_DIR (~ expands, as upstream's
  agent_dir does; appdir now lets that variable carry ~). models.json and
  settings.json were checked against upstream v0.10.0 (pa-core settings and
  models registry): Pi's camelCase fields, the same thinking levels and
  enabledModels rules. Connect writes providers.magpie, defaultProvider and
  defaultModel and keeps the user's providers and settings. Only the global
  settings.json is written; allowedModels and subagentDefaultModel are left
  alone.
- Prime Agent sends no User-Agent, so its provider block carries the key
  magpie-prime-agent and the usage log names it (piLikeKeyed). The block is
  Pi's otherwise, compat.sendSessionAffinityHeaders included (Prime Agent's
  openai_completions honours it), kept as the user set it (piBlockKept).
- Disconnect restores both files byte-for-byte: before magpie's first write
  a copy is kept (*.before-magpie, or a note that the file was absent), and
  Disconnect puts it back when nothing else changed since (Agent.Restore). A
  file changed while connected is left with only magpie's part taken out.
- WSL kind, agentenv, the icon, PICKS_ITSELF in the GUI, docs and READMEs.

Run
- go test -tags nogui ./internal/agent ./internal/appdir ./internal/agentenv
  ./internal/library ./internal/usage; the new tests went red with the key,
  the restore, the ~ expansion, PICKS_ITSELF and the icon each taken out.
- pi-default-note.test.cjs in chromium and webkit.
- Real use: prime-agent 0.10.0 installed into a sandbox HOME, a sandbox
  gateway on 127.0.0.1:3651 and a fake upstream on 3652. The interactive
  TUI with no flags started on magpie/fake/echo-1, the fake got the request
  and usage.jsonl recorded agent "prime-agent". `magpie prime-agent default`
  put models.json back byte-for-byte; settings.json got its values back, but
  Prime Agent rewrites the whole file when it runs (every key, nulls), so
  that file is equal in content, not bytes. Reconnecting over that
  null-filled file and disconnecting again left it byte-identical. After
  the rebase onto 7a5536793 (compat in Pi's block) the turn was run again:
  same result, and both files byte-identical after Disconnect.
  `prime-agent -p` ignores the saved default upstream (print mode picks a
  featured model); with --provider magpie --model it goes through magpie.
- gofmt -l, GOOS=linux and GOOS=windows go vet, full go test ./...
2026-10-11 03:11:33 +08:00
yetone b1396d2360 gateway, provider, gui: a routing group of decision models answers /v1/systemone, failing over between them (ARNO on Discord)
ARNO asked for decision models to get the group feature too: /v1/systemone
took only "<provider>/<model>" (xxx/jev-latest), so one refusing key or
vendor failed the call with nothing to fall back on.

A routing group may now be of decision models alone (provider.Group.Decides,
provider/decide_group.go). SaveGroup refuses one mixed with models that hold
a conversation, a decision group inside a chat group, and patterns, rules,
classifier, effort, levels, fast mode or a member effort on it. It is kept
out of the agents' catalog (groupEntries), and a chat request to it gets a
400 pointing at /v1/systemone.

POST /v1/systemone with "model":"group/<id>" (or the group's id or name, as
GroupFor reads them) goes to serveDecisionGroup (gateway/decide_group.go):
- the members' keys and accounts are planned with planGroup in the group's
  routing order, resting ones last; perKeyBarred no longer drops a
  decision-only provider's keys (it speaks no chat protocol), so each key
  is a try of its own;
- a gateway key's model and account limits and pause rules hold as for chat;
- a retryable failure that isn't the request's own (shape/prompt/protection)
  rests the candidate via restAfter and the next is asked; a transport error
  rests it as a 502; the last one's answer and Retry-After are passed on;
- every try is a Try of one route in the routing log; one usage row for the
  answer.
A group classifier naming a decision group fails over the same way
(askDecisionGroup; systemOne now returns decideRefused with the vendor's
status, headers and body, and postDecide returns the headers).

The GUI group editor offers a group of decision models only decision models
(groups.deciders), a chat group no decision model or decision group, a new
one both, and a decision model's row has no reasoning picker (groupJSON
.decides). The TUI member picker and `magpie group add` follow the same rule.
#1514's plugin_decide_test and TestMixedDecisionProvider now assert a mixed group is refused and a group
of decision models saves. Docs: reference.md (routing groups),
gateway-routing.md, provider-plugins.md.

Run:
- go test -tags nogui -timeout 40m . ./internal/provider ./internal/gateway
  ./internal/gui ./internal/tui: ok
- new: TestSystemOneDecisionGroupFailsOver (httptest System One fakes: a
  provider with two keys answering 429 and 503, then a second provider
  answering 200: tries ka1,ka2,kb, both failures rested and ask by name
  goes to kb first; all failing passes the last answer on; chat to the
  group is 400), TestDecisionGroupClassifierFailsOver, TestDecisionGroup,
  TestGroupAddDecisionModels, TestMemberOptionsDecisionGroup,
  group-decide-members.test.cjs (Chromium and WebKit, en and zh; no new
  strings)
- each broken by hand and seen red: no dispatch (404), no perKeyBarred
  change (ka2 skipped), no classifier failover, no rest, decision group in
  the catalog, CLI resolver, TUI and GUI picker filters
- GUI: group-*, routing-effort*, routing-levels, routing-save*,
  routing-intent-entry, routing-manual, i18n-keys in both engines: 169 pass
- gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on the
  touched packages
- after rebasing on bc2496dca, the five packages again: ok. The first run
  had TestMaxRPMWaitsForRoomInTheMinute red once under load; it passed
  -count=3 alone and in the rerun, and nothing here touches rpm.go.
Not tried against a real TypeSafe or Bailian account.
2026-10-11 01:37:18 +08:00
yetone f04792f906 icon: remote icons are fetched through usemagpie.ai/api/icon, so their hosts never see the user's IP
A plugin's package.json icon, an import link's icon= and the library's
market icons sit on hosts their authors pick. magpie fetched each straight
from there, so an author could log the IP of everyone who opened Discover
or the library. The owner asked for icons to keep showing without that.

- site/worker.js: /api/icon?url=<https URL> fetches the picture from
  Cloudflare with only Accept: image/* and its own User-Agent, follows
  redirects, caps it at 1 MB (the app's MaxIcon), passes on only PNG,
  JPEG, GIF, WebP, ICO or SVG (by bytes, as StoreIcon), and counts and
  keeps nothing. It refuses http, userinfo, a non-443 port and
  usemagpie.ai itself; 404s are cached 5 minutes, 5xx not at all.
- internal/iconproxy: URL(u) is the proxied address (MAGPIE_ICON_PROXY
  for tests); a picture already on usemagpie.ai is asked for as it is.
- provider.FetchIcon (plugin, import link and partner icons) and
  library.fetchImage (market icons, avatars) fetch through it. The
  import link's checks (https, public host) still come first; there is
  no direct fallback. provider.FaviconFor still reads the user's own
  provider's site directly: they already send it their requests.
- Privacy text in README en/zh, docs/reference.md and site docs
  start/import in en/zh/ja says so.

Ran:
- node --test site/*.test.mjs: 28 pass. The new test asks with Cookie,
  UA, X-Forwarded-For and CF-Connecting-IP and checks only accept and
  user-agent go upstream; 415/413/502/400 cases; its fetch stub throws
  instead of reaching the network. With the usemagpie.ai refusal
  removed by hand it goes red (27/1).
- TestFetchIconGoesThroughTheProxy and TestIconGoesThroughTheProxy
  (author host is .invalid; an httptest server stands in for the proxy):
  with the proxy taken out by hand both go red (provider: lookup
  author.invalid; library: the proxy was never asked), green restored.
- go test ./internal/iconproxy ./internal/provider ./internal/library
  ./internal/gui: ok. gofmt -l clean; go vet darwin (those four),
  linux (iconproxy, provider, library), windows (all four): clean.
2026-10-11 01:28:22 +08:00
yetone 2c75d89827 agent: AstrBot is an agent magpie connects: its default chat model one of magpie's, its own providers kept (orange27 on Discord)
orange27 asked on Discord for AstrBot (AstrBotDevs/AstrBot) as an agent.

What changed:
- internal/agent/astrbot.go: a new agent for AstrBot's data/cmd_config.json
  under its root ($ASTRBOT_ROOT, else ~/.astrbot, the desktop app's, else
  ~/astrbot / ~/AstrBot when it holds an install).
  - Connecting adds one "magpie" entry to provider_sources
    (openai_chat_completion at the gateway, key magpie-astrbot) and one
    "magpie/<model>" entry per model of magpie's to provider.
  - It sets the default chat model:
    agent_runner.config.model.provider_id on 4.28+, or
    provider_settings.default_provider_id on older layouts.
  - Field types are taken from AstrBot's own defaults and validator: key is
    a list, timeout and max_context_tokens are ints, modalities lists
    text/image/tool_use, and custom_headers / custom_extra_body are objects.
  - The user's own sources and models are kept byte for byte. What they
    change in magpie's entries (timeout, proxy, enable) stays through a
    sync, and a sync with nothing new doesn't rewrite the file.
  - The UTF-8 BOM AstrBot writes is kept.
  - The first connect copies the file to cmd_config.json.before-magpie.
  - Disconnect takes magpie's entries out and puts back the pick it found,
    so the file comes back byte for byte.
  - A pick the user makes while connected is theirs and stands.
  - Without the file it says to start AstrBot once (or set ASTRBOT_ROOT).
    Without provider_sources (before 4.10) it says to update.
  - The notice says to restart AstrBot, before saving in its WebUI: it
    reads the file only at start-up and its WebUI writes the whole file
    back on save.
  - Docker installs aren't reached: their root is inside the container.
- agents.go, agentenv.go: registers it; ASTRBOT_ROOT joins the agent env.
- icons/astrbot.svg: AstrBot's logo, as a mask icon.
- applied_test.go, rewire_test.go: the every-agent tests seed AstrBot's
  settings, as they do Hanako's.
- docs/subsystems/agent-wiring.md, docs/reference.md: AstrBot's row.

What was run:
- go test -tags nogui ./internal/agent -run '^TestAstrBot'. The tests went
  red when, by hand, I dropped the BOM, rewrote the user's entries, left
  the pick unrestored, overwrote the user's own pick, made a no-op sync
  write, rewrote the backup on a switch, or broke the legacy layout.
- Real use:
  - AstrBot 4.28.2 installed with uv into a scratch venv (Python 3.12),
    run from an isolated root under a sandbox HOME.
  - A sandbox magpie (MAGPIE_ADDR 127.0.0.1:3617, ASTRBOT_ROOT set) with a
    fake OpenAI upstream on 3618 ran `magpie astrbot magpie/fake/echo-1`.
  - AstrBot restarted, logged "Selected openai_chat_completion(magpie/
    fake/echo-1) as default chat model provider", and answered a WebUI
    chat (/api/chat/send) with the upstream's reply.
  - usage.jsonl recorded the turn under agent "astrbot".
  - `magpie astrbot default` gave back the file AstrBot wrote,
    byte-identical, and AstrBot started clean on it.
- The icon rendered as a mask in Chromium and WebKit. No GUI strings were
  added: the notice is the agent's own English line, like the others'.
- gofmt -l; go vet (darwin, GOOS=linux, GOOS=windows) on internal/agent and
  internal/agentenv; go test -tags nogui ./... under a temp HOME (load
  ~170-240): every package passed but internal/gateway. That package
  doesn't import internal/agent. It timed out at 10m, then with -timeout
  30m failed TestQueuedStreamWaitedOutIsTheStreamsError (its 400ms idle
  read and the 100ms "the first has the slot" sleep; a delay injected
  before the first request reproduces it). internal/agent and
  internal/agentenv were rerun green after rebasing on origin/main.
2026-10-11 00:41:09 +08:00
yetone 3541ec2fd5 gateway, gui: a gateway key's limit can run every N days, and Reset usage counts it from 0 again (#1509, PennyVibe)
PennyVibe asked for a key limit on a cycle of N days rather than a
calendar day, week or month, and for a way to zero a key's usage by
hand. Both are in.

Every N days (N from 1 to 3650):
- access.Limit gains Days and Since. Since is magpie's own: the
  limit-key action always works it out, and a value a client sends is
  ignored.
- The cycle starts when the limit is set. Each cycle is N×24h of
  absolute time from Since, so a restart, a time-zone change or a DST
  shift doesn't move it.
- Changing only the caps or "count cache reads" keeps the cycle.
  Changing N or the period, or turning the limit on, starts a new
  cycle now.
- A hand-written "days" limit with no Since runs from the Unix epoch.
- The GUI window menu offers "Every N days" with a Days field. The CLI
  takes `magpie gateway-key limit <id> 10d`. The refusal and status
  name the cycle ("for this 1-day cycle").

Reset usage:
- A new action, reset-limit-key, is on the editor's "Reset usage"
  button (after a confirm) and on `magpie gateway-key limit <id> reset`.
- It sets Since to now, so tokens and cost both count from 0 together.
- An N-day key starts a new cycle then.
- A day, week or month key keeps its window's end, so it stays on the
  calendar. Only the calls before the reset stop counting.
- The usage log is not touched. Authenticate reloads keys each request,
  so the reset takes effect at once.

Keys saved before keep their JSON byte for byte (omitzero, nothing
written on load).

Docs: reference.md documents the cycle and reset rules. The docker page
(en, zh, ja) mentions every-N-days.

Run:
- go test -tags nogui ./... with a temp HOME.
- New Go tests:
  - TestLimitDaysCycle covers the NY DST, UTC and UTC+8 boundaries.
  - TestLimitCalendarReset.
  - TestLimitSetAndReset covers keep/restart, an old key's JSON left
    untouched, and errors.
  - TestKeyLimitDaysCycleAndReset covers the 429 text and header, a
    restart, the cycle boundary, and Reset clearing the token and cost
    caps together.
  - TestKeyLimitCalendarReset.
  - TestGatewayKeyLimitCLI covers 10d, reset and bad args.
- Broken by hand: with reset leaving Since alone,
  TestLimitSetAndReset, TestKeyLimitDaysCycleAndReset and
  TestKeyLimitCalendarReset go red.
- gofmt -l is clean. GOOS=linux and GOOS=windows go vet -tags nogui
  pass on ., access, budget, gateway and gui.
- GUI: the new gateway-key-cycle.test.cjs runs in chromium and webkit ×
  en, zh, zh-TW, ja and de, with a narrow-width check. Also run, in both
  engines: every test using the caller-keys fixture, i18n-keys,
  gui-ja, gui-de and gui-zh-tw (80 pass).
- Real use:
  - Sandbox magpie (temp HOME, gateway 127.0.0.1:3691, dev UI 3692)
    with a fake OpenAI upstream (300+50 tokens a call).
  - `gateway-key limit <id> 1d --tokens 700` allowed 2 calls with curl,
    then a 429 "for this 1-day cycle" with X-Magpie-Limit-Reset a day
    after it was set.
  - Pressed Reset usage in the GUI with Playwright and confirmed. The
    badge was no longer spent and showed 0 of 700, and curl passed 2
    calls again before the next 429.
2026-10-10 22:53:11 +08:00
yetone 8d95ebc8c3 provider: Bailian Token Plan is a preset of its own, with its decision model for routing groups; the Qwen AI platform's decision model too, and Bailian's shows Bailian's icon (#1506, IamMiao)
Alibaba sells two Token Plans, both with sk-sp- keys, and a key works only
on its own host. qwen-token-plan is the Qwen AI platform's
(token-plan.maas.qianwenaiapi.com), but its website and keys links pointed
at Bailian's console. Bailian's own plan
(token-plan.cn-beijing.maas.aliyuncs.com) had no preset.

What changed:
- presets: new bailian-token-plan (chat /compatible-mode/v1, Anthropic
  /apps/anthropic, decide on /compatible-mode/v1/systemone, models from the
  docs' list, shared with qwen-token-plan as alibabaPlanModels).
  qwen-token-plan's links now point at the Qwen AI platform. New
  qwen-decision for Qwen's pay-as-you-go decision model at
  maas.qianwenaiapi.com/compatible-mode/v1/systemone. bailian-decision shows
  the Bailian icon instead of Qwen's.
- decide: bailianDecides also matches the bare maas.qianwenaiapi.com host.
  A chat preset that also decides on a Bailian/Qwen host (bailianApart)
  lists decision-model-preview as its only decision model, so it is offered
  for routing groups and never given to an agent as a chat model.
- gateway: dashScope() covers bailian-token-plan and maas.qianwenaiapi.com.
- CLI help, docs/reference.md and the import docs (en, zh, ja) name the new
  preset.

Usage: neither plan's docs give a usage or quota API; the remaining quota
is only on the console (百炼控制台 Token Plan > 我的订阅, Qwen 工作台
token-plan/individual), which needs a browser session. So no usage card is
added. An exhausted plan's 429 insufficient_quota is already read as out of
credit.

Not tried against the real API: no Bailian or Qwen key was available. The
stand-in is an httptest server copying the docs' systemone curl (Bearer
sk-sp-, model decision-model-preview) and its error table (401 on a wrong
key, 422 on a bad body). qwen-decision sends "Authorization: Bearer <key>";
the Qwen doc's curl shows the bare key, which is untested.

Run:
- go test -tags nogui -count=1 ./... (temp HOME)
- TestBailianTokenPlan, TestQwenDecisionPreset and TestDashScopeHosts fail
  with the old decide.go and gateway.go swapped in
- gofmt -l; GOOS=linux and GOOS=windows go vet -tags nogui on .
  internal/provider, internal/gateway, internal/gui
- GUI: system-one, add-sheet, gateway-decide-info, routing-kind tests in
  chromium and webkit (20 pass)
2026-10-10 21:14:38 +08:00
yetone b6a263b9fd gateway, usage: the Usage page's numbers are read over the gateway, and a Claude Code subagent's call says which subagent and which started it (HoGee_xxl on X)
HoGee_xxl wants their own usage app to read magpie over the gateway,
which had no /api/usage counterpart, and asked for subagents' parent ids.

- GET /v1/magpie/usage (the /api/usage summary, ?period=) and
  GET /v1/magpie/usage/requests (the /api/usage/requests ledger page, same
  filters, offset/limit) on the gateway. The builders moved out of gui into
  internal/usageapi so both serve the same JSON; gui keeps aliases and sets
  usageapi.Clients for agent names (gateway can't import agent). Guard as
  /v1/magpie/quotas: this machine, or another with an enabled gateway key,
  behind the same Host check. A key held to a budget, models or accounts is
  refused the summary (403) and gets the ledger filtered to its own
  CallerKey, with callerKeys/agents/providers/accounts cut to its own rows
  (usageapi.OwnPage): those facets are drawn from every call in the period.
  `path` is left out for another machine.
- usage.Record gains subagent and parent_agent; session stays the parent
  conversation. Gateway rows take them from x-claude-code-agent-id and
  x-claude-code-parent-agent-id; session-file rows from the file name
  (<session>/subagents[/workflows/<run>]/agent-<id>.jsonl, no cache version
  bump) and the parentAgentId of the agent-<id>.meta.json beside it. Both
  packed into the request page's text columns (now 29, msg at 29).
  Codex sub-threads: only kind, as before; no spawned thread on disk to
  take a parent shape from.

Run: real Claude Code 2.1.296 under a sandbox CLAUDE_CONFIG_DIR against a
local fake Anthropic endpoint that made it spawn a subagent from a
subagent: the nested request carried X-Claude-Code-Agent-Id=a143287ac46b82a96
and X-Claude-Code-Parent-Agent-Id=a99ca20c03d1813d8, the first-level one
the agent id only, Session-Id the parent's throughout; the nested meta.json
had parentAgentId. Tests use those bytes. TestUsageOverGateway goes red
with OwnPage, the CallerKey pin, or the header read removed (each tried).
gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
GOOS=windows go vet ./...; set -o pipefail; go test ./... green.
2026-10-10 20:47:00 +08:00
yetone 34a6576cc4 usage: a relay-renamed model with no price is counted at the price of the model its reply said answered (#1498, liuweifeng)
A relay that sells kimi-k3 as moonshot-kimi-k3 answers as kimi-k3, and the
record keeps that as served, but the ledger priced only Record.Model, so
every such call showed "no price" and counted $0 although
relay-a/kimi-k3 has one ($3/$15, cache $0.3/$3 from models.dev).

pricer (which the ledger, the request page, sessions totals, OTel and
NewCoster all use) now falls back to EffectivePriceIn(provider, served)
when the model asked for has no price. The model asked for keeps its own
price whenever it has one, a zero set by the user included, so a ledger
that matched a vendor's bill still does; the served name is only used
where there was nothing. The cache key includes served. Documented
beside `magpie model price` in docs/reference.md.

Run: TestLedgerPricesARenamedModelAsTheOneServed (the reporter's record
byte for byte: priced at $0.0916398; a priced model keeps its own; a
user's 0 stays 0; a model priced by neither name stays unpriced), red on
the old pricer; go test -tags nogui ./internal/usage. Built magpie in a
sandbox HOME with the real models.dev cache and a relay-a custom
provider, the reporter's record in usage.jsonl: `magpie usage today`
shows "≈$0.092" where the old build shows "no price", and `usage --csv`
cost_usd 0.091640. gofmt -l, GOOS=linux/windows go vet clean.
2026-10-10 19:55:29 +08:00
yetone 5fb75d26cf agents: WorkBuddy AI, the international build, gets magpie's models in its own ~/.workbuddy-ai/models.json (#1494, ysicing)
WorkBuddy AI (www.workbuddy.ai, bundle com.workbuddy.workbuddy-ai) keeps
its data in ~/.workbuddy-ai: its cli/product.json sets dataFolderName
".workbuddy-ai", and the custom-models reader (getUserConfigPath in
5.6.2's app.asar) takes ~/<dataFolderName>/models.json when
WORKBUDDY_CONFIG_DIR isn't set. magpie only wrote ~/.workbuddy/models.json,
the China build's, so the reporter's WorkBuddy AI never listed magpie's
models although magpie said it was wired.

WorkBuddy AI is now its own agent, workbuddy-ai, built from the same code
as WorkBuddy (workbuddyBuild): its models.json in ~/.workbuddy-ai, a bare
list as WorkBuddy writes one, under its own key (magpie-workbuddy-ai).
WORKBUDDY_CONFIG_DIR stays WorkBuddy's, so the two rows never write one
file. Its MCP servers and skills go to its own folder too (library target),
and the library's "trust it in WorkBuddy" note names WorkBuddy AI when a
server is given to it. README agent lists and docs/reference.md list it.

Run: go test -tags nogui ./internal/agent ./internal/library
./internal/usage ./internal/gateway (sandbox HOME); new
TestWorkBuddyAIWritesItsOwnFolder (writes ~/.workbuddy-ai only, China
file untouched, env var ignored); GUI library-workbuddy-trust in Chromium
and WebKit, en/zh/zh-TW/ja/de, red on the old library.js for the
WorkBuddy AI case. A built magpie in a sandbox HOME lists "WorkBuddy AI
~/.workbuddy-ai/models.json", and `magpie workbuddy-ai provider magpie`
wrote deepseek/deepseek-chat there with key magpie-workbuddy-ai and no
~/.workbuddy. Not tried in the WorkBuddy AI app itself (needs a signed-in
account); the path is read from the installed 5.6.2's own code. gofmt -l,
GOOS=linux/windows go vet clean.
2026-10-10 19:55:29 +08:00
wei 14255b532a docs: the reference says how to add Google Vertex AI, which models each location serves, and what to do about each of its errors; README lists the preset
The reference's new Google Vertex AI section: what to turn on in the
project and how to sign in, the CLI's pairs and the editor's fields,
the models each location answered with, how to ask for Priority PayGo
and Flex PayGo, and the fix for each failure a user can meet (no
credentials, a sign-in refused, a 403 from Vertex AI, a 403 from IAM
Credentials). Google's pages are linked where they are now, under
Gemini Enterprise Agent Platform, the name Google's documentation gives
Vertex AI today.
2026-10-10 19:21:57 +08:00
yetone cb406c8425 plugins: a plugin can add an agent magpie has no setup of its own for
Plugins could be subscription providers or gateway middleware. Now a third
kind: an agent plugin, so a user whose agent magpie doesn't ship can still
put it on magpie.

- internal/agentplug: a plugin's magpie.agent module (or a *.agent.js file)
  exports agent = {id, name, config, format?, model, prefix?, bin?, dir?,
  ua?, icon?, notice?} and an optional connect({gateway, model, models,
  agent}) returning the other keys to write. Compiled in moejs, reloaded
  when plugins.json or the file changes; why one didn't load is kept.
- internal/jsmod: module compiling (imports kept inside the plugin), moved
  out of middleware so both share it.
- internal/agent/plugged.go: each becomes an Agent (Plugin set) after
  magpie's own. JSON, YAML and env files are edited key by key, comments
  kept; what each key held is stashed typed under plugin:<id>:<path>, and
  its own model or Disconnect puts every key back. A built-in id is
  refused; a connect that throws writes nothing. Key magpie-<id>; usage
  names it by key or ua (usage.PluginAgents).
- GUI Plugins page: an Agent kind chip and glyph, a Discover "Agents"
  section (market kind "agent"), and an installed row line "Adds X to
  Agents" or why it didn't load. zh, zh-TW, ja, de strings.
- Docs: site Plugins page (en, zh, ja) "Agent plugins", reference.md,
  agent-wiring.md, gateway-middleware.md.

Run:
- go test ./... (all ok); gofmt -l clean; GOOS=linux go vet -tags nogui
  ./... and GOOS=windows go vet ./... clean.
- TestPluggedYAML, TestPluggedJSONUnwire, TestPluggedRefused.
- GUI: plugin-agent.test.cjs 22/22 (en, zh, zh-TW, ja, de; 980 and 420;
  chromium and webkit); all plugin-*.test.cjs, i18n-keys,
  deprecated-subscriptions, filter-ime: 315 pass, 0 fail.
- Real use, in a sandbox HOME: an Aider plugin (~/.aider.conf.yml, prefix
  openai/, connect writes openai-api-base/key) installed in a dev build;
  picking DeepSeek V4.1 Flash on the Agents page wired the file keeping the
  user's comment and keys; real aider 0.86.2 `--message` answered through
  magpie from the real DeepSeek account; usage.jsonl recorded agent aider,
  provider deepseek, 200; Disconnect restored the file byte for byte.
2026-10-10 18:39:47 +08:00