process

package
v0.52.1 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: MIT Imports: 5 Imported by: 0

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.

func (OSReader) Children

func (OSReader) Children(pid int) ([]int, error)

Children returns direct child PIDs of the given pid.

func (OSReader) Cmdline

func (OSReader) Cmdline(pid int) ([]string, error)

Cmdline returns the full argument list for pid.

func (OSReader) Comm

func (OSReader) Comm(pid int) string

Comm returns the short process name for pid.

func (OSReader) Environ

func (OSReader) Environ(pid int) map[string]string

Environ returns the environment map for pid, or nil if unavailable.

func (OSReader) TPGID

func (OSReader) TPGID(pid int) (int, error)

TPGID returns the terminal process group ID for pid.

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) Cmdline

func (s *SnapshotReader) Cmdline(pid int) ([]string, error)

func (*SnapshotReader) Comm

func (s *SnapshotReader) Comm(pid int) string

func (*SnapshotReader) Environ

func (s *SnapshotReader) Environ(pid int) map[string]string

func (*SnapshotReader) TPGID

func (s *SnapshotReader) TPGID(pid int) (int, error)

Jump to

Keyboard shortcuts

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