screen

package
v0.16.355 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 10 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 screen reads what a coding agent's terminal UI (Claude Code, Codex) shows in a captured tmux pane: whether it is working, which menu or permission prompt is open, what the input line holds, whether a queued message waits, and which keys answer an AskUserQuestion dialog. Every function is pure: the caller captures the pane (plain, or styled with SGR attributes where a function says so) and decides what to do with the answer.

The patterns follow the agents' screens as captured in testdata. Whitespace and "any character" mean what they mean in the regular expressions the previous runtime used (JavaScript's \s and .), so both read a screen the same way.

Index

Constants

View Source
const (
	CodexUpdatePrompt   = "prompt"
	CodexUpdateUpdating = "updating"
	CodexUpdateSuccess  = "success"
)

Codex update screen states.

View Source
const (
	ClaudeModeDefault     = "default"
	ClaudeModeAcceptEdits = "acceptEdits"
	ClaudeModePlan        = "plan"
	ClaudeModeAuto        = "auto"
	ClaudeModeBypass      = "bypassPermissions"
)

Claude Code's permission modes as its footer names them; ClaudeModeDefault is a footer that names none.

View Source
const (
	// MaxAnswerOptions is the most options a question may have.
	MaxAnswerOptions = 8
	// KeyStepDelay follows every key or text; KeyAdvanceDelay follows each question's keys.
	KeyStepDelay    = 150 * time.Millisecond
	KeyAdvanceDelay = 350 * time.Millisecond
	// AnswerConfirmPoll and AnswerConfirmTimeout pace the wait for the dialog to leave the screen.
	AnswerConfirmPoll    = 250 * time.Millisecond
	AnswerConfirmTimeout = 3000 * time.Millisecond
)

Variables

This section is empty.

Functions

func AutoDenySeconds added in v0.16.5

func AutoDenySeconds(plain string) (int, bool)

AutoDenySeconds is how long Claude says it waits before it denies the request on the screen by itself ("1:17" is 77, "45" is 45); false when the screen says nothing of the kind. Only the last 40 lines are read.

func BuildAnswerSteps

func BuildAnswerSteps(shapes []QuestionShape, choices []QuestionChoice) [][]KeyStep

BuildAnswerSteps is the keys for every question in turn, one group per question, then "1" for "Submit answers" unless the call is one single-choice question. The request must have passed ValidateAnswerRequest.

func ChatAboutRow

func ChatAboutRow(screen string) (present, selected bool)

ChatAboutRow reads the «Chat about this» row of Claude's AskUserQuestion dialog off the plain screen: whether the dialog has it among its last lines, and whether the cursor (❯) stands on it.

func ClaudeBoxHoldsEnd added in v0.15.46

func ClaudeBoxHoldsEnd(box, text string) bool

ClaudeBoxHoldsEnd: Claude's box has read a paste of this message to its end — the box ends with the message's last 24 characters (white space and picture references aside), or Claude folded the paste into a "[Pasted text #n …]".

func ClaudeBoxPieceOf added in v0.15.40

func ClaudeBoxPieceOf(input, text string) bool

ClaudeBoxPieceOf: what is left in Claude's box (picture references aside) is a piece of text, however short — the box being cleared of a message of ours row by row.

func ClaudePermissionMode

func ClaudePermissionMode(plain string) (mode string, ok bool)

ClaudePermissionMode is the permission mode the footer under Claude's prompt box names, ClaudeModeDefault when it names none; ok is false when no prompt box is drawn (the footer cannot be told from the history then). Only the lines under the box's last border are read: the history above may quote any of the words.

func ClaudeStillInBox

func ClaudeStillInBox(input, text string) bool

ClaudeStillInBox: the text on Claude Code's input line (Read's Input, its first line) is this message — a "[Pasted text #n …]" token, or the message's start: the line's first 24 characters, image tokens and whitespace aside, begin the message, or the message's first 24 characters are on the line — or, for a message too long for the box, a piece of it at least 24 characters long. An empty line reads as gone.

func CodexLimitLine added in v0.15.40

func CodexLimitLine(plain string) string

CodexLimitLine is Codex's notice of the usage limit when it is the last thing above the composer — the turn that just ended stopped on it: «■ You've hit your usage limit. … try again at 6:05 PM.», its wrapped lines joined. "" when the last thing above the composer is anything else (an older notice the agent has written past).

func CodexStillInBox

func CodexStillInBox(screen, text string) bool

CodexStillInBox: Codex's prompt box (its last › line and the 5 lines under it) still holds the message — its first 24 characters, whitespace collapsed, or a "[Pasted Content …]" token. A placeholder or a steer list reads as gone.

func ConfirmFocus added in v0.15.40

func ConfirmFocus(plain string) (seen, yes bool)

ConfirmFocus reads the focused answer of Claude's "Switch model?"/"Change effort level?" from the lines under its title: seen is whether a focused numbered answer is on screen, yes whether it is "1. Yes…". It does not need the whole menu: in a short pane (a terminal docked under the chat) Claude's dialog is cut at the bottom and "2. No, go back" is not drawn, but its focused first answer is.

func CountEffortSet

func CountEffortSet(plain string) int

CountEffortSet counts Claude's "Set effort level to" and "Ultracode on" lines.

func CountFast

func CountFast(plain string, on bool) int

CountFast counts Claude's answers of /fast that leave the mode on, or off.

func CountFastRefused

func CountFastRefused(plain string) int

CountFastRefused counts Claude's answers that fast mode cannot run (another model, an account without it).

func CountKept

func CountKept(plain string) int

CountKept counts Claude's "Kept model"/"Kept effort" lines; a new one means the change was declined.

func CountModelSet

func CountModelSet(plain string) int

CountModelSet counts Claude's "Set model to" lines; a new one means a /model change was applied.

func CountPanelHints

func CountPanelHints(plain string) int

CountPanelHints counts the panel footer lines among the last 20 lines of a plain screen.

func CountUltracode added in v0.15.40

func CountUltracode(plain string, on bool) int

CountUltracode counts Claude's answers to "/effort ultracode on" ("Ultracode on (this session only): …") or, with on false, to "/effort ultracode off" ("Ultracode off. Effort stays high.").

func CountUltracodeRefused added in v0.15.40

func CountUltracodeRefused(plain string) int

CountUltracodeRefused counts Claude's refusals of "/effort ultracode on".

func CutShort added in v0.15.46

func CutShort(entry, text string) bool

CutShort: a user entry of the transcript is the start of this message and not all of it — Claude took the box while the paste was still coming in (a loaded machine) and read the rest as gone. Long enough not to be a coincidence.

func HasPermissionPrompt

func HasPermissionPrompt(pane string) bool

HasPermissionPrompt: the pane shows a permission prompt.

func InterruptedLast added in v0.15.40

func InterruptedLast(plain string) bool

InterruptedLast: the newest turn on a plain screen ended by the person's stop — Claude's «Interrupted · What should Claude do instead?» comes after the last line of the agent's output (● …); the turn's summary, a spinner and the prompt lines below it do not count.

func IsBusy

func IsBusy(plain string) bool

IsBusy: the bottom of a plain screen says the agent is working — Claude's spinner line, or "esc to interrupt" (Codex "Working (3s • esc to interrupt)", older Claude). While Claude streams text the spinner may be off screen, so callers also look at the hook-driven state.

func IsBusyAnywhere

func IsBusyAnywhere(plain string) bool

IsBusyAnywhere is IsBusy over the whole screen: a long todo list pushes the spinner above the last lines.

func IsChoiceComplete

func IsChoiceComplete(c QuestionChoice, otherOn bool) bool

IsChoiceComplete: a pick, or text once "Other" is open.

func IsCodexComposerReady

func IsCodexComposerReady(content string) bool

IsCodexComposerReady: a plain capture shows Codex's composer taking input — a composer line among the last 8 non-blank-ended lines, no "Input disabled." and no update prompt. Codex reports its session only after the first prompt, so this is how a fresh Codex tab is known to be up.

func IsInstantAnswer

func IsInstantAnswer(shapes []QuestionShape) bool

IsInstantAnswer: one single-choice question answers on the key press itself; every other call ends with the review screen.

func IsLaunchConfirm

func IsLaunchConfirm(plain string) bool

IsLaunchConfirm: Claude asks "Switch model?" or "Change effort level?".

func IsLaunchedPromptBoxReady

func IsLaunchedPromptBoxReady(pane string) bool

IsLaunchedPromptBoxReady is IsPromptBoxReady for an agent that was just launched in a pane that may still show the footer of the agent that ran there before: the footer counts only when it comes after the last launch line.

func IsPromptBoxReady

func IsPromptBoxReady(pane string) bool

IsPromptBoxReady: Claude's prompt box footer is among the last 8 non-empty lines of a plain screen (notices and the agents list may sit below it).

func IsQuestionOnScreen

func IsQuestionOnScreen(screen string) bool

IsQuestionOnScreen: the bottom of a plain Claude screen is the AskUserQuestion dialog — one of its question tabs (the footer starts with "Enter to select" and may wrap) or the review screen. Only the last 5 non-empty lines count: the conversation above may quote the words.

func JoinedIn

func JoinedIn(entry, text string) bool

JoinedIn: a user entry of the transcript holds this message as one of several. Claude reads the messages waiting in its queue at once, as one prompt of their texts one after another, a line apart (14.11, HRN-1470: two steered messages came as one `queued_command`). The message is a whole run of the entry's lines — not merely a part of a line — and not the whole entry (that is SameMessage's case).

func LastEcho added in v0.15.40

func LastEcho(plain, line string) (answer string, ok bool)

LastEcho is the answer Claude printed under the last echo of a command line («❯ /model opus» then «⎿ Set model to Opus 5.5 …»): the answer's first line, without its «⎿». ok is false when the command's echo is not on the screen. Counting answer lines alone misleads in a short pane, where an older answer scrolls off as the new one comes.

func MessageHash

func MessageHash(text string) string

MessageHash names a message's text the way SameMessage compares it — picture references and white space aside — so the agent's prompt-submit hook and the queue can say «this text» without carrying it. "" for a text with no words.

func OptionNumber

func OptionNumber(label string) (string, bool)

OptionNumber is the number a label starts with ("2" for "2. No"); false when it has none.

func PanelSnapshot

func PanelSnapshot(plain string) string

PanelSnapshot is the panel part of a plain screen: below Claude's ▔▔▔ top rule when there is one (the history above it is not the panel), without blank lines and rules, at most the last 30 lines.

func ParsePlanOptions

func ParsePlanOptions(pane string) []string

ParsePlanOptions reads the options of Claude's plan approval prompt: the first run of option lines (indented or marked) whose labels start with "Yes", "No" or "Tell Claude", number prefixes dropped.

func PicturesOnly

func PicturesOnly(entry string) bool

PicturesOnly: a user entry of the transcript holds picture references and nothing else — the entry of a message of pictures alone, which has no words to be known by.

func PlayAnswerSteps

func PlayAnswerSteps(groups [][]KeyStep, io KeyIO) error

PlayAnswerSteps sends the groups in order, KeyStepDelay after every step and KeyAdvanceDelay after every group. It stops at the first error.

func PreviewFromScreen

func PreviewFromScreen(questionCount int, screen string) bool

PreviewFromScreen stands in for a question's missing preview flag (a page of an older release sends none): a lone question has the preview layout when its footer offers notes; several questions are tabs whose layouts differ, so they keep the plain keys.

func QueueInPromptBox

func QueueInPromptBox(styled string) bool

QueueInPromptBox: Claude's prompt box shows queued messages — its input line holds the "Press up to edit queued messages" placeholder, or one of the 10 lines above it is the "ctrl+x ctrl+s to send now" hint. Only the prompt box counts: the agent's own output may quote the same words anywhere above it.

func ReadInputLine

func ReadInputLine(styled string) (text string, ok bool)

ReadInputLine reads the text typed into the TUI's own input line from a styled capture: the last line that starts at column 0 with ❯ or › (leading SGR resets aside). An input showing its dim placeholder reads "". ok is false when no input line is on screen. Only the input line itself counts: a wrapped draft is judged by its first line.

func SameMessage added in v0.15.40

func SameMessage(entry, text string) bool

SameMessage: a user entry of the transcript is this message — the same text, picture references and white space aside, or (a message long enough not to be a coincidence) the entry carries it whole, as Claude may wrap it.

func SpinnerLine

func SpinnerLine(line string) bool

SpinnerLine: the line is Claude's spinner — «✻ Working… (2s)».

func StripANSI

func StripANSI(s string) string

StripANSI removes terminal escape sequences from a styled capture.

func StripNumberPrefix

func StripNumberPrefix(label string) string

StripNumberPrefix drops a label's "1. ".

func TakesFreeText

func TakesFreeText(s QuestionShape) bool

TakesFreeText: the question has an "Other" row — every layout but the single-choice one with previews.

func TrustAcceptKeys

func TrustAcceptKeys(text string) []string

TrustAcceptKeys is the next step of answering a folder trust dialog with yes: the arrows to the yes option while another one is focused, and Enter only once the yes option is. They never go out together: an agent drops part of what it gets around its first paint, and an arrow lost in front of Enter answers "No, exit", which ends the agent. Nil when the text is not such a dialog or its focus cannot be read.

func TurnDoneLast added in v0.15.40

func TurnDoneLast(plain string) bool

TurnDoneLast: Claude says on a plain screen that its newest turn is over — the turn's summary or the stop mark lies between the person's last message (❯ …) and the input box. A turn waiting on the model shows neither, spinner or not, so a quiet screen without them is still a turn at work.

func ValidateAnswerRequest

func ValidateAnswerRequest(shapes []QuestionShape, choices []QuestionChoice) error

ValidateAnswerRequest refuses what the dialog could not take; nil when the choices fit the questions.

func WaitForQuestionGone

func WaitForQuestionGone(read func() (string, bool), sleep func(time.Duration)) bool

WaitForQuestionGone polls the screen every AnswerConfirmPoll for up to AnswerConfirmTimeout until the dialog is gone. read returns false when the screen cannot be read.

Types

type Aside added in v0.16.15

type Aside string

Aside is a screen of Claude Code the person opened in the terminal and left over the input box: a message from the chat cannot go in while it is up, and Esc closes it without changing anything.

const (
	NoAside     Aside = ""
	AsideLogin  Aside = "login"  // /login: «Select login method» or «Paste code here if prompted»
	AsideModel  Aside = "model"  // the /model picker
	AsideEffort Aside = "effort" // the /effort slider
)

func ClaudeAside added in v0.16.15

func ClaudeAside(plain string) Aside

ClaudeAside reads which aside is up at the bottom of a plain screen. Only screens whose own footer says Esc cancels them count, and only these: the trust dialog and the first-run login say «Esc to cancel» too, and there Esc quits Claude or does nothing — those are never closed. The footer has to be the screen's last line: with the input box up the last lines are the box and its status, so words the agent printed into the transcript never read as a dialog.

type CodexUpdate

type CodexUpdate struct {
	Status         string  `json:"status"`
	CurrentVersion *string `json:"currentVersion"`
	LatestVersion  *string `json:"latestVersion"`
	UpdateCommand  *string `json:"updateCommand"`
}

CodexUpdate is Codex's own update screen.

func MatchCodexUpdatePrompt

func MatchCodexUpdatePrompt(text string) *CodexUpdate

MatchCodexUpdatePrompt reads Codex's update screen from terminal text (wrapped lines are joined first): the prompt with both versions and the update command, the update running, or done; nil for anything else.

type KeyIO

type KeyIO interface {
	Key(name string) error
	Text(text string) error
	Sleep(d time.Duration)
}

KeyIO sends answer steps to the pane.

type KeyStep

type KeyStep struct {
	Literal bool
	Value   string
}

KeyStep is one thing to send: a tmux key name, or text typed literally.

type Menu struct {
	Title        *string  `json:"title"`
	Request      *string  `json:"request"`
	Options      []string `json:"options"`
	FocusedIndex int      `json:"focusedIndex"`
	// Cut: the window is too low for the menu, and it shows only the options that fit (Claude scrolls the list).
	Cut bool `json:"-"`
}

Menu is a numbered choice block with a focus marker near the bottom of the screen, with its title and question.

func FindMenu

func FindMenu(plain string) *Menu

FindMenu is the choice block in the last 25 lines of a plain screen; nil when there is none.

func (m *Menu) YesFocused() bool

YesFocused: the focus is on the first option and it reads "1. Yes…" — Claude's "Switch model?" asked with its default answer.

type Options

type Options struct {
	Options      []string `json:"options"`
	FocusedIndex int      `json:"focusedIndex"`
	Title        string   `json:"title,omitempty"`
	Request      string   `json:"request,omitempty"`
}

Options is a prompt's choices as drawn on screen: labels in screen order, the focused one, and the text above them. Title is set only when the block above starts with a checkbox heading (AskUserQuestion's ☐ tab); Request is the paragraph right above the options. Both are "" when absent.

func ParseChoiceOptions

func ParseChoiceOptions(pane string) Options

ParseChoiceOptions reads the last numbered choice block of a pane that has a focus marker (❯, › or >) and at least two options: AskUserQuestion, model pickers, Codex menus. Numbers are kept as drawn (a scrolled list skips some); a number not above the previous one starts a new block. Nothing found gives no options and focus 0.

func ParsePermissionOptions

func ParsePermissionOptions(pane string) Options

ParsePermissionOptions reads a permission prompt: numbered options first, unnumbered keyword options second, and only when they form a known pattern (Yes/No, Accept/Decline, Open System Settings, Use this/Continue without, the resume and idle-return dialogs). Anything else gives no options and focus 0.

type PromptOptions

type PromptOptions struct {
	Options
	// BypassPrompt: the pane is Claude's "Bypass Permissions" warning.
	BypassPrompt bool `json:"isBypassPrompt,omitempty"`
}

PromptOptions is what the permission-options route answers for a pane.

func ReadPromptOptions

func ReadPromptOptions(pane string) PromptOptions

ReadPromptOptions is a permission prompt when there is one, otherwise any choice menu.

type QuestionChoice

type QuestionChoice struct {
	Picked []int  `json:"picked"`
	Other  string `json:"other"`
}

QuestionChoice is what the person chose for one question: option indexes, and the free text of the "Other" row ("" when not used).

func ParseAnswer

func ParseAnswer(answer string, labels []string) QuestionChoice

ParseAnswer reads back the answer Claude Code records for a question: the labels of the picked options joined by ", " in click order, or the free text of "Other". Labels may themselves hold ", ", so the text is consumed label by label, and what no label matches is the free text.

type QuestionShape

type QuestionShape struct {
	OptionCount int  `json:"optionCount"`
	MultiSelect bool `json:"multiSelect"`
	// Preview: the options carry previews.
	Preview bool `json:"preview"`
}

QuestionShape is the part of a question the keys depend on.

type SendNowFrame

type SendNowFrame struct {
	// Input is the typed text of the input line; InputLine whether one is on screen.
	Input     string
	InputLine bool
	Menu      bool
	// Queued: Claude shows a waiting queue in its prompt box.
	Queued bool
}

SendNowFrame is what one look at the screen tells "send now".

func ObserveSendNow

func ObserveSendNow(styled string) SendNowFrame

ObserveSendNow reads a styled capture for "send now": the input line, an open menu, and the queue.

type State

type State struct {
	// Plain is the capture without escape sequences.
	Plain string
	Busy  bool
	Menu  *Menu
	// Panel: a panel or picker footer is among the last lines.
	Panel bool
	// Input is the typed text of the input line ("" when empty or when there is no input line); InputLine says
	// whether an input line is on screen at all.
	Input     string
	InputLine bool
}

State is one look at a styled capture.

func Read

func Read(styled string) State

Read classifies a styled capture.

type TrustPrompt

type TrustPrompt struct {
	// Agent is "claude" or "codex".
	Agent      string `json:"agent"`
	FolderPath string `json:"folderPath"`
}

TrustPrompt is an agent asking whether to trust the folder it starts in.

func MatchTrustPrompt

func MatchTrustPrompt(text string) *TrustPrompt

MatchTrustPrompt reads Claude's or Codex's folder trust dialog and the folder it is about; nil when the text is not such a dialog or names no absolute path.

Jump to

Keyboard shortcuts

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