intercept

package
v0.3.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package intercept preserves the historical regex-interceptor API as a thin compatibility facade over the backend-neutral adapters package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSensitiveText

func IsSensitiveText(value string) bool

IsSensitiveText reports whether text looks like a credential or secret prompt. It complements static Pattern.Sensitive metadata by classifying the actual matched output at runtime.

Types

type Detection

type Detection struct {
	Pattern     string
	Description string
	Match       string
	Sensitive   bool
}

Detection describes a prompt match emitted by an Interceptor.

type Hooks

type Hooks struct {
	OnOutput func()
	OnPrompt func(Detection)
}

Hooks receives lightweight output notifications and prompt detections. Hooks run synchronously after the Interceptor releases its lock, so they may safely call Output, Acknowledge, or Reblock.

type Interceptor

type Interceptor struct {
	// contains filtered or unexported fields
}

Interceptor owns the bounded output history and rolling ANSI-free detection window for one terminal stream. Consume is safe to call concurrently with Acknowledge, IsBlocked, Output, and Reblock.

func New

func New(patterns []Pattern, capacity int, hooks Hooks) (*Interceptor, error)

New validates patterns and creates an Interceptor with bounded output.

func (*Interceptor) Acknowledge

func (i *Interceptor) Acknowledge()

Acknowledge clears the blocked state and old detection tail so a later prompt can be detected without retriggering the prompt just answered.

func (*Interceptor) Consume

func (i *Interceptor) Consume(chunk []byte)

Consume sanitizes and retains a terminal-output chunk, then searches the rolling clean-text window for the first configured prompt. A partial ANSI sequence at the end of a chunk is carried into the next call.

func (*Interceptor) IsBlocked

func (i *Interceptor) IsBlocked() bool

IsBlocked reports whether a prompt is currently awaiting acknowledgement.

func (*Interceptor) Output

func (i *Interceptor) Output() string

Output returns an ordered copy of the bounded, sanitized terminal history.

func (*Interceptor) Reblock

func (i *Interceptor) Reblock()

Reblock restores the blocked state when delivering an answer fails.

func (*Interceptor) Run

func (i *Interceptor) Run(ctx context.Context, reader io.Reader) error

Run reads terminal output until EOF, cancellation, or an unexpected read error. The blocking read is intended to run in its own goroutine.

type Pattern

type Pattern = adapters.Pattern

Pattern remains an alias so existing intercept_patterns callers keep their source compatibility while GenericRegexAdapter owns regex interpretation.

func DefaultPatterns

func DefaultPatterns() []Pattern

DefaultPatterns returns an independent copy of the built-in prompt list.

Jump to

Keyboard shortcuts

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