An agent in a WSL distro under NAT reaches the gateway at Windows'
address, where only a named key is taken; magpie writes it the sharing
key while sharing is on (keyAt). One connected while nothing was shared
was written gateway.Token, and turning sharing on afterwards left it
there: tried on the Windows box with magpie-desktop (NAT), Codex · WSL
connected, then Settings → LAN sharing on, `codex exec` in WSL was 401
"not an enabled magpie gateway key" on every try. #1488 (91581fca2) did
this for the library's relayed MCP servers only.
The LAN toggle now takes agent.OnGateway() before ConfigureLAN and
agent.Rekey()s the ones that reach the gateway beyond loopback after it:
on, off and a new key alike. Rekey shares setAgain with Rewire (the port
move), so what the agent had before magpie stays stashed. An agent that
can't be set again is said on the Settings page (settingsJSON.rekeyed).
Run: TestRekeyGivesWSLAgentTheSharingKey (red with Rekey made a no-op:
key "magpie"), TestRekeyLeavesLoopback; go test ./internal/agent and
./internal/gateway alone green (the full ./... run timed both out at
10m under load average ~200, each test then 1-5s in); gui green in the
full run; gofmt, go vet (darwin, windows; linux for internal/agent).
Real use on the Windows box (this commit cross-built, sandbox HOME,
port 3436): sharing off then on rewrote the WSL Codex token to the
sharing key, and `codex exec "Reply with exactly: hi from wsl"` in
magpie-desktop answered through the gateway (Gateway page: codex
deepseek/deepseek-flash responses 200).