taskquery

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 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 taskquery is the read model over a store snapshot: the structural tree, effective availability, and the selections the read surfaces render. It is the Go counterpart of lib/tasks/tree.rb and the read half of lib/tasks/task_queries.rb.

Nothing here writes. The whole package answers questions about a snapshot a caller is already holding, so two renderings of the same snapshot can never disagree.

Index

Constants

View Source
const (
	ReasonAvailable         = "available"
	ReasonScheduled         = "scheduled"
	ReasonOnHold            = "on_hold"
	ReasonAncestorScheduled = "ancestor_scheduled"
	ReasonAncestorOnHold    = "ancestor_on_hold"
	ReasonProposed          = "proposed"
	ReasonClosed            = "closed"
)

The reasons, in the order lib/tasks/task_queries.rb declares them.

View Source
const DefaultUrgentDays = 3

DefaultUrgentDays is the deadline window that counts as urgent.

View Source
const DeferTag = "defer"

DeferTag is the semantic tag that means someday/maybe. It rides ALONGSIDE the task's real state rather than replacing it, the same way important and urgent do, so a deferred NEXT action is still a NEXT action when it comes back.

Variables

View Source
var QuadrantLabels = [][2]string{
	{"Q1", "Q1 · Important + Urgent  (do now)"},
	{"Q2", "Q2 · Important, Not Urgent  (schedule)"},
	{"Q3", "Q3 · Urgent, Not Important  (delegate)"},
	{"Q4", "Q4 · Neither  (eliminate)"},
}

QuadrantLabels are the canonical headings, shared so the CLI and TUI never drift. Each frontend applies its own formatting around the text.

Functions

func ClosedStates

func ClosedStates() []string

ClosedStates is the finished vocabulary. `recur` reads it to refuse a live repeater on a task `done` can never reach to roll — dead recurrence that would sit in the file forever looking like a schedule.

func Headline

func Headline(item store.Item) string

Headline is the item's summary rendered from its own fields, star-less: state, optional priority cookie, title, trailing tag cluster in STORED order. One derivation, so the string can never fork between a read command and the report a mutation prints.

func Important

func Important(item store.Item) bool

Important is priority A or B, or the explicit tag.

func OpenStates

func OpenStates() []string

OpenStates is the accepted-and-not-finished vocabulary, which is the default scope for every ref.

func Quadrant

func Quadrant(item store.Item, today temporal.Date, urgentDays int) string

Quadrant is "Q1".."Q4" for an item.

func Recurring

func Recurring(item store.Item) bool

Recurring reports a VALID repeater cookie. A cookie that does not match the grammar reads as non-recurring so completion closes the task normally — Check still reports the bad cookie.

func StateOrder

func StateOrder() []string

StateOrder is the order the grouped human views print states in.

func Urgent

func Urgent(item store.Item, today temporal.Date, urgentDays int) bool

Urgent is a deadline inside the window — overdue counts — or the explicit tag. An available-from date alone never makes work urgent: "I can start" is not "I must finish".

Types

type APITime

type APITime struct {
	Local             string
	Timezone          string
	Fold              int
	EffectiveTimezone string
	Instant           string
}

APITime is TemporalValue#api_time: the stored halves plus what they resolve to for THIS reader. Both are needed — the stored zone is what the user wrote, the effective zone and instant are what it means right now.

type Availability

type Availability struct {
	Reason      string
	BlockerID   string
	Scheduled   temporal.Date
	Value       *temporal.Value
	AvailableAt time.Time
}

Availability is the effective answer for one item: why it is or is not workable now, and what would change that.

func (Availability) Available

func (a Availability) Available() bool

Available reports whether the item can be worked on now.

type Node

type Node struct {
	Title string
	Line  int
	Level int
	// ID is the record's stable 8-hex id — a task's or a section's. Sections
	// carry no Item, so the id lives on the node itself; it is what the
	// outliner's fold state and selection follow for section rows.
	ID       string
	Item     *store.Item // nil for a section
	Body     []string
	Children []*Node
	Parent   *Node
}

Node is one record in the structural index: a section or a task, with its own body lines and its children. Hierarchy comes straight from each record's `parent` pointer — no star counting, no block inference — so a whole class of boundary bugs is structurally absent.

func (*Node) OpenProject

func (n *Node) OpenProject() *Node

OpenProject is the task's project FOR GROUPING: the nearest ancestor headline that is a section or an OPEN task, climbing past closed ancestors. A closed ancestor is transparent, the same way the outliner hoists open descendants out of a closed parent. Deferred tasks count as open — a deferred project still owns its subtasks.

func (*Node) Project

func (n *Node) Project() *Node

Project is the nearest ancestor headline: a task's project, or a subtask's parent task.

func (*Node) Section

func (n *Node) Section() bool

Section reports a node that does not.

func (*Node) Task

func (n *Node) Task() bool

Task reports a node that carries an item.

type Option

type Option func(*Queries)

Option configures a read model at construction. The variadic form is deliberate: a reader that does not care about link configuration should not have to name it.

func WithLinkConfig

func WithLinkConfig(shorthands, systems map[string]string) Option

WithLinkConfig supplies the configured shorthand templates (`link.<name>`) and self-hosted system hosts (`system.<name>`).

type Override

type Override struct {
	// Deferred replaces the task's own indefinite-hold marker.
	Deferred *bool
	// Scheduled replaces the task's own available-from value when ScheduledSet.
	Scheduled *temporal.Value
	// ScheduledSet distinguishes "clear it" (nil) from "leave it alone".
	ScheduledSet bool
	// Lead replaces the task's own lead span; "" clears it.
	Lead *string
}

Override is the own-field substitution a PREVIEW applies before asking for an availability answer: "if this write landed, what would this task's availability be?"

It is Ruby's `availability_after(item, deferred:, scheduled:, lead:)`, and it is deliberately own-field only. Ancestor precedence still comes from the read model rather than being duplicated in the CLI, so a dry-run cannot disagree with the write it previews about who blocks whom.

Each field is a pointer because "not overridden" and "overridden to the clearing value" are different questions. Scheduled is a pointer to a value: nil with ScheduledSet true means "the write clears the available-from date".

type ProjectView

type ProjectView struct {
	ID          string
	Title       string
	ParentID    string
	HasParentID bool
	Kind        string
	Line        int
	OpenCount   int
	NextCount   int
	NextDate    temporal.Date
	HasNextDate bool
	NextTime    APITime
	HasNextTime bool
	NextAt      time.Time
	Stuck       bool
	Body        string
	HasBody     bool
	TaskIDs     []string
	HeldCount   int
}

ProjectView is the canonical project/area resource: a section rolled up over its open, non-deferred descendant tasks at any depth.

Kind distinguishes a project (a section under the top-level "Projects" heading) from an area (any other top-level list that currently holds open work). Stuck flags a project or area with no open NEXT action — including one with zero open tasks. Line is the physical coordinate for adapters; like the task resource it never appears in the JSON, keeping reusable resources free of file positions. NextDate is the soonest deadline-or-scheduled date across the rolled-up open tasks, the key the listing sorts on (absent sorts last). HeldCount counts open descendant tasks excluded from the rollup because they are deferred or held (own or inherited hold); the archive refusal treats them as open work too, so a parked-but-open project cannot be swept by accident.

type Queries

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

Queries is the read model over one snapshot for one reader.

func New

func New(snapshot *store.Snapshot, context temporal.Context, options ...Option) *Queries

New builds the read model. The tree indexes the LIVE file only; archive items have no structural context by construction, which is why an archived item's availability is `closed` without a walk.

func (*Queries) APITimeFor

func (q *Queries) APITimeFor(value temporal.Value, present bool) (APITime, bool)

APITimeFor renders a value's time half, or ok=false for an all-day value, which has no wall time to report.

func (*Queries) AgendaItems

func (q *Queries) AgendaItems() []store.Item

AgendaItems is the `agenda` view: every OPEN, AVAILABLE item carrying a date, soonest first, priority breaking ties, file order breaking those.

func (*Queries) ArchiveItems

func (q *Queries) ArchiveItems() []store.Item

ArchiveItems is the swept file's tasks in file order. Only the surfaces that deliberately widen to closed history read it.

func (*Queries) AvailabilityAfter

func (q *Queries) AvailabilityAfter(item store.Item, override Override) Availability

AvailabilityAfter is the availability an item WOULD have if the named own fields took the given values. Never cached: it answers about a task that does not exist yet.

func (*Queries) AvailabilityFor

func (q *Queries) AvailabilityFor(item store.Item) Availability

AvailabilityFor is the effective availability of an item INCLUDING every task ancestor. Closed ancestors stay transparent to lifecycle hoisting, but their own timed or indefinite blocker still participates in this walk — a hold on a finished parent is still a hold the subtree inherited.

func (*Queries) Body

func (q *Queries) Body(item store.Item) []string

Body is the item's own body lines. It never includes a child's body — children are separate records.

func (*Queries) Context

func (q *Queries) Context() temporal.Context

Context is the reader this model answers for.

func (*Queries) DeadlineValue

func (q *Queries) DeadlineValue(item store.Item) (temporal.Value, bool)

func (*Queries) Deferred

func (q *Queries) Deferred(item store.Item) bool

Deferred reports the someday/maybe hold.

func (*Queries) FindLive

func (q *Queries) FindLive(id string) (store.Item, bool)

FindLive is the live item with this id, if any. Availability names a blocker by id; a renderer that wants its title has to look it up.

func (*Queries) InboxItems

func (q *Queries) InboxItems() []store.Item

InboxItems is the `inbox` view: unfiled captures that are workable now, in file order. There is no ranking — an inbox is a queue to triage, not a list to choose from.

func (*Queries) LeadAnchorValue

func (q *Queries) LeadAnchorValue(item store.Item) (temporal.Value, bool)

LeadAnchorValue is the stamp a lead is measured back from: the deadline when there is one, otherwise the available-from date.

func (*Queries) LeadOpens

func (q *Queries) LeadOpens(item store.Item) (temporal.Date, bool)

LeadOpens is the date this task's OWN lead window opens. It is present even while an ancestor's gate or a hold is what currently hides the task, and absent once `activate` has released the current occurrence.

func (*Queries) LeadOpensAt

func (q *Queries) LeadOpensAt(item store.Item) (time.Time, bool)

LeadOpensAt is the same window as an instant, which is the only shape a clock lead can be expressed in.

func (*Queries) LeadOpensValue

func (q *Queries) LeadOpensValue(item store.Item) (temporal.Value, bool)

LeadOpensValue is the window's explaining value: the date, plus the wall time when a CLOCK lead put the opening at an instant no date can express. A renderer needs the whole value, not only its date, or a clock lead would print the day it opens and lose the hour.

func (*Queries) LeadWindowValue

func (q *Queries) LeadWindowValue(item store.Item) (temporal.Value, bool)

LeadWindowValue is where this task's lead window sits for its CURRENT anchor, whether or not `activate` has already released it. That is the question `show` asks: the record still carries the span, and a reader looking at the record wants to see the date it produces. LeadOpensValue answers the other question — "is a window still holding this task back" — and is what the availability-shaped surfaces read.

func (q *Queries) Links(item store.Item) []links.Link

Links is every web link the task points at: stored formal links first, then its title and body. URL dedupe keeps the first position while allowing a later labelled spelling to upgrade an unlabelled one in place.

func (*Queries) List

func (q *Queries) List(filter query.Filter) []store.Item

List selects the items a filter names, in file order.

func (*Queries) LiveItems

func (q *Queries) LiveItems() []store.Item

LiveItems is the live file's tasks in file order — the population ref resolution addresses. The archive is deliberately absent: a ref names something you can still act on.

func (*Queries) NextItems

func (q *Queries) NextItems() []store.Item

NextItems is the `next` view: every available NEXT action, ranked by priority. Ties keep file order — Ruby's sort_by is unstable, so this has to be an explicitly stable sort or same-priority rows shuffle between runs, and the canonical order the API and the TUI share would be nondeterministic.

func (*Queries) NodeFor

func (q *Queries) NodeFor(item store.Item) *Node

NodeFor is the tree node an item sits at, or nil for an archive item.

func (*Queries) Project

func (q *Queries) Project(item store.Item) (string, bool)

Project is the task's project FOR DISPLAY: the title of the nearest ancestor headline that is a section or an open task. A task whose every ancestor is a closed task, and which has no section above it, has none — it falls out of the Projects view rather than heading a dead group.

func (*Queries) ProjectView

func (q *Queries) ProjectView(id string) (ProjectView, bool)

ProjectView is a single project, area or reserved GTD list by section id, or ok=false when the id is not such a section: a task, the Projects heading, a nested sub-section, or an area with no open work today.

func (*Queries) Projects

func (q *Queries) Projects() []ProjectView

Projects is every project and area as a rolled-up view.

Projects are the section children of the top-level "Projects" heading, listed even when empty — an empty project is a commitment you have not started, and hiding it is how a project goes quietly missing. Areas are the other top-level lists that currently hold open, non-deferred work, excluding the reserved GTD lists (see reservedListTitles), the Projects heading itself, and everything inside its subtree (a nested sub-section rolls up into its project rather than listing beside it).

Sorted projects before areas, then by soonest date (dateless last), then title, then file order.

func (*Queries) QuadrantItems

func (q *Queries) QuadrantItems() []store.Item

QuadrantItems is the `quadrants` view: every OPEN, AVAILABLE task in file order, each paired with the quadrant it falls in. Order is the file's — the grouping is the view, not a sort.

func (*Queries) QuadrantOf

func (q *Queries) QuadrantOf(item store.Item, urgentDays int) string

QuadrantOf classifies against this reader's own today.

func (*Queries) Record

func (q *Queries) Record(item store.Item) (record.Record, bool)

Record is the raw record an item came from.

func (*Queries) ReservedLists added in v1.8.0

func (q *Queries) ReservedLists() []ProjectView

ReservedLists is every addressable reserved GTD list — the top-level sections the Projects listing deliberately omits, minus Inbox, which stays unaddressable. Callers that resolve a section by ref use it to widen the listing's candidate set without widening the listing itself.

func (*Queries) ScheduledValue

func (q *Queries) ScheduledValue(item store.Item) (temporal.Value, bool)

ScheduledValue and DeadlineValue are the stored date plus whatever wall time and zone qualify it. They are built from the RECORD rather than the item so the time object travels with the date it belongs to.

func (*Queries) SectionView added in v1.8.0

func (q *Queries) SectionView(id string) (ProjectView, bool)

SectionView is a rolled-up view of ANY live section by id — not just the projects and areas the Projects listing admits. The outline renders every section as a selectable row, and the row's actions (rename, capture, complete, archive) all take a bare section id, so the view exists for sections the listing would exclude: Inbox, the Projects heading, nested sub-sections, and areas with no open work.

Kind is resolved the same way the listing resolves it — "project" for a child of the Projects root, "area" for any other top-level section — and falls back to "list" for everything nested deeper.

func (*Queries) Snapshot

func (q *Queries) Snapshot() *store.Snapshot

Snapshot is the exact read this model was built over. A caller that already holds the queries can ask for the underlying records — the section list, the raw live half — without capturing a SECOND snapshot that could disagree with the one every other answer came from.

func (*Queries) Today

func (q *Queries) Today() temporal.Date

Today is the reader's own calendar day, which every date-sensitive read is measured against.

func (*Queries) Tree

func (q *Queries) Tree() Tree

Tree is the structural index over the live file.

type Tree

type Tree struct {
	Roots       []*Node
	NodesByLine map[int]*Node
}

Tree is the forest plus the line index every per-item lookup goes through.

func BuildTree

func BuildTree(records []record.Record, items []store.Item) Tree

BuildTree reconstructs the forest in one pass over the live records, linking each to its parent by id. The file is in DFS pre-order, so a single forward pass suffices and no ordering is inferred.

Jump to

Keyboard shortcuts

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