Documentation
¶
Overview ¶
Package agentflags checks the options a launch passes to the coding agent, so every place that stores them (prompts and launch defaults) and the launcher that passes them apply the same rules.
It knows the agent's effort levels, what a model name may look like, which flags the launcher sets itself (and so may not be added by hand), and how to read extra flags typed on one line, quoted the way a shell would, into one argument each.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidEffort is returned for an effort level the agent does not accept. ErrInvalidEffort = errors.New("unknown effort level") // ErrInvalidModel is returned for a model name the agent could misread. ErrInvalidModel = errors.New("invalid model name") // ErrReservedFlag is returned for an extra flag the launcher sets itself. ErrReservedFlag = errors.New("reserved flag") // ErrEmptyFlag is returned for an empty extra argument. ErrEmptyFlag = errors.New("empty argument") // ErrNULByte is returned for an argument holding a NUL byte, which no process // argument can carry. ErrNULByte = errors.New("value contains a NUL byte") // ErrTilde is returned for an argument that starts with ~: launch scripts quote every // argument, so no shell expands it. ErrTilde = errors.New("~ is not expanded") // ErrUnterminatedQuote is returned by Split for a quote that is never closed. ErrUnterminatedQuote = errors.New("unterminated quote") )
Functions ¶
func CheckExtra ¶
CheckExtra checks extra arguments added by a prompt or a launch default. Each must be non-empty and free of NUL bytes, must not start with ~ or give a flag a value that does (--add-dir=~/x), since nothing expands it, and must not set a flag the launcher owns (see ReservedFlagError).
func EffortLevels ¶
func EffortLevels() []string
EffortLevels returns the values the agent accepts for --effort, lowest first.
func Join ¶
Join writes arguments on one line that Split reads back unchanged: an argument made only of letters, digits, and _@%+=:,./- is written as is, and any other is single-quoted.
func Split ¶
Split reads extra flags typed on one line into one argument each, the way a POSIX shell splits words, but without expanding anything: whitespace separates arguments, single quotes keep everything up to the next single quote, double quotes keep everything but an escaped \" or \\, and a backslash outside quotes keeps the next character. Two single quotes in a row make an empty argument. An unclosed quote is an ErrUnterminatedQuote. Split(Join(args)) returns args.
func ValidateEffort ¶
ValidateEffort accepts "" (the agent's default) or one of EffortLevels.
func ValidateModel ¶
ValidateModel accepts "" (the agent's default) or a model alias or full name: one word of printable characters, at most 100 long, that does not start with "-", so the agent can never read it as a flag.
Types ¶
type ReservedFlagError ¶
type ReservedFlagError struct {
// Flag is the argument as written, such as "--model" or "-w".
Flag string
// Reason completes the sentence "<flag> ...": what to do instead.
Reason string
}
ReservedFlagError is returned for an extra flag the launcher sets itself. Its message says which setting owns the flag.
func (*ReservedFlagError) Error ¶
func (e *ReservedFlagError) Error() string
Error reads like "--model is set by the Model setting".
func (*ReservedFlagError) Is ¶
func (e *ReservedFlagError) Is(target error) bool
Is makes a ReservedFlagError match ErrReservedFlag.