task

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 14 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 holds the tasks and their pure rules.

Index

Constants

View Source
const (
	EventCreated = "task_created"
	EventLinked  = "task_linked"
)

The events of a task's own unit the tasks service records: EventCreated when sync derives the task, or a person captures one on a unit (a capture with no unit, and a task another service opens, record none); EventLinked when a link lands on an item the task holds.

View Source
const (
	OverTasks = "tasks"
	OverGates = "gates"
)

What a view lists: the stored tasks, or the gates.

View Source
const (
	PropKind = "kind"
	// PropOwner is who owns the task; the waiting verb's on names it.
	PropOwner = "owner"
	// PropCheckOn is when to check on a task someone else owes; the waiting verb's resurface sets it.
	PropCheckOn = "check_on"
	// PropLastNudge is when a nudge last went to whoever owes the task; the task.nudged effect writes it.
	PropLastNudge = "last_nudge"
	// PropUnfollowed is when reconcile dropped a unit's own task because nobody followed the unit any more, so
	// following it again brings the task back; a person's drop never sets it.
	PropUnfollowed = "unfollowed"
)

The properties the loop's own rules read, as the bundled tasks.toml declares them.

View Source
const (
	OriginDerived = "derived"
	OriginUser    = "user"
	OriginMessage = "message"
	OriginDraft   = "draft"
	OriginGate    = "gate"
)
View Source
const ArgTask = "task"

ArgTask is the argument of a merge, split, relate or unrelate request that names the other task by id: the task to merge with, the one merged in to split out, the one to relate or unrelate.

View Source
const DefaultReviewEvery = 7 * 24 * time.Hour

DefaultReviewEvery is the review interval of a project that sets none.

View Source
const IDPrefix = "t-"

IDPrefix starts every task id.

View Source
const KindProject = "project"

KindProject is the value of the kind property the project verb gives the parent it creates, and the one it attaches tasks to.

Variables

Actors are every actor.

Categories are every category, in the order a task moves through them.

View Source
var ErrNoStateOf = errors.New("the profile declares no state of the category")

ErrNoStateOf is a move into a category the profile declares no state of.

View Source
var LoopRoles = []Role{RoleRelated, RoleMerged}

LoopRoles are the roles whose property only the loop's handlers write, so no writer may write it.

PropTypes are every property type.

RoleTypes are the type of the property each role acts on.

Roles are every role.

Writers are every writer.

Functions

func ActiveSince

func ActiveSince(f UnitFacts, e Task) bool

ActiveSince says whether a person's activity on f.Unit came after the user saw task e, or after e was made when they never did.

func AddWorkdays

func AddWorkdays(t time.Time, n int, loc *time.Location) time.Time

AddWorkdays is t moved n working days (Monday to Friday) forward, at the same clock time in loc.

func PairKey added in v0.4.0

func PairKey(other ID, at time.Time) string

PairKey is the key of the event a verb that pairs a task with other records at, unique per run: other's id, then the time.

func ParseDeadline

func ParseDeadline(s string, loc *time.Location) (time.Time, bool)

ParseDeadline reads an item's deadline: RFC 3339 as is, "YYYY-MM-DD" as 18:00 that day in loc, anything else none.

func UnitOf

func UnitOf(id ID) unit.Unit

UnitOf is the task provider's unit of id.

func VerbEventKind

func VerbEventKind(v Verb) string

VerbEventKind is the kind of the event running v on a task records.

func VerbEventKinds

func VerbEventKinds(verbs []string) []string

VerbEventKinds are the kinds of the events of verbs, the profile's.

Types

type Actor

type Actor string

Actor is who ran a transition or resolved a gate; the same set as Writer.

const (
	ActorPerson   Actor = "person"
	ActorWorkflow Actor = "workflow"
	ActorAgent    Actor = "agent"
	ActorPlugin   Actor = "plugin"
)

type Category

type Category string

Category is the closed set a profile's state belongs to; Go reads a task's category, never its state's name.

const (
	CategoryInbox    Category = "inbox"
	CategoryReady    Category = "ready"
	CategoryActive   Category = "active"
	CategoryWaiting  Category = "waiting"
	CategoryDeferred Category = "deferred"
	CategoryDone     Category = "done"
	CategoryDropped  Category = "dropped"
)

type Change

type Change struct {
	Op   ChangeOp
	Task Task
	Why  string
}

func Activity

func Activity(f UnitFacts, its []items.Item, me Me, have []Task, now time.Time) []Change

Activity marks Changed the tasks of f.Unit parked on someone else when f.LastHuman is after what the user saw (SeenAt, or Created before any): a deferred task, or an open one out of the inbox that has an owner but me, a date to check on it, or an item of its that waits on someone but me. It moves no task: a task never returns to the inbox on activity, and a wake on activity is the wakes' to match.

func Reconcile

func Reconcile(f UnitFacts, its []items.Item, me Me, have []Task, st Profile, now time.Time) ([]Change, error)

Reconcile is what the items of one unit call for, given the tasks that hold them or the unit.

One task per task key (items.Item.TaskKey, else the item id) of the open items that wait on Me, or that Me requested, is assigned while no other assignee owes it, or f.Cares about, and wait on others. An item a task already holds stays with that task, so a task the user merged keeps its items, and every item of a key goes to the task holding one of them. A key no task holds that names f.Unit goes to the unit's own task (UnitTask) while it is open, else to the oldest open task holding f.Unit as a link, such as a task you started whose pull request was attached, else to its own closed one; any other gets a new task, DerivedID of the key, in the first state of the category its first item proposes (items.Item.Initial), else the inbox for an item waiting on Me and the waiting category for one waiting on others. A new task takes the item's contexts and deadline in the properties of RoleContexts and RoleDeadline, and the kind f.Kind names, as the plugin writes them.

An open task keeps an item it holds while the item waits on someone, even once no rule above calls for it, except an item of the key that names f.Unit. A derived task none of whose items calls for it any more is resolved into the done category. The task of a key that names f.Unit, the unit's one task, is dropped once its card says the user no longer Cares about the unit (PropUnfollowed), to come back when they do again, and, while it holds no other unit, is resolved only when an item of its key resolved after the task last opened or closed (OpenChanged), so one the user opened again stays open until the unit moves. An item of that key that waits on nobody keeps the task while f Cares. A task that was clarified never returns to the inbox: a done task moves back into the ready category with Changed set only when its unit asks something new of Me, an item waiting on Me that the task did not hold or that asked again after the task last closed, or when an item the task held as resolved opens again after that; an item that opens again on an open task sets Changed and keeps its state. A task the user dropped stays dropped.

Never changes the state, the parent or a property the user set, except to resolve and to reopen as said.

Due: items.Item.Deadline in RFC 3339 is taken as is; "YYYY-MM-DD" is 18:00 in now's location that day; anything else is none.

type ChangeOp

type ChangeOp string
const (
	OpCreate  ChangeOp = "create"
	OpUpdate  ChangeOp = "update"
	OpResolve ChangeOp = "resolve"
)

type Codec

type Codec struct{}

Codec is the codec of the task provider: a unit's key is a task's ID.

func (Codec) Provider

func (Codec) Provider() unit.ProviderID

func (Codec) Valid

func (Codec) Valid(key string) error

Valid accepts a non-blank key without spaces or line breaks.

type Counters

type Counters struct {
	Area     string
	Views    map[View]int   // every view that lists something, narrowed to Area
	Areas    map[string]int // the open tasks per area
	Contexts map[string]int // the open tasks per context, within Area
	Badge    int            // the sum of the views the profile's badge names
}

Counters are the counts of the profile's views over Area ("" every area).

type ID

type ID string

ID is "t-" + 16 hex. A task an item calls for: DerivedID, so a re-derivation is idempotent; captures and projects: random. Draft tasks: "draft:<draft id>".

func DerivedID

func DerivedID(u unit.Unit, item string) ID

DerivedID is the id of the task item of u calls for, so a re-derivation finds it again. It hashes as the action entries of schema version 6 did, so the tasks they became keep matching their items.

func IDOf

func IDOf(u unit.Unit) (ID, bool)

IDOf is the task u names; false for a unit of another provider.

func NewID

func NewID() ID

NewID is a random task id.

func PairOfKey added in v0.4.0

func PairOfKey(key string) (ID, bool)

PairOfKey is the other task of an event PairKey keyed; false for a key it did not write.

type ItemRef

type ItemRef struct {
	Unit unit.Unit
	Item string
}

ItemRef names an items.Item.ID of a unit.

type Me

type Me = items.Identity

Me is the user's identity over the enabled plugins (items.Identity; Person.Is(Me)).

type Profile

type Profile interface {
	States
	PropOf(r Role) (name string, values []string)
}

Profile is the profile as the rules read it: its states, and the property each role acts on with its values, "" for a role no property takes.

type PropType

type PropType string

PropType is the type a profile declares for a task property.

const (
	PropString   PropType = "string"
	PropStrings  PropType = "string[]"
	PropInt      PropType = "int"
	PropEnum     PropType = "enum"
	PropDate     PropType = "date"
	PropDuration PropType = "duration"
	PropActor    PropType = "actor"
	PropActors   PropType = "actor[]"
)

type Props

type Props map[string]Value

Props are a task's properties by name; a property never set is absent.

func (Props) Get

func (p Props) Get(name string) (Value, bool)

Get is the value of the property name, false when it was never set.

type Query

type Query struct {
	View     View
	Area     string
	Contexts []string
	All      bool
}

Query selects a view's tasks, narrowed to the tasks whose area is Area and that hold every one of Contexts. A store reads All only: every task when true, else the open ones (neither done nor dropped).

type ReviewRun

type ReviewRun struct {
	ID         string
	StartedAt  time.Time
	FinishedAt time.Time // zero while a step is open
	Done       []string
}

ReviewRun is one review: when it started, the steps done (the views they walk), and when the last of them was.

type Role

type Role string

Role is a mechanism of the loop that reads or writes a task property: the profile's tasks.toml gives it to the property it acts on, so Go names the role and never the property.

const (
	// RoleArea is the property the area filter of the lists and their counters reads, which the area handler
	// sets and a new parent takes from the task it starts with: a string.
	RoleArea Role = "area"
	// RoleContexts is the property the contexts filter reads, which the context handler sets and a task takes
	// from the item or the request that opens it: a string[].
	RoleContexts Role = "contexts"
	// RoleStar is the property the star handler toggles between its first value, starred, and its second: an
	// enum.
	RoleStar Role = "star"
	// RoleDeadline is the property a task takes from its items' deadline, and a draft's task from its gate's
	// window: a date.
	RoleDeadline Role = "deadline"
	// RolePromise is the property the promise handler sets from the time you promise an answer by, which the
	// fact task.promised reads: a date.
	RolePromise Role = "promise"
	// RoleRelated is the property that lists, by id, the tasks the relate handler linked to the task, which
	// relate and unrelate keep the same on both: a string[].
	RoleRelated Role = "related"
	// RoleMerged is the property that lists, by id in merge order, the tasks the merge handler folded into the
	// task, each followed by those merged into it before: a string[]. Split gives back the ones whose merge
	// record names the task. While it lists one, Reconcile treats the task as the holder of every unit it took
	// in:
	//   - when no item of unit u calls for it, only u's items move to its resolved ones; it resolves into the
	//     done category once it holds no open item of any unit, and drops on unfollow only then;
	//   - an item no task holds whose derived id is one it lists goes to it, whatever its state, so a merged
	//     task's id is never derived again;
	//   - its title no longer follows its single item.
	RoleMerged Role = "merged"
)

The roles, a closed set.

type State

type State string

State is a state the profile declares (tasks.toml); Go reads its Category, never its name.

type States

type States interface {
	CategoryOf(state string) (Category, bool)
	FirstOf(c Category) string
}

States are the profile's states as the rules read them: the category of a state, and the first state of a category, which a task moved into that category takes.

type Task

type Task struct {
	ID ID
	// State is the task's state; Category is its category, which every rule reads.
	State    State
	Category Category
	Title    string
	Notes    string
	Items    []ItemRef
	// Resolved are the items the task held that no longer call for it, such as one resolved: they keep the
	// task as their holder, so an item that opens again comes back to it.
	Resolved []ItemRef
	Units    []unit.Unit // attached units; their cards render in the detail
	// Props are the task's properties; Written says who wrote each, and when.
	Props      Props
	Written    map[string]Written
	Parent     ID  // "" none
	Position   int // order among its parent's children
	Sequential bool
	// Asleep says the task holds a wake (wake.Wake), as the store reads it; writing a task leaves its wake as
	// it is.
	Asleep  bool
	Changed bool // "changed since you saw it"; cleared by the seen verb
	SeenAt  time.Time
	Origin  string // "derived", "user", "message", "draft"

	Created, Updated time.Time
	// OpenChanged is when the task last opened or closed: the Updated of the write that moved it between an
	// open category and done or dropped, or of its first write; the store keeps it.
	OpenChanged time.Time
	// ClosedAt is when the task last moved from an open category to done or dropped, as the store stamps it;
	// zero when it never did since schema version 15.
	ClosedAt time.Time

	// A parent's review interval (zero: DefaultReviewEvery) and last review.
	ReviewEvery time.Duration
	ReviewedAt  time.Time
}

func Place

func Place(others []Task, e Task, pos int) []Task

Place puts e among its project's other actions at position pos (1 first; past the end, last) and numbers them all from 1 in that order.

func UnitTask

func UnitTask(ts []Task, u unit.Unit) (Task, bool)

UnitTask is u's own task among ts, whatever its state: of the tasks whose first unit is u, an open one first, the one holding an item of u, then the oldest, then by id; with none open, the one updated last.

func (*Task) Become

func (e *Task) Become(s State, st States)

Become moves the task to state s, in the category st declares of it; an undeclared state keeps the task's category.

func (Task) CapturedByUser

func (e Task) CapturedByUser() bool

CapturedByUser says whether the user made the task, rather than the loop deriving it from a source's items or opening it for a gate.

func (Task) FirstUnit

func (e Task) FirstUnit() (unit.Unit, bool)

FirstUnit is the unit the task is about: its first unit, else its first item's.

func (Task) IsProject

func (e Task) IsProject() bool

IsProject says whether the task is a project, as its kind property says.

func (Task) LinkedUnits added in v0.4.0

func (e Task) LinkedUnits() []unit.Unit

LinkedUnits are the units the task links: its units, then its items' units, each once.

func (*Task) MoveTo

func (e *Task) MoveTo(c Category, st States) error

MoveTo moves the task into category c, in the first state st declares of it; ErrNoStateOf, naming c, when st declares none, and the task is left as it was.

func (Task) Open

func (e Task) Open() bool

Open says whether the task is still to do: its category is neither done nor dropped.

func (Task) Prop

func (e Task) Prop(name string) Value

Prop is the task's property name; a zero Value when it is unset.

func (Task) ReviewDue

func (e Task) ReviewDue(now time.Time) bool

ReviewDue says whether project e's interval passed at now since its last review, or since it was created when it was never reviewed.

func (Task) ReviewInterval

func (e Task) ReviewInterval() time.Duration

func (Task) Role

func (e Task) Role(p Profile, r Role) Value

Role is the value of the property role acts on in p; a zero Value when no property takes it or it is unset.

func (Task) Same

func (e Task) Same(o Task) bool

Same says whether e and o hold the same values, Updated aside.

func (*Task) SetProp

func (e *Task) SetProp(name string, v Value, by Writer, at time.Time)

SetProp sets the property name to v as by wrote it at at; a zero v unsets it. Setting the value it holds, by the writer that wrote it, changes nothing.

func (*Task) SetRole

func (e *Task) SetRole(p Profile, r Role, v Value, by Writer, at time.Time)

SetRole sets the property role acts on in p, as SetProp does; nothing when no property takes it.

func (Task) Snoozed

func (e Task) Snoozed() bool

Snoozed says whether the task is deferred under a wake.

type UnitFacts

type UnitFacts struct {
	Unit          unit.Unit
	StartedByMe   bool
	ClosurePosted bool
	Cares         bool      // followed/watched by the user, or the user's own unit
	Carded        bool      // the unit's card is stored, so Cares says what its plugin reported
	LastHuman     time.Time // newest human event not by the user (card.LastHuman when !Who.Is(Me))
	// Kind is the value of the kind property the unit's plugin gives the tasks of its units, such as thread;
	// "" gives none.
	Kind string
}

UnitFacts are what the rules need beyond the items, from the plugin's card.

type Value

type Value struct {
	Text   string         `json:"text,omitempty"`
	Int    int64          `json:"int,omitempty"`
	Time   time.Time      `json:"time,omitzero"`
	Dur    time.Duration  `json:"dur,omitempty"`
	Actors []items.Person `json:"actors,omitempty"`
	List   []string       `json:"list,omitempty"`
}

Value is a property's value: the field its PropType names is set, the others are zero. Text holds string and enum, Int int, Time date, Dur duration, Actors actor and actor[] (one person for actor), List string[].

func (Value) IsZero

func (v Value) IsZero() bool

IsZero says whether v holds no value, which unsets a property.

type Verb

type Verb string
const (
	VerbNext      Verb = "next"
	VerbWaiting   Verb = "waiting"
	VerbSchedule  Verb = "schedule"
	VerbWake      Verb = "wake"
	VerbSomeday   Verb = "someday"
	VerbReference Verb = "reference"
	VerbFocus     Verb = "focus"
	VerbProject   Verb = "project"
	VerbApprove   Verb = "approve"
	VerbDelegate  Verb = "delegate"
	VerbDone      Verb = "done"
	VerbDismiss   Verb = "dismiss"
	VerbSeen      Verb = "seen"
	VerbContext   Verb = "context"
	VerbArea      Verb = "area"
	VerbAnswer    Verb = "answer"
	VerbEdit      Verb = "edit" // drafts only, registered by the outbox
	VerbRetry     Verb = "retry"
	VerbReply     Verb = "reply" // a draft the user writes on the task's unit, served by the daemon
	VerbMerge     Verb = "merge"
	VerbSplit     Verb = "split"
	VerbRelate    Verb = "relate"
	VerbUnrelate  Verb = "unrelate"
)
const (
	VerbReviewed   Verb = "reviewed"
	VerbSequential Verb = "sequential"
)

The project verbs; position is an argument of VerbProject.

type View

type View string

View is a view's id, as the profile's views.toml names it.

type Writer

type Writer string

Writer is who wrote a property.

const (
	WriterPerson   Writer = "person"
	WriterWorkflow Writer = "workflow"
	WriterAgent    Writer = "agent"
	WriterPlugin   Writer = "plugin"
)

func (Writer) Trusted

func (w Writer) Trusted() bool

Trusted says whether an approval rule may read what w wrote: an agent's and a plugin's writes come from text no person vouched for.

type Written

type Written struct {
	By Writer
	At time.Time
}

Written is who last wrote a property, and when.

Jump to

Keyboard shortcuts

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