Documentation
¶
Overview ¶
Package syncer uploads spooled events to the server: it resolves local project/session hints to server IDs, uploads in batches, deletes events only after the server ACKs them, and backs off exponentially while the server is unreachable.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBackoff = errors.New("in backoff after a failed sync")
ErrBackoff means the previous attempt failed and the retry delay has not elapsed. Use force to retry immediately.
var ErrLocked = errors.New("another sync is running")
ErrLocked means another sync is already running.
var ErrNotConnected = errors.New("device not connected (run 'memspace client connect <server-url>')")
ErrNotConnected means `memspace client connect` has not been run.
Functions ¶
func SaveCredentials ¶
func SaveCredentials(path string, c *Credentials) error
SaveCredentials writes the credentials file with owner-only permissions.
func ShouldTrigger ¶
ShouldTrigger reports whether a hook should start a background sync: not when one is already running, and not while backing off after a failure.
Types ¶
type Credentials ¶
type Credentials struct {
ServerURL string `json:"server_url"`
DeviceID string `json:"device_id"`
DeviceName string `json:"device_name"`
Token string `json:"token"`
ConnectedAt time.Time `json:"connected_at"`
// MCPToken is the device's read-only token for the MCP endpoint, handed
// to agents at runtime (never written into their configuration).
MCPToken string `json:"mcp_token,omitempty"`
}
Credentials identify this device to the server. Written by `memspace client connect`, mode 0600.
func LoadCredentials ¶
func LoadCredentials(path string) (*Credentials, error)
LoadCredentials reads the credentials file.
type Importer ¶
type Importer interface {
Name() string
Import(ctx context.Context, sp *spool.Spool, heartbeat func()) (int, error)
}
Importer pulls events from an agent's own records (e.g. Codex rollout files) into the spool. heartbeat must be called periodically during long imports to keep the sync lock alive.
type State ¶
type State struct {
ConsecutiveFailures int `json:"consecutive_failures"`
NextAttemptAt time.Time `json:"next_attempt_at"`
LastAttemptAt time.Time `json:"last_attempt_at"`
LastSuccessAt time.Time `json:"last_success_at"`
LastError string `json:"last_error,omitempty"`
TotalUploaded int64 `json:"total_uploaded"`
TotalDuplicates int64 `json:"total_duplicates"`
TotalRejected int64 `json:"total_rejected"`
}
State is the persisted outcome of recent sync attempts, used for exponential backoff and for `memspace client status`.
type Syncer ¶
type Syncer struct {
Cfg config.ClientConfig
Spool *spool.Spool
Creds *Credentials
Client *client.Client
Importers []Importer
Log io.Writer
// AfterSync, when set, runs after a sync that reached the server, with
// the server's version ("" from servers that do not report it); the
// client upgrades itself there. It runs outside the sync lock.
AfterSync func(ctx context.Context, serverVersion string)
// UpgradeStatus, when set, returns a failed automatic upgrade (target
// version and error) to report to the server.
UpgradeStatus func() (target, err string)
// contains filtered or unexported fields
}
Syncer runs one device's upload loop.
func New ¶
func New(cfg config.ClientConfig, sp *spool.Spool, creds *Credentials, importers ...Importer) *Syncer
New builds a Syncer from config and saved credentials.