screenrules

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package screenrules holds the rules the holder reads coding agents' screens with (internal/holder/prompt.go): how each harness draws its menus and question UIs — its cursor, the patterns of its key hints and headers, how many rows to look at, and which of the holder's ways of finding a dialog's top edge, frame or question UI applies. What can only be written as code (walking the rows, the box characters) stays in the holder; the rules pick it by name.

The rules stagent ships are embedded, one file per harness and one shared by all (builtin/<name>.json). A host overrides them with a file of the same name in ~/.ssh-term/agent/screen-rules (paths.Layout.ScreenRules), so a screen that changed can be followed without a new stagent release; a holder reads them when it starts. An override is laid over its built-in file: the members it names replace the built-in ones (an object member by member), null turns a rule off. A file that cannot be read or does not make valid rules is not used — those rules stay built-in — and Set.Files says why (stagent doctor, stagent explain, the holder's log).

Index

Constants

View Source
const (
	// EdgeSolidRule: a solid rule (─━═▔) starting in the first column.
	EdgeSolidRule = "solid_rule"
	// EdgeFirstColumn: a line with text in its first column.
	EdgeFirstColumn = "first_column"
	// EdgeBoxTop: a line whose text starts with ╭.
	EdgeBoxTop = "box_top"
	// EdgeShallowIndent: a line with text indented two columns at most.
	EdgeShallowIndent = "shallow_indent"
)

Ways of finding the top edge of a harness's dialog (Menu.DialogEdge): the nearest line above the options that is one.

View Source
const (
	// QuestionHintAndHeader: a key hint among the last rows of the screen
	// and, above it, a header with nothing between starting in the first
	// column; or, when the header scrolled away, indented rows reaching
	// the top of the screen.
	QuestionHintAndHeader = "hint_and_header"
	// QuestionBottomBox: a box at the bottom of the screen whose top edge
	// matches a title; or, when that edge scrolled away, whose rows reach
	// the top of the screen with an option under a cursor.
	QuestionBottomBox = "bottom_box"
)

Kinds of question UIs (Question.Kind).

View Source
const (
	// EdgeOutsideBar: a line that is not in the bar.
	EdgeOutsideBar = "outside_bar"
	// EdgeTitleMark: a line holding Dialogs.TitleMark.
	EdgeTitleMark = "title_mark"
)

Ways of finding the top edge of a dialog drawn right of a bar (Dialogs.DialogEdge): the nearest line above the options that is one.

View Source
const (
	// DialogChoiceRow: all options on one row matching Row, two or more
	// spaces apart, without numbers or a cursor; Hint on one of the
	// HintRows non-blank lines under it.
	DialogChoiceRow = "choice_row"
	// DialogNumberedRows: options numbered `1. label` (a description
	// indented under each) without a cursor, right above the lowest line
	// matching Hint.
	DialogNumberedRows = "numbered_rows"
	// DialogRadioRows: consecutive rows in the bar numbered from 1 with a
	// radio mark after the number (`2 (●) label`; z, the row to type an
	// answer in, last), ● on the highlighted one; Hint on one of the
	// HintRows non-blank lines under them.
	DialogRadioRows = "radio_rows"
	// DialogTitledRows: under a line reading Title, consecutive lines
	// matching Rows one by one; an option's label is its text up to two
	// spaces.
	DialogTitledRows = "titled_rows"
)

Kinds of dialogs drawn right of a bar (Dialog.Kind).

View Source
const (
	// HintInBar: in the bar.
	HintInBar = "bar"
	// HintOutsideBar: not in the bar (below it).
	HintOutsideBar = "outside_bar"
)

Where a dialog's key hint is (Dialog.HintPlace): anywhere ("").

View Source
const Common = "common"

Common is the name of the file of the rules every harness shares.

View Source
const FrameBox = "box"

FrameBox is Menu.Frame of a harness that draws its menus inside a `│ … │` box: they are read there only, a wrapped label continuing at the column of its number.

View Source
const UnnumberedTitledDialog = "titled_dialog"

UnnumberedTitledDialog is Unnumbered.Kind of a menu without numbers that only a dialog of a given title has: options in one column, one under the menu's cursor, a key hint below them.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommonMenu

type CommonMenu struct {
	Hint           *Regexp `json:"hint"`
	HintRows       int     `json:"hint_rows"`
	TranscriptMark *Regexp `json:"transcript_mark"`
}

CommonMenu: a menu has a key hint (Hint) within HintRows rows under its options, or nothing but blanks below them; a transcript entry there (TranscriptMark) makes the list part of the conversation.

type CommonRules

type CommonRules struct {
	Menu *CommonMenu `json:"menu"`
}

CommonRules are the rules of every harness's menus (common.json).

type Dialog

type Dialog struct {
	Kind      string    `json:"kind"`
	Row       *Regexp   `json:"row,omitempty"`
	Hint      *Regexp   `json:"hint,omitempty"`
	HintRows  int       `json:"hint_rows,omitempty"`
	HintPlace string    `json:"hint_place,omitempty"`
	Title     string    `json:"title,omitempty"`
	Rows      []*Regexp `json:"rows,omitempty"`
}

Dialog is one dialog of Dialogs, read the way Kind (Dialog*) names: DialogChoiceRow uses Row, Hint and HintRows; DialogNumberedRows uses Hint; DialogRadioRows uses Hint and HintRows; DialogTitledRows uses Title and Rows. HintPlace (Hint*) says where the hint is.

type Dialogs

type Dialogs struct {
	Bar        string  `json:"bar"`
	ScrollBar  string  `json:"scroll_bar,omitempty"`
	DialogEdge string  `json:"dialog_edge"`
	TitleMark  string  `json:"title_mark,omitempty"`
	Permission *Dialog `json:"permission,omitempty"`
	Question   *Dialog `json:"question,omitempty"`
	Trust      *Dialog `json:"trust,omitempty"`
}

Dialogs are the menus of a harness that draws its dialogs right of a bar (Bar, `┃`) and tells them by their rows and key hints rather than by a cursor: its permission dialog (Permission), its question tool's (Question, the harness's question UI) and its folder trust prompt (Trust), each read the way its Kind (Dialog*) names; the first of them the screen shows is the harness's menu. DialogEdge (EdgeOutsideBar, or EdgeTitleMark with TitleMark) finds a dialog's top edge. ScrollBar is the scroll bar the harness draws in the last column, left out.

type Ends

type Ends struct {
	LastLabel  *Regexp `json:"last_label"`
	Below      *Regexp `json:"below"`
	Rows       int     `json:"rows"`
	ScrollBar  string  `json:"scroll_bar,omitempty"`
	Permission bool    `json:"permission,omitempty"`
}

Ends tells a numbered menu of the harness that has no key hint below it by its own end: the label of its last option matches LastLabel, and within Rows rows under that option there is nothing but blanks before a line matching Below (a spinner) or the bottom of the screen. ScrollBar is the scroll bar the harness draws in the last column, left out of both. With Permission, the first option (number 1) of such a menu allows the call whatever its label (a translated one): the menu is a permission prompt.

type File

type File struct {
	Path string
	// Name is the file's name without .json: Common or a harness id.
	Name string
	// Err is why the file is not used; nil when it is.
	Err error
}

File is one override file.

type Menu struct {
	Cursor          string  `json:"cursor"`
	DialogEdge      string  `json:"dialog_edge"`
	Frame           string  `json:"frame,omitempty"`
	PermissionLabel *Regexp `json:"permission_label,omitempty"`
	Ends            *Ends   `json:"ends,omitempty"`
}

Menu is how the harness draws its numbered menus: Cursor marks the highlighted option, DialogEdge (Edge*) finds the dialog's top edge (the text from there to the options identifies a permission prompt), Frame ("" or FrameBox) says whether they are in a box, and a menu whose first option (number 1) matches PermissionLabel is a permission prompt. Ends tells a menu with no key hint below it; with Ends.Permission, such a menu is a permission prompt too, and PermissionLabel may be left out.

type Question

type Question struct {
	Kind     string  `json:"kind"`
	Header   *Regexp `json:"header,omitempty"`
	Hint     *Regexp `json:"hint,omitempty"`
	HintRows int     `json:"hint_rows,omitempty"`
	Title    *Regexp `json:"title,omitempty"`
	Cursor   string  `json:"cursor,omitempty"`
}

Question is the UI of a question the harness asked through its question tool, for a harness that draws it as no menu of its own (Kind Question*). QuestionHintAndHeader uses Header, Hint and HintRows (the rows from the bottom the hint may be on); QuestionBottomBox uses Title and Cursor.

type Regexp

type Regexp struct {
	*regexp.Regexp
	// contains filtered or unexported fields
}

Regexp is a regular expression of a rules file, its source in JSON; validating the rules compiles it.

func (*Regexp) MarshalJSON

func (r *Regexp) MarshalJSON() ([]byte, error)

func (*Regexp) UnmarshalJSON

func (r *Regexp) UnmarshalJSON(b []byte) error

type Rules

type Rules struct {
	Menu       *Menu       `json:"menu,omitempty"`
	Unnumbered *Unnumbered `json:"unnumbered,omitempty"`
	Question   *Question   `json:"question,omitempty"`
	Dialogs    *Dialogs    `json:"dialogs,omitempty"`
}

Rules are the rules of one harness (<harness>.json); a harness that draws no menu or question UI of its own has none.

type Set

type Set struct {
	// Dir is the override directory read ("" for Builtin).
	Dir       string
	Common    CommonRules
	Harnesses map[string]Rules
	// Files are the override files found in Dir, by name; Err is why one
	// is not used.
	Files []File
	// contains filtered or unexported fields
}

Set is the rules in force: built-in, with the overrides of a directory laid over them.

func Builtin

func Builtin() *Set

Builtin returns the rules stagent ships.

func Load

func Load(dir string) *Set

Load returns the built-in rules with the overrides in dir laid over them. A missing dir has none.

func (*Set) FileReport

func (s *Set) FileReport() []wire.ScreenRulesFile

FileReport lists the override files as `stagent doctor` and `stagent explain` report them.

func (*Set) Origin

func (s *Set) Origin(name, rule string) string

Origin returns the override file that set rule (menu, unnumbered, question, dialogs) of name (Common or a harness id), "" when it is built-in.

func (*Set) Rule

func (s *Set) Rule(name, rule string) json.RawMessage

Rule returns rule of name as its file has it, null when there is none.

type Unnumbered

type Unnumbered struct {
	Kind  string `json:"kind"`
	Title string `json:"title"`
}

Unnumbered is a menu of the harness without numbers (Kind UnnumberedTitledDialog), recognized in the dialog Title only: the first line under its top edge (Menu.DialogEdge), its options under Menu.Cursor.

Jump to

Keyboard shortcuts

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