sessionprocess

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sessionprocess tracks session-owned OS processes independently of agent lifetime.

Index

Constants

View Source
const CaptureTimeout = 2 * time.Second

CaptureTimeout bounds best-effort ownership capture before keeping descendants.

Variables

This section is empty.

Functions

This section is empty.

Types

type Identity

type Identity struct {
	PID       int
	StartedAt time.Time
}

type Observation

type Observation struct {
	Identity
	Owner           Owner
	PGID            int
	FirstSeen       time.Time
	GroupObservedAt time.Time
	Attribution     string
	KernelToken     string
}

Observation deliberately has no session foreign key: deleting a session keeps its processes discoverable.

type Owner

type Owner struct {
	SessionID, WorkspaceID, ProfileID, Name string
	LeaderPID                               int
	LeaderStartedAt                         time.Time
	LeaderKernelToken                       string
	Live, ToolBusy, Starting                bool
}

type Process

type Process struct {
	procutil.ScannedProcess
	Owner                         Owner
	Attribution, Kind, TerminalID string
}

type Result

type Result struct {
	Identity
	Outcome, Error string
}

type Service

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

func New

func New(
	ctx context.Context,
	source Source,
	persistence Store,
	logger *slog.Logger,
	stopBudget time.Duration,
) (*Service, error)

func (*Service) Acquire

func (s *Service) Acquire() func()

func (*Service) AfterStop

func (s *Service) AfterStop(sessionID string, await func(context.Context) error)

AfterStop owns and joins cleanup after an accepted stop outlives its caller.

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context) (Snapshot, error)

func (*Service) Shutdown

func (s *Service) Shutdown()

func (*Service) Summary

func (s *Service) Summary(sessionID string) Summary

func (*Service) Terminate

func (s *Service) Terminate(
	ctx context.Context,
	sessionID string,
	targets []Identity,
	all bool,
	allowed func(Owner) bool,
) ([]Result, error)

Terminate resolves targets only inside the caller's authorized ownership set. An empty session ID is reserved for the operator aggregate boundary.

type Snapshot

type Snapshot struct {
	Supported bool
	ScannedAt time.Time
	Duration  time.Duration
	Processes []Process
}

type Source

type Source interface {
	Owners(context.Context) ([]Owner, error)
	Owner(context.Context, string) (Owner, bool, error)
	OrphanOwner(context.Context, procutil.ScannedProcess) (Owner, bool, error)
	Terminals(context.Context) ([]Terminal, error)
	CloseTerminal(context.Context, Process) error
	ProcessesChanged(context.Context, string)
	RecordTermination(context.Context, Process, Result) error
}

type Store

type Store interface {
	LoadProcessObservations(context.Context) ([]Observation, error)
	SaveProcessObservations(context.Context, []Observation, []Identity) error
}

type Summary

type Summary struct {
	Supported             bool
	Background, Terminals int
	Ports                 []int
}

type Terminal

type Terminal struct {
	PID       int
	StartedAt time.Time
	ID        string
	Owner     Owner
}

Jump to

Keyboard shortcuts

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