graph

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 20 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

graph

github.com/webong/ext/res/graph records what is observed about a machine, its adapters and its shell sessions in a graph, and supervises local processes while projecting their state into it.

Package What it is
graph (the module root) The recorder. It projects observations onto the ext.system vocabulary and reads them back: Graph, Open and New; ObserveShell and ObserveWeb; ScanHost and ObserveHost; ScanProcesses and ObserveProcesses; ObserveInventory and ResolveInventory for adapters, contexts, installers and programs; and ReadHost, ResolveHost and PrepareHost for host requirements
store A generic, namespaced, directed graph store with transactions, in memory or in a file. It is domain-neutral: callers own their node and edge vocabulary, and several services can keep their own namespaces in one store
supervisor Generic local component processes with recovery for unexpected exits, projecting their state into a store.Store

A state seen through supervisor.Instance is already in the graph: the supervisor applies each lifecycle fact before it releases the instance. See the supervisor.

The recorder takes its observations from the collectors in res/system (Scan* calls a collector and then records the result; Observe* records a result the caller already holds). res/graph requires res/system; res/system never requires res/graph. The store and the supervisor use the standard library only.

The recorder currently describes the local machine, under the vertex machine/local. It does not authorize use of an adapter or prove that a remote context is running; callers still check trust and validate native selections.

CTX and other consumers share this library rather than each implementing their own. The graph namespace and the vertex and edge identifiers are persisted in graph files and do not change between versions.

The path res/graph was used for an earlier form of the module that is now res/system (v0.1.x, deprecated); this module reuses the path from v0.2.0. See the migration table in module versioning, the graph runtime decision record and host discovery.

Documentation

Overview

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

Index

Constants

View Source
const Namespace = "ext.system"

Variables

This section is empty.

Functions

func SafeOrigin added in v0.2.0

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

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

Types

type AdapterObservation added in v0.2.0

type AdapterObservation struct {
	Name, Runtime, Selector                          string
	DiscoveryStatus                                  string
	Surfaces, Capabilities, Supports                 []string
	Engine, Role                                     []string
	BrowserShare                                     []string
	Trusted, ListSupported, ObserveSupported, Listed bool
	Contexts                                         []ContextObservation
	// Programs are the executables CTX found for the commands this adapter
	// declares. They are machine facts: the graph holds one vertex per file, however
	// many adapters were given it.
	Programs  []program.Candidate
	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 added in v0.2.0

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

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

type ContextCandidate added in v0.2.0

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"`
	Engine            []string          `json:"engine,omitempty"`
	Role              []string          `json:"role,omitempty"`
	BrowserShare      map[string]string `json:"browser_share,omitempty"`
	Program           *ContextProgram   `json:"program,omitempty"`
	// Default marks the adapter the user prefers for the kind a resolve asked for.
	// It filters nothing; a caller that wants one adapter asks for a pick.
	Default    bool      `json:"default,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 added in v0.2.0

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 ContextProgram added in v0.2.0

type ContextProgram struct {
	Path       string   `json:"path"`
	RealPath   string   `json:"realpath"`
	Version    string   `json:"version,omitempty"`
	OnPath     bool     `json:"on_path,omitempty"`
	Installers []string `json:"installers,omitempty"`
	// Suggested names installers the adapter that runs the file guessed from its
	// location. It is not a fact; see "installers".
	Suggested []string `json:"suggested_installers,omitempty"`
}

ContextProgram is the executable a context runs, as observed. Installers names the installer adapters that reported the file; it is empty when the file was found on PATH alone. The file may have been replaced since the scan.

type FilesystemRequirement added in v0.2.0

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 Graph added in v0.2.0

type Graph struct{ Store store.Store }

func New added in v0.2.0

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

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

func Open added in v0.2.0

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

func (*Graph) Close added in v0.2.0

func (g *Graph) Close() error

func (*Graph) ObserveHost added in v0.2.0

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 added in v0.2.0

func (g *Graph) ObserveInventory(ctx context.Context, adapters []AdapterObservation, aliases []AliasObservation, installers ...InstallerObservation) 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 added in v0.2.0

func (g *Graph) ObserveProcesses(ctx context.Context, observation proc.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 added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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

ReadHost reads host observations without refreshing or probing the OS.

func (*Graph) ResolveHost added in v0.2.0

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 added in v0.2.0

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 added in v0.2.0

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

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

func (*Graph) ScanProcesses added in v0.2.0

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

ScanProcesses discovers and reconciles the caller-visible process inventory.

type HostCandidates added in v0.2.0

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

type HostInventory added in v0.2.0

type HostInventory struct {
	Shells        []host.ShellInfo               `json:"shells"`
	Filesystems   []host.FilesystemInfo          `json:"filesystems"`
	Webviews      []host.WebviewInfo             `json:"webviews"`
	Desktop       *surface.DesktopInfo           `json:"desktop,omitempty"`
	Surfaces      *surface.SurfaceSnapshot       `json:"surfaces,omitempty"`
	Accessibility *surface.AccessibilitySnapshot `json:"accessibility,omitempty"`
	Permissions   *surface.PermissionSnapshot    `json:"permissions,omitempty"`
	Resources     *host.ResourceInfo             `json:"resources,omitempty"`
	// contains filtered or unexported fields
}

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

func DiscoverHost added in v0.2.0

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

DiscoverHost returns local host inventory without opening a graph store.

type HostRequirementError added in v0.2.0

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 added in v0.2.0

func (err *HostRequirementError) Error() string

func (*HostRequirementError) Unwrap added in v0.2.0

func (err *HostRequirementError) Unwrap() error

type HostSnapshot added in v0.2.0

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 InstallerObservation added in v0.2.0

type InstallerObservation struct {
	Name, Source string
}

InstallerObservation declares an installer that is not an adapter, such as one the user described in their own configuration. Installers that are adapters (role "installer") need no entry here.

type Inventory added in v0.2.0

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 added in v0.2.0

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

Find returns a currently observed context with the requested capabilities.

func (Inventory) FreshWithin added in v0.2.0

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

type OperationRequirements added in v0.2.0

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 added in v0.2.0

type PreparedHost struct {
	Operation   string               `json:"operation"`
	Shell       *host.ShellInfo      `json:"shell,omitempty"`
	Filesystem  *host.FilesystemInfo `json:"filesystem,omitempty"`
	Webview     *host.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 RelationObservation added in v0.2.0

type RelationObservation struct{ From, To, Kind string }

RelationObservation connects two resources reported by the same adapter.

type ResourceObservation added in v0.2.0

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 ShellRequirement added in v0.2.0

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 WebviewRequirement added in v0.2.0

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 added in v0.2.0

type WebviewValidator func(context.Context, host.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
examples
consumer-shaped command
This consumer-owned example uses consumer-shaped names to demonstrate that CTX accepts arbitrary namespaces and leaves semantic validation to the consumer.
This consumer-owned example uses consumer-shaped names to demonstrate that CTX accepts arbitrary namespaces and leaves semantic validation to the consumer.
Package store provides a generic, namespaced, directed graph store.
Package store provides a generic, namespaced, directed graph store.
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