Documentation
¶
Overview ¶
Package focus brings a coding-agent session forward: the window it runs in, and where it can tell, its tab, its tmux pane or its Claude desktop conversation.
A session's hooks record where they ran (Capture, sent as a hook event's hookevents.Terminal). Focuser takes that record and, in order:
- opens a Claude desktop session on its own conversation, through the app's claude:// link;
- selects a tmux session's pane on the client most recently used for it, and goes on with the terminal that client runs in;
- selects the terminal's tab: kitty through its remote control, iTerm2 and Terminal through AppleScript, by the tab's terminal device;
- raises the window: hyprctl on Hyprland, xdotool or wmctrl on X11, the the application's own process, else its bundle, on macOS.
It supports Linux and macOS. Other Wayland compositors than Hyprland have no way for one program to raise another's window, so Predict offers nothing there.
Index ¶
Constants ¶
const ( // Session is the session's own pane, tab or conversation. Session = "session" // Window is the window or application it runs in. Window = "window" )
Precisions of a focus.
Variables ¶
This section is empty.
Functions ¶
func Ancestors ¶
func Ancestors() []hookevents.Process
Ancestors are the running hook's ancestors, its parent first: what ties a Git hook to the agent session whose command ran it.
func Capture ¶
func Capture() *hookevents.Terminal
Capture describes where the running hook was started: the variables of hookevents.TerminalEnv it has, its ancestors, its parent first, and the controlling terminal of the nearest ancestor that has one. Agents start hooks in a session of their own, so the hook itself has none. It returns nil where none of that can be read.
Types ¶
type Focuser ¶
type Focuser struct {
Run Runner
GOOS string
// Getenv reads the daemon's environment.
Getenv func(string) string
// Process reads a running process: itself, its parent's id and whether
// it runs.
Process func(pid int) (hookevents.Process, int, bool)
// Executable is a running process's executable file.
Executable func(pid int) string
// LookPath finds a command.
LookPath func(name string) (string, error)
// ClaudeDir is Claude desktop's configuration directory; empty is its
// default for the platform.
ClaudeDir string
// ConfigureCodexTitle prepares Codex's terminal title for session focus.
ConfigureCodexTitle func() (bool, error)
}
Focuser brings sessions forward. The zero value works on the system it runs on; the fields are seams for tests.
func (*Focuser) Predict ¶
func (f *Focuser) Predict(agent string, t *hookevents.Terminal) string
Predict is how precisely Focus could bring the session forward, judged from its record without running anything: Session, Window, or empty when it could not at all. The application names its action after it.