Help us shape the future of Go! Take the 2026 Go Developer Survey

plugin

package
v1.0.0-rc.4 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateSchemaVersion = 3
	VersionLocal       = "local"
)
View Source
const ActivationTransactionSchemaVersion = 3

Variables

This section is empty.

Functions

func RuntimeMCPName

func RuntimeMCPName(pluginName, componentName string) string

func ValidateName

func ValidateName(name string) error

func ValidateVersion

func ValidateVersion(version string) error

Types

type ActivationTransaction

type ActivationTransaction struct {
	SchemaVersion    int       `json:"schema_version"`
	Name             string    `json:"name"`
	OwnerID          string    `json:"owner_id"`
	Kind             string    `json:"kind"`
	Phase            string    `json:"phase"`
	Previous         *State    `json:"previous,omitempty"`
	Candidate        State     `json:"candidate"`
	LocalReplacement bool      `json:"local_replacement,omitempty"`
	CreatedAt        time.Time `json:"created_at"`
}

type ChangeResult

type ChangeResult struct {
	Action        string `json:"action"`
	Name          string `json:"name"`
	Version       string `json:"version,omitempty"`
	PackageDigest string `json:"package_digest,omitempty"`
	Changed       bool   `json:"changed"`
	Enabled       bool   `json:"enabled"`
}

type ComponentIndex

type ComponentIndex struct {
	Skills []SkillComponent `json:"skills,omitempty"`
	MCP    []MCPComponent   `json:"mcp,omitempty"`
}

type Error

type Error struct {
	Code  string
	Stage string
	Err   error
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Installed

type Installed struct {
	State
	Root string `json:"root"`
}

type MCPComponent

type MCPComponent struct {
	Name           string            `json:"name"`
	Description    string            `json:"description"`
	Transport      string            `json:"transport"`
	URL            string            `json:"url,omitempty"`
	Command        string            `json:"command,omitempty"`
	Args           []string          `json:"args,omitempty"`
	CWD            string            `json:"cwd,omitempty"`
	Environment    map[string]string `json:"env,omitempty"`
	Headers        map[string]string `json:"headers,omitempty"`
	HeaderEnv      map[string]string `json:"header_env,omitempty"`
	EnvBindings    map[string]string `json:"env_bindings,omitempty"`
	RequiredEnv    []string          `json:"required_env,omitempty"`
	TimeoutMS      int               `json:"timeout_ms,omitempty"`
	RuntimeName    string            `json:"runtime_name"`
	StorageKey     string            `json:"storage_key"`
	RelativeSource string            `json:"source"`
}

type MCPReview

type MCPReview struct {
	Name             string   `json:"name"`
	Description      string   `json:"description"`
	Transport        string   `json:"transport"`
	URL              string   `json:"url,omitempty"`
	Command          string   `json:"command,omitempty"`
	CWD              string   `json:"cwd,omitempty"`
	EnvironmentNames []string `json:"environment_names,omitempty"`
	HeaderNames      []string `json:"header_names,omitempty"`
	RuntimeName      string   `json:"runtime_name"`
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager(agentDockHome string) (*Manager, error)

func (*Manager) AbortActivation

func (m *Manager) AbortActivation(ctx context.Context, name string) error

AbortActivation 回滚当前 Manager 拥有的 live activation。若当前进程没有 owner,则在取得 writer lease 后恢复持久化的 pending transaction。

func (*Manager) Acquire

func (m *Manager) Acquire(ctx context.Context, name string) (Installed, func(), error)

func (*Manager) AcquireActivationCandidate

func (m *Manager) AcquireActivationCandidate(name string) (Installed, func(), error)

AcquireActivationCandidate 是唯一允许读取 pending candidate 的入口。 普通 Acquire 会被 activation writer lease 阻塞,因此正式 resolver 在 Finalize 前 update 只能看到 Previous,首次 install 则仍表现为未安装。

func (*Manager) CleanupObsoleteVersions

func (m *Manager) CleanupObsoleteVersions(name string)

CleanupObsoleteVersions removes package versions that are no longer selected.

func (*Manager) EnsureDataDir

func (m *Manager) EnsureDataDir(name string) (string, error)

func (*Manager) FinalizeActivation

func (m *Manager) FinalizeActivation(name string) error

FinalizeActivation 在 runtime activation 成功后才发布 candidate。整个过程 仍持有跨进程 writer lease,并对 journal owner 与正式 state 做 CAS 校验; install 要求正式 state 仍不存在,update 则要求它仍等于 Previous。

func (*Manager) Inspect

func (m *Manager) Inspect(name string) (Installed, error)

func (*Manager) InstallReviewedSource

func (m *Manager) InstallReviewedSource(ctx context.Context, source string, enabled bool, reviewToken string) (ChangeResult, error)

InstallReviewedSource stages the source once, verifies that the exact staged candidate matches a prior security review, and commits that same snapshot.

func (*Manager) List

func (m *Manager) List() ([]Installed, error)

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, name, dataPolicy string) (ChangeResult, error)

func (*Manager) RemoveWithLifecycle

func (m *Manager) RemoveWithLifecycle(ctx context.Context, name, dataPolicy string, lifecycle RemoveLifecycle) (ChangeResult, error)

RemoveWithLifecycle 把正式 state、package ownership、Plugin data 和外部 owned state 的清理放在同一个 Plugin writer lease 中。purge 先持久化 tombstone 再进入 不可逆清理,因此失败后只允许向前重试,不会重新暴露为 installed。

func (*Manager) SetEnabled

func (m *Manager) SetEnabled(ctx context.Context, name string, enabled bool) (ChangeResult, error)

func (*Manager) SetEnabledWithLifecycle

func (m *Manager) SetEnabledWithLifecycle(ctx context.Context, name string, enabled bool, reconcile func(State) error) (ChangeResult, error)

SetEnabledWithLifecycle keeps runtime reconciliation and formal state mutation under the same Plugin writer lease. The callback receives the target state; if state persistence fails after runtime switched, it is called again with the previous state before the lease is released.

func (*Manager) Store

func (m *Manager) Store() *Store

func (*Manager) UpdateReviewedSource

func (m *Manager) UpdateReviewedSource(ctx context.Context, source string, reviewToken string, beforeSwitch func(State) error) (ChangeResult, error)

UpdateReviewedSource verifies and commits one staged Portable Plugin snapshot. beforeSwitch runs only after package/version checks pass, so the runtime layer can stop the current owned MCP immediately before the atomic switch.

func (*Manager) Validate

func (m *Manager) Validate(source string) Review

func (*Manager) ValidateSource

func (m *Manager) ValidateSource(_ context.Context, source string) Review

type Manifest

type Manifest struct {
	Name        string      `json:"name"`
	Version     string      `json:"version"`
	Description string      `json:"description,omitempty"`
	Provenance  *Provenance `json:"provenance,omitempty"`
}

type Package

type Package struct {
	Root          string
	Manifest      Manifest
	PackageDigest string
	Components    ComponentIndex
	Warnings      []string
	Executables   []string
	Format        string
}

func LoadPackage

func LoadPackage(root string) (Package, error)

type Provenance

type Provenance struct {
	Origin   string `json:"origin"`
	Ref      string `json:"ref,omitempty"`
	Revision string `json:"revision,omitempty"`
	Subdir   string `json:"subdir,omitempty"`
}

Provenance records where an imported Portable Plugin originally came from. It is part of plugin.json, so it is covered by the package digest and review token.

type PurgeOwnership

type PurgeOwnership struct {
	Name           string   `json:"name"`
	MCPStorageKeys []string `json:"mcp_storage_keys,omitempty"`
}

PurgeOwnership 是 remove keep 后仍需保留的最小清理元数据。 Plugin data 与 Plugin Skill data/env 都可由 Name 确定;只有 MCP storage key 可能因为长名称哈希而无法从 Plugin 名反推,因此需要持久化。

type RemoveLifecycle

type RemoveLifecycle struct {
	BeforeDelete func(State) error
	Restore      func(State) error
	Purge        func(PurgeOwnership) error
}

type Review

type Review struct {
	Valid         bool             `json:"valid"`
	Name          string           `json:"name,omitempty"`
	Version       string           `json:"version,omitempty"`
	Description   string           `json:"description,omitempty"`
	PackageDigest string           `json:"package_digest,omitempty"`
	ReviewToken   string           `json:"review_token,omitempty"`
	Provenance    *Provenance      `json:"provenance,omitempty"`
	Skills        []SkillComponent `json:"skills"`
	MCP           []MCPReview      `json:"mcp"`
	Warnings      []string         `json:"warnings"`
	Executables   []string         `json:"executables"`
	Issues        []string         `json:"issues"`
	Format        string           `json:"format"`
}

type SkillComponent

type SkillComponent struct {
	Name          string `json:"name"`
	Description   string `json:"description"`
	RelativePath  string `json:"path"`
	ContentDigest string `json:"content_digest"`
}

type State

type State struct {
	SchemaVersion  int            `json:"schema_version"`
	Name           string         `json:"name"`
	Version        string         `json:"version"`
	Description    string         `json:"description,omitempty"`
	PackageDigest  string         `json:"package_digest"`
	Provenance     *Provenance    `json:"provenance,omitempty"`
	Enabled        bool           `json:"enabled"`
	InstalledAt    time.Time      `json:"installed_at"`
	Components     ComponentIndex `json:"components"`
	MCPStorageKeys []string       `json:"mcp_storage_keys,omitempty"`
	Format         string         `json:"format"`
	Warnings       []string       `json:"warnings,omitempty"`
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

func NewStore

func NewStore(agentDockHome string) (*Store, error)

func (*Store) AcquireBinding

func (s *Store) AcquireBinding(ctx context.Context, name string) (func(), error)

AcquireBinding protects only the brief state->version binding window. Long-running Plugin work must use AcquireVersionRead after resolving state.

func (*Store) AcquireVersionRead

func (s *Store) AcquireVersionRead(name, version string) (func(), error)

func (*Store) AcquireWrite

func (s *Store) AcquireWrite(ctx context.Context, name string) (func(), error)

func (*Store) CreateRuntimeSnapshot

func (s *Store) CreateRuntimeSnapshot(name, version, packageRoot string) (string, error)

CreateRuntimeSnapshot copies one already-installed Plugin package into a writable runtime generation. The reviewed package itself remains immutable, so runtime-generated files do not invalidate the persisted package digest.

func (*Store) DataPath

func (s *Store) DataPath(name string) (string, error)

func (*Store) Delete

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

func (*Store) DeleteActivationTransaction

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

func (*Store) DeleteRemovalOwnership

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

func (*Store) EnsureDataDir

func (s *Store) EnsureDataDir(name string) (string, error)

func (*Store) EnsurePackageParent

func (s *Store) EnsurePackageParent(name string) (string, error)

func (*Store) Home

func (s *Store) Home() string

func (*Store) List

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

func (*Store) ListActivationTransactions

func (s *Store) ListActivationTransactions() ([]ActivationTransaction, error)

func (*Store) Load

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

func (*Store) LoadActivationTransaction

func (s *Store) LoadActivationTransaction(name string) (ActivationTransaction, error)

func (*Store) LoadRemovalOwnership

func (s *Store) LoadRemovalOwnership(name string) (PurgeOwnership, error)

func (*Store) LoadRemovalRecord

func (s *Store) LoadRemovalRecord(name string) (removalRecord, error)

func (*Store) PackagePath

func (s *Store) PackagePath(name, version string) (string, error)

func (*Store) RemoveData

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

func (*Store) RemoveVersionIfIdle

func (s *Store) RemoveVersionIfIdle(name, version string) (bool, error)

func (*Store) Save

func (s *Store) Save(state State) error

func (*Store) SaveActivationTransaction

func (s *Store) SaveActivationTransaction(transaction ActivationTransaction) error

func (*Store) SaveRemovalOwnership

func (s *Store) SaveRemovalOwnership(ownership PurgeOwnership) error

func (*Store) SaveRemovalRecord

func (s *Store) SaveRemovalRecord(record removalRecord) error

func (*Store) StatePath

func (s *Store) StatePath(name string) (string, error)

func (*Store) TempPath

func (s *Store) TempPath(prefix string) (string, error)

func (*Store) UpdateBackupPath

func (s *Store) UpdateBackupPath(name string) (string, error)

func (*Store) UpdateCandidatePath

func (s *Store) UpdateCandidatePath(name, ownerID string) (string, error)

func (*Store) WaitVersionIdle

func (s *Store) WaitVersionIdle(ctx context.Context, name, version string) error

Jump to

Keyboard shortcuts

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