Documentation
¶
Overview ¶
Package process reads OS-level process information for tmux panes. It performs no classification; callers decide which processes represent agents.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetSnapshotChildren ¶
func SetSnapshotChildren(s *SnapshotReader, m map[int][]int)
SetSnapshotChildren replaces the internal children map. Intended for tests only — allows injecting a known map without triggering a real OS snapshot.
Types ¶
type CandidateProcesses ¶
type CandidateProcesses struct {
Foreground ProcessInfo
Children []ProcessInfo
}
CandidateProcesses is returned by Candidates. It contains the foreground process for a pane plus any children at depths 1 and 2, which are needed to detect wrapper invocations (e.g. node → claude, sh → aider). Classifying which, if any, of these processes is an agent is the caller's responsibility.
func Candidates ¶
func Candidates(panePID int, r ProcessReader) (*CandidateProcesses, error)
Candidates resolves the foreground process for panePID and collects child processes up to depth 2. It performs no classification.
type OSReader ¶
type OSReader struct{}
OSReader reads process info from the real OS.
type ProcessInfo ¶
type ProcessInfo struct {
PID int
Comm string // short binary name (from p_comm / /proc/N/comm)
Argv []string // full argument list (may be nil on macOS hardened runtime)
Env map[string]string // environment (nil if unavailable)
}
ProcessInfo holds raw OS-level data for a single process.
type ProcessReader ¶
type ProcessReader interface {
// TPGID returns the terminal process group ID for pid.
TPGID(pid int) (int, error)
// Comm returns the short process name for pid.
Comm(pid int) string
// Cmdline returns the full argument list for pid.
Cmdline(pid int) ([]string, error)
// Environ returns the environment map for pid, or nil if unavailable.
Environ(pid int) map[string]string
// Children returns direct child PIDs of the given pid.
// Used for depth-2 wrapper detection (e.g., node → claude).
Children(pid int) ([]int, error)
}
ProcessReader abstracts OS-level process introspection. Unit tests inject fakes; production uses OSReader.
type SnapshotReader ¶
type SnapshotReader struct {
// contains filtered or unexported fields
}
SnapshotReader wraps a ProcessReader and pre-loads child process mappings from a single OS call at construction time. All Children calls during a refresh cycle share that snapshot instead of re-querying the OS per pane.
Create one SnapshotReader at the top of each refresh cycle and discard it afterwards. The snapshot is intentionally short-lived: it may be slightly stale (a process could start or exit mid-cycle), but for agent detection this is an acceptable trade-off.
func NewSnapshotReader ¶
func NewSnapshotReader(base ProcessReader) *SnapshotReader
NewSnapshotReader builds a SnapshotReader backed by base. It reads the full process table once via snapshotChildren and stores a ppid→childPID map. If the snapshot fails (e.g., permission error), Children falls back to the base reader so detection still works at the cost of per-pane syscalls.
func (*SnapshotReader) Children ¶
func (s *SnapshotReader) Children(pid int) ([]int, error)
Children returns child PIDs from the in-memory snapshot when available, falling back to the base reader if the snapshot was not built.
func (*SnapshotReader) Comm ¶
func (s *SnapshotReader) Comm(pid int) string