Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(phrocs): add explicit input mode for sending keystrokes (#70138)

Georges-Antoine Assi1ba350393767
diff --git a/tools/phrocs/README.md b/tools/phrocs/README.md
index de95a6914b05..082a30e9cd7f 100644
--- a/tools/phrocs/README.md
+++ b/tools/phrocs/README.md
@@ -70,16 +70,20 @@ You typically run phrocs via `hogli start` rather than directly.
| `pgup` | Scroll output up |
| `home` | Jump to top of output |
| `end` | Jump to bottom of output |
+| `s` | Start selected process |
+| `x` | Stop selected process |
| `r` | Restart selected process |
| `R` | Restart all failed processes |
-| `s` | Stop selected process |
+| `l` | Clear logs of selected process |
| `c` | Enter copy mode |
| `i` | Show process info in pager |
| `o` | Sort processes by <name/CPU/RAM/status> |
| `g` | Cycle process grouping (from config `groups` field) |
| `a` | Toggle show all registry processes |
+| `t` | Enter setup mode (choose which services to run) |
| `/` | Enter search mode (then `tab` to switch to filter mode) |
| `esc` | Exit copy, search, and filter modes |
+| `↵` | Send keystrokes to the process (output pane) |
| `?` | Toggle full help |
| `q` | Quit |
@@ -91,6 +95,12 @@ Press `c` to enter copy mode in the output pane.
Navigate with `↑`/`↓`, press `c` again to mark the selection start, then extend with `↑`/`↓` and press `c` to copy to clipboard.
Press `esc` to exit without copying.
+### Sending input to a process
+
+Some processes wait for input on stdin, like a `(y/n)` confirmation, a REPL, an interactive CLI. Focus the output pane (`tab`), then type to send keystrokes to the process's PTY.
+
+phrocs auto-detects a prompt when the last output didn't end in a newline, and starts forwarding keystrokes right away. That heuristic misses prompts that print a trailing newline, so you can also press `↵` to enter **input mode** explicitly: every key then goes to the process until you press `esc` to leave.
+
### Search and filter modes
Press `/` to enter search mode, type a query, then use `↓`/`↑` to jump between matches.
diff --git a/tools/phrocs/internal/tui/app.go b/tools/phrocs/internal/tui/app.go
index 9900f01d570d..d697e14c62cf 100644
--- a/tools/phrocs/internal/tui/app.go
+++ b/tools/phrocs/internal/tui/app.go
@@ -92,6 +92,9 @@ type Model struct {
// Buffered text for PTY input when the output pane is focused
inputBuffer string
+ // Explicit input mode: forward keystrokes to the proc's PTY regardless of
+ // the HasPrompt() heuristic. Toggled on with enter, off with esc.
+ inputMode bool
// Show-all mode: display registry processes not in the current intent config
showAllRegProcs bool
@@ -505,6 +508,7 @@ func (m Model) loadActiveProc() (Model, []tea.Cmd) {
m.copyMode = false
m.searchMode = false
m.filterMode = false
+ m.inputMode = false
m.inputBuffer = ""
m.viewport.StyleLineFunc = nil
diff --git a/tools/phrocs/internal/tui/app_test.go b/tools/phrocs/internal/tui/app_test.go
index 6a360e3d6cc0..1f686880a69f 100644
--- a/tools/phrocs/internal/tui/app_test.go
+++ b/tools/phrocs/internal/tui/app_test.go
@@ -198,6 +198,75 @@ func TestFocus_mouseClickOutput(t *testing.T) {
}
}
+// ── Input mode ──────────────────────────────────────────────────────────────
+
+// startedModel returns a ready model with a single running process, skipping
+// the test if the subprocess can't be spawned in this environment.
+func startedModel(t *testing.T, shell string) (Model, *process.Process) {
+ t.Helper()
+ f := false
+ cfg := &config.Config{
+ Procs: map[string]config.ProcConfig{"proc": {Shell: shell, Autostart: &f}},
+ MouseScrollSpeed: 3,
+ Scrollback: 1000,
+ }
+ mgr := process.NewManager(cfg)
+ mgr.SetSend(func(tea.Msg) {}) // drain status/output so Start doesn't block
+ m := New(mgr, cfg, "", nil)
+ m = update(m, tea.WindowSizeMsg{Width: 120, Height: 40})
+ p := m.activeProc()
+ if err := p.Start(mgr.Send()); err != nil {
+ t.Skipf("cannot spawn subprocess: %v", err)
+ }
+ if !p.IsRunning() {
+ t.Skip("proc did not reach running state")
+ }
+ return m, p
+}
+
+func TestInputMode_enterAndExit(t *testing.T) {
+ m, p := startedModel(t, "sleep 30")
+ defer p.Stop()
+
+ m = update(m, specialKey(tea.KeyTab)) // focus output pane
+ if m.focusedPane != focusOutput {
+ t.Fatal("expected output focus after tab")
+ }
+ m = update(m, specialKey(tea.KeyEnter))
+ if !m.inputMode {
+ t.Error("enter should activate input mode on a running proc")
+ }
+ m = update(m, specialKey(tea.KeyEscape))
+ if m.inputMode {
+ t.Error("esc should leave input mode")
+ }
+}
+
+func TestInputMode_ignoredWhenProcNotRunning(t *testing.T) {
+ m := readyModel(t, "backend")
+ m = update(m, specialKey(tea.KeyTab))
+ if m.focusedPane != focusOutput {
+ t.Fatal("expected output focus after tab")
+ }
+ m = update(m, specialKey(tea.KeyEnter))
+ if m.inputMode {
+ t.Error("enter should not activate input mode when the proc is not running")
+ }
+}
+
+func TestInputMode_resetWhenLeavingOutputPane(t *testing.T) {
+ m := readyModel(t, "backend")
+ m.focusedPane = focusOutput
+ m.inputMode = true
+ m = update(m, specialKey(tea.KeyTab)) // back to sidebar
+ if m.focusedPane != focusServices {
+ t.Fatal("expected sidebar focus after tab")
+ }
+ if m.inputMode {
+ t.Error("leaving the output pane should reset input mode")
+ }
+}
+
// ── Help ──────────────────────────────────────────────────────────────────────
func TestHelp_toggle(t *testing.T) {
diff --git a/tools/phrocs/internal/tui/keymap.go b/tools/phrocs/internal/tui/keymap.go
index 90c76e058ab3..5c377b2747c3 100644
--- a/tools/phrocs/internal/tui/keymap.go
+++ b/tools/phrocs/internal/tui/keymap.go
@@ -25,6 +25,7 @@ type keyMap struct {
SearchPrev key.Binding
CommitFilter key.Binding
ToggleFilter key.Binding
+ InputMode key.Binding
Quit key.Binding
Help key.Binding
Backspace key.Binding
@@ -128,6 +129,10 @@ func defaultKeyMap() keyMap {
key.WithKeys("tab"),
key.WithHelp("↹:", "back to search"),
),
+ InputMode: key.NewBinding(
+ key.WithKeys("enter"),
+ key.WithHelp("↵:", "input"),
+ ),
Quit: key.NewBinding(
key.WithKeys("q", "ctrl+c"),
key.WithHelp("q:", "quit"),
diff --git a/tools/phrocs/internal/tui/keys.go b/tools/phrocs/internal/tui/keys.go
index b51dbff7a3bc..ce57e83c3b10 100644
--- a/tools/phrocs/internal/tui/keys.go
+++ b/tools/phrocs/internal/tui/keys.go
@@ -87,6 +87,11 @@ func (m *Model) cyclePane(dir int) {
for i, p := range panes {
if p == m.focusedPane {
m.focusedPane = panes[(i+dir+len(panes))%len(panes)]
+ // Leaving the output pane drops explicit input mode.
+ if m.focusedPane != focusOutput {
+ m.inputMode = false
+ m.inputBuffer = ""
+ }
m.dbg("focus: → %d", m.focusedPane)
return
}
@@ -361,11 +366,21 @@ func (m *Model) restartAllFailed() int {
return count
}
+// isForwardingInput reports whether keystrokes should go to the active proc's
+// PTY rather than the TUI. True when the output pane is focused, the proc is
+// running, and either the user explicitly entered input mode or the proc looks
+// like it's waiting for input (HasPrompt heuristic).
+func (m Model) isForwardingInput() bool {
+ p := m.activeProc()
+ return p != nil && m.focusedPane == focusOutput && p.IsRunning() &&
+ (m.inputMode || p.HasPrompt())
+}
+
func (m Model) handleNormalKey(msg tea.KeyPressMsg, cmds []tea.Cmd) (tea.Model, tea.Cmd) {
// When the active process is waiting for input, buffer keystrokes and send them on Enter.
p := m.activeProc()
- procHasPrompt := p != nil && m.focusedPane == focusOutput && p.HasPrompt()
- // Control keys are excluded so navigation still works.
+ // Control keys are excluded so navigation (pane switching, scrolling) still
+ // works even while keystrokes are being forwarded to the proc.
isControlKey := key.Matches(msg, m.keys.NextPane) ||
key.Matches(msg, m.keys.PrevPane) ||
key.Matches(msg, m.keys.GotoTop) ||
@@ -373,7 +388,15 @@ func (m Model) handleNormalKey(msg tea.KeyPressMsg, cmds []tea.Cmd) (tea.Model,
key.Matches(msg, m.keys.ScrollDown) ||
key.Matches(msg, m.keys.ScrollUp)
- if procHasPrompt && !isControlKey {
+ if m.isForwardingInput() && !isControlKey {
+ // esc always leaves explicit input mode without touching the proc.
+ if m.inputMode && msg.Code == tea.KeyEscape {
+ m.inputMode = false
+ m.inputBuffer = ""
+ m.dbg("input mode: exit")
+ return m, tea.Batch(cmds...)
+ }
+
var input []byte
switch msg.Code {
@@ -586,6 +609,17 @@ func (m Model) handleNormalKey(msg tea.KeyPressMsg, cmds []tea.Cmd) (tea.Model,
m.viewport.GotoTop()
m.dbg("info mode: enter")
+ case key.Matches(msg, m.keys.InputMode):
+ // Enter explicit input mode so keystrokes reach a proc that's waiting on
+ // stdin even when the HasPrompt heuristic didn't catch it. Skipped while
+ // a committed search (query survives a proc switch) is pending, so the
+ // footer's "enter: navigate" hint doesn't get hijacked into input mode.
+ if p != nil && m.focusedPane == focusOutput && p.IsRunning() && m.searchQuery == "" {
+ m.inputMode = true
+ m.inputBuffer = ""
+ m.dbg("input mode: enter")
+ }
+
case key.Matches(msg, m.keys.SetupMode):
m = m.enterSetupMode()
m.dbg("setup mode: enter")
diff --git a/tools/phrocs/internal/tui/render.go b/tools/phrocs/internal/tui/render.go
index e20adc240a2f..dddc36500e9b 100644
--- a/tools/phrocs/internal/tui/render.go
+++ b/tools/phrocs/internal/tui/render.go
@@ -316,9 +316,10 @@ func (m Model) viewportWithIndicator() string {
lines := strings.Split(view, "\n")
- // Show a cursor after the last line when the process is waiting for input.
+ // Show a cursor after the last line when keystrokes are being forwarded to
+ // the process (auto-detected prompt or explicit input mode).
if p := m.activeProc(); p != nil {
- showCursor := m.focusedPane == focusOutput && p.HasPrompt()
+ showCursor := m.isForwardingInput()
if showCursor {
lastLine := len(lines) - 1
lines[lastLine] = strings.TrimRight(lines[lastLine], " ") + " " + m.inputBuffer + "▌"
@@ -353,6 +354,11 @@ func (m Model) renderFooter() string {
return footerStyle.Width(m.width - 2).Render(
lipgloss.NewStyle().Foreground(colorBlue).Render(hint),
)
+ } else if p := m.activeProc(); m.inputMode && m.focusedPane == focusOutput && p != nil && p.IsRunning() {
+ hint := "-- INPUT -- send text to the process ↵: send ⌫: delete esc: cancel"
+ return footerStyle.Width(m.width - 2).Render(
+ lipgloss.NewStyle().Foreground(colorGreen).Render(hint),
+ )
} else if m.infoMode {
hint := "-- INFO -- i/esc: close"
return footerStyle.Width(m.width - 2).Render(
@@ -401,9 +407,9 @@ func (m Model) renderFooter() string {
if m.searchQuery != "" {
var matchInfo string
if len(m.searchMatches) == 0 {
- matchInfo = fmt.Sprintf("search: %q [no matches] esc: leave", m.searchQuery)
+ matchInfo = fmt.Sprintf("search: %q [no matches] esc: cancel", m.searchQuery)
} else {
- matchInfo = fmt.Sprintf("search: %q [%d/%d] ↵/⇧↵: navigate esc: leave", m.searchQuery, m.searchCursor+1, len(m.searchMatches))
+ matchInfo = fmt.Sprintf("search: %q [%d/%d] ↵/⇧↵: navigate esc: cancel", m.searchQuery, m.searchCursor+1, len(m.searchMatches))
}
return footerStyle.Width(m.width - 2).Render(
lipgloss.NewStyle().Foreground(colorYellow).Render(matchInfo),