Expand description
Shared pieces for running a provider CLI’s login under a PTY and reading
its OAuth URL out of the output: used by the desktop host
(agentmux-cef commands/cli_login.rs) and by srv’s auth.*
(agentmux-srv server/identity_auth_spawn.rs,
identity/auth_patterns.rs). docs/specs/SPEC_PROVIDER_LOGIN_THROUGH_SRV_2026_10_09.md.
Structs§
- DsrResponding
Reader - Wraps the raw PTY reader and transparently answers a cursor-position
query (see
DSR_CURSOR_POSITION_QUERY) the moment it appears anywhere in the stream — not just at startup, since a TUI could plausibly re-probe after a resize — passing every byte through unchanged to the caller (the query’s own bytes included; they’re harmless noise to the caller’s line-scanning loop, not worth the extra complexity of stripping them from the pass-through). - Terminal
Line - A line of terminal output with its escape sequences removed: the visible
text, and the target of every OSC-8 hyperlink it carried.
Constants§
- DSR_
CURSOR_ POSITION_ QUERY - Device Status Report cursor-position query — some CLIs (confirmed:
Claude Code, on detecting a real TTY) send this immediately and BLOCK
waiting for the terminal to reply with
ESC[<row>;<col>Rbefore printing anything else at all. A bareportable_ptyhandle has no attached terminal emulator to answer this automatically — nothing does, on any platform, without code specifically watching for it — so the child hangs forever and the whole capture loop below times out having seen zero bytes. This is the confirmed root cause of issue #2429 (“no PTY output captured… despite correct binary resolution”): isolated repro (a standalone portable_pty harness spawning the exact same binary/args) showed the child’s first and ONLY output was these 4 bytes, then silence: answering this one query unblocked it immediately, and it printed its OAuth URL within half a second. - DSR_
CURSOR_ POSITION_ REPLY - Synthetic “row 1, col 1” reply. The actual reported position doesn’t matter to these CLIs — confirmed by the repro above — they only need something to answer so their TTY-capability probe stops blocking.
- LOGIN_
PTY_ COLS - Columns for a login PTY. Wide enough that the CLI’s own line-wrapping
never wraps the OAuth URL. At 80 cols it did — Claude Code prints
“If the browser didn’t open, visit:
” as plain text and hard-wraps it mid-query-string, so only a truncated fragment missing client_idand everything after it was captured (issue #2429). 4096 comfortably covers any realistic query string.
Functions§
- extract_
auth_ url - Extract an OAuth URL from a line of CLI output: an
https://URL that looks like an auth URL, from an OSC-8 link target first, else from the visible text. - strip_
terminal_ codes - Remove terminal escape sequences from
line. Two families matter here: