ac4af582301a4e8a29245dbba767eba31334ddf9
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
b7631300ec |
claudetui: a successful interactive turn tells its account's allowance
Since the interactive mode replaced -p for Claude subscription turns ( |
||
|
|
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. |
||
|
|
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
|
||
|
|
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
|