Centralize stdio TTY checks into dedicated functions#185
Merged
Conversation
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
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.
Summary
Introduces dedicated functions in the
stdiomodule 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
stdin_is_tty(),stdout_is_tty(), andstderr_is_tty()as the canonical places to callisatty()on each streaminteractive_stdio(): Now composesstdin_is_tty()andstdout_is_tty()instead of callingsys.stdin.isatty()andsys.stdout.isatty()directlysys.stdin.isatty()andsys.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())_read_stdin_key()to usestdio.piped_stdin_text()instead of rawsys.stdin.read(), providing clearer semantics and better error handlinginteractive_stdio()to verify correct behavior with both TTY and piped inputsImplementation Details
The new functions serve as mutation-resistant seams that:
https://claude.ai/code/session_01UcQmBRzu1UL12DbFTGdiRf