Files
magpie/internal/tui
yetone 82962db79a routing: a rule can match the system prompt or the last user message, by words or a regex, with no model asked (SucroseMoE on X)
SucroseMoE asked for routing on plain string and regex matches instead
of an intent model: `system[0] matches /^你是对话标题命名/` → model A,
`user[-1] matches /^正在上下文压缩/` → model B, so any harness's title
and compaction calls can be routed without a classifier.

Two new rule condition fields, beside message/effort/subagent/agent:

- system: any block of the system prompt as the agent sent it (Anthropic
  system blocks, Chat system/developer messages, Responses instructions
  and system/developer items, Gemini systemInstruction). Any block, not
  only the first, because Claude Code's first block is its billing
  header.
- last: any text of the request's last user message as sent, reminders
  the agent adds included, so an anchored ^ still meets a compaction ask.

Ops for both: contains, doesn't contain, starts with, matches (regex,
case-insensitive; a value written /…/ has its slashes dropped). The
gateway reads system and last only when a rule asks (RulesRead), and
decodes raw system JSON lazily then. Like every rule, the decision is
made as a turn starts and its tool rounds keep it.

GUI: Routing → group → Rules, "+" on a rule row offers "System prompt text"
and "Last user message" pills (no modal), with tooltips, placeholders
and the bad-regex mark; zh, zh-TW, ja, de. CLI: `--when "system matches
^You are"`, with aliases system[0], user[-1], last-user. TUI hint, docs
(gateway-routing.md, site start pages) say the same.

Ran, on mote (macOS) until its sshd began refusing connections: gofmt
-l internal/ clean, go vet of provider/gateway/cli/tui, the rule tests;
the routing GUI files (routing-rule*, routing-rules-line,
routing-pause*, group-*, i18n-*, routing-compact, routing-intent-*,
routing-smart-intent) in chromium and webkit: 751 of 781, the 30 reds
being "System prompt" taken by a core word (now "System prompt text"),
routing-rules-line's + menu count (now with system and last), and
routing-intent-entry, red on main since 01a260af4 (#5392, next commit).
Then on the Linux box (wsl-run, magpie-desktop): go vet -tags nogui and
GOOS=windows go vet of the same packages; go test -tags nogui of
internal/provider, gateway, cli, tui, gui; node --check of the routing
plugin; routing-rule-ops, routing-rules-line, routing-intent-entry,
i18n-keys, i18n-en-no-cjk, routing-rule-example in chromium and webkit,
the new test 16 of 16 over four repeats.

Broken by hand: holdsIn's system/last cases returning false turns
TestCondHolds and 8 of TestRuleSystemAndLastText's cases red; dropping
the Anthropic system wiring turns its two Anthropic cases (one the real
Claude Code system fixture) red.

Not tried: a real harness's title or compaction request end to end
through a live gateway; the fixtures are Claude Code's, Codex's and pi's
recorded system prompts.
2026-11-10 18:48:13 +08:00
..