ENG-11018: Make the cloud CLI agent-usable (--json everywhere, non-interactive off a TTY, --follow opt-in)

Merged
AM
3mo ago
+2201-452

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 logs at a terminal prints one page and exits instead of paging; pass --follow true for the old behavior. Kept as type=bool rather than a --follow/--no-follow pair on purpose — a flag pair would make an existing --follow false silently bind false to the optional app_id argument.
  • Off a TTY, commands take the non-interactive path without being asked. In practice that turns a hang into an error: reflex cloud apps list in CI with no token now exits 1 with Token is required for non-interactive mode. instead of opening a browser nobody can see.

Also fixed along the way

  • delete --json reports "deleted": false with the server's message when the delete is refused, rather than reporting a refused delete as a success. stop / start do the same.
  • logs --json keeps "could not read them" distinguishable from "there are none", via an error field that is null on the normal path.
  • generate_config returns the path it wrote, so config no longer prints "Configuration file generated." when it declined to overwrite an existing cloud.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/ and tests/units/reflex_base/utils/test_log.py, covering the JSON payload of each command, the TTY-derived interactive default, the --follow default, and that human-readable output stays off stdout while a document is on it.
  • Existing prompt-driven tests now pass --interactive explicitly, since CliRunner's stdout is not a terminal.
  • uv run pytest tests/units → 7651 passed, 18 skipped. ruff check / ruff format --check / pyright clean. Two failures left untouched because they reproduce on main: test_is_process_on_port_free_port (no IPv6 in my container) and a pyright error in tests/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, --interactive and apps 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?

Review in cubic

🤖 Generated with Claude Code

https://claude.ai/code/session_01UqTVZN9bsCxt7hz5U3qJok