Commit Graph
5 Commits
Author SHA1 Message Date
yetone c8eb7b3877 search: a search API's keys are a list, each switched off, moved and removed on its own
Web search took one key per API in one field (辰林鸭~ on Discord: only one
Tavily key). Settings › Models › Web search now lists an API's keys under
it as a provider's accounts are: each masked on its own row with a tick
(off / on), Show, Copy and Remove; several pasted at once (commas,
semicolons, lines), the reply saying how many were new and how many it
had; the order changed by dragging or Alt+↑/↓. A resting key says why and
until when on its row ("asked last until 14:05: rate limited"), from the
gateway's rest (SearchKeyRest, SearchQuota.Ref); rotation on 401/403,
402/432/433 and 429 (#1477) is unchanged.

provider.SearchAPI keeps Key as the keys on, comma-joined, so the gateway
and an older magpie never ask one switched off; keyList is written only
while a key is off. A Key that differs from the list (an older magpie, a
sync) wins, its keys on in its order, the list's off keys after. The last
key on can't be switched off or removed. The GUI names a key by
SearchKeyRef (a hash): POST /api/settings/search-keys (add, ref+on,
ref+remove, arrange) and /api/settings/search-key with ref. Saving an API
with no key keeps its keys, off ones too. Backup and WebDAV sync carry
the off keys, or leave them out with the rest. `magpie search` says
"+N off". docs/subsystems/gateway-routing.md has "The keys as a list".

Run (mote, at this tree, base 3441035a2):
- go test -count=1 ./internal/gui ./internal/provider ./internal/backup
  ./internal/davsync ./internal/cli: ok but gui's
  TestPanelHiddenByWailsMarksPageOutOfSight (#5322, mote, untouched) and
  cli's TestEveryRouteHasACommandOrIsNamed, then fixed (search-keys named
  S2) and run again: ok. ./internal/gateway search tests ok earlier.
- node --test search-key-list, search-keys, search-api, search-signs-in,
  search-order: 84/84, Chromium and WebKit, en/zh/zh-TW/ja/de, 1100 and
  420px (search-api/order at their own widths). i18n-keys: only "a
  plugin's words are its own" red, as on main (#5332, #5426, #5482).
- go build ./..., go vet ./..., GOOS=linux go vet -tags nogui ./...,
  GOOS=windows go vet ./...: ok. gofmt -l: clean.

Broken by hand, each red then restored:
- SetSearchAPI drops KeyList: provider and gui tests red.
- backup clears Key only / davsync merges Key only: their tests red.
- off keys still put in Key: provider, gui, backup and gateway red.
- the whole key in /api/state: TestSearchKeyListFromSettings red.
- no last-key-on check: TestSearchKeyList red.
- settings.js at HEAD: search-key-list.test.cjs red.

Not tried: a real Tavily account with several keys (the vendor is faked;
no test reaches the network); the real app window (the GUI ran in
Playwright only); Windows and Linux runs of the tests (vet only). The
full Go and GUI suites run after the push, under mote's suite lock.

Reported-by: 辰林鸭~ (Discord)
2026-11-07 21:21:48 +08:00
yetoneandmdwsk88 30a0bfe889 gateway, provider, cli: search APIs marked mix are asked together, their pages merged (#2845)
A search asked the search APIs in order and gave the model the first
one's pages. On #2845's 80-query benchmark no single API was best on
both sets. The deduplicated union of two or three APIs' pages scored
higher than the best single API and lost no query (60-query set: 108 to
114-117 of 120, sign test p <= 0.03).

Off by default. When two or more search APIs are marked mix
(SearchAPI.Mix), they are asked first, at once (askSearchAPIsTogether).
Each uses its own keys and timeouts, as when it is asked alone
(askSearchAPIKeys). Their pages go to the model in turn: each API's
first page in the saved order, then each one's second. A page an
earlier API already gave is left out by its address (pageKey). One
that fails or finds nothing leaves the others' pages. When none finds
anything, the APIs not mixed are asked in order. With fewer than two
mixed APIs on and ready, a search runs in order as before. No text
says which API found a page, so what a vendor sees reads as before.

MixSearchAPIs marks the vendors named (two or more, set up, each once)
and clears the rest; none clears all. SetSearchAPI keeps the mark, as
it keeps off, since Settings sends an edit without it. Backup copies
the whole entry, so the mark carries over. CLI: magpie search mix
<api>,<api>, magpie search mix off, and magpie search lists a mixed
one as mix. docs/subsystems/gateway-routing.md has a section on it.

Ported from mdwsk88's 2966cce77 and reviewed line by line. What
changed from it:
- The cap follows the search's count (#5545, the commit before this):
  searchMixMost is 2 x the count a search asks for, at most 20
  (searchHitsMost). The default stays 12 pages, as in the patch.
  TestSearchAPIsMixedCapped is a table over count settings and named
  counts.
- The CLI keeps both search count and search mix.
- No Settings toggle. The mode stays CLI-only, by the UI-restraint
  rule; the docs say so.

Run (mote-run):
- go test -count=1 -run "Search|Mix" ./internal/gateway/: ok; -race
  -run "TestSearchAPIsMixed|TestMixSearchAPIs": ok.
- go test ./internal/provider/ ./internal/backup/: ok; ./internal/cli/
  -run "TestSearchCLI|TestEveryRoute": ok.

Broken by hand: with apiSearch's mixed branch turned off,
TestSearchAPIsMixedAskedTogether fails (only the first API's pages)
and TestSearchAPIsMixedCapped fails ("count set 0, named 0: 6 pages,
want 12"). Restored, both pass.

Not tried: a real search with two vendors' live keys. The tests use
fake search APIs.

Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
Reported-by: mdwsk88 (dawei on Discord)
2026-11-07 04:03:01 +08:00
yetoneandmdwsk88 4e0e8e7933 gateway, settings, gui, cli: the results a search is answered with can be set, 1 to 20 (#5545)
Claude Code's WebSearch and Codex's web_search never name a count, so
magpie answered every such search with searchHits, 6 pages (#5545,
mdwsk88: more pages for research-heavy work, fewer to save context).

settings.SearchCount holds the count. 0 means the default, 6
(SearchCountDefault), and the most is 20 (SearchCountMost), the most
Brave and Tavily return. Save refuses a value out of range, so nothing
is written. Settings.SearchPages reads it. The gateway's searchCount
falls back to it when a search names no count. The web_search MCP tool
still answers a named count with that count, and its schema's default
says the count set. It reaches every search API (Brave, Tavily, Exa,
You, the plugins' searchers), as a named count already did.

- Settings › Models › Web search: "Results per search", segments 3, 6,
  10, 15 and 20, plus a count set by hand in settings.json.
  POST /api/settings/search-count sets it alone. settingsapi.Apply
  keeps it as it keeps search-all, so a save of the Settings form
  doesn't put it back.
- CLI: magpie search count says the count; magpie search count <n>
  sets it; magpie search count default puts 6 back. A bad value is
  refused and nothing is written.
- docs/subsystems/gateway-routing.md says it.
- New strings are in zh, zh-TW, ja and de.

Run at this tree (mote-run, macOS):
- go test -count=1: internal/settings, settingsapi, cli, gateway
  (TestSearchMCPCount, TestSearchCountReachesEveryAPI,
  TestSearchCountSetting), and gui (TestSettingsSearchCountSetOnItsOwn, and
  TestSettingsSaveKeepsWhatItDoesNotSend with SearchCount set): ok.
  internal/gateway whole: ok with -timeout 45m (847s). internal/gui
  whole: ok but TestMainWindowCorners/macOS_26_SDK (#3949, mote is on
  macOS 27).
  The first cli run was red on TestEveryRouteHasACommandOrIsNamed:
  the new route had no CLI entry. cliForRoute maps it to search count
  now.
- Broken by hand: searchCount returning searchHits again makes
  TestSearchCountSetting fail ("set 11: a search naming no count asks
  for 6, want 11"). Restored, it passes.
- GUI: node --test --test-concurrency=4 over routing-*, usage-*,
  ledger-*, panel-*, call-*, search-*, searcher-*, settings-*, i18n-*
  and gui-* (Chromium and WebKit; the files cover en, zh, zh-TW, ja
  and de), with #2398 and #5545 in one tree: 4961 of 5016 ok. The 55
  reds are in 12 files. i18n-keys' "a plugin's words are its own"
  names other files' strings (#5327, #5426, #5482). The other 11 files
  were run alone at dc49feca9 (this tree without either change) and at
  this tree: 52 and 51 reds, the same tests. The one apart is
  usage-focus-steady, which flakes (#3501). Each is filed: #5392,
  #3414, #5048, #3799, #3415, #3954, #4627, #4628, #5223, #1529.
  routing-canceled-row.test.cjs: 10 of 10. With the .rt-req.gone rule
  taken out, its dot is the answered green rgb(24, 154, 88) and it
  fails. Restored, it passes.
- Not tried: a real Claude Code WebSearch through this tree with a live
  search API key. The tests use fake search APIs.

Co-authored-by: mdwsk88 <11055210+mdwsk88@users.noreply.github.com>
Reported-by: mdwsk88 (dawei on Discord)
2026-11-07 04:03:01 +08:00
yetone ec13d1162a search: the search APIs are dragged into the order they are asked in, and each switches off without losing its key (#2286, blackrion)
The search APIs were asked in the order they were added, and the only way
to keep one out of the chain (to try another alone, or rest one whose
credit is nearly spent) was to remove it and paste its key again later.

- provider: SearchAPI.Off; SearchAPIs() leaves an API switched off out, so
  neither a model's search nor the web_search MCP asks it. SwitchSearchAPI
  keeps key, URL and place; SetSearchAPI keeps Off. ArrangeSearchAPIs puts
  them in the vendors' order, refuses an unknown or twice-named vendor, and
  keeps one not named after them. RestoreSearchAPIs now puts a backup's
  APIs in the backup's order (one only here after them), so a restored
  order and Off come back as they were; sync already mirrors the list.
- GUI: each API's row and its keys' row are one unit, dragged off its
  buttons with dragRows (as routing's groups, #779) or moved with Alt+↑/↓,
  renumbered at once, focus kept, redrawn as saved if the order is
  refused. A lib-switch per row posts {vendor, on}; one off is dimmed and
  says Off; Search first with counts only APIs that are on. The row's
  buttons wrap instead of running past a 420px window.
- CLI: magpie search off|on <api>, move <api> <n>; the list says off.
- POST /api/settings/search-api takes {arrange} and {vendor, on}.
- Docs: gateway-routing "The search APIs' order, and one switched off",
  gui-shell, README (en, zh-CN).

Run: go test -tags nogui ./internal/provider ./internal/cli ./internal/gui
./internal/gateway (TestSearch*) ./internal/backup ./internal/davsync;
GOOS=linux/windows go vet of the touched packages; gofmt -l clean.
GUI: search-order.test.cjs 16/16 (chromium + webkit, en/zh/ja/de,
1100/420), and search-api, search-first, search-instead, search-keys,
search-mcp, searcher-pick, i18n-keys, gui-ja, gui-de, gui-zh-tw 100/100.
Broken by hand: SearchAPIs without the Off filter turns
TestSearchAPIOrderAndOff and TestSearchCLIOffAndMove red; the GUI
counting off APIs for Search first turns search-order red.
Full suite: SUITE_LINE
2026-10-15 23:08:00 +08:00
yetone 23e764d0e0 cli: magpie's commands move from the root into internal/cli; the root keeps only main.go
The root held 89 .go files (30 commands, 59 tests). They move as they are
to internal/cli (package cli), with git mv so history follows them. The
only code change is main() becoming cli.Main(version): the root's new
main.go keeps `var version` in package main, so -ldflags "-X
main.version=…" in the Makefile, the Dockerfile and magpie-releases, and
every workflow, work unchanged. go-winres's rsrc_windows_*.syso still land
next to package main in the root.

Tests that read testdata by a root-relative path now go up one level
(../plugin/testdata/fake, ../sessions/testdata). Five subsystem doc links
point at internal/cli/.

Run:
- go build ./..., gofmt -l, go vet on darwin, linux and windows (nogui)
- builds with tags production, dev, "production nogui"; windows
  -H windowsgui; linux CGO_ENABLED=0
- make release-cli TARGETS="darwin/arm64 linux/amd64 windows/amd64
  android/arm64" VERSION=9.9.9-tidy: all four built, binary prints
  "magpie 9.9.9-tidy"
- docker build --build-arg VERSION=7.7.7-tidy: container prints
  "magpie 7.7.7-tidy"
- go test ./internal/cli (default and nogui): 152 tests, the same count
  as the root on main
- go test ./...: all packages pass (agent, gateway, library, provider
  timed out at 10m under other sessions' load and passed rerun alone
  with -timeout 40m; none of them changed)
- the built binary in a sandbox HOME: version, help, ls, providers,
  claude, and an unknown command's error
2026-10-12 20:40:22 +08:00