agents

package
v0.12.59 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionTarName = "agent-session.tar.gz"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArchiveReader

type ArchiveReader interface {
	// ReadManifest reads manifest.json from the archive.
	ReadManifest(path string) (*SessionManifest, error)
	// ExtractSubtree extracts the requested archive subtree into dst.
	ExtractSubtree(path, archivePath, dst string) error
	// Contains reports whether the requested archive subtree exists.
	Contains(path, archivePath string) (bool, error)
}

ArchiveReader reads and extracts uploaded agent session archives.

Implementations must reject unsafe archive entries because session archives are downloaded before being restored into user-controlled directories.

type ArchiveStore

type ArchiveStore interface {
	// Download fetches an archive and stores it under a temporary provider path.
	Download(ctx context.Context, url, runID string, provider console.AgentRuntimeType) (*DownloadedArchive, error)
	// Finalize moves the archive under the provider directory recorded by the manifest.
	Finalize(download *DownloadedArchive, runID string, provider console.AgentRuntimeType) (*DownloadedArchive, error)
}

ArchiveStore downloads and finalizes uploaded agent session archives.

type ClaudeRestorer

type ClaudeRestorer struct {
	// contains filtered or unexported fields
}

ClaudeRestorer restores Claude CLI session state and launches Claude resume.

func (*ClaudeRestorer) Prepare

func (*ClaudeRestorer) Provider

func (r *ClaudeRestorer) Provider() console.AgentRuntimeType

func (*ClaudeRestorer) Resume

func (r *ClaudeRestorer) Resume(ctx context.Context, prepared *PreparedSession) error

type CodexRestorer

type CodexRestorer struct {
	// contains filtered or unexported fields
}

CodexRestorer restores Codex session state and launches codex resume.

func (*CodexRestorer) Prepare

func (*CodexRestorer) Provider

func (r *CodexRestorer) Provider() console.AgentRuntimeType

func (*CodexRestorer) Resume

func (r *CodexRestorer) Resume(ctx context.Context, prepared *PreparedSession) error

type Command

type Command interface {
	// Run executes command with inherited stdio.
	Run(ctx context.Context, command string, args ...string) error
	// Output executes command and returns trimmed combined output.
	Output(ctx context.Context, command string, args ...string) (string, error)
}

Command runs external executables from a configured working directory.

Restorers use this boundary to invoke provider CLIs while tests can replace it with narrower fakes.

func Executable

func Executable(execDir string, env ...string) Command

Executable returns a Command backed by os/exec.

type Confirmer

type Confirmer interface {
	// Confirm asks a yes/no question and returns the selected value.
	Confirm(message string, def bool) (bool, error)
}

Confirmer abstracts yes/no prompts used while preparing a local resume.

type DirectoryPrompter

type DirectoryPrompter interface {
	// Directory asks the user for an existing directory path.
	Directory(message, def string) (string, error)
}

DirectoryPrompter abstracts directory selection with validation and completion.

type DownloadedArchive

type DownloadedArchive struct {
	// Path is the local archive file path.
	Path string
	// WorkDir is the directory containing the archive and temporary restore data.
	WorkDir string
}

DownloadedArchive describes a session archive stored on disk.

type GeminiRestorer

type GeminiRestorer struct {
	// contains filtered or unexported fields
}

GeminiRestorer restores Gemini CLI session state and launches gemini resume.

func (*GeminiRestorer) Prepare

func (*GeminiRestorer) Provider

func (r *GeminiRestorer) Provider() console.AgentRuntimeType

func (*GeminiRestorer) Resume

func (r *GeminiRestorer) Resume(ctx context.Context, session *PreparedSession) error

type GitRepository

type GitRepository struct {
	// contains filtered or unexported fields
}

GitRepository implements Repository operations using the local git executable.

func NewGitRepository

func NewGitRepository(httpClient *http.Client, confirmer Confirmer) *GitRepository

NewGitRepository returns a git-backed repository preparer.

func (*GitRepository) Prepare

func (p *GitRepository) Prepare(ctx context.Context, run *console.AgentRunMinimalFragment, bundle *SessionBundle, repoPath string) (string, error)

Prepare checks out a PR ref when present, or creates a local branch from the base branch and applies the uploaded patch when a PR has not been created.

func (*GitRepository) Validate

func (p *GitRepository) Validate(repoPath string, manifest *SessionManifest) error

Validate ensures the selected directory is the expected repository and, when a branch is specified, that the checkout is on that branch.

func (*GitRepository) ValidateRepository

func (p *GitRepository) ValidateRepository(repoPath string, manifest *SessionManifest) error

ValidateRepository ensures the selected directory is the expected repository.

type HTTPArchiveStore

type HTTPArchiveStore struct {
	// contains filtered or unexported fields
}

HTTPArchiveStore downloads session archives over HTTP into the Plural cache.

func NewHTTPArchiveStore

func NewHTTPArchiveStore(client *http.Client) *HTTPArchiveStore

NewHTTPArchiveStore returns an archive store using the supplied HTTP client.

func (*HTTPArchiveStore) Download

func (s *HTTPArchiveStore) Download(ctx context.Context, url, runID string, provider console.AgentRuntimeType) (*DownloadedArchive, error)

func (*HTTPArchiveStore) Finalize

func (s *HTTPArchiveStore) Finalize(download *DownloadedArchive, runID string, provider console.AgentRuntimeType) (*DownloadedArchive, error)

type Interaction

type Interaction interface {
	Confirmer
	Selector
	DirectoryPrompter
}

Interaction groups all user prompts needed by agent session restoration.

This interface keeps restore and repository logic independent from the concrete terminal UI implementation. The current implementation uses survey, but callers should depend on this interface so the prompts can move to a Bubble Tea model later without rewriting the restore flow.

type MapRestorerRegistry

type MapRestorerRegistry struct {
	// contains filtered or unexported fields
}

MapRestorerRegistry is an in-memory provider-to-restorer registry.

func NewDefaultRestorerRegistry

func NewDefaultRestorerRegistry(archive ArchiveReader) *MapRestorerRegistry

NewDefaultRestorerRegistry returns the built-in restorers supported by the CLI.

func NewRestorerRegistry

func NewRestorerRegistry(restorers ...SessionRestorer) *MapRestorerRegistry

NewRestorerRegistry registers the supplied provider restorers.

func (*MapRestorerRegistry) ForProvider

type OpencodeRestorer

type OpencodeRestorer struct {
	// contains filtered or unexported fields
}

OpencodeRestorer imports and resumes Opencode session state.

func (*OpencodeRestorer) Prepare

func (*OpencodeRestorer) Provider

func (*OpencodeRestorer) Resume

func (r *OpencodeRestorer) Resume(ctx context.Context, prepared *PreparedSession) error

type OverwritePrompt

type OverwritePrompt func(path string) (bool, error)

OverwritePrompt decides whether an existing local provider session file can be replaced during restore.

type PreparedSession

type PreparedSession struct {
	// RepoPath is the local repository where the provider resume command runs.
	RepoPath string
	// WorkDir is the local directory containing restored provider files.
	WorkDir string
	// SessionID is the provider-specific session identifier to resume.
	SessionID string
}

PreparedSession is the local provider session after archive extraction and before invoking the provider's resume command.

type Repository

type Repository interface {
	// Prepare checks out or creates the branch that should be used for resume.
	Prepare(ctx context.Context, run *console.AgentRunMinimalFragment, bundle *SessionBundle, repoPath string) (string, error)
	// ValidateRepository verifies the local repository origin matches the session manifest.
	ValidateRepository(repoPath string, manifest *SessionManifest) error
	// Validate verifies the local repository matches the session manifest.
	Validate(repoPath string, manifest *SessionManifest) error
}

Repository prepares and validates the user's local clone before session resume.

type RestoreOptions

type RestoreOptions struct {
	// RepoPath is the selected local repository checkout.
	RepoPath string
	// ArchivePath is the local path to the downloaded session archive.
	ArchivePath string
	// WorkDir is the local directory used for extracted restore data.
	WorkDir string
	// Manifest is the validated session manifest from the archive.
	Manifest *SessionManifest
	// Interaction prompts before overwriting existing provider session data.
	Interaction Confirmer
	// ConfirmOverwrite overrides overwrite prompting for tests and custom flows.
	ConfirmOverwrite OverwritePrompt
}

RestoreOptions are the inputs a provider restorer needs to recreate local session state from an uploaded archive.

type RestorerRegistry

type RestorerRegistry interface {
	// ForProvider returns the restorer registered for provider.
	ForProvider(provider console.AgentRuntimeType) (SessionRestorer, error)
}

RestorerRegistry resolves the provider-specific restorer for a session.

type Selector

type Selector interface {
	// Select asks the user to choose one option from the supplied list.
	Select(message string, options []string) (string, error)
}

Selector abstracts single-choice prompts.

type SessionBundle

type SessionBundle struct {
	// Run is the minimal console run metadata needed for local resume.
	Run *console.AgentRunMinimalFragment
	// Manifest is the validated manifest read from the session archive.
	Manifest *SessionManifest
	// ArchivePath is the local path to the finalized session archive.
	ArchivePath string
	// WorkDir is the local working directory used while restoring the session.
	WorkDir string
}

SessionBundle contains a downloaded agent session archive and the console run metadata needed to restore it into a local checkout.

type SessionManifest

type SessionManifest struct {
	// Version is the manifest schema version.
	Version int `json:"version"`
	// AgentRunID is the console agent run that produced the archive.
	AgentRunID string `json:"agentRunId"`
	// Provider identifies the runtime whose local state is stored in the archive.
	Provider console.AgentRuntimeType `json:"provider"`
	// Repository is the git remote URL expected for the local checkout.
	Repository string `json:"repository"`
	// Branch is the expected local branch after repository preparation.
	Branch string `json:"branch,omitempty"`
	// Session describes where provider-specific session state is stored.
	Session SessionMetadata `json:"session"`
}

SessionManifest is the metadata embedded in an uploaded agent session archive.

func (*SessionManifest) UnmarshalJSON

func (m *SessionManifest) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts provider values from older archives while normalizing them to the generated console enum representation.

func (*SessionManifest) Validate

Validate checks that the archive manifest is compatible with the selected run and safe to extract.

type SessionMetadata

type SessionMetadata struct {
	// ID is the provider-specific session identifier used by resume commands.
	ID string `json:"id,omitempty"`
	// Path is the original provider session path recorded by the runtime.
	Path string `json:"path,omitempty"`
	// ArchivePath is the subtree in the archive containing session files.
	ArchivePath string `json:"archivePath,omitempty"`
}

SessionMetadata identifies the provider session data inside the archive.

type SessionRestorer

type SessionRestorer interface {
	// Provider returns the console runtime type this restorer supports.
	Provider() console.AgentRuntimeType
	// Prepare restores provider state from the archive into local files.
	Prepare(ctx context.Context, opts RestoreOptions) (*PreparedSession, error)
	// Resume launches the provider-specific resume command.
	Resume(ctx context.Context, prepared *PreparedSession) error
}

SessionRestorer restores and resumes sessions for one agent runtime provider.

type SessionService

type SessionService struct {
	// contains filtered or unexported fields
}

SessionService coordinates download, repository preparation, validation, and provider-specific session restoration.

func NewSessionService

func NewSessionService(options ...SessionServiceOption) *SessionService

NewSessionService builds a service with production defaults unless overridden.

func (*SessionService) Download

Download fetches the run's uploaded session archive and validates its manifest.

func (*SessionService) RestoreAndResume

func (s *SessionService) RestoreAndResume(ctx context.Context, bundle *SessionBundle, repoPath string) error

RestoreAndResume prepares the local repository, restores provider state, and launches the provider-specific resume command.

type SessionServiceOption

type SessionServiceOption func(*SessionService)

SessionServiceOption customizes SessionService dependencies for tests and alternate UI/storage implementations.

func WithSessionInteraction

func WithSessionInteraction(interaction Confirmer) SessionServiceOption

WithSessionInteraction sets the prompt implementation used by session restore.

func WithSessionRepository

func WithSessionRepository(repository Repository) SessionServiceOption

WithSessionRepository sets the repository preparer used before restoration.

type SurveyInteraction

type SurveyInteraction struct{}

SurveyInteraction implements Interaction using github.com/AlecAivazis/survey.

func NewSurveyInteraction

func NewSurveyInteraction() *SurveyInteraction

NewSurveyInteraction returns the default prompt implementation for CLI use.

func (SurveyInteraction) Confirm

func (SurveyInteraction) Confirm(message string, def bool) (bool, error)

func (SurveyInteraction) Directory

func (s SurveyInteraction) Directory(message, def string) (string, error)

func (SurveyInteraction) Select

func (SurveyInteraction) Select(message string, options []string) (string, error)

type TarGzipArchiveReader

type TarGzipArchiveReader struct{}

TarGzipArchiveReader reads the tar.gz session archive format uploaded by agent runtimes.

func (TarGzipArchiveReader) Contains

func (in TarGzipArchiveReader) Contains(path, archivePath string) (bool, error)

func (TarGzipArchiveReader) ExtractSubtree

func (in TarGzipArchiveReader) ExtractSubtree(path, archivePath, dst string) error

func (TarGzipArchiveReader) ReadManifest

func (in TarGzipArchiveReader) ReadManifest(path string) (*SessionManifest, error)

Jump to

Keyboard shortcuts

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