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
- func SafeOrigin(raw string) (scheme, host string, ok bool)
- func Schema() store.Schema
- type AdapterObservation
- type AliasObservation
- type ContextCandidate
- type ContextObservation
- type ContextProgram
- type FilesystemRequirement
- type Graph
- func (g *Graph) Close() error
- func (g *Graph) ObserveHost(ctx context.Context, inventory HostInventory) error
- func (g *Graph) ObserveInventory(ctx context.Context, adapters []AdapterObservation, aliases []AliasObservation, ...) error
- func (g *Graph) ObserveProcesses(ctx context.Context, observation proc.ProcessSnapshot) error
- func (g *Graph) ObserveShell(ctx context.Context, cwd, profile string, selections map[string]string) error
- func (g *Graph) ObserveWeb(ctx context.Context, provider, profile, scheme, host string) error
- func (g *Graph) PrepareHost(ctx context.Context, requirements OperationRequirements, ...) (PreparedHost, error)
- func (g *Graph) ReadHost(ctx context.Context) (HostSnapshot, error)
- func (g *Graph) ResolveHost(ctx context.Context, requirements OperationRequirements) (HostCandidates, error)
- func (g *Graph) ResolveInventory(ctx context.Context, runtimeName string) (Inventory, error)
- func (g *Graph) ScanHost(ctx context.Context) (HostInventory, error)
- func (g *Graph) ScanProcesses(ctx context.Context, options proc.ProcessOptions) (proc.ProcessSnapshot, error)
- type HostCandidates
- type HostInventory
- type HostRequirementError
- type HostSnapshot
- type InstallerObservation
- type Inventory
- type OperationRequirements
- type PreparedHost
- type RelationObservation
- type ResourceObservation
- type ShellRequirement
- type WebviewRequirement
- type WebviewValidator
Constants ¶
const Namespace = "ext.system"
const SchemaVersion = "1"
SchemaVersion changes whenever the kinds or relationships of Schema change.
Variables ¶
This section is empty.
Functions ¶
func SafeOrigin ¶ added in v0.2.0
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
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
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"`
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"`
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
func New ¶ added in v0.2.0
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
Open opens the ext.system graph in configHome/graph.db, the SQLite store.
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
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
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
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
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.
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
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 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 the vocabulary to the consumer, which declares it as a schema.
|
This consumer-owned example uses consumer-shaped names to demonstrate that CTX accepts arbitrary namespaces and leaves the vocabulary to the consumer, which declares it as a schema. |
|
Package store provides a generic, namespaced, directed graph store.
|
Package store provides a generic, namespaced, directed graph store. |
|
sqlite
Package sqlite is the durable store.Store: the res/graph store contract over one SQLite database, in pure Go (modernc.org/sqlite, no cgo).
|
Package sqlite is the durable store.Store: the res/graph store contract over one SQLite database, in pure Go (modernc.org/sqlite, no cgo). |
|
storetest
Package storetest runs the shared store fixtures in res/graph/testdata/store/v1 against a store.Store implementation.
|
Package storetest runs the shared store fixtures in res/graph/testdata/store/v1 against a store.Store implementation. |
|
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. |