shellwait

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package shellwait recognizes provider shell commands that block on external work, so a session can be redirected to a daemon-owned monitor instead. It inspects parsed commands rather than text, so a quoted mention of a watch in a commit message or a search pattern is not a wait.

Index

Constants

View Source
const (
	// MinDelaySeconds is the shortest wait that is redirected. It matches the
	// smallest timer monitor, so every denied delay has a monitor replacement.
	MinDelaySeconds = 5
	// MaxDelaySeconds is the longest timer monitor.
	MaxDelaySeconds = 86400
)
View Source
const HookCommandName = "shell-wait-hook"

HookCommandName is the hidden CLI verb a provider PreToolUse hook runs.

Variables

This section is empty.

Functions

func DenyReason

func DenyReason(finding Finding) string

DenyReason names the exact daemon-owned replacement for a detected wait.

func RunHook

func RunHook(stdin io.Reader, stdout io.Writer)

RunHook answers one PreToolUse hook call: it writes a deny decision for a shell wait and nothing otherwise. Every failure allows the command, because a broken guard must never stop a session's shell.

Types

type Finding

type Finding struct {
	Kind Kind
	// Argv is the unwrapped command for KindWatch.
	Argv []string
	// Source is the full command line for KindPoll, and for a KindWatch whose Argv
	// alone would lose its directory, environment, or dynamic arguments.
	Source string
	// Shell runs Source: bash, whose syntax Detect parses, or powershell.
	Shell string
	// Exact marks a KindWatch that Argv alone reproduces.
	Exact bool
	// DelaySeconds is the delay for KindSleep.
	DelaySeconds int
	// PullRequest marks a KindWatch on a pull request, which has a daemon-owned monitor of its own.
	PullRequest bool
}

Finding describes one detected wait and the data its redirect needs.

func Detect

func Detect(command string) (Finding, bool)

Detect reports the first wait in a POSIX shell command line. An unparsable command is allowed: the guard fails open.

func DetectPowerShell

func DetectPowerShell(command string) (Finding, bool)

DetectPowerShell reports the first wait in a PowerShell command line. It reads statements token by token because the POSIX parser rejects PowerShell loops.

func DetectToolInput

func DetectToolInput(raw json.RawMessage) (Finding, bool)

DetectToolInput reads a provider-native shell tool input. It accepts the command string of a Bash tool, the argv array Codex reports, and the command-plus-args shape of an ACP terminal/create request.

type Kind

type Kind string

Kind names the shape of a detected wait.

const (
	// KindWatch is a command that blocks until remote work finishes, such as gh pr checks --watch.
	KindWatch Kind = "watch"
	// KindSleep is a plain delay of at least MinDelaySeconds.
	KindSleep Kind = "sleep"
	// KindPoll is a loop that sleeps between checks.
	KindPoll Kind = "poll"
)

Jump to

Keyboard shortcuts

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