Documentation
¶
Overview ¶
Package harness holds the types shared by the core packages and the harness-specific code behind them, so that terminput never imports provider and provider never imports terminput. What one harness draws on its screen, how its process is named and how its input box is emptied live behind the Composer interface, implemented per harness (claude/), never in the core. This package must not import other internal packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenSessions ¶
OpenSessions keys holders by session, leaving out the processes exclude reports (nil: none). It is the rule that makes a session open in a terminal: some live holder that is not the caller's own. When two processes hold one session, the highest pid (the newest, as a rule) wins, whatever the order of hs.
Types ¶
type Composer ¶
type Composer interface {
// Read parses a screen.
Read(screen string) Screen
// BoxShows compares the input box on screen with text.
BoxShows(screen, text string) Match
// IsAgentProcess reports whether comm, a tty's foreground command name
// or path, is the harness itself.
IsAgentProcess(comm string) bool
// RefuseText reports whether the harness would treat text as something
// other than a message (a shell escape; a command, unless allowCommands).
RefuseText(text string, allowCommands bool) bool
// RoomKeys is the probe for a box with text.
RoomKeys() RoomKeys
// ClearKeys are the keys that empty an input box of rows rows from any
// cursor position.
ClearKeys(rows int) []Key
}
Composer is one harness's terminal knowledge: it reads the screen and says which process is the harness, which texts it would not take as a message, and which keys make room in its input box.
type Holder ¶
Holder is a running harness process that holds a session open: its pid, the session it holds and the status the harness reports for it ("busy", "idle" or "").
type Key ¶
type Key string
Key is a single key sent to a terminal, such as "1" for a prompt option.
const ( KeyEscape Key = "escape" KeyEnter Key = "enter" KeySpace Key = "space" KeyBackspace Key = "backspace" // KeyClear empties the input row the cursor is on, from any cursor // position (drivers send end of line, then kill to line start). KeyClear Key = "clear" )
Keys other than digits that a terminal driver can press.
type LiveSessions ¶
LiveSessions reports the sessions a harness has open right now: every live holder by mode's rule, one per process and session, so a caller can leave out processes of its own before keying by session (OpenSessions). The error is Strict's; a List read never fails, and callers read an error as no session open.
type Match ¶
type Match struct {
// Words: the box holds the same words in order, only spacing and
// wrapping changed.
Words bool
// Shown: the box visibly holds the text, compared without whitespace.
Shown bool
// Typed: Shown, or, for text that is pasted (PasteText), the box shows
// the harness's paste placeholder: the text just typed waits there.
Typed bool
}
Match is how the input box compares with a given text.
type Mode ¶
type Mode int
Mode picks the rule a LiveSessions read applies. There is one source of holders and two rules, so the session list and the router can differ only where this table says (Claude Code's, discovery.LiveCache):
case List Strict registry holder live (pid alive, start ok) holder holder registry stale (pid gone or reused) none none registry unreadable (dir, a file, a decode) readable ones error found only by command line (claude <id>) none holder command line names id, live registry another the other the other aimux-owned adapter holder holder
Both modes return aimux's own adapter processes; callers leave them out (OpenSessions' exclude, the router's Manager.Owns), so an owned holder is never open in a terminal under either rule.
const ( // List is the session list's rule (open_in_terminal, terminal input, // the queue, waiting): it never fails, and a registry entry it cannot // read counts as no holder. List Mode = iota // Strict is the router's rule before an agent writes to a session: an // unreadable registry is an error, since the entry aimux cannot read may // be the terminal holding the session, and a live process with the // session on its command line holds it too. Strict )
type Prompt ¶
type Prompt struct {
// ID is stable for the same body, question and labels, so a retried key
// can be matched against the prompt it was meant for.
ID string
Question string
// Detail is what the prompt is about, as the harness shows it above the
// question (a tool and its argument, a file and a preview), bounded in
// size by the harness; empty when it cannot be read whole.
Detail string
Options []Option
}
Prompt is a permission prompt read from the screen.
type RoomKeys ¶
type RoomKeys struct {
// Probe, when set, is pressed first: a box that then reads empty held
// only a suggestion, which the message replaces. Unprobe, when set, is
// pressed when the box still holds text, to take Probe back out.
Probe, Unprobe Key
}
RoomKeys is how a harness's input box is made ready for a message when it holds text. The caller checks the screen and its own safety rules before every key.
type Screen ¶
type Screen struct {
// Prompt is the live permission prompt, or nil.
Prompt *Prompt
// Working: the harness shows it is working on a turn.
Working bool
// WorkingSeconds is how long the harness says the turn has run; 0 when
// it shows no time or is not working.
WorkingSeconds int
// InputEmpty: the live input box shows nothing typed (placeholders
// count as empty).
InputEmpty bool
// BoxHasText: with no prompt showing, the input box holds text, which
// may be the owner's draft or a suggestion the harness drew.
BoxHasText bool
// BoxRows is the number of text rows in the input box; 0 when none.
BoxRows int
// PasteMarker is the box's only row when that row is the harness's
// placeholder for a long paste; "" otherwise. It is never other text.
PasteMarker string
}
Screen is what a harness's screen shows, as one read sees it.
type SessionStore ¶
type SessionStore interface {
// SessionFile is the transcript of session id, or "" when there is none.
SessionFile(id string) string
// SessionCwd is the first working directory the transcript at path
// records; an error when it records none or cannot be read.
SessionCwd(path string) (string, error)
// Fingerprint changes whenever session id's transcript does; "" when
// there is no transcript.
Fingerprint(id string) string
}
SessionStore is where a harness keeps its session transcripts, as far as continuing a session needs it: the file of a session, the working directory the session recorded and a fingerprint that changes whenever the transcript does. Claude Code's is provider.Claude.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package claude is Claude Code's harness.Composer: it parses the screen Claude Code draws in a terminal (input box, permission prompt, working line, paste marker) and knows its process names.
|
Package claude is Claude Code's harness.Composer: it parses the screen Claude Code draws in a terminal (input box, permission prompt, working line, paste marker) and knows its process names. |