Documentation
¶
Overview ¶
Package ledger stores cr review runs in SQLite.
Index ¶
- Constants
- Variables
- type AllocateRunParams
- type Finding
- type ListRunsForHeadScopeParams
- type NamedSession
- type Outcome
- type PR
- type PlannedAction
- type PlannedActionKind
- type PlannedActionStatus
- type PostMode
- type Run
- type Session
- type SessionRole
- type Store
- func (s *Store) AllocateRun(ctx context.Context, params AllocateRunParams) (Run, error)
- func (s *Store) Close() error
- func (s *Store) CompleteRun(ctx context.Context, runID string, outcome Outcome, completedAt time.Time) error
- func (s *Store) DeleteNamedSession(ctx context.Context, name string) error
- func (s *Store) DeleteRun(ctx context.Context, runID string) error
- func (s *Store) GetNamedSession(ctx context.Context, name string) (NamedSession, error)
- func (s *Store) GetPR(ctx context.Context, prKey string) (PR, error)
- func (s *Store) GetRun(ctx context.Context, runID string) (Run, error)
- func (s *Store) GetSession(ctx context.Context, sessionRowID string) (Session, error)
- func (s *Store) InsertFinding(ctx context.Context, finding Finding) error
- func (s *Store) InsertPlannedAction(ctx context.Context, action PlannedAction) error
- func (s *Store) InsertSession(ctx context.Context, session Session) error
- func (s *Store) ListFindings(ctx context.Context, runID string) ([]Finding, error)
- func (s *Store) ListNamedSessions(ctx context.Context) ([]NamedSession, error)
- func (s *Store) ListPlannedActions(ctx context.Context, runID string) ([]PlannedAction, error)
- func (s *Store) ListRuns(ctx context.Context) ([]Run, error)
- func (s *Store) ListRunsForHeadScope(ctx context.Context, params ListRunsForHeadScopeParams) ([]Run, error)
- func (s *Store) ListSessionsForRun(ctx context.Context, runID string) ([]Session, error)
- func (s *Store) UpdateHeartbeat(ctx context.Context, runID string, heartbeatAt time.Time) error
- func (s *Store) UpdatePlannedAction(ctx context.Context, action PlannedAction) error
- func (s *Store) UpsertNamedSession(ctx context.Context, session NamedSession) error
Constants ¶
const ( // SchemaVersion is the current ledger schema version. SchemaVersion = 2 // DefaultBusyTimeout is the SQLite busy timeout configured at open. DefaultBusyTimeout = 5 * time.Second )
const ( PlannedActionFailureClassTerminal = "terminal" PlannedActionFailureClassAuth = "auth" )
PlannedActionFailureClass values stored for terminal post-phase failures.
Variables ¶
var ( // ErrClosed means a mutating operation was attempted after Store.Close. ErrClosed = errors.New("ledger: store closed") // ErrNotFound means a requested ledger row does not exist. ErrNotFound = errors.New("ledger: not found") // ErrInvalidInput means a caller supplied an invalid storage value. ErrInvalidInput = errors.New("ledger: invalid input") // ErrRunExists means AllocateRun recovery mode received an existing run id. ErrRunExists = errors.New("ledger: run already exists") )
Functions ¶
This section is empty.
Types ¶
type AllocateRunParams ¶
type AllocateRunParams struct {
PRKey string
PRURL string
RunID string
SHA string
BaseSHA string
Profile string
PostingIdentity string
PostMode PostMode
StartedAt time.Time
ArtifactPath string
}
AllocateRunParams contains the inputs needed to create a run row.
type Finding ¶
type Finding struct {
FindingID review.FindingID
RunID string
SessionRowID string
Severity review.Severity
FilePath string
Side *review.DiffSide
Line *int64
DiffPosition *int64
Anchoring review.Anchoring
Body string
}
Finding records one harness-assigned review finding.
type ListRunsForHeadScopeParams ¶
type ListRunsForHeadScopeParams struct {
PRKey string
SHA string
Profile string
PostingIdentity string
}
ListRunsForHeadScopeParams identifies local rows for one PR/head/profile/identity scope.
type NamedSession ¶
type NamedSession struct {
Name string
Profile string
Provider string
Adapter string
Model string
Host string
ProviderSessionID string
CreatedAt time.Time
LastUsedAt time.Time
}
NamedSession records cross-run provider session reuse metadata.
type Outcome ¶
type Outcome string
Outcome records a finalized run outcome.
const ( OutcomeIncomplete Outcome = "incomplete" OutcomeApproved Outcome = "approved" OutcomeRequestChanges Outcome = "request_changes" OutcomeComment Outcome = "comment" OutcomeNothingToReview Outcome = "nothing_to_review" OutcomeDryRun Outcome = "dry_run" OutcomeAborted Outcome = "aborted" OutcomeFailed Outcome = "failed" )
Outcome values.
func ParseOutcome ¶
ParseOutcome parses a storage outcome.
type PlannedAction ¶
type PlannedAction struct {
ActionID string
RunID string
Kind PlannedActionKind
FindingID *string
ThreadID *string
PlannedAt time.Time
PayloadJSON string
Status PlannedActionStatus
Required bool
Attempts int
AttemptedAt *time.Time
PostedAt *time.Time
UpstreamID *string
Error *string
FailureClass *string
}
PlannedAction records one outbox action planned for a run.
type PlannedActionKind ¶
type PlannedActionKind string
PlannedActionKind identifies the host-side action to execute later.
const ( PlannedActionInlineComment PlannedActionKind = "inline_comment" PlannedActionThreadReply PlannedActionKind = "thread_reply" PlannedActionResolveThread PlannedActionKind = "resolve_thread" PlannedActionRollupComment PlannedActionKind = "rollup_comment" PlannedActionSubmitReview PlannedActionKind = "submit_review" )
PlannedActionKind values.
func ParsePlannedActionKind ¶
func ParsePlannedActionKind(value string) (PlannedActionKind, error)
ParsePlannedActionKind parses a storage planned action kind.
func (PlannedActionKind) String ¶
func (k PlannedActionKind) String() string
func (PlannedActionKind) Valid ¶
func (k PlannedActionKind) Valid() bool
Valid reports whether k is a known planned action kind.
type PlannedActionStatus ¶
type PlannedActionStatus string
PlannedActionStatus records the durable outbox status for a planned action.
const ( PlannedActionPending PlannedActionStatus = "pending" PlannedActionPosted PlannedActionStatus = "posted" PlannedActionFailedTerminal PlannedActionStatus = "failed_terminal" PlannedActionSuperseded PlannedActionStatus = "superseded" PlannedActionPlannedOnly PlannedActionStatus = "planned_only" )
PlannedActionStatus values.
func ParsePlannedActionStatus ¶
func ParsePlannedActionStatus(value string) (PlannedActionStatus, error)
ParsePlannedActionStatus parses a storage planned action status.
func (PlannedActionStatus) String ¶
func (s PlannedActionStatus) String() string
func (PlannedActionStatus) Valid ¶
func (s PlannedActionStatus) Valid() bool
Valid reports whether s is a known planned action status.
type PostMode ¶
type PostMode string
PostMode records whether a run is live or dry-run.
func ParsePostMode ¶
ParsePostMode parses a storage post mode.
type Run ¶
type Run struct {
RunID string
PRKey string
SHA string
BaseSHA string
Attempt int
Profile string
PostingIdentity string
PostMode PostMode
StartedAt time.Time
HeartbeatAt *time.Time
CompletedAt *time.Time
Outcome *Outcome
ArtifactPath string
BlockingCount int
MajorCount int
MinorCount int
NitsCount int
}
Run is one cr review invocation recorded in the ledger.
type Session ¶
type Session struct {
SessionRowID string
RunID string
ProviderSessionID string
Role SessionRole
AgentID *string
Adapter string
Model string
Effort *string
StartedAt time.Time
CompletedAt *time.Time
DurationMS *int64
TokensIn *int64
TokensOut *int64
CacheRead *int64
CacheCreate *int64
CostUSD *float64
}
Session records LLM session usage for a run.
type SessionRole ¶
type SessionRole string
SessionRole records the role attached to an LLM session row.
const ( SessionRoleOrchestrator SessionRole = "orchestrator" SessionRoleReviewer SessionRole = "reviewer" )
SessionRole values.
func ParseSessionRole ¶
func ParseSessionRole(value string) (SessionRole, error)
ParseSessionRole parses a storage session role.
func (SessionRole) String ¶
func (r SessionRole) String() string
func (SessionRole) Valid ¶
func (r SessionRole) Valid() bool
Valid reports whether r is a known session role.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store owns the SQLite connection and serializes mutating ledger writes.
func (*Store) AllocateRun ¶
AllocateRun creates a run and allocates its attempt transactionally.
func (*Store) CompleteRun ¶
func (s *Store) CompleteRun(ctx context.Context, runID string, outcome Outcome, completedAt time.Time) error
CompleteRun records the terminal post-phase outcome for a run.
func (*Store) DeleteNamedSession ¶
DeleteNamedSession deletes a named provider session row.
func (*Store) GetNamedSession ¶
GetNamedSession returns a named provider session row.
func (*Store) GetSession ¶
GetSession returns a session by internal row id.
func (*Store) InsertFinding ¶
InsertFinding inserts a validated harness finding row.
func (*Store) InsertPlannedAction ¶
func (s *Store) InsertPlannedAction(ctx context.Context, action PlannedAction) error
InsertPlannedAction inserts an outbox planned-action row.
func (*Store) InsertSession ¶
InsertSession inserts an LLM session row.
func (*Store) ListFindings ¶
ListFindings lists findings for a run in stable order.
func (*Store) ListNamedSessions ¶
func (s *Store) ListNamedSessions(ctx context.Context) ([]NamedSession, error)
ListNamedSessions returns named provider sessions in stable name order.
func (*Store) ListPlannedActions ¶
ListPlannedActions lists planned actions for a run in stable order.
func (*Store) ListRunsForHeadScope ¶
func (s *Store) ListRunsForHeadScope(ctx context.Context, params ListRunsForHeadScopeParams) ([]Run, error)
ListRunsForHeadScope lists runs for one PR/head/profile/identity across bases.
func (*Store) ListSessionsForRun ¶
ListSessionsForRun lists sessions for a run in stable order.
func (*Store) UpdateHeartbeat ¶
UpdateHeartbeat records the latest liveness timestamp for a run.
func (*Store) UpdatePlannedAction ¶
func (s *Store) UpdatePlannedAction(ctx context.Context, action PlannedAction) error
UpdatePlannedAction updates the mutable outbox state for an existing action.
func (*Store) UpsertNamedSession ¶
func (s *Store) UpsertNamedSession(ctx context.Context, session NamedSession) error
UpsertNamedSession inserts or updates a named provider session row.