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 snapshot with m. 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 SnapshotCache ¶ added in v0.62.0
type SnapshotCache struct {
// contains filtered or unexported fields
}
SnapshotCache shares one process-table snapshot across refresh cycles that fall within maxAge of each other. On darwin a snapshot copies the whole kernel process table, which is too costly to repeat on every status poll. It is safe for concurrent use.
func NewSnapshotCache ¶ added in v0.62.0
func NewSnapshotCache(maxAge time.Duration) *SnapshotCache
NewSnapshotCache returns a cache whose snapshots are reused for maxAge.
func (*SnapshotCache) Reader ¶ added in v0.62.0
func (c *SnapshotCache) Reader(base ProcessReader) *SnapshotReader
Reader returns a SnapshotReader over base that takes its children map from the cache on first use.
type SnapshotReader ¶
type SnapshotReader struct {
// contains filtered or unexported fields
}
SnapshotReader wraps a ProcessReader and answers Children from a single ppid → child PID map read on first use. All Children calls during a refresh cycle share that snapshot instead of re-querying the OS per pane, and a cycle that never asks for children never reads the process table.
Create one SnapshotReader at the top of each refresh cycle and discard it afterwards. The snapshot 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 that reads the process table on its first Children call. If the read fails (e.g., a 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 snapshot when available, falling back to the base reader if the snapshot could not be built.
func (*SnapshotReader) Comm ¶
func (s *SnapshotReader) Comm(pid int) string