adapter

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 32 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.

Documentation

Overview

Package adapter is the host side of the adapter system: manifests, the installed-adapter store, package lifecycle, trust checks and executable invocation. Any ext product can use it; a product supplies only the store home and the wording of its trust hint. The adapter process protocol that executables implement lives in pkg/ext-go (the root package).

Index

Constants

View Source
const (
	// ManifestFileName is the manifest at the top of an adapter directory.
	ManifestFileName = "plugin.json"

	// MetadataKey names the metadata object that carries what ctx interprets.
	MetadataKey = "ctx.adapter/v1"

	// BrowserShareContract and BrowserManagementContract carry the browser
	// operations an adapter declares; BrowserContractVersion is their version.
	BrowserShareContract      = "ext.adapter.browser.share"
	BrowserManagementContract = "ext.adapter.browser.management"
	BrowserContractVersion    = "1"

	// ArgvRuntime is the entrypoint runtime of an adapter: the host invokes the
	// executable once per operation with arguments and streams, not as a
	// long-lived JSON-line session.
	ArgvRuntime = "argv"
)

An adapter is an ext package. Its manifest is plugin.json, the same ext.package/v1 document every package has, and nothing else: this file turns that document into the fields hosts use (Manifest) and back.

  • The adapter name is the package identity id.
  • The capabilities are the operations of the ext.adapter contract, at the adapter API version; browser share and management operations are the operations of two more contracts.
  • The launchers are artifacts and entrypoints: "main" runs the executable under the "argv" runtime, "main.windows" is the native Windows one.
  • Runtime assets are further artifacts (a file, or a tree for a directory).
  • Everything ctx itself interprets is one metadata object, MetadataKey. Its schema belongs to ctx; ext never reads it (see docs/adapter-api.md).
View Source
const APIVersion = "2.0"
View Source
const Protocol = "ext.adapter/" + APIVersion

Protocol is the entrypoint protocol of an adapter: its argv and stream binding at the adapter API version.

Variables

This section is empty.

Functions

func BuildGoPackage

func BuildGoPackage(options GoBuildOptions) (string, error)

BuildGoPackage compiles a local Go adapter and creates a platform archive. Only the sealed plugin.json, the resulting executable, and the artifacts it lists are shipped.

func ConfigHome

func ConfigHome() string

ConfigHome is the root of ext's per-user state, shared by every product so that ctx and ctn see the same installed adapters and the same trust decisions. EXT_HOME overrides it.

func FileSHA256

func FileSHA256(path string) (string, error)

FileSHA256 returns the checksum users can pin when publishing an adapter index.

func Home

func Home() string

Home is the directory holding installed adapters and their trust records. It is global to the user: trusting an adapter once makes it available to every product. EXT_ADAPTER_HOME overrides it, then EXT_HOME.

func IsKnownRuntime

func IsKnownRuntime(runtime string) bool

IsKnownRuntime reports whether this library defines the runtime.

func PackageDirectory

func PackageDirectory(directory, output, goos, goarch string) error

PackageDirectory writes a platform-specific adapter archive from a ready-to-run directory: a source directory with a plugin.json template and the files it lists, or an already sealed package. The archive holds the sealed plugin.json and exactly the artifacts it lists, so unlisted files in the directory are not shipped. A template is sealed for the target: the launcher that does not apply is dropped and the platform is recorded on the one that does.

func Seal

func Seal(directory string, target Target) (packagekit.Manifest, error)

Seal turns the template in directory into a sealed manifest and writes it as plugin.json. The artifacts the template declares must exist; every other regular file in the directory is added as an artifact too, in path order, so the sealed manifest lists exactly the files the directory holds and a first-party adapter keeps shipping the helper binaries built beside its launcher. Seal computes each digest (a declared directory is a tree artifact), stamps the platform on the launchers when target is set, and sets the revision to the digest of the first launcher. For a target it first drops the launcher of the other kind (see pruneToTarget); the dropped launcher's file is not listed.

func TemplateFromKeyValues

func TemplateFromKeyValues(text string) (packagekit.Manifest, error)

TemplateFromKeyValues converts the compact key = "value" notation of earlier ext versions into a package template. It exists for tooling and for tests that write adapters; the loader reads plugin.json only.

func ValidateDependency

func ValidateDependency(dependency Dependency, target *Adapter) error

ValidateDependency checks the declared API and capability of a runtime dependency. Trust is checked separately against the installed package.

func WriteIndex

func WriteIndex(output string, packages []string) error

WriteIndex records platform archives and their digests for one adapter. Archives must sit beside the index so its references work locally and over HTTPS.

func WriteKeyValueManifest

func WriteKeyValueManifest(directory, text string) error

WriteKeyValueManifest writes the plugin.json template of an adapter given in the compact key = "value" notation to directory.

func WriteManifest

func WriteManifest(directory string, pm packagekit.Manifest) error

WriteManifest writes pm as the plugin.json of directory.

Types

type Adapter

type Adapter struct {
	Directory string
	Manifest  Manifest
	// Package is the ext.package/v1 document the Manifest was derived from: a
	// template in a source directory, sealed in an installed or packaged one.
	Package packagekit.Manifest
}

func LoadDirectory

func LoadDirectory(directory string) (*Adapter, error)

func LoadDirectoryForOS

func LoadDirectoryForOS(directory, goos string) (*Adapter, error)

LoadDirectoryForOS validates a package for a specific target operating system.

func LoadSource

func LoadSource(directory, goos string) (*Adapter, error)

LoadSource validates the plugin.json template of an adapter source directory without requiring its executable to exist yet: a Go adapter is built before it can run. Everything else is checked as LoadDirectoryForOS does.

func (*Adapter) Checksum

func (a *Adapter) Checksum() (string, error)

func (*Adapter) Command

func (a *Adapter) Command(invocation Invocation) (*exec.Cmd, error)

func (*Adapter) CommandContext

func (a *Adapter) CommandContext(ctx context.Context, invocation Invocation) (*exec.Cmd, error)

CommandContext prepares an adapter invocation whose process is cancelled when ctx is done. A nil context retains Command's behavior.

func (*Adapter) ConfigKeys

func (a *Adapter) ConfigKeys() []string

func (*Adapter) Declarative added in v0.2.0

func (a *Adapter) Declarative() bool

Declarative reports whether the adapter is data only: it names directories to look in and has no executable. CTX never runs it.

func (*Adapter) DisplayLabel

func (a *Adapter) DisplayLabel() string

DisplayLabel is presentation metadata, never an authentication identity.

func (*Adapter) ExecutablePath

func (a *Adapter) ExecutablePath() string

func (*Adapter) ExecutablePathForOS

func (a *Adapter) ExecutablePathForOS(goos string) string

func (*Adapter) HasBrowserManagement

func (a *Adapter) HasBrowserManagement(operation string) bool

func (*Adapter) HasBrowserShare

func (a *Adapter) HasBrowserShare(operation string) bool

func (*Adapter) HasCapability

func (a *Adapter) HasCapability(capability string) bool

func (*Adapter) HasCommand

func (a *Adapter) HasCommand(command string) bool

func (*Adapter) HasComputerCapability

func (a *Adapter) HasComputerCapability(capability string) bool

func (*Adapter) HasComputerCommand

func (a *Adapter) HasComputerCommand(command string) bool

func (*Adapter) HasEngine added in v0.2.0

func (a *Adapter) HasEngine(engine string) bool

HasEngine reports whether the manifest declares an engine, such as "evaluator".

func (*Adapter) HasRole added in v0.2.0

func (a *Adapter) HasRole(role string) bool

HasRole reports whether the manifest declares a role, such as "installer".

func (*Adapter) HasSupport added in v0.2.0

func (a *Adapter) HasSupport(kind string) bool

HasSupport reports whether the manifest declares the resource kind in supports, such as "container" or "jvm".

func (*Adapter) IsComputerEndpoint

func (a *Adapter) IsComputerEndpoint() bool

func (*Adapter) IsKnownRuntime

func (a *Adapter) IsKnownRuntime() bool

IsKnownRuntime reports whether the adapter's runtime is one this library defines; products should skip adapters for which it is false.

func (*Adapter) IsRuntime

func (a *Adapter) IsRuntime(runtimeName string) bool

func (*Adapter) IsSelectable

func (a *Adapter) IsSelectable() bool

func (*Adapter) PluginDescriptor

func (a *Adapter) PluginDescriptor() (plugin.Descriptor, error)

PluginDescriptor gives ext adapters the same immutable selection contract used by library consumers. The directory digest covers all adapter assets.

func (*Adapter) SupportsSurface

func (a *Adapter) SupportsSurface(surface string) bool

type Check

type Check struct {
	Name  string
	State TrustState
	// Err is why the adapter could not be loaded: a malformed manifest, an
	// escaping path, a symbolic link, a name that does not match its directory.
	// State is empty when Err is set.
	Err error
}

Check is the verification result for one adapter directory.

func (Check) OK

func (c Check) OK() bool

OK reports whether the adapter loaded and matches its recorded digest.

type Dependency

type Dependency struct {
	Space      string
	Adapter    string
	APIVersion string
}

Dependency binds a share space to a separately installed adapter using an exact adapter API version. The binding is platform-specific in the manifest.

type GoBuildOptions

type GoBuildOptions struct {
	Source string
	Output string
	OS     string
	Arch   string
}

type Invocation

type Invocation struct {
	Operation   string
	Selection   string
	Arguments   []string
	Values      map[string]string
	Profile     string
	Project     string
	Command     string
	RealCommand string
}

type Manifest

type Manifest struct {
	APIVersion        string
	Name              string
	Runtime           string
	Surfaces          []string
	Executable        string
	ExecutableWindows string
	// ProgramRoots are the directory patterns of a declarative installer: it has
	// no executable, and CTX looks for programs in these directories itself. They
	// come from the package file named by the program_roots metadata key, so they
	// are sealed and trusted with the package.
	ProgramRoots         []string
	Description          string
	DisplayName          string
	Capabilities         []string
	Supports             []string
	Engine               []string
	Role                 []string
	SelectorKey          string
	Selectable           bool
	ExtraKeys            []string
	Commands             []string
	ComputerCommands     []string
	ComputerCapabilities []string
	ComputerHookEvents   []string
	ComputerHookDefaults []string
	ComputerHookSettings string
	ComputerHookTemplate string
	ShareSpaces          []string
	Dependencies         map[string]Dependency
	BrowserShare         []string
	BrowserQueryPriority int
	BrowserQueryAuto     bool
	OverrideEnv          []string
	DefaultProvider      bool
	SelfContained        bool
	BrowserManagement    []string
}

type Store

type Store struct {
	Home      string
	TrustFile string
}

func NewStore

func NewStore(home string) *Store

func (*Store) AssertTrusted

func (s *Store) AssertTrusted(a *Adapter) error

func (*Store) Install

func (s *Store) Install(source string) (*Adapter, error)

func (*Store) InstallSource

func (s *Store) InstallSource(source, expectedSHA256 string) (*Adapter, error)

InstallSource installs a local adapter directory, a package archive, or an HTTPS archive. Remote archives require a caller-supplied SHA-256 digest.

func (*Store) IsTrusted

func (s *Store) IsTrusted(a *Adapter) (bool, error)

func (*Store) List

func (s *Store) List() ([]*Adapter, error)

func (*Store) Load

func (s *Store) Load(name string) (*Adapter, error)

func (*Store) Remove

func (s *Store) Remove(name string) error

func (*Store) RemoveTrust

func (s *Store) RemoveTrust(name string) error

func (*Store) Replace

func (s *Store) Replace(source string) (*Adapter, error)

Replace validates and seals an adapter, then delegates the atomic swap to the shared package store. The previous package survives a failed swap.

func (*Store) Trust

func (s *Store) Trust(a *Adapter) error

func (*Store) TrustState

func (s *Store) TrustState(a *Adapter) (TrustState, error)

TrustState compares a's current content with the recorded digest. IsTrusted reports only match or no match; this separates an adapter nobody reviewed from one that was reviewed and has since been modified.

func (*Store) Verify

func (s *Store) Verify(names ...string) ([]Check, error)

Verify checks installed adapters without running any of them: it loads each one with the same validation an install applies, then compares its content with the recorded trust digest. With no names it checks every adapter directory under Home. Unlike List, it reports an adapter that fails to load instead of skipping it, so a damaged install is visible. An unreadable trust file is an error, since no adapter can then be called trusted. Results are sorted by name.

type Target

type Target struct{ OS, Arch string }

Target is the platform a package is built for. A zero Target is portable.

type TrustState

type TrustState string

TrustState is how an installed adapter's content compares with the digest recorded when it was trusted.

const (
	// TrustTrusted means the content matches the recorded digest.
	TrustTrusted TrustState = "trusted"
	// TrustUntrusted means no digest was ever recorded for the adapter.
	TrustUntrusted TrustState = "untrusted"
	// TrustChanged means a digest was recorded and the content no longer matches.
	TrustChanged TrustState = "changed"
)

Directories

Path Synopsis
Package adaptercmd provides the shared ext adapter management command.
Package adaptercmd provides the shared ext adapter management command.

Jump to

Keyboard shortcuts

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