task

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package task implements tasks, their status machine and dependencies.

Mutating functions take a *sql.Tx opened with BEGIN IMMEDIATE (db.DB.Tx); every status change is a compare-and-swap on tasks.version plus an events row in that tx.

Index

Constants

View Source
const (
	Draft     = "draft"
	Ready     = "ready"
	Claimed   = "claimed"
	Running   = "running"
	Waiting   = "waiting"
	Review    = "review"
	Done      = "done"      // finished, ready to deliver
	Delivered = "delivered" // handed over (`otag task deliver`); only from done
	Blocked   = "blocked"
	Cancelled = "cancelled"
)

Task statuses. DESIGN.md names: taslak, hazır, alındı, çalışıyor, soru_bekliyor, review, bitti, teslim edildi, engellendi, iptal.

View Source
const ReviewNone = "none"

ReviewNone is the review override that disables review for a task.

Variables

View Source
var DepKinds = []string{"blocks", "review_of", "parent", "related"}

DepKinds are the allowed dependency kinds.

Statuses lists every status in lifecycle order.

Functions

func AddDep

func AddDep(ctx context.Context, tx *sql.Tx, taskID, kind, on string, expectVersion int64, actor Actor) error

AddDep adds edge taskID -> on of kind. For blocks, parent and review_of it rejects edges that would close a cycle. Adding an edge bumps the task's version (CAS against expectVersion when non-zero); an existing edge is a no-op.

func CanTransition

func CanTransition(from, to string) bool

CanTransition reports whether from -> to is allowed.

func RemoveDep

func RemoveDep(ctx context.Context, tx *sql.Tx, taskID, kind, on string, expectVersion int64, actor Actor) error

RemoveDep deletes edge taskID -> on of kind and bumps the task's version (CAS against expectVersion when non-zero); a missing edge is a no-op.

func ReopenReason added in v0.1.2

func ReopenReason(ctx context.Context, q db.Querier, taskID, runID string) (string, error)

ReopenReason is the reason of the reopen the run after runID follows: the task.reopened event that names runID as the task's latest run ("" = the task's first run; "" result = none).

func SetBranch added in v0.1.2

func SetBranch(ctx context.Context, tx *sql.Tx, id, branch string) (bool, error)

SetBranch stores the task's branch the first time its worktree is created; a task that has one keeps it. It reports whether it stored it.

func SetCurrentRun

func SetCurrentRun(ctx context.Context, tx *sql.Tx, id, runID string) error

SetCurrentRun points a claimed task at the run working on it (CAS on version).

func Terminal

func Terminal(s string) bool

Terminal reports whether s is a final status: no work is left. A done task still waits for its delivery (done -> delivered), which is not work.

func ValidStatus

func ValidStatus(s string) bool

ValidStatus reports whether s is a known status.

Types

type Actor

type Actor struct {
	Name   string // e.g. "user:enes" or "run:<id>"
	RunID  string
	Source string // events.source; default "cli"
}

Actor identifies who performs a mutation; recorded on events.

type AddInput

type AddInput struct {
	ProjectID   int64
	Prefix      string
	Title       string
	Body        string
	Priority    int
	Profile     string
	Draft       bool
	ExternalRef string
	Metadata    json.RawMessage
	ExtraPrompt string
	Deps        []DepRef
	Base        string // overrides the project's base ("" = the project's)
	Review      string // "" = the project's review_profile, ReviewNone, or a profile
}

AddInput describes a new task.

type Dep

type Dep struct {
	Kind   string `json:"kind"`
	TaskID string `json:"task_id"`
	Title  string `json:"title"`
	Status string `json:"status"`
}

Dep is one dependency edge as seen from a task.

type DepRef

type DepRef struct {
	Kind string
	On   string // task id
}

DepRef names a dependency edge from a new or edited task.

type EditInput

type EditInput struct {
	Title       *string
	Body        *string
	Priority    *int
	Profile     *string
	ExternalRef *string
	ExtraPrompt *string
	Metadata    json.RawMessage   // replaces the whole object
	MetaSet     map[string]string // merged keys; values parsed as JSON when valid
	AddDeps     []DepRef
	RemoveDeps  []DepRef
	// Base ("" = the project's again) is refused once the task has its worktree: the
	// branch already starts there.
	Base *string
	// Review: "" = the project's review_profile again, ReviewNone, or a profile. It
	// applies the next time the task finishes.
	Review        *string
	ExpectVersion int64 // 0 = no check
}

EditInput lists optional changes; nil pointers are left untouched.

type Filter

type Filter struct {
	ProjectID int64 // 0 = all projects
	Statuses  []string
	ReadyOnly bool // use the ready_tasks view (ready and unblocked)
	Open      bool // exclude done, delivered and cancelled
	// Deliverable: done tasks waiting for delivery, without review tasks (they are
	// delivered with the task they review).
	Deliverable bool
	// Recent orders by the last status change, newest first (instead of priority), so a
	// Limit keeps the latest.
	Recent bool
	Limit  int
}

Filter selects tasks for List.

type Push added in v0.1.2

type Push struct {
	Remote string `json:"remote"`
	Branch string `json:"branch"`
	SHA    string `json:"sha"`
	At     string `json:"at"`
}

Push records the last push of a task branch (`otag task push`).

type Task

type Task struct {
	ID              string          `json:"id"`
	Project         string          `json:"project"`
	ProjectID       int64           `json:"-"`
	Title           string          `json:"title"`
	Body            string          `json:"body"`
	Status          string          `json:"status"`
	StatusReason    string          `json:"status_reason"`
	Priority        int             `json:"priority"`
	Profile         string          `json:"profile"`
	CurrentRunID    string          `json:"current_run_id"`
	Version         int64           `json:"version"`
	ExternalRef     string          `json:"external_ref"`
	Metadata        json.RawMessage `json:"metadata"`
	ExtraPrompt     string          `json:"extra_prompt"`
	ClaimedBy       string          `json:"claimed_by"`
	ClaimedAt       string          `json:"claimed_at"`
	StatusChangedAt string          `json:"status_changed_at"`
	ClosedAt        string          `json:"closed_at"`
	DeliveredAt     string          `json:"delivered_at"`
	CreatedBy       string          `json:"created_by"`
	CreatedAt       string          `json:"created_at"`
	UpdatedAt       string          `json:"updated_at"`
	// Base overrides the project's base for this task ("" = the project's); frozen
	// once the task has its worktree (Branch set).
	Base string `json:"base"`
	// Branch is the task's branch, stored when its worktree is first created and used
	// from then on ("" = no worktree yet, or a same-mode project).
	Branch string `json:"branch"`
	// Review overrides the project's review_profile: "" = the project's, ReviewNone =
	// no review, else a profile.
	Review string `json:"review"`
	// Push is the last `otag task push` (nil = never pushed).
	Push *Push `json:"push"`
	// Deps are edges from this task; Dependents are edges pointing at it. Filled by Get.
	Deps       []Dep `json:"deps,omitempty"`
	Dependents []Dep `json:"dependents,omitempty"`
}

Task is a unit of work.

func Add

func Add(ctx context.Context, tx *sql.Tx, in AddInput, actor Actor) (*Task, error)

Add creates a task in status ready (or draft) and records task.created.

func Claim

func Claim(ctx context.Context, tx *sql.Tx, id string, expectVersion int64, actor Actor) (*Task, error)

Claim atomically takes a ready, unblocked task. With id == "" it takes the highest-priority ready task of projectID. Exactly one concurrent caller wins; the others get CONFLICT.

func ClaimNext

func ClaimNext(ctx context.Context, tx *sql.Tx, projectID int64, actor Actor) (*Task, error)

ClaimNext claims the next ready task of a project.

func ClaimWaiting

func ClaimWaiting(ctx context.Context, tx *sql.Tx, id string, expectVersion int64, actor Actor) (*Task, error)

ClaimWaiting takes over a waiting task whose run has ended (parked while its question is open, or ended without releasing the task) for the task's next run: waiting -> claimed. While a run of the task has not ended it is CONFLICT: that run owns the task. An open question stays open; its answer follows the task. `otag task claim` (Claim) still takes only ready tasks.

func Deliver

func Deliver(ctx context.Context, tx *sql.Tx, id, note string, expectVersion int64, actor Actor) (*Task, error)

Deliver moves a done task to delivered (compare-and-swap) with delivered_at and a task.delivered event; note is kept as the status reason. The caller (run.Manager. DeliverTask) removes the task's worktrees after the commit.

func Edit

func Edit(ctx context.Context, tx *sql.Tx, id string, in EditInput, actor Actor) (*Task, error)

Edit updates task fields (not status) with a version check.

func Get

func Get(ctx context.Context, q db.Querier, id string) (*Task, error)

Get returns a task with its dependency edges.

func List

func List(ctx context.Context, q db.Querier, f Filter) ([]Task, error)

List returns tasks ordered by priority then age (Filter.Recent: newest status change first).

func RecordPush added in v0.1.2

func RecordPush(ctx context.Context, tx *sql.Tx, id string, p Push, prev *Push, force bool, actor Actor) (*Task, error)

RecordPush stores a push of the task's branch and records task.pushed. prev is the push record the pusher read before pushing: if another push was recorded meanwhile it is a retryable CONFLICT and nothing is recorded (the remote has one of the two commits; push again to record it).

func Reopen added in v0.1.2

func Reopen(ctx context.Context, tx *sql.Tx, id, reason string, expectVersion int64, actor Actor) (*Task, error)

Reopen moves a done task back to ready (compare-and-swap): the same worktree and branch get another run. reason is required; it becomes the status reason and is recorded on the task.reopened event with the task's latest run ("run"), which is the run the next attempt follows, so its prior-attempt summary carries the reason. closed_at is cleared (it is set again when the task is done again). A delivered task is not reopened, nor is a review task (reopen the task it reviews). The caller (run.Manager.Reopen) marks the task's reviews stale and retracts its done notice in the same transaction.

func Transition

func Transition(ctx context.Context, tx *sql.Tx, id, to, reason string, expectVersion int64, actor Actor) (*Task, error)

Transition moves a task to status `to` if the status machine allows it.

Jump to

Keyboard shortcuts

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