live

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package live provides adapters for detecting and interacting with LIVE Claude sessions running in the user's terminal (not started by cdev).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SupportedTerminals

func SupportedTerminals() []string

SupportedTerminals returns the list of supported terminals for the current platform.

Types

type Detector

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

Detector finds and tracks running Claude processes not managed by cdev.

func NewDetector

func NewDetector(workspacePath string) *Detector

NewDetector creates a new live session detector for a specific workspace.

func (*Detector) DetectAll

func (d *Detector) DetectAll() ([]*LiveSession, error)

DetectAll finds all LIVE Claude processes.

func (*Detector) GetLiveSession

func (d *Detector) GetLiveSession(sessionID string) *LiveSession

GetLiveSession returns a LIVE session for the workspace.

If sessionID resolves to an on-disk Claude session file, we keep that ID. If it does not resolve (e.g. stale/foreign session id from remote client), we still return a detected LIVE Claude process in the workspace as best effort. This preserves inbound prompt delivery to an already-running terminal session.

func (*Detector) RegisterManagedPID

func (d *Detector) RegisterManagedPID(pid int)

RegisterManagedPID marks a PID as managed by cdev (will be excluded from detection).

func (*Detector) UnregisterManagedPID

func (d *Detector) UnregisterManagedPID(pid int)

UnregisterManagedPID removes a PID from the managed list.

type Injector

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

Injector sends input to a terminal for LIVE sessions. Supports multiple platforms with different injection methods.

func NewInjector

func NewInjector() *Injector

NewInjector creates a new injector for the current platform.

func (*Injector) Send

func (i *Injector) Send(tty string, text string) error

Send sends text as keystrokes to the terminal application.

func (*Injector) SendKey

func (i *Injector) SendKey(tty string, key string) error

SendKey sends a special key to the terminal application.

func (*Injector) SendKeyToApp

func (i *Injector) SendKeyToApp(key string, terminalApp string) error

SendKeyToApp sends a special key to a specific terminal application.

func (*Injector) SendToApp

func (i *Injector) SendToApp(text string, terminalApp string) error

SendToApp sends text as keystrokes to a specific terminal application.

func (*Injector) SendWithEnter

func (i *Injector) SendWithEnter(tty string, text string) error

SendWithEnter sends text followed by Enter key.

func (*Injector) SendWithEnterToApp

func (i *Injector) SendWithEnterToApp(text string, terminalApp string) error

SendWithEnterToApp sends text followed by Enter key to a specific app.

type LiveSession

type LiveSession struct {
	PID         int       `json:"pid"`
	TTY         string    `json:"tty"`          // e.g., "/dev/ttys002"
	WorkDir     string    `json:"work_dir"`     // Working directory of the process
	SessionID   string    `json:"session_id"`   // Claude session ID from JSONL file
	TerminalApp string    `json:"terminal_app"` // The terminal app (Terminal, iTerm2, Code, Cursor, etc.)
	StartTime   time.Time `json:"start_time"`
}

LiveSession represents a detected Claude process running in user's terminal.

type MacOSPlatform

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

MacOSPlatform implements injection for macOS using AppleScript.

func (*MacOSPlatform) DetectTerminalApp

func (p *MacOSPlatform) DetectTerminalApp(tty string) string

DetectTerminalApp tries to detect which terminal app is running Claude.

func (*MacOSPlatform) Name

func (p *MacOSPlatform) Name() string

func (*MacOSPlatform) SendKey

func (p *MacOSPlatform) SendKey(key string) error

func (*MacOSPlatform) SendKeyCode

func (p *MacOSPlatform) SendKeyCode(keyCode int) error

func (*MacOSPlatform) SendKeyCodeToApp

func (p *MacOSPlatform) SendKeyCodeToApp(keyCode int, tty string) error

func (*MacOSPlatform) SendKeyToApp

func (p *MacOSPlatform) SendKeyToApp(key string, tty string) error

func (*MacOSPlatform) SendText

func (p *MacOSPlatform) SendText(text string) error

func (*MacOSPlatform) SendTextToApp

func (p *MacOSPlatform) SendTextToApp(text string, tty string) error

func (*MacOSPlatform) SetTargetApp

func (p *MacOSPlatform) SetTargetApp(app string)

SetTargetApp sets which application to send keystrokes to.

type Platform

type Platform interface {
	SendText(text string) error
	SendKey(key string) error
	SendKeyCode(keyCode int) error
	Name() string
}

Platform defines the interface for platform-specific injection.

type TerminalReader

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

TerminalReader reads terminal content from native terminal applications. Platform-specific implementations: - macOS: AppleScript (Terminal.app, iTerm2) - Windows: UI Automation / PowerShell (Windows Terminal, cmd, PowerShell)

func NewTerminalReader

func NewTerminalReader(terminalApp string) *TerminalReader

NewTerminalReader creates a reader for a specific terminal application.

func (*TerminalReader) GetContent

func (r *TerminalReader) GetContent() (string, error)

GetContent reads the current content from the terminal window. This is implemented per-platform in terminal_reader_darwin.go and terminal_reader_windows.go

func (*TerminalReader) GetLastNLines

func (r *TerminalReader) GetLastNLines(n int) (string, error)

GetLastNLines returns the last N lines from the terminal.

func (*TerminalReader) GetVisibleContent

func (r *TerminalReader) GetVisibleContent() (string, error)

GetVisibleContent returns approximately the visible portion of the terminal. Default implementation returns last 50 lines.

func (*TerminalReader) IsRunning

func (r *TerminalReader) IsRunning() bool

IsRunning returns whether the reader is currently polling.

func (*TerminalReader) Output

func (r *TerminalReader) Output() <-chan string

Output returns the channel that receives new terminal content.

func (*TerminalReader) SetPollInterval

func (r *TerminalReader) SetPollInterval(interval time.Duration)

SetPollInterval sets how often to poll for terminal content changes.

func (*TerminalReader) Start

func (r *TerminalReader) Start() error

Start begins polling the terminal for content changes.

func (*TerminalReader) Stop

func (r *TerminalReader) Stop()

Stop stops polling the terminal.

type UnsupportedPlatform

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

UnsupportedPlatform is used for platforms without injection support.

func (*UnsupportedPlatform) Name

func (p *UnsupportedPlatform) Name() string

func (*UnsupportedPlatform) SendKey

func (p *UnsupportedPlatform) SendKey(key string) error

func (*UnsupportedPlatform) SendKeyCode

func (p *UnsupportedPlatform) SendKeyCode(keyCode int) error

func (*UnsupportedPlatform) SendText

func (p *UnsupportedPlatform) SendText(text string) error

type WindowsPlatform

type WindowsPlatform struct{}

WindowsPlatform implements injection for Windows using PowerShell SendKeys.

func (*WindowsPlatform) Name

func (p *WindowsPlatform) Name() string

func (*WindowsPlatform) SendKey

func (p *WindowsPlatform) SendKey(key string) error

func (*WindowsPlatform) SendKeyCode

func (p *WindowsPlatform) SendKeyCode(keyCode int) error

func (*WindowsPlatform) SendText

func (p *WindowsPlatform) SendText(text string) error

Jump to

Keyboard shortcuts

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