debug

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package debug is the --debug mode's recorder: a small append-only log file plus an in-memory ring of the most recent entries, which pkg/gui draws in a floating panel over the output panel.

It exists because once gocui owns the terminal there is nowhere left to print: stderr is unusable and the status bar is one line. When a key does not do what it should — a combination gocui swallowed, a remap that did not take, a Shift-Down turned into a click by the mouse collision of ADR 0003 — this is what there is to look at.

The central rule of the whole package: **a nil *Logger is the "debug mode off" state**, and every method is nil-safe. Call sites therefore write gui.debug.Key(...) unconditionally, the same way pkg/i18n's Catalog.T is nil-safe, which is what makes it possible to sprinkle calls through the input path without wrapping each one in an if.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	At   time.Time
	Kind Kind
	Text string
}

Entry is one recorded line, as the panel consumes it.

type Kind

type Kind int

Kind is what a line is about. The three are deliberately coarse: reading a debug log is scanning for one of them, not filtering a taxonomy.

const (
	// KindKey is a raw or normalized keystroke seen by the output panel's
	// Editor.
	KindKey Kind = iota
	// KindAction is an action that actually fired — a registered keybinding,
	// a mouse gesture, or a branch of the Editor's own switch.
	KindAction
	// KindEvent is everything else worth a timestamp: session lifecycle,
	// agent state transitions, resizes, tab changes.
	KindEvent
)

func (Kind) String

func (k Kind) String() string

String is the tag written to the file. Fixed width so the file stays column-aligned and greppable.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger writes to the file and keeps the last ringSize entries in memory.

mu is not optional: Key and Action come from gocui's own goroutine, but Event is called from the goEvery background tickers (session exits, agent state, sampling), and Recent is read from whichever goroutine is drawing.

func New

func New(path string) (*Logger, error)

New opens (creating it if needed) the log file at path and writes a header line marking the start of this run. The file is appended to, never truncated: comparing two runs is most of the point.

0o600 rather than 0o644 because the log contains every keystroke typed into a shell — including whatever was typed at a password prompt of a program that does not disable echo.

func (*Logger) Action

func (l *Logger) Action(format string, args ...any)

func (*Logger) Close

func (l *Logger) Close() error

Close flushes nothing (writes are unbuffered) and releases the file. Safe on a nil Logger so pkg/app can defer it unconditionally.

func (*Logger) Event

func (l *Logger) Event(format string, args ...any)

func (*Logger) Key

func (l *Logger) Key(format string, args ...any)

Key, Action and Event record one line of their respective kind. All three are no-ops on a nil Logger — see the package comment.

func (*Logger) Path

func (l *Logger) Path() string

Path is where New opened the file, so the caller can tell the user where to look. Empty on a nil Logger.

func (*Logger) Recent

func (l *Logger) Recent(n int) []Entry

Recent returns up to n entries, oldest first, ending with the most recent one — the order a panel that scrolls downwards wants. n <= 0, or a nil Logger, yields nil.

Jump to

Keyboard shortcuts

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