A claude magpie spawns runs --dangerously-skip-permissions: the flag is
on the bridge's own arguments, a user's claude may be a wrapper that
adds it, and an account's default mode may be Bypass Permissions. Where
no settings source the run reads has skipDangerousModePermissionPrompt,
Claude Code 2.1.295 blocks on its disclaimer — "❯ No, exit / Yes, I
accept, Enter to confirm" — and no one was there to answer it: each run
sat on the dialog for 45s (ReadyWait), ended, and the next run asked
again, so interactive requests failed in a loop (502 or a hung restart)
until magpie fell back to claude -p.
- the helper tells the disclaimer yes where TrustEnv says so, with the
same ↓-until-"Yes"-then-Enter the trust question gets (its "No, exit"
pairs the same, and a key sent as it is first drawn is lost the same
way); Claude Code records the acceptance itself, and the next run is
shown none of it.
- where TrustEnv isn't set — the account Claude Code is signed in to, in
a caller's folder — the disclaimer is the user's to answer: the run
ends at once saying so, not after 45s.
- a disclaimer left unanswered at a run's deadline is named as such
("asked to accept running in Bypass Permissions mode, not answered"),
never "showed no prompt".
Generated-by: GLM-5.3-Flash (ZCode)
Reviewed and ported, narrowed: as written, the shim accepted the
disclaimer wherever TrustEnv was set, and the bridge sets TrustEnv for
magpie's own folder in the account Claude Code is signed in to
(configDir ""), as do the warmup and /usage runs. Accepting there makes
Claude Code write skipDangerousModePermissionPrompt into the user's own
~/.claude/settings.json, a consent for every run after that is the
user's to give. Now a separate claudetui.BypassEnv says yes, set only by
claudeBypassEnv for a tui run in an account folder of magpie's
(configDir != ""), at the bridge and both warmup sites; TrustEnv alone
ends the run at once with the "asks to accept" message. The subject's
"as the trust question is" holds for the keys sent, not for where.
On mote, with tui.go at the parent: TestShimAcceptsBypassDisclaimer FAIL
("the shim wrote 0 lines of 3 in 30s"), TestShimNeverPrints' bypass
cases FAIL ("neither answered nor ended in 30s"),
TestShimEndsAtItsCallersDeadline/bypass_disclaimer_unanswered FAIL
("showed no prompt"); green with the patch. Broken by hand: the gate
back on TrustEnv turns TestShimNeverPrints/bypass_disclaimer_with_the_
folder_trusted red, and claudeBypassEnv ignoring configDir turns
TestClaudeBypassOnlyInMagpiesAccountFolder red ("user's own account: got
[MAGPIE_CLAUDE_TUI_BYPASS=1]"). go test -timeout 45m ./internal/gateway
and ./internal/claudetui ok; GOOS=linux/windows/darwin go vet ok. Not
tried: a real Claude Code 2.1.295 showing the disclaimer under a saved
account (needs a wrapper adding the flag).
Co-authored-by: ggbdpq <ggbdpq@gmail.com>
62 lines
3.0 KiB
Go
62 lines
3.0 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"
|
|
|
|
// BypassEnv, "1", has the shim tell Claude Code yes when it asks to accept
|
|
// running in Bypass Permissions mode (a user's claude that is a wrapper
|
|
// adding --dangerously-skip-permissions, or an account whose default mode
|
|
// it is; #5042). Claude Code records the acceptance in its config folder's
|
|
// settings.json, for every run after, so the bridge sets it only for an
|
|
// account folder of magpie's, whose Claude Code no one else runs. In the
|
|
// account Claude Code is signed in to the acceptance is its user's to give,
|
|
// and the run ends at once, saying so.
|
|
const BypassEnv = "MAGPIE_CLAUDE_TUI_BYPASS"
|
|
|
|
// DeadlineEnv holds, in Unix milliseconds, when a one-off run's caller
|
|
// (a /usage read, a test's "hi") stops waiting for it. The helper ends
|
|
// then on its own, saying on its stderr what Claude Code hadn't done and
|
|
// what it last drew. Killed at the caller's deadline instead, it said
|
|
// nothing, and the reading's error was its exit code alone, "exit status
|
|
// 1" on Windows (#4830).
|
|
const DeadlineEnv = "MAGPIE_CLAUDE_TUI_BY"
|
|
|
|
// 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; ""
|
|
// with Distro set when Windows can't, or its home is unknown: the
|
|
// transcript is then read inside the distro (wslread.go)
|
|
Projects string `json:"projects,omitempty"`
|
|
// Distro is the distro, as wsl.exe -d names it
|
|
Distro string `json:"distro,omitempty"`
|
|
}
|
|
|
|
// 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"
|