taskqueue

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package taskqueue implements a central SQLite-backed queue that records every unit of work cloop performs — PM task executions, auto-heal retries, evolve discoveries, and externally-added tasks. The queue is the single source of truth for "what is cloop doing right now and what did it just do," giving the UI full auditability and ensuring no work runs anonymously.

The queue is intentionally append-mostly: rows are inserted when work begins and updated only with terminal status. List() returns rows newest-first.

As of Task 20079 the queue table lives inside the project state database (.cloop/state.db) so a project has exactly one SQLite file. Existing .cloop/queue.db files are migrated transparently on first Open and removed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func QueuePath

func QueuePath(workDir string) string

QueuePath returns the on-disk path of the database that backs the queue for a project working directory. As of Task 20079 this is the project's state.db — the queue table is co-located with project state so there is exactly one SQLite file per project.

Types

type Entry

type Entry struct {
	ID            int64      `json:"id"`
	Kind          Kind       `json:"kind"`
	TaskID        int        `json:"task_id,omitempty"`   // 0 if not linked to a plan task
	Attempt       int        `json:"attempt,omitempty"`   // 1-based attempt counter (heal retries)
	ParentID      int64      `json:"parent_id,omitempty"` // queue id of the parent entry, if any
	Title         string     `json:"title"`
	Description   string     `json:"description,omitempty"`
	Status        Status     `json:"status"`
	Source        string     `json:"source,omitempty"` // "orchestrator" | "evolve" | "external" | "api" | "cli"
	CreatedAt     time.Time  `json:"created_at"`
	StartedAt     *time.Time `json:"started_at,omitempty"`
	CompletedAt   *time.Time `json:"completed_at,omitempty"`
	OutputSummary string     `json:"output_summary,omitempty"`
	ErrorMessage  string     `json:"error_message,omitempty"`
}

Entry is a single queue row.

type Kind

type Kind string

Kind identifies what type of work the queue entry represents.

const (
	KindTask     Kind = "task"     // PM task execution
	KindHeal     Kind = "heal"     // auto-heal retry attempt
	KindEvolve   Kind = "evolve"   // evolve discovery cycle
	KindExternal Kind = "external" // externally-added task merged in
	KindSession  Kind = "session"  // session-level work (decompose, optimize, etc.)
)

type ListOptions

type ListOptions struct {
	// Limit caps the number of returned rows. 0 = default 200.
	Limit int
	// Offset for pagination. 0 = from newest.
	Offset int
	// Status filter. Empty = all statuses.
	Status Status
	// Kind filter. Empty = all kinds.
	Kind Kind
	// TaskID filter. 0 = all tasks.
	TaskID int
}

ListOptions filters and paginates List results.

type Queue

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

Queue is a thread-safe handle to the queue database.

func Open

func Open(workDir string) (*Queue, error)

Open opens (or creates) the queue database. The caller must Close() it.

Storage is the project's state.db (the queue table is part of that file's schema, see pkg/statedb). On first call, any rows in a legacy .cloop/queue.db are migrated into state.db and the legacy file is removed.

func (*Queue) Close

func (q *Queue) Close() error

Close releases the queue database connection.

func (*Queue) Enqueue

func (q *Queue) Enqueue(e Entry) (int64, error)

Enqueue inserts a new queue entry and returns its assigned id. The Status, CreatedAt, ID, StartedAt, and CompletedAt fields of the input are ignored — Enqueue assigns its own values.

func (*Queue) List

func (q *Queue) List(opts ListOptions) ([]Entry, error)

List returns queue entries matching opts, newest first.

func (*Queue) MarkDone

func (q *Queue) MarkDone(id int64, summary string) error

MarkDone sets the entry status to "done" and records a brief output summary.

func (*Queue) MarkFailed

func (q *Queue) MarkFailed(id int64, errMsg string) error

MarkFailed sets the entry status to "failed" and records an error message.

func (*Queue) MarkRunning

func (q *Queue) MarkRunning(id int64) error

MarkRunning transitions an entry to the running state and stamps started_at. No-op if id is zero.

func (*Queue) MarkSkipped

func (q *Queue) MarkSkipped(id int64, reason string) error

MarkSkipped sets the entry status to "skipped" and records a reason.

func (*Queue) Path

func (q *Queue) Path() string

Path returns the on-disk path of the queue database.

func (*Queue) Stats

func (q *Queue) Stats() (map[Status]int, error)

Stats returns counts grouped by status.

func (*Queue) Truncate

func (q *Queue) Truncate() error

Truncate removes all queue entries. Used by tests and `cloop reset`.

type Status

type Status string

Status enumerates queue entry lifecycle states.

const (
	StatusQueued  Status = "queued"
	StatusRunning Status = "running"
	StatusDone    Status = "done"
	StatusFailed  Status = "failed"
	StatusSkipped Status = "skipped"
)

Jump to

Keyboard shortcuts

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