globaldb

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WorkspaceFilesystemStatePresent means the workspace root exists on disk.
	WorkspaceFilesystemStatePresent = "present"
	// WorkspaceFilesystemStateMissing means the registry row is retained only
	// because durable catalog data still exists in global.db.
	WorkspaceFilesystemStateMissing = "missing"
)

Variables

View Source
var (
	// ErrWorkflowArchived reports an archive request against an archived workflow identity.
	ErrWorkflowArchived = errors.New("globaldb: workflow archived")
	// ErrWorkflowHasActiveRuns reports archive conflicts caused by active runs.
	ErrWorkflowHasActiveRuns = errors.New("globaldb: workflow has active runs")
	// ErrWorkflowNotArchivable reports archive conflicts caused by incomplete synced state.
	ErrWorkflowNotArchivable = errors.New("globaldb: workflow not archivable")
)
View Source
var (
	// ErrWorkspaceNotFound reports missing workspace registrations.
	ErrWorkspaceNotFound = errors.New("globaldb: workspace not found")
	// ErrWorkflowNotFound reports missing workflow rows.
	ErrWorkflowNotFound = errors.New("globaldb: workflow not found")
	// ErrRunNotFound reports missing run rows.
	ErrRunNotFound = errors.New("globaldb: run not found")
	// ErrWorkspaceHasActiveRuns reports unregister conflicts.
	ErrWorkspaceHasActiveRuns = errors.New("globaldb: workspace has active runs")
	// ErrWorkflowSlugConflict reports an active workflow slug collision.
	ErrWorkflowSlugConflict = errors.New("globaldb: workflow slug conflict")
	// ErrRunAlreadyExists reports a duplicate run identifier.
	ErrRunAlreadyExists = errors.New("globaldb: run already exists")
)
View Source
var ErrReviewRoundNotFound = errors.New("globaldb: review round not found")

ErrReviewRoundNotFound reports a missing review round.

View Source
var ErrSchemaTooNew = errors.New("globaldb: schema too new")

ErrSchemaTooNew reports that a database carries a migration newer than this binary understands.

View Source
var ErrTaskItemNotFound = errors.New("globaldb: task item not found")

ErrTaskItemNotFound reports a missing synced task-item projection row.

View Source
var ErrWorkflowSyncInvalid = errors.New("globaldb: workflow sync invalid")

Functions

This section is empty.

Types

type ActiveRunsError

type ActiveRunsError struct {
	WorkspaceID string
	ActiveRuns  int
}

ActiveRunsError reports how many active runs blocked a workspace unregister.

func (ActiveRunsError) Error

func (e ActiveRunsError) Error() string

func (ActiveRunsError) Is

func (e ActiveRunsError) Is(target error) bool

type ArtifactSnapshotInput

type ArtifactSnapshotInput struct {
	ArtifactKind    string
	RelativePath    string
	Checksum        string
	FrontmatterJSON string
	BodyText        string
	SourceMTime     time.Time
}

ArtifactSnapshotInput describes one authored workflow artifact snapshot that should be mirrored into global.db.

type ArtifactSnapshotRow

type ArtifactSnapshotRow struct {
	WorkflowID      string
	ArtifactKind    string
	RelativePath    string
	Checksum        string
	FrontmatterJSON string
	BodyText        string
	BodyStorageKind string
	SourceMTime     time.Time
	SyncedAt        time.Time
}

ArtifactSnapshotRow captures one durable authored-artifact snapshot row.

type GlobalDB

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

GlobalDB owns the durable home-scoped catalog used by the daemon.

func Open

func Open(ctx context.Context, path string) (*GlobalDB, error)

Open opens or creates the daemon global catalog at path and applies migrations.

func (*GlobalDB) Close

func (g *GlobalDB) Close() error

Close releases the underlying SQLite handle.

func (*GlobalDB) CloseContext

func (g *GlobalDB) CloseContext(ctx context.Context) error

CloseContext checkpoints the SQLite WAL and closes the underlying handle.

func (*GlobalDB) CountActiveRuns

func (g *GlobalDB) CountActiveRuns(ctx context.Context) (int, error)

CountActiveRuns returns the number of non-terminal runs across all workspaces.

func (*GlobalDB) CountWorkspaces

func (g *GlobalDB) CountWorkspaces(ctx context.Context) (int, error)

CountWorkspaces returns the number of registered workspaces.

func (*GlobalDB) DeleteRun

func (g *GlobalDB) DeleteRun(ctx context.Context, runID string) error

DeleteRun removes one durable run index row.

func (*GlobalDB) DeleteRuns

func (g *GlobalDB) DeleteRuns(ctx context.Context, runIDs []string) error

DeleteRuns removes multiple durable run index rows in one transaction.

func (*GlobalDB) DeleteWorkspaceIfNoCatalogData

func (g *GlobalDB) DeleteWorkspaceIfNoCatalogData(ctx context.Context, workspaceID string) (bool, error)

DeleteWorkspaceIfNoCatalogData removes an empty workspace registry row.

func (*GlobalDB) Get

func (g *GlobalDB) Get(ctx context.Context, idOrPath string) (Workspace, error)

Get loads a workspace by id or normalized root path.

func (*GlobalDB) GetActiveWorkflowBySlug

func (g *GlobalDB) GetActiveWorkflowBySlug(ctx context.Context, workspaceID string, slug string) (Workflow, error)

GetActiveWorkflowBySlug loads the active workflow row for one workspace and slug.

func (*GlobalDB) GetLatestArchivedWorkflowBySlug

func (g *GlobalDB) GetLatestArchivedWorkflowBySlug(
	ctx context.Context,
	workspaceID string,
	slug string,
) (Workflow, error)

GetLatestArchivedWorkflowBySlug returns the most recently archived row for one workflow slug.

func (*GlobalDB) GetLatestReviewRound

func (g *GlobalDB) GetLatestReviewRound(ctx context.Context, workflowID string) (ReviewRound, error)

GetLatestReviewRound loads the newest review round for one workflow.

func (*GlobalDB) GetReviewRound

func (g *GlobalDB) GetReviewRound(ctx context.Context, workflowID string, round int) (ReviewRound, error)

GetReviewRound loads one review round by workflow and round number.

func (*GlobalDB) GetRun

func (g *GlobalDB) GetRun(ctx context.Context, runID string) (Run, error)

GetRun loads one run row by run identifier.

func (*GlobalDB) GetTaskItemByTaskID

func (g *GlobalDB) GetTaskItemByTaskID(
	ctx context.Context,
	workflowID string,
	taskID string,
) (TaskItemRow, error)

GetTaskItemByTaskID returns one synced task-item row by stable task id.

func (*GlobalDB) GetWorkflow

func (g *GlobalDB) GetWorkflow(ctx context.Context, id string) (Workflow, error)

GetWorkflow loads one workflow by primary key.

func (*GlobalDB) GetWorkflowArchiveEligibility

func (g *GlobalDB) GetWorkflowArchiveEligibility(
	ctx context.Context,
	workspaceID string,
	slug string,
) (WorkflowArchiveEligibility, error)

GetWorkflowArchiveEligibility reads the synced daemon catalog state used to archive one workflow.

func (*GlobalDB) List

func (g *GlobalDB) List(ctx context.Context) ([]Workspace, error)

List returns all registered workspaces in stable root order.

func (*GlobalDB) ListArtifactSnapshots

func (g *GlobalDB) ListArtifactSnapshots(ctx context.Context, workflowID string) ([]ArtifactSnapshotRow, error)

ListArtifactSnapshots returns authored-artifact snapshot rows for one workflow.

func (*GlobalDB) ListInterruptedRuns

func (g *GlobalDB) ListInterruptedRuns(ctx context.Context) ([]Run, error)

ListInterruptedRuns returns runs left in non-terminal daemon-owned states that must be reconciled on startup.

func (*GlobalDB) ListReviewIssues

func (g *GlobalDB) ListReviewIssues(ctx context.Context, roundID string) ([]ReviewIssue, error)

ListReviewIssues loads the durable issue rows for one review round.

func (*GlobalDB) ListReviewRounds

func (g *GlobalDB) ListReviewRounds(ctx context.Context, workflowID string) ([]ReviewRound, error)

ListReviewRounds returns persisted review rounds for one workflow in round order.

func (*GlobalDB) ListRuns

func (g *GlobalDB) ListRuns(ctx context.Context, opts ListRunsOptions) ([]Run, error)

ListRuns returns run rows filtered by workspace, mode, or status.

func (*GlobalDB) ListTaskItems

func (g *GlobalDB) ListTaskItems(ctx context.Context, workflowID string) ([]TaskItemRow, error)

ListTaskItems returns synced task-item rows for one workflow in task order.

func (*GlobalDB) ListTerminalRunsForPurge

func (g *GlobalDB) ListTerminalRunsForPurge(
	ctx context.Context,
	policy RunRetentionPolicy,
) ([]Run, error)

ListTerminalRunsForPurge selects terminal runs in oldest-first order while respecting the configured keep-count and keep-days bounds.

func (*GlobalDB) ListWorkflows

func (g *GlobalDB) ListWorkflows(ctx context.Context, opts ListWorkflowsOptions) ([]Workflow, error)

ListWorkflows returns workflow rows for one workspace.

func (*GlobalDB) MarkRunCrashed

func (g *GlobalDB) MarkRunCrashed(
	ctx context.Context,
	runID string,
	endedAt time.Time,
	errorText string,
) (Run, error)

MarkRunCrashed mirrors startup reconciliation into the durable run index.

func (*GlobalDB) MarkRunsCrashed

func (g *GlobalDB) MarkRunsCrashed(ctx context.Context, updates []RunCrashUpdate) error

MarkRunsCrashed updates multiple runs inside one transaction.

func (*GlobalDB) MarkWorkflowArchived

func (g *GlobalDB) MarkWorkflowArchived(
	ctx context.Context,
	workflowID string,
	archivedAt time.Time,
) (Workflow, error)

MarkWorkflowArchived persists the archived state for one active workflow row.

func (*GlobalDB) Path

func (g *GlobalDB) Path() string

Path reports the on-disk database path.

func (*GlobalDB) PruneMissingActiveWorkflows

func (g *GlobalDB) PruneMissingActiveWorkflows(
	ctx context.Context,
	workspaceID string,
	presentSlugs []string,
) (WorkflowPruneResult, error)

PruneMissingActiveWorkflows removes active workflow rows whose source directories were absent from a successful root sync.

func (*GlobalDB) PutRun

func (g *GlobalDB) PutRun(ctx context.Context, run Run) (Run, error)

PutRun inserts one durable run index row.

func (*GlobalDB) PutWorkflow

func (g *GlobalDB) PutWorkflow(ctx context.Context, workflow Workflow) (Workflow, error)

PutWorkflow inserts or updates one workflow identity row.

func (*GlobalDB) ReconcileWorkflowSync

func (g *GlobalDB) ReconcileWorkflowSync(
	ctx context.Context,
	input WorkflowSyncInput,
) (result WorkflowSyncResult, retErr error)

ReconcileWorkflowSync upserts the authored workflow state into the daemon catalog and removes stale projection rows that no longer exist on disk.

func (*GlobalDB) Register

func (g *GlobalDB) Register(ctx context.Context, path string, name string) (Workspace, error)

Register explicitly registers a workspace path and is idempotent on normalized roots.

func (*GlobalDB) Resolve

func (g *GlobalDB) Resolve(ctx context.Context, path string) (Workspace, error)

Resolve resolves a filesystem path and lazily registers the owning workspace.

func (*GlobalDB) ResolveOrRegister

func (g *GlobalDB) ResolveOrRegister(ctx context.Context, path string) (Workspace, error)

ResolveOrRegister resolves a filesystem path and returns one stable workspace row.

func (*GlobalDB) TaskCountsByWorkflowIDs

func (g *GlobalDB) TaskCountsByWorkflowIDs(
	ctx context.Context,
	workflowIDs []string,
) (map[string]WorkflowTaskCountsRow, error)

TaskCountsByWorkflowIDs returns aggregated task counts keyed by workflow id.

func (*GlobalDB) Unregister

func (g *GlobalDB) Unregister(ctx context.Context, idOrPath string) error

Unregister removes a workspace only when no active runs are present.

func (*GlobalDB) UpdateRun

func (g *GlobalDB) UpdateRun(ctx context.Context, run Run) (Run, error)

UpdateRun updates one durable run index row in place.

func (*GlobalDB) UpdateWorkspaceState

func (g *GlobalDB) UpdateWorkspaceState(ctx context.Context, update WorkspaceStateUpdate) (Workspace, error)

UpdateWorkspaceState records derived filesystem/sync state for a workspace.

func (*GlobalDB) WorkflowArchiveEligibilityByIDs

func (g *GlobalDB) WorkflowArchiveEligibilityByIDs(
	ctx context.Context,
	workflows []Workflow,
) (map[string]WorkflowArchiveEligibility, error)

WorkflowArchiveEligibilityByIDs returns archive-eligibility snapshots keyed by workflow id.

func (*GlobalDB) WorkflowSlugsByIDs

func (g *GlobalDB) WorkflowSlugsByIDs(ctx context.Context, ids []string) (map[string]string, error)

WorkflowSlugsByIDs returns workflow slugs for the supplied workflow ids.

func (*GlobalDB) WorkspaceCatalogStats

func (g *GlobalDB) WorkspaceCatalogStats(ctx context.Context, workspaceID string) (WorkspaceCatalogStats, error)

WorkspaceCatalogStats returns durable catalog counts for one workspace.

type ListRunsOptions

type ListRunsOptions struct {
	WorkspaceID string
	Status      string
	Mode        string
	Limit       int
}

ListRunsOptions controls durable run listing behavior.

type ListWorkflowsOptions

type ListWorkflowsOptions struct {
	WorkspaceID     string
	IncludeArchived bool
}

ListWorkflowsOptions controls workflow listing behavior.

type ReviewIssue

type ReviewIssue struct {
	ID          string
	RoundID     string
	IssueNumber int
	Severity    string
	Status      string
	SourcePath  string
	UpdatedAt   time.Time
}

ReviewIssue captures one durable review-issue projection row.

type ReviewIssueInput

type ReviewIssueInput struct {
	IssueNumber int
	Severity    string
	Status      string
	SourcePath  string
}

ReviewIssueInput describes one parsed review issue projection row.

type ReviewRound

type ReviewRound struct {
	ID              string
	WorkflowID      string
	RoundNumber     int
	Provider        string
	PRRef           string
	ResolvedCount   int
	UnresolvedCount int
	UpdatedAt       time.Time
}

ReviewRound captures one durable review-round projection row.

type ReviewRoundInput

type ReviewRoundInput struct {
	RoundNumber     int
	Provider        string
	PRRef           string
	ResolvedCount   int
	UnresolvedCount int
	Issues          []ReviewIssueInput
}

ReviewRoundInput describes one parsed review round plus its issue rows.

type Run

type Run struct {
	RunID            string
	WorkspaceID      string
	WorkflowID       *string
	ParentRunID      string
	Mode             string
	Status           string
	PresentationMode string
	StartedAt        time.Time
	EndedAt          *time.Time
	ErrorText        string
	RequestID        string
}

Run captures one durable global run index row.

type RunCrashUpdate

type RunCrashUpdate struct {
	RunID     string
	EndedAt   time.Time
	ErrorText string
}

RunCrashUpdate captures one durable crash reconciliation update.

type RunRetentionPolicy

type RunRetentionPolicy struct {
	KeepTerminalDays int
	KeepMax          int
	Now              time.Time
}

RunRetentionPolicy describes the terminal-run retention rules used when selecting purge candidates.

type SchemaTooNewError

type SchemaTooNewError struct {
	CurrentVersion int
	KnownVersion   int
}

SchemaTooNewError carries the current database and binary migration versions.

func (SchemaTooNewError) Error

func (e SchemaTooNewError) Error() string

func (SchemaTooNewError) Is

func (e SchemaTooNewError) Is(target error) bool

type TaskItemInput

type TaskItemInput struct {
	TaskNumber int
	TaskID     string
	Title      string
	Status     string
	Kind       string
	DependsOn  []string
	SourcePath string
}

TaskItemInput describes one parsed task file projection row.

type TaskItemRow

type TaskItemRow struct {
	ID         string
	WorkflowID string
	TaskNumber int
	TaskID     string
	Title      string
	Status     string
	Kind       string
	DependsOn  []string
	SourcePath string
	UpdatedAt  time.Time
}

TaskItemRow captures one durable task projection row.

type Workflow

type Workflow struct {
	ID           string
	WorkspaceID  string
	Slug         string
	ArchivedAt   *time.Time
	LastSyncedAt *time.Time
	CreatedAt    time.Time
	UpdatedAt    time.Time
}

Workflow captures one durable workflow identity row.

type WorkflowActiveRunsError

type WorkflowActiveRunsError struct {
	WorkspaceID string
	WorkflowID  string
	Slug        string
	ActiveRuns  int
}

WorkflowActiveRunsError reports how many active runs block archiving one workflow.

func (WorkflowActiveRunsError) Error

func (e WorkflowActiveRunsError) Error() string

func (WorkflowActiveRunsError) Is

func (e WorkflowActiveRunsError) Is(target error) bool

type WorkflowArchiveEligibility

type WorkflowArchiveEligibility struct {
	Workflow               Workflow
	TaskTotal              int
	PendingTasks           int
	ReviewRoundCount       int
	ReviewIssueTotal       int
	UnresolvedReviewIssues int
	ActiveRuns             int
}

WorkflowArchiveEligibility captures the synced daemon state used to decide whether one workflow can be archived.

func (WorkflowArchiveEligibility) Archivable

func (e WorkflowArchiveEligibility) Archivable() bool

Archivable reports whether the workflow can be archived.

func (WorkflowArchiveEligibility) ConflictError

func (e WorkflowArchiveEligibility) ConflictError() error

ConflictError converts one ineligible workflow snapshot into the canonical typed conflict.

func (WorkflowArchiveEligibility) SkipReason

func (e WorkflowArchiveEligibility) SkipReason() string

SkipReason reports why the workflow is not archivable.

type WorkflowArchivedError

type WorkflowArchivedError struct {
	WorkspaceID string
	Slug        string
}

WorkflowArchivedError reports an archive request against an already archived workflow identity.

func (WorkflowArchivedError) Error

func (e WorkflowArchivedError) Error() string

func (WorkflowArchivedError) Is

func (e WorkflowArchivedError) Is(target error) bool

type WorkflowNotArchivableError

type WorkflowNotArchivableError struct {
	WorkspaceID string
	WorkflowID  string
	Slug        string
	Reason      string
}

WorkflowNotArchivableError reports a synced-state reason that blocks archiving one workflow.

func (WorkflowNotArchivableError) Error

func (WorkflowNotArchivableError) Is

func (e WorkflowNotArchivableError) Is(target error) bool

type WorkflowPruneResult

type WorkflowPruneResult struct {
	PrunedSlugs []string
	Skipped     []WorkflowPruneSkipped
}

WorkflowPruneResult reports stale active workflow rows removed during a root sync plus rows deliberately kept for conflict reasons.

type WorkflowPruneSkipped

type WorkflowPruneSkipped struct {
	Slug       string
	Reason     string
	ActiveRuns int
}

WorkflowPruneSkipped reports a stale active workflow row that pruning kept because durable state still indicates active work.

type WorkflowSyncInput

type WorkflowSyncInput struct {
	WorkspaceID        string
	WorkflowSlug       string
	SyncedAt           time.Time
	CheckpointScope    string
	CheckpointChecksum string
	ArtifactSnapshots  []ArtifactSnapshotInput
	TaskItems          []TaskItemInput
	ReviewRounds       []ReviewRoundInput
}

WorkflowSyncInput captures one workflow reconciliation payload.

type WorkflowSyncResult

type WorkflowSyncResult struct {
	Workflow             Workflow
	SnapshotsUpserted    int
	TaskItemsUpserted    int
	ReviewRoundsUpserted int
	ReviewIssuesUpserted int
	CheckpointsUpdated   int
}

WorkflowSyncResult reports the durable rows touched by one reconciliation.

type WorkflowSyncValidationError

type WorkflowSyncValidationError struct {
	Message string
}

WorkflowSyncValidationError reports invalid authored workflow state that prevents sync from projecting the workflow into global.db.

func (WorkflowSyncValidationError) Error

func (WorkflowSyncValidationError) Is

func (e WorkflowSyncValidationError) Is(target error) bool

type WorkflowTaskCountsRow

type WorkflowTaskCountsRow struct {
	Total     int
	Completed int
	Pending   int
}

WorkflowTaskCountsRow captures aggregated task counts for one workflow.

type Workspace

type Workspace struct {
	ID              string
	RootDir         string
	Name            string
	FilesystemState string
	LastCheckedAt   *time.Time
	LastSyncedAt    *time.Time
	LastSyncError   string
	WorkflowCount   int
	RunCount        int
	HasCatalogData  bool
	ReadOnly        bool
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

Workspace captures one durable workspace registration.

type WorkspaceCatalogStats

type WorkspaceCatalogStats struct {
	WorkflowCount int
	RunCount      int
}

WorkspaceCatalogStats captures durable data counts owned by one workspace.

type WorkspaceRegistry

type WorkspaceRegistry interface {
	Resolve(context.Context, string) (Workspace, error)
	ResolveOrRegister(context.Context, string) (Workspace, error)
	Register(context.Context, string, string) (Workspace, error)
	Get(context.Context, string) (Workspace, error)
	List(context.Context) ([]Workspace, error)
	Unregister(context.Context, string) error
}

WorkspaceRegistry exposes durable workspace registration operations.

type WorkspaceStateUpdate

type WorkspaceStateUpdate struct {
	WorkspaceID     string
	FilesystemState string
	CheckedAt       time.Time
	LastSyncedAt    *time.Time
	LastSyncError   *string
}

WorkspaceStateUpdate describes derived workspace state persisted by daemon maintenance.

Jump to

Keyboard shortcuts

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