host

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package host discovers what the local machine provides to programs: shells, mounted filesystems, web view runtimes and host resource capacity (CPU, memory, storage, power and container state). Discovery reads paths and permissions; it never launches what it finds.

The native checks the host-requirements resolver needs (FilesystemAt, ExecutableAccess, DirectoryWritable) are exported here, because they are OS mechanisms; the resolver itself and the graph vocabulary are in res/graph.

Index

Constants

View Source
const (
	// ContainerDetected, ContainerNone, and ContainerUnsupported are the only
	// container states. Unsupported means the platform exposes no safe local
	// signal, not that the process is outside a container.
	ContainerDetected    = "detected"
	ContainerNone        = "none"
	ContainerUnsupported = "unsupported"
)
View Source
const (
	PowerStateCharging    = "charging"
	PowerStateDischarging = "discharging"
	PowerStateCharged     = "charged"
	PowerStateUnknown     = "unknown"
)

PowerState values.

Variables

View Source
var ErrInvalid = errors.New("invalid resource snapshot")

ErrInvalid reports a resource snapshot that breaks the rules of testdata/host/v1.

Functions

func Code added in v0.4.0

func Code(err error) string

Code is the stable error code of err for another language to match: invalid. It is empty for an error this package does not define.

func DirectoryWritable

func DirectoryWritable(path string) error

DirectoryWritable reports whether the calling user may create entries in the directory at path, without creating a probe file.

func Environment

func Environment() string

Environment identifies the host environment the observations were made in. Graph records carry it so a consumer can tell when they came from somewhere else.

func ExecutableAccess

func ExecutableAccess(path string) error

ExecutableAccess reports whether the calling user may execute the file at path. It does not run it.

func IsExecutable

func IsExecutable(path string) bool

IsExecutable reports whether path is a regular file the calling user may execute.

func PathKey

func PathKey(path string) string

PathKey returns the key under which a host path is compared and recorded: the cleaned path, lower-cased on Windows.

func RedactSource

func RedactSource(source string) string

RedactSource removes URL credentials from a filesystem source.

func WebviewIdentity

func WebviewIdentity(item WebviewInfo) string

WebviewIdentity returns the key that identifies a web view across scans: its name, scope and location.

Types

type ContainerInfo

type ContainerInfo struct {
	Detected bool     `json:"detected"`
	State    string   `json:"state"`
	Evidence []string `json:"evidence"`
}

ContainerInfo reports whether this process runs inside a container and which local markers support that conclusion. Evidence is a sorted list of stable names, not file contents or environment values.

type FilesystemInfo

type FilesystemInfo struct {
	MountPoint  string           `json:"mount_point"`
	Source      string           `json:"source"`
	Type        string           `json:"type"`
	ReadOnly    bool             `json:"read_only"`
	Space       *FilesystemSpace `json:"space,omitempty"`
	Label       string           `json:"label,omitempty"`
	DriveKind   string           `json:"drive_kind,omitempty"`
	DetailError string           `json:"detail_error,omitempty"`
}

FilesystemInfo describes a mounted filesystem visible to this process. Space is nil when the OS cannot provide it. This is not a list of unmounted disks or a filesystem-driver catalog. Source never includes URL credentials.

func DiscoverFilesystems

func DiscoverFilesystems(ctx context.Context) ([]FilesystemInfo, error)

DiscoverFilesystems reads the native mount inventory and available space. It observes the caller's mount namespace and permissions, including when CTX itself runs inside a container. It does not traverse filesystem contents.

func FilesystemAt

func FilesystemAt(ctx context.Context, path string) (FilesystemInfo, error)

FilesystemAt describes the mounted filesystem that contains path, in the same terms as DiscoverFilesystems. It reports an error where the platform cannot answer.

type FilesystemSpace

type FilesystemSpace struct {
	TotalBytes     uint64 `json:"total_bytes"`
	FreeBytes      uint64 `json:"free_bytes"`
	AvailableBytes uint64 `json:"available_bytes"`
}

FilesystemSpace is a point-in-time capacity observation, in bytes. Available space is what the calling user can allocate; it can differ from free space. On Windows, total space is also limited by any quota on the calling user.

type PowerInfo

type PowerInfo struct {
	State                string `json:"state"`      // charging, discharging, charged, unknown
	Percentage           int    `json:"percentage"` // 0-100
	TimeRemainingSeconds int64  `json:"time_remaining_seconds,omitempty"`
}

PowerInfo describes battery/power state. All fields are zero when the platform does not expose them.

type ResourceInfo

type ResourceInfo struct {
	OS                  string                `json:"os"`
	Architecture        string                `json:"architecture"`
	ObservedAt          time.Time             `json:"observed_at"`
	LogicalCPUs         int                   `json:"logical_cpus"`
	CPUCapacity         float64               `json:"cpu_capacity"`
	CPUStatus           proc.CollectionStatus `json:"cpu_status"`
	MemoryBytes         uint64                `json:"memory_bytes"`
	MemoryCapacityBytes uint64                `json:"memory_capacity_bytes"`
	MemoryStatus        proc.CollectionStatus `json:"memory_status"`
	Storage             []StorageInfo         `json:"storage,omitempty"`
	Power               *PowerInfo            `json:"power,omitempty"`
	Container           ContainerInfo         `json:"container"`
	Uptime              *time.Duration        `json:"-"` // on the wire: uptime_seconds, a number of seconds
	BootTime            *time.Time            `json:"boot_time,omitempty"`
	UptimeStatus        proc.CollectionStatus `json:"uptime_status"`
}

ResourceInfo is a point-in-time observation of the local machine's computing resources. Container-adjusted values never guess: a field whose native source is unavailable carries a non-complete status instead of the host value.

It is local host state only. Network shape stays in res/system/service/network and is never duplicated here.

func DiscoverResources

func DiscoverResources(ctx context.Context) (ResourceInfo, error)

DiscoverResources observes the local machine's CPU, memory, container state, storage, power/battery, and uptime. It reads local files and system counters only: no command is launched, no network is contacted, and no identity or protocol is attached.

func (ResourceInfo) MarshalJSON added in v0.4.0

func (r ResourceInfo) MarshalJSON() ([]byte, error)

MarshalJSON writes the wire form every binding shares: uptime is uptime_seconds, a number.

func (*ResourceInfo) UnmarshalJSON added in v0.4.0

func (r *ResourceInfo) UnmarshalJSON(data []byte) error

UnmarshalJSON reads the wire form MarshalJSON writes.

func (ResourceInfo) Validate added in v0.4.0

func (r ResourceInfo) Validate() error

Validate checks a snapshot against the rules of testdata/host/v1: the identity and time are set, the CPU and memory figures agree, each status fits the capability rules, storage, power and container are consistent, and uptime and boot time come together.

type ShellInfo

type ShellInfo struct {
	Name              string   `json:"name"`
	Path              string   `json:"path"`
	ResolvedPath      string   `json:"resolved_path"`
	ConfiguredDefault bool     `json:"configured_default"`
	Sources           []string `json:"sources"`
}

ShellInfo describes an executable available to this host user. Discovery checks paths and permissions without launching the executable. The configured default is an environment declaration, not proof of the current process.

func DiscoverShells

func DiscoverShells(ctx context.Context) ([]ShellInfo, error)

DiscoverShells finds registered shells, standard shell executable names on PATH, platform shell locations, and a configured SHELL/ComSpec executable. Registered and configured paths can identify shells with arbitrary names.

func DiscoverShellsOnPath

func DiscoverShellsOnPath(ctx context.Context, searchPath string) ([]ShellInfo, error)

DiscoverShellsOnPath is DiscoverShells with an explicit PATH-style search list in place of the process environment's.

type StorageInfo

type StorageInfo struct {
	Device         string `json:"device"`
	MountPoint     string `json:"mount_point"`
	TotalBytes     uint64 `json:"total_bytes"`
	AvailableBytes uint64 `json:"available_bytes"`
	Type           string `json:"type,omitempty"`
	ReadOnly       bool   `json:"read_only,omitempty"`
}

StorageInfo describes one mounted storage volume visible to the process.

type WebviewInfo

type WebviewInfo struct {
	Name         string `json:"name"`
	Engine       string `json:"engine"`
	API          string `json:"api"`
	Version      string `json:"version,omitempty"`
	ABIVersion   string `json:"abi_version,omitempty"`
	Architecture string `json:"architecture,omitempty"`
	Location     string `json:"location"`
	ResolvedPath string `json:"resolved_path,omitempty"`
	Scope        string `json:"scope"`
	Source       string `json:"source"`
	DetailError  string `json:"detail_error,omitempty"`
}

WebviewInfo describes evidence of a shared web rendering runtime. Discovery does not load the runtime or establish that a particular app can use it. Location is a framework/library path or a Windows registry location. Version is the runtime version; ABIVersion is a library API/ABI generation, not the underlying WebKit or Chromium version.

func DiscoverWebviews

func DiscoverWebviews(ctx context.Context) ([]WebviewInfo, error)

DiscoverWebviews inventories host webview runtimes without launching a browser, reading app profiles, or depending on installed ext adapters.

Jump to

Keyboard shortcuts

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