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 ¶
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.
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.
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.
const IncludeFile = ".worktreeinclude"
IncludeFile is the file at the repository root that names what to copy.
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).
const MaxCommand = 4 << 10
MaxCommand caps a project's setup command: a line or a short script.
const Subcommand = "worktree-setup"
Subcommand is the hidden `caprock` subcommand that runs Main.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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.
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.