Files
magpie/internal/claudetui/command.go
T
yetone 59fdab0af7 gateway: a caller's folder the user hasn't trusted runs in magpie's, not a 502 (lwjef on X)
lwjef (X, 2116867007799030000): a cwd Claude Code hasn't trusted hangs
the interactive-mode bridge (paseo chat).

Cause: in the user's own account the helper leaves the trust question
to the user (no MAGPIE_CLAUDE_TUI_TRUST) and ends at once saying so. Up
to 11-01 that run became -p; since e5f66f8a6 nothing runs as -p, so the
turn got a 502 (endedBefore, "Claude Code asks whether to trust the
folder"). A Claude Code client such as paseo's asks again with backoff
on a 5xx, so the chat looked hung. The real Claude Code 2.1.309 in an
untrusted folder (sandbox HOME, copied account) ends the helper in 1.3s
with that line.

Fix: startTrusted runs startRun, and when the helper ended over the
trust question (its stderr read to the end, saidOnEnd) in the caller's
folder under the user's own account, remembers that folder for 10
minutes (passedOver) and starts the run once more in magpie's own folder,
told the caller's (envElsewhere), as a caller on another computer is.
Only one retry: a second refusal is returned as before. The saved-session
retry in start goes through startTrusted too.

Run (mote, at this tree):
- go test -run 'Claude|MCP|Bridge' ./internal/gateway: ok
- TestClaudeTUIUntrustedFolderAnswered: ok

Broken by hand: saidOnEnd returning false made the new test red (502
"exited before it answered magpie's initialize request ... trust the
folder"); passedOver turned off made it red with the same 502 after one
retry. An earlier draft that retried through start itself looped forever
with passedOver off; the retry is bounded to one since.

Not tried: a real gateway turn from paseo; the real helper and Claude
Code were run on each side of the retry (untrusted folder ends at once;
a trusted magpie folder answers), not through a live gateway. A user who
trusts the folder within 10 minutes still runs in magpie's folder until
then.

At the pushed head's tree, on origin/main 79f83798f (which has 2b52302dc,
crosscn's 400KB fix), on mote: gofmt -l is clean, and go vet
./internal/... is ok for darwin, windows and linux. go test -timeout 45m
./internal/claudetui ./internal/claudebridge is ok. ./internal/gateway is
ok except TestCodexPoolSaysTheClientsVersion, which fails the same way in
a gateway run at origin/main 79f83798f itself and passes alone at both
(#4807, filed here). The conflict with main's tuiRefusal and replay change
in start() was resolved by keeping main's req.told and calling
startTrusted. Before the rebase, the three packages were ok on
magpie-desktop (Linux) too.
2026-11-01 23:47:47 +08:00

40 lines
1.8 KiB
Go

package claudetui
// Command is the hidden subcommand that runs it.
const Command = "claude-tui-helper"
// TrustEnv, "1", has the shim tell Claude Code yes when it asks whether
// to trust the folder it runs in: the bridge sets it for magpie's own
// folder, and for a caller's in an account folder of magpie's, whose
// Claude Code no one else runs. Otherwise the question is the user's to
// answer in their own Claude Code, and the run ends, saying so.
const TrustEnv = "MAGPIE_CLAUDE_TUI_TRUST"
// Untrusted begins what the helper says, on its stderr, as it ends over a
// folder it wasn't told to trust: the bridge then runs the turn in a
// folder of magpie's.
const Untrusted = "Claude Code asks whether to trust the folder"
// WSLEnv holds, as JSON (WSL), how to run a Claude Code that is in a WSL
// distro: the helper, on Windows, runs wsl.exe in its pseudo console.
const WSLEnv = "MAGPIE_CLAUDE_TUI_WSL"
// WSL is a Claude Code in a WSL distro, as the helper runs it.
type WSL struct {
// Args are wsl.exe's arguments up to Claude Code's own, its path last
Args []string `json:"args"`
// Mount is where the distro mounts Windows' drives ("/mnt/"): an
// image's path is pasted as Claude Code there reads it
Mount string `json:"mount"`
// Projects is Claude Code's projects folder, as Windows reads it
Projects string `json:"projects"`
}
// MCPCommand is the hidden subcommand of magpie's tool server, the MCP
// server a run's --mcp-config names "magpie" (claudebridge.RunMCP). Its
// arguments are the callback's file, the tools' file and, for the
// interactive mode, a file it writes once Claude Code has listed its
// tools: the first message waits for it (MinhuWang on X: a first message
// sent before then had none of the agent's tools).
const MCPCommand = "claude-mcp-helper"