wrkcli

package
v0.0.110 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 63 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodGoInstall           = installplan.MethodGoInstall
	MethodGoRunInstall        = installplan.MethodGoRunInstall
	ActionInstall      Action = "install"
	ActionSkip         Action = "skip"

	DiagLevelNotice  = installplan.DiagLevelNotice
	DiagLevelWarning = installplan.DiagLevelWarning

	DiagKindPreferScript    = installplan.DiagKindPreferScript
	DiagKindAmbiguousCmd    = installplan.DiagKindAmbiguousCmd
	DiagKindAmbiguousScript = installplan.DiagKindAmbiguousScript
	DiagKindNestedScript    = installplan.DiagKindNestedScript
)

Variables

This section is empty.

Functions

func Complete

func Complete(wrkHome string, req CompletionRequest) []string

Complete returns bash tab-completion candidates for the given request.

func FormatCompareBranches

func FormatCompareBranches(refA, refB string, result *git.CompareBranchesResult) string

FormatCompareBranches returns kool compare-branch text for refA vs refB.

func FormatMasterBrief

func FormatMasterBrief(result *git.CompareBranchesResult, colorEnabled bool) string

FormatMasterBrief returns a one-line master sync summary for --status linked worktrees.

func FormatRemoteBrief

func FormatRemoteBrief(result *git.CompareBranchesResult, colorEnabled bool) string

FormatRemoteBrief returns a one-line remote sync summary for --projects.

func FormatStderrError added in v0.0.17

func FormatStderrError(msg string) string

FormatStderrError colors a leading "Error:" prefix red when color is on. Prefer prefix-only coloring so the body stays plain.

func FormatStderrWarning added in v0.0.17

func FormatStderrWarning(msg string) string

FormatStderrWarning colors a leading "warning:" prefix yellow/orange when color is on.

func IsWipSubject added in v0.0.2

func IsWipSubject(subject string) bool

IsWipSubject reports whether a commit subject is a WIP commit for sync pass-1. After trimming surrounding whitespace, match is case-insensitive prefix any of:

wip:  |  wip(  |  [wip]

Empty / whitespace-only subjects and mid-string-only occurrences are not WIP.

func NormalizeTaskSlug

func NormalizeTaskSlug(taskDesc string) (string, error)

NormalizeTaskSlug turns free-text task into a path slug. Empty or whitespace-only input yields empty slug (no task segment). Non-empty input that slugifies to empty is an error.

func RegisterWebServe

func RegisterWebServe(fn webServeFunc)

RegisterWebServe sets the implementation used by `wrk --web`. cmd/wrk calls this from init with wrkcli/web.Serve.

func ResolveReinstallScanRoot added in v0.0.6

func ResolveReinstallScanRoot(workDir string, useMain bool) (string, error)

ResolveReinstallScanRoot returns the absolute directory from which Go module discovery should begin for multi-module local reinstall planning.

func ResolveWrkHome

func ResolveWrkHome(wrkHome string) (string, error)

ResolveWrkHome returns wrkHome when non-empty; otherwise WRK_HOME or ~/.wrk.

func Run

func Run(args []string) error

Run executes wrk logic with args. The first positional argument, if present, is the source directory for all modes.

func RunWithOpts added in v0.0.34

func RunWithOpts(opts RunOpts) error

RunWithOpts is like Run but accepts optional in-process test/runtime opts (passed down the call stack; no env or package globals).

func RunWithWriters added in v0.0.25

func RunWithWriters(stdout, stderr io.Writer, opts CaptureOpts) error

RunWithWriters runs wrk in-process, writing primary output to the given writers (nil → discard). Env/Dir isolation matches Capture. Prefer Capture when you need the full CLI exit-code + formatted-stderr contract.

Note: non-ExitCodeError return values are not auto-printed to stderr (unlike Capture / main); callers that need main's formatting should use Capture.

func SetForceStderrColor added in v0.0.17

func SetForceStderrColor(v bool)

SetForceStderrColor records --color for top-level Error:/warning: printing.

func ShellSafeQuote

func ShellSafeQuote(s string) string

ShellSafeQuote encodes s as a single POSIX shell word using single quotes. Empty string becomes ”; embedded single quotes use the '\” join form.

func Version

func Version() string

Version returns the embedded build version (e.g. "v0.0.1").

Types

type Action added in v0.0.6

type Action string

type CaptureOpts added in v0.0.25

type CaptureOpts struct {
	// Args are CLI args after the program name (same as wrkcli.Run).
	Args []string
	// Dir, when non-empty, is the virtual process cwd for the duration of the
	// call (via processCwd / captureDir under the capture mutex — no os.Chdir,
	// so parallel test Setup/git keep a valid real getcwd). Prefer absolute
	// paths. Omit when cwd is irrelevant (most short paths).
	Dir string
	// WrkHome, when non-empty, overrides WRK_HOME without os.Setenv (Parallel-safe).
	WrkHome string
	// Env are additional KEY=VAL entries. WRK_HOME and WRK_DATE are peeled into
	// capture overrides (no Setenv). Other keys still use temporary Setenv under
	// the capture mutex — avoid those when mixing with parallel Environ readers.
	Env []string
	// Stdin, when non-empty, replaces os.Stdin with a pipe containing this
	// data for the duration of the call (restored afterward). Use for
	// --confirm-from-stdin and similar non-TTY prompt paths. Empty leaves
	// the process stdin unchanged (typically not a pipe under go test).
	Stdin string
	// ScanTestPauseAfterFirstPrint is passed through to RunWithOpts (not env).
	// See RunOpts.ScanTestPauseAfterFirstPrint for docs and supporting tests.
	ScanTestPauseAfterFirstPrint time.Duration
	// WithGo is the injectable Go SDK resolver for dep-update versioned tidy.
	// Production leaves this zero; Capture tests set InstallDir + Download:false.
	WithGo withgo.ResolveOptions
}

CaptureOpts configures an in-process CLI invocation that mirrors main's stdout/stderr/exit-code contract without spawning the wrk binary.

type CaptureResult added in v0.0.25

type CaptureResult struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

CaptureResult is the CLI-shaped outcome of Capture / RunWithWriters.

func Capture added in v0.0.25

func Capture(opts CaptureOpts) CaptureResult

Capture runs wrk in-process, capturing stdout and stderr like a subprocess. Errors are formatted onto stderr the same way as cmd/wrk main (except ExitCodeError, which stays silent and only sets ExitCode).

Capture holds an internal mutex for the duration of the call (stdout/stderr swap, optional virtual cwd). Prefer for short paths (help, skill, version, flag reject) and dual-mode InProcess leaves.

func RunCapture added in v0.0.25

func RunCapture(args ...string) CaptureResult

RunCapture is a convenience wrapper: Capture with only Args set.

type CompletionRequest

type CompletionRequest struct {
	Words []string
	CWord int
}

CompletionRequest carries bash COMP_WORDS and COMP_CWORD for tab completion.

type Config

type Config struct {
	Version int            `json:"version"`
	Create  *CreateSection `json:"create,omitempty"`
}

Config is the optional user config at $WRK_HOME/config.json.

type CreateAgent

type CreateAgent struct {
	Enabled        *bool    `json:"enabled,omitempty"`
	Runner         string   `json:"runner,omitempty"`
	PromptTemplate string   `json:"prompt_template,omitempty"`
	Args           []string `json:"args,omitempty"`
	// Browser names the browser for `dsh web open --browser` (dsh-web runner
	// only); empty forwards nothing.
	Browser string `json:"browser,omitempty"`
}

CreateAgent configures agent-run launch after create.

type CreateSection

type CreateSection struct {
	Window   *CreateWindow   `json:"window,omitempty"`
	Terminal *CreateTerminal `json:"terminal,omitempty"`
	Agent    *CreateAgent    `json:"agent,omitempty"`
}

CreateSection holds create-mode UX options. Legacy create.interceptor is deliberately omitted so leftover JSON is ignored.

type CreateTerminal

type CreateTerminal struct {
	// Mode is "new" | "reuse" | "smart"; absent/empty means terminal off.
	Mode string `json:"mode,omitempty"`
}

CreateTerminal configures iTerm2 open mode.

type CreateWindow

type CreateWindow struct {
	// Mode is "new" when window UX is on; absent/empty means off.
	Mode string `json:"mode,omitempty"`
}

CreateWindow configures Mission Control Desktop creation.

type CreateWorktreeResult

type CreateWorktreeResult struct {
	Path   string
	Branch string
}

CreateWorktreeResult is the structured outcome of default worktree creation.

func CreateDefaultWorktree

func CreateDefaultWorktree(projectPath, wrkHome, taskSlug string) (*CreateWorktreeResult, error)

CreateDefaultWorktree creates a linked worktree under wrkHome/worktrees using wrk default naming (basename-branchToken-date[-slug][-N]).

projectPath may be the main repo or any checkout that resolves to it. wrkHome must be non-empty (callers inject Options.WrkHome or ResolveWrkHome). taskSlug is an already-slugified task segment; empty means no task in names. Callers that accept free-text tasks should use NormalizeTaskSlug first.

type DepUpdateAllAction added in v0.0.64

type DepUpdateAllAction struct {
	ConsumerModDir string
	ConsumerPath   string
	CheckoutPath   string // stack member Path containing the consumer
	DepModule      string
	DepDir         string // owner module dir on registered main path
	OldVersion     string
	NewVersion     string
	Tag            string
}

DepUpdateAllAction is one planned pin under --dep-update --all.

type DepUpdateAllPlan added in v0.0.64

type DepUpdateAllPlan struct {
	Actions   []DepUpdateAllAction
	Already   int
	Skipped   int
	Warnings  []string // may include warning: prefix
	Checkouts int      // stack member count (used when there are no pin actions)
}

DepUpdateAllPlan is the pure plan for wrk --dep-update --all.

func PlanDepUpdateAll added in v0.0.64

func PlanDepUpdateAll(workDir, wrkHome string) (*DepUpdateAllPlan, error)

PlanDepUpdateAll builds pin actions for inventory-owned requires on the unwind stack (CollectStackInventory). External (non-inventory) requires are silent. Same-checkout local filesystem replaces and no-tag owners count as skipped. --all still requires a git repo.

type DirHintOptions

type DirHintOptions struct {
	RawArgs     []string
	Positionals []string
	DepMode     bool
}

DirHintOptions carries CLI context for reconstructing guided file-collision hints.

type Edge added in v0.0.6

type Edge struct {
	ConsumerProject string
	ConsumerModule  string
	DepPath         string
	DepVersion      string
	OwnerProject    string
}

Edge is a require from a consumer module to a dependency module path whose owner project is known in the inventory.

type ExitCodeError

type ExitCodeError struct {
	Code int
}

ExitCodeError signals a non-zero exit without stderr output.

func (ExitCodeError) Error

func (e ExitCodeError) Error() string

type Inventory added in v0.0.6

type Inventory struct {
	Projects     []ProjectEntry
	SkippedPaths []string
}

Inventory is the in-process model of registered projects, their modules, and soft-skipped registry paths.

func BuildInventory added in v0.0.6

func BuildInventory(wrkHome string) (Inventory, error)

BuildInventory loads WRK_HOME projects, soft-skips missing paths, scans modules, and builds ownership.

func (Inventory) CrossEdges added in v0.0.6

func (inv Inventory) CrossEdges() []Edge

CrossEdges returns require edges where consumer and owner projects both known and differ.

func (Inventory) FindOwner added in v0.0.6

func (inv Inventory) FindOwner(modulePath string) (projectPath string, ok bool)

FindOwner returns the registered project path that owns modulePath.

func (Inventory) IntraEdges added in v0.0.6

func (inv Inventory) IntraEdges() []Edge

IntraEdges returns require edges where consumer and owner projects both known and equal.

type LocalReinstallPlan added in v0.0.6

type LocalReinstallPlan struct {
	ModuleRoot  string
	ModulePath  string // full module path from go.mod
	ModuleName  string // basename of module path from go.mod
	BinDir      string
	Items       []PlanItem            // sorted lexicographically by BinName
	Diagnostics []ReinstallDiagnostic // sorted by BinName, then Kind
}

LocalReinstallPlan is the pure discovery/filter result for local binary reinstalls.

func PlanLocalReinstalls added in v0.0.6

func PlanLocalReinstalls(moduleRoot, binDir string) (*LocalReinstallPlan, error)

PlanLocalReinstalls discovers package-main candidates under moduleRoot's cmd/ and script/ trees and filters them against binDir.

moduleRoot must contain a parseable go.mod with a module path. Callers resolve binDir (e.g. GOBIN); this function only stats entries there. Discovery and merge rules live in gotool/mod/installplan.

type Method added in v0.0.6

type Method = installplan.Method

Method and Action are string type aliases so harness code can use string(it.Method).

type ModuleEntry added in v0.0.6

type ModuleEntry struct {
	Dir      string // relative to project Path; "." for root
	Path     string // module path from go.mod
	Requires []RequireEntry
	Replaces []ReplaceEntry
}

ModuleEntry describes one go.mod under a project.

type ModuleReinstallPlan added in v0.0.6

type ModuleReinstallPlan struct {
	ModuleRoot  string
	ModulePath  string                // full module path from go.mod
	ModuleName  string                // basename of module path from go.mod
	RelDir      string                // module root relative to scan root ("." or slash path); set by FromWorkDir
	Items       []PlanItem            // sorted lexicographically by BinName
	Diagnostics []ReinstallDiagnostic // per-module; sorted by BinName, then Kind
}

ModuleReinstallPlan is one module's contribution to a multi-module plan.

type MultiLocalReinstallPlan added in v0.0.6

type MultiLocalReinstallPlan struct {
	BinDir  string
	Modules []ModuleReinstallPlan
}

MultiLocalReinstallPlan is the multi-module discovery/filter result for a shared binDir. Modules are ordered lexicographically by absolute ModuleRoot.

func PlanLocalReinstallsFromWorkDir added in v0.0.6

func PlanLocalReinstallsFromWorkDir(workDir, binDir string, useMain bool) (*MultiLocalReinstallPlan, error)

PlanLocalReinstallsFromWorkDir resolves the scan root from workDir, discovers every Go module under that root via mod/scan, and builds a multi-module reinstall plan against binDir.

func PlanLocalReinstallsMulti added in v0.0.6

func PlanLocalReinstallsMulti(moduleRoots []string, binDir string) (*MultiLocalReinstallPlan, error)

PlanLocalReinstallsMulti runs PlanLocalReinstalls for each module root and returns a multi-module plan sorted by absolute ModuleRoot path.

Empty moduleRoots yields an empty Modules list and nil error. After per-module planning, if the same BinName has Action=install from two or more modules, returns a hard error naming the bin and both modules. Skip-only (or install×skip) duplicates across modules are allowed.

type PinLocalsAction added in v0.0.53

type PinLocalsAction struct {
	ConsumerModDir string
	ConsumerPath   string
	DepPath        string
	DepModDir      string
	RelPath        string // ./ or ../ slash form
	Kind           string // add | rewrite | already
}

PinLocalsAction is one planned relative replace for a consumer→dep edge.

type PinLocalsPlan added in v0.0.53

type PinLocalsPlan struct {
	Actions  []PinLocalsAction
	Warnings []string // soft multi-owner etc. (may include warning: prefix)
}

PinLocalsPlan is the pure plan for wrk --pin-locals.

func PlanPinLocals added in v0.0.53

func PlanPinLocals(workDir string) (*PinLocalsPlan, error)

PlanPinLocals builds relative-replace actions from the unwind stack inventory. Inventory = CollectStackInventory only (no WRK_HOME project universe). Wanted set per consumer = require paths ∪ replace OldPaths that have a stack owner.

type PlanItem added in v0.0.6

type PlanItem struct {
	BinName string
	RelPath string // "./cmd/foo" or "./script/foo/install"
	Method  Method // "go-install" | "go-run-install"
	Action  Action // "install" | "skip"
}

PlanItem is one candidate binary to install or skip.

type ProjectEntry added in v0.0.6

type ProjectEntry struct {
	Path    string
	Modules []ModuleEntry
}

ProjectEntry is one existing registered main-repo path and its Go modules.

type ReinstallDiagnostic added in v0.0.8

type ReinstallDiagnostic = installplan.Diagnostic

ReinstallDiagnostic is a non-fatal notice or warning produced while merging cmd/ and script/ candidates for the same BinName.

type ReinstallExecStats added in v0.0.53

type ReinstallExecStats struct {
	Reinstalled int
	Skipped     int
	Failed      int
}

ReinstallExecStats counts execute-path outcomes for --reinstall-local.

type ReplaceEntry added in v0.0.6

type ReplaceEntry struct {
	OldPath    string
	NewPath    string
	NewVersion string
}

ReplaceEntry is a single replace directive from go.mod.

type RequireEntry added in v0.0.6

type RequireEntry struct {
	Path    string
	Version string
}

RequireEntry is a single require directive from go.mod.

type RunOpts added in v0.0.34

type RunOpts struct {
	// Args are CLI args after the program name (same as Run).
	Args []string

	// ScanTestPauseAfterFirstPrint, when > 0, pauses after the first path
	// printed by --scan-git-repos so mid-scan interrupt tests can cancel
	// while the walk is still open. Production leaves this zero.
	//
	// Supporting tests:
	//   - cmd/wrk/tests/scan-git-repos/interrupt/sigint-after-first-path
	//   - (other leaves under scan-git-repos/interrupt/ if added)
	ScanTestPauseAfterFirstPrint time.Duration

	// WithGo is the injectable Go SDK resolver for dep-update versioned tidy.
	// Zero value: production defaults (userHomeDir()/installed, Download:true).
	WithGo withgo.ResolveOptions
}

RunOpts configures an in-process wrk invocation. CLI main uses Run (zero opts).

type StatusPathLists added in v0.0.5

type StatusPathLists struct {
	Primary  []string
	External []string
}

StatusPathLists holds ordered primary vs external status paths for main-repo status display planning.

func PartitionStatusPaths added in v0.0.5

func PartitionStatusPaths(mainRoot string, scanPaths, linkedOrdered []string) StatusPathLists

PartitionStatusPaths partitions status paths for main-repo status display planning. Primary: mainRoot first, then main-owned linked worktrees in linkedOrdered (ListLinked porcelain) order. External: scanPaths that are not primary, sorted by normalized path. Returned paths are storage.NormalizePath'd.

type SyncResult added in v0.0.53

type SyncResult struct {
	IntoMain int
	IntoWT   int
	Skipped  int
}

SyncResult is the outcome of one runSync / runSyncOpts pass.

type WebServeOptions

type WebServeOptions struct {
	WrkHome string
	Port    int
	Dev     bool
}

WebServeOptions configures the local web UI started by `wrk --web`.

Directories

Path Synopsis
Package teapre must be imported before bubbletea so OSC background probes do not hang on PTYs that never answer (tty-watch, some CI harnesses).
Package teapre must be imported before bubbletea so OSC background probes do not hang on PTYs that never answer (tty-watch, some CI harnesses).
Package tui implements the interactive Bubble Tea dashboard for bare `wrk`.
Package tui implements the interactive Bubble Tea dashboard for bare `wrk`.
web
Package web serves the wrk React SPA (wrk-react) and mounts wrkserver.
Package web serves the wrk React SPA (wrk-react) and mounts wrkserver.

Jump to

Keyboard shortcuts

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