sqlite

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package sqlite persists QUANTUM_LOG data locally using a CGo-free driver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Checkpoint added in v0.2.0

func Checkpoint(ctx context.Context, path string) (result error)

Checkpoint validates and checkpoints a quiescent local ledger without migrations.

func ValidateAllocations

func ValidateAllocations(allocations []AllocationInput) error

Types

type Allocation

type Allocation struct {
	ProjectID   string `json:"project_id"`
	ProjectSlug string `json:"project_slug"`
	BasisPoints int64  `json:"basis_points"`
	Method      string `json:"method"`
	Confidence  string `json:"confidence"`
}

type AllocationInput

type AllocationInput struct {
	ProjectID   string
	BasisPoints int64
}

type AnchorMismatch added in v0.2.0

type AnchorMismatch struct {
	Source    string
	SessionID string
	Expected  string
	Actual    string
	Truncated bool
}

type BudgetAlert added in v0.2.0

type BudgetAlert struct {
	BudgetRecord
	AllocatedCostUSDMicros int64  `json:"allocated_cost_usd_micros"`
	ThresholdUSDMicros     int64  `json:"threshold_usd_micros"`
	Alert                  string `json:"alert"`
}

type BudgetInput added in v0.2.0

type BudgetInput struct {
	Scope                string
	Target               string
	MonthlyCostUSDMicros int64
	AlertPercent         int64
}

type BudgetRecord added in v0.2.0

type BudgetRecord struct {
	ID                   string `json:"id"`
	Scope                string `json:"scope"`
	Target               string `json:"target"`
	MonthlyCostUSDMicros int64  `json:"monthly_cost_usd_micros"`
	AlertPercent         int64  `json:"alert_percent"`
}

type CopilotOTLPEvidenceQuery added in v0.3.1

type CopilotOTLPEvidenceQuery struct {
	From        time.Time
	To          time.Time
	ProjectSlug string
}

type ExportRecord

type ExportRecord struct {
	ID                     string       `json:"id"`
	OccurredAt             time.Time    `json:"occurred_at"`
	ProjectSlug            string       `json:"project_slug"`
	ProjectLocationPath    string       `json:"project_location_path,omitempty"`
	Provider               string       `json:"provider"`
	Model                  string       `json:"model"`
	Agent                  string       `json:"agent"`
	InputTokens            int64        `json:"input_tokens"`
	OutputTokens           int64        `json:"output_tokens"`
	ReasoningTokens        int64        `json:"reasoning_tokens"`
	CachedInputTokens      int64        `json:"cached_input_tokens"`
	CacheWriteTokens       int64        `json:"cache_write_tokens"`
	TotalTokens            int64        `json:"total_tokens"`
	EstimatedCostUSDMicros int64        `json:"estimated_cost_usd_micros"`
	CaptureQuality         string       `json:"capture_quality"`
	Allocations            []Allocation `json:"allocations"`
}

type LedgerAnchor added in v0.2.0

type LedgerAnchor struct {
	Source     string `json:"source"`
	SessionID  string `json:"session_id"`
	HeadHash   string `json:"head_hash"`
	Events     int64  `json:"events"`
	LastSeenAt string `json:"last_seen_at"`
}

type ModelCallInput

type ModelCallInput struct {
	ProjectID              string
	ProjectLocationID      string
	WorkContextID          string
	TaskID                 string
	SessionID              string
	TurnID                 string
	Provider               string
	ModelID                string
	AgentName              string
	InputTokens            int64
	OutputTokens           int64
	ReasoningTokens        int64
	CachedInputTokens      int64
	CacheWriteTokens       int64
	EstimatedCostUSDMicros int64
	EstimatedCostEURMicros int64
	OccurredAt             time.Time
	CaptureQuality         string
}

type PricingRecalculateQuery

type PricingRecalculateQuery struct {
	From time.Time
	To   time.Time
}

type PricingRuleRecord

type PricingRuleRecord struct {
	ID        string       `json:"id"`
	Rule      pricing.Rule `json:"rule"`
	CreatedAt time.Time    `json:"created_at"`
}

type ProjectReport added in v0.2.0

type ProjectReport struct {
	Project                ProjectSummary `json:"project"`
	Tags                   []ProjectTag   `json:"tags"`
	ActiveTaskCount        int64          `json:"active_task_count"`
	ObservedModelCallCount int64          `json:"observed_model_call_count"`
	ObservedTokens         int64          `json:"observed_tokens"`
	AllocatedCostUSDMicros int64          `json:"allocated_cost_usd_micros"`
	BudgetAlerts           []BudgetAlert  `json:"budget_alerts"`
}

type ProjectSummary

type ProjectSummary struct {
	ID            string    `json:"id"`
	Slug          string    `json:"slug"`
	Name          string    `json:"name"`
	LocationCount int64     `json:"location_count"`
	TagCount      int64     `json:"tag_count"`
	CreatedAt     time.Time `json:"created_at"`
}

type ProjectTag

type ProjectTag struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type RawEventInput

type RawEventInput struct {
	Source               string
	SessionID            string
	EventType            string
	Payload              []byte
	OccurredAt           time.Time
	ProjectID            string
	ProjectLocationID    string
	WorkContextID        string
	ResolutionMethod     string
	ResolutionConfidence string
	EvidenceJSON         string
}

type Store

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

func Open

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

func OpenReadOnly added in v0.2.0

func OpenReadOnly(ctx context.Context, path string) (*Store, error)

OpenReadOnly opens an initialized database without creating files or applying migrations.

func (*Store) AddPricingRule

func (s *Store) AddPricingRule(ctx context.Context, rule pricing.Rule) (PricingRuleRecord, error)

func (*Store) AddProjectTag

func (s *Store) AddProjectTag(ctx context.Context, projectID, key, value string) error

func (*Store) AppendRawEvent

func (s *Store) AppendRawEvent(ctx context.Context, input RawEventInput) (string, error)

func (*Store) AssignUnattributedModelCall added in v0.2.0

func (s *Store) AssignUnattributedModelCall(ctx context.Context, modelCallID, projectID string) error

func (*Store) BudgetAlerts added in v0.2.0

func (s *Store) BudgetAlerts(ctx context.Context, now time.Time) ([]BudgetAlert, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) CreateWorkContext

func (s *Store) CreateWorkContext(ctx context.Context, input WorkContextInput) (domain.WorkContext, error)

func (*Store) Doctor

func (s *Store) Doctor(ctx context.Context) error

func (*Store) EnsureSession

func (s *Store) EnsureSession(ctx context.Context, id, agentName string, startedAt time.Time) error

func (*Store) ExportModelCalls

func (s *Store) ExportModelCalls(ctx context.Context, query PricingRecalculateQuery) ([]ExportRecord, error)

func (*Store) FinishTask

func (s *Store) FinishTask(ctx context.Context, id, result string) error

func (*Store) HasRecentCopilotOTLPModelCall added in v0.3.1

func (s *Store) HasRecentCopilotOTLPModelCall(ctx context.Context, query CopilotOTLPEvidenceQuery) (bool, error)

func (*Store) LedgerAnchors added in v0.2.0

func (s *Store) LedgerAnchors(ctx context.Context) ([]LedgerAnchor, error)

func (*Store) ListPricingRules

func (s *Store) ListPricingRules(ctx context.Context) ([]PricingRuleRecord, error)

func (*Store) ListProjects

func (s *Store) ListProjects(ctx context.Context) ([]ProjectSummary, error)

func (*Store) ListTasks

func (s *Store) ListTasks(ctx context.Context, projectSlug string) ([]TaskRecord, error)

func (*Store) ModelCallAllocations

func (s *Store) ModelCallAllocations(ctx context.Context, modelCallID string) ([]Allocation, error)

func (*Store) ProjectByLocation added in v0.2.0

func (s *Store) ProjectByLocation(ctx context.Context, path string) (domain.Project, domain.ProjectLocation, bool, error)

func (*Store) ProjectBySlug

func (s *Store) ProjectBySlug(ctx context.Context, slug string) (domain.Project, domain.ProjectLocation, bool, error)

func (*Store) ProjectReport added in v0.2.0

func (s *Store) ProjectReport(ctx context.Context, slug string, now time.Time) (ProjectReport, error)

func (*Store) ProjectTags

func (s *Store) ProjectTags(ctx context.Context, projectID string) ([]ProjectTag, error)

func (*Store) RecalculateCosts

func (s *Store) RecalculateCosts(ctx context.Context, query PricingRecalculateQuery) (int, error)

func (*Store) RecordModelCall

func (s *Store) RecordModelCall(ctx context.Context, input ModelCallInput) (string, error)

func (*Store) RegisterProject

func (s *Store) RegisterProject(ctx context.Context, name, slug, path string) (domain.Project, domain.ProjectLocation, error)

func (*Store) RegisteredPaths

func (s *Store) RegisteredPaths(ctx context.Context) (map[string]string, error)

func (*Store) RepairModelCallAllocation

func (s *Store) RepairModelCallAllocation(ctx context.Context, modelCallID, projectID string) error

func (*Store) ReplaceAllocations

func (s *Store) ReplaceAllocations(ctx context.Context, subjectType, subjectID string, allocations []AllocationInput) error

func (*Store) SetBudget added in v0.2.0

func (s *Store) SetBudget(ctx context.Context, input BudgetInput) (BudgetRecord, error)

func (*Store) StartTask

func (s *Store) StartTask(ctx context.Context, input TaskInput) (string, error)

func (*Store) TaskSummary added in v0.2.0

func (s *Store) TaskSummary(ctx context.Context, id string) (TaskSummary, error)

func (*Store) UnattributedSummary added in v0.2.0

func (s *Store) UnattributedSummary(ctx context.Context) (UnattributedSummary, error)

UnattributedSummary intentionally reports calls without allocations. A manual repair or split removes a call from this queue without rewriting raw usage.

func (*Store) Usage

func (s *Store) Usage(ctx context.Context, query UsageQuery) (UsageReport, error)

func (*Store) VerifyAnchors added in v0.2.0

func (s *Store) VerifyAnchors(ctx context.Context, expected []LedgerAnchor) ([]AnchorMismatch, error)

func (*Store) VerifyLedger

func (s *Store) VerifyLedger(ctx context.Context, sessionID string) error

func (*Store) Warnings added in v0.2.0

func (s *Store) Warnings() []string

type TaskInput

type TaskInput struct {
	ProjectID string
	Title     string
	TaskType  string
}

type TaskRecord

type TaskRecord struct {
	ID          string     `json:"id"`
	ProjectSlug string     `json:"project_slug"`
	Title       string     `json:"title"`
	TaskType    string     `json:"task_type"`
	Status      string     `json:"status"`
	Result      string     `json:"result"`
	StartedAt   time.Time  `json:"started_at"`
	FinishedAt  *time.Time `json:"finished_at,omitempty"`
}

type TaskSummary added in v0.2.0

type TaskSummary struct {
	TaskRecord
	ModelCallCount         int64 `json:"model_call_count"`
	ObservedTokens         int64 `json:"observed_tokens"`
	AllocatedCostUSDMicros int64 `json:"allocated_cost_usd_micros"`
}

TaskSummary reports task lifecycle data plus usage already recorded against it. It does not infer usage from an agent session or project.

type UnattributedModelCall added in v0.2.0

type UnattributedModelCall struct {
	ID                     string    `json:"id"`
	OccurredAt             time.Time `json:"occurred_at"`
	Provider               string    `json:"provider"`
	Model                  string    `json:"model"`
	TotalTokens            int64     `json:"total_tokens"`
	EstimatedCostUSDMicros int64     `json:"estimated_cost_usd_micros"`
}

type UnattributedSummary added in v0.2.0

type UnattributedSummary struct {
	ModelCallCount         int64                   `json:"model_call_count"`
	ObservedTokens         int64                   `json:"observed_tokens"`
	EstimatedCostUSDMicros int64                   `json:"estimated_cost_usd_micros"`
	ModelCalls             []UnattributedModelCall `json:"model_calls"`
}

type UsageQuery

type UsageQuery struct {
	From        time.Time
	To          time.Time
	ProjectSlug string
	GroupBy     []string
}

type UsageReport

type UsageReport struct {
	GroupBy                []string   `json:"group_by"`
	Rows                   []UsageRow `json:"rows"`
	TotalTokens            int64      `json:"total_tokens"`
	AllocatedCostUSDMicros int64      `json:"allocated_cost_usd_micros"`
}

type UsageRow

type UsageRow struct {
	ProjectSlug            string `json:"project_slug"`
	AgentName              string `json:"agent_name"`
	Provider               string `json:"provider"`
	Model                  string `json:"model"`
	CaptureQuality         string `json:"capture_quality"`
	InputTokens            int64  `json:"input_tokens"`
	OutputTokens           int64  `json:"output_tokens"`
	ReasoningTokens        int64  `json:"reasoning_tokens"`
	CachedInputTokens      int64  `json:"cached_input_tokens"`
	CacheWriteTokens       int64  `json:"cache_write_tokens"`
	TotalTokens            int64  `json:"total_tokens"`
	AllocatedCostUSDMicros int64  `json:"allocated_cost_usd_micros"`
}

type WorkContextInput

type WorkContextInput struct {
	ProjectID            string
	LocationID           string
	SessionID            string
	CWD                  string
	GitRoot              string
	GitBranch            string
	GitCommit            string
	StartedAt            time.Time
	ResolutionMethod     string
	ResolutionConfidence string
	EvidenceJSON         string
}

Jump to

Keyboard shortcuts

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