Files
magpie/docs
yetone 9768b384e4 router: find_tools finds tools for a query in Chinese, and names every tool when none matches (Passings_z on X)
Passings_z asked on X (tweet 2123227759409586219) why, with the MCP
router's tools on demand, some tools never get used. An agent given
find_tools and call_tool that asks in Chinese found none of the tools
there were:

- hubWords split only at characters that aren't letters or digits, so
  帮我截个图 was one word, and hubWordIn looked for it whole in the
  description, which an English one never has.
- hubMatch.clears needs two thirds of the query's key words, so
  截图 screenshot failed on a tool named screenshot too: 截图 counted
  against it.
- With nothing matched, the reply named 8 tools a server, so a model
  had no way to the rest.

Now:
- hubWords also cuts where a spaceless script (Han, kana, Hangul) meets
  another (截图screenshot is 截图 and screenshot). A spaceless word is
  cut at characters that say nothing of a tool (hubStopRunes: 我 帮 个
  を …), each piece a key word (帮我截个图 is 截 and 图), found in a text
  when it is one character there or at least half of its two-character
  runs are (hubPhraseIn).
- Key words are matched against the tool's router name, its server's
  own name (a server named in Chinese) and its description.
- A key word with letters not in ASCII counts only for a tool whose
  name, server or description has such letters, so 截图 screenshot is
  screenshot to an English tool. An English query matches what it did.
- No match names every tool of each server when that fits in hubSayMax
  (2000 characters), else 8 a server and that find_tools with an empty
  query names every tool. A query not in ASCII when no tool has such
  letters is told the tools are named and described in English.

Siblings: hubNear (call_tool's close names) shares hubKeyWords and
hubMatchOf, so it takes the same words. The GUI's searches are
substring filters (includes), not this tokenizer; nothing to change.
find_tools' and call_tool's descriptions and the instructions, the text
that goes to the vendor, are unchanged.

docs/subsystems/mcp-router.md: Tools on demand says the new matching
and the no-match reply.

Tests (internal/gateway/hub_find_cjk_test.go):
- TestHubFindInChinese: 截图 screenshot, 截图screenshot, 帮我截个图,
  截取屏幕, 发消息到群聊, 截屏 (a server named 截屏工具) find their tool
  first, and not each other's.
- TestHubFindNotFoundNamesEveryTool: all 12 of a server named, the
  English hint, and past the budget the empty-query hint.
- TestHubFindEnglishAsBefore: 30 English queries match exactly what
  they matched at 14b6b9555.

Run:
- Old code (14b6b9555 with the new test file, on mica):
  TestHubFindInChinese FAIL ("截图 screenshot" matched [], "帮我截个图"
  matched [], 6 of 8), TestHubFindNotFoundNamesEveryTool FAIL (not
  every tool, no English hint, no empty-query hint),
  TestHubFindEnglishAsBefore PASS (as it should).
New code, at base 14b6b9555, on mica (mote's load was over 18):
  gofmt -l prints nothing; go vet ./..., GOOS=linux go vet -tags nogui
  ./..., GOOS=windows go vet ./..., go build, GOOS=linux go build
  -tags nogui, GOOS=windows go build: ok.
  HOME=<temp> go test -tags nogui -timeout 45m ./...: every package ok
  but agent, dirent, gateway and gui. Each red rerun on mica at the new
  code and at 14b6b9555:
  - internal/dirent watch tests: red at both (#7031).
  - TestOpenCodeGoOwnFreeModelGetsNothingOfOpenCodes: red 3 of 3 at
    both (#7117).
  - gateway doneHold.serve "close of closed channel" panic
    (continuation_test.go:781): #6505, #6690; not seen on the rerun.
  - TestWSLAgentFolderIsALink (#7150) and TestGatewayModeListsNoOwnSessions
    (#7064): pass on the rerun at both.
  The new hub tests and every Hub/HubMCP/HubFind test pass.
- Rebased on origin/main 7d5db0f29 (cli plugin hosts, update hint; no
  file in common): go build, go vet ./... and
  go test ./internal/gateway -run 'Hub' run again there: build ok, vet ok, gateway Hub tests ok.
- Not tried: a real agent without its own tool search (e.g. OpenCode,
  Kimi) asking the router in Chinese end to end; the queries tested are
  my own phrasings against real servers' English descriptions plus
  invented Chinese ones, not the reporter's own tool list.
2026-11-19 10:54:42 +08:00
..