Skip to content

feat(shell): PTY-based interactive command execution with SecureInput - #38510

Closed
ziuus wants to merge 2 commits into
anomalyco:devfrom
ziuus:feat/sudo-pty-interactive
Closed

ziuus wants to merge 2 commits into
anomalyco:devfrom
ziuus:feat/sudo-pty-interactive

Conversation

@ziuus

@ziuus ziuus commented Jul 23, 2026

Copy link
Copy Markdown

Summary

Add PTY-based interactive command execution for commands that require password/secure input (sudo, ssh -t, ansible -K, etc.). These commands previously failed because the ShellTool used ChildProcessSpawner with stdin: 'ignore'.

Implementation

This PR adds a SecureInput Effect service and integrates it into the ShellTool:

New module: packages/opencode/src/secure-input/

  • SecureInput Service — Effect layer with password prompt detection, PTY execution, and event-driven user input flow
  • SecureInputID — Newtype prefixed with sec_
  • Password prompt detection — Matches patterns like [sudo] password for user:, Password:, Enter passphrase:, etc.
  • Interactive command auto-detection — Matches commands starting with sudo, ssh -t, ansible -K, su, gpg
  • PTY execution — Uses bun-pty via the existing pty module to spawn commands, write passwords directly to the PTY fd (never stored or logged)
  • Event bus integration — secure-input.requested, .submitted, .cancelled, .timed-out events

Modified files

  • packages/opencode/src/tool/shell/prompt.ts — Added interactive?: boolean parameter with LLM-facing description
  • packages/opencode/src/tool/shell.ts — Added PTY execution branch activated by params.interactive or auto-detection
  • packages/opencode/src/tool/shell/shell.txt — Added usage note about interactive commands
  • packages/opencode/src/id/id.ts — Added secureinput: "sec" prefix
  • packages/opencode/src/effect/app-runtime.ts — Registered SecureInput layer
  • packages/opencode/src/server/routes/instance/ — Added /secure-input Hono routes (GET /, POST /:id/submit, POST /:id/cancel)
  • packages/opencode/src/server/routes/instance/index.ts — Registered routes

How it works

  1. LLM calls ShellTool with interactive: true (auto-detected for sudo/ssh/ansible)
  2. Tool spawns command via bun-pty instead of ChildProcessSpawner
  3. On detecting a password prompt in PTY output, publishes secure-input.requested event
  4. Password prompt is sanitized to [password supplied] in the returned output
  5. User submits via API (POST /:id/submit) or cancels (POST /:id/cancel)
  6. Password written directly to PTY — never stored, never logged

Follow-up work

  • TUI secure input prompt component (SolidJS)
  • Web app secure input prompt component
  • SDK client types

ziuus added 2 commits May 10, 2026 20:34
When OpenCode discovers skills from multiple scan paths (e.g. global ~/.agents/skills/ and project-level .agents/skills/), the same physical SKILL.md file can be found multiple times. The add() function would log a warning with identical existing and duplicate paths, then overwrite the same map entry.

This fix returns early when the same file path is encountered again, silencing the false-positive warning. If two different files share the same skill name, the warning is still shown as intended.

Fixes #26709
Add support for interactive commands (sudo, ssh -t, ansible -K) that
require password/secure input. Previously these commands would fail
because the tool used ChildProcessSpawner with stdin: 'ignore'.

Changes:
- Add SecureInput Effect service with:
  - Password prompt pattern detection (sudo, SSH, GPG, ansible, etc.)
  - Interactive command auto-detection
  - PTY-based command execution via bun-pty
  - Event-driven password request/submit/cancel/timeout flow
  - Password goes directly to PTY, never stored or logged
  - 60s timeout, output sanitization ([password supplied])
- Add 'interactive: boolean' parameter to ShellTool parameter schema
- Add PTY execution branch in ShellTool that activates on interactive
  flag or auto-detection
- Add SecureInputID identifier prefix (sec_)
- Add Hono API routes: GET /secure-input (list), POST /:id/submit,
  POST /:id/cancel
- Register SecureInput layer in AppRuntime
- Register routes in instance server
- Update shell.txt prompt template with interactive usage note

Output sanitization replaces detected password prompts with
'[password supplied]' before returning to the LLM.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jul 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 23, 2026
@github-actions github-actions Bot closed this Jul 23, 2026
@isavcic

isavcic commented Sep 23, 2026

Copy link
Copy Markdown

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

Just TWO HOUR window? Isn't this a bit overdramatic?

@ziuus

ziuus commented Sep 23, 2026

Copy link
Copy Markdown
Author

@isavcic absolutely right

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