Documentation
¶
Overview ¶
Package engine plans and performs a session transport: it decides where a session goes on this machine, which files move, how paths map, what to do about the repository and worktrees, and then stages, rewrites, verifies and commits the copy with an undo record.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBlocked = errors.New("plan has unresolved blockers")
ErrBlocked means the plan has unresolved blockers.
Functions ¶
Types ¶
type Env ¶
type Env struct {
StateDir string // staging/ and undo/ live here
Log *audit.Log
// Progress, if set, receives one line per step.
Progress func(step string)
}
Env is where Apply keeps its working state.
type FileItem ¶
type FileItem struct {
Src string `json:"src"` // path on the source filesystem
Rel string `json:"rel"` // path relative to the target project dir
Kind string `json:"kind"` // transcript | subagent | tool-result | sidecar | file-history | memory
Size int64 `json:"size"`
Rewrite string `json:"rewrite"` // jsonl | text | none
}
FileItem is one file to copy.
type Input ¶
type Input struct {
Summary *sessions.Summary
Git *repos.GitState // source git state of the session's directory (nil if unknown)
Live *sessions.LiveEntry
}
Input bundles what BuildPlan needs about the session.
type Options ¶
type Options struct {
TargetDir string // explicit local directory to resume in (skips repo matching)
ReposDir string
GHQLayout bool
Clone bool // clone the repository if it is not found locally
Worktree WorktreeMode
Fork bool // keep the source session running (fork) instead of handing off
RemoteCtl bool
NotifyOld bool
Redact bool
DropThinking bool // the target uses a different Anthropic account
CopyMemory bool // merge the project's auto-memory folder
ExtraRoots []string
}
Options are the user's choices for one transport.
type Plan ¶
type Plan struct {
SessionID string `json:"sessionId"`
Title string `json:"title"`
SourceHost string `json:"sourceHost"`
SourceOS string `json:"sourceOs"`
SourceFile string `json:"sourceFile"`
SourceCWD string `json:"sourceCwd"`
SourceVersion string `json:"sourceVersion,omitempty"`
Live bool `json:"live"`
OldName string `json:"oldName,omitempty"`
Repo RepoPlan `json:"repo"`
TargetCWD string `json:"targetCwd"`
TargetDir string `json:"targetProjectDir"`
TargetFile string `json:"targetFile"`
Mappings []rewrite.Mapping `json:"mappings"`
Files []FileItem `json:"files"`
TotalBytes int64 `json:"totalBytes"`
Duplicates []string `json:"duplicates,omitempty"` // existing copies to set aside
Warnings []string `json:"warnings,omitempty"`
Blockers []string `json:"blockers,omitempty"` // must be resolved before Apply
Options Options `json:"options"`
NewName string `json:"newName"`
Resume link.Resume `json:"resume"`
StartContext link.Context `json:"-"`
}
Plan is everything a transport will do. Front-ends render it before Apply.
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"` // branch checked out in the source's main folder
InWorktree bool `json:"sourceInWorktree,omitempty"`
ClaudeWT bool `json:"sourceClaudeWorktree,omitempty"`
Action string `json:"action"` // use | clone | needs-clone | dir | none
LocalPath string `json:"localPath,omitempty"`
Alternatives []string `json:"alternatives,omitempty"`
LocalBranch string `json:"localBranch,omitempty"` // branch currently checked out locally
Worktree string `json:"worktree,omitempty"` // worktree to create
Unpushed int `json:"unpushed"`
Dirty int `json:"dirty"`
}
RepoPlan is what happens to the repository on this machine.
type Result ¶
type Result struct {
TargetFile string `json:"targetFile"`
UndoID string `json:"undoId"`
Rewrite rewrite.Stats `json:"rewrite"`
Secrets scan.Summary `json:"secrets"`
Copied int `json:"filesCopied"`
Bytes int64 `json:"bytesCopied"`
Cloned bool `json:"cloned"`
Worktree string `json:"worktreeCreated,omitempty"`
SetAside []string `json:"setAside,omitempty"`
}
Result reports a completed transport.
type Source ¶
type Source struct {
Host string
OS string // darwin | linux | windows
FS fsys.FS
ConfigDir string
Home string
Auth *link.Auth // the login there, when it could be read
}
Source is the machine a session is copied from (possibly this machine).
type Target ¶
type Target struct {
Host string
OS string
ConfigDir string
Home string
// ClaudeVersion is `claude --version` here, if known ("" = not installed or unknown).
ClaudeVersion string
ClaudePath string // the claude binary here, if found
Auth *link.Auth // the login here, when it could be read
}
Target is this machine.
type UndoManifest ¶
type UndoManifest struct {
ID string `json:"id"`
SessionID string `json:"sessionId"`
SourceHost string `json:"sourceHost"`
Time time.Time `json:"time"`
TargetFile string `json:"targetFile"`
Created []string `json:"created"`
SetAside []Moved `json:"setAside"`
Undone bool `json:"undone"`
}
UndoManifest is the journal of one transport.
func ListUndo ¶
func ListUndo(stateDir string) ([]UndoManifest, error)
ListUndo returns transports that can be undone, newest first.
func Undo ¶
func Undo(stateDir, match string, log *audit.Log) (*UndoManifest, error)
Undo reverses the newest transport of a session (match by session id prefix or undo id). Files created by the transport are removed and anything set aside is restored. Clones and worktrees are left in place (they may hold your work); the result says so.
type WorktreeMode ¶
type WorktreeMode string
WorktreeMode says how to handle a session that ran in a git worktree (or on a branch the local checkout is not on).
const ( WorktreeAuto WorktreeMode = "auto" // recreate the worktree if the session used one WorktreeCreate WorktreeMode = "create" // always use a worktree on the session's branch WorktreeMain WorktreeMode = "main" // use the main checkout as it is )