ac4af582301a4e8a29245dbba767eba31334ddf9
35
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
8fa3c60f80 |
claude: an interactive run takes many images between words (#5654)
Chapin2018's message of nineteen images between words (the issue's
script, Claude Code 2.1.319, claude-fable-5-1) ended the interactive
helper "after 13s (exit status 1)" and the client got a 502, while -p
answered. The cause is how the helper saw a paste taken. It looked for
"[Image #N]" and "[Pasted text #N" only in what Claude Code drew after
the paste. Once the prompt runs past a row, Claude Code draws it again
only where it changed and moves the cursor past cells that are already
right. After the 33rd piece the drawing held "\r\x1b[16C\x1b[1B3": one
digit of "[Image #33]". The helper waited out pasteWait (10s) and ended.
Text marks came out in part too ("[Pasted t xt #16"), so several word
pieces each sat out their own 10s before that. There is no limit in
Claude Code's TUI: the same paste is on its screen whole, so no -p
fallback is needed.
Each check now also reads the prompt as the 200x50 screen grid shows
it: the rows between its last two rules, words one space apart (a mark
can wrap onto the next row). The mark that ends it counts (lastMark),
an image's [Image #N] or a whole [Pasted text #N +k lines], numbered
past the piece before, and so do words the prompt ends with. The
stream check stays first.
Run:
- Real, macOS arm64, this Mac, sandbox HOME and CLAUDE_CONFIG_DIR
(token by env, nothing rotated, DISABLE_AUTOUPDATER=1), the issue's
script unchanged, --images 19, Claude Code 2.1.319:
- origin/main
|
||
|
|
999ba6a00e |
claudetui: a replayed history keeps its words when one of its lines names an image file and an image follows (#5548)
#5548, Suge8 (magpie 0.1.3106, Claude Code 2.1.318, macOS, interactive mode, Pi over OpenAI Chat): a compacted Pi conversation told whole to a new Claude Code reached it as its four images and the closing notes only; the history, which had `ls` output naming screenshots (a.jpg, …), came into the next prompt, out of order. Cause: send pasted a message's text piece and, without waiting for it to show, the image after it; only the last text piece was waited for. Claude Code 2.1.318 tries each pasted line ending in .png, .jpg, .jpeg, .gif or .webp as an image file before it takes the words in (for a relative name it asks the clipboard through osascript, about 0.45s), and keeps one "pasting" mark for every paste. The image's read ended first and cleared it, so the Enter after the closing notes sent the prompt without the words. Fix: - send waits for every text piece to show before the next piece, not only the last one. - shown counts a "[Pasted text #N" only with N past the paste before it, else the words' own last line: images and pasted text share Claude Code's numbering, so send keeps one number for both, and the prompt drawn again shows the earlier "[Pasted text #1". An inline paste (800 bytes and 2 line breaks at most) takes no number in 2.1.318, so the number stays exact. A paste not shown within shownWait is still gone past, as before. - Every paste goes through send, the WSL and queued (busy) messages too; a message of an image alone has no text to wait for, and one of text alone was already waited for. Tests: the fake Claude Code now does what 2.1.318 does here: it draws a long paste as "[Pasted text #N +B lines]" numbered with the images, draws the prompt again as a paste starts, takes words naming an image file in after 1s, and keeps one pasting mark (an Enter while it is set is lost). TestShimWaitsForWordsNamingImages sends [words naming foo.png, image, an ls naming bar.png and baz.png, image, closing notes], and the same naming .txt files. TestShimPastesImages now expects its second image as #3: the "and" between two images is 4 line breaks, pasted text as 2.1.318 numbers it. Run, at this tree on |
||
|
|
325dc3ab32 |
claude-tui: a Claude Code that draws nothing is said with what it waits on, and its turn isn't waited out twice
sowhynot (v0.1.3222, macOS): every interactive run ended "Claude Code showed no prompt in 45s: nothing on its screen (0 bytes read)", and the bridge then started a new Claude Code told the whole conversation, which waited out another 45s before the turn was answered 502. Cause class: Claude Code blocks before its first draw on something it waits for and writes nothing to the pty. Reproduced on mote with real Claude Code 2.1.319 (npm latest) in a sandbox HOME: its read of the "Claude Code" Keychain item is a synchronous `security find-generic-password` with no time limit (its other Keychain reads have 2s/10s limits), so a Keychain waiting on an allow window or a locked keychain gives exactly "0 bytes read" at 45s. Its network waits (remote managed settings and policy limits, for a setup-token or team account with --mcp-config) are bounded at ~30s and draw after, so they don't give 0 bytes. - claudetui: with 0 bytes read, the reason adds what Claude Code runs (its descendants from ps, longest first) and how much it holds; a Keychain read is named with its item and what to do. Other commands are named by program (and an interpreter's script) only, never their arguments. macOS and Linux; Windows says what it said before. - gateway: a helper that ends saying why the interactive mode didn't come up is tuiNoStart, not tried again told the whole conversation, unless Claude Code ended itself before its prompt (claudetui.EndedEarly, the "No conversation found" case the retry is for). - No early end on 0 bytes: a Keychain window may still be answered. No -p fallback: removed on purpose in |
||
|
|
82403f9f6d |
claude: /usage is read through -p, never the interactive mode, which opened idle accounts' 5-hour window (#5582)
Since v0.1.2635 ( |
||
|
|
9e6687e3a5 |
claudetui: the Claude in Chrome offer is declined once it has stayed drawn, and an error never ends on an empty screen
sowhynot (Discord, magpie 0.1.3216, Claude Code 2.1.319, macOS, Claude
Pro, interactive mode): every request and the endpoint test failed with
"claude-tui: Claude Code showed no prompt in the 21.9s its caller waits
for it:" and nothing after the colon; `claude -p` worked.
Cause: where the Claude in Chrome extension is installed and Claude
Code's tengu_chrome_auto_enable flag is on, 2.1.319 opens its
ChromeAutoEnableDialog as it starts (a claude.ai sign-in, no answer
recorded). The helper cleared its screen and sent Esc the moment it saw
"keep browser tools off". The dialog turns away a key that comes just
after it opens (refuseInput/refusedWithin) and draws nothing again for
it, so the screen the helper read stayed empty: nothing matched again,
the run waited out its caller, and lastScreen() had nothing to say. The
decline is never recorded, so every run met it again.
Fix:
- The offer is answered through onboard(): Esc once it has stayed drawn
trustSettle, at most onboardTries times, then an error that says the
offer takes no answer.
- seen(): with nothing drawn since the screen was cleared for
redrawWait (1.5s), ready() reads the screen as it stands (the grid),
so a key lost to a dialog that draws nothing again is sent again.
- What the run hadn't done is read from the screen as it stands too:
"asked whether to use Claude in Chrome, not answered".
- lastScreen(): with nothing drawn since a clear it gives the grid's
text, and with nothing on it, "nothing on its screen (N bytes read)".
There is no -p fallback for the one-off runs (the endpoint test, a
/usage read) by design: the shim never turns into -p (TestShimNeverPrints).
Run, on mote at this tree (base
|
||
|
|
77031d5817 |
claude usage: a /usage panel with no window is no window started, and a failure says why
koohoko5924 (Discord #help, v0.1.3057, macOS): a Claude Enterprise
account with a five-hour window only. A manual refresh took ~5s and
gave the card no window and the error "Claude Code's usage showed no
usage figures: ▐▛███▜▌ … magpie-claude-work…": Claude Code's banner,
not a reason.
Claude Code 2.1.316's Usage tab (gi) draws a window only once
Anthropic's answer has it non-null, and a window is null until the
request that starts it. An idle 5h-only account's panel loads with
the session's cost, maybe the plan's credit bar, and no window. The
helper told that panel's words, joined from the top of the screen, and
the card took them as a failure with the banner first.
- claudetui: a panel that loaded (tabs, Session/Total cost, nothing
loading, refreshing, stale or failed, no gateway Spend limit) with no
"Current session"/"Current week" is told as NoUsageWindow ("No usage
window has started"). The provider reads that as no window started:
no error, the unstarted 5h window as for any account.
- claudetui: the two rate-limit errors gi draws ("Claude is temporarily
limiting requests to the usage page (not your usage limit)…",
"Usage endpoint is rate limited until …") are failures to load, like
"Failed to load usage data": retried once, then told as an error with
the panel's own "Error: …" text, never the banner. A panel with no
window and no error is told from its tabs on, the session's cost
lines left out.
- provider: "(not your usage limit)" no longer reads as an account
refused (claudeDenied, at every place claudeUsageDenied judged a
reading: the CLI parse, codex_switch, quota_last, subscription_usage).
Counts ("Last 7d · 403 requests …") are taken out wherever they sit in
a line before that check, as the panel's words come on one line now.
A no-figures error keeps every line (600 runes), not the first clipped
at 120.
Tests are built from 2.1.316's own strings (ko/gi/hi in the bundled
cli.js), drawn on the helper's 200x50 grid row by row. Guessed: the
exact bytes of a real Enterprise panel (not captured; no such account
here) and the credit bar's layout.
Run (mote, at this tree): go test ./internal/claudetui ./internal/provider
-run 'Usage|Claude|Shim|Quota|Codex' ok; go vet for claudetui, provider,
gateway; GOOS=linux -tags nogui and GOOS=windows go vet; gofmt -l clean.
Broken by hand (each red, then restored):
- the NoUsageWindow case off: TestShimReadsUsageWithNoWindow red in all
three panels (told the panel's words as success);
- the provider's claudeNoWindow branch off: TestClaudeUsageNoWindowStarted
red ("showed no usage figures: No usage window has started");
- claudeDenied back to claudeUsageDenied: TestClaudeUsageWhyKept red
("read as an account refused");
- usageFailed back to "Failed to load usage data" and the whole screen as
the reason: TestShimToldWhyUsageFailed red in all three (the banner as
the reason; the rate-limit panels told as no window), TestUsageNoWindow
red.
Not tried: a real Claude Enterprise account; a real rate-limited panel.
|
||
|
|
b7631300ec |
claudetui: a successful interactive turn tells its account's allowance
Since the interactive mode replaced -p for Claude subscription turns ( |
||
|
|
6b4a6dcd41 |
claudetui: the Bypass Permissions disclaimer is answered as the trust question is (#5042, luzhuang)
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>
|
||
|
|
fe6533ad8b |
claudetui: Claude Code's exit is recorded once its last words are read (#5283)
The shim closed `exited` as soon as cmd.Wait returned, which can be
before the PTY reader has read what Claude Code wrote just before it
ended. Every "Claude Code ended ..." error then carried an empty screen
in place of the reason it gave, which is what TestShimNeverPrints/
failed_start saw on a loaded ubuntu CI runner (run 41899504898):
"ended before it showed its prompt (exit status 3): " with no
"something went wrong". The shim's own stderr line is meant; the test
checks the reason is in it.
Now the exit goes through shim.ended: on Unix it waits for read to end
(the master reads EIO once the last slave writer is gone), on Windows,
whose pseudo console stays open, until reading has gone quiet for 250ms
after its first bytes; two seconds at most either way, for a terminal a
child of Claude Code keeps open.
Run:
- Red before: with a 200ms sleep injected at the top of read(), the old
code failed failed_start 5 of 5 on Linux (wsl-run, magpie-desktop)
with CI's exact message; with the fix and the same injection, 50 of 50
green. Without injection the old code passed 300 of 300 there (an
idle machine never loses the race).
- New TestShimEndedAfterLastWordsRead (a reader given the last words
300ms late, terminal ending and staying open). Broken by hand (ended
records at once): red on both subtests; restored: green 20 of 20 with
TestShimNeverPrints on Linux.
- internal/claudetui: Linux (wsl-run) -count=3 ok; macOS (mote-run)
-race -count=2 ok; Windows (win-run) -count=2: only
TestShimFirstMessageWaitsForTools red, the same at origin/main
|
||
|
|
dd61299231 |
claudetui: /usage's saved figures, drawn while Claude Code refreshes them, are not told as today's
jsc9495 (Discord #help, 0.1.2950+, Claude Max): on one account at one
moment magpie's card said 5h 92% / 7d 99% left, another app 53% / 94%.
Claude Code 2.1.316's /usage panel draws the figures it saved on its last
read (cachedUsageUtilization in .claude.json, used up to an hour old,
keyed by accountUuid) at once, with "Refreshing…" under them, while it
asks Anthropic for today's. When that fails it keeps them and says
"Showing last-known usage as of 20m ago (rate limited until …)" or
"… (could not refresh)". The helper took any figures that stood still
for a second as the answer, so with a refresh slower than 1s, or a
rate-limited or failed one, each read told the figures of the read
before it (up to an hour old) stamped with the time now.
Now "Refreshing…" is waited past (up to commandWait). A panel that is
still refreshing at that point, or that shows last-known usage, is told as
"/usage couldn't load the plan's usage: …". claudeUsageUnknown already
matches that, so the card keeps its own last reading and that reading's
time. Figures Claude Code seeds from this session's own reply headers
("Partial usage data", "Per-model breakdown unavailable", "Could not
refresh usage data") are current and are still reported.
Fixtures are real bytes. Claude Code 2.1.316 ran on mote in a sandbox
CLAUDE_CONFIG_DIR with a made-up sign-in and saved figures 20 minutes
old (8% / 1%), and /usage was typed through a pty. It drew "Refreshing…"
and then "Showing last-known usage as of 20m ago (rate limited until
12:11am)". No real account was used, and no Keychain or live config was
touched.
Run (mote-run, at this tree on
|
||
|
|
59c1306035 |
claude: an auto-mode client's tool loop keeps its interactive run (#4804)
Auto mode's safeguards change with every tool batch: prior_turn_context grows by the turn before. An interactive Claude Code run read them once, from CLAUDE_CODE_EXTRA_BODY in its environment as it started. So a tool loop either started the run again (the whole conversation written to the cache again), or kept it and sent the classifier the context it started with, which is not what real Claude Code sends. Each turn's safeguards now reach the running run: - The bridge writes the extra body to <run tmp>/guard.json and hands its path to the helper as MAGPIE_CLAUDE_GUARD (mapped for WSL in newTap). - tap.js, on each /v1/messages request whose string body has a safeguards key, reads the file and puts its safeguards in the body. It also sets CLAUDE_CODE_EXTRA_BODY to the file's text, so Claude Code's own later reads agree. The first time, it writes guard.json.live. - setSafeguards rewrites the file (temp and rename, retried for Windows) instead of restarting, once .live exists. Without .live (a Claude Code that doesn't load the tap), it falls back to the old rule: keep the run when only the varying parts changed, otherwise restart. A beta change, or safeguards appearing or going, still restarts. The tap changes only the safeguards value; any other byte of the body is Claude Code's own. Bodies without safeguards, count_tokens and non-string bodies are passed through untouched. The tool-results path logged "process expired" alone while the run's end read "magpie ended it". It now aborts the run with the reason and logs "tool results process expired: <reason>". continueWith's "not waiting for tool results" does the same. Tests: - TestClaudeTUIToolLoopCarriesEachBatchsSafeguards: three tool batches with growing prior_turn_context, then the answer. Checks one run and that each request carried its own batch's safeguards. - TestClaudeTUIToolResultsLogWhyTheRunEnded: no tap and the rules change. Checks that the log has the reason. - TestTapPutsTheGuardFilesSafeguards (bun and node): the rewrite, the bodies left alone, the env, and .live. - TestTapEnv: MAGPIE_CLAUDE_GUARD is passed through, WSL-mapped. Run (worktree at |
||
|
|
3d7b1233dd |
claudetui: /usage's screen is read at the terminal's own 200 by 50 on macOS and Linux (#4988, shinnqy on X)
shinnqy on X: in the latest magpie Claude Code's usage doesn't load.
#4988 (0.1.2776, macOS, Team plan): the card said 100% / unused, and
`magpie quota refresh claude` gave one window, "7 days · Fable" 0%, while
the account's 5 hours were 29% and 7 days 17% used.
Cause:
|
||
|
|
3a74cd92e8 |
claude: /usage waits for its figures, and a read without them is unknown
Seagull fries (haioushutiao, Discord #help; magpie 0.1.2704, Claude Code
2.1.316, Windows 11, Claude Pro): the Claude card said 暂时无法获取额度,
"Claude Code's /usage told no allowance: ❯ /usage ─── Settin s Status
Config Usage …". Reproduced with a real Claude Code 2.1.316 under
Windows' pseudo console in a sandbox: /usage's panel is drawn first with
"Loading usage data…" while Claude Code asks Anthropic for the figures
(5s timeout, retried only on a 401), and the helper took 3s of a still
screen as the panel drawn whole. On a slow answer it told the panel's
frame as the result, and parseClaudeUsage called any text with no window
"told no allowance". A failed load ("Error: Failed to load usage data",
"r to retry") went the same way.
claudetui:
- screen.go: a small terminal grid (CUP/CUU..CHA/VPA, EL, ED, ECH, CR/LF
with scrolling, OSC/DCS skipped, an escape or UTF-8 character cut
between reads kept), 200x50 on Windows as the pseudo console is made,
80x24 elsewhere. The pseudo console sends only the cells that changed,
skipping a cell that holds the same letter ("Settin\x1b[1Cs"), so the
stream read split words and kept a redrawn digit beside the old one.
While /usage is read, each look of the screen with a window is kept
(panel), and usageText reads that before the stream.
- command(), built on b4073c06a's wait for the panel (ikunbots; its
usageDrawn and "hadn't drawn" error kept, now also judged on the grid,
since the pseudo console's split "Settin s" never matched its tabs):
"Loading usage data" on screen is waited out (to
commandWait, s.doing "was still loading /usage's figures" for the
deadline message); "Failed to load usage data" gets one "r"; a panel
still with no figure and loading or failed on screen is an
error_during_execution result, "/usage couldn't load the plan's usage:
<screen>".
- the fake draws the panel a frame at a time (fakeFrames), as Claude Code
does: with one write, the pseudo console passed on only the last
frame, which no longer shows the windows. TestShimReadsUsage now passes
on Windows (#4820, the fake's side; a real panel with figures was not
seen on Windows, see below).
provider:
- parseClaudeUsage: a panel with no figure is "Claude Code's /usage
showed no usage figures: …", not "told no allowance" (kept for
claudeUsageDenied's refusals).
- claudeUsageUnknown: Claude Code's "temporarily unavailable" and the
helper's "couldn't load the plan's usage" keep the account's reported
reading (quota_last), as the first did alone before. Other no-figure
text is still shown as an error (TestClaudeHeaderSurvivesUnclassified-
UsageFailure, TestClaudeUsageReadingAloneDoesNotHideUnclassifiedFailure
hold that).
Fixtures are the reporter's case as the pseudo console passed it on for
the real 2.1.316 (a temporary dump of the helper's screen bytes, sandbox config,
proxy that never answers / refuses): testdata/usage-loading-win-2.1.316.bin
and usage-failed-win-2.1.316.bin.
Run at the pushed head:
- mote: go test ./internal/claudetui ./internal/provider ok; go test
-run 'Claude|Usage|TUI' ./internal/gateway ok; GOOS=darwin/linux/
windows go vet ./internal/claudetui ./internal/provider ok; gofmt -l
clean.
- xiaomi-gpu (win-run): go test ./internal/claudetui: all pass except
TestShimFirstMessageWaitsForTools, red on Windows at main (#4810).
- xiaomi-gpu, real Claude Code 2.1.316 (npm), sandbox CLAUDE_CONFIG_DIR
with a fake token, magpie.exe built from this tree, helper run as the
gateway runs it: a proxy that never answers gives is_error "/usage
couldn't load the plan's usage: … Settings Status … Loading usage data…"
after the 20s wait (was a success with the chrome); a refused proxy
shows "Failed to load usage data", "r" is pressed, and the same error
comes back in 6.6s. "Settings" is whole now.
Broken by hand (before the rebase onto b4073c06a; the merged loop is
re-checked below):
- old tui.go: TestShimWaitsForUsageFigures slow, retried and failed again
all red, each telling the reporter's chrome as success.
- the "r" not written: TestShimWaitsForUsageFigures/retried red.
- old parse message: TestClaudeUsageWithoutFiguresIsUnknown red ("told
no allowance"); old quota_last check: its couldn't-load cases red.
- after the rebase, on the merged loop: the "r" not written,
TestShimWaitsForUsageFigures/retried red; the old "anything still 3s"
in place of usageDrawn on the grid, TestShimWaitsPastTheBanner red.
Not tried: a real account (the box has none of the owner's), so a real
2.1.316 panel with figures was never seen through the pseudo console;
whether Claude Code's frames that show the windows reach the pseudo
console's output before it renders the next one is shown only by the
fake. Not taken: asking Anthropic's /api/oauth/usage, which the owner
ruled out (
|
||
|
|
b4073c06a0 |
claude-tui: /usage waits for its panel, never takes Claude Code's banner as it (ikunbots on X)
ikunbots (v0.1.2738) showed a Claude card saying "Claude Code's /usage told no allowance: ▘▘ ▝▝ /private/var/folders/…/magpie-claude-work-501 ────". After /usage is typed, Claude Code draws itself again (banner, folder, the prompt's rules) before the panel. A slow /usage leaves that still, and the helper took any screen still for 3s as the panel, so the banner was told as /usage's answer and parsed as an error. Now a screen without "NN% used" counts as drawn only when the panel's Settings tabs show and nothing says loading (usageDrawn). With no panel by commandWait (or the caller's deadline), the result is an error naming what was last drawn, never a success carrying the banner. Run (on mote): - go test ./internal/claudetui/: ok (new TestShimWaitsPastTheBanner: the fake draws the reporter's banner, then the 2.1.316 panel 4.5s later; TestUsageDrawn; a "banner, no /usage panel" case in TestShimEndsAtItsCallersDeadline). - Broken by hand (old "anything still 3s" condition back): TestShimWaitsPastTheBanner red, told the banner as the result, as in the report. - go test -run 'Usage|TUI' ./internal/gateway/ ./internal/provider/: ok. - GOOS=darwin/linux/windows go vet ./internal/claudetui/ ./internal/gateway/: clean; gofmt clean. Not tried: a real slow /usage on a real account; the "loading" word is a guess at the panel's loading text, which only keeps waiting longer. |
||
|
|
e7185daebe |
claude: a failed interactive read says why in app.log, and names the trust question (#4830)
mydosu (#4830) found nothing in app.log to say why every /usage read and
test of a saved account failed, and the card's reason, "showed no
prompt", said nothing of the trust question Claude Code was waiting on.
- claudetui: when the helper's deadline comes while Claude Code shows
"trust this folder", the reason is "Claude Code asked whether to trust
<folder>, not answered in the 16.8s its caller waits for it: <screen>".
Any other screen keeps "showed no prompt".
- gateway: askClaudeTUI and claudeUsageTUI log a failure to app.log
(logOneOff): "claude: a /usage read of saved account <dir> failed: ...",
with the helper's whole reason on one line, which the card clips to 300
bytes. The home folder and any /Users/<name>, /home/<name> or
C:\Users\<name> become ~, secrets go through redact.Scrub, and past
800 bytes the line keeps the first 300 and the last 500, so the end of
the last screen stays.
- docs/subsystems/claude-subscription-bridge.md says both.
Run at this head (mote, rebased on origin/main; the gateway set re-run
with Upstream|Unsent|Routing added after the rebase): gofmt -l clean; go vet for claudetui and
gateway, and GOOS=linux and GOOS=windows go vet for claudetui, gateway
and provider: ok. go test -count=1 -timeout 45m ./internal/claudetui
./internal/provider: ok. ./internal/gateway -run
'Claude|TUI|Usage|Warm|Ask|Trust|Subscription|Bridge|OneOff': ok.
Windows (win-run): ./internal/claudetui ran with the new trust_unanswered
case passing through ConPTY; TestShimFirstMessageWaitsForTools and
TestShimReadsUsage are red there, the same at origin/main
|
||
|
|
d39358f1bb |
claude: /usage and "hi" reads run in magpie's work folder and say why they ended (#4830)
mydosu's Claude Code quota reads on Windows failed for both accounts
with "exit status 1" alone. Two things were behind it:
- Each one-off interactive run (claudeUsageTUI, askClaudeTUI) started in
a new magpie-claude-<n> temp folder, which the helper trusted, so each
read wrote one more trusted projects entry into the config's state file.
The reporter had 67 in ~/.claude.json.
- The caller's budget (subscriptionTimeout, 20s) is shorter than the
helper's own waits (45s for the prompt, 20s for a panel). The context's
kill came first, and that is TerminateProcess on Windows, so Wait said
"exit status 1" with an empty stderr. On Unix the same kill says
"signal: killed".
What changed:
- One-off TUI runs work in claudeWorkDir (oneOffDir). That is the
owner-checked folder the bridge's own runs already use, so each config
directory holds one trusted entry instead of one per read. A temp
folder is made only when that folder can't be.
- The run's session file there is removed by the session_id the helper's
init line names (dropOneOff). It is not removed under WSL.
- The helper is told its caller's deadline (claudetui.DeadlineEnv, the
context's deadline less min(3s, a quarter of what is left)). At that
time it ends on its own, saying what Claude Code hadn't done and its
last screen, e.g. "Claude Code hadn't drawn /usage's panel in the
2.9s its caller waits for it: ...".
- A run that still says nothing reads "Claude Code's interactive mode
said nothing before magpie stopped waiting for it (...)" (oneOffErr),
not an exit code.
- quotaError says these reasons on the card as "Allowance unavailable:
{why}" (an existing key in every language). The full text stays in
the tooltip. Nearby comments were cut so the core script budget holds
without a raise.
- No -p fallback was added. The -p asks keep their own temp folder,
since -p asks nothing about trust.
- The entries older magpies left in ~/.claude.json are left alone:
magpie never writes that file.
Run at this head (after the rebase on
|
||
|
|
af4ff747bc |
claudetui: Claude Code's first-run screens are gone through as a person would, not the run's end (#4817, steven_4422 on Discord)
With "runs as" Interactive, a Claude Code whose onboarding was never finished (no hasCompletedOnboarding in the state file: steven_4422's every request 502'd, uiuing's /usage read in #4817) stopped on the "Security notes" screen, and |
||
|
|
ccd746e039 |
claude: /usage is read in the interactive mode, typed in it, not through -p
With the interactive mode on, the plan's allowance (the Claude account's
usage card) was still read by `claude -p /usage`, the one -p run left
beside a request. Claude Code 2.1.316's -p /usage also tells only the
session's cost, no window. Now claudeUsage, with claudeTUIOn, runs the
interactive mode's helper (claudeUsageTUI) and gives it a line
{"type":"command","command":"/usage"}. The helper types /usage, waits for
the panel to settle (a "N% used" and a second without change, or three
seconds of anything else, 20s at most), closes it with Esc, and tells
what was drawn as -p's lines say it (usageText: "Current session: 0% used
· resets 5am (Asia/Shanghai)"), so parseClaudeUsage reads it unchanged.
No model is asked. The helper types no other command. The machine
reasons a request is refused for (no shim, OS, missing, off) refuse the
read the same way. Turned off, -p runs it as before.
Run (mote, at this tree on origin/main
|
||
|
|
14e3513780 |
claude: Claude Code in WSL runs interactively when Windows can't read its transcripts
With the interactive mode on, Claude Code in WSL was refused with a 502
in two cases: the distro user's own folder unreadable from Windows
(\\wsl$ needs the 9P redirector, which a session over ssh hasn't;
"wslread") and a distro whose home the probe didn't find ("wsl-home").
Both now run interactively: the helper reads the transcript inside the
distro.
- claudetui/wslread.go: before Claude Code starts, a shell run through
wsl.exe notes how much of $HOME/.claude/projects/*/<sid>.jsonl is
there (a resumed session's earlier turns), says "ready", then tail -F's
the rest; the helper copies it to a file of its own and tails that as
any transcript. When Claude Code ends it waits for the copy to stop
growing (settle), then closes the shell's stdin, which ends it.
- claudetui.WSL gets Distro (Projects omitempty); the gateway's tuiWSL
sets it when Windows can't read the folder or the home is unknown.
- the wslread and wsl-home refusals are gone (claudeTUI, claudeWhy,
claudeNotTUIWhy); the GUI's "wsl-home" reason and its 4 strings too.
- docs/subsystems/claude-subscription-bridge.md says how it is read.
Run, at origin/main
|
||
|
|
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 |
||
|
|
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).
|
||
|
|
2b52302dcb |
claude: the interactive mode takes a first message of any length
@crosscn on X (11-01): after the upgrade made the interactive mode the default, a week-old conversation (a DeepSeek harness on a Claude model) got a 502, and worked again only with -p turned back on. A conversation told whole to a new interactive Claude Code is its first message, and words over 400KB were refused (claudePrint's "big", tuiPromptMost). The bound was never tried: the commit that set it lists "a ~400KB paste" under Not tried. Tried on real Claude Code 2.1.316 in a sandbox HOME, haiku: a 3MB bracketed paste showed "[Pasted text #1 +46154 lines]" after 35s; a 500KB one was sent, its transcript holds every line and the question, and the model answered it (184,168 tokens written to the cache). - tuiPromptMost and the "big" refusal are gone; claudeTUI, claudePrint, claudePrintWhy and claudeNotTUIWhy no longer take the prompt, which only that bound read. - the helper waits for a paste to show a second per 64KB longer than pasteWait (shownWait): 10s alone would press Enter while a 3MB paste was still being taken in. - the editor's tooltip says -p takes what the interactive mode can't "yet": a JSON schema (en, zh, zh-TW, ja, de). - docs/subsystems/claude-subscription-bridge.md says so. Tests: TestClaudeTUIBigFirstMessage (a ~1.1MB first message runs through the helper, 200), TestShownWaitGrowsWithThePaste; TestClaudeTUIOnRefusesPrint refuses a JSON schema now; TestClaudeTUIChosen's long-message row runs interactively. Run on mote (go1.26.8): - full go test ./internal/gateway ./internal/claudetui (-timeout 45m) at |
||
|
|
e5f66f8a61 |
claude: with the interactive mode on, nothing ever runs as -p; the editor switches TUI and claude -p
The owner (11-01): the interactive mode falling back to -p is dangerous,
for the account (a -p request counts as another client's) and for the
cache (a -p run starts without the interactive mode's), so it goes
entirely. With Settings › Models › Replies' interactive mode on:
- a request it can't take (safeguards, client cache marks, a JSON
schema, an image by URL, words over 400KB, a branch of a -p session,
a WSL Claude Code whose home or transcripts magpie can't reach) is
refused before any Claude Code starts, saying why and naming the
setting (claudeTUIErr), never run as -p;
- a helper that can't start the interactive mode (sign-in asked,
first-run notes, an untrusted folder, no prompt within ReadyWait)
ends saying why (claudetui fail); printMode, OnlyEnv and the
claude-tui-broken mark that sent every run to -p for a day are gone;
- a helper that never answers initialize fails the turn
(tuiNoStart), and the next turn tries again.
Off still runs every request as -p. The "Interactive only" choice of
v0.1.2448 (claudeTUIOnly) is what On is now; the setting is no longer
read or sent.
The Claude Code provider editor's "Claude Code runs as" row is a
switch between Interactive mode (TUI) and claude -p (owner, 11-01),
saving claudePrintMode and reading /api/claude/mode again; disabled in
magpie web. It reads the settings first when the Settings page was
never opened (prefs null crashed the switch; found by the GUI test).
Chromium has no onfocusin property, so the card on keyboard focus
listens for focusin/focusout. Words in en, zh, zh-TW, ja and de.
Docs: claude-subscription-bridge.md describes refusal, not fallback.
Not covered yet, now refused under On rather than run as -p (follow-
ups, each to be done inside the interactive mode): an image by URL, a
JSON schema, safeguards, client cache marks, over 400KB, a -p
session's branch, WSL transcripts Windows can't read. /usage reads
the allowance with claude -p /usage (no model request) either way.
Run (worktree at
|
||
|
|
8215164296 |
claude: a branch is a cut copy of its run's session, in its run's mode (bbfatx on X)
A sub-agent's first request that answers calls another request already answered branches off the lead's run's session (branch). That branch was `claude -p --resume S --fork-session --resume-session-at U`, and claudePrint forced every branch to -p, because Claude Code's interactive mode ignores --resume-session-at (Claude Code 2.1.316 on mote: it resumes the whole session). Runs are the interactive mode by default now, so the lead's cache has the interactive prompt, and a -p branch of it read only tools and system from the cache and wrote the conversation again (measured on mote, sandbox HOME, 30 MCP tools: an interactive fork of a -p session read only tools and system; the other way round was not measured). With "Interactive only" no branch was made at all, and the fork was told the whole conversation. Now the branch's run copies the session's lines up to U into a new session file next to it, with sessionId set to the copy's id (cutSession), and resumes it with --resume <copy> in the mode its source run had (savedSession.tui). claudePrint keeps "branch" only for a branch of a -p run. Under "Interactive only" a -p run's session isn't branched. The run owns the copy, as it owns an unshelved session. The copy waits up to 2s for U's line to be fully written; if it never is, the turn is told whole, as before. claudetui's translator now passes each assistant row's uuid through, as -p does, so an interactive run's lines can be cut. Measured on mote with real Claude Code 2.1.316: a cut copy resumed interactively read 7648 and wrote 14; with -p it read 24009 and wrote 13. Run (mote-run, this tree): - go test -tags nogui -count=1 -timeout 30m -run 'Claude|Bridge|ToolChoice|Subscription|Retire|Rewrit|Fork|Branch|Shelf|Shelve' ./internal/gateway: ok 63s - go test -tags nogui -count=1 ./internal/claudetui: ok - go vet -tags nogui ./internal/gateway ./internal/claudetui; gofmt -l: clean Broken by hand (each red, then put back): - old claude_subscription.go and transcript.go (cutSession stubbed): TestClaudeForkBranchesOffTheLeadsSession interactive (branch ran -p), interactive only (told it whole), print (old flags), TestClaudeCutSessionCopiesAsFarAsTheLine and TestTranslatorTellsTheRowsUUID red - claudePrint's branch reason for every branch again: interactive and interactive only red - the copy taking the whole file: all three subtests and the cut test red - branch() refusing every run under Interactive only: interactive only red Not tried: a real fork sub-agent through the gateway. The cache numbers come from copying by hand with real Claude Code; the tests use a stand-in. Windows and WSL keep no session on disk, so they never branch, as before. Not taken from the suggestion: the fork's own runtime and TypeScript wrapper. The cut is done here at the one place a branch starts. |
||
|
|
606743831e |
appdir: on Windows an agent's folder variable follows the registry, and a gone folder it names isn't made again (bm_rabbit on Discord)
bm_rabbit (0.1.2405, Windows x64, Pi 1.4.0) moved Pi's AgentDir from
F:\piData\.pi\agent to F:\HarnessData\Pi\.pi\agent, deleted the old one and
set the User variable PI_CODING_AGENT_DIR to the new path. Changing Pi's
model in magpie then made the deleted folder again with only models.json
and settings.json in it.
Cause: Windows gives a process its variables once, from the registry, and
never passes a changed User variable to one already running. magpie runs
for days in the tray, so appdir.Getenv("PI_CODING_AGENT_DIR") (piDir) kept
the old path, and edit's write did MkdirAll on it. Every agent folder
variable (CODEX_HOME, CLAUDE_CONFIG_DIR, ...) had the same problem.
Fix, where every agent folder is read (appdir.LookupEnv, follow.go): on
Windows a variable in agentenv.Vars that came from the registry (its value
in magpie's environment at start matched the registry's, unset in both
counts too) is read from HKCU\Environment, else HKLM's Session Manager
Environment, with %...% expanded, at most once a second, and set in
magpie's environment so the programs magpie starts get it too. A value
the launcher set itself, or one set inside magpie since (a test sandbox),
stands. The direct os.Getenv reads of agent variables go through appdir
now: claudetui's CLAUDE_CONFIG_DIR, sessions' CODEX_SQLITE_HOME and
PI_DESKTOP_DATA_DIR, cliupdate's GROK_HOME, omp's OMP_PROFILE/PI_PROFILE.
And edit's writeFile no longer makes a missing tree of folders that an
agent's variable names: when the folder the variable names is missing
and so is the folder above it (bm_rabbit's whole F:\piData was gone),
appdir.Gone returns a GoneError naming the variable and the folder. The
named folder itself is still made when its parent is there, as mkdir
would (a CODEX_HOME or ANTE_HOME set before the agent first ran; 12
internal/agent tests rely on it), and an agent's default folder is made
as before. TestAnteHome's ANTE_HOME was <tmp>/elsewhere/ante with
elsewhere missing; it now makes elsewhere first. Writes that call
os.MkdirAll themselves don't ask yet: #4634.
Pi's install-layout.json isn't Pi's: Pi 1.4.0's getAgentDir
(@earendil-works/pi-coding-agent dist/config.js) reads PI_CODING_AGENT_DIR,
else ~/.pi/agent, and no file in the package names install-layout.
magpie doesn't read it.
Tests: TestAgentVarFollowsTheRegistry, TestAgentVarAddedLaterFollows,
TestAgentVarSetByHandStands, TestRegistryReadAtMostEachFollowFor,
TestGoneNamedFolderIsNotMade (internal/appdir, a fake registry), and
TestWriteNeverMakesANamedFolderAgain (internal/edit).
Broken by hand: LookupEnv back on os.LookupEnv, TestAgentVarFollowsTheRegistry
and TestAgentVarAddedLaterFollows FAIL ("after the user moved it,
PI_CODING_AGENT_DIR = .../old, want .../new"); Gone's refusal turned off,
TestGoneNamedFolderIsNotMade and TestWriteNeverMakesANamedFolderAgain FAIL
("= <nil>, want a GoneError", "the folder was made again"); Gone refusing
whenever the named folder is missing, TestGoneNamedFolderIsNotMade FAILs
("a named folder whose parent exists: ..."). All put back, green.
Real Windows run on xiaomi-gpu, sandbox USERPROFILE/APPDATA/LOCALAPPDATA,
at this head: a probe built from this tree started with
PI_CODING_AGENT_DIR=<sb>\piData\.pi\agent in its environment and the User
registry; then the User variable was set to <sb>\HarnessData\Pi\.pi\agent
and <sb>\piData deleted, and agent.Find("pi").Apply("model", ...) ran in
the same process. Pi's dir and os.Getenv are the new folder,
settings.json written there, piData not made. With HarnessData deleted
too: "PI_CODING_AGENT_DIR names <sb>\HarnessData\Pi\.pi\agent, which
doesn't exist and neither does the folder above it: ...", not made. An
earlier run of the old code (LookupEnv on os.LookupEnv, no Gone) wrote
into the old folder and made it again: bm_rabbit's case. The User
variable was removed after; the box had none.
Full run at this change on
|
||
|
|
e6b595e1ab |
claude: Interactive only, a setting under which a model request never runs as claude -p (_yuchanns_ on X)
_yuchanns_ on X, on the interactive mode falling back to -p: for people
who stayed off magpie's Claude subscriptions because of -p, a fallback
is a time bomb. Settings › Models › Replies › Claude Code's interactive
mode now has three choices: Off (always -p), On (the default, falling
back to -p as before) and Interactive only.
With Interactive only (settings.ClaudeTUIOnly; ClaudePrintMode set too
wins):
- a run claudeTUI would make -p is not started; the request fails with
the reason and the setting (claudeOnlyErr, claudeNotTUIWhy);
- the helper is handed MAGPIE_CLAUDE_TUI_ONLY=1 (claudetui.OnlyEnv,
claudeCLI.tuiEnv). Where it would exec -p (no start, sign-in, first-run
notes, untrusted folder, 45s timeout) it exits with the reason
(fallBack in Run), and it ignores the broken mark;
- a helper that never answers initialize ends the turn with an error,
not a -p retry, and `broken` isn't counted (claudeMachineWhy), so the
next run tries the interactive mode again;
- the model test's and warm-up's "hi" (askClaude) runs through the
helper (askClaudeTUI) in stream-json, its stdin closed at the first
result. The helper command and env are built in one place now
(tuiCommand, tuiEnv) for both.
Reading the plan's allowance (/usage) asks no model and stays -p; the
setting's text says so. Docs: claude-subscription-bridge.md.
Provider editor, on e8347401f's "Claude Code runs as" pill
(ClaudeMode.Only): with the interactive mode in use and no last
request, it says a request it can't take fails, and the card's foot says
nothing runs as -p. Where the interactive mode can't run, the pill names
Interactive only, never claude -p, the line says "Claude requests fail:
<why>", and Change in Settings goes to the row. A request refused this
way never ran, so it isn't noted as the last request (noteClaudeRun
comes after the refusal).
app.js: the Replies rows share one helper (segRow, which waitRow uses
too), so app.js is 530 bytes under main's with the third choice; no
budget raise.
Tests: TestClaudeTUIOnlyRefusesPrint, TestClaudeTUIOnlyHungHelperNoPrint,
TestClaudeTUIOnlyTellsHelper, TestAskClaudeTUIOnly (gateway);
TestShimOnlyNeverPrints (claudetui: fake fail/trust/login/notes each
exit with an error and no -p, a marked-broken run still interactive);
claude-tui-setting.test.cjs (three choices, Only saves claudeTUIOnly with
claudePrintMode false) and claude-mode.test.cjs (Only in use, and Only where it can't run).
Broken by hand, each red, then put back: the startRun gate off
(RefusesPrint 200); start()'s Only check off (HungHelper 502 without the
Only reason); tuiEnv's OnlyEnv off (TellsHelper); askClaude's branch off
(AskClaudeTUIOnly); the helper's fallBack ignoring only (4 subtests);
BrokenSince's `&& !only` gone ("marked broken"); the save without
claudeTUIOnly (16 of 16 setting tests) and claudemode.js's m.only
branches gone, rebuilt on e8347401f's file (10 of 10 Only tests,
Chromium).
Run on mote at
|
||
|
|
88a0262bf2 |
claudetui: Claude Code's first-run notes send the run to -p at once, not after 45s
A config folder whose onboarding isn't done (one only -p was run in,
given CLAUDE_CODE_OAUTH_TOKEN) has the interactive mode show "Security
notes: … Press Enter to continue". The helper knew the sign-in screen
but not this one, so it waited out ReadyWait (45s) before running -p.
Now firstRun is matched like signIn: the run is -p at once and the
start is marked broken. Agreeing to the notes is left to the user.
The match is on the screen's words with any space between them one
(strings.Fields): the real 2.1.316 screen didn't match a plain regexp,
since Claude Code draws some spaces by moving the cursor.
Run:
- mote: go test ./internal/claudetui -count=1 ok; go vet for darwin,
windows, linux; gofmt clean.
- Broken by hand: with the case off, TestShimFallsBackToPrint/first-run
notes goes red ("wrote 0 lines of 1 in 30s").
- Real, on xiaomi-gpu (Windows 11), Claude Code 2.1.316 (official dist,
sha256 checked), a real subscription token, a fresh config folder:
before, "showed no prompt in 45s" and -p at 48s; with the first regexp
still 45s (the space case above); now "shows its first-run notes" and
the -p answer at 7.9s and 16.9s (two runs), streamed.
Not tried: WSL with a fresh folder (same helper code path); macOS/Linux
native with a fresh folder.
|
||
|
|
8a410f35a2 |
claudetui: Claude Code's interactive mode streams its replies, through a preload that copies the main turn's stream
The owner: make a Claude subscription stream as it goes while Claude
Code runs in its interactive mode (TUI), on macOS, Windows and WSL.
Until now the helper read Claude Code's transcript, which has a message
only once it ends, so a reply came to the client whole.
Claude Code is a Bun program, and Bun loads a script named in
BUN_OPTIONS (--preload) before it. The helper writes tap.js to a folder
of its own and starts Claude Code with BUN_OPTIONS="--preload tap.js"
(after the user's own BUN_OPTIONS, but not a Windows one's for a Claude
Code in WSL, where both go through WSLENV). tap.js makes Bun.FetchSession
a subclass whose fetch is the real one's, so the request, its headers,
its connection and TLS are Claude Code's own. For a reply to a
request marked x-claude-code-request-class: main to /v1/messages that
is text/event-stream, it tees the body: Claude Code reads its copy as
before, and tap.js writes each event, as it comes, as a JSON line to
the file MAGPIE_CLAUDE_TAP names. It takes itself out of BUN_OPTIONS,
execArgv and the environment first, so nothing Claude Code runs
inherits it.
The helper reads that file and tells the events as -p's stream_event
lines, so the gateway reads them as it reads -p's. A transcript message
waits up to 1s for its stream to begin (then it's told whole, its late
stream left out); a turn's end waits for its streams to end; a stream
cut short ends with a message_stop and no message_delta, as -p ends
one. The bridge now keeps the streamed messages by id, since a whole
message can come during the next message's stream, and a client
tool_use shown from the stream isn't told again from the whole message.
On Windows, BUN_OPTIONS has no quoting, so a temp path with a space
takes its short name; one that still has whitespace gets no tap, and
replies come whole, as they do from a Claude Code that isn't Bun or
doesn't send through FetchSession (2.1.281 on Windows doesn't; 2.1.289
and 2.1.316 do).
Run:
- gofmt -l: clean. go vet on mote for darwin, GOOS=linux and
GOOS=windows: 0.
- go test ./internal/claudetui ./internal/gateway on mote
(-timeout 45m): ok, ok (gateway 654s).
- go test ./internal/claudetui with win-run (Windows 11) and wsl-run
(magpie-desktop): ok, ok.
- macOS, real account (Claude Code 2.1.316, sandbox HOME, keychain
token): a reply came as message_start, text deltas,
content_block_stop, message_delta, message_stop, then the whole
message, then the result; stderr clean, the tap's folder removed.
- Windows native, Claude Code 2.1.316 against a fake that sends an SSE
event every 250ms (a user preload marking the request main, which
also checks the user's BUN_OPTIONS is kept): the deltas came 250ms
apart, before the whole message. The same with TEMP holding a space
(short name).
- WSL magpie-desktop, Claude Code 2.1.289 run through wsl.exe from the
Windows helper, the fake in WSL: the same.
- The scrub, on macOS and Windows: Claude Code's BUN_OPTIONS and
execArgv have no tap, MAGPIE_CLAUDE_TAP is gone, --smol is kept.
- Rebased on origin/main
|
||
|
|
a4151142a6 |
claudetui: the Unix pseudo-terminal child is made through proc.Command (#4491)
internal/claudetui/child_unix.go started Claude Code with exec.Command directly, so TestNoCommandBypassesProc was red on main since the interactive mode's Unix child landed ( |
||
|
|
fb9c176756 |
claudetui: Claude Code in WSL runs in its interactive mode too
A Claude Code found in a WSL distro (Windows has none of its own) was always claude -p, the entrypoint the plan counts at about twice the interactive mode's. Many Windows users run it there. The Windows helper now runs wsl.exe in its pseudo console. The gateway hands it MAGPIE_CLAUDE_TUI_WSL (claudetui.WSL, claudeCLI.tuiWSL): the wsl.exe arguments up to Claude Code's (wslrun.Tool.Args, with MAGPIE_WSL_RUN), the distro's mount, and the projects folder as Windows reads it. That is the account's config directory, handed in through CLAUDE_CONFIG_DIR/p, or the distro user's own ~/.claude/projects through \\wsl$\<distro> (wslrun.Tool.Home, a new line in the probe; wslrun.Tool.Windows). TERM is added to WSLENV, and an image's path is pasted as the distro reads it (/mnt/c/…). The helper is the Windows magpie.exe, not the /mnt/c/… path the MCP helper starts at; the first real run failed on exactly that (fork/exec /mnt/c/...magpie.exe). The gate keeps -p for a WSL Claude Code whose home is unknown, and, in the distro user's own folder, when Windows can't stat \\wsl$\<distro>\<home> (tuiWSLUnread): over ssh it can't (no 9P redirector), and the helper would wait for a transcript it can't see. Doc updated. Run: - go test ./internal/claudetui ./internal/wslrun on mote and on Windows 11 (xiaomi-gpu): ok. New: TestShimInWSL (image path, WSLENV), TestClaudeTUIWSL (projects folder both ways, wsl args), the home in the probe and Windows() in wslrun, the gate's two WSL cases, TestClaudeTUIWSLUnread. - go test -run 'Claude|Refusal|Thinking' ./internal/gateway on mote: ok. - go vet of claudetui, gateway, wslrun for darwin, linux, windows (-tags nogui, and the main package for windows); gofmt -l clean. - Real account on xiaomi-gpu: a sandbox HOME gateway (3462) with no Windows Claude Code reachable (PATH trimmed, MAGPIE_TEST_SANDBOX so the registry PATH isn't read), the Claude Max account, Claude Code 2.1.289 in magpie-desktop, haiku-5-5. Tree: helper -> wsl.exe -> claude on a pts in the distro, TERM=xterm-256color, CLAUDE_CONFIG_DIR=/mnt/c/..., no CLAUDE_CODE_ENTRYPOINT. One tool call, two in one message, text then a call, and two image turns: all right. Every transcript row "entrypoint":"cli", no "-p" line in the log, images noted as /mnt/c/.../magpie-claude-images-*/image-N.png and no folder left. Killing the gateway ended its four claude processes in the distro within 3s. The token wasn't refreshed; the copied credentials were deleted. Broken by hand: shim.path returning the Windows path unchanged, TestShimInWSL red; tuiWSLUnread ignoring the stat error, TestClaudeTUIWSLUnread red. Not tried: a WSL Claude Code run from the distro user's own ~/.claude for real (only the account config directory ran; over ssh \\wsl$\magpie-desktop is unreadable, so that run would be -p, and a desktop session's \\wsl$ wasn't tried), a distro whose default user is root, a distro not sharing Windows' loopback (wslrun.Tool.Host set), WSL1. |
||
|
|
06c2c35d13 |
claude: the interactive mode's start is waited for, and a hung one goes to -p (#4504)
derrors (Linux Docker, 2 vCPU, v0.1.2281): every new Claude Code run
failed "Claude Code has not answered magpie's initialize request in 10s"
and the turn was 502 after 6 tries, while -p runs on the same account
answered.
Cause: the claude-tui-helper answers the bridge's initialize only once
the interactive Claude Code shows its prompt (claudetui.ready, up to
45s), or as -p after it falls back. The bridge gave it the 10s of any
control request and then ended it, so a Claude Code slower than 10s to
start was killed before its own -p fallback could run, and nothing was
marked: each try started the interactive mode again.
Fix:
- startRun waits tuiInitWait (claudetui.ReadyWait + 2x controlWait, 65s)
for a TUI run's initialize, and gives up on the request's context.
- a helper that still answers nothing is ended, the machine is marked
(claudetui.MarkBroken), and start runs the turn again as -p.
- claudePrintWhy goes -p at once while the mark holds ("the interactive
mode failed to start lately"), so no helper is started.
- the mark counts failed starts in a row: 30m after one, doubled to a
day (brokenFor), so a machine where it never starts waits about once a
day. A start that shows its prompt removes the mark.
- the helper falls back at once when Claude Code asks how to sign in
(a container signed in for -p only, CLAUDE_CODE_OAUTH_TOKEN), which
it otherwise took for the prompt or waited 45s on.
Every other control request keeps its 10s; initialize is the only one
a TUI run is sent (cliControl's one other caller is setSafeguards,
and a run with safeguards or cache marks is -p).
Run (mote, at this tree):
- go test ./internal/claudetui/ (whole package) ok
- go test ./internal/gateway/ -run Claude ok
- GOOS=linux and GOOS=windows go vet ./internal/claudetui/
./internal/gateway/ ok; gofmt -l clean
- wsl-run (magpie-desktop, Ubuntu 24.04): go test ./internal/claudetui/
./internal/gateway/ -run 'TestShim|TestBroken|TestClaudeTUI|
TestClaudeEndedRunSaysWhy|TestClaudeUnloadable' ok
Broken by hand (each red, then restored):
- TUI initialize waits controlWait, no mark, no retry (the old code):
TestClaudeTUISlowStartAnswered 502 "Claude Code has not answered
magpie's initialize request in 10s", the reporter's message
- TUI initialize waits controlWait only: marked broken, red
- no MarkBroken in the bridge, or no retry in start:
TestClaudeTUIHungHelperGoesPrint 502
- no sign-in check: TestShimFallsBackToPrint/asks_to_sign_in timed out
- no clearBroken: TestShimStartClearsBroken red
- brokenFor not doubling: TestBrokenGrows red
Not tried: a real Claude Code in a headless container, or any real
account. Why derrors' Claude Code was slow or stuck is not known: the
sign-in screen is a guess from -p working where the interactive mode
didn't; the helper's line now logs the screen it stopped on. No full
suite.
|
||
|
|
c59c547c5b |
claudetui: Claude Code's interactive mode on Windows, in a pseudo console
A Claude run on Windows was always claude -p, the entrypoint the plan counts at about twice the interactive mode's. The helper now starts Claude Code in a ConPTY there (child_windows.go): CreatePseudoConsole on two pipes, CreateProcess with the console attribute and STARTF_USESTDHANDLES with no handles. Without that flag a child takes the helper's own standard handles (the bridge's pipes) and draws into them, not the console. A .cmd claude is quoted by proc.Command as the -p run's. Ending closes the console, then kills after 3s; the -p fallback runs Claude Code as a child, as Windows has no exec. The pty code moved to child_unix.go unchanged, and tui.go has no build tag. Windows ends a run by killing its job, which no handler hears, so a turn's images folder is now removed once its message is sent, and a helper starting removes magpie-claude-images-* folders over an hour old (dropLeftImages). The gateway's gate lets Windows through (WSL stays -p), and the setting's text no longer says Windows is always -p (en, zh, zh-TW, ja, de). Doc updated. Run: - go test ./internal/claudetui on macOS (mote), Linux (magpie-desktop WSL2) and Windows 11 26200 (xiaomi-gpu): ok. The fake Claude Code on Windows is a claude.cmd, its console made raw with SetConsoleMode. New: TestDropLeftImages, and TestShimPastesImages checks the folder is gone after its message. - go test -run Claude ./internal/gateway on mote, and the TUI tests on Windows: ok. - i18n-keys and claude-tui-setting (chromium and webkit, en/zh/ja/de, 1100 and 420): 20 of 20 on the Windows box. On mote chromium passed and every webkit case timed out in browserType.launch, beside other sessions' GUI suites running for up to 20 hours (load 22). - go vet -tags nogui of claudetui, gateway and cli for darwin, linux and windows; gofmt -l clean. - Real account on xiaomi-gpu: a sandbox HOME gateway (port 3462) with the Claude Max account, real claude.exe 2.1.281, haiku-5-5. One tool call, two in one message, text then a call, and two image turns (twice): all right answers. 81 transcript rows, every one "entrypoint":"cli", no "-p" line in the log. Images noted as C:\Users\...\magpie-claude-images-*\image-N.png and no folder left. Killing the gateway ended its four resident helpers and claude.exe. The token wasn't refreshed; the copied credentials were deleted. (This ran before the 1809 check in start was added; the claudetui tests on Windows and GOOS=windows vet ran again after it: ok.) Broken by hand: STARTF_USESTDHANDLES removed, TestShimTurnsInteractive on Windows red (3 lines of 5 in 30s: the fake's drawing reached the shim's stdout). Not tried: an npm claude.cmd install with the real account (only the fake .cmd), Windows 10 before 1809 (no CreatePseudoConsole: the start checks for it and falls back to -p), a run ended mid-turn by the client on Windows. A stray "The system cannot find the path specified." showed once in the Windows test output; it wasn't on the shim's stderr, and three reruns didn't show it. |
||
|
|
bca0d6d69a |
claudetui: a turn's images are pasted as files, not sent to claude -p
A request with images ran claude -p, and a turn with one ended the interactive run. The helper now writes each base64 image to image-N.<ext> (0600) in a magpie-claude-images-* temp folder and pastes its path alone, which Claude Code 2.1.314 reads into the message as [Image #N]; a path inside other words stays words. Claude Code reads the file after the paste returns, so the helper waits for [Image #N] past the last one before pasting the next piece. The folder is removed when the helper ends. Only an image known by its URL still goes to -p (urlImages), and tuiPromptMost counts words without images. Run: go test ./internal/claudetui ./internal/cli on mote and in WSL magpie-desktop, ok; go test -run 'TestClaudeTUI|TestSubscription| TestClaudePrint' ./internal/gateway on mote, ok; go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./..., go build, gofmt -l, ok. Real account (Claude Code 2.1.314, haiku, sandbox HOME) through the sandbox gateway with tools: a red then a blue square in two turns, 3 of 3 answered red, blue; the transcript has image blocks in both user rows, entrypoint cli, and the second turn went on in the same run. Broken by hand: without the wait for [Image #N], TestShimPastesImages loses the second image. Not tried: an image over Claude Code's size limit; Linux with a real account. |
||
|
|
faaba45236 |
claudetui: the folder-trust question is answered Yes only once Yes is drawn
The real-account end-to-end through a running gateway found every interactive run going to -p. The gateway's working folder (magpie-claude-work-<uid>) wasn't yet trusted under the account's config dir, so Claude Code 2.1.314 asked whether to trust it, with "No, exit" chosen. The helper pressed down and then, 300ms later, Enter without looking. Its down was lost when sent as the question was first drawn (the question is drawn again on No), Enter chose "No, exit", and Claude Code ended with status 1 (screen: "B"). The start failure marked the interactive mode broken for 30 minutes and every run went to -p, so v0.1.2266's default did nothing on a fresh account. ready() now reads the choice as the last of "❯ No, exit" / "❯ Yes, I trust" drawn, presses down (at most once a second) while No is chosen, and Enter only on a Yes that stayed drawn for 300ms (trustSettle). The test's fake asks as the real one does: words placed by cursor moves, No chosen first, keys in its first 150ms lost, and drawn again on No; Enter on No exits 1. Run: - By hand: real Claude Code 2.1.314 in a PTY in the gateway's folder, sandbox HOME with a real account's config dir: the question opens on No; a down sent at once is undone by the redraw, one sent 0.3s or 1.5s in moves to Yes. - mote: go test -count=3 -run TestShim ./internal/claudetui ok; go test ./internal/claudetui ok; go vet ./internal/claudetui on darwin, linux, windows; gofmt -l clean. - Real account, sandbox HOME, a gateway running this build (and the next commit's), haiku: a tool call, two calls in one message, words then a call: all answered, every transcript row "entrypoint":"cli", no broken mark. Broken by hand: the old ready() with the new fake: TestShimTrustsWhenTold red, "Claude Code ended before it showed its prompt (exit status 1)", the real failure. Not tried: Linux with a real Claude Code; a Claude Code version whose question words differ (it then waits out 45s and goes -p, marked). |
||
|
|
43966a53fb |
claude: a subscription's run is Claude Code's interactive mode, -p only as the fallback
The owner (10-31): a Claude subscription ran `claude -p`, whose
requests Anthropic labels sdk-cli and counts at about twice the
interactive mode's cli (anthropics/claude-code#97074). Running the real
interactive Claude Code is what its terms describe and uses the plan as
a person does. Wanted inside magpie, on by default, with a way off.
`magpie claude-tui-helper <claude> <-p args>` (internal/claudetui)
stands where `claude -p` stood and speaks the same stream-json. It
turns the -p arguments into the interactive mode's (no -p, no
--dangerously-skip-permissions: --permission-mode default with only
mcp__magpie, and the WebSearch -p was given, allowed; --no-chrome;
--session-id or the --resume given), starts Claude Code in a
pseudo-terminal of its own (no tmux), pastes each message into its
prompt and presses Enter, and tells the session's transcript back as
-p's lines: whole assistant messages, an API error as the turn's error
result with its rate_limit_info, turn_duration as the result. Nothing
sets CLAUDE_CODE_ENTRYPOINT, and the user's ~/.claude and
~/.claude.json are never written. The folder-trust question is
answered only for magpie's own folder or a saved account's config
directory (MAGPIE_CLAUDE_TUI_TRUST).
A Claude Code that doesn't start or show its prompt in 45s becomes
`claude -p` on the same pid, its input still unread, so the turn is
answered all the same; that is remembered for 30 minutes
(<cache>/magpie/claude-tui-broken). An untrusted folder goes to -p
without the mark.
claudeTUI keeps -p for Windows and WSL, Settings › Models › Replies ›
Claude Code's interactive mode Off (claudePrintMode), safeguards,
client cache marks, a JSON schema, images and a first message over
400KB. A TUI run ends instead of taking an image turn, a rewind or an
effort change, and letGo doesn't take one back. The gateway's tests
run with claudeTUIRuns off: their binary has no claude-tui-helper.
docs/subsystems/claude-subscription-bridge.md has the section.
The core's scripts grow 725 bytes with the setting's row;
coreScriptBudget is raised to the exact size, 1,537,356, with no room
added.
Run (rebased on
|