statedb

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CachedIssue

type CachedIssue struct {
	ID        string    `json:"id"`
	Repo      string    `json:"repo"`
	Source    string    `json:"source"` // "github" or "gitlab"
	Title     string    `json:"title"`
	Body      string    `json:"body,omitempty"`
	Status    string    `json:"status"`
	URL       string    `json:"url,omitempty"`
	Author    string    `json:"author,omitempty"`
	Labels    string    `json:"labels,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	FetchedAt time.Time `json:"fetched_at"`
}

CachedIssue represents a cached remote issue.

type DB

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

DB is a SQLite-backed state store for tasks, embeddings, and index state.

func Open

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

Open opens or creates the state database at .mit/state.db under the workspace root found by walking up from dir.

func OpenPath

func OpenPath(dbPath string) (*DB, error)

OpenPath opens or creates the state database at an explicit file path.

func (*DB) BeginTx

func (db *DB) BeginTx() error

BeginTx starts a transaction. All subsequent DB operations will use it.

func (*DB) CacheIssues

func (db *DB) CacheIssues(repo string, issues []CachedIssue) error

CacheIssues replaces the cached issues for a given repo with fresh data.

func (*DB) ClaimTask

func (db *DB) ClaimTask(id, agentID string) error

ClaimTask atomically assigns a task to an agent. It only succeeds when the task has status "open" and agent_id IS NULL. Returns an error if the task was already claimed or does not exist.

func (*DB) ClearIssueCache

func (db *DB) ClearIssueCache() error

ClearIssueCache removes all cached issues.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) CommitTx

func (db *DB) CommitTx() error

CommitTx commits the active transaction.

func (*DB) CreateTask

func (db *DB) CreateTask(title, description, repo string) (string, error)

CreateTask inserts a new task with status "open" and returns its UUID.

func (*DB) DeleteByFile

func (db *DB) DeleteByFile(repo, file string) error

DeleteByFile removes all embedding records for a given repo and file.

func (*DB) GetAllEmbeddings

func (db *DB) GetAllEmbeddings() ([]EmbeddingRecord, error)

GetAllEmbeddings returns every embedding record.

func (*DB) GetCacheAge

func (db *DB) GetCacheAge(repos []string) time.Duration

GetCacheAge returns the age of the oldest cached entry for the given repos. Returns 0 if cache is empty. If repos is empty, checks all cached repos.

func (*DB) GetCachedIssues

func (db *DB) GetCachedIssues(repo string) ([]CachedIssue, error)

GetCachedIssues returns cached issues, optionally filtered by repo.

func (*DB) GetIndexState

func (db *DB) GetIndexState(filePath string) (IndexState, error)

GetIndexState returns the stored state for a file path. If the file has not been indexed, it returns a zero IndexState and a nil error.

func (*DB) GetTask

func (db *DB) GetTask(id string) (*Task, error)

GetTask returns a single task by ID, or an error if not found.

func (*DB) ListTasks

func (db *DB) ListTasks(status, agentID, repo string) ([]Task, error)

ListTasks returns tasks matching the optional filters. Pass empty strings to skip a filter.

func (*DB) Path

func (db *DB) Path() string

Path returns the file path of the database.

func (*DB) RollbackTx

func (db *DB) RollbackTx() error

RollbackTx rolls back the active transaction.

func (*DB) SetIndexState

func (db *DB) SetIndexState(filePath, checksum string, mtimeNs, fileSize int64) error

SetIndexState upserts the state for a file path.

func (*DB) StoreEmbedding

func (db *DB) StoreEmbedding(repo, file string, chunkIndex, lineStart, lineEnd int, contentHash string, embedding []byte) error

StoreEmbedding inserts a new embedding record.

func (*DB) UpdateTaskStatus

func (db *DB) UpdateTaskStatus(id, status string) error

UpdateTaskStatus changes the status of a task. If the new status is "completed", the completed_at timestamp is set.

type EmbeddingRecord

type EmbeddingRecord struct {
	ID          int64  `json:"id"`
	Repo        string `json:"repo"`
	File        string `json:"file"`
	ChunkIndex  int    `json:"chunk_index"`
	LineStart   int    `json:"line_start"`
	LineEnd     int    `json:"line_end"`
	ContentHash string `json:"content_hash"`
	Embedding   []byte `json:"embedding"`
}

EmbeddingRecord represents a row in the embeddings table.

type IndexState

type IndexState struct {
	Checksum string
	MtimeNs  int64
	FileSize int64
}

IndexState holds the stored state for a file in the index.

type Task

type Task struct {
	ID          string     `json:"id"`
	Title       string     `json:"title"`
	Description string     `json:"description,omitempty"`
	Status      string     `json:"status"`
	AgentID     string     `json:"agent_id,omitempty"`
	ParentID    string     `json:"parent_id,omitempty"`
	Repo        string     `json:"repo,omitempty"`
	CreatedAt   time.Time  `json:"created_at"`
	ClaimedAt   *time.Time `json:"claimed_at,omitempty"`
	CompletedAt *time.Time `json:"completed_at,omitempty"`
	Metadata    string     `json:"metadata,omitempty"`
}

Task represents a row in the tasks table.

Jump to

Keyboard shortcuts

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