system

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 24 Imported by: 0 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.

README

system

github.com/webong/ext/res/system is how CTX observes the machine it runs on: the operating system, its file systems, its shells and web views, and the processes running on it. It reports what is there without starting anything, and can record it in a graph.

Package What it is
system (the module root) Host, shell, filesystem and web view discovery, process inspection, and the requirements a host has to meet
system/graph A generic, namespaced, directed graph store with transactions, in memory or in a file
system/supervisor Process supervision and recovery

The graph store is domain-neutral: callers own their node and edge vocabulary, and the discovery code in the module root records what it finds through it. CTX and other consumers share this library rather than each implementing their own.

Product-specific provider discovery belongs in the owning adapter under adapters/<name>/. This module supplies the portable collectors and vocabulary only.

The module was called res/graph until it was renamed to say what it is for. The generic store is now res/system/graph, the discovery package that lived in res/graph/system is now the module root, and res/system/supervisor is unchanged. See the migration table in module versioning.

See host discovery and the graph runtime decision record.

Documentation

Overview

Package system projects CTX machine inventory, shell, and browser observations onto the public generic graph API. It owns the ext.system vocabulary; the base graph package remains product-neutral.

Index

Constants

View Source
const Namespace = "ext.system"

Variables

This section is empty.

Functions

func SafeOrigin

func SafeOrigin(raw string) (scheme, host string, ok bool)

SafeOrigin parses a navigation URL and returns only scheme and host.

Types

type AdapterObservation

type AdapterObservation struct {
	Name, Runtime, Selector                          string
	DiscoveryStatus                                  string
	Surfaces, Capabilities, Supports                 []string
	BrowserShare                                     []string
	Trusted, ListSupported, ObserveSupported, Listed bool
	Contexts                                         []ContextObservation
	Resources                                        []ResourceObservation
	Relations                                        []RelationObservation
}

AdapterObservation describes an installed adapter and any contexts it listed. Listed means its discovery operation completed; it does not prove each configured remote endpoint is running or authorize its use.

type AliasObservation

type AliasObservation struct {
	Space, Name, Adapter, Selection string
	Metadata                        map[string]string
}

AliasObservation is a local user declaration that names one adapter context.

type ApplicationInfo

type ApplicationInfo struct {
	Name string `json:"name"`
	Path string `json:"path"`
}

ApplicationInfo identifies an application through OS packaging conventions. It does not assign product capabilities or infer an engine from a name.

type CollectionStatus

type CollectionStatus struct {
	State      string     `json:"state"`
	Detail     string     `json:"detail,omitempty"`
	ObservedAt *time.Time `json:"observed_at,omitempty"`
}

CollectionStatus distinguishes an empty observation from inaccessible data. State is complete, partial, permission-denied, unsupported, exited, or unavailable. Detail is a diagnostic, never process arguments or environment contents.

type ContextCandidate

type ContextCandidate struct {
	Adapter           string            `json:"adapter"`
	Runtime           string            `json:"runtime"`
	Selection         string            `json:"selection"`
	SelectionDigest   string            `json:"selection_digest"`
	SelectionRedacted bool              `json:"selection_redacted,omitempty"`
	Capabilities      []string          `json:"capabilities"`
	Supports          []string          `json:"supports,omitempty"`
	BrowserShare      map[string]string `json:"browser_share,omitempty"`
	ObservedAt        time.Time         `json:"observed_at"`
}

ContextCandidate is a graph observation, not authorization to run an adapter. Callers must still check trust and validate the native selection.

type ContextObservation

type ContextObservation struct {
	Selection    string            `json:"selection"`
	Capabilities []string          `json:"capabilities,omitempty"`
	Supports     []string          `json:"supports,omitempty"`
	BrowserShare map[string]string `json:"browser_share,omitempty"`
	Attributes   map[string]any    `json:"attributes,omitempty"`
}

ContextObservation is a native adapter selection with optional narrower capabilities and resource support, plus ordinary non-secret metadata.

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.

type FilesystemRequirement

type FilesystemRequirement struct {
	Select                string   `json:"select,omitempty"` // Mount point.
	Path                  string   `json:"path,omitempty"`   // Existing file/directory or a future output path.
	Types                 []string `json:"types,omitempty"`
	Writable              bool     `json:"writable,omitempty"`
	MinimumAvailableBytes uint64   `json:"minimum_available_bytes,omitempty"`
}

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 Graph

type Graph struct{ Store graph.Store }

func New

func New(store graph.Store) (*Graph, error)

New registers the CTX system vocabulary on any graph.Store. Other services may keep their own namespaces in the same store.

func Open

func Open(configHome string) (*Graph, error)

func (*Graph) Close

func (g *Graph) Close() error

func (*Graph) ObserveHost

func (g *Graph) ObserveHost(ctx context.Context, inventory HostInventory) error

ObserveHost reconciles host-owned records and their machine relationships. Adapter inventory, shell sessions, and other namespaces are preserved.

func (*Graph) ObserveInventory

func (g *Graph) ObserveInventory(ctx context.Context, adapters []AdapterObservation, aliases []AliasObservation) error

ObserveInventory replaces CTX's adapter inventory projection while leaving shell and web observations intact. It records only ordinary metadata and redacts context names that resemble paths, URLs, or opaque values.

func (*Graph) ObserveProcesses

func (g *Graph) ObserveProcesses(ctx context.Context, observation ProcessSnapshot) error

ObserveProcesses projects generic OS evidence. Complete enumeration removes missing process instances. Partial inventories retain unseen instances. A targeted observation only replaces that PID and its inspected resource kinds. Resource nodes retain their own timestamps across later identity-only scans.

func (*Graph) ObserveShell

func (g *Graph) ObserveShell(ctx context.Context, cwd, profile string, selections map[string]string) error

ObserveShell records the current shell session and its active directory. It never reads arbitrary environment values or shell history.

func (*Graph) ObserveWeb

func (g *Graph) ObserveWeb(ctx context.Context, provider, profile, scheme, host string) error

ObserveWeb records the current web origin after ctx open succeeds. URL paths, queries, fragments, and credentials are intentionally not persisted.

func (*Graph) PrepareHost

func (g *Graph) PrepareHost(ctx context.Context, requirements OperationRequirements, validateWebview WebviewValidator) (PreparedHost, error)

PrepareHost discovers current candidates, selects one for each requirement, and performs live checks. Ambiguous choices require an explicit selection. Webview preparation requires a validator from the consuming backend.

func (*Graph) ReadHost

func (g *Graph) ReadHost(ctx context.Context) (HostSnapshot, error)

ReadHost reads host observations without refreshing or probing the OS.

func (*Graph) ResolveHost

func (g *Graph) ResolveHost(ctx context.Context, requirements OperationRequirements) (HostCandidates, error)

ResolveHost refreshes stale requested categories and returns matching candidates. Webview candidates are installation evidence, not usable backends.

func (*Graph) ResolveInventory

func (g *Graph) ResolveInventory(ctx context.Context, runtimeName string) (Inventory, error)

ResolveInventory reads the CTX projection from the public graph. A blank runtime returns every context. Redacted selections remain in the graph for inspection but cannot be used as executable candidates.

func (*Graph) ScanHost

func (g *Graph) ScanHost(ctx context.Context) (HostInventory, error)

ScanHost refreshes all host inventories in the graph and returns the facts.

func (*Graph) ScanProcesses

func (g *Graph) ScanProcesses(ctx context.Context, options ProcessOptions) (ProcessSnapshot, error)

ScanProcesses discovers and reconciles the caller-visible process inventory.

type HostCandidates

type HostCandidates struct {
	Operation   string               `json:"operation"`
	Shells      []ShellInfo          `json:"shells,omitempty"`
	Filesystems []FilesystemInfo     `json:"filesystems,omitempty"`
	Webviews    []WebviewInfo        `json:"webviews,omitempty"`
	ObservedAt  map[string]time.Time `json:"observed_at"`
}

type HostInventory

type HostInventory struct {
	Shells      []ShellInfo      `json:"shells"`
	Filesystems []FilesystemInfo `json:"filesystems"`
	Webviews    []WebviewInfo    `json:"webviews"`
	// contains filtered or unexported fields
}

HostInventory is discovered directly by the graph library, independently of adapters. Nil slices in ObserveHost preserve the corresponding inventory; non-nil empty slices remove previously observed entries of that kind.

func DiscoverHost

func DiscoverHost(ctx context.Context) (HostInventory, error)

DiscoverHost returns local host inventory without opening a graph store.

type HostRequirementError

type HostRequirementError struct {
	Operation string
	Kind      string
	Reason    string
	Cause     error
}

HostRequirementError identifies a failed operation requirement. Cause, when present, preserves OS, context, and backend errors for errors.Is/errors.As.

func (*HostRequirementError) Error

func (err *HostRequirementError) Error() string

func (*HostRequirementError) Unwrap

func (err *HostRequirementError) Unwrap() error

type HostSnapshot

type HostSnapshot struct {
	HostInventory
	ObservedAt map[string]time.Time `json:"observed_at"`
	// contains filtered or unexported fields
}

HostSnapshot is the typed graph view with separate freshness per category.

type Inventory

type Inventory struct {
	ObservedAt time.Time          `json:"observed_at"`
	Contexts   []ContextCandidate `json:"contexts"`
}

Inventory is the latest reconciled adapter view. ObservedAt is refreshed on every scan, even when the set of contexts is unchanged.

func (Inventory) Find

func (inventory Inventory) Find(adapter, selection string, capabilities ...string) (ContextCandidate, error)

Find returns a currently observed context with the requested capabilities.

func (Inventory) FreshWithin

func (inventory Inventory) FreshWithin(maxAge time.Duration) bool

type OperationRequirements

type OperationRequirements struct {
	Operation  string                 `json:"operation"`
	Shell      *ShellRequirement      `json:"shell,omitempty"`
	Filesystem *FilesystemRequirement `json:"filesystem,omitempty"`
	Webview    *WebviewRequirement    `json:"webview,omitempty"`
	MaxAge     time.Duration          `json:"-"`
}

OperationRequirements describes host resources needed by a caller. Non-nil requirements are conjunctive. Select pins a resource: failure never causes a different resource to be substituted. MaxAge defaults to five seconds; a negative value forces discovery. No adapter or backend is chosen by name.

type PreparedHost

type PreparedHost struct {
	Operation   string          `json:"operation"`
	Shell       *ShellInfo      `json:"shell,omitempty"`
	Filesystem  *FilesystemInfo `json:"filesystem,omitempty"`
	Webview     *WebviewInfo    `json:"webview,omitempty"`
	ValidatedAt time.Time       `json:"validated_at"`
}

PreparedHost contains one validated resource per requirement. This does not authorize execution, reserve capacity, or eliminate races with OS changes.

type ProcessInfo

type ProcessInfo struct {
	PID         int                         `json:"pid"`
	ParentPID   int                         `json:"parent_pid"`
	Name        string                      `json:"name"`
	StartID     string                      `json:"start_id,omitempty"`
	Executable  string                      `json:"executable,omitempty"`
	Owner       string                      `json:"owner,omitempty"`
	Application *ApplicationInfo            `json:"application,omitempty"`
	Usage       *ProcessUsage               `json:"usage,omitempty"`
	Coverage    map[string]CollectionStatus `json:"coverage"`
	Resources   []ProcessResource           `json:"resources,omitempty"`
	// contains filtered or unexported fields
}

ProcessInfo identifies a process instance using PID and an OS start identity. StartID is opaque and platform-specific. Empty StartID means identity could not be established; such entries are returned but never projected as stable nodes.

type ProcessOptions

type ProcessOptions struct {
	MaxProcesses int
	MaxResources int
	Timeout      time.Duration
}

ProcessOptions bounds returned records and collection time. Zero values select 4096 processes, 1024 resources per category, and a ten-second deadline. Detailed resource inspection is opt-in through InspectProcess.

type ProcessResource

type ProcessResource struct {
	Kind          string `json:"kind"`
	Path          string `json:"path,omitempty"`
	Descriptor    string `json:"descriptor,omitempty"`
	Protocol      string `json:"protocol,omitempty"`
	LocalAddress  string `json:"local_address,omitempty"`
	RemoteAddress string `json:"remote_address,omitempty"`
	Endpoint      string `json:"endpoint,omitempty"`
	State         string `json:"state,omitempty"`
}

ProcessResource is OS evidence. A socket does not imply an automation API. Endpoint preserves an OS-rendered address when its roles cannot be established. Descriptors are process-local observations, not reusable handles.

type ProcessSnapshot

type ProcessSnapshot struct {
	HostID      string           `json:"host_id"`
	Scope       string           `json:"scope"`
	ObservedAt  time.Time        `json:"observed_at"`
	Enumeration CollectionStatus `json:"enumeration"`
	Processes   []ProcessInfo    `json:"processes"`
}

ProcessSnapshot is a non-atomic, point-in-time OS observation. Scope is all or process; only complete all-process enumeration permits removing absent PIDs. HostID includes the boot/namespace identity so records cannot cross reboots.

func DiscoverProcesses

func DiscoverProcesses(ctx context.Context, options ProcessOptions) (ProcessSnapshot, error)

DiscoverProcesses collects identities without scanning every process's files. Processes hidden by the OS are outside this caller-visible inventory.

func InspectProcess

func InspectProcess(ctx context.Context, pid int, options ProcessOptions) (ProcessSnapshot, error)

InspectProcess inspects one process and checks its identity again afterwards. Resources collected during exit or PID reuse are discarded, never reassigned.

type ProcessUsage

type ProcessUsage struct {
	ResidentBytes *uint64  `json:"resident_bytes,omitempty"`
	VirtualBytes  *uint64  `json:"virtual_bytes,omitempty"`
	CPUSeconds    *float64 `json:"cpu_seconds,omitempty"`
	Threads       *uint32  `json:"threads,omitempty"`
}

type RelationObservation

type RelationObservation struct{ From, To, Kind string }

RelationObservation connects two resources reported by the same adapter.

type ResourceObservation

type ResourceObservation struct {
	ID, Kind, Context string
	Attributes        map[string]any
}

ResourceObservation identifies a resource in one observed context. ID is adapter-local; the graph stores a digest rather than the raw identifier.

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.

type ShellRequirement

type ShellRequirement struct {
	Name       string  `json:"name,omitempty"`
	Select     string  `json:"select,omitempty"` // Executable name or path.
	SearchPath *string `json:"-"`                // Optional effective PATH, without changing the process environment.
}

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 CTX adapters.

type WebviewRequirement

type WebviewRequirement struct {
	Select       string `json:"select,omitempty"` // Discovery location.
	Engine       string `json:"engine,omitempty"`
	API          string `json:"api,omitempty"`
	ABIVersion   string `json:"abi_version,omitempty"`
	Version      string `json:"version,omitempty"` // Exact runtime version, when known.
	Architecture string `json:"architecture,omitempty"`
}

type WebviewValidator

type WebviewValidator func(context.Context, WebviewInfo) error

WebviewValidator belongs to the embedding backend. It must establish that this backend can use the selected runtime, including its ABI and dependencies.

Directories

Path Synopsis
Package graph provides a generic, namespaced, directed graph store.
Package graph provides a generic, namespaced, directed graph store.
service
Package supervisor runs generic local component processes and projects their observed lifecycle into a graph.
Package supervisor runs generic local component processes and projects their observed lifecycle into a graph.

Jump to

Keyboard shortcuts

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