store

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentHash

func ContentHash(data []byte) string

ContentHash computes the SHA-256 hash of plaintext content.

func FormatSize

func FormatSize(bytes int64) string

FormatSize formats a byte count as a human-readable string.

func MatchGlob

func MatchGlob(path, pattern string) bool

MatchGlob matches a path against a glob pattern with ** support. It splits both path and pattern into segments and matches segment-by-segment.

func ResolveMergeStrategy

func ResolveMergeStrategy(relPath string, strategies map[string]string) string

ResolveMergeStrategy finds the merge strategy for a file based on glob patterns.

func ResolveMergeStrategyWithPattern

func ResolveMergeStrategyWithPattern(relPath string, strategies map[string]string) (strategy string, pattern string)

ResolveMergeStrategyWithPattern returns both the strategy and the pattern that matched. An empty pattern means a built-in default was used. When multiple glob patterns match, the most specific wins (most segments, fewest wildcards). This ensures deterministic resolution regardless of Go map iteration order.

func Rotate

func Rotate(cfg *config.Config, oldIdentity age.Identity, newRecipient age.Recipient, verbose bool, progress ProgressFunc) (int, error)

Rotate re-encrypts all sealed objects with a new key.

Types

type DiffResult

type DiffResult struct {
	Added    []string // files in new but not old
	Modified []string // files in both but with different hashes
	Deleted  []string // files in old but not new
}

DiffResult describes the differences between two manifests.

func Status

func Status(cfg *config.Config) (*DiffResult, error)

Status returns the diff between the current claude directory and the seal manifest.

func UnsealStatus

func UnsealStatus(cfg *config.Config) (*DiffResult, error)

UnsealStatus returns what Unseal would do without actually writing anything. "Added" = files in manifest but missing on disk (would be restored). "Modified" = files on disk with different content than manifest (would be overwritten). "Deleted" = managed files on disk but not in manifest (would be deleted).

type FileEntry

type FileEntry struct {
	ContentHash   string `json:"content_hash"`
	SizePlaintext int64  `json:"size_plaintext"`
	SizeEncrypted int64  `json:"size_encrypted"`
	Mtime         string `json:"mtime"`
	MergeStrategy string `json:"merge_strategy"`
	// For JSONL files, track line count for efficient dedup merge
	JSONLLineCount int `json:"jsonl_line_count,omitempty"`
	// Whether a session file is complete (immutable)
	SessionComplete bool `json:"session_complete,omitempty"`
}

FileEntry describes a single file in the seal store.

type Manifest

type Manifest struct {
	Version  int                  `json:"version"`
	DeviceID string               `json:"device_id"`
	SealedAt string               `json:"sealed_at"`
	Files    map[string]FileEntry `json:"files"`
}

Manifest tracks all files in the seal store with their content hashes and metadata.

func LoadManifest

func LoadManifest(sealDir string) (*Manifest, error)

Load reads a manifest from disk.

func NewManifest

func NewManifest(deviceID string) *Manifest

NewManifest creates an empty manifest for the given device.

func (*Manifest) Diff

func (m *Manifest) Diff(other *Manifest) DiffResult

Diff compares this manifest against another and returns the differences.

func (*Manifest) Save

func (m *Manifest) Save(sealDir string) error

Save writes the manifest to disk.

type ObjectStore

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

ObjectStore manages content-addressed encrypted blobs. Files are stored as objects/<hash[0:2]>/<hash[2:]>.age

func NewObjectStore

func NewObjectStore(sealDir string) *ObjectStore

NewObjectStore creates an ObjectStore rooted at the given directory.

func (*ObjectStore) Delete

func (s *ObjectStore) Delete(hash string) error

Delete removes an object by its content hash.

func (*ObjectStore) Exists

func (s *ObjectStore) Exists(hash string) bool

Exists checks if an object with the given hash exists.

func (*ObjectStore) Init

func (s *ObjectStore) Init() error

Init creates the objects directory.

func (*ObjectStore) ListAll

func (s *ObjectStore) ListAll() ([]string, error)

ListAll returns all content hashes of objects on disk.

func (*ObjectStore) ObjectPath

func (s *ObjectStore) ObjectPath(hash string) string

ObjectPath returns the filesystem path for a given content hash.

func (*ObjectStore) Read

func (s *ObjectStore) Read(hash string) ([]byte, error)

Read returns the encrypted data for a given content hash.

func (*ObjectStore) Write

func (s *ObjectStore) Write(hash string, encrypted []byte) error

Write stores encrypted data at the content-addressed path.

type ProgressFunc

type ProgressFunc func(current, total int, path string)

ProgressFunc is called during long operations to report progress.

type RepairResult

type RepairResult struct {
	TotalManifest  int
	TotalOnDisk    int
	MissingObjects []string // manifest entries with no .age file
	CorruptObjects []string // objects that fail decrypt or hash mismatch
	OrphanObjects  []string // .age files not in manifest
	Fixed          int
}

RepairResult describes the outcome of a seal store integrity check.

func Repair

func Repair(cfg *config.Config, identity age.Identity, deleteOrphans bool, verbose bool) (*RepairResult, error)

Repair fixes seal store integrity issues.

func Verify

func Verify(cfg *config.Config, identity age.Identity, verbose bool) (*RepairResult, error)

Verify checks seal store integrity without modifying anything.

type ScanResult

type ScanResult struct {
	// RelPath is the path relative to the claude directory.
	RelPath string
	// AbsPath is the absolute filesystem path.
	AbsPath string
	// Size in bytes.
	Size int64
	// ModTime as Unix timestamp (milliseconds).
	ModTimeMs int64
}

ScanResult represents a file found during scanning.

func ScanFiles

func ScanFiles(claudeDir string, includes, excludes []string) ([]ScanResult, error)

ScanFiles walks the claude directory and returns files matching include patterns but not matching exclude patterns.

type SealStats

type SealStats struct {
	Scanned   int
	Added     int
	Modified  int
	Deleted   int
	Unchanged int
	Errors    int
}

SealStats tracks what happened during a seal operation.

func Seal

func Seal(cfg *config.Config, recipient age.Recipient, verbose bool, progress ProgressFunc) (SealStats, error)

Seal encrypts changed files from claudeDir into the seal store.

func (SealStats) HasChanges

func (s SealStats) HasChanges() bool

HasChanges returns true if the seal produced any modifications worth committing.

func (SealStats) String

func (s SealStats) String() string

type UnsealStats

type UnsealStats struct {
	Total     int
	Restored  int
	Unchanged int
	Deleted   int
	Errors    int
}

UnsealStats tracks what happened during an unseal operation.

func Unseal

func Unseal(cfg *config.Config, identity age.Identity, verbose bool, progress ProgressFunc) (UnsealStats, error)

Unseal decrypts seal contents back to claudeDir and removes managed files not in the manifest. The manifest is the source of truth.

func (UnsealStats) String

func (s UnsealStats) String() string

Jump to

Keyboard shortcuts

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