wtsetup

package
v0.167.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package wtsetup makes a new worktree ready to run (ADR-050): it copies the git-ignored files the repository's .worktreeinclude names from the main checkout into the new worktree, and runs the project's setup command in the agent's own terminal before the agent starts.

.worktreeinclude has Claude Code's semantics: gitignore patterns at the repository root, and a file is copied only when it matches one AND git ignores it — tracked files are already in the worktree, and an untracked file nobody ignores is work in progress, not configuration.

Index

Constants

View Source
const (
	MaxFiles = 5000
	MaxBytes = 256 << 20
)

Limits on one copy. A .worktreeinclude is for .env files and local configuration; a pattern that sweeps up a dependency tree stops here rather than filling the disk or holding up the agent's start.

View Source
const (
	EnvCommand = "CAPROCK_SETUP_COMMAND"
	EnvTimeout = "CAPROCK_SETUP_TIMEOUT"
	EnvNote    = "CAPROCK_SETUP_NOTE"
)

The wrapper's inputs travel in the environment rather than on its command line, so the script needs no quoting and does not sit in the process list; both are removed before the agent starts.

View Source
const DefaultTimeout = 10 * time.Minute

DefaultTimeout bounds a setup command: long enough for a cold `npm install` on a slow network, short enough that a hung one does not keep the agent from starting all afternoon. Ctrl+C skips it sooner.

View Source
const IncludeFile = ".worktreeinclude"

IncludeFile is the file at the repository root that names what to copy.

View Source
const Marker = "\x1b]777;caprock-setup-done\x07"

Marker is written to the terminal once setup is over and the agent is about to start: an OSC sequence a terminal ignores, which tells the daemon that what is drawn next is the agent's own screen (a first message must not be typed into the setup).

View Source
const MaxCommand = 4 << 10

MaxCommand caps a project's setup command: a line or a short script.

View Source
const Subcommand = "worktree-setup"

Subcommand is the hidden `caprock` subcommand that runs Main.

Variables

This section is empty.

Functions

func Main

func Main(args []string, stdout io.Writer) int

Main is `caprock worktree-setup -- <agent> <args…>`: run the setup command named in the environment, say how it went, then become the agent. It is what a session's terminal runs first when its fresh worktree has a setup command (agents.Spawn). Never started by a person.

Types

type Copied

type Copied struct {
	// Files and Bytes were copied.
	Files int
	Bytes int64
	// Names are the first few copied paths, slash-separated, for a log line.
	Names []string
	// Skipped counts files left alone: already in the worktree, a symlink
	// pointing outside the repository, or not a regular file.
	Skipped int
	// OverLimit is true when MaxFiles or MaxBytes stopped the copy early.
	OverLimit bool
}

Copied reports what CopyIncluded did.

func CopyIncluded

func CopyIncluded(ctx context.Context, src, dst string) (Copied, error)

CopyIncluded copies into dst every file under src that src's .worktreeinclude names and git ignores. src is the checkout the worktree was made from (its top level); dst is the new worktree.

It never writes outside dst, never overwrites a file that is already there, and copies a symlink only when it is relative and points inside src. No .worktreeinclude is not an error: nothing is copied.

func (Copied) Summary

func (c Copied) Summary() string

Summary is Copied as one line, empty when nothing happened.

type Outcome

type Outcome struct {
	Took        time.Duration
	Err         error // the command failed, or could not start
	TimedOut    bool
	Interrupted bool // Ctrl+C
}

Outcome is how a setup run ended.

func Run

func Run(script, dir string, timeout time.Duration, out io.Writer, interrupt <-chan os.Signal) Outcome

Run runs script in dir through the system shell with output to out and no input, and stops it — the whole process tree — at timeout or when interrupt fires.

func (Outcome) Line

func (o Outcome) Line(timeout time.Duration) string

Line is the outcome as the one line the terminal shows.

Jump to

Keyboard shortcuts

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