discovery

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetParentPID = getParentPIDImpl

GetParentPID returns the parent PID for a given process, or 0 on error. Exported for use by the correlator. Variable so tests can override it.

Functions

func FindSessionFile

func FindSessionFile(sessionID, projectsDir string) string

FindSessionFile searches for a session JSONL file matching the given session ID within the projects directory.

func FindSessionFileDefault

func FindSessionFileDefault(sessionID string) string

FindSessionFileDefault searches for a session file using the default ~/.claude/projects/ directory.

func GetProcessCwd

func GetProcessCwd(pid int) (string, error)

GetProcessCwd returns the current working directory of a process. Uses `lsof -a -d cwd -p PID -Fn` which only queries the cwd file descriptor instead of listing all open files. Times out after 3 seconds to avoid blocking the discovery loop when lsof hangs on a process.

func MatchTmuxSession

func MatchTmuxSession(sessions []TmuxSession, workingDir string) string

MatchTmuxSession finds a tmux session matching the "claude-<project>" naming convention based on the working directory's base name.

func PsLines added in v0.8.1

func PsLines(psOutput string) []string

PsLines returns the trimmed non-empty lines from ps aux output (skipping header). Providers use this to avoid re-splitting the shared snapshot.

func ScanProcesses

func ScanProcesses() ([]agent.Agent, error)

ScanProcesses runs `ps aux`, parses each line, and returns Instance stubs for every detected Claude process. Subagent processes (whose parent PID is also a Claude process) are automatically filtered out so that only top-level sessions appear.

func ScanProcessesFromOutput added in v0.8.1

func ScanProcessesFromOutput(psOutput string) []agent.Agent

ScanProcessesFromOutput parses pre-captured `ps aux` output for Claude processes.

func SessionFilesForDir

func SessionFilesForDir(workingDir string) []string

SessionFilesForDir finds all JSONL session files associated with a working directory. Claude converts directory paths by replacing "/" with "-" to form the project directory key.

Types

type AgentProvider

type AgentProvider interface {
	Name() string
	Discover() ([]agent.Agent, error)
}

AgentProvider is the minimal interface that the orchestrator requires from each provider. It is intentionally kept small to avoid a circular dependency between the discovery and provider packages. Any type implementing provider.Provider automatically satisfies this interface.

type Orchestrator

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

Orchestrator coordinates multiple providers to produce a unified list of agents.

func NewOrchestrator

func NewOrchestrator(providers ...AgentProvider) *Orchestrator

NewOrchestrator creates an orchestrator that iterates the given providers.

func (*Orchestrator) Discover

func (o *Orchestrator) Discover() ([]agent.Agent, error)

Discover queries every registered provider and merges the results. A single process snapshot is taken first and shared with providers that implement SnapshotProvider, avoiding redundant ps/tmux calls.

func (*Orchestrator) ProviderFor

func (o *Orchestrator) ProviderFor(name string) AgentProvider

ProviderFor returns the first provider whose Name() matches the given name, or nil if no provider matches.

type SessionInfo

type SessionInfo struct {
	SessionID        string
	GitBranch        string
	Model            string
	TokensIn         int64
	TokensOut        int64
	CacheReadTokens  int64
	CacheWriteTokens int64
	MessageCount     int
	LastTimestamp    time.Time
	LastAction       string // most recent tool call, e.g. "Ed main.go"
}

SessionInfo holds aggregated data parsed from a Claude JSONL session file.

func ParseSessionFile

func ParseSessionFile(path string) (SessionInfo, error)

ParseSessionFile reads a JSONL session file and aggregates token usage across all messages.

type Snapshot added in v0.8.1

type Snapshot struct {
	PsOutput     string        // raw `ps aux` output
	TmuxSessions []TmuxSession // parsed tmux sessions
}

Snapshot holds shared data collected once and reused by all providers.

func TakeSnapshot added in v0.8.1

func TakeSnapshot() *Snapshot

TakeSnapshot captures a process snapshot (ps aux + tmux) once.

type SnapshotProvider added in v0.8.1

type SnapshotProvider interface {
	DiscoverWithSnapshot(snap *Snapshot) ([]agent.Agent, error)
}

SnapshotProvider is an optional interface for providers that can accept a shared process snapshot. This avoids each provider calling `ps aux` and `tmux list-sessions` independently (~200ms each).

type TmuxSession

type TmuxSession struct {
	Name     string
	Attached bool
}

TmuxSession represents a tmux session with its name and attachment state.

func ListTmuxSessions

func ListTmuxSessions() []TmuxSession

ListTmuxSessions runs `tmux list-sessions` and returns the parsed results. Returns nil if tmux is not running or not installed.

type Watcher added in v0.9.0

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

Watcher monitors session directories for new files and triggers a callback. Events are debounced to avoid excessive re-discovery on rapid file creation.

func NewWatcher added in v0.9.0

func NewWatcher(dirs []string, onChange func()) (*Watcher, error)

NewWatcher creates a watcher on the given directories. Directories that don't exist are silently skipped. The onChange callback is debounced to fire at most once per 500ms.

func (*Watcher) Stop added in v0.9.0

func (w *Watcher) Stop()

Stop shuts down the watcher.

Jump to

Keyboard shortcuts

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