engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 22 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 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

View Source
var ErrBlocked = errors.New("plan has unresolved blockers")

ErrBlocked means the plan has unresolved blockers.

Functions

func Human

func Human(n int64) string

Human formats a byte count for display.

func LocalOS

func LocalOS() string

LocalOS is this machine's GOOS.

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 Moved

type Moved struct {
	From string `json:"from"`
	To   string `json:"to"`
}

Moved records a file moved out of the way.

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.

func BuildPlan

func BuildPlan(ctx context.Context, src Source, tgt Target, in Input, opt Options) (*Plan, error)

BuildPlan works out a transport without changing anything.

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.

func Apply

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

Apply performs the plan. On failure nothing is committed into Claude's folders.

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
)

Jump to

Keyboard shortcuts

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