config

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArchiveDir

func ArchiveDir() string

ArchiveDir returns the path to the session archive directory Archives are stored in ~/.config/clade/archive/ to persist across base_dir changes

func BuiltInLabels

func BuiltInLabels() map[string]LabelConfig

BuiltInLabels returns the built-in label configurations

func ConfigPath

func ConfigPath() (string, error)

ConfigPath returns the path to the config file Always uses ~/.config/clade/ for consistency across platforms

func EnsureRepoHooksTrusted

func EnsureRepoHooksTrusted(repoPath string) error

EnsureRepoHooksTrusted checks if repo hooks are trusted, prompting if not Returns error if user declines or an error occurs

Set CLADE_TRUST_REPO_HOOKS=1 (or legacy PACER_TRUST_REPO_HOOKS=1) to auto-trust all repo hooks (for testing/CI).

func ExpandPath

func ExpandPath(path string) string

ExpandPath expands ~ to home directory

func ExperimentKey

func ExperimentKey(repo, name string) string

ExperimentKey generates a unique key for an experiment (v1 format)

func GetWorktreePath

func GetWorktreePath(cfg *Config, repoName string, wt *Worktree) string

GetWorktreePath returns the actual path for a worktree, using custom Path if set

func HashFile

func HashFile(path string) (string, error)

HashFile computes SHA-256 hash of a file's contents

func LegacyStatePath

func LegacyStatePath(cfg *Config) string

LegacyStatePath returns the old state file location (in base_dir) Used for auto-migration from v2 to v3

func SetTestStateDir

func SetTestStateDir(dir string)

SetTestStateDir sets a custom state directory for testing Pass empty string to reset to default behavior

func StatePath

func StatePath() string

StatePath returns the path to the state file State is stored in ~/.config/clade/ alongside other metadata

func TrustRegistryPath

func TrustRegistryPath() (string, error)

TrustRegistryPath returns the path to the trust registry file

func WorktreePath

func WorktreePath(cfg *Config, repoName, name string) string

WorktreePath returns the path for a worktree given config and repo name

Types

type Config

type Config struct {
	BaseDir            string                  `json:"base_dir"`
	Agent              string                  `json:"agent"`
	AgentFlags         []string                `json:"agent_flags"`
	Editor             string                  `json:"editor,omitempty"`
	AutoInit           bool                    `json:"auto_init"`
	Repos              map[string]string       `json:"repos"`
	RepoSettings       map[string]RepoSettings `json:"repo_settings,omitempty"`
	LastRepo           string                  `json:"last_repo"`
	TmuxSplitDirection string                  `json:"tmux_split_direction,omitempty"`
	CustomLabels       map[string]LabelConfig  `json:"custom_labels,omitempty"`
	CopyFiles          []string                `json:"copy_files,omitempty"` // Additional files to copy to worktrees (beyond defaults)
}

Config holds the user configuration for clade

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a config with default values

func Load

func Load() (*Config, error)

Load reads the config from disk, creating default if not exists

func (*Config) ExperimentsDir

func (c *Config) ExperimentsDir() string

ExperimentsDir returns the path to experiments directory (legacy v0.2 structure) Deprecated: Use ReposDir() for new worktrees

func (*Config) GetBaseDir

func (c *Config) GetBaseDir() string

GetBaseDir returns the expanded base directory

func (*Config) GetLabelConfig

func (c *Config) GetLabelConfig(label string) (LabelConfig, bool)

GetLabelConfig returns the configuration for a label (built-in or custom)

func (*Config) GetRepoCopyFiles

func (c *Config) GetRepoCopyFiles(repoPath string) []string

GetRepoCopyFiles returns the copy_files setting for a repo

func (*Config) ProjectsDir

func (c *Config) ProjectsDir() string

ProjectsDir returns the path to projects directory

func (*Config) ReposDir

func (c *Config) ReposDir() string

ReposDir returns the path to repos directory (v0.3+ repo-centric structure)

func (*Config) Save

func (c *Config) Save() error

Save writes the config to disk

func (*Config) ScratchDir

func (c *Config) ScratchDir() string

ScratchDir returns the path to scratch directory

func (*Config) SetRepoCopyFiles

func (c *Config) SetRepoCopyFiles(repoPath string, files []string)

SetRepoCopyFiles saves the copy_files setting for a repo

type Experiment

type Experiment struct {
	Name     string    `json:"name"`
	Repo     string    `json:"repo"`
	Path     string    `json:"path"`
	Branch   string    `json:"branch"`
	Ticket   string    `json:"ticket,omitempty"`
	Created  time.Time `json:"created"`
	LastUsed time.Time `json:"last_used"`
}

Experiment represents a tracked experiment (v1 format, deprecated) Kept for backward compatibility during migration

type LabelConfig

type LabelConfig struct {
	BranchPrefix  string `json:"branch_prefix"`
	MergeExpected bool   `json:"merge_expected"`
}

LabelConfig defines a custom label configuration

type Project

type Project struct {
	Name     string        `json:"name"`
	Path     string        `json:"path"`
	Branch   string        `json:"branch"`
	Repos    []ProjectRepo `json:"repos"`
	Created  time.Time     `json:"created"`
	LastUsed time.Time     `json:"last_used"`
}

Project represents a tracked multi-repo project

type ProjectRepo

type ProjectRepo struct {
	Name   string `json:"name"`
	Source string `json:"source"`
}

ProjectRepo represents a repo within a project

type RepoSettings

type RepoSettings struct {
	CopyFiles []string `json:"copy_files,omitempty"`
}

RepoSettings holds per-repo configuration

type Scratch

type Scratch struct {
	Name     string    `json:"name"`
	Path     string    `json:"path"`
	Ticket   string    `json:"ticket,omitempty"`
	Created  time.Time `json:"created"`
	LastUsed time.Time `json:"last_used"`
}

Scratch represents a no-git scratch folder

type State

type State struct {
	Version int `json:"version"`

	// v2 format: nested worktrees by repo name
	// map[repoName]map[worktreeName]*Worktree
	Worktrees map[string]map[string]*Worktree `json:"worktrees,omitempty"`

	// v1 format (deprecated): flat experiments map
	// Kept for backward compatibility during migration
	Experiments map[string]*Experiment `json:"experiments,omitempty"`

	Projects  map[string]*Project `json:"projects"`
	Scratches map[string]*Scratch `json:"scratches,omitempty"`
}

State holds the runtime state of clade

func LoadState

func LoadState(cfg *Config) (*State, error)

LoadState reads the state from disk Automatically migrates from legacy location if needed

func NewState

func NewState() *State

NewState creates a new empty state with default values

func (*State) AddExperiment

func (s *State) AddExperiment(exp *Experiment)

AddExperiment adds or updates an experiment in state (v1 format, deprecated)

func (*State) AddScratch

func (s *State) AddScratch(scratch *Scratch)

AddScratch adds or updates a scratch in state

func (*State) AddWorktree

func (s *State) AddWorktree(repoName string, wt *Worktree)

AddWorktree adds or updates a worktree in v2 state

func (*State) FindExperimentByName

func (s *State) FindExperimentByName(name string) *Experiment

FindExperimentByName searches for an experiment by name in v1 format Returns the experiment or nil if not found

func (*State) FindWorktreeByName

func (s *State) FindWorktreeByName(name string) (string, *Worktree)

FindWorktreeByName searches for a worktree by name across all repos Returns (repoName, worktree) or ("", nil) if not found

func (*State) GetExperiment

func (s *State) GetExperiment(key string) *Experiment

GetExperiment retrieves an experiment by key (v1 format)

func (*State) GetScratch

func (s *State) GetScratch(name string) *Scratch

GetScratch retrieves a scratch by name

func (*State) GetWorktree

func (s *State) GetWorktree(repoName, name string) *Worktree

GetWorktree retrieves a worktree by repo name and worktree name

func (*State) RemoveExperiment

func (s *State) RemoveExperiment(key string)

RemoveExperiment removes an experiment from state (v1 format)

func (*State) RemoveScratch

func (s *State) RemoveScratch(name string)

RemoveScratch removes a scratch from state

func (*State) RemoveWorktree

func (s *State) RemoveWorktree(repoName, name string)

RemoveWorktree removes a worktree from v2 state

func (*State) Save

func (s *State) Save(cfg *Config) error

Save writes the state to disk Note: cfg parameter kept for backward compatibility but is no longer used as state is now saved to ~/.config/clade/state.json

type TrustEntry

type TrustEntry struct {
	Hash      string    `json:"hash"`       // SHA-256 hash of hooks.yaml content
	TrustedAt time.Time `json:"trusted_at"` // When the user approved
}

TrustEntry represents a trusted repo's hook configuration

type TrustRegistry

type TrustRegistry struct {
	Repos map[string]TrustEntry `json:"repos"` // repo path -> trust entry
}

TrustRegistry holds trust information for repos with hooks

func LoadTrustRegistry

func LoadTrustRegistry() (*TrustRegistry, error)

LoadTrustRegistry loads the trust registry from disk

func (*TrustRegistry) IsTrusted

func (t *TrustRegistry) IsTrusted(repoPath, hooksPath string) (bool, error)

IsTrusted checks if a repo's hooks are trusted and unchanged

func (*TrustRegistry) Revoke

func (t *TrustRegistry) Revoke(repoPath string) error

Revoke removes trust for a repo

func (*TrustRegistry) Save

func (t *TrustRegistry) Save() error

Save writes the trust registry to disk

func (*TrustRegistry) Trust

func (t *TrustRegistry) Trust(repoPath, hooksPath string) error

Trust marks a repo's hooks as trusted

type Worktree

type Worktree struct {
	Name     string    `json:"name"`
	Label    string    `json:"label"` // feature, bug, spike, chore, hotfix, docs, or custom
	Branch   string    `json:"branch"`
	Path     string    `json:"path,omitempty"` // Actual path if not in ~/clade/repos/ (for adopted worktrees)
	Ticket   string    `json:"ticket,omitempty"`
	Created  time.Time `json:"created"`
	LastUsed time.Time `json:"last_used"`
}

Worktree represents a tracked worktree (v2 format)

Jump to

Keyboard shortcuts

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