← Catalog

pi-agent-shell

High-performance interactive shell extension for pi — OS-level read-block detection gives agents a single turn() primitive with no polling or timing heuristics

Extension

Install

Install with PiG

pig install npm:pi-agent-shell

Install with Pi

pi install npm:pi-agent-shell
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./index.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 0.1.0 (README.md). PiG does not review it.

pi-agent-shell

A high-performance, general-purpose interactive shell extension for pi.

Gives AI agents a single turn() primitive to interact with any CLI program — no polling, no timing heuristics, no program-specific adapters. Uses OS-level read-block detection to know exactly when a program is waiting for input.

Install

pi install ~/Projects/pi-agent-shell

How it works

The agent interacts with shell programs through one atomic operation:

turn(sessionId, input?) → { newOutput, prompt, waitingForInput, exited }

Internally, turn() writes input to a PTY, drains output, and waits for an OS-level signal that the process is blocked on a read syscall. The agent never polls or guesses timing — every round-trip is a decision, not a timing check.

OS read-block detection

  • macOS: process state probing via ps on the leaf foreground process
  • Linux: /proc/{pid}/syscall — syscall number 0 (read) or select/epoll variants
  • Fallback: quiet-window timeout when OS probing is unavailable (CI, containers)

Tool: agent_shell

Start a session

{ "command": "python3 game.py" }
→ { "sessionId": "abc-123" }

Take a turn

{ "sessionId": "abc-123", "input": "north" }
→ { "newOutput": "You enter a dark cave.\n> ", "prompt": "> ", "waitingForInput": true }

Peek (non-blocking)

{ "sessionId": "abc-123", "peek": true }
→ { "newOutput": "...", "waitingForInput": false }

Kill a session

{ "sessionId": "abc-123", "kill": true }

Parameters

ParameterTypeDefaultDescription
commandstring—Shell command to start a new session
sessionIdstring—Session to interact with
inputstring—Text to send (appends \n if missing)
peekbooleanfalseNon-blocking snapshot, no input
killbooleanfalseTerminate the session
cwdstringpi cwdWorking directory
envobject—Additional environment variables
timeoutMsnumber30000Max wait time for turn()
quietMsnumber200Quiet-window fallback threshold

User commands

CommandDescription
/sessionsList all active sessions
/attach [id]Reattach the session overlay to watch/interact

Session overlay

When a session is running, an overlay shows real-time output. Controls:

  • Ctrl+B — background the session (overlay hides, session keeps running)
  • Ctrl+C — kill the session
  • ↑/↓ — scroll through output

Architecture

See ARCHITECTURE.md for design details.

Development

npm test        # run tests

Limitations

  • Line-oriented programs only — full-screen TUI programs (vim, nano, htop) are not supported. The agent has better tools for file editing (read/edit/write), and most interactive CLI programs have non-interactive equivalents.
  • Unix only — requires PTY support (macOS, Linux). No Windows/ConPTY support.
  • Local processes only — no remote PTY or SSH session management.