workspace

package
v0.0.0-...-7b55b97 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package workspace implements the multi-pack orchestration engine. It provides tools discovery, parallel pack operations, progress display, linting, and the sync engine used by packwand workspace commands.

Index

Constants

This section is empty.

Variables

View Source
var (
	OpUpdate = Operation{
		Name:        "update",
		Gerund:      "updating",
		PackwizArgs: []string{"update", "--all", "-y"},
		HonorIgnore: true,
	}
	OpRefresh = Operation{
		Name:        "refresh",
		Gerund:      "refreshing",
		PackwizArgs: []string{"refresh"},
		HonorIgnore: false,
	}
)

Functions

func AutoLintDirs

func AutoLintDirs(dirs []string)

AutoLintDirs lints all .pw.toml files under mods/ in each given dir. Warnings are printed but the function never exits — it is a best-effort post-op check.

func CacheSlotCount

func CacheSlotCount() int

CacheSlotCount returns the number of packwand export operations that may run concurrently against the on-disk pack cache. Controlled by PACKWAND_CACHE_SLOTS.

func CheckUpdatesInDir

func CheckUpdatesInDir(dir string) ([]string, error)

CheckUpdatesInDir runs packwand update --all --dry-run and returns found update strings.

func CollectTargets

func CollectTargets(root string, honorIgnore bool, packFilter string, explicit bool) (targets []string, skipped []string)

CollectTargets discovers pack subdirectories eligible for op under root.

func ConfigureSubprocess

func ConfigureSubprocess(c *exec.Cmd)

ConfigureSubprocess keeps workspace-level fanout from multiplying by each child packwand process's internal fanout. Explicit user limits are preserved.

func CopyFileFast

func CopyFileFast(src, dst string) error

CopyFileFast copies src to dst using a 1 MiB buffer.

func FindRepoRoot

func FindRepoRoot() string

FindRepoRoot walks up from cwd looking for .git or modpacks/.

func GitChangedFiles

func GitChangedFiles() []string

GitChangedFiles returns filenames changed in the last commit.

func Indent

func Indent(s, prefix string) string

Indent prefixes every line of s with prefix.

func LintOne

func LintOne(path string) error

LintOne validates a single .json or .pw.toml file for syntax.

func MaxConcurrent

func MaxConcurrent() int

MaxConcurrent returns the number of parallel workers to use.

func ModpacksDir

func ModpacksDir() string

ModpacksDir returns the root directory containing all pack directories.

func ResolveScope

func ResolveScope(args []string, startCwd string) (packFilter string, explicit bool)

ResolveScope converts command args into a (packFilter, explicit) pair. Pass startCwd as the directory where the user invoked the command.

func Run

func Run(op Operation, packFilter string, explicit bool) error

Run executes op across all eligible pack subdirs under ModpacksDir().

func RunLintFiles

func RunLintFiles(files []string) (failed, checked int64)

RunLintFiles lints files concurrently and returns (failed, checked) counts.

func RunSync

func RunSync(dryRun bool) error

RunSync performs the base→consumer pack sync. dryRun prints what would change.

func SelfBin

func SelfBin() string

SelfBin returns the path to the running packwand binary for sub-invocations. Reads PACKWAND_BIN first; falls back to PACKWIZ_BIN for backward compatibility.

func WorkPool

func WorkPool(targets []string, op Operation, prog *Progress) []string

WorkPool runs op across targets using the scheduler, returning paths that failed.

func WriteJSON

func WriteJSON(path string, v any) error

WriteJSON writes v as indented JSON to path.

Types

type Operation

type Operation struct {
	Name        string
	Gerund      string
	PackwizArgs []string
	HonorIgnore bool
	// ExtraArgsFor, when set, appends per-target arguments to PackwizArgs
	// (e.g. a per-subdir --report path).
	ExtraArgsFor func(dir string) []string
}

Operation describes a packwand sub-command to run across pack subdirectories.

type Progress

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

func NewProgress

func NewProgress(label string, total int) *Progress

NewProgress creates and starts a TTY progress display.

func (*Progress) Done

func (p *Progress) Done()

Done stops the progress display and clears the line.

func (*Progress) Step

func (p *Progress) Step(item string)

Step records one unit of progress.

type Resource

type Resource string

Resource is an exclusive resource key that tasks can claim.

func CacheSlot

func CacheSlot(key string, slots int) Resource

CacheSlot returns a Resource key that distributes dirs across n slots by FNV hash.

type Scheduler

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

Scheduler runs tasks concurrently while serialising tasks that share a Resource.

func NewScheduler

func NewScheduler(workers int) *Scheduler

NewScheduler creates a Scheduler with the given worker count.

func (*Scheduler) Close

func (s *Scheduler) Close()

Close signals that no more tasks will be submitted. Workers exit once all pending tasks finish. Must be called after the last Submit.

func (*Scheduler) Submit

func (s *Scheduler) Submit(t Task) <-chan error

Submit enqueues a task and returns a channel that receives the error when done.

func (*Scheduler) SubmitWait

func (s *Scheduler) SubmitWait(t Task) error

SubmitWait submits a task and blocks until it completes.

func (*Scheduler) Wait

func (s *Scheduler) Wait()

Wait blocks until all pending tasks have completed.

type Task

type Task struct {
	Name     string
	Priority int
	Needs    []Resource
	Run      func() error
}

Task describes a unit of work for the Scheduler.

Jump to

Keyboard shortcuts

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