ENG-11018: Make the cloud CLI agent-usable (--json everywhere, non-interactive off a TTY, --follow opt-in)
Delegating to the reflex cloud CLI is the alternative to reimplementing the cloud surface inside the Reflex MCP. Today an agent that tries has three ways to get stuck: it gets human-formatted tables to regex, a prompt can block it forever, and apps logs follows by default and never returns.
What changed
1. --json on every command. It was on apps inspect, apps list, apps history and a handful of project / providers reads. It is now on all 33 commands under reflex cloud, including the action-shaped ones that previously only logged their outcome: rollback, describe, build-logs, status, stop, start, delete, logs, scale, secrets update / delete, project invite / select / selected, create-token, config and gcp-standalone.
Emitting JSON is only half of it, because log lines land on stdout beside it. So passing --json now reserves stdout for the document: it is written straight to stdout, while log records, tables, rules, spinners and progress bars render to stderr for the duration (new reserve_stdout() in reflex-base). The reservation is also read off argv in the hosting_cli group callback — that callback emits its reflex-version warning before click has parsed the subcommand's options, so waiting for the parsed flag would let the warning land in front of the document.
2. Non-interactive when stdout isn't a TTY. One shared interactive_option replaces ~30 copies of default=True, resolving to sys.stdout.isatty() when neither spelling is passed. An explicit --interactive / --no-interactive still wins.
3. apps logs --follow defaults to off. Following means prompting between pages, and a prompt nobody answers is a command that never exits. It is now opt-in, and refused outright in JSON mode, where paging belongs to the caller (the response carries the next cursor).
Behavior changes to be aware of
reflex cloud apps logsat a terminal prints one page and exits instead of paging; pass--follow truefor the old behavior. Kept astype=boolrather than a--follow/--no-followpair on purpose — a flag pair would make an existing--follow falsesilently bindfalseto the optionalapp_idargument.- Off a TTY, commands take the non-interactive path without being asked. In practice that turns a hang into an error:
reflex cloud apps listin CI with no token now exits 1 withToken is required for non-interactive mode.instead of opening a browser nobody can see.
Also fixed along the way
delete --jsonreports"deleted": falsewith the server's message when the delete is refused, rather than reporting a refused delete as a success.stop/startdo the same.logs --jsonkeeps "could not read them" distinguishable from "there are none", via anerrorfield that isnullon the normal path.generate_configreturns the path it wrote, soconfigno longer prints "Configuration file generated." when it declined to overwrite an existingcloud.yml.
Deliberately not in scope
reflex deploy gets the TTY-based --interactive but no data --json: it already carries one from @log_options meaning JSON log records, and a second flag of the same name would collide. Its progress is a stream rather than a result, so the log-record form is the better fit anyway.
Testing
- 51 new tests across
tests/units/reflex_cli/andtests/units/reflex_base/utils/test_log.py, covering the JSON payload of each command, the TTY-derived interactive default, the--followdefault, and that human-readable output stays off stdout while a document is on it. - Existing prompt-driven tests now pass
--interactiveexplicitly, sinceCliRunner's stdout is not a terminal. uv run pytest tests/units→ 7651 passed, 18 skipped.ruff check/ruff format --check/pyrightclean. Two failures left untouched because they reproduce onmain:test_is_process_on_port_free_port(no IPv6 in my container) and a pyright error intests/units/docgen/.- Also exercised by hand against the real CLI, both under a pipe and under a pty.
Linear: ENG-11018
All Submissions:
- Have you followed the guidelines stated in CONTRIBUTING.md file?
- Have you checked to ensure there aren't any other open Pull Requests for the desired changed?
Type of change
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to not work as expected) — two defaults change, see Behavior changes above
- This change requires a documentation update — the CLI reference for
--json,--interactiveandapps logs --follow
New Feature Submission:
- Does your submission pass the tests?
- Have you linted your code locally prior to submission?
Changes To Core Features:
- Have you added an explanation of what your changes do and why you'd like us to include them?
- Have you written new tests for your core changes, as applicable?
- Have you successfully ran tests with your changes locally?
🤖 Generated with Claude Code