Fix pc login for agentic workflows#75
Merged
austin-denoble merged 6 commits intomainfrom Mar 24, 2026
Merged
Conversation
…, tty detection for the input handling on the login flow, supporting JSON output through stdout for agentic use. update target GetAndSetAccessToken to handle things
…style output is going to stderr. add text.encode helper to allows marshalling to JSON without HTML escaping. drive json logic from the top down checking the provided flag along with TTY presence. add unit tests for the new text functionality
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
…here's a TTY detected
…cated - we should output structured JSON to stdout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
pc loginwas unusable in agentic contexts:stdout(Visit https://... to authorize the CLI.), making it impossible for agents to reliably extract the URL from the output.stdinunnecessarily.--jsonflag, no machine-readable URL emission.stdout, giving agents no way to detect the existing session.stdout, mixing with any data output that would be relevant for agent / machine interaction.Solution
Auto-detected JSON output
When
stdoutis not a TTY (machine / agent capturing output), JSON mode is enabled automatically — no flagrequired.
--jsonis also available as an explicit override for users who want structured output in a terminal. The format decision is resolved once at the top ofRun()and passed down;GetAndSetAccessTokenand other helpers use it directly without re-running TTY detection.Structured output at each stage
Immediately before blocking on the OAuth callback:
After successful authentication:
When already logged in:
TTY-gated interactivity
The "Press [Enter]" prompt and
stdin-reading goroutine are gated onterm.IsTerminal(int(os.Stdin.Fd())). Non-interactive runs skipstdinentirely and block cleanly on the OAuth callback. The prompt is preserved for TTY sessions regardless of JSON mode — a user passing --json in a terminal is still at a keyboard and benefits from browser-open.All human-readable output routed to stderr
The prose URL line, Enter prompt, success messages, info messages, and hints all go to
stderr. In JSON mode,stdoutcarries only the structured objects above. In prose mode, TTY users see everything in their terminal as before.Fixed HTML escaping in JSON output
text.IndentJSONandtext.InlineJSONnow usejson.EncoderwithSetEscapeHTML(false). The default Go JSON marshaler escapes & as\u0026— correct for embedding JSON in HTML, wrong for CLI output. This was causing OAuth URLs in the pending JSON object to be un-pasteable. Unit tests added to prevent regression.Removed dead code
IOstruct and parameter removed fromRun()— was accepted but never used; all writes go directly toos.Stdout/os.Stderr/os.Stdin.--quiet/io.Discardbranches removed from both login command files.msg.Blank()added to the msg package for consistent stderr blank-line spacingType of Change
Test Plan
You can test locally by piping stdin / stdout, or passing the
--jsonflag manually.Make sure the traditional login experience works as expected:
Note
Medium Risk
Changes
pc login/pc auth loginoutput behavior and login helper signatures, which could affect existing scripts and interactive UX, though core OAuth exchange remains the same.Overview
Improves
pc loginandpc auth loginfor non-interactive/agentic use by adding--jsonand auto-emitting JSON when stdout is not a TTY, while keeping human-readable messaging on interactive terminals.The login flow now prints structured JSON status objects (e.g.
pendingwith the OAuth URL,authenticated/already_authenticatedwith claims) to stdout, moves prompts and prose to stderr, and gates the "Press [Enter]" stdin reader on interactive stdin to avoid hanging in piped runs.Updates shared helpers (
login.Run,GetAndSetAccessToken) to takelogin.Options{Json: ...}, addsmsg.Blank()for consistent spacing, and adjusts JSON encoding (text.InlineJSON/IndentJSON) to disable HTML escaping (with new tests).Written by Cursor Bugbot for commit 64aea12. This will update automatically on new commits. Configure here.