tree

package
v0.1.0-dev.20260131030825 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package tree provides deployment tree building for writ.

Index

Constants

This section is empty.

Variables

View Source
var PackagesManifestFiles = []string{
	"packages-manifest.yaml",
	"packages-manifest.json",
	"packages.manifest",
}

PackagesManifestFiles are filenames that contain package specifications. These files are processed by the Package Graph Builder to produce package installation nodes in the execution graph.

packages-manifest.{yaml,json} is the canonical format. packages.manifest is supported for backward compatibility.

Functions

This section is empty.

Types

type BuildConfig

type BuildConfig struct {
	// SourceRoot is the source directory for single-source mode.
	// Deprecated: Use Sources for multi-layer support.
	SourceRoot string

	// TargetRoot is the target directory (e.g., $HOME).
	// Used as default when Sources is empty.
	TargetRoot string

	// Sources are the layer sources for multi-source mode.
	// If empty, falls back to single-source mode using SourceRoot/TargetRoot.
	Sources []LayerSource

	// Projects to include (e.g., ["all", "noblefactor"]).
	Projects []string

	// Segments for platform matching.
	Segments segment.Segments
}

BuildConfig holds configuration for building a deployment graph.

type BuildResult

type BuildResult struct {
	// Files are the file entries discovered.
	Files []*FileEntry

	// SourceRoot is the source root directory (for single-source mode).
	SourceRoot string

	// TargetRoot is the target root directory.
	TargetRoot string

	// Sources are the layer sources processed (for multi-source mode).
	Sources []LayerSource

	// Projects included in this build.
	Projects []string

	// MatchedDirs are the directories that matched the segments.
	MatchedDirs []segment.MatchResult

	// Collisions are files where a more specific source overrode a less specific one.
	Collisions []Collision
}

BuildResult contains the built file entries and build-time metadata.

func Build

func Build(cfg BuildConfig) (*BuildResult, error)

Build creates an execution graph from the given configuration. Supports both single-source mode (SourceRoot) and multi-source mode (Sources).

func (*BuildResult) CompactString

func (r *BuildResult) CompactString() string

CompactString returns a compact summary of the build result.

func (*BuildResult) FileCount

func (r *BuildResult) FileCount() int

FileCount returns the number of files discovered.

func (*BuildResult) HasCollisions

func (r *BuildResult) HasCollisions() bool

HasCollisions returns true if there were file collisions during build.

func (*BuildResult) LinkCount

func (r *BuildResult) LinkCount() int

LinkCount returns the number of simple symlink files.

func (*BuildResult) PackagesCount

func (r *BuildResult) PackagesCount() int

PackagesCount returns the number of packages-manifest entries. These require the Package Graph Builder (NOT YET IMPLEMENTED).

func (*BuildResult) SecretCount

func (r *BuildResult) SecretCount() int

SecretCount returns the number of encrypted files.

func (*BuildResult) String

func (r *BuildResult) String() string

String returns a human-readable representation of the build result.

func (*BuildResult) TemplateCount

func (r *BuildResult) TemplateCount() int

TemplateCount returns the number of template files.

type Collision

type Collision struct {
	// Target is the relative target path that had a collision.
	Target string

	// Winner is the source that won (more specific or higher layer).
	Winner string

	// WinnerSpecificity is the number of suffixes on the winning directory.
	WinnerSpecificity int

	// WinnerLayer is the layer of the winner (empty for single-source mode).
	WinnerLayer string

	// Loser is the source that was overridden (less specific or lower layer).
	Loser string

	// LoserSpecificity is the number of suffixes on the losing directory.
	LoserSpecificity int

	// LoserLayer is the layer of the loser (empty for single-source mode).
	LoserLayer string
}

Collision records when a more specific file overrides a less specific one.

type FileEntry

type FileEntry struct {
	// ID is the relative target path (unique identifier).
	ID string

	// Operations is the pipeline of operations to perform.
	// Examples: ["link"], ["decrypt", "expand", "copy"].
	Operations []string

	// Source is the absolute path to the source file.
	Source string

	// Target is the absolute path to the target file.
	Target string

	// Project this file belongs to.
	Project string

	// Layer is the repository layer (base, team, personal).
	Layer string

	// Mode is the file permissions to set (0 means default 0644).
	Mode os.FileMode
}

FileEntry represents a file discovered during tree walking. This is pure file metadata - no execution state.

type LayerSource

type LayerSource struct {
	Layer      string // "base", "team", or "personal"
	Path       string // Repo root path
	Order      int    // 0=base, 1=team, 2=personal (for precedence sorting)
	SourceRoot string // Full path to source directory (e.g., /path/to/repo/Home)
	TargetRoot string // Target root (e.g., $HOME or /)
	TargetName string // "System" or "Home"
}

LayerSource represents a repository layer with its path and precedence order.

type Operation

type Operation int

Operation represents a file processing operation.

const (
	// OpLink creates a symlink from target to source.
	OpLink Operation = iota

	// OpExpand processes a .template file with Go text/template.
	OpExpand

	// OpCopy writes content to target (used after expand or decrypt).
	OpCopy

	// OpDecrypt decrypts a .age file using age encryption.
	OpDecrypt

	// OpPackages marks a packages-manifest.yaml file that requires processing
	// by the Package Graph Builder to add package installation nodes to the
	// execution graph. This is NOT a delegation to another tool—writ and lore
	// share the same execution engine.
	//
	// NOT YET IMPLEMENTED: The Package Graph Builder (internal/lore/graph) does
	// not exist yet. When implemented, it will parse the manifest and produce
	// install/configure/verify nodes that the shared engine executes.
	OpPackages
)

func (Operation) String

func (o Operation) String() string

String returns the operation name.

type Operations

type Operations []Operation

Operations is a slice of operations for JSON marshaling.

func ProcessingPipeline

func ProcessingPipeline(filename string) (targetName string, ops Operations)

ProcessingPipeline determines operations from a filename. Extensions are processed outside-in (like .tar.gz).

Examples:

"foo"                     → "foo",                     [link]
"foo.template"            → "foo",                     [expand, copy]
"foo.age"                 → "foo",                     [decrypt, copy]
"foo.template.age"        → "foo",                     [decrypt, expand, copy]
"packages-manifest.yaml"  → "packages-manifest.yaml",  [packages]

func (Operations) HasCopy

func (ops Operations) HasCopy() bool

HasCopy returns true if the operations include a copy operation. Files with copy are written to disk (templates, secrets) rather than symlinked.

func (Operations) HasPackages

func (ops Operations) HasPackages() bool

HasPackages returns true if the operations include a packages operation. This indicates a packages-manifest.yaml file that needs processing by the Package Graph Builder (NOT YET IMPLEMENTED).

func (Operations) Strings

func (ops Operations) Strings() []string

Strings returns the operation names.

Jump to

Keyboard shortcuts

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