Skip to content

feat(terminal): read and select wait for typed input - #2542

Merged
chaliy merged 1 commit into
mainfrom
claude/project-thread-vu3h37
Oct 7, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/project-thread-vu3h37

Conversation

@chaliy

@chaliy chaliy commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

What changed

  • In a terminal session, read with no pipe or redirect now waits for a line typed on the terminal, instead of getting EOF. -p prints the prompt, -s turns echo off, -n N returns after N characters, and -t SECS gives up with status 142. Ctrl-D on an empty line is EOF (status 1), and Ctrl-C interrupts the command. Piped or redirected stdin still wins.
  • select shows its menu and PS3 and reads the choice from the terminal.
  • Prompt detection: Terminal::input_prompt() returns the question on the cursor line while a command waits for a typed line. This covers read -p, echo -n 'Q? '; read and select. TerminalTool reports activity: "input" with input_prompt, so an agent can tell a question apart from a busy command. Python input_prompt() and JS inputPrompt() mirror it.
  • Fixes found along the way: a reader dropped mid-wait (a read -t deadline, Ctrl-C) no longer leaves the session marked idle, and run_until_idle polls an idle session once more so an expired read -t fires.

Why

Interactive scripts (read -p "Continue? [y/N]", select menus) silently got EOF before. This change narrows L-TERM-002 to cat, head and other commands that still get EOF.

Before / After

$ read -p 'Name? ' n; echo "hi $n"
Before: prints "hi " immediately (EOF, rc=1)
After:  shows "Name? ", waits; typing "Ann Lee<Enter>" prints "hi Ann Lee"
TerminalTool: {"activity": "input", "input_prompt": "Overwrite? [y/N] ", ...}

Tests: terminal::tests::{read_waits_for_a_typed_line, read_flags_on_terminal, select_reads_choice_from_terminal} and terminal::tool::tests::question_is_reported_as_input. The L-TERM-002 evidence test now uses cat. Locally, all 2868 lib tests (--features terminal,git) and 1329 integration tests pass, and clippy is clean with and without terminal.

Risk

  • Low. The terminal path is behind the terminal feature, which is off by default. Without a terminal, read and select behave exactly as before.

Checklist

  • Tests added or updated
  • Backward compatibility considered

Generated by Claude Code

With no stdin inside a terminal session, read and select read a typed
line from the terminal (read -p/-s/-n/-t supported). Terminal::input_prompt
and TerminalTool activity "input" with input_prompt tell an agent a
command is asking a question. Narrows L-TERM-002 to cat/head and friends.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit e94da47 Commit Preview URL

Branch Preview URL
Oct 07 2026, 05:35 AM

@chaliy
chaliy merged commit 6796566 into main Oct 7, 2026
49 checks passed
@chaliy
chaliy deleted the claude/project-thread-vu3h37 branch October 7, 2026 06:00
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.

1 participant