db

package
v1.20.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	RoundSelectionSourceUser    = "user"
	RoundSelectionSourceAutoFix = "auto_fix"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB wraps a SQLite database connection.

func Open

func Open(path string) (*DB, error)

Open opens (or creates) the SQLite database at path and runs migrations.

func (*DB) CleanupOldIntentCache added in v1.14.0

func (d *DB) CleanupOldIntentCache(maxAge time.Duration) (int64, error)

CleanupOldIntentCache deletes entries older than maxAge. Returns rows deleted.

func (*DB) ClearStepFindings

func (d *DB) ClearStepFindings(id string) error

ClearStepFindings removes any stored findings JSON from a step result.

func (*DB) Close

func (d *DB) Close() error

Close closes the database connection.

func (*DB) CompleteStep

func (d *DB) CompleteStep(id string, exitCode int, durationMS int64, logPath string) error

CompleteStep marks a step as completed with timing and result info.

func (*DB) CompleteStepWithStatus added in v1.10.1

func (d *DB) CompleteStepWithStatus(id string, status types.StepStatus, exitCode int, durationMS int64, logPath string) error

CompleteStepWithStatus marks a step as finished with timing and result info.

func (*DB) DeleteRepo

func (d *DB) DeleteRepo(id string) error

DeleteRepo deletes a repo by ID (cascade deletes runs and steps).

func (*DB) FailStep

func (d *DB) FailStep(id string, errMsg string, durationMS int64) error

FailStep marks a step as failed with an error message and duration.

func (*DB) FixedFindingsByStep added in v1.18.0

func (d *DB) FixedFindingsByStep(step *StepResult) (int, error)

FixedFindingsByStep returns how many findings were resolved for a single step.

func (*DB) GetActiveRun

func (d *DB) GetActiveRun(repoID, branch string) (*Run, error)

GetActiveRun returns the currently active run (pending or running) for a repo, if any. When branch is non-empty, only a run on that exact branch is returned - the setup wizard relies on this to decide whether a new run is needed for the current branch. When branch is empty, returns the most recently created active run across any branch.

func (*DB) GetIntentCache added in v1.14.0

func (d *DB) GetIntentCache(key string) (*IntentCacheEntry, error)

GetIntentCache returns the cached summary for a key, or nil if absent.

func (*DB) GetRepo

func (d *DB) GetRepo(id string) (*Repo, error)

GetRepo returns a repo by ID.

func (*DB) GetRepoByPath

func (d *DB) GetRepoByPath(workingPath string) (*Repo, error)

GetRepoByPath returns a repo by its working path.

func (*DB) GetRoundsByStep added in v1.1.0

func (d *DB) GetRoundsByStep(stepResultID string) ([]*StepRound, error)

GetRoundsByStep returns all rounds for a step result, ordered by round number.

func (*DB) GetRun

func (d *DB) GetRun(id string) (*Run, error)

GetRun returns a run by ID.

func (*DB) GetRunsByRepo

func (d *DB) GetRunsByRepo(repoID string) ([]*Run, error)

GetRunsByRepo returns all runs for a repo, newest first.

func (*DB) GetStats added in v1.16.0

func (d *DB) GetStats() (*Stats, error)

GetStats aggregates historical usage across all repositories.

func (*DB) GetStepResult

func (d *DB) GetStepResult(id string) (*StepResult, error)

GetStepResult returns a step result by ID.

func (*DB) GetStepsByRun

func (d *DB) GetStepsByRun(runID string) ([]*StepResult, error)

GetStepsByRun returns all step results for a run, in execution order.

func (*DB) InsertRepo

func (d *DB) InsertRepo(workingPath, upstreamURL, defaultBranch string) (*Repo, error)

InsertRepo creates a new repo record and returns it with a generated ID.

func (*DB) InsertRepoWithID

func (d *DB) InsertRepoWithID(id, workingPath, upstreamURL, defaultBranch string) (*Repo, error)

InsertRepoWithID creates a new repo record with a caller-provided ID.

func (*DB) InsertRun

func (d *DB) InsertRun(repoID, branch, headSHA, baseSHA string) (*Run, error)

InsertRun creates a new run record.

func (*DB) InsertStepResult

func (d *DB) InsertStepResult(runID string, stepName types.StepName) (*StepResult, error)

InsertStepResult creates a new step result record.

func (*DB) InsertStepRound added in v1.1.0

func (d *DB) InsertStepRound(stepResultID string, round int, trigger string, findingsJSON *string, fixSummary *string, durationMS int64) (*StepRound, error)

InsertStepRound creates a new round record for a step result. fixSummary may be nil for non-fix rounds or when the agent produced no summary.

func (*DB) PutIntentCache added in v1.14.0

func (d *DB) PutIntentCache(e IntentCacheEntry) error

PutIntentCache inserts or replaces an intent cache entry.

func (*DB) RecoverStaleRuns

func (d *DB) RecoverStaleRuns(errMsg string) (int, error)

RecoverStaleRuns marks any runs stuck in pending/running status as failed and fails any in-progress steps. This is called at daemon startup to clean up after a previous crash. Returns the number of recovered runs.

func (*DB) SetStepDuration added in v1.1.0

func (d *DB) SetStepDuration(id string, durationMS int64) error

SetStepDuration sets the execution-only duration on a step result.

func (*DB) SetStepFindings

func (d *DB) SetStepFindings(id string, findingsJSON string) error

SetStepFindings sets the findings JSON on a step result.

func (*DB) SetStepRoundSelectedFindingIDs added in v1.5.0

func (d *DB) SetStepRoundSelectedFindingIDs(id string, selectedFindingIDs *string) error

SetStepRoundSelectedFindingIDs preserves the old API for callers that do not need to distinguish how the selection was made.

func (*DB) SetStepRoundSelection added in v1.5.0

func (d *DB) SetStepRoundSelection(id string, selectedFindingIDs *string, source string) error

SetStepRoundSelection records which findings were selected for fix AFTER the given round produced its findings, along with whether that selection came from the user or auto-fix filtering. Passing a nil or empty JSON array clears both columns.

func (*DB) SetStepRoundUserFindings added in v1.10.0

func (d *DB) SetStepRoundUserFindings(id string, userFindingsJSON *string) error

SetStepRoundUserFindings records the merged finding list (with user instructions attached and user-added findings appended) that was dispatched to the fix agent for the round. Passing nil clears the column.

func (*DB) StartStep

func (d *DB) StartStep(id string) error

StartStep marks a step as running with a started_at timestamp.

func (*DB) StepFindingStats added in v1.18.0

func (d *DB) StepFindingStats(step *StepResult) (StepStats, error)

StepFindingStats returns reported and fixed finding counts for a single step.

func (*DB) UpdateRunError

func (d *DB) UpdateRunError(id, errMsg string) error

UpdateRunError sets the error message on a run.

func (*DB) UpdateRunErrorStatus

func (d *DB) UpdateRunErrorStatus(id, errMsg string, status types.RunStatus) error

UpdateRunErrorStatus sets the error message and terminal status on a run.

func (*DB) UpdateRunHeadSHA

func (d *DB) UpdateRunHeadSHA(id, headSHA string) error

UpdateRunHeadSHA updates the run head SHA and timestamp.

func (*DB) UpdateRunIntent added in v1.14.0

func (d *DB) UpdateRunIntent(id string, intent RunIntent) error

UpdateRunIntent persists the inferred user intent for a run.

func (*DB) UpdateRunPRURL

func (d *DB) UpdateRunPRURL(id, prURL string) error

UpdateRunPRURL sets the PR URL on a run.

func (*DB) UpdateRunStatus

func (d *DB) UpdateRunStatus(id string, status types.RunStatus) error

UpdateRunStatus updates a run's status and updated_at timestamp.

func (*DB) UpdateStepStatus

func (d *DB) UpdateStepStatus(id string, status types.StepStatus) error

UpdateStepStatus updates a step's status.

func (*DB) UpdateStepStatusWithDuration added in v1.18.0

func (d *DB) UpdateStepStatusWithDuration(id string, status types.StepStatus, durationMS int64) error

UpdateStepStatusWithDuration updates a step's status and execution duration together.

type IntentCacheEntry added in v1.14.0

type IntentCacheEntry struct {
	CacheKey  string
	Summary   string
	AgentName string
	SessionID string
	CreatedAt int64
}

IntentCacheEntry is a cached summarization for a known agent session.

type Repo

type Repo struct {
	ID            string
	WorkingPath   string
	UpstreamURL   string
	DefaultBranch string
	CreatedAt     int64
}

Repo represents a registered repository.

type RepoStats added in v1.16.0

type RepoStats struct {
	RepoID           string
	WorkingPath      string
	Runs             int
	RescueRuns       int
	ReportedFindings int
	FixedFindings    int
}

RepoStats summarizes historical usage for one repository.

func (RepoStats) DisplayName added in v1.16.0

func (r RepoStats) DisplayName() string

DisplayName returns a compact repository name for terminal reports.

type Run

type Run struct {
	ID              string
	RepoID          string
	Branch          string
	HeadSHA         string
	BaseSHA         string
	Status          types.RunStatus
	PRURL           *string
	Error           *string
	Intent          *string
	IntentSource    *string
	IntentSessionID *string
	IntentScore     *float64
	CreatedAt       int64
	UpdatedAt       int64
}

Run represents a pipeline run.

type RunIntent added in v1.14.0

type RunIntent struct {
	Summary   string
	Source    string
	SessionID string
	Score     float64
}

RunIntent carries the four intent-related columns persisted on a run.

type Stats added in v1.16.0

type Stats struct {
	TotalRepos       int
	TotalRuns        int
	PullRequests     int
	RescueRuns       int
	ReportedFindings int
	FixedFindings    int
	StepStats        []StepStats
	RepoStats        []RepoStats
}

Stats summarizes historical no-mistakes usage across all repositories.

type StepResult

type StepResult struct {
	ID           string
	RunID        string
	StepName     types.StepName
	StepOrder    int
	Status       types.StepStatus
	ExitCode     *int
	DurationMS   *int64
	LogPath      *string
	FindingsJSON *string
	Error        *string
	StartedAt    *int64
	CompletedAt  *int64
}

StepResult represents the result of a pipeline step execution.

type StepRound added in v1.1.0

type StepRound struct {
	ID           string
	StepResultID string
	Round        int
	Trigger      string  // "initial", "auto_fix"; legacy "user_fix" is treated as "auto_fix"
	FindingsJSON *string // nullable - findings produced by this round
	// UserFindingsJSON, when non-nil, is the merged finding list that was
	// dispatched to the fix agent after the user edited per-finding
	// instructions or added their own findings. It includes both the
	// selected agent-produced findings (with any attached user
	// instructions) and the user-authored findings.
	UserFindingsJSON *string
	// SelectedFindingIDs, when non-nil, is a JSON array of finding IDs that
	// were chosen (by the user or auto-fix filter) to be fixed AFTER this
	// round. It is populated on the round whose findings triggered the next
	// round, so that later rounds' prompts can tell which findings were
	// deliberately left unselected.
	SelectedFindingIDs *string
	SelectionSource    *string
	// FixSummary, when non-nil, is the agent's one-line commit summary for
	// the fix attempt performed during this round. It is only set when the
	// round itself was a fix round (trigger=="auto_fix").
	FixSummary *string
	DurationMS int64
	CreatedAt  int64
}

StepRound represents one execution round within a pipeline step.

type StepStats added in v1.16.0

type StepStats struct {
	StepName         types.StepName
	ReportedFindings int
	FixedFindings    int
}

StepStats summarizes reported and fixed findings for one pipeline step.

Jump to

Keyboard shortcuts

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