Skip to content

feat(core): add interactive pty tool for retained REPL, debugger, and EOF-driven terminal sessions #65017

Open

Description

@zsicheng0214

Summary

OpenCode's shell tool handles one-shot commands and background jobs well, but agents currently have no native tool to drive an interactive pseudoterminal (PTY) across multiple steps — such as Python/Node REPLs, gdb/lldb/pdb debuggers, psql/redis-cli, interactive setup wizards, or programs that prompt for line input and canonical TTY EOF (Ctrl+D).

OpenCode already ships both PersistentPty.Service (backed by the embedded @opencode/pty daemon) and Pty.Service (#pty) for TUI terminals, but neither is exposed as an agent-callable tool.

Proposal

Expose a built-in pty tool (packages/core/src/tool/plugin/pty.ts) backed by PersistentPty.Service (with automatic fallback to local Pty.Service when the daemon is unavailable):

  • open: Launch a command (or login shell) in a retained PTY (cols/rows, TERM=xterm-256color, OPENCODE_SESSION_ID), enforcing the same ShellParse, FileAccess, and shell permission checks as ShellTool, returning { ptyID, status, exitCode, output, cursor, timedOut, matched }.
  • write: Send verbatim input (input, including \n when submitting a line), interrupt: true (Ctrl+C), or eof: true (Ctrl+D / \x04 canonical TTY EOF) to an owned ptyID and stream newly produced output.
  • read: Read or wait (waitFor substring or /regex/flags, bounded by timeout) for incremental output from the tracked session cursor.
  • close: Terminate and release a retained PTY session, returning any remaining unread output.
  • Session isolation & cleanup: Restrict write/read/close to the session that opened ptyID, and automatically tear down owned sessions on SessionEvent.Deleted.

Activity

  1. opencodejr commented on Nov 19, 2026

    @opencodejr
    Contributor

    Thanks for the detailed proposal, @zsicheng0214!

    You're asking for a built-in pty tool so the agent can keep an interactive terminal session (REPLs, debuggers, psql, setup wizards) open across steps. It would send input, Ctrl+C or Ctrl+D, and read new output as it arrives. Maintainers will consider it.

    What I found in the current V2 code:

    • The shell tool (packages/core/src/tool/plugin/shell.ts) takes command, workdir, timeout and background. Background commands return immediately and notify the session when they finish, and foreground commands that run past their timeout move to the background. I didn't find any way in that tool to send input to a process that is still running.
    • Plugins can define tools, but the only terminal access they get is experimental.terminal.read (packages/core/src/plugin/host.ts). So a plugin can't open a PTY, write to it or close it yet, and I haven't written one. If the plugin API exposed opening, writing to and closing a session-scoped PTY, this could also be built as a plugin.

    Related issues and PRs:

  2. added
    area/core
    type/feature
    version/v2
    on Nov 19, 2026
  3. zsicheng0214 commented on Nov 19, 2026

    @zsicheng0214
    Author

    Thanks! Per CONTRIBUTING.md ("wait for design approval before opening the implementation PR"), we pushed a focused V2 reference implementation + test suite (11/11 bun test covering both PersistentPty daemon and Pty fallback, tsc -b + oxlint clean) to TraceLite-AI:interactive-pty-tool in case it helps design review — happy to open a PR or adapt it to a PluginHost surface if maintainers prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coretype/featureversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions