backup

package
v0.1.421 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package backup packs what the user set up in magpie into one file, sealed with a passphrase, to carry to another machine: the providers (their keys too, unless left out), the pictures picked for them, the settings, the profiles, every agent's model and the library (the instructions, MCP servers and skills magpie gives the agents). Subscriptions are not in it: each is the sign-in of an agent on this machine, so each machine signs in on its own.

The file is JSON: a header naming how it is sealed, and the bundle encrypted with AES-256-GCM under a key derived from the passphrase with PBKDF2-SHA256. Nothing in it can be read without the passphrase.

Index

Constants

View Source
const Ext = ".magpie-backup"

Ext is the extension backups are saved with.

Variables

All is every part.

View Source
var ErrPassphrase = errors.New("wrong passphrase, or the file was changed")

ErrPassphrase is a passphrase that does not open the backup.

Functions

func Seal

func Seal(b Bundle, pass string) ([]byte, error)

Seal encrypts the bundle under the passphrase.

func Secret added in v0.1.182

func Secret(name string) bool

Secret reports whether a header or an environment variable by that name looks like it holds a key: what a backup without keys leaves empty.

Types

type Bundle

type Bundle struct {
	Version   int                        `json:"version"`
	Created   time.Time                  `json:"created"`
	App       string                     `json:"app,omitempty"` // the magpie that made it
	Keys      bool                       `json:"keys"`          // whether the providers carry their keys
	Providers []provider.Provider        `json:"providers"`
	Icons     map[string][]byte          `json:"icons,omitempty"`  // pictures picked for providers, by file name
	Groups    []provider.Group           `json:"groups,omitempty"` // the user's model groups
	Settings  *settings.Settings         `json:"settings,omitempty"`
	Profiles  map[string]profile.Profile `json:"profiles,omitempty"`
	Agents    map[string]string          `json:"agents,omitempty"`  // every agent's fields as they are now
	Library   *library.Bundle            `json:"library,omitempty"` // nil from a magpie before it, or with none
}

Bundle is what a backup holds.

func Collect

func Collect(keys bool, app string) (Bundle, error)

Collect gathers the bundle; without keys, providers carry none, nor any header that looks like one, and the library's servers no environment variable or header that looks like one (their names stay).

func Open

func Open(data []byte, pass string) (Bundle, error)

Open decrypts a backup.

type Parts

type Parts struct {
	Providers, Settings, Profiles, Agents, Library bool
}

Parts picks what a restore puts back.

type Result

type Result struct {
	Added, Replaced int      // providers
	NeedKey         []string // providers that came without a key and have none here
	Settings        bool
	Profiles        int
	Agents          int               // agent fields changed
	Skipped         []string          // agent fields left alone: the agent is not on this machine, or the value failed
	Library         bool              // the library was put in
	LibraryProblems []library.Problem `json:",omitempty"` // what of it couldn't be given to an agent
}

Result says what a restore did.

func Restore

func Restore(b Bundle, parts Parts) (Result, error)

Restore puts the chosen parts of the bundle in. Providers come first, so the agents' models that go through them resolve. Only agents on this machine are set.

Jump to

Keyboard shortcuts

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