discovery

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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 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 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. Individual provider errors are silently skipped so that one failing provider does not prevent the others from returning agents.

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 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.

Jump to

Keyboard shortcuts

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