sync

package
v0.7.19 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package sync implements the repo sync poller (Loop 1 in the P2 design): periodically HEAD-check each connected repo, shallow-clone on SHA change, parse cronfoundry.yaml + referenced SKILL.md files, upsert skill + schedule rows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadManifest

func LoadManifest(repoRoot string) (*config.Manifest, map[string]*config.Skill, error)

LoadManifest reads and validates a checked-out repo's cronfoundry.yaml, then parses each SKILL.md it references. Returns (manifest, skillsByPath) or an error on any step.

Security: each skill path from the manifest is resolved to an absolute path and verified to stay inside repoRoot. A malicious cronfoundry.yaml that claims `path: ../../etc/passwd` is rejected before we touch the filesystem outside the clone dir.

func UpsertSkillsAndSchedules

func UpsertSkillsAndSchedules(
	ctx context.Context,
	pool *pgxpool.Pool,
	orgID, repoID pgtype.UUID,
	manifest *config.Manifest,
	skills map[string]*config.Skill,
	sha string,
) error

UpsertSkillsAndSchedules reconciles the parsed manifest + skill frontmatters against the DB:

  • skills present in the manifest are upserted (keyed on repo_id+path)
  • skills absent from the manifest are deleted (cascades to their schedules)
  • for each manifest skill, schedules absent from the manifest are soft-disabled (enabled=false) to preserve run history; schedules present are upserted and marked enabled.

All DB work happens in a single transaction.

Types

type Poller

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

Poller orchestrates repo-sync passes. P2c will add a Run() loop that schedules SyncOne against all due repo_connection rows on a ticker.

func NewPoller

func NewPoller(cfg PollerConfig) *Poller

NewPoller constructs a Poller with sensible defaults.

func (*Poller) SyncOne

func (p *Poller) SyncOne(ctx context.Context, connID pgtype.UUID) error

SyncOne runs a single sync pass for the named repo_connection.

Flow:

  1. Load the repo_connection row.
  2. Fetch an installation token.
  3. HEAD-check the default branch via the GitHub API.
  4. If the SHA matches last_synced_head_sha, touch last_synced_at and return.
  5. Otherwise shallow-clone the repo at the new SHA into a tempdir.
  6. Parse cronfoundry.yaml + SKILL.md files.
  7. Upsert skill + schedule rows.
  8. Mark the repo_connection as synced at the new SHA.

Errors at any step are recorded in last_sync_error and surfaced to the caller; the row's last_synced_at is still advanced so a broken repo doesn't back up the queue.

type PollerConfig

type PollerConfig struct {
	Pool          *pgxpool.Pool
	OrgID         pgtype.UUID
	Installations *github.InstallationCache
	GitHubBaseURL string                          // default: "https://api.github.com"
	HTTPClient    *http.Client                    // default: http.DefaultClient
	CloneURLFor   func(owner, name string) string // default: x-access-token HTTPS
}

PollerConfig bundles the poller's collaborators. Only Pool, OrgID, and Installations are required; the rest have sensible defaults.

OrgID is retained for the P2c scheduler loop — it'll be used to list the connections belonging to this org ("list connections for this org" queries). It is NOT used for per-row upserts in SyncOne; each repo_connection row carries its own OrgID and is the source of truth for downstream skill/schedule writes to prevent cross-tenant writes if someone ever hands SyncOne a connID from a different org.

Jump to

Keyboard shortcuts

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