Skip to content

fix(stdin): add is_stdin_interactive() helper - #108

Closed
KooshaPari wants to merge 1 commit into
masterfrom
fix/f-windows-stdin-detect
Closed

KooshaPari wants to merge 1 commit into
masterfrom
fix/f-windows-stdin-detect

Conversation

@KooshaPari

@KooshaPari KooshaPari commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

User description

Summary

Add three cross-platform stdin interactivity helpers to crates/jcode-core/src/stdin_detect.rs:

Function Returns true when...
is_stdin_interactive() stdin is a terminal (not piped/redirected)
is_stdin_terminal() stdin is a terminal (semantic alias)
is_stdin_pipe() stdin is piped/redirected (negation of above)

Motivation

From the F-code-quality audit: the stdin_detect module only exposed is_waiting_for_stdin(pid) (check a different process) with no helpers for checking the current process's stdin state. Many call sites in the codebase (auth, setup-hints, TUI, session-picker) inline std::io::stdin().is_terminal() directly. These helpers give a named, discoverable API.

Implementation

All three delegate to std::io::IsTerminal (stable since Rust 1.70), which uses:

  • Unix: isatty(STDIN_FILENO)
  • Windows: GetConsoleMode + GetFileType on the stdin handle

This is the same approach the codebase already uses in 15+ call sites. The new functions add documentation and a consistent namespace.

Tests

3 new unit tests verify the invariant relationships:

  • is_stdin_interactive() == is_stdin_terminal()
  • is_stdin_pipe() == !is_stdin_interactive()
  • is_stdin_interactive() == std::io::stdin().is_terminal()

Verification

  • cargo check -p jcode-core — clean
  • cargo test -p jcode-core -- stdin_detect_tests — 5/5 passed (3 new + 2 existing)

Related

  • F-code-quality audit artifact
  • Item 1 of 2 (Windows stdin detection)

CodeAnt-AI Description

Detect interactive terminals and piped input across platforms

What Changed

  • Callers can check whether stdin is an interactive terminal or is receiving piped or redirected input
  • Terminal checks use platform-native behavior on Unix and Windows

Impact

✅ Accurate terminal checks on Windows
✅ Interactive UI can distinguish terminal input from piped input

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Add three convenience functions to stdin_detect:

- is_stdin_interactive() - true when stdin is a terminal (not piped/redirected)
- is_stdin_terminal()   - semantic alias for is_stdin_interactive()
- is_stdin_pipe()       - true when stdin is piped/redirected (negation)

All three delegate to std::io::IsTerminal which uses isatty() on Unix
and GetConsoleMode on Windows, giving correct cross-platform behavior
without needing platform-specific cfg blocks.

Includes 3 unit tests verifying the invariant relationships.

tx-agent:     jcode
tx-validated: test
tx-scope:     crates/jcode-core/src/stdin_detect.rs
tx-intent:    Add cross-platform stdin interactivity helpers for Windows
Copilot AI balanced review requested due to automatic review settings October 17, 2026 06:45
@codeant-ai

codeant-ai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR b6e10d2 Oct 17, 2026 · 06:45 06:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codeant-ai

codeant-ai Bot commented Oct 17, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@coderabbitai

coderabbitai Bot commented Oct 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: fc1b28fd-ccff-4aa8-bda5-38c3b7219f9a
📥 Commits

Reviewing files that changed from the base of the PR and between 6cf71ed and b6e10d2.

📒 Files selected for processing: 2
  • crates/jcode-core/src/stdin_detect.rs
  • crates/jcode-core/src/stdin_detect_tests.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codeant-ai codeant-ai Bot added the size:M This PR changes 30-99 lines, ignoring generated files label Oct 17, 2026
@codeant-ai

codeant-ai Bot commented Oct 17, 2026

Copy link
Copy Markdown

CodeAnt PR Risk: Low Risk

  • The PR appears safe to merge; its stdin helpers consistently use Rust’s IsTerminal API to distinguish terminal input from redirected input.

Assessed commit: b6e10d2f0ced

KooshaPari added a commit that referenced this pull request Oct 17, 2026
Squash-merged from origin/fix/f-windows-stdin-detect. See PR #108 for the per-commit history.

tx-agent:     jcode
tx-validated: manual
tx-scope:     fix/f-windows-stdin-detect
tx-intent:    forward-path 2026-10-17 batch merge
tx-pr:        108
(cherry picked from commit 17632a2b0925df50ccaa2574694528fde961e7d7)
@KooshaPari

Copy link
Copy Markdown
Owner Author

Squash-merged into master via the forward-path 2026-10-17 batch (see commit on master). Closing as completed.

@KooshaPari KooshaPari closed this Oct 17, 2026
@kilo-code-bot

kilo-code-bot Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 5 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 5
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
crates/jcode-core/src/stdin_detect.rs 23 is_stdin_terminal() is a byte-for-byte duplicate of is_stdin_interactive() (both call std::io::IsTerminal::is_terminal(&std::io::stdin())). Copy-paste will drift. Delegate.
crates/jcode-core/src/stdin_detect_tests.rs 220 test_is_stdin_interactive_and_terminal_agree is a tautology — both functions are implemented identically, so the assertion can never fail.
crates/jcode-core/src/stdin_detect_tests.rs 228 test_is_stdin_pipe_is_negation_of_interactive is a tautology — is_stdin_pipe() is defined as !is_stdin_interactive(), so the assertion is true by construction.
crates/jcode-core/src/stdin_detect_tests.rs 234 test_is_stdin_interactive_consistency_with_is_terminal_trait is a tautology — is_stdin_interactive() is implemented as the raw trait call, so equality can never fail.
crates/jcode-core/src/stdin_detect_tests.rs 218 All three new tests are tautologies, so this PR adds zero verification of the new helpers. No behavioral or platform-specific test exists (e.g. under redirection, or Windows CI).
Files Reviewed (2 files)
  • crates/jcode-core/src/stdin_detect.rs - 1 issue
  • crates/jcode-core/src/stdin_detect_tests.rs - 4 issues

Reviewed by free · Input: 282.2K · Output: 38.2K · Cached: 165.4K

KooshaPari added a commit that referenced this pull request Oct 17, 2026
…ash commits)

5 of 6 audited forward-path PRs squash-merged into master via the
2026-10-17 batch (security, PR94 blockers, cherry-picks, stdin, println,
docs in priority order). 30 files / +2,900 / -78 LOC across the batch.

Master pre-batch:  3f4746e
Master post-batch: 521c66e

Per-PR squash SHAs:
  #108 -> 827ff9d  (cherry-pick from 17632a2b0)
  #109 -> 2f29ed0  (cherry-pick from 365d0a13a)
  #111 -> a1e19e5  (1 add/add conflict resolved: docs/GOOGLE_GUIDED_SETUP.md)
  #112 -> no-op      (rustls patch already in master; PR closed)
  #113 -> 7fdbe2f  (landed at cycle start; file-level cherry-pick of
                       update_product.rs only)
  #114 -> 521c66e

Source artifacts (canonical): phenotype-registry/audits/kcode-fork-forward-path-2026-10-17/
This directory: docs/audits/2026-10-17-forward-path-batch/  (HTML + PDF + README)

tx-agent:     jcode
tx-validated: manual
tx-scope:     docs/audits/2026-10-17-forward-path-batch/
tx-intent:    persist forward-path batch deliverables in source repo
tx-pr:        115
@KooshaPari KooshaPari reopened this Nov 5, 2026
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

@KooshaPari

Copy link
Copy Markdown
Owner Author

Closing under the host-ops closure audit (2026-11-11): the same change already landed on master (matching commit subject); this PR is the leftover branch. The branch fix/f-windows-stdin-detect is preserved on the remote, so the work is recoverable with git fetch origin fix/f-windows-stdin-detect or by reopening this PR. Nothing was deleted.

@KooshaPari KooshaPari closed this Nov 11, 2026
@KooshaPari
KooshaPari deleted the fix/f-windows-stdin-detect branch November 27, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants