Documentation
¶
Overview ¶
Package treepad cuts git worktrees from Go code. Unlike the tp CLI, a caller names the repository it means rather than standing in it, so one process can serve several repositories concurrently.
A worktree cut here is indistinguishable from one cut by tp new: config sync runs and lifecycle hooks fire. It diverges from the CLI in two ways, both because nobody is watching a library call:
- A hook configured interactive = true is refused with ErrInteractiveHook before anything is written. The CLI hands such a hook the terminal; a library caller has no terminal to hand over.
- RemoveOptions.Force deletes a branch git considers unmerged, but never a worktree with uncommitted changes — Remove returns ErrDirty instead, where tp remove --force would wipe it.
A failed post hook is the one error that leaves the operation done. New and Remove wrap ErrPostHook once the worktree is already cut or already gone, and New returns its fully populated Worktree alongside it. A caller reconciling desired state should report it rather than retry: a second New fails on the branch the first one created, and a second Remove returns ErrNotFound.
Calls are serialised per repository, since two concurrent git worktree adds contend on the same index and ref locks. That lock is held in this process only. Two processes against one repository — or tp run by hand next to a library caller — are not serialised, and need coordinating elsewhere.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDirty = errors.New("worktree has uncommitted changes")
ErrDirty reports uncommitted changes in the target worktree. Nothing has been touched. Force does not override it — destroying uncommitted work is a decision for a human who can see it.
var ErrInteractiveHook = errors.New("interactive hooks are not supported by the library API")
ErrInteractiveHook reports that the repository configures a hook with interactive = true for an event the requested operation fires. Nothing has been written. An interactive hook wants a human at a terminal, which a library caller cannot promise.
var ErrNotFound = errors.New("worktree not found")
ErrNotFound reports that no worktree is checked out on the named branch. Remove is idempotent against it: a second call on the same branch returns it.
var ErrPostHook = errors.New("post hook failed")
ErrPostHook reports that a post hook failed. The cut itself succeeded: the returned Worktree is complete and on disk.
Functions ¶
Types ¶
type NewOptions ¶
type NewOptions struct {
Branch string
Base string
// RepoDir is an absolute path inside the target repository.
RepoDir string
// OutputDir is where the editor artifact is written. Empty means
// $HOME/<repo-slug>-workspaces, matching the CLI.
OutputDir string
// Stderr receives the same narrative the CLI prints. Nil discards it.
Stderr io.Writer
}
NewOptions parameterises New. Branch and RepoDir are required.
type RemoveOptions ¶
type RemoveOptions struct {
Branch string
// RepoDir is an absolute path inside the target repository.
RepoDir string
// OutputDir is where the editor artifact was written. It must match the
// OutputDir the worktree was cut with, or the artifact is left behind.
OutputDir string
// Force deletes a branch git considers unmerged — what a squash merge
// leaves. It never overrides the dirty-worktree refusal.
Force bool
// Stderr receives the same narrative the CLI prints. Nil discards it.
Stderr io.Writer
}
RemoveOptions parameterises Remove. Branch and RepoDir are required.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package batch resolves Manifests into scheduling Members: the Chains and Ticket-to-branch derivation that no fleet tool has an equivalent for.
|
Package batch resolves Manifests into scheduling Members: the Chains and Ticket-to-branch derivation that no fleet tool has an equivalent for. |
|
cmd
|
|
|
tp
command
|
|
|
e2e
|
|
|
internal
|
|
|
artifact
Package artifact renders per-worktree files from config-supplied templates.
|
Package artifact renders per-worktree files from config-supplied templates. |
|
config
Package config loads optional per-repo configuration from .treepad.toml.
|
Package config loads optional per-repo configuration from .treepad.toml. |
|
exec
Package exec detects project task runners and enumerates their scripts.
|
Package exec detects project task runners and enumerates their scripts. |
|
gh
Package gh is the entire gh CLI surface for Batch orchestration (ADR 0003): `gh auth status`, via Available; `gh pr list`, via PRList; and `gh stack link`, via StackLink.
|
Package gh is the entire gh CLI surface for Batch orchestration (ADR 0003): `gh auth status`, via Available; `gh pr list`, via PRList; and `gh stack link`, via StackLink. |
|
hook
Package hook runs lifecycle hooks defined in .treepad.toml.
|
Package hook runs lifecycle hooks defined in .treepad.toml. |
|
launcher
Package launcher starts one agent in one worktree and never supervises it again.
|
Package launcher starts one agent in one worktree and never supervises it again. |
|
passthrough
Package passthrough executes a command in a target directory with stdio inherited from the calling process.
|
Package passthrough executes a command in a target directory with stdio inherited from the calling process. |
|
profile
Package profile provides lightweight wall-time stage profiling.
|
Package profile provides lightweight wall-time stage profiling. |
|
sync
Package sync copies files matching gitignore-style patterns between directories.
|
Package sync copies files matching gitignore-style patterns between directories. |
|
treepad/cdshell
Package cdshell owns the __TREEPAD_CD__ shell-bridge protocol.
|
Package cdshell owns the __TREEPAD_CD__ shell-bridge protocol. |
|
treepad/lifecycle
Package lifecycle owns the worktree creation, removal, and pruning verbs.
|
Package lifecycle owns the worktree creation, removal, and pruning verbs. |
|
treepad/repo
Package repo resolves the repository context shared by every treepad verb: the worktree list, the main worktree, the repo slug, and the artifact output directory.
|
Package repo resolves the repository context shared by every treepad verb: the worktree list, the main worktree, the repo slug, and the artifact output directory. |
|
treepad/treepadtest
Package treepadtest provides shared test helpers for packages that depend on treepad sub-package dependencies.
|
Package treepadtest provides shared test helpers for packages that depend on treepad sub-package dependencies. |
|
tty
Package tty provides access to the process's controlling terminal.
|
Package tty provides access to the process's controlling terminal. |
|
ui
Package ui provides a structured, tag-prefixed printer for user-facing stderr output.
|
Package ui provides a structured, tag-prefixed printer for user-facing stderr output. |
|
worktree/worktreetest
Package worktreetest provides shared test helpers for packages that depend on worktree.CommandRunner.
|
Package worktreetest provides shared test helpers for packages that depend on worktree.CommandRunner. |
|
Package skills embeds the agent skills treepad ships, so `tp skill install` can copy them onto disk without a separate download step.
|
Package skills embeds the agent skills treepad ships, so `tp skill install` can copy them onto disk without a separate download step. |