migrate

package
v0.1.0-dev.20260129011539 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Classify

func Classify(entries []InventoryEntry)

Classify assigns a FileClass to each inventory entry based on path, name, and file attributes. It modifies entries in place.

func Execute

func Execute(w io.Writer, plan *MigrationPlan) error

Execute performs the directory renames specified in the migration plan. It writes progress to the given writer (typically os.Stderr).

func FormatPlan

func FormatPlan(w io.Writer, plan *MigrationPlan, format string) error

FormatPlan writes the migration plan in the specified format.

func UniquePlatforms

func UniquePlatforms(entries []InventoryEntry) []string

UniquePlatforms returns a sorted list of unique platform values from entries.

func UniqueProjects

func UniqueProjects(entries []InventoryEntry) []string

UniqueProjects returns a sorted list of unique project names from entries.

Types

type DirectoryMapping

type DirectoryMapping struct {
	SourceDir string // e.g., "all-Darwin"
	TargetDir string // e.g., "all.Darwin"
	Project   string // e.g., "all"
	Platform  string // e.g., "Darwin"
}

DirectoryMapping represents a rename from legacy to writ naming.

func BuildMappings

func BuildMappings(root string) ([]DirectoryMapping, error)

BuildMappings generates the directory rename mappings for all directories that use the <project>-<Platform> convention.

type EncryptionSystem

type EncryptionSystem string

EncryptionSystem identifies the secret encryption tool in use.

const (
	EncryptGitCrypt     EncryptionSystem = "git-crypt"
	EncryptBlackbox     EncryptionSystem = "blackbox"
	EncryptTranscrypt   EncryptionSystem = "transcrypt"
	EncryptGPG          EncryptionSystem = "gpg"
	EncryptAge          EncryptionSystem = "age"
	EncryptAnsibleVault EncryptionSystem = "ansible-vault"
	EncryptSOPS         EncryptionSystem = "sops"
	EncryptNone         EncryptionSystem = "none"
)

func DetectEncryptedFile

func DetectEncryptedFile(path string) EncryptionSystem

DetectEncryptedFile checks a single file's content for encryption signatures.

func DetectEncryption

func DetectEncryption(root string) []EncryptionSystem

DetectEncryption identifies encryption systems in use in the repository. Returns a list of detected systems (there may be multiple).

type FileClass

type FileClass string

FileClass categorizes a file by its role in the environment.

const (
	ClassStaticConfig    FileClass = "static-config"
	ClassLifecycleScript FileClass = "lifecycle-script"
	ClassScript          FileClass = "script"
	ClassSecret          FileClass = "secret"
	ClassTemplate        FileClass = "template"
	ClassFont            FileClass = "font"
	ClassManPage         FileClass = "man-page"
	ClassCompletion      FileClass = "completion"
	ClassBinary          FileClass = "binary"
)

type InventoryEntry

type InventoryEntry struct {
	RelPath      string // Relative path from source root
	AbsPath      string // Absolute path
	Project      string // Parsed from directory name
	Platform     string // Parsed from directory name (empty if base)
	Class        FileClass
	IsExecutable bool
	SizeBytes    int64
	Observations []string
}

InventoryEntry represents a single file discovered during inventory.

func Inventory

func Inventory(root string) ([]InventoryEntry, error)

Inventory walks the source root and builds a list of all files with their project and platform assignments.

type MigratedMarker

type MigratedMarker struct {
	Timestamp string             `yaml:"timestamp"`
	System    SourceSystem       `yaml:"system"`
	Mappings  []DirectoryMapping `yaml:"mappings"`
}

MigratedMarker records what was done during execution.

type Migration

type Migration struct {
	Issue    string   // what's wrong
	Commands []string // suggested git commands to fix it
}

Migration describes a recommended migration step.

type MigrationPlan

type MigrationPlan struct {
	SourceRoot        string             `json:"source_root" yaml:"source_root"`
	System            SourceSystem       `json:"system" yaml:"system"`
	RepoLayer         RepoLayer          `json:"repo_layer" yaml:"repo_layer"`
	EncryptionSystems []EncryptionSystem `json:"encryption_systems" yaml:"encryption_systems"`
	Entries           []InventoryEntry   `json:"entries" yaml:"entries"`
	Mappings          []DirectoryMapping `json:"mappings" yaml:"mappings"`
	Projects          []string           `json:"projects" yaml:"projects"`
	Scripts           []ScriptAnalysis   `json:"scripts" yaml:"scripts"`
	SecretFindings    []SecretFinding    `json:"secret_findings" yaml:"secret_findings"`
	Stats             Stats              `json:"stats" yaml:"stats"`
	Observations      []string           `json:"observations" yaml:"observations"`
	Warnings          []string           `json:"warnings" yaml:"warnings"`
}

MigrationPlan represents the complete analysis of a migration.

func BuildPlan

func BuildPlan(ctx context.Context, opts Options) (*MigrationPlan, error)

BuildPlan performs detection, inventory, classification, analysis, and assembles a complete migration plan.

type Options

type Options struct {
	SourceRoot string
	TargetRoot string // empty = rename in place
	Execute    bool
	Verbose    bool
	Format     string // "text", "yaml", "json"
	Provider   model.Provider
	RegClient  *registry.Client
}

Options controls migration behavior.

type ProjectInfo

type ProjectInfo struct {
	Name      string
	Path      string
	Segment   string // segment suffix (e.g., "Darwin", "Unix")
	FileCount int
	Templates int
	Secrets   int
}

ProjectInfo describes a detected project directory.

type RepoLayer

type RepoLayer string

RepoLayer indicates the precedence layer of a repo. Precedence: base (lowest) → team → personal (highest).

const (
	LayerBase     RepoLayer = "base"
	LayerTeam     RepoLayer = "team"
	LayerPersonal RepoLayer = "personal"
)

type ScanResult

type ScanResult struct {
	Path string

	// Git information
	IsGit    bool
	Remote   string
	Branch   string
	Dirty    int // count of uncommitted changes
	GitError string

	// Structure detection
	Structure     SourceStructure
	HomePath      string // path to detected Home-equivalent directory
	Projects      []ProjectInfo
	NestedUnder   string // non-empty if projects are nested (e.g., "Configs")
	TemplateCount int
	SecretCount   int
	HasRecipients bool

	// Migration guidance
	Migrations []Migration
}

ScanResult holds the results of scanning a source directory for migration.

func ScanSource

func ScanSource(path string) *ScanResult

ScanSource inspects a directory and reports on its suitability for writ migration.

func (*ScanResult) NeedsMigration

func (r *ScanResult) NeedsMigration() bool

NeedsMigration returns true if the scan found issues that require migration.

func (*ScanResult) PrintReport

func (r *ScanResult) PrintReport()

PrintReport outputs the scan result to stderr.

type ScriptAnalysis

type ScriptAnalysis struct {
	RelPath        string   // Relative path from source root
	Name           string   // Base filename
	Phase          string   // "install" or "initialize"
	PackageNames   []string // Extracted package names
	PackageManager string   // Detected package manager
	PlatformGuard  string   // Platform guard if detected
	LineCount      int
	Observations   []string // Grounded observations about what the script does
}

ScriptAnalysis captures information extracted from a lifecycle script.

func AnalyzeScripts

func AnalyzeScripts(entries []InventoryEntry) []ScriptAnalysis

AnalyzeScripts examines lifecycle script entries and extracts information about what they install and how.

type SecretFinding

type SecretFinding struct {
	RelPath          string           // Relative path from source root
	Encryption       EncryptionSystem // Current encryption (or EncryptNone)
	Reason           string           // Why we think it's a secret
	SuggestedPattern string           // Suggested .sops.yaml path_regex (for AI)
}

SecretFinding represents a detected secret file.

type SourceStructure

type SourceStructure int

SourceStructure describes the detected source directory layout.

const (
	StructureUnknown    SourceStructure = iota
	StructureCompatible                 // Home/<project>/ with "." segments
	StructurePartial                    // Has Home/ but needs migration
	StructureFlat                       // Dot-prefixed files at root (e.g., .bashrc, .vimrc)
	StructureStow                       // GNU Stow directory with packages
)

func (SourceStructure) String

func (s SourceStructure) String() string

String returns a human-readable label for the structure type.

type SourceSystem

type SourceSystem string

SourceSystem identifies the dotfile management approach used in the source repository.

const (
	SystemNative      SourceSystem = "native" // Already writ-compatible (Home/ or System/)
	SystemTuckr       SourceSystem = "tuckr"
	SystemStow        SourceSystem = "stow"
	SystemChezmoi     SourceSystem = "chezmoi"
	SystemYadm        SourceSystem = "yadm"
	SystemBareGit     SourceSystem = "bare-git"
	SystemScriptBased SourceSystem = "script-based"
	SystemUnknown     SourceSystem = "unknown"
)

func Detect

func Detect(root string) (SourceSystem, error)

Detect identifies the source system used in the given directory. It checks for tool-specific markers first, then falls back to native/unknown.

type Stats

type Stats struct {
	TotalFiles       int `json:"total_files" yaml:"total_files"`
	StaticConfigs    int `json:"static_configs" yaml:"static_configs"`
	Scripts          int `json:"scripts" yaml:"scripts"`
	LifecycleScripts int `json:"lifecycle_scripts" yaml:"lifecycle_scripts"`
	Secrets          int `json:"secrets" yaml:"secrets"`
	Fonts            int `json:"fonts" yaml:"fonts"`
	Templates        int `json:"templates" yaml:"templates"`
	Completions      int `json:"completions" yaml:"completions"`
	ManPages         int `json:"man_pages" yaml:"man_pages"`
	Binaries         int `json:"binaries" yaml:"binaries"`
	Projects         int `json:"projects" yaml:"projects"`
	Platforms        int `json:"platforms" yaml:"platforms"`
	Renames          int `json:"renames" yaml:"renames"`
}

Stats summarizes the migration plan numerically.

Jump to

Keyboard shortcuts

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