relocate

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 9 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 relocate moves a whole project to another machine: the repository (cloned there from its origin, or a project there that has it), every task worktree with its commits and uncommitted work, every branch holding commits its origin hasn't (given a worktree here first, so it travels the same way), and the agents — each continued there with its conversation, then closed here.

It is what the TUI's project move does, made a library so the CLI (`conch project move`) and Conch.app, through the CLI, do the same: a Plan first, read from both servers and changing nothing, then Run, which reports each step as it goes. One worktree failing doesn't stop the others; what stayed here, and why, is in the Result.

Index

Constants

This section is empty.

Variables

View Source
var ErrNothing = errors.New("nothing would move")

ErrNothing is a project with nothing to move: no task worktree, no branch of its own and no agent.

Functions

func BranchesToMove

func BranchesToMove(proj *proto.ProjectInfo) []proto.BranchInfo

BranchesToMove is proj's branches with no worktree that hold commits the origin hasn't: local only, gone upstream, or ahead of it. The base branch stays: the clone there has its own.

func CheckedOut

func CheckedOut(proj *proto.ProjectInfo, branch string) bool

CheckedOut says whether branch has a worktree in proj.

func CloneFolder

func CloneFolder(path, home string) string

CloneFolder is where a clone goes on the other machine: where the project is here, relative to the home folder (~/workspace/daos), or ~/name when it is outside it.

func ContinueAgents

func ContinueAgents(from, to *client.Client, agents []proto.PaneInfo, here, dir, fromLabel string, cols, rows int) (started []proto.PaneInfo, closed, failed []string)

ContinueAgents starts each agent's conversation in dir on to — the same agent, or one afresh when it saved none — and closes its pane on from once that worked. here is the folder the agents worked in on from.

func Count

func Count(n int, one, many string) string

Count is n said with the noun that fits it: 1 agent continues, 2 agents continue — what a person reads, rather than agent(s).

func ErrText

func ErrText(err error) string

ErrText is an error for a status line: a server's own message without its code.

func HandOver

func HandOver(ctx context.Context, from, to *client.Client, s proto.SessionInfo, dir, fromLabel, agent string, cols, rows int) (proto.PaneInfo, error)

HandOver gives session s to agent in dir on to.

func InMainCheckout

func InMainCheckout(proj *proto.ProjectInfo, p proto.PaneInfo) bool

InMainCheckout says whether agent p works in proj's main checkout rather than a worktree: an agent in a worktree that is not moving stays with it.

func NormalRemote

func NormalRemote(u string) string

NormalRemote is a remote URL as host/path, without .git.

func ProjectWorktrees

func ProjectWorktrees(proj *proto.ProjectInfo) []proto.WorktreeInfo

ProjectWorktrees is the task worktrees of proj: checked out on a branch that isn't the base.

func RemoteName

func RemoteName(u string) string

RemoteName is a remote URL's repository, for labels: owner/name.

func SameRemote

func SameRemote(a, b string) bool

SameRemote says whether two remote URLs name the same repository, however they are written: git@host:a/b.git, ssh://git@host/a/b, https://host/a/b.

func Tildify

func Tildify(path, home string) string

Tildify writes path with ~ for home, when it is inside it.

Types

type Event

type Event struct {
	Kind   string `json:"kind"`  // clone, branch, worktree, agents, done
	Name   string `json:"name"`  // the branch, or what is cloned
	State  string `json:"state"` // start, ok, fail
	Detail string `json:"detail,omitempty"`
	Step   int    `json:"step"`
	Steps  int    `json:"steps"`
}

Event is a step of a run, said as it starts and as it ends.

type Options

type Options struct {
	Cols, Rows int
}

Options are the size new panes there start at.

type Plan

type Plan struct {
	ProjectID string `json:"project_id"`
	Name      string `json:"name"`
	Path      string `json:"path"` // the main checkout, here
	Remote    string `json:"remote,omitempty"`
	From      string `json:"from"` // labels, for what is said
	To        string `json:"to"`

	// Target is the project there that has the same origin; when there
	// is none, CloneTo is where the origin is cloned there first.
	Target     string `json:"target,omitempty"`
	TargetName string `json:"target_name,omitempty"`
	TargetPath string `json:"target_path,omitempty"`
	CloneTo    string `json:"clone_to,omitempty"`
	// Bundle is a project with no origin: its repository — every branch
	// and tag — is carried there and made a project at CloneTo, rather
	// than cloned. Its branches go with it, so Branches is empty.
	Bundle bool `json:"bundle,omitempty"`

	Worktrees []Worktree `json:"worktrees,omitempty"`
	// Branches have no worktree and hold commits the origin hasn't (local
	// only, gone upstream, or ahead of it): each is given a worktree here,
	// then moves like the others.
	Branches []proto.BranchInfo `json:"branches,omitempty"`
	// MainAgents work in the main checkout: they continue in the project's
	// own checkout there.
	MainAgents []proto.PaneInfo `json:"main_agents,omitempty"`

	// What stays here: worktrees that can't move (and why), the main
	// checkout's uncommitted files, terminals.
	Skipped []string `json:"skipped,omitempty"`
	// Already is the branches the project there has checked out already,
	// with no agent left to follow them: nothing to do.
	Already   []string `json:"already,omitempty"`
	MainDirty int      `json:"main_dirty,omitempty"`
	Terminals int      `json:"terminals,omitempty"`
}

Plan is what a move would do, read from both machines; nothing changes until Run.

func NewPlan

func NewPlan(ctx context.Context, from, to *client.Client, projectID, fromLabel, toLabel, into string) (Plan, error)

NewPlan reads what moving projectID from from to to would do. into, when given, is where to clone it there instead of the folder it has here (relative to the home folder).

func (Plan) Agents

func (p Plan) Agents() []proto.PaneInfo

Agents is every agent the plan continues there.

func (Plan) Empty

func (p Plan) Empty() bool

Empty says whether there is nothing to move. A project carried as a bundle is never empty: the repository is what moves.

func (Plan) Steps

func (p Plan) Steps() int

Steps is how many steps a run of p reports.

type Result

type Result struct {
	Target     string           `json:"target"`
	TargetPath string           `json:"target_path"`
	Moved      []string         `json:"moved,omitempty"`
	Started    []proto.PaneInfo `json:"started,omitempty"`
	Failed     []string         `json:"failed,omitempty"`
}

Result is what a run did: the branches that arrived, the agents that continue there, and what stayed here, with why.

func Run

func Run(ctx context.Context, p Plan, from, to *client.Client, opt Options, emit func(Event)) (Result, error)

Run moves p from from to to, saying each step to emit (which may be nil). An error is returned only when nothing could move at all — the clone failed; a worktree that fails is in Result.Failed and the rest go on.

type Worktree

type Worktree struct {
	Branch string                 `json:"branch"`
	Path   string                 `json:"path"`
	Info   proto.WorktreeMoveInfo `json:"info"`
	Agents []proto.PaneInfo       `json:"agents,omitempty"`
	// There is the worktree the project there already has on this branch —
	// an earlier move's. Nothing is copied over it; its agents continue in
	// it.
	There string `json:"there,omitempty"`
}

Worktree is one checkout that moves, with the agents working in it.

Jump to

Keyboard shortcuts

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