Documentation
¶
Overview ¶
Package platform provides platform detection and registration for AI coding assistant configuration management.
This package detects and manages configurations for supported AI coding assistants: Claude Code, OpenCode, Codex, and Gemini CLI. It provides detection capabilities to determine which platforms are installed on the current system, and a registry for tracking registered platform names.
Platform Registry ¶
The Registry tracks which platform names are registered. Create a new registry and register platform names:
registry := platform.NewRegistry()
// Register platform names
if err := registry.Register("claude"); err != nil {
log.Fatal(err)
}
// Check if a platform is registered
if registry.Get("claude") {
fmt.Println("Claude is registered")
}
// List all registered platform names
for _, name := range registry.All() {
fmt.Printf("Registered: %s\n", name)
}
// List only installed platforms
for _, name := range registry.Available() {
fmt.Printf("Installed: %s\n", name)
}
The registry is safe for concurrent use and returns platform names in deterministic (alphabetical) order.
Platform Detection ¶
Use DetectPlatform to check if a specific platform is installed:
result := platform.DetectPlatform(paths.PlatformClaude)
if result != nil && result.Status == platform.StatusInstalled {
fmt.Printf("Claude is installed at %s\n", result.GlobalConfig)
}
Use DetectAll to discover all platforms regardless of installation status:
for _, result := range platform.DetectAll() {
fmt.Printf("%s: %s\n", result.Name, result.Status)
}
Use DetectInstalled to get only platforms that are currently installed:
installed := platform.DetectInstalled()
if len(installed) == 0 {
fmt.Println("No AI coding assistants found")
}
Installation Status ¶
The InstallStatus type indicates the installation state of a platform:
- StatusInstalled: Platform config directory exists
- StatusNotInstalled: Platform config directory does not exist
- StatusPartial: Reserved for future use (e.g., config exists but binary missing)
Detection Results ¶
DetectionResult contains information about a detected platform:
- Name: Platform identifier (claude, opencode, codex, gemini)
- GlobalConfig: Path to global configuration directory
- MCPConfig: Path to MCP configuration file
- Status: Current installation status
Sentinel Errors ¶
The registry operations return specific sentinel errors:
- ErrPlatformAlreadyRegistered: Platform name already in use
- ErrInvalidPlatformName: Platform name not recognized
Thread Safety ¶
All functions and types in this package are safe for concurrent use. The Registry uses sync.RWMutex for thread-safe operations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPlatformAlreadyRegistered is returned when attempting to register // a platform with a name that is already in use. ErrPlatformAlreadyRegistered = errors.New("platform already registered") // ErrInvalidPlatformName is returned when attempting to register // a platform with an invalid name. ErrInvalidPlatformName = errors.New("invalid platform name") )
Sentinel errors for registry operations.
Functions ¶
This section is empty.
Types ¶
type DetectionResult ¶
type DetectionResult struct {
// Name is the platform identifier (claude, opencode, codex, gemini).
Name string
// GlobalConfig is the path to the global configuration directory.
// This path may be empty if the home directory cannot be determined.
GlobalConfig string
// MCPConfig is the path to the MCP configuration file.
// This path may be empty if the home directory cannot be determined.
MCPConfig string
// Status indicates the installation state of the platform.
Status InstallStatus
}
DetectionResult contains information about a detected platform.
func DetectAll ¶
func DetectAll() []*DetectionResult
DetectAll returns detection results for all known platforms. Platforms are returned in deterministic order defined in paths.Platforms().
func DetectInstalled ¶
func DetectInstalled() []*DetectionResult
DetectInstalled returns only platforms that are installed (Status == StatusInstalled). Platforms are returned in deterministic order.
func DetectPlatform ¶
func DetectPlatform(name string) *DetectionResult
DetectPlatform checks if a specific platform is installed and returns detection info. Returns nil if the platform name is invalid.
type InstallStatus ¶
type InstallStatus string
InstallStatus indicates the installation state of a platform.
const ( // StatusInstalled indicates the platform's global config directory exists. StatusInstalled InstallStatus = "installed" // StatusNotInstalled indicates the platform's global config directory does not exist. StatusNotInstalled InstallStatus = "not_installed" // StatusPartial indicates a partial installation state. // Reserved for future use (e.g., config exists but binary missing). StatusPartial InstallStatus = "partial" )
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages platform name registration and lookup. It is safe for concurrent use.
func (*Registry) All ¶
All returns all registered platform names in deterministic order defined in paths.Platforms().
func (*Registry) Available ¶
Available returns only registered platforms that are installed. Uses DetectPlatform() to check installation status. Platforms are returned in deterministic order defined in paths.Platforms().
Directories
¶
| Path | Synopsis |
|---|---|
|
Package claude provides data models for Claude Code configuration entities.
|
Package claude provides data models for Claude Code configuration entities. |
|
Package gemini provides Gemini CLI specific configuration and path handling.
|
Package gemini provides Gemini CLI specific configuration and path handling. |
|
Package opencode provides OpenCode specific configuration and path handling.
|
Package opencode provides OpenCode specific configuration and path handling. |