clihooks

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 2 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 IsStreamingSuspended added in v0.16.19

func IsStreamingSuspended() bool

IsStreamingSuspended reports whether SuspendStreaming is active. Called by the streaming callback to decide whether to suppress a chunk.

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).

Refcounted like SuspendStreaming: overlapping prompts (an approval prompt inside a WithCookedStdin callback, a parallel subagent's ask_user) each keep the pause alive for their own duration. Only the OUTERMOST PauseSteer actually stops the reader; inner pauses just count. A stray early resume from one prompt cannot resurrect the reader while another prompt is still on screen — the last- writer-wins behavior previously let an inner ResumeSteer restart the readLoop under a cooked-mode prompt, and the prompt's termios restore then wedged that loop in a blocking Read (VMIN=1) past Stop()'s 2s timeout.

func ResumeIndicator added in v0.16.18

func ResumeIndicator()

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

func ResumeSteer

func ResumeSteer()

ResumeSteer unwinds one PauseSteer. Only the outermost resume (depth returns to zero) restarts the reader. Clamped at zero so an unbalanced extra resume can never go negative and suppress a later legit pause.

func ResumeStreaming added in v0.16.19

func ResumeStreaming()

ResumeStreaming decrements the streaming-suspension depth. Clamped at zero so an unbalanced extra resume can never drive the counter negative and mask a later suspend. Safe to call when nothing was suspended (the counter floors at zero).

func SetResumeIndicator added in v0.16.18

func SetResumeIndicator(fn func())

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

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.

Installing or clearing the hooks marks a turn boundary, so the pause refcount is reset here: a leaked unbalanced pause (a prompt that returned without its deferred ResumeSteer) must not suppress the next turn's first real pause.

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 SuspendStreaming added in v0.16.19

func SuspendStreaming()

SuspendStreaming increments the streaming-suspension depth. The streaming callback (see IsStreamingSuspended) suppresses prose while the depth is greater than zero. Used by interactive prompts (security approvals, edit review) that render to the terminal while the agent's streaming goroutine may still be receiving chunks — without this, the streaming callback clobbers the prompt with mid-stream prose.

The depth is refcounted so overlapping prompts (e.g. a parallel subagent's ask_user plus a security elevation prompt) each keep the suspension alive for their own duration; a stray early ResumeStreaming from one prompt cannot clear the flag while another prompt is still on screen. Callers MUST pair each SuspendStreaming with a deferred ResumeStreaming.

func WithCookedStdin added in v0.16.2

func WithCookedStdin(fn func() error) error

WithCookedStdin runs fn with the activity-indicator suspended, the SteerInputReader paused, and streaming suspended so stdin is back in cooked mode for the duration of the call and no streaming prose clobbers anything the callback renders. Wraps the SuspendIndicator + SuspendStreaming + PauseSteer / ResumeSteer + ResumeStreaming + ResumeIndicator 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): all 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