Skip to content

Let a bot type into a running program: shell tty and write_stdin - #322

Merged
lydakis merged 15 commits into
mainfrom
claude/project-thread-obvuqb
Oct 29, 2026
Merged

lydakis merged 15 commits into
mainfrom
claude/project-thread-obvuqb

Conversation

@lydakis

@lydakis lydakis commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

The last item borrowed from fx, after #299 and #306. George asked for it so bots can work with REPLs.

Until now a bot's shell gave commands no stdin. Anything waiting for typed input, like a REPL (python, node, psql, a debugger) or a Continue? [y/N] prompt, sat there until it timed out. This follows Codex's exec_command plus write_stdin, which fx also has.

What a bot gets

  • shell with tty: true runs the command in a pseudo-terminal that is its own session. It returns what the command wrote within yield_time_ms (default 1 s, at most 30 s). While the command runs, the result also carries a proc:N handle.
  • write_stdin {handle, chars, yield_time_ms, kill} types chars into that handle and returns what the command wrote since the last read. Control keys are sent as characters, for example \^C for Ctrl-C. An empty chars only reads. It waits 250 ms after typing and 5 s when only reading, which are Codex's defaults. kill: true ends the command's process group.
  • A terminal has no timeout and takes no process slot. It runs until it exits or is killed, across turns. wait on its handle reports how it ended (exit_code, or signal), along with any output no write read.
  • Output merges stdout and stderr, as a terminal does. The last 64 KiB of unread output is kept and anything dropped is counted. \r\n becomes \n, and output is redacted like every other tool result. Commands get the same environment as other shell commands, TERM=dumb included, which keeps REPLs on plain prompts. Codex does the same.

Checked by hand against real REPLs: python3 -q (assignments, a multi-line def, a sleep, exit() → exit 0) and node ([1,2,3].map(x => x * 2) → [ 2, 4, 6 ]).

Bounds and ownership

  • Each bot keeps at most 16 terminals. Starting a 17th kills the one it used least recently, as Codex prunes its sessions.
  • Only the bot that started a terminal can type into it. Any other bot, and any terminal that has ended, gets terminal_not_running.
  • Terminals end when the daemon stops (Registry::end_terminals runs in the shutdown path). Without that, a live terminal held up shutdown by 5 s. The runtime test checks that shutdown stays fast with one running.

Approvals and sandbox

  • A terminal never leaves its bot's sandbox: tty with require_escalated is refused. write_stdin is in sandbox::confinable, so a sandboxed bot's input runs without review, the same as its commands. For an unsandboxed bot, write_stdin is gated like shell (it is not in UNGATED), so auto judges what gets typed.
  • Known limit: under bubblewrap (--new-session) the command runs in a session of its own, so Ctrl-C typed into the terminal doesn't reach it there. kill does. On macOS (sandbox-exec) and for unsandboxed bots, Ctrl-C works and is tested.

Clients

  • write_stdin is a default tool, next to shell (client::default_tools). The docs' default lists are updated.
  • Sonny's verbose view shows Typed into proc:N "..." and Killed proc:N. The clean view hides it like any other ordinary call, so there's nothing new to screenshot.

Daemon cost

Nothing runs unless a bot starts a terminal. Each terminal costs one PTY, one reader task and one exit task. There's no new dependency: the PTY uses libc::openpty with tokio's AsyncFd. The shell description grew by one sentence; the detail went into write_stdin's own description, after a longer version tipped the tight-budget test_compaction pacing test.

Tests

  • tool_contract::a_terminal_takes_typed_input_and_reports_its_end: argument checks, a prompt that sees a terminal, typing an answer, the exit code on the write and on the handle, other bots refused, Ctrl-C delivering SIGINT, and kill ending a command that ignores SIGINT.
  • Runtime test_a_terminal_takes_input_across_turns_and_ends_on_its_handle: start in one turn, type in the next, wait on the handle, another bot refused, and a prompt daemon shutdown with a terminal still running.
  • A unit test for UTF-8 split across reads and for \r\r\n.
  • cargo test, clippy and fmt pass locally, as do the terminal runtime test and all of test_compaction on release builds. The earlier full runtime run failed only test_served's bubblewrap tests, which this container can't run.

claude added 10 commits October 28, 2026 23:23
A bot whose context left turns out could only read them by number, so it
had to guess where something was said. `history` now takes `query`
(and `before` to continue): it walks the lineage newest first, leaves out
the turn the search runs in, and lists up to 20 matches with their turn,
item type and the text around each, ignoring ASCII case. It stops at a
turn boundary after 20 matches or 64 MiB of items and names that turn as
`next_before`. The context note now mentions the search. Borrowed from
fx, whose compacted turns are searchable by text.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEJ3nWi13hKbRCL7Hh
A multiline item reads with its whitespace compacted, so a query copied
from a history page may not occur in the item as stored. The raw-item
prefilter now passes multiline items through to the view check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEJ3nWi13hKbRCL7Hh
Search is what a bot's provider offers, so Claude on Bedrock and other
gateways had no way to read a web page. `web_fetch` reads one http or
https URL from the daemon: up to ten redirects within 30 seconds, at most
4 MiB of body, text only. HTML comes back as Markdown with its title and
links made absolute; past 64 KiB the result shows the start and end and
keeps the whole as the call's `text` artifact for `read`. A status outside
2xx marks the result failed. Clients give it to every new bot unless
`web_search = "disabled"`. It is gated like any other tool, and `auto`
judges it, since its URL leaves the machine.

Commands now also get AI_AGENT=agent, the variable fx sets so tools can
tell an agent runs them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEJ3nWi13hKbRCL7Hh
Codex's review of #306: skipping hidden elements copied the rest of the
page each time, so many of them made conversion quadratic, and it ran on
the daemon's one runtime thread; deep lists indented without bound; code
blocks lost blank lines; a literal < swallowed text up to the next >;
and Latin-1 pages were misread as UTF-8.

Conversion now runs on a blocking thread, finds a hidden element's close
tag without copying, indents at most 8 levels and cuts Markdown at 8 MiB.
Code blocks keep their lines as they are, a < that opens no tag is text,
and Latin-1 reads as windows-1252, as browsers read it; other charsets
are refused with web_fetch_charset.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEJ3nWi13hKbRCL7Hh
Codex's second review of #306: charset= anywhere in a page's first KiB
picked its decoder, so text that named one could; a base element was
ignored, sending relative links to the wrong place; and unclosed links
kept piling up resolved targets. Now only a meta tag declares a charset,
base moves where relative links lead, and an opening link ends the one
still open, as HTML has it, so at most one is pending.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEJ3nWi13hKbRCL7Hh
…and read attributes whole

Codex's third review of #306: decoding a large body still ran on the
runtime thread; a page past 1 MiB was kept as its head and tail with
nothing marking the gap, as a shell stream marks it; and an attribute
name inside another attribute's quoted value was taken for the real one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEJ3nWi13hKbRCL7Hh
As Codex's exec_command and write_stdin: shell with tty=true runs the
command in a pseudo-terminal and returns what it wrote within
yield_time_ms, with a proc handle while it runs. write_stdin types into
it (control keys as characters), reads what it wrote since, or kills it.
A terminal runs until it exits or is killed, across turns; wait on its
handle reports how it ended. Each bot keeps at most 16, pruning the one
it used least recently, and terminals end when the daemon stops.

A terminal never leaves its bot's sandbox, so a sandboxed bot's input
runs without review as its commands do; an unsandboxed bot's write_stdin
is gated like shell. write_stdin is a default tool beside shell.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEJ3nWi13hKbRCL7Hh
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T01:41:13.273859Z ac9d351 New commits
🔒 Security Review ✅ Completed 2026-10-29T01:42:56.304679Z ac9d351 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad265194c5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server/turn.rs Resolved
Comment thread src/server/turn.rs Resolved
Comment thread src/tools/terminal.rs Resolved
Comment thread src/tools/terminal.rs Resolved
Comment thread src/tools/terminal.rs Resolved
A terminal remembers the sandbox it started under; input typed after the
bot's sandbox changed ends it instead of running outside the new one.
While the command runs, a read holds back trailing carriage returns and
any tail that could begin a credential, so a credential split across two
reads is redacted whole. Line ends are normalized in one pass, and a
terminal belongs to its bot's id rather than its reusable name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEJ3nWi13hKbRCL7Hh

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 458a0cf6c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/tools/terminal.rs Resolved
Comment thread src/tools/terminal.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e8f60beea

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/tools.rs Resolved
Comment thread src/tools/terminal.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac9d351006

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/tools/terminal.rs Resolved
Comment thread src/tools/terminal.rs Resolved
@lydakis
lydakis merged commit bf3782a into main Oct 29, 2026
4 checks passed
@lydakis lydakis mentioned this pull request Oct 29, 2026
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