sync

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeFileHash

func ComputeFileHash(path string) (string, error)

ComputeFileHash returns the SHA-256 hex digest of the file at path.

func ComputeHash

func ComputeHash(r io.Reader) (string, error)

ComputeHash returns the SHA-256 hex digest of data from r.

func FindClaudeSourceFile

func FindClaudeSourceFile(
	projectsDir, sessionID string,
) string

FindClaudeSourceFile finds the original JSONL file for a Claude session ID by searching all project directories.

func FindCodexSourceFile

func FindCodexSourceFile(sessionsDir, sessionID string) string

FindCodexSourceFile finds a Codex session file by UUID. Searches the year/month/day directory structure for files matching rollout-{timestamp}-{uuid}.jsonl.

func FindGeminiSourceFile

func FindGeminiSourceFile(
	geminiDir, sessionID string,
) string

FindGeminiSourceFile locates a Gemini session file by its session UUID. Searches all project hash directories.

Types

type DiscoveredFile

type DiscoveredFile struct {
	Path    string
	Project string           // pre-extracted project name
	Agent   parser.AgentType // AgentClaude or AgentCodex
}

DiscoveredFile holds a discovered session JSONL file.

func DiscoverClaudeProjects

func DiscoverClaudeProjects(projectsDir string) []DiscoveredFile

DiscoverClaudeProjects finds all project directories under the Claude projects dir and returns their JSONL session files.

func DiscoverCodexSessions

func DiscoverCodexSessions(sessionsDir string) []DiscoveredFile

DiscoverCodexSessions finds all JSONL files under the Codex sessions dir (year/month/day structure).

func DiscoverGeminiSessions

func DiscoverGeminiSessions(
	geminiDir string,
) []DiscoveredFile

DiscoverGeminiSessions finds all session JSON files under the Gemini directory (~/.gemini/tmp/*/chats/session-*.json).

type Engine

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

Engine orchestrates session file discovery and sync.

func NewEngine

func NewEngine(
	database *db.DB,
	claudeDir, codexDir, geminiDir, machine string,
) *Engine

NewEngine creates a sync engine.

func (*Engine) FindSourceFile

func (e *Engine) FindSourceFile(sessionID string) string

FindSourceFile locates the original source file for a session ID.

func (*Engine) LastSync

func (e *Engine) LastSync() time.Time

LastSync returns the time of the last completed sync.

func (*Engine) LastSyncStats

func (e *Engine) LastSyncStats() SyncStats

LastSyncStats returns statistics from the last sync.

func (*Engine) SyncAll

func (e *Engine) SyncAll(onProgress ProgressFunc) SyncStats

SyncAll discovers and syncs all session files from all agents.

func (*Engine) SyncPaths added in v0.3.0

func (e *Engine) SyncPaths(paths []string)

SyncPaths syncs only the specified changed file paths instead of discovering and hashing all session files. Paths that don't match known session file patterns are silently ignored.

func (*Engine) SyncSingleSession

func (e *Engine) SyncSingleSession(sessionID string) error

SyncSingleSession re-syncs a single session by its ID. Unlike the bulk SyncAll path, this includes exec-originated Codex sessions and uses the existing DB project as fallback.

type Phase

type Phase string

Phase describes the current sync phase.

const (
	PhaseIdle        Phase = "idle"
	PhaseDiscovering Phase = "discovering"
	PhaseSyncing     Phase = "syncing"
	PhaseDone        Phase = "done"
)

type Progress

type Progress struct {
	Phase           Phase  `json:"phase"`
	CurrentProject  string `json:"current_project,omitempty"`
	ProjectsTotal   int    `json:"projects_total"`
	ProjectsDone    int    `json:"projects_done"`
	SessionsTotal   int    `json:"sessions_total"`
	SessionsDone    int    `json:"sessions_done"`
	MessagesIndexed int    `json:"messages_indexed"`
}

Progress reports sync progress to listeners.

func (Progress) Percent

func (p Progress) Percent() float64

Percent returns the sync progress as a percentage (0–100).

type ProgressFunc

type ProgressFunc func(Progress)

ProgressFunc is called with progress updates during sync.

type SyncResult

type SyncResult struct {
	SessionID string `json:"session_id"`
	Project   string `json:"project"`
	Skipped   bool   `json:"skipped"`
	Messages  int    `json:"messages"`
}

SyncResult describes the outcome of syncing a single session.

type SyncStats

type SyncStats struct {
	TotalSessions int `json:"total_sessions"`
	Synced        int `json:"synced"`
	Skipped       int `json:"skipped"`
}

SyncStats summarizes a full sync run.

func (*SyncStats) RecordSkip

func (s *SyncStats) RecordSkip()

RecordSkip increments the skipped session counter.

func (*SyncStats) RecordSynced

func (s *SyncStats) RecordSynced(n int)

RecordSynced adds n to the synced session counter.

type Watcher

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

Watcher uses fsnotify to watch session directories for changes and triggers a callback with debouncing.

func NewWatcher

func NewWatcher(
	debounce time.Duration, onChange func(paths []string),
) (*Watcher, error)

NewWatcher creates a file watcher that calls onChange when files are modified after the debounce period elapses.

func (*Watcher) Start

func (w *Watcher) Start()

Start begins processing file events in a goroutine.

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop stops the watcher and waits for it to finish.

func (*Watcher) WatchRecursive

func (w *Watcher) WatchRecursive(root string) (int, error)

WatchRecursive walks a directory tree and adds all subdirectories to the watch list. Returns the number of directories added.

Jump to

Keyboard shortcuts

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