Documentation
¶
Overview ¶
Package install provides installation automation for dashlights. It handles shell prompt integration and AI agent hook installation.
Index ¶
- Constants
- func GetPathExportTemplate(shell ShellType) string
- func GetShellTemplate(templateType TemplateType) string
- type AgentConfig
- type AgentInstaller
- func (i *AgentInstaller) CheckCursorConflict(config *AgentConfig) (string, bool, error)
- func (i *AgentInstaller) GetAgentConfig(agentType AgentType) (*AgentConfig, error)
- func (i *AgentInstaller) Install(config *AgentConfig, dryRun bool, nonInteractive bool) (*InstallResult, error)
- func (i *AgentInstaller) IsInstalled(config *AgentConfig) (bool, error)
- type AgentType
- type BackupManager
- type BackupResult
- type BinaryConfig
- type BinaryInstallState
- type BinaryInstaller
- func (b *BinaryInstaller) AddPathExport(shellConfig *ShellConfig, dryRun bool) (*InstallResult, error)
- func (b *BinaryInstaller) CheckBinaryState(config *BinaryConfig) (BinaryInstallState, error)
- func (b *BinaryInstaller) CheckPathExportState(shellConfigPath string) (InstallState, error)
- func (b *BinaryInstaller) CompareVersions(sourcePath, targetPath string) (bool, error)
- func (b *BinaryInstaller) EnsureBinaryInstalled(shellConfig *ShellConfig, dryRun bool) (*InstallResult, error)
- func (b *BinaryInstaller) FindInstallDir() (string, bool, error)
- func (b *BinaryInstaller) GetBinaryConfig(shellConfig *ShellConfig) (*BinaryConfig, error)
- func (b *BinaryInstaller) InstallBinary(config *BinaryConfig, dryRun bool) (*InstallResult, error)
- type ExitCode
- type Filesystem
- type InstallOptions
- type InstallResult
- type InstallState
- type Installer
- type MockFilesystem
- func (f *MockFilesystem) Chmod(path string, mode os.FileMode) error
- func (f *MockFilesystem) CopyFile(src, dst string) error
- func (f *MockFilesystem) Executable() (string, error)
- func (f *MockFilesystem) Exists(path string) bool
- func (f *MockFilesystem) Getenv(key string) string
- func (f *MockFilesystem) IsWritable(path string) bool
- func (f *MockFilesystem) Lstat(path string) (os.FileInfo, error)
- func (f *MockFilesystem) MkdirAll(path string, perm os.FileMode) error
- func (f *MockFilesystem) ReadFile(path string) ([]byte, error)
- func (f *MockFilesystem) Rename(src, dst string) error
- func (f *MockFilesystem) SplitPath() []string
- func (f *MockFilesystem) Stat(path string) (os.FileInfo, error)
- func (f *MockFilesystem) UserHomeDir() (string, error)
- func (f *MockFilesystem) WriteFile(path string, data []byte, perm os.FileMode) error
- type OSFilesystem
- func (f *OSFilesystem) Chmod(path string, mode os.FileMode) error
- func (f *OSFilesystem) CopyFile(src, dst string) error
- func (f *OSFilesystem) Executable() (string, error)
- func (f *OSFilesystem) Exists(path string) bool
- func (f *OSFilesystem) Getenv(key string) string
- func (f *OSFilesystem) IsWritable(path string) bool
- func (f *OSFilesystem) Lstat(path string) (os.FileInfo, error)
- func (f *OSFilesystem) MkdirAll(path string, perm os.FileMode) error
- func (f *OSFilesystem) ReadFile(path string) ([]byte, error)
- func (f *OSFilesystem) Rename(src, dst string) error
- func (f *OSFilesystem) SplitPath() []string
- func (f *OSFilesystem) Stat(path string) (os.FileInfo, error)
- func (f *OSFilesystem) UserHomeDir() (string, error)
- func (f *OSFilesystem) WriteFile(path string, data []byte, perm os.FileMode) error
- type ShellConfig
- type ShellInstaller
- func (i *ShellInstaller) CheckInstallState(config *ShellConfig) (InstallState, error)
- func (i *ShellInstaller) DetectShell() (ShellType, error)
- func (i *ShellInstaller) GetShellConfig(configPathOverride string) (*ShellConfig, error)
- func (i *ShellInstaller) Install(config *ShellConfig, dryRun bool) (*InstallResult, error)
- type ShellType
- type TemplateType
Constants ¶
const ( PathSentinelBegin = "# BEGIN dashlights-path" PathSentinelEnd = "# END dashlights-path" )
Sentinel markers for PATH export.
const ( SentinelBegin = "# BEGIN dashlights" SentinelEnd = "# END dashlights" )
Sentinel markers for idempotency detection.
const ( // BashTemplate is the prompt integration for bash. BashTemplate = `` /* 215-byte string literal not displayed */ // ZshTemplate is the prompt integration for zsh. ZshTemplate = `` /* 243-byte string literal not displayed */ // FishTemplate is the prompt integration for fish. FishTemplate = `` /* 195-byte string literal not displayed */ // P10kTemplate is the prompt segment function for Powerlevel10k. P10kTemplate = `` /* 203-byte string literal not displayed */ )
Shell prompt templates wrapped with sentinel markers.
const ( // BashPathExport adds ~/.local/bin to PATH in bash. BashPathExport = `# BEGIN dashlights-path # Added by dashlights installer export PATH="$HOME/.local/bin:$PATH" # END dashlights-path ` // ZshPathExport adds ~/.local/bin to PATH in zsh. ZshPathExport = `# BEGIN dashlights-path # Added by dashlights installer export PATH="$HOME/.local/bin:$PATH" # END dashlights-path ` // FishPathExport adds ~/.local/bin to PATH in fish. FishPathExport = `# BEGIN dashlights-path # Added by dashlights installer fish_add_path $HOME/.local/bin # END dashlights-path ` )
PATH export templates for adding ~/.local/bin to PATH.
const ( // ClaudeHookJSON is the hook configuration to add to Claude's settings. // This is not the full file, but the structure to merge in. ClaudeHookJSON = `` /* 230-byte string literal not displayed */ // CursorHookJSON is the hook configuration for Cursor. CursorHookJSON = `{ "beforeShellExecution": { "command": "dashlights --agentic" } }` )
Agent configuration templates.
const DashlightsCommand = "dashlights --agentic"
DashlightsCommand is the command to run for agentic mode.
const DefaultBinDir = ".local/bin"
Default fallback directory for binary installation.
Variables ¶
This section is empty.
Functions ¶
func GetPathExportTemplate ¶ added in v1.1.3
GetPathExportTemplate returns the PATH export template for a shell type.
func GetShellTemplate ¶
func GetShellTemplate(templateType TemplateType) string
GetShellTemplate returns the appropriate template for a template type.
Types ¶
type AgentConfig ¶
type AgentConfig struct {
Type AgentType
ConfigPath string // Full path to config file
Name string // Human-readable, e.g., "Claude Code"
}
AgentConfig contains agent configuration information.
type AgentInstaller ¶
type AgentInstaller struct {
// contains filtered or unexported fields
}
AgentInstaller handles AI agent configuration installation.
func NewAgentInstaller ¶
func NewAgentInstaller(fs Filesystem) *AgentInstaller
NewAgentInstaller creates a new AgentInstaller.
func (*AgentInstaller) CheckCursorConflict ¶
func (i *AgentInstaller) CheckCursorConflict(config *AgentConfig) (string, bool, error)
CheckCursorConflict checks if there's an existing Cursor hook that would be overwritten. Returns (existingCommand, hasConflict).
func (*AgentInstaller) GetAgentConfig ¶
func (i *AgentInstaller) GetAgentConfig(agentType AgentType) (*AgentConfig, error)
GetAgentConfig returns the configuration for an agent type.
func (*AgentInstaller) Install ¶
func (i *AgentInstaller) Install(config *AgentConfig, dryRun bool, nonInteractive bool) (*InstallResult, error)
Install installs the dashlights hook for the specified agent.
func (*AgentInstaller) IsInstalled ¶
func (i *AgentInstaller) IsInstalled(config *AgentConfig) (bool, error)
IsInstalled checks if dashlights is already installed for the agent.
type AgentType ¶
type AgentType string
AgentType represents the type of AI agent.
func ParseAgentType ¶
ParseAgentType parses an agent type string.
type BackupManager ¶
type BackupManager struct {
// contains filtered or unexported fields
}
BackupManager handles backup file operations.
func NewBackupManager ¶
func NewBackupManager(fs Filesystem) *BackupManager
NewBackupManager creates a new BackupManager with the given filesystem.
func (*BackupManager) CreateBackup ¶
func (b *BackupManager) CreateBackup(filePath string) (*BackupResult, error)
CreateBackup creates a backup of the specified file. If a backup already exists, a timestamped backup is created. Returns BackupResult with Created=false if the file doesn't exist.
type BackupResult ¶
BackupResult contains information about a backup operation.
type BinaryConfig ¶ added in v1.1.3
type BinaryConfig struct {
SourcePath string // Path to currently running binary
TargetDir string // Directory to install to
TargetPath string // Full path to target binary
PathNeedsExport bool // Whether ~/.local/bin needs to be added to PATH
ShellConfigPath string // Shell config file to modify for PATH export
Shell ShellType
}
BinaryConfig contains information about binary installation.
type BinaryInstallState ¶ added in v1.1.3
type BinaryInstallState int
BinaryInstallState represents the state of the binary installation.
const ( BinaryNotInstalled BinaryInstallState = iota BinaryInstalled // Same version already installed BinaryOutdated // Different version exists BinaryIsSymlink // Target is a symlink (warn, don't overwrite) )
type BinaryInstaller ¶ added in v1.1.3
type BinaryInstaller struct {
// contains filtered or unexported fields
}
BinaryInstaller handles installation of the dashlights binary to PATH.
func NewBinaryInstaller ¶ added in v1.1.3
func NewBinaryInstaller(fs Filesystem) *BinaryInstaller
NewBinaryInstaller creates a new BinaryInstaller.
func (*BinaryInstaller) AddPathExport ¶ added in v1.1.3
func (b *BinaryInstaller) AddPathExport(shellConfig *ShellConfig, dryRun bool) (*InstallResult, error)
AddPathExport adds ~/.local/bin to PATH in shell config file.
func (*BinaryInstaller) CheckBinaryState ¶ added in v1.1.3
func (b *BinaryInstaller) CheckBinaryState(config *BinaryConfig) (BinaryInstallState, error)
CheckBinaryState checks if the binary is already installed and its state.
func (*BinaryInstaller) CheckPathExportState ¶ added in v1.1.3
func (b *BinaryInstaller) CheckPathExportState(shellConfigPath string) (InstallState, error)
CheckPathExportState checks if PATH export is already configured in shell config.
func (*BinaryInstaller) CompareVersions ¶ added in v1.1.3
func (b *BinaryInstaller) CompareVersions(sourcePath, targetPath string) (bool, error)
CompareVersions compares the running binary against the installed one. Returns true if they are the same (by size and checksum).
func (*BinaryInstaller) EnsureBinaryInstalled ¶ added in v1.1.3
func (b *BinaryInstaller) EnsureBinaryInstalled(shellConfig *ShellConfig, dryRun bool) (*InstallResult, error)
EnsureBinaryInstalled installs the binary and adds PATH export if needed. This is a convenience method for use by prompt and agent installers.
func (*BinaryInstaller) FindInstallDir ¶ added in v1.1.3
func (b *BinaryInstaller) FindInstallDir() (string, bool, error)
FindInstallDir finds the best directory to install the binary to. Priority: 1. If dashlights already exists somewhere in PATH, use that location 2. First user-writable directory in PATH (excluding system dirs and non-preferred homebrew subdirs) 3. Fallback to ~/.local/bin
func (*BinaryInstaller) GetBinaryConfig ¶ added in v1.1.3
func (b *BinaryInstaller) GetBinaryConfig(shellConfig *ShellConfig) (*BinaryConfig, error)
GetBinaryConfig determines the source and target paths for binary installation.
func (*BinaryInstaller) InstallBinary ¶ added in v1.1.3
func (b *BinaryInstaller) InstallBinary(config *BinaryConfig, dryRun bool) (*InstallResult, error)
InstallBinary copies the binary to the target location.
type Filesystem ¶
type Filesystem interface {
ReadFile(path string) ([]byte, error)
WriteFile(path string, data []byte, perm os.FileMode) error
Stat(path string) (os.FileInfo, error)
Lstat(path string) (os.FileInfo, error) // for symlink detection
Exists(path string) bool
MkdirAll(path string, perm os.FileMode) error
Rename(src, dst string) error
UserHomeDir() (string, error)
Getenv(key string) string
Executable() (string, error) // returns path of running binary
CopyFile(src, dst string) error // copy file preserving permissions
Chmod(path string, mode os.FileMode) error
SplitPath() []string // splits $PATH by os.PathListSeparator
IsWritable(path string) bool // checks if directory is writable
}
Filesystem abstracts file operations for testability.
type InstallOptions ¶
type InstallOptions struct {
InstallAll bool // Unified install (binary, prompt, agents)
InstallPrompt bool
InstallAgent string // Agent name (claude, cursor)
ConfigPathOverride string // If set, overrides auto-detected config path
NonInteractive bool
DryRun bool
}
InstallOptions contains options for installation.
type InstallResult ¶
type InstallResult struct {
ExitCode ExitCode
Message string
BackupPath string
ConfigPath string
WhatChanged string
}
InstallResult contains the result of an installation operation.
type InstallState ¶
type InstallState int
InstallState represents the current installation state.
const ( NotInstalled InstallState = iota // Neither marker present FullyInstalled // Both markers present PartialInstall // Only one marker present (corrupted) )
type Installer ¶
type Installer struct {
// contains filtered or unexported fields
}
Installer is the main orchestrator for installation operations.
func NewInstaller ¶
func NewInstaller() *Installer
NewInstaller creates a new Installer with OS filesystem.
func NewInstallerWithFS ¶
func NewInstallerWithFS(fs Filesystem) *Installer
NewInstallerWithFS creates a new Installer with a custom filesystem.
func (*Installer) Run ¶
func (i *Installer) Run(opts InstallOptions) ExitCode
Run executes the installation based on the provided options.
type MockFilesystem ¶
type MockFilesystem struct {
Files map[string][]byte
Modes map[string]os.FileMode
EnvVars map[string]string
HomeDir string
// Binary installation support
ExecutablePath string // path returned by Executable()
Symlinks map[string]string // path -> target (for symlink detection)
WritableDirs map[string]bool // dir path -> writable
PathEnv string // value for PATH (overrides EnvVars["PATH"])
// Error simulation
ReadFileErr error
WriteFileErr error
StatErr error
MkdirAllErr error
RenameErr error
HomeDirErr error
ExecutableErr error
CopyFileErr error
ChmodErr error
LstatErr error
}
MockFilesystem implements Filesystem for testing.
func NewMockFilesystem ¶
func NewMockFilesystem() *MockFilesystem
NewMockFilesystem creates a new mock filesystem for testing.
func (*MockFilesystem) Chmod ¶ added in v1.1.3
func (f *MockFilesystem) Chmod(path string, mode os.FileMode) error
Chmod changes the mode of a file in the mock filesystem.
func (*MockFilesystem) CopyFile ¶ added in v1.1.3
func (f *MockFilesystem) CopyFile(src, dst string) error
CopyFile copies a file in the mock filesystem.
func (*MockFilesystem) Executable ¶ added in v1.1.3
func (f *MockFilesystem) Executable() (string, error)
Executable returns the mock executable path.
func (*MockFilesystem) Exists ¶
func (f *MockFilesystem) Exists(path string) bool
Exists checks if a file exists in the mock filesystem.
func (*MockFilesystem) Getenv ¶
func (f *MockFilesystem) Getenv(key string) string
Getenv returns a mock environment variable.
func (*MockFilesystem) IsWritable ¶ added in v1.1.3
func (f *MockFilesystem) IsWritable(path string) bool
IsWritable checks if a directory is writable in the mock filesystem.
func (*MockFilesystem) Lstat ¶ added in v1.1.3
func (f *MockFilesystem) Lstat(path string) (os.FileInfo, error)
Lstat returns mock file info, detecting symlinks.
func (*MockFilesystem) MkdirAll ¶
func (f *MockFilesystem) MkdirAll(path string, perm os.FileMode) error
MkdirAll is a no-op in the mock filesystem.
func (*MockFilesystem) ReadFile ¶
func (f *MockFilesystem) ReadFile(path string) ([]byte, error)
ReadFile reads from the mock filesystem.
func (*MockFilesystem) Rename ¶
func (f *MockFilesystem) Rename(src, dst string) error
Rename moves a file in the mock filesystem.
func (*MockFilesystem) SplitPath ¶ added in v1.1.3
func (f *MockFilesystem) SplitPath() []string
SplitPath returns the directories in the mock PATH.
func (*MockFilesystem) Stat ¶
func (f *MockFilesystem) Stat(path string) (os.FileInfo, error)
Stat returns mock file info.
func (*MockFilesystem) UserHomeDir ¶
func (f *MockFilesystem) UserHomeDir() (string, error)
UserHomeDir returns the mock home directory.
type OSFilesystem ¶
type OSFilesystem struct{}
OSFilesystem implements Filesystem using real OS operations.
func (*OSFilesystem) Chmod ¶ added in v1.1.3
func (f *OSFilesystem) Chmod(path string, mode os.FileMode) error
Chmod changes the mode of a file.
func (*OSFilesystem) CopyFile ¶ added in v1.1.3
func (f *OSFilesystem) CopyFile(src, dst string) error
CopyFile copies a file from src to dst, preserving permissions.
func (*OSFilesystem) Executable ¶ added in v1.1.3
func (f *OSFilesystem) Executable() (string, error)
Executable returns the path of the running binary.
func (*OSFilesystem) Exists ¶
func (f *OSFilesystem) Exists(path string) bool
Exists returns true if the file exists.
func (*OSFilesystem) Getenv ¶
func (f *OSFilesystem) Getenv(key string) string
Getenv returns the value of an environment variable.
func (*OSFilesystem) IsWritable ¶ added in v1.1.3
func (f *OSFilesystem) IsWritable(path string) bool
IsWritable checks if a directory is writable by the current user.
func (*OSFilesystem) Lstat ¶ added in v1.1.3
func (f *OSFilesystem) Lstat(path string) (os.FileInfo, error)
Lstat returns file info without following symlinks.
func (*OSFilesystem) MkdirAll ¶
func (f *OSFilesystem) MkdirAll(path string, perm os.FileMode) error
MkdirAll creates a directory and all parent directories.
func (*OSFilesystem) ReadFile ¶
func (f *OSFilesystem) ReadFile(path string) ([]byte, error)
ReadFile reads the contents of a file.
func (*OSFilesystem) Rename ¶
func (f *OSFilesystem) Rename(src, dst string) error
Rename renames (moves) a file.
func (*OSFilesystem) SplitPath ¶ added in v1.1.3
func (f *OSFilesystem) SplitPath() []string
SplitPath returns the directories in $PATH.
func (*OSFilesystem) Stat ¶
func (f *OSFilesystem) Stat(path string) (os.FileInfo, error)
Stat returns file info for the given path.
func (*OSFilesystem) UserHomeDir ¶
func (f *OSFilesystem) UserHomeDir() (string, error)
UserHomeDir returns the user's home directory.
type ShellConfig ¶
type ShellConfig struct {
Shell ShellType // The actual shell (bash, zsh, fish)
Template TemplateType // Which template to use (may differ, e.g., p10k for zsh)
ConfigPath string // Full path, e.g., /home/user/.bashrc
Name string // Human-readable, e.g., "Zsh (Powerlevel10k)"
}
ShellConfig contains shell detection and configuration information.
type ShellInstaller ¶
type ShellInstaller struct {
// contains filtered or unexported fields
}
ShellInstaller handles shell prompt installation.
func NewShellInstaller ¶
func NewShellInstaller(fs Filesystem) *ShellInstaller
NewShellInstaller creates a new ShellInstaller.
func (*ShellInstaller) CheckInstallState ¶
func (i *ShellInstaller) CheckInstallState(config *ShellConfig) (InstallState, error)
CheckInstallState checks if dashlights is already installed in the config file.
func (*ShellInstaller) DetectShell ¶
func (i *ShellInstaller) DetectShell() (ShellType, error)
DetectShell detects the shell type from the $SHELL environment variable.
func (*ShellInstaller) GetShellConfig ¶
func (i *ShellInstaller) GetShellConfig(configPathOverride string) (*ShellConfig, error)
GetShellConfig returns the shell configuration including paths and templates.
func (*ShellInstaller) Install ¶
func (i *ShellInstaller) Install(config *ShellConfig, dryRun bool) (*InstallResult, error)
Install installs dashlights into the shell config file.
type TemplateType ¶
type TemplateType string
TemplateType determines which prompt template to use.
const ( TemplateBash TemplateType = "bash" TemplateZsh TemplateType = "zsh" TemplateFish TemplateType = "fish" TemplateP10k TemplateType = "p10k" )
func InferTemplateFromPath ¶
func InferTemplateFromPath(configPath string) (TemplateType, bool)
InferTemplateFromPath determines the template type from a config file path.