writ

package
v0.1.0-dev.20260311011736 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Overview

Package writ implements the writ CLI commands.

Index

Constants

View Source
const CurrentVersion = op.GraphFormatVersion

CurrentVersion is the graph format version (delegates to op.GraphFormatVersion).

Variables

View Source
var LayerOrder = []string{"base", "team", "personal"}

LayerOrder defines the processing order for repository layers. Layers are processed in this order, with later layers overriding earlier ones.

Functions

func BuildTree

func BuildTree(g *op.Graph, cfg *Config, reg *op.ActionRegistry) (manifests []string, err error)

BuildTree walks the source directories and populates the graph with file nodes. This processes layers in order (base → team → personal) with collision detection. Returns discovered manifest source paths instead of creating nodes for them.

Parameters:

  • g: target graph to populate with nodes
  • cfg: resolved writ configuration
  • reg: action registry for node creation

Returns:

  • []string: manifest source paths discovered during tree walk
  • error: tree build or node creation error

func CollectLayerSources

func CollectLayerSources() ([]tree.LayerSource, error)

CollectLayerSources gathers all configured repository layers and expands them into source/target pairs. Returns sources ordered: base/System, base/Home, team/System, team/Home, personal/System, personal/Home (if configured/exist).

func ConfigureEngine

func ConfigureEngine(cfg *Config, targetRoot string) (*execution.GraphExecutor, error)

ConfigureEngine creates and configures an execution engine for a graph. The targetRoot parameter specifies the executor's root directory, allowing each scope's graph to execute against its own target (e.g., "/" for system, "$HOME" for home).

Parameters:

  • cfg: resolved writ configuration
  • targetRoot: root directory for this executor (overrides cfg.TargetRoot)

Returns:

  • *execution.GraphExecutor: configured executor
  • error: configuration error

func NewGraph

func NewGraph(cfg *Config) *op.Graph

NewGraph creates an op.Graph with common fields populated for writ.

Parameters:

  • cfg: resolved writ configuration

Returns:

  • *op.Graph: graph with context populated from config

func NewRootCmd

func NewRootCmd() *cobra.Command

NewRootCmd creates the root writ command with all subcommands.

func NewScopedGraph

func NewScopedGraph(cfg *Config, scope, targetRoot string) *op.Graph

NewScopedGraph creates an op.Graph tagged with a target scope and root. Used for multi-scope graph building where each scope gets its own graph.

Parameters:

  • cfg: resolved writ configuration
  • scope: target scope identifier ("system", "home")
  • targetRoot: target root path for this scope ("/" or "$HOME")

Returns:

  • *op.Graph: graph with scope and target root set

func PartitionByScope

func PartitionByScope(sources []tree.LayerSource) map[string][]tree.LayerSource

PartitionByScope groups layer sources by their TargetName ("System", "Home"). Sources within each partition retain their original ordering. Returns an empty map when sources is empty.

Parameters:

  • sources: flat list of layer sources from CollectLayerSources

Returns:

  • map[string][]tree.LayerSource: sources keyed by TargetName

Types

type AdoptConfig

type AdoptConfig struct {
	Config

	// Files to adopt.
	Files []string

	// Layer to adopt into (personal, team, base).
	Layer string

	// LayerPath is the resolved path to the layer directory.
	LayerPath string

	// Project to adopt into.
	Project string

	// FromReceipt adopts from a lore receipt.
	FromReceipt bool
}

AdoptConfig contains all settings for an adopt operation.

type AdoptGraphBuilder

type AdoptGraphBuilder struct {
	// contains filtered or unexported fields
}

AdoptGraphBuilder builds execution graphs for adopt operations.

func NewAdoptGraphBuilder

func NewAdoptGraphBuilder(cfg *AdoptConfig) *AdoptGraphBuilder

NewAdoptGraphBuilder creates a new adopt graph builder.

func (*AdoptGraphBuilder) Build

func (b *AdoptGraphBuilder) Build() (*op.Graph, error)

Build creates an execution graph for an adopt operation.

type Config

type Config struct {
	// Tool is "writ" or "lore".
	Tool string

	// Sources
	LayerSources []tree.LayerSource
	SourceRoot   string // single-repo mode (when no layers configured)
	TargetRoot   string

	// Selection
	Projects []string
	Segments segment.Segments

	// Behavior
	DryRun             bool
	Verbose            bool
	ConflictResolution execution.ConflictResolution

	// Data for templates
	TemplateData map[string]any

	// Identities for decryption
	Identities []age.Identity

	// Signing key (optional)
	SigningKey *age.X25519Identity
}

Config contains all resolved settings for a lifecycle operation. This is the common base; specific operations extend it.

func (*Config) SegmentMap

func (c *Config) SegmentMap() map[string]string

SegmentMap returns the segments as a string map for template data.

type DecommissionConfig

type DecommissionConfig struct {
	Config

	// Force decommission even with unsigned state.
	Force bool

	// Prune empty parent directories after file removal.
	Prune bool
}

DecommissionConfig contains all settings for a decommission operation.

type DecommissionGraphBuilder

type DecommissionGraphBuilder struct {
	// contains filtered or unexported fields
}

DecommissionGraphBuilder builds execution graphs for decommission operations.

func NewDecommissionGraphBuilder

func NewDecommissionGraphBuilder(cfg *DecommissionConfig, view *execution.StateView, reg *op.ActionRegistry) *DecommissionGraphBuilder

NewDecommissionGraphBuilder creates a new decommission graph builder.

func (*DecommissionGraphBuilder) Build

func (b *DecommissionGraphBuilder) Build() (*op.Graph, error)

Build creates an execution graph for a decommission operation.

type DeployConfig

type DeployConfig struct {
	Config

	// AllowDirty permits planning against layers with uncommitted changes.
	AllowDirty bool
}

DeployConfig contains all settings for a deploy operation.

type DeployGraphBuilder

type DeployGraphBuilder struct {
	Planner *lore.Planner // nil means skip manifest resolution
	// contains filtered or unexported fields
}

DeployGraphBuilder builds execution graphs for deploy operations.

func NewDeployGraphBuilder

func NewDeployGraphBuilder(cfg *DeployConfig, reg *op.ActionRegistry) *DeployGraphBuilder

NewDeployGraphBuilder creates a new deploy graph builder.

Parameters:

  • cfg: resolved deploy configuration
  • reg: action registry with registered actions

Returns:

  • *DeployGraphBuilder: configured builder

func (*DeployGraphBuilder) Build

func (b *DeployGraphBuilder) Build() ([]*op.Graph, error)

Build creates execution graphs for a deploy operation. In single-source mode, returns one graph. In multi-source mode, builds a unified tree for cross-scope collision detection, then partitions winning entries by target scope and creates one graph per populated scope.

Returns:

  • []*op.Graph: one graph per target scope
  • error: tree build or graph creation error

type MigrateGraphBuilder

type MigrateGraphBuilder struct {
	// contains filtered or unexported fields
}

MigrateGraphBuilder builds execution graphs for migrate operations.

func NewMigrateGraphBuilder

func NewMigrateGraphBuilder(cfg *Config, sourcePath string) *MigrateGraphBuilder

NewMigrateGraphBuilder creates a new migrate graph builder.

func (*MigrateGraphBuilder) Build

func (b *MigrateGraphBuilder) Build() (*op.Graph, error)

Build creates an execution graph for a migrate operation.

type ReconcileConfig

type ReconcileConfig struct {
	Config

	// CheckDrift enables drift detection for copied files.
	CheckDrift bool

	// JSONOutput outputs JSON instead of human-readable text.
	JSONOutput bool
}

ReconcileConfig contains all settings for a reconcile operation.

type ReconcileGraphBuilder

type ReconcileGraphBuilder struct {
	// contains filtered or unexported fields
}

ReconcileGraphBuilder builds execution graphs for reconcile operations.

func NewReconcileGraphBuilder

func NewReconcileGraphBuilder(cfg *ReconcileConfig) *ReconcileGraphBuilder

NewReconcileGraphBuilder creates a new reconcile graph builder.

func (*ReconcileGraphBuilder) Build

func (b *ReconcileGraphBuilder) Build() (*op.Graph, error)

Build creates an execution graph for a reconcile operation.

type TargetSpec

type TargetSpec struct {
	SourceDir  string // "System" or "Home"
	TargetRoot string // "/" or "$HOME"
}

TargetSpec defines a source directory within a repo and its deployment target.

func TargetOrder

func TargetOrder() []TargetSpec

TargetOrder defines the processing order for targets within each repo. System files are deployed before Home files.

type UpgradeConfig

type UpgradeConfig struct {
	Config

	// Force upgrades even if target has local modifications.
	Force bool
}

UpgradeConfig contains all settings for an upgrade operation.

type UpgradeGraphBuilder

type UpgradeGraphBuilder struct {
	// contains filtered or unexported fields
}

UpgradeGraphBuilder builds execution graphs for upgrade operations.

func NewUpgradeGraphBuilder

func NewUpgradeGraphBuilder(cfg *UpgradeConfig, view *execution.StateView) *UpgradeGraphBuilder

NewUpgradeGraphBuilder creates a new upgrade graph builder.

func (*UpgradeGraphBuilder) Build

func (b *UpgradeGraphBuilder) Build() (*op.Graph, error)

Build creates an execution graph for an upgrade operation.

type VerifyResult

type VerifyResult int

VerifyResult indicates the outcome of signature verification.

const (
	VerifyOK VerifyResult = iota
	VerifyUnsigned
	VerifyInvalid
	VerifyMissing
)

VerifyOK indicates the signature matched, VerifyUnsigned means no signature was present, VerifyInvalid means the signature failed verification, and VerifyMissing means the expected signature data was absent.

func VerifyGraphSignature

func VerifyGraphSignature(g *op.Graph, identities []age.Identity) (VerifyResult, error)

VerifyGraphSignature verifies the graph signature using the provided identities. Returns the verification result and any error encountered.

func (VerifyResult) String

func (r VerifyResult) String() string

String returns a human-readable description of the verify result.

Directories

Path Synopsis
Package identity provides age identity loading for writ.
Package identity provides age identity loading for writ.
Package migrate implements dotfile migration analysis and execution.
Package migrate implements dotfile migration analysis and execution.
Package reconcile implements drift detection and repair for writ deployments.
Package reconcile implements drift detection and repair for writ deployments.
Package secrets handles encryption/decryption operations via SOPS.
Package secrets handles encryption/decryption operations via SOPS.
Package segment provides segment-based directory matching for writ.
Package segment provides segment-based directory matching for writ.
Package snapshot provides git worktree-based snapshots for hermetic planning.
Package snapshot provides git worktree-based snapshots for hermetic planning.
Package tree builds deployment trees from source and target specifications.
Package tree builds deployment trees from source and target specifications.

Jump to

Keyboard shortcuts

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