focus

package
v0.1.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 16 Imported by: 0

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:

  1. opens a Claude desktop session on its own conversation, through the app's claude:// link;
  2. selects a tmux session's pane on the client most recently used for it, and goes on with the terminal that client runs in;
  3. selects the terminal's tab: kitty through its remote control, iTerm2 and Terminal through AppleScript, by the tab's terminal device;
  4. 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

View Source
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) Focus

func (f *Focuser) Focus(ctx context.Context, agent, id string, t *hookevents.Terminal) Result

Focus brings the session agent/id, whose hooks recorded t, forward.

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.

type Result

type Result struct {
	// Precision is Session or Window, or empty when nothing was brought
	// forward.
	Precision string
	// Message says what could not be done and how to make it possible, empty
	// when everything was.
	Message string
}

Result is what a focus did.

type Runner

type Runner func(ctx context.Context, env []string, name string, args ...string) ([]byte, error)

Runner runs a command with env added to the daemon's environment and returns its standard output.

Jump to

Keyboard shortcuts

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