move

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 23 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 move moves a session between locations with the same agent: plan (pure decisions, nothing written) and apply (stage, rewrite, verify, install with a journal, record lineage, mark the copy left behind). Every agent-specific step is the module's.

Index

Constants

View Source
const (
	RelationNew      = "new"      // no copy there yet: a new session
	RelationAppend   = "append"   // the copy there is as it was left: add the new work to it
	RelationSame     = "same"     // nothing new on either side
	RelationBehind   = "behind"   // only the copy there changed
	RelationDiverged = "diverged" // both changed
)

Relations between a session and its copy in the other agent.

View Source
const (
	ViaImport  = "import"
	ViaHopsesh = "hopsesh"
)

Via choices: the target agent's own importer, or hopsesh's conversion even when the configuration prefers the importer.

View Source
const (
	ConflictReplace  = "replace"
	ConflictKeepBoth = "keep-both"
)

Conflict choices when the copy here changed too.

View Source
const (
	MarkNow         = "now"          // right after the move
	MarkWhenStopped = "when-stopped" // the copy left behind is still open: on a later scan
	MarkOff         = "off"
)

Mark states.

View Source
const (
	KindMove     = "move"     // the same agent, another place
	KindContinue = "continue" // another agent
)

Kinds of plans.

View Source
const (
	RepoUse        = "use"         // an existing checkout here
	RepoClone      = "clone"       // clone it
	RepoNeedsClone = "needs-clone" // not here and cloning was not asked for
	RepoDir        = "dir"         // the folder the user chose
	RepoNone       = "none"        // not a git repository: the same path
)

Repository actions.

Variables

View Source
var ErrBlocked = errors.New("the move cannot go ahead")

ErrBlocked means the plan has blockers.

Functions

func DescribeSync

func DescribeSync(r repos.SyncResult, branch, source string) string

DescribeSync turns a sync result into a line for people.

func Human

func Human(n int64) string

Human formats a byte count.

Types

type ContinuePlan

type ContinuePlan struct {
	From     string           `json:"from"` // source agent name
	Fidelity convert.Fidelity `json:"fidelity"`
	Relation string           `json:"relation"`
	AppendTo *agent.Summary   `json:"appendTo,omitempty"`
	Report   convert.Report   `json:"report"`
	Briefing string           `json:"briefing"`
	Via      string           `json:"via,omitempty"` // ViaImport: the target agent's importer converts it
	// contains filtered or unexported fields
}

ContinuePlan is how a session continues in another agent.

type Copy

type Copy struct {
	Summary agent.Summary
	Live    agent.LiveInfo
	Lineage *lineage.Manifest
}

Copy is a copy of the session already at the target.

type Endpoint

type Endpoint struct {
	Location string `json:"location"`
	OS       string `json:"os"`
	CWD      string `json:"cwd"`
	Path     string `json:"path,omitempty"`
	Version  string `json:"agentVersion,omitempty"`
}

Endpoint describes one end for people and JSON.

type Env

type Env struct {
	StateDir string
	Audit    *audit.Log
	Progress func(step string)
}

Env is where apply keeps its state and logs.

type Input

type Input struct {
	Source  Side
	Session agent.Summary
	Live    agent.LiveInfo
	Git     *repos.GitState // the session's checkout on the source (nil when unknown)
	GitErr  string          // why the checkout could not be read ("" when it was)
	Lineage *lineage.Manifest
	Target  Side
	// Copies are the target agent's sessions with the same key at the target.
	Copies []Copy
	// Worktrees are agent-managed worktree folders (from every module).
	Worktrees []string
	// Push pushes the session's branch on the source machine; GitFetch reaches the
	// source's repository over SSH. Both are nil when the source is this machine.
	Push     func(ctx context.Context, dir string) (string, error)
	GitFetch func(dir string) *repos.FetchSource
	// Native is the source's own agent on the target, for a continuation on another
	// machine: the session is also kept there byte for byte (nil: it is not installed).
	Native *NativeSide
}

Input is what planning needs.

type NativeCopy

type NativeCopy struct {
	Agent    string           `json:"agent"` // its name
	Key      agent.SessionKey `json:"key"`
	Replaces bool             `json:"replaces,omitempty"` // an older copy there makes way
}

NativeCopy is the source agent's own copy kept next to a continuation, so a later return to that agent there adds only the new work to the original turns.

type NativeSide

type NativeSide struct {
	Target Side
	Copies []Copy
}

NativeSide is the source agent on the target and its copies of the session there.

type Options

type Options struct {
	TargetDir     string // resume here (skips repository matching)
	Clone         bool   // clone the repository when it is not here
	ReposDir      string
	ExtraRoots    []string // more folders to look for checkouts in
	GHQLayout     bool
	Worktree      WorktreeMode
	Fork          bool // keep the source session running (both continue)
	RemoteControl bool
	Notify        bool // tell the old session it moved on
	Redact        bool
	App           bool // open in the agent's desktop app
	Mark          bool // mark the copy left behind
	SyncCode      bool // bring the checkout to the session's commit
	Push          bool // push unpushed commits on the source first
	StopLocal     bool // quit a copy of this session that is open here
	Conflict      string
	OtherAccount  bool // the target is signed in to another account (set by the planner)
	// Continuing in another agent.
	Fidelity convert.Fidelity // history (default) or note
	Native   bool             // render exact tool calls as the target's own (when it can)
	Note     string           // a handoff note the source agent wrote
	// CarryRules adds the user's global instructions for the source agent to the briefing.
	CarryRules bool
	// Via is how another agent gets the session: "" (hopsesh converts it) or ViaImport (the
	// target agent's own importer converts it; hopsesh adds its briefing).
	Via string
	Go  bool // start the continued session with "Continue."
}

Options are the user's choices.

type Plan

type Plan struct {
	Kind      string           `json:"kind"`
	Key       agent.SessionKey `json:"key"`
	Title     string           `json:"title"`
	Agent     string           `json:"agent"` // display name
	Source    Endpoint         `json:"source"`
	Target    Endpoint         `json:"target"`
	Live      bool             `json:"live"`
	Repo      RepoPlan         `json:"repo"`
	Placement agent.Placement  `json:"placement"`
	Files     agent.MovePlan   `json:"files"`
	Bytes     int64            `json:"bytes"`
	// SetAside are copies at the target that make way (kept by the journal for undo).
	SetAside []agent.Summary `json:"setAside,omitempty"`
	Conflict string          `json:"conflict,omitempty"`
	Warnings []string        `json:"warnings,omitempty"`
	Blockers []string        `json:"blockers,omitempty"`
	Mark     string          `json:"mark"`
	StopHere bool            `json:"stopHere,omitempty"` // quit the copy open here first
	Push     bool            `json:"push,omitempty"`
	Sync     string          `json:"sync,omitempty"`
	// SyncFromSource: unpushed commits are fetched straight from the source machine.
	SyncFromSource bool          `json:"syncFromSource,omitempty"`
	NewName        string        `json:"newName"`
	Resume         agent.Command `json:"resume"`
	StartPrompt    string        `json:"-"`
	Options        Options       `json:"options"`
	OldName        string        `json:"oldName,omitempty"`
	Continue       *ContinuePlan `json:"continue,omitempty"`
	NativeCopy     *NativeCopy   `json:"nativeCopy,omitempty"`
	// contains filtered or unexported fields
}

Plan is a move, worked out without changing anything.

func Build

func Build(ctx context.Context, in Input, opt Options) (*Plan, error)

Build works out a move. It reads (the bundle's file list, the target's copies) but writes nothing.

type RepoPlan

type RepoPlan struct {
	Identity     string   `json:"identity,omitempty"`
	Remote       string   `json:"remote,omitempty"`
	SourceTop    string   `json:"sourceTop,omitempty"`
	SourceMain   string   `json:"sourceMain,omitempty"`
	SourceBranch string   `json:"sourceBranch,omitempty"`
	MainBranch   string   `json:"sourceMainBranch,omitempty"`
	InWorktree   bool     `json:"sourceInWorktree,omitempty"`
	AgentWT      bool     `json:"sourceAgentWorktree,omitempty"`
	Unpushed     int      `json:"unpushed,omitempty"`
	Dirty        int      `json:"dirty,omitempty"`
	Action       string   `json:"action"`
	LocalPath    string   `json:"localPath,omitempty"`
	Alternatives []string `json:"alternatives,omitempty"`
	LocalBranch  string   `json:"localBranch,omitempty"`
	Worktree     string   `json:"worktree,omitempty"` // to create
	SourceHead   string   `json:"sourceHead,omitempty"`
	HasUpstream  bool     `json:"sourceUpstream,omitempty"`
}

RepoPlan is how the session's repository is found or made here.

type Result

type Result struct {
	Journal    string            `json:"journal"` // id for undo
	Files      int               `json:"files"`
	Bytes      int64             `json:"bytes"`
	Rewrite    rewrite.Stats     `json:"rewrite"`
	Secrets    scan.Summary      `json:"secrets"`
	Cloned     bool              `json:"cloned,omitempty"`
	Worktree   string            `json:"worktree,omitempty"`
	SetAside   []string          `json:"setAside,omitempty"`
	Stopped    bool              `json:"stopped,omitempty"`
	Pushed     string            `json:"pushed,omitempty"`
	PushError  string            `json:"pushError,omitempty"`
	Sync       *repos.SyncResult `json:"sync,omitempty"`
	SyncNote   string            `json:"syncNote,omitempty"`
	Mark       string            `json:"mark"` // done | pending | off | failed
	MarkError  string            `json:"markError,omitempty"`
	PromptFile string            `json:"promptFile,omitempty"`
	Command    string            `json:"command"` // to resume, for this machine's shell
	Notice     string            `json:"notice,omitempty"`
	Warnings   []string          `json:"warnings,omitempty"`
	// Owed is a mark the source still needs once its open copy ends, when the source is a
	// snapshot: its sender keeps it (on other sources hopsesh keeps it here).
	Owed *lineage.Pending `json:"owed,omitempty"`
}

Result is what a move did.

func Apply

func Apply(ctx context.Context, p *Plan, in Input, env Env) (*Result, error)

Apply carries out a plan.

type Side

type Side struct {
	Machine *host.Machine
	Module  agent.Module
	Install agent.Install
	Account *agent.Account // nil when unknown
}

Side is one end of a move: a machine, the agent module and its install there.

type WorktreeMode

type WorktreeMode string

WorktreeMode chooses between the main checkout and a worktree.

const (
	WorktreeAuto   WorktreeMode = "auto"   // recreate the worktree if the session used one
	WorktreeCreate WorktreeMode = "create" // always work in a worktree on the session's branch
	WorktreeMain   WorktreeMode = "main"   // use the main checkout as it is
)

Jump to

Keyboard shortcuts

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