clients

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClientIDClaudeCode = "claude-code"
	ClientIDCursor     = "cursor"
)

ClientID constants for supported AI coding clients

Variables

This section is empty.

Functions

func AllClientIDs added in v0.5.4

func AllClientIDs() []string

AllClientIDs returns all known client IDs

func HasAnyErrors

func HasAnyErrors(results map[string]InstallResponse) bool

HasAnyErrors checks if any client installation failed

func IsValidClientID added in v0.5.4

func IsValidClientID(id string) bool

IsValidClientID checks if the given ID is a known client ID

func Register

func Register(client Client)

Register registers a client in the global registry

Types

type AssetBundle

type AssetBundle struct {
	Asset    *lockfile.Asset
	Metadata *metadata.Metadata
	ZipData  []byte
}

AssetBundle contains asset + metadata + zip data

type AssetResult

type AssetResult struct {
	AssetName string
	Status    ResultStatus
	Message   string
	Error     error
}

AssetResult represents the result of installing/uninstalling one asset

type BaseClient

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

BaseClient provides default implementations for common functionality

func NewBaseClient

func NewBaseClient(id, displayName string, supportedTypes []asset.Type) BaseClient

NewBaseClient creates a new base client with capabilities

func (*BaseClient) DisplayName

func (b *BaseClient) DisplayName() string

func (*BaseClient) ID

func (b *BaseClient) ID() string

func (*BaseClient) SupportsAssetType

func (b *BaseClient) SupportsAssetType(assetType asset.Type) bool

type Client

type Client interface {
	// Identity
	ID() string          // Machine name: "claude-code", "cursor", "cline"
	DisplayName() string // Human name: "Claude Code", "Cursor", "Cline"

	// Detection
	IsInstalled() bool  // Check if this client is installed/configured
	GetVersion() string // Get client version (empty if not available)

	// Capabilities - what asset types this client supports
	SupportsAssetType(assetType asset.Type) bool

	// Installation - client has FULL control over installation mechanism
	// Receives all assets to install at once (batch)
	InstallAssets(ctx context.Context, req InstallRequest) (InstallResponse, error)

	// Uninstallation - remove assets
	UninstallAssets(ctx context.Context, req UninstallRequest) (UninstallResponse, error)

	// Asset operations - for MCP server support
	// ListAssets returns all installed assets for a given scope
	ListAssets(ctx context.Context, scope *InstallScope) ([]InstalledSkill, error)
	// ReadSkill reads the content of a specific skill by name
	ReadSkill(ctx context.Context, name string, scope *InstallScope) (*SkillContent, error)

	// EnsureAssetSupport ensures asset infrastructure is set up for the current context.
	// This is called after installation to ensure rules files, MCP servers, etc. are configured.
	// For Cursor, this creates local .cursor/rules/skills.md with skills from all applicable scopes.
	// Clients that don't need post-install setup can return nil.
	EnsureAssetSupport(ctx context.Context, scope *InstallScope) error

	// InstallBootstrap installs client infrastructure (hooks, MCP servers, etc.).
	// This sets up hooks for auto-update/usage tracking and registers the sx MCP server.
	// Called during installation to ensure all client infrastructure is in place.
	// Clients that don't need bootstrap can return nil.
	InstallBootstrap(ctx context.Context) error

	// UninstallBootstrap removes client infrastructure installed by InstallBootstrap.
	// This removes hooks and unregisters the sx MCP server.
	// Called during full uninstall (--all flag) to clean up system infrastructure.
	// Clients that don't need bootstrap can return nil.
	UninstallBootstrap(ctx context.Context) error

	// ShouldInstall checks if installation should proceed in hook mode.
	// Returns true to proceed, false to skip.
	// Called before any installation work begins.
	// For clients like Cursor that fire hooks on every prompt, this enables
	// tracking conversation IDs to only run install once per conversation.
	ShouldInstall(ctx context.Context) (bool, error)

	// VerifyAssets checks if assets are actually installed (not just tracked).
	// Used by --repair mode to detect discrepancies between tracker and filesystem.
	// Each client implements verification according to its own installation structure.
	VerifyAssets(ctx context.Context, assets []*lockfile.Asset, scope *InstallScope) []VerifyResult

	// ScanInstalledAssets scans for all installed assets of supported types.
	// Used during init to detect existing assets that could be imported into the vault.
	ScanInstalledAssets(ctx context.Context, scope *InstallScope) ([]InstalledAsset, error)

	// GetAssetPath returns the filesystem path to an installed asset.
	// Used during import to pass the asset directory to the add command.
	// Returns an error for asset types that don't have a simple directory structure.
	GetAssetPath(ctx context.Context, name string, assetType asset.Type, scope *InstallScope) (string, error)
}

Client represents an AI coding client that can have assets installed

type InstallOptions

type InstallOptions struct {
	Force   bool // Force reinstall even if already installed
	DryRun  bool // Don't actually install, just validate
	Verbose bool // Verbose output
}

InstallOptions contains optional installation settings

type InstallRequest

type InstallRequest struct {
	Assets  []*AssetBundle // All assets to install (batch)
	Scope   *InstallScope  // Where to install (global/repo/path)
	Options InstallOptions // Additional options
}

InstallRequest contains everything needed for installation

type InstallResponse

type InstallResponse struct {
	Results []AssetResult
}

InstallResponse contains results per asset

type InstallScope

type InstallScope struct {
	Type     ScopeType // Global, Repository, Path
	RepoRoot string    // Repository root (if applicable)
	RepoURL  string    // Repository URL (if applicable)
	Path     string    // Specific path within repo (if applicable)
}

InstallScope defines where assets should be installed

type InstalledAsset added in v0.5.4

type InstalledAsset struct {
	Name        string     // Asset name
	Description string     // Asset description from metadata
	Version     string     // Asset version
	Type        asset.Type // Asset type (skill, command, agent, etc.)
}

InstalledAsset represents any asset that has been installed in a client

type InstalledSkill

type InstalledSkill struct {
	Name        string // Skill name
	Description string // Skill description from metadata
	Version     string // Skill version
}

InstalledSkill represents a skill that has been installed

type Orchestrator

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

Orchestrator coordinates installation across multiple clients

func NewOrchestrator

func NewOrchestrator(registry *Registry) *Orchestrator

NewOrchestrator creates a new installation orchestrator

func (*Orchestrator) InstallToAll

func (o *Orchestrator) InstallToAll(ctx context.Context,
	assets []*AssetBundle,
	scope *InstallScope,
	options InstallOptions) map[string]InstallResponse

InstallToAll installs assets to all detected clients concurrently

func (*Orchestrator) InstallToClients

func (o *Orchestrator) InstallToClients(ctx context.Context,
	assets []*AssetBundle,
	scope *InstallScope,
	options InstallOptions,
	targetClients []Client) map[string]InstallResponse

InstallToClients installs assets to specific clients concurrently

type Registry

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

Registry holds all registered clients

func Global

func Global() *Registry

Global returns the global registry

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new client registry

func (*Registry) DetectInstalled

func (r *Registry) DetectInstalled() []Client

DetectInstalled returns all clients detected as installed

func (*Registry) FilterByAssetType

func (r *Registry) FilterByAssetType(assetType asset.Type) []Client

FilterByAssetType returns clients that support the given asset type

func (*Registry) Get

func (r *Registry) Get(id string) (Client, error)

Get retrieves a client by ID

func (*Registry) GetAll

func (r *Registry) GetAll() []Client

GetAll returns all registered clients

func (*Registry) Register

func (r *Registry) Register(client Client)

Register adds a client to the registry

type ResultStatus

type ResultStatus string
const (
	StatusSuccess ResultStatus = "success"
	StatusFailed  ResultStatus = "failed"
	StatusSkipped ResultStatus = "skipped"
)

type ScopeType

type ScopeType string
const (
	ScopeGlobal     ScopeType = "global"
	ScopeRepository ScopeType = "repo" // Must match lockfile.ScopeRepo
	ScopePath       ScopeType = "path"
)

type SkillContent

type SkillContent struct {
	Name        string // Skill name
	Description string // Skill description from metadata
	Version     string // Skill version from metadata
	Content     string // Contents of SKILL.md (or configured prompt file)
	BaseDir     string // Directory where skill is installed (for resolving @ file references)
}

SkillContent contains the full content of a skill for MCP responses

type UninstallOptions

type UninstallOptions struct {
	Force   bool // Force uninstall even if dependencies exist
	DryRun  bool // Don't actually uninstall
	Verbose bool // Verbose output
}

type UninstallRequest

type UninstallRequest struct {
	Assets  []asset.Asset
	Scope   *InstallScope
	Options UninstallOptions
}

UninstallRequest contains assets to uninstall

type UninstallResponse

type UninstallResponse struct {
	Results []AssetResult
}

UninstallResponse contains results per asset

type VerifyResult

type VerifyResult struct {
	Asset     *lockfile.Asset // The asset that was verified
	Installed bool            // Whether the asset is actually installed correctly
	Message   string          // Details about what was found or missing
}

VerifyResult represents the result of verifying a single asset's installation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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