sync

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package sync provides git-friendly memory synchronization via compressed chunks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUsername

func GetUsername() string

GetUsername returns the current username for chunk metadata.

Types

type ChunkData

type ChunkData struct {
	Sessions     []*domain.Session     `json:"sessions"`
	Observations []*domain.Observation `json:"observations"`
	Prompts      []*domain.Prompt      `json:"prompts"`
}

ChunkData is the content of a single sync chunk.

type ChunkEntry

type ChunkEntry struct {
	ID        string `json:"id"`
	CreatedBy string `json:"created_by,omitempty"`
	CreatedAt string `json:"created_at,omitempty"`
	Sessions  int    `json:"sessions,omitempty"`
	Memories  int    `json:"memories,omitempty"`
	Prompts   int    `json:"prompts,omitempty"`
}

ChunkEntry describes a single sync chunk in the manifest.

type FileTransport

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

FileTransport implements Transport using the local filesystem. Chunks are stored as gzipped JSONL files in a chunks/ subdirectory.

func NewFileTransport

func NewFileTransport(syncDir string) *FileTransport

NewFileTransport creates a FileTransport rooted at the given sync directory.

func (*FileTransport) ReadChunk

func (ft *FileTransport) ReadChunk(chunkID string) ([]byte, error)

ReadChunk reads and decompresses a gzipped chunk file.

func (*FileTransport) ReadManifest

func (ft *FileTransport) ReadManifest() (*Manifest, error)

ReadManifest reads manifest.json from the sync directory. Returns an empty manifest (Version=1) if the file doesn't exist.

func (*FileTransport) WriteChunk

func (ft *FileTransport) WriteChunk(chunkID string, data []byte, _ ChunkEntry) error

WriteChunk gzips data and writes to chunks/{chunkID}.jsonl.gz.

func (*FileTransport) WriteManifest

func (ft *FileTransport) WriteManifest(m *Manifest) error

WriteManifest writes the manifest to manifest.json with pretty-printing.

type ImportResult

type ImportResult struct {
	ChunksImported       int `json:"chunks_imported"`
	ChunksSkipped        int `json:"chunks_skipped"`
	SessionsImported     int `json:"sessions_imported"`
	ObservationsImported int `json:"observations_imported"`
	PromptsImported      int `json:"prompts_imported"`
}

ImportResult is returned after an import operation.

type Manifest

type Manifest struct {
	Version int          `json:"version"`
	Chunks  []ChunkEntry `json:"chunks,omitempty"`
}

Manifest tracks all sync chunks and their metadata.

type SyncResult

type SyncResult struct {
	ChunkID              string `json:"chunk_id,omitempty"`
	SessionsExported     int    `json:"sessions_exported"`
	ObservationsExported int    `json:"observations_exported"`
	PromptsExported      int    `json:"prompts_exported"`
	IsEmpty              bool   `json:"is_empty"`
}

SyncResult is returned after an export operation.

type SyncStore

type SyncStore interface {
	ExportAll(ctx context.Context) (*sqlitestore.ExportData, error)
	ImportData(ctx context.Context, data *sqlitestore.ExportData) (*sqlitestore.SyncImportResult, error)
	GetSyncedChunks(ctx context.Context) (map[string]bool, error)
	RecordSyncedChunk(ctx context.Context, chunkID string) error
}

SyncStore defines the store methods needed by the Syncer.

type Syncer

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

Syncer handles chunk-based memory synchronization.

func NewSyncer

func NewSyncer(store SyncStore, transport Transport) *Syncer

NewSyncer creates a new Syncer with the given store and transport.

func (*Syncer) Export

func (sy *Syncer) Export(ctx context.Context, createdBy, project string) (*SyncResult, error)

Export creates a new sync chunk from database contents.

func (*Syncer) Import

func (sy *Syncer) Import(ctx context.Context) (*ImportResult, error)

Import reads chunks from the manifest and imports new ones into the database.

func (*Syncer) Status

func (sy *Syncer) Status(ctx context.Context) (local, remote, pending int, err error)

Status returns sync status: local chunks, remote chunks, pending imports.

type Transport

type Transport interface {
	ReadManifest() (*Manifest, error)
	WriteManifest(m *Manifest) error
	WriteChunk(chunkID string, data []byte, entry ChunkEntry) error
	ReadChunk(chunkID string) ([]byte, error)
}

Transport defines the interface for reading/writing sync chunks and manifest.

Jump to

Keyboard shortcuts

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