migrate

package
v0.1.0-dev.20260127210113 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 14 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 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"`
	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"
	AIProvider ai.Provider
	RegClient  *registry.Client
}

Options controls migration behavior.

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 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 SourceSystem

type SourceSystem string

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

const (
	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 filesystem signals in priority order and returns the first match.

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