sync

package
v1.801.455 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package sync is data sync: link two endpoints and keep them in step, on a webhook, on a schedule, or on demand.

A Sync (/v1/sync) names the two endpoints and the engine reconciles them. Git (GitHub/GitLab ⇆ native Hanzo Git) is the one provider registered today; another kind is another Provider, with nothing in the engine to change.

Shape (decomplected):

  • store.go ONE table, syncs — the sync intent + engine cursor state.
  • engine.go the ONE place a sync happens: resolve → loop-guard → cursor dedupe → provider.Apply → chain (hop-bounded). Kind-agnostic.
  • provider.go the engine↔provider contract (Plan/Apply per kind) + registry.
  • git_provider.go the git provider, composing the existing git object-plane seams.
  • sync_api.go /v1/sync CRUD + /v1/sync/:id/run (manual).

Triggers (GitHub App webhook, Hanzo Git push webhook) resolve to Syncs and call cloud.Sync — they never sync directly, so the engine is the single seam.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Mount

func Mount(app cloud.Router, deps cloud.Deps) error

Mount wires /v1/sync, registers the git provider, and installs the reconcile func as the cloud.SyncFunc so triggers (cloud.Sync) reach it.

func Shutdown

func Shutdown() error

Shutdown stops the reconcile scheduler (waiting for an in-flight sweep to drain) and then closes every open per-org store — in THAT order, so a store is never closed out from under a running reconcile. Idempotent.

Types

type Endpoint

type Endpoint struct {
	Connector string `json:"connector,omitempty"`
	Provider  string `json:"provider"`
	Locator   string `json:"locator"`
}

Endpoint is one side of a sync. Connector is an OPTIONAL connectorruntime connector id (a connected platform); when set the engine can resolve the transport from the connector registry. Provider is the concrete integration ("github"|"gitlab"|"hanzo-git"); Locator is provider-specific (a clone URL, or a native repo name). Provider+Locator is always sufficient; a Connector is a convenience over raw URLs where a connection already exists.

type Event

type Event struct {
	Provider string // endpoint the event came from: "github" | "gitlab" | "hanzo-git"
	Org      string
	Locator  string // source repo locator (clone URL or "<org>/<repo>")
	Repo     string // short repo name (git)
	Ref      string // FULL ref: refs/heads/<branch> or refs/tags/<tag>
	Before   string
	After    string // cursor position value (git: the tip SHA)
	Actor    string // who made the upstream change (loop guard compares to Sync.Actor)
	Token    string // OPTIONAL pre-minted credential (never logged)
	Manual   bool   // manual /run or initial reconcile (no specific position)
	Hop      int
}

Event is the provider-agnostic trigger the engine hands a provider. Branch/After are the generic cursor position (git: branch + tip SHA); other kinds map them to their own partition + version token.

type Provider

type Provider interface {
	Kind() string
	Reconcile(ctx context.Context, sy Sync, ev Event) (changed bool, err error)
}

Provider reconciles one Sync's endpoints toward agreement for a kind. ONE method — Reconcile converges (drives source→target, or ensures the mirror, per the Sync's direction) and returns whether it CHANGED the target, so the engine advances the cursor and fires the chain. Stateless: every call carries the full Sync + event, so one registered value serves every org.

type Sync

type Sync struct {
	ID        string
	Org       string
	Kind      string // "git" now; "storage" | "db" | ... later
	Source    Endpoint
	Target    Endpoint
	Direction string // both | pull | push | off
	Trigger   string // webhook | poll | manual
	Cursor    string // engine state: JSON map[position]fingerprint (git: branch→sha)
	Actor     string // the identity a reconcile writes AS — the loop-guard identity
	CreatedAt int64
	UpdatedAt int64 // bumped on every reconcile — the last-synced time
}

Sync is one org's sync intent + engine cursor.

Jump to

Keyboard shortcuts

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