design.md icon indicating copy to clipboard operation
design.md copied to clipboard

fix(stdin): show TTY hint when reading from interactive terminal

Open Emp1500 opened this issue 5 months ago • 0 comments

Problem

When a user runs a design.md command with - as the file path from an interactive terminal, the process hangs silently with no output:

$ design.md lint -
█  ← cursor blocks here indefinitely

There is no indication that the tool is waiting for input, or that the user must press Ctrl+D to signal end-of-file. A user unfamiliar with this Unix convention has no feedback to distinguish a stalled process from one that is working correctly.

Root Cause

readInput reads stdin via for await (const chunk of process.stdin) with no TTY detection. When stdin is an interactive terminal (process.stdin.isTTY === true), the loop blocks until EOF — but nothing prompts the user to send one.

Solution

Before entering the read loop, check whether stdin is a TTY and, if so, emit a one-line hint to stderr:

Piped usage is completely unaffected — isTTY is false for pipes, so the hint never appears and existing behavior is unchanged:

cat DESIGN.md | design.md lint -   # works exactly as before

Design Decisions

  • readInput now accepts an optional stdin stream parameter that defaults to process.stdin. All existing call sites remain unchanged.
  • The optional parameter makes the TTY code path fully unit-testable via injected mock streams, without any need to mock globals.
  • StdinStream is exported so test files can type mock streams without duplicating the interface definition.

Changes

File Change
utils.ts Export StdinStream type; add optional stdin param to readInput; add TTY check before read loop
utils.test.ts 4 new tests: piped content, empty stream, TTY hint emission, non-TTY silence — all using injected mock streams

Emp1500 avatar Jun 28 '26 05:06 Emp1500