Skip to content

Centralize stdio TTY checks into dedicated functions#185

Merged
alexkroman merged 1 commit into
mainfrom
claude/upbeat-cerf-9xktom
Jun 16, 2026
Merged

Centralize stdio TTY checks into dedicated functions#185
alexkroman merged 1 commit into
mainfrom
claude/upbeat-cerf-9xktom

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

Summary

Introduces dedicated functions in the stdio module as single chokepoints for checking whether stdin, stdout, and stderr are interactive terminals. This centralizes TTY detection logic and makes it easier to test and mock terminal behavior across the codebase.

Changes

  • New stdio functions: Added stdin_is_tty(), stdout_is_tty(), and stderr_is_tty() as the canonical places to call isatty() on each stream
  • Updated interactive_stdio(): Now composes stdin_is_tty() and stdout_is_tty() instead of calling sys.stdin.isatty() and sys.stdout.isatty() directly
  • Updated callers: Replaced direct sys.stdin.isatty() and sys.stderr.isatty() calls in:
    • aai_cli/app/context.py (_interactive_session())
    • aai_cli/ui/output.py (_stdout_is_tty())
    • aai_cli/commands/login.py (_read_stdin_key())
  • Improved login key reading: Refactored _read_stdin_key() to use stdio.piped_stdin_text() instead of raw sys.stdin.read(), providing clearer semantics and better error handling
  • Comprehensive test coverage: Added tests for all three new TTY functions and interactive_stdio() to verify correct behavior with both TTY and piped inputs

Implementation Details

The new functions serve as mutation-resistant seams that:

  • Provide a single point of control for TTY detection across the codebase
  • Make it easier to test code paths that depend on terminal interactivity
  • Establish clear contracts for what "interactive" means in different contexts (stdin+stdout for prompting, stdin+stderr for browser login)

https://claude.ai/code/session_01UcQmBRzu1UL12DbFTGdiRf

Route the stdin-reading and isatty checks that bypassed the core/stdio
chokepoint through it:

- login --with-api-key now reads stdin via stdio.stdin_is_piped/
  piped_stdin_text instead of raw sys.stdin, so the one stdin reader
  outside the shared module no longer drifts from the others.
- Add named stdin_is_tty/stdout_is_tty/stderr_is_tty predicates as the
  single home for raw isatty calls; interactive_stdio composes them,
  and output._stdout_is_tty + context._interactive_session delegate to
  them instead of reaching for sys.{stdin,stdout,stderr} directly.

https://claude.ai/code/session_01UcQmBRzu1UL12DbFTGdiRf
@alexkroman alexkroman enabled auto-merge June 16, 2026 19:29
@alexkroman alexkroman added this pull request to the merge queue Jun 16, 2026
Merged via the queue into main with commit d58c173 Jun 16, 2026
19 checks passed
@alexkroman alexkroman deleted the claude/upbeat-cerf-9xktom branch June 16, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants