clihooks

package
v0.16.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package clihooks holds tiny callback hooks that wire higher-level CLI behavior (e.g. the activity-indicator spinner in pkg/console) into lower-level code paths (e.g. pkg/utils' AskForConfirmation, pkg/agent_tools' AskUser) without creating import cycles.

Owners of the hooks call SetSuspendIndicator at startup to register their implementation. Callers that are about to render a prompt invoke SuspendIndicator to clear the spinner from the terminal first. If no implementation is registered, SuspendIndicator is a no-op.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PauseSteer

func PauseSteer()

PauseSteer runs the registered pause hook if one is set. Callers that are about to read stdin in cooked mode (interactive prompts) MUST pair this with a deferred ResumeSteer so the reader resumes when the prompt returns. No-op when no hook is registered (e.g. non-interactive run, no active turn).

func ResumeSteer

func ResumeSteer()

ResumeSteer runs the registered resume hook if one is set.

func SetSteerHooks

func SetSteerHooks(pause, resume func())

SetSteerHooks installs the pause/resume hooks for the SP-055 SteerInputReader. The reader holds stdin in raw mode while a turn is in flight, which blocks any cooked-mode bufio reader (e.g. the security elevation prompt in pkg/utils.AskForConfirmation) from receiving input. Owners — typically SteerCoordinator — register the pair on StartTurn and clear it (with nil/nil) on EndTurn.

pause must stop the reader's goroutine and restore cooked termios. resume must re-enter raw mode and restart the reader. Both must be idempotent.

func SetSuspendIndicator

func SetSuspendIndicator(fn func())

SetSuspendIndicator installs (or clears, with nil) the global function used to stop the active CLI activity indicator. Called by the indicator owner (typically the agent CLI entry point).

func SuspendIndicator

func SuspendIndicator()

SuspendIndicator runs the registered suspend hook if one is set. Safe to call from anywhere; no-op when nothing is registered.

func WithCookedStdin added in v0.16.2

func WithCookedStdin(fn func() error) error

WithCookedStdin runs fn with the activity-indicator suspended and the SteerInputReader paused so stdin is back in cooked mode for the duration of the call. Wraps the SuspendIndicator + PauseSteer / ResumeSteer dance that interactive prompts and child-process editors must perform when invoked during a turn — the steer reader otherwise holds stdin in raw mode and bufio.Reader / term.ReadPassword calls hit EOF immediately.

Safe to call even when no indicator or steer reader is registered (e.g. non-interactive runs, slash commands that fire before the first turn): both hooks no-op in that case.

Callers that prefer the explicit pattern can still do so directly; this helper exists so the most common "I'm about to read stdin or spawn an interactive child process" idiom is a one-liner that's hard to get wrong.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL