Documentation
¶
Index ¶
- Constants
- Variables
- func BracketedPaste(text string) string
- func ClassifyFrame(tail []byte, cols, rows int) (bool, string)
- func ClassifyScreen(text string) (bool, string)
- func ClearsOnEsc(runner string) bool
- func CollapseRedraws(b []byte) []byte
- func Flatten(b []byte) []byte
- func FormatRepairReport(events []RepairEvent) string
- func FrameHasInterrupt(tail []byte, cols, rows int) bool
- func FrameInterrupted(tail []byte, cols, rows int) bool
- func FrameLineEmpty(tail []byte, cols, rows int) bool
- func FramePromptEmpty(tail []byte, cols, rows int) bool
- func FramePromptText(tail []byte, cols, rows int) string
- func FrameText(sc *Screen) string
- func IsRule(ln string) bool
- func MaxInt(a, b int) int
- func MinInt(a, b int) int
- func RenderHistory(b []byte, cols int) []byte
- func Replay(b []byte, mode string, cols, rows int) []byte
- func ReplayCols(widths []int, wantCols int) int
- func ReplayCut(b []byte, mode string, cuts []SizeCut, rows int) []byte
- func ReplayMode(st *store.Store) string
- func SplitKeepingEndings(b []byte) [][]byte
- func StripPasteMarkers(text string) string
- func StripSGR(b []byte) []byte
- type EscParser
- type RepairEvent
- type RepairWatch
- type ReplayStats
- type Screen
- func (s *Screen) Apply(b []byte)
- func (s *Screen) ApplyCuts(b []byte, cuts []SizeCut)
- func (s *Screen) Cursor() (row, col int)
- func (s *Screen) Grid() string
- func (s *Screen) HistoryRows() int
- func (s *Screen) ResizeRows(rows int)
- func (s *Screen) Text() string
- func (s *Screen) TextWithCursor() string
- type SizeCut
Constants ¶
const ( MarkHoldBytes = 4096 MarkHoldTime = 2 * time.Second )
Bounds on a held mark. A runner that stops mid-sequence, or sends a string that never ends, must not keep the divider from drawing for good, so a mark is forced out once this many bytes have passed it or this long has gone by, whichever is first. A real sequence is far shorter than either.
const ( FrameIdle = "idle_prompt" FrameNoBox = "no_input_box" FrameOpenBox = "box_not_closed" FrameHint = "interrupt_hint" FrameSpinner = "spinner_line" )
Why a frame was judged as it was, for the log line. Told apart so a wrong badge can be traced to the classifier and not to hook ordering.
const ( PasteOpen = "\x1b[200~" PasteClose = "\x1b[201~" )
const (
ClearMarkOSC = "\x1b]7777;atrium-clear\x07"
)
clearMark is the OSC payload atrium writes into the output stream at the moment it knows a session is being cleared: a new-context cycle it drives, or a `/clear` the operator typed. See `runner.markClear`.
A clear does not reach the board as erase-display. The pty on Windows is a ConPTY, which repaints the cleared grid in place (`ESC[H`, then the new frame over the old rows, `ESC[K` for the rest) and never says 2J or 3J, so the page that was showing was overwritten without ever going into history. The mark is in the stream, so it is in the ring and in every replay, and a live viewer and a reattach both see it at the same byte. A terminal that does not know the OSC ignores it.
const EscAgainWithin = 2 * time.Second
EscAgainWithin is how soon a second lone Esc has to follow the first to clear a prompt. See noteOperatorTyped.
const FrameTailBytes = 64 << 10
FrameTailBytes is how much of the ring is rendered to find the last screen. Enough to hold several full redraws, so the render starts from a complete one.
const MaxSkipColumns = 1000
MaxSkipColumns caps spaces produced by cursor-forward sequences to limit allocation from malformed or excessively large parameters.
const ScreenMaxRows = 400
ScreenMaxRows bounds that growth. A runner addressing row 10,000 is a corrupt parameter, not a very tall window, and a grid that believed it would allocate a hundred megabytes of blank cells.
const ScreenRows = 24
ScreenRows is the starting height when the stream provides none. The ring records columns but not rows, so grow the grid as larger rows are addressed. Start small: scrolling a row into history early preserves it, while an oversized grid can let later repaints overwrite older content.
Variables ¶
var ReplayModes = []string{"raw", "flat", "screen"}
ReplayModes are the renderings, in the order they interpret the stream least to most.
Functions ¶
func BracketedPaste ¶
BracketedPaste wraps text in bracketed paste markers, and is the only place that does.
Text that holds the closing marker ends its own paste, and whatever follows arrives as keystrokes: `ESC[Z` is Shift+Tab, which cycles the permission mode. So both markers are removed from the text first. A lone trailing ESC goes too, since it would join the closer and form a different sequence.
func ClassifyFrame ¶
ClassifyFrame reports whether the screen `tail` (raw pty bytes, composed at cols by rows) ends with Claude Code at an idle prompt, and the reason either way.
func ClassifyScreen ¶
ClassifyScreen judges rendered screen text, colour already removed.
func ClearsOnEsc ¶
ClearsOnEsc is a runner whose prompt a second Esc clears.
func CollapseRedraws ¶
CollapseRedraws keeps the last frame of repeated in-place updates.
ONLY EVER FOR THE FLATTENER, and running it anywhere else destroys output. It has no grid, so it decides what a frame is from `\r` and the erases, and `\r` is not only a redraw: claude-code ends every WRAPPED VISUAL ROW with one. A paragraph three rows wide is one newline-free segment with three boundaries in it, this reads them as three frames, and two rows of the paragraph are thrown away before any renderer sees them.
Measured on one card's ring: twelve findings went in, and what came out of here had zero of their `#:`, `Sev:` and `Location:` lines and eight of their twelve `Issue:` lines. A whole day was spent on renderers that were being handed that.
The flattener needs it, because without a grid a spinner that redrew four hundred times becomes four hundred lines. The screen model does not: a grid resolves a repaint by definition, which is what a grid is for. Same ring through the screen model uncollapsed keeps all twelve.
Run during replay to keep parsing off the write path. Never collapse across a newline, since completed lines belong in history. Detect frames by boundaries, since counters and timers change the text. Require two boundaries so a single prompt overwrite is preserved.
func Flatten ¶
Flatten returns the bytes with everything that could overwrite what came before it removed.
Colour is kept, because a transcript without it is markedly harder to read and SGR cannot move or erase anything. Everything else in the escape vocabulary is dropped rather than interpreted: this is not a terminal emulator and does not need to be one to answer "can this byte destroy the line above it".
func FormatRepairReport ¶
func FormatRepairReport(events []RepairEvent) string
FormatRepairReport is tab separated: one header line, one line per candidate, and a `totals` line.
func FrameHasInterrupt ¶
FrameHasInterrupt is whether any of the last rows of the screen carries the hint a working runner draws.
func FrameInterrupted ¶ added in v0.1.0
FrameInterrupted is whether the screen is an idle prompt under the line Claude Code draws when the operator interrupts a turn. An interrupt fires no Stop hook, so this line is the only sign the turn ended.
func FrameLineEmpty ¶
FrameLineEmpty is a looser read than framePromptEmpty, for a runner whose line is only unsure because of a restart. It asks for the prompt row under a rule and nothing typed on it, and no interrupt hint in the footer rows. Reply text that happens to hold an ellipsis and a bracket, a status line taller than the box classifier allows, and the dim suggestion Claude draws in an empty prompt all leave classifyScreenPrompt unsure, and none of them is a draft.
func FramePromptEmpty ¶
FramePromptEmpty is whether the screen `tail` shows Claude Code at an idle prompt with nothing typed on the input line.
func FramePromptText ¶ added in v0.0.4
FramePromptText is the text on the prompt row of an idle Claude prompt, or "" when the prompt is empty, shows only the dim suggestion, or the screen is not an idle prompt. One row only: a wrapped draft is cut at the first line.
func FrameText ¶
FrameText is the live grid as text, one line per row. The second cell of a wide character holds contCh and is skipped, as writeRow does, so the character appears once.
func RenderHistory ¶
RenderHistory is the entry point: bytes in, transcript out.
func Replay ¶
Replay renders captured terminal bytes the way an attach would.
`cols` and `rows` are the size the bytes were COMPOSED at, not the size something will display them at. A terminal user interface writes hard line breaks and absolute cursor moves for a specific grid, so replaying into a different one is the difference between reading the output and reading its wreckage. The ring records both; a capture taken any other way has to be told.
Zero for either takes the default, which is 80 columns and `screenRows`.
func ReplayCols ¶
ReplayCols selects the last recorded width to match the newest output. Using the attaching browser's width would misplace cursor updates.
func ReplayCut ¶
ReplayCut is Replay for output composed at more than one size. The screen starts at the first cut's size and is resized at each later one. See `applyCuts`. `rows` is the height to start at when the first cut recorded none.
func ReplayMode ¶
ReplayMode is how this daemon has been asked to replay history.
Read on every attach rather than cached, so flipping it takes effect on the next attach instead of on the next restart. An attach is a websocket upgrade and one settings read is nothing beside it.
A STORE THAT CANNOT ANSWER GETS THE DEFAULT. A halted store means the daemon is already reporting a failure, and picking some other rendering on top of that would be a second surprise.
func SplitKeepingEndings ¶
SplitKeepingEndings cuts into lines with each line's ending still attached, so reassembling is a concatenation and no ending is invented or lost.
func StripPasteMarkers ¶
StripPasteMarkers removes both markers until none remain, because removing one can splice its neighbours into a new one (`ESC[20` + marker + `1~`).
Types ¶
type EscParser ¶
type EscParser struct {
// contains filtered or unexported fields
}
EscParser is a small state machine over a runner's output bytes. It does not interpret anything, it only knows whether the stream is between sequences (ground) or in the middle of one, so the clear mark is never written into the middle of a CSI, an OSC or DCS string, or a UTF-8 character. See `runner.markClear`.
func (*EscParser) FeedUntilGround ¶
feedUntilGround consumes b and returns the index just past the first byte after which the parser is in ground state, or -1 if it never is. It stops there, so the caller can put something in at that point.
type RepairEvent ¶
type RepairEvent struct {
// contains filtered or unexported fields
}
RepairEvent is one candidate and how it came out.
func RepairReport ¶
func RepairReport(b []byte, cuts []SizeCut, rows int) []RepairEvent
RepairReport replays `b` through a grid that is watching, and answers what it found. It is `ReplayCut`'s screen arm, minus the rendering, so the bytes and the cuts are the ones an attach would have replayed.
type RepairWatch ¶
type RepairWatch struct {
// contains filtered or unexported fields
}
RepairWatch is the detector's state. One per report, never shared.
type ReplayStats ¶
ReplayStats are the numbers worth knowing about a rendering without reading it. Enough to answer "did that change help" in one line, and never enough to answer "is it right", which needs eyes.
type Screen ¶
type Screen struct {
// contains filtered or unexported fields
}
screen is a grid, a cursor, and the lines that have scrolled off it.
func NewScreenSized ¶
NewScreenSized builds the grid at the size the output was drawn at.
THE HEIGHT IS THE PART THAT WAS BEING GUESSED, and it decides what becomes history rather than how anything wraps. A grid taller than the terminal that wrote these bytes keeps rows the session had already scrolled past, and the next repaint lands on top of them: content that a shorter grid would have filed away is silently overwritten. That is why replaying through a screen preserved LESS of a real session than not replaying through one at all.
Zero means nothing recorded a height, which is every buffer written before the ring carried one. `screenRows` stands in, and `grow` still stretches the grid to any row that gets addressed, so an under-estimate costs nothing and an over-estimate costs history.
func (*Screen) Apply ¶
apply feeds bytes into the screen model. Skip unsupported sequences without changing the grid.
func (*Screen) ApplyCuts ¶
applyCuts is apply with the grid resized at each cut, the way the terminal that produced the bytes was.
HEIGHT TOO, not only width. gwt opens a session in a console of about thirty rows and the board attaches later at sixty. Replayed into a grid at the later height, everything the session drew at thirty rows stayed on the grid instead of scrolling into history, and the repaints addressed at rows twenty-two and twenty-three wrote over it. The operator attached to a fresh session and got one screen of it.
ONE WIDTH FOR THE WHOLE RING IS WHAT DOUBLED THE LINES. After a room restart a resumed session reprints its transcript at the width the card was saved at, and the operator's pane is often a few columns narrower. Laid into a grid at the newest width, every line padded to the full saved width ran past the edge, the padding wrapped onto a row of its own, and the replay showed a blank line under every full-width coloured diff line. Resizing at the mark keeps each run on the grid it was drawn for, and the history it already scrolled keeps the width it had.
A cut that falls inside an escape sequence or a rune is taken at the next boundary, so resizing never splits one.
func (*Screen) Grid ¶
Grid is the visible rows as text, without history and without the cells a wide character covers.
func (*Screen) HistoryRows ¶
HistoryRows is how many rows have scrolled off the top.
func (*Screen) ResizeRows ¶
ResizeRows changes the grid's height the way a terminal does. Shrinking drops blank rows under the cursor first, then scrolls rows off the top into history, so the cursor stays on the grid. Growing adds blank rows at the bottom and never pulls history back, because a row pulled back is a row the next repaint can overwrite.
A height given here is a recorded one, so the grid stops guessing and stops growing past it.
func (*Screen) Text ¶
text renders scrolled history followed by the current screen. Trim grid padding and trailing blank rows. Emit colour only when it changes and reset it at line endings.
func (*Screen) TextWithCursor ¶
textWithCursor is text() plus a trailing move that leaves the terminal's cursor where the SESSION left its own, which is what the replay owes an attaching viewer.
The renderer reconstructs every cell and then the terminal sits its cursor at the end of the last line it was handed. A terminal user interface does not leave its cursor there: it parks it in its input box, some rows up from the bottom-most output and at a column it worked out. Without this, the first character the operator types echoes at the end of the output instead, and the pane reads as corrupt.
The move is RELATIVE, from the resting position at the bottom, because the transcript is appended to whatever scrollback the terminal already holds and there is no absolute row to aim at. That is safe precisely because a live cursor sits within a screenful of the end: it is never up in the history that has already scrolled past, so walking it up from the bottom always reaches it. See `TestReplayRestoresTheCursor`.
Until 8400fa8 this was done for free by the resize every attach performed: the SIGWINCH made the runner repaint, and the repaint carried an absolute cursor move. Once an attach at an unchanged size stopped resizing, the repaint stopped coming, and restoring the cursor became the replay's own job.