Commit Graph
8 Commits
Author SHA1 Message Date
yetone bee3ea6753 claudetui: the first message waits for Claude Code to list magpie's tools (MinhuWang on X)
MinhuWang (X, 2116836405548916907): in the interactive mode the first
message can go before MCP has loaded, and then has none of pi's tools.

Cause: the helper's ready() took the drawn "❯ " prompt as ready. Claude
Code connects its MCP servers beside the prompt, so a message pasted at
once was answered with no mcp__magpie__ tools. Reproduced with the real
Claude Code 2.1.309 (sandbox HOME, a copy of the owner's account): an MCP
server held 8s before answering initialize got "NOTOOL" for "what is the
secret word, use your tool".

Fix: startRun gives claude-mcp-helper a third argument, a `listed` file in
the run's temp folder, which RunMCP writes after it has answered
tools/list. The helper finds that path in the run's --mcp-config
(mcpListed) and ready() waits for it as well as the prompt, inside the
same ReadyWait (45s); past it the run ends saying the tools weren't
listed. Runs without that server (warm-up, model test) don't wait.

Run (mote, at this tree):
- go test ./internal/claudetui ./internal/claudebridge: ok
- go test -run 'Claude|MCP|Bridge' ./internal/gateway: ok
- real Claude Code 2.1.309 here, a sandbox HOME with a copy of the
  account's credentials, the new helper and the real claude-mcp-helper
  behind an 8s sleep: initialize answered at 12.7s, the first turn called
  mcp__magpie__pi_secret and answered "The secret word is PELICAN".
  Without the sleep: answered at 2.1s, same answer. 2.1.309 sends
  server/discover before initialize; the helper's method-not-found answer
  is taken and initialize follows.

Broken by hand: toolsListed returning true made
TestShimFirstMessageWaitsForTools red ("echo: hello (without magpie's
tools)"); RunMCP not writing the file made TestToolsListedFileWritten
red.

Not tried: Claude Code in WSL (the path is the gateway's Windows temp
path, handed to magpie.exe as the callback path is); a Claude Code that
lists tools only on its first request (2.1.309 lists them at start),
which would now wait 45s and fail saying so instead of answering
without tools; the full gateway suite (run after the next commits).
2026-11-01 23:26:57 +08:00
yetone 641f00e4c5 claudebridge: the MCP helper calls magpie back past the agent's proxy (#2440)
ump45nose's TestClaudeToolCallbackOnANonLoopbackAddress was red on their
macOS with "curl: (56) Recv failure: Connection reset by peer". The run
hands Claude Code the proxy magpie gives it for Anthropic (by default the
system's: netproxy.EnvWith), with NO_PROXY of localhost, 127.0.0.1, ::1
and the system's exceptions. A gateway on a LAN or Tailscale address
(MAGPIE_ADDR, #1546) isn't in it, so the helper Claude Code starts, which
inherits that environment, sent its tool callback to the proxy. A proxy
that resets it or can't reach back left the call short of the run, and the
turn with the tool's results found no run waiting. The same path is real,
not only the test's: Go's http client takes *_PROXY for every host but
loopback, and the helper serves Claude, Cursor and Grok runs alike.

The helper's callback is always magpie on this computer, so its client
now uses no proxy at all. The test stand-ins of the helper (the takeback
and fork scripts' curl) call back with --noproxy '*' as it does.

Run:
- Reproduced the report: settings.Proxy on a local listener that resets
  every connection, TestClaudeToolCallbackOnANonLoopbackAddress red with
  the reporter's exact curl (56) reset; green after (temporary edit, not
  kept).
- New TestCallbackGoesPastTheAgentsProxy runs the helper as its own
  process with every *_PROXY on a resetting proxy, calling back to this
  computer's non-loopback address. Red on the old helper ("read: connection
  reset by peer"), green now.
- gofmt -l clean; go vet -tags nogui for darwin, linux and windows on
  internal/claudebridge and internal/gateway.
- Full suite: go test -timeout 45m ./... at a61a6f954 + this change: 65
  ok, internal/provider red in TestSecurityKeychainAnswers only (10.03s,
  the 10s keychainWait on a fake `security` written with os.WriteFile;
  fixed at its cause in the next commit). internal/claudebridge and
  internal/gateway ok.
2026-10-16 02:51:37 +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
tobitege 21702d01ff Add German translation; harden paths against unset env vars (#770)
* Add German translation and harden paths against unset env vars

Add a German locale to the GUI, tray menu, usage alerts and website home page, and refuse to start when the home folder is unset or relative so nothing is written under the working folder; the pi plugin no longer adopts the user's PI_CODING_AGENT_DIR, and an inherited APPIMAGE no longer selects portable mode. Scripts refuse to run from the wrong folder or empty a shared out folder, and a new internal/testenv sandboxes every test package from the user's real files, which also fixes the Claude picker and Termux installer tests on Windows.

* Makefile: know magpie's folder by its go.mod, so paths with spaces work

The check compared $(CURDIR) with $(dir $(abspath …)), which make splits on spaces, so a checkout under 'My Projects' or 'John Doe' refused every target. It now reads go.mod relative to the working folder and wants magpie's module there: make -C and a symlinked Makefile work, make -f from another folder still stops before any recipe runs.

* i18n: German for the strings main added since, with a parity test

75 strings main added (group order, patterns, slow-start wait, usage caps, RTK savings …) get their German, and two that main dropped go. gui-de.test.cjs checks, as gui-ja does, that de has every zh string with its placeholders and tags, and that the window reads in German when picked or on a German system.

* appdir: ignore relative folder variables when reading, keep them for children

CheckEnv no longer unsets anything. magpie reads the XDG folders, APPDATA/LOCALAPPDATA and every agent's folder variable through appdir.Getenv/LookupEnv, which pass over a relative value; the environment stays as it is, so the agents magpie starts get the variable as the user set it. That covers what proc.UserPath lends from the login shell too, which is set after main's check and reached the desktop app unchecked. On Windows a path rooted on the current drive (\Users\x, Git Bash's /c/x) counts as usable, and magpie version and help answer without a home, before run makes any folder.

* Sandbox the tests main added since

internal/wslrun gets testenv's TestMain, and four tests main added that set HOME alone set their home with testenv.SetHome, so on Windows they don't read the runner's profile through USERPROFILE.

* agentenv: PI_CONFIG_DIR and OPENCODE_DB take relative names on purpose

omp puts $PI_CONFIG_DIR under the home and OpenCode a relative $OPENCODE_DB in its data folder, so neither depends on the working folder: appdir no longer passes them over.

* i18n: German for the Library's multi-select and System One's decision API

The 19 strings main added since (#791's skill multi-select, the decision API snippets) get their German; the one main replaced (four APIs → five APIs) goes.

* appdir: tidy the import into magpie's group; say what Go makes of /c/x

The appdir import joins the group of magpie's own imports where a file has one. rooted's comment now says that Go takes a Git Bash path like /c/x as \c\x on the current drive, not C:\x.
2026-10-04 23:30:56 +08:00
yetone 2199eaf76f claude: a tool Claude Code's ToolSearch loads mid-turn is handed to the running subscription session, not a restart with the conversation as text (StringKe on Discord: with ENABLE_TOOL_SEARCH, tool calls came out as raw XML and the turn stalled) — when the client offered a tool the hidden claude -p was never told of, magpie ended the run and started one told the whole conversation in one message, earlier tool calls and results written as text, and its model went on to write its own calls as text. The new tools now go back with the tool results: magpie's MCP helper declares listChanged, swaps its tools, sends notifications/tools/list_changed and answers the call once Claude Code has listed them again (at most 5s). Prompts and headers are unchanged. TestToolSearchLoadKeepsTheRun and TestNewToolsListedBeforeTheAnswer fail without the change; real Claude Code 2.1.286 against a fake API offers the new tool on its next request. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui ./... pass. 2026-10-01 19:44:28 +08:00
yetone 20948e596f gateway: a Grok subscription (SuperGrok, X Premium+) works like a Cursor one — magpie runs the signed-in Grok Build CLI in a home of its own (none of the user's hooks, skills, rules or MCP servers; only search_tool/use_tool, reaching magpie's MCP tools), borrowing the user's token through magpie grok-token without touching their sign-in; the add sheet has a Grok tile that signs in with grok login's device code 2026-09-24 17:35:36 +08:00
yetone c8130269c6 gateway: a Cursor subscription works like a Claude one — magpie runs the signed-in cursor-agent in a home of its own (no user hooks, only magpie's MCP tools allowed), streams its thinking and text, hands tool calls to the client one answer at a time, and a slow tool is collected with magpie_wait; the add sheet has a Cursor tile that signs in through cursor-agent login 2026-09-24 15:49:47 +08:00
yetone 702477525a Claude subscription as a provider; model lists fetched, never compiled in
A signed-in Claude Code is now offered as a provider (claude/…) like Codex
and Copilot. Anthropic classifies another agent's system prompt as
third-party traffic even over Claude Code's OAuth, so magpie drives the
real local claude binary for every generation: the caller's tools are
bridged in over MCP (magpie claude-mcp-helper), and tool results resume
the same Claude Code turn. Token counting is estimated locally so the
OAuth token takes no side path.

No model list is compiled in any more. The built-in catalog, preset
defaults and Claude Code's alias list are gone; the picker shows the
models.dev catalog (refreshed in the background when stale) layered with
each vendor's own /models answer, and signed-in accounts fetch theirs at
start-up. Whether a model rejects temperature/top_p now comes from
models.dev rather than a name prefix.

The gateway retries a Chat request on the Responses endpoint when the
model is Responses-only, and remembers that. Recent calls keep the first
256 KB of request and response bodies, viewable in the call list. The
Usage tab shows subscription allowances (Claude, Codex, Copilot) as the
vendors report them.
2026-09-24 00:20:59 +08:00