taskquery

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 16 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 (
	AgendaOverdue  = "overdue"
	AgendaToday    = "today"
	AgendaTomorrow = "tomorrow"
	AgendaLater    = "later"
)

The agenda's day buckets, by key.

View Source
const (
	BlockApprovals = "approvals"
	BlockInbox     = "inbox"
)

Inbox blocks: the intake tab is two queues, one above the other.

View Source
const (
	SectionInbox        = "inbox"
	SectionProjectsRoot = "projects_root"
	SectionProject      = "project"
	SectionArea         = "area"
	SectionList         = "list"
	SectionSubsection   = "subsection"
)

Section kinds. They name the ROLE the model already gives a section, not a stored field — sections carry no role of their own yet, so the Inbox, the Projects root and the saved GTD lists are recognised by title exactly as the Projects listing recognises them.

View Source
const (
	OutlineSectionNode = "section"
	OutlineTaskNode    = "task"
)

Outline node kinds.

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 (
	ViewAgenda    = "agenda"
	ViewNext      = "next"
	ViewQuadrants = "quadrants"
	ViewProjects  = "projects"
	ViewOutline   = "outline"
	ViewInbox     = "inbox"
)

The named views, spelled once. The TUI's tab keys are these values.

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.

View Source
const RejectedRecentDays = 30

RejectedRecentDays is what "recent" means for a declined proposal, in both the CLI's `list --rejected` and the TUI's show-rejected toggle: the decline happened within this many days of the reader's today, counting today as day zero. One number, in one place, so the two surfaces can never disagree about which rejects are still reachable — and so a store that has been running for years does not turn the restore list into an archive browser.

View Source
const UnfiledIntake = "Inbox"

UnfiledIntake is the one bucket every intake row with no project of its own lands in: a task sitting directly in the file's Inbox section, and a task sitting under no section at all, are the same thing to a reader triaging them — unfiled. It is a display key as well as a bucket key, so it is spelled the way the file spells that section rather than as a marker word.

Variables

View Source
var AgendaBuckets = [][2]string{
	{AgendaOverdue, "Overdue"},
	{AgendaToday, "Today"},
	{AgendaTomorrow, "Tomorrow"},
	{AgendaLater, "Later"},
}

AgendaBuckets are the agenda's groups in painted order, with the label a surface prints. The TUI shouts them in its section rules; the text is the same word either way.

NamedViews are the views NamedView answers. Projects has its own resource and the outline its own shape (see Outline), so neither is here.

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 DayBucket added in v1.18.0

func DayBucket(days int, scheduled bool) string

DayBucket classifies a day delta. `scheduled` marks a date that is a start date rather than a deadline: a start date that has already passed is not overdue, it is startable, so it lands in TODAY.

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 OutlineHiddenClosedCount added in v1.18.0

func OutlineHiddenClosedCount(node *Node, showClosed bool) int

OutlineHiddenClosedCount is how many closed tasks and closed sections the closed toggle is holding back beneath a node. It is zero while closed rows are shown: nothing is being held back.

func OutlineRenders added in v1.18.0

func OutlineRenders(node *Node, showClosed bool) bool

OutlineRenders reports whether anything at all paints beneath a node — not `len(node.Children) > 0`, because a hidden row is transparent and a task whose only children are hidden paints nothing under it.

func OutlineShownCount added in v1.18.0

func OutlineShownCount(node *Node, showClosed bool) int

OutlineShownCount is every task beneath a node that the Outline is showing, folded or not — the number a section's badge carries.

func OutlineShows added in v1.18.0

func OutlineShows(node *Node, showClosed bool) bool

OutlineShows reports whether the Outline paints a node's own row. A closed section, and a task the Outline's view rule hides (a proposal, or a closed task while closed rows are hidden), is TRANSPARENT rather than pruned: its children carry on at the same depth, which is what keeps an open task from vanishing under a parent someone completed.

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 ReservedListTitle added in v1.17.0

func ReservedListTitle(title string) bool

ReservedListTitle reports whether a top-level section title is one of the saved GTD lists whose membership is already expressed by task state. These lists remain addressable sections, but callers should not present them as a project or area label beside the task's own state.

func ResolveUrgentDays added in v1.18.0

func ResolveUrgentDays(options ...Option) int

ResolveUrgentDays is the window a read model built with these options classifies against, for a surface that must publish it without a snapshot in hand (the API's /meta). Resolving through the options themselves keeps it one source: there is no second `urgent_days` to drift from Task.quadrant.

func SectionActionRefusal added in v1.18.0

func SectionActionRefusal(kind, action string) string

SectionActionRefusal is why a section cannot take a structural action, or "" when it can. action is "rename", "complete", "drop", "reopen" or "archive".

Two sections hold the file together rather than holding work: the Inbox is where every unfiled capture lands, and the Projects root is what makes its children projects. Renaming, closing or archiving either would silently change where captures go or what counts as a project, so they are refused. Reopening is always allowed — it is the way back if one was closed anyway.

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 Group added in v1.18.0

type Group struct {
	Key   string
	Nodes []*Node
}

Group is one named bucket of nodes, already sorted.

type NamedViewOptions added in v1.18.0

type NamedViewOptions struct {
	// UrgentDays overrides the quadrant urgency horizon; zero means the read
	// model's own configured window (WithUrgentDays), the one QuadrantFor
	// classifies a single task against.
	UrgentDays int
	// IncludeUnavailable is the TUI's Z toggle: rows that are held, deferred
	// or not yet startable are admitted instead of hidden. It never reaches
	// Approvals, which is a decision queue with no availability gate.
	IncludeUnavailable bool
}

NamedViewOptions are the reader's choices a view honours.

type NamedViewResult added in v1.18.0

type NamedViewResult struct {
	Name   string
	Items  []store.Item
	Groups []ViewGroup
}

NamedViewResult is one named view: every row it admits, each once, in the view's canonical order — the order `tasks <view>` prints — and the groups a grouped surface lays them out in. A row can sit in several groups (a task with two contexts in Next) but appears in Items once.

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
	// State and Closed are the section lifecycle pair when this node is a
	// section. Tasks carry lifecycle on their Item, sections carry it here
	// so row builders can ask a node directly without a second lookup.
	State     string
	Closed    string
	HasClosed bool
}

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) IsClosed added in v1.17.0

func (n *Node) IsClosed() bool

IsClosed reports whether this section node is closed.

func (*Node) Open added in v1.17.0

func (n *Node) Open() bool

Open reports whether this section node is open.

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) ProjectSection added in v1.17.0

func (n *Node) ProjectSection() *Node

ProjectSection climbs ancestors to the section that is a child of the Projects root, or nil when there is none. It is the resolver the task detail rail uses to name the project a task belongs to.

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.

func (*Node) TopLevelSection added in v1.17.0

func (n *Node) TopLevelSection() *Node

TopLevelSection returns the outermost section containing this node. It is nil for a detached task or section. Presentation callers use it only after ProjectSection returns nil, so a task filed under Projects still names its concrete project rather than the Projects root.

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 WithDocLinkPatterns added in v1.19.0

func WithDocLinkPatterns(patterns []string) Option

WithDocLinkPatterns supplies the configured `doc_link_patterns`: URL shapes classified as the `doc` system ahead of any host row.

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>`).

func WithUrgentDays added in v1.18.0

func WithUrgentDays(days int) Option

WithUrgentDays supplies the configured `urgent_days` window. A value below one keeps DefaultUrgentDays, the same fallback every surface applies.

type OutlineCounts added in v1.18.0

type OutlineCounts struct {
	// Shown is what the Outline paints beneath the section right now.
	Shown int
	// Open and Closed count tasks by lifecycle, whatever the toggle says.
	Open   int
	Closed int
	// HiddenClosed is the closed tasks and sections the toggle is holding back.
	HiddenClosed int
}

OutlineCounts are a section node's task tallies, all at any depth.

type OutlineNode added in v1.18.0

type OutlineNode struct {
	Kind     string
	ID       string
	ParentID string
	Depth    int
	Item     *store.Item
	Section  SectionInfo
	Counts   OutlineCounts
}

OutlineNode is one row of the Outline: a section or a task, the id of the nearest SHOWN ancestor it nests under ("" at the top), and its depth among shown rows. Because hidden rows are transparent, ParentID and Depth describe the outline as painted, which can differ from the record's own parent.

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
	State       string
	Closed      string
	HasClosed   bool
}

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.

func (ProjectView) IsClosed added in v1.17.0

func (v ProjectView) IsClosed() bool

IsClosed reports whether the project section is closed (DONE or CANCELLED).

func (ProjectView) Open added in v1.17.0

func (v ProjectView) Open() bool

Open reports whether the project is still open.

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) AgendaBucket added in v1.18.0

func (q *Queries) AgendaBucket(item store.Item) string

AgendaBucket is the day group one item belongs to, measured against this reader's today — the server's zone for the API, the terminal's for the TUI. An undated row files under later.

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) AgentReady added in v1.18.0

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

AgentReady is the one definition of claimable agent work: an agent marker nobody has claimed, on a live task in an accepted open state that is actually workable right now. `list --agent-ready`, `scope=agent_ready`, and the task resource's `agent_ready` all read this, so a client never has to re-derive the rule.

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) ArchivedOn added in v1.18.0

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

ArchivedOn is the day an archived task was swept to the archive. A sweep stamps `archived` on the subtree root only, so a descendant answers with its nearest stamped ancestor's date. A live task was never archived and answers false.

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 (q *Queries) CarriesLink(item store.Item, raw string) bool

CarriesLink reports whether any of the task's links (formal, title, or body) is the same link as `raw` under links.MatchKey. It is the one definition of "this task already carries that URL" the CLI and the API filter on.

func (*Queries) Context

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

Context is the reader this model answers for.

func (*Queries) Created added in v1.18.0

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

Created is the day the task was captured. There is no stored creation stamp, so the source is the `Captured [date]` note a capture writes into the body: the first body line of that shape whose date is a real calendar day. A body edit that removed the note leaves the task undated, and that is reported as false rather than approximated from `updated` or the id.

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 — except for the two QUEUE scopes (`--agent-ready` and `--proposed`), which come back in the shared triage order below.

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) NamedView added in v1.18.0

func (q *Queries) NamedView(name string, options NamedViewOptions) (NamedViewResult, bool)

NamedView answers one named view over the live file, or ok=false for a name that is not one.

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) Outline added in v1.18.0

func (q *Queries) Outline(showClosed bool) []OutlineNode

Outline is the live tree as the Outline tab paints it, in file order: one flat DFS pre-order list. Proposals never appear (Approvals owns undecided work); closed tasks and closed sections appear only when showClosed is set. Availability is not a filter here — the outline is the whole tree.

Presentation the tab layers on top — fold state, and the urgency sub-bands it draws inside a section whose children are all tasks — is not part of the answer; the order is the file's.

func (*Queries) PrimaryDate added in v1.18.0

func (q *Queries) PrimaryDate(item store.Item) (temporal.Date, string, temporal.Value, bool)

PrimaryDate is the date a row is filed under: the deadline if there is one, else the available-from date. kind is "deadline" or "scheduled".

func (*Queries) PriorityThenDueBefore added in v1.9.0

func (q *Queries) PriorityThenDueBefore(left, right store.Item) bool

PriorityThenDueBefore is RankByPriorityThenDue's comparator on its own, for callers that already own a sort — a row builder ordering rows rather than items, say — and must order by the same rule rather than a lookalike.

It is deliberately NOT a total order: it reports nothing about two items that tie on priority and date, leaving the caller's stable sort to preserve whatever order they arrived in.

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) ProjectsIncluding added in v1.17.0

func (q *Queries) ProjectsIncluding(includeClosed bool) []ProjectView

ProjectsIncluding is Projects with an explicit closed filter. When includeClosed is false, closed projects are omitted — the default for every existing caller. When true, they are included.

func (*Queries) QuadrantFor added in v1.18.0

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

QuadrantFor is the classification a single task carries on its own: its quadrant under the configured window (WithUrgentDays) for an open live task, and false for a proposed, closed, or archived one, which no quadrant describes. Unlike the `quadrants` view it does not require the task to be available — an on-hold task is still important or urgent, it just is not listed yet.

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) RankByPriorityThenDue added in v1.9.0

func (q *Queries) RankByPriorityThenDue(items []store.Item) []store.Item

RankByPriorityThenDue is the shared TRIAGE order: the one ranking every surface uses when a queue exists to be decided rather than browsed.

priority A > B > C > none
within a band, the soonest date boundary first
an undated row after every dated row in its band
canonical file/DFS order as the final tiebreak

It is a core function, not an adapter detail, because the ORDER is part of what the list means: the agent-ready queue is taken from the top, and the Approvals queue is scanned from the top. A sort that lived in whichever surface happened to print it would drift between CLI, TUI and HTTP the first time one of them grew a new caller.

The date used is agendaSortKey — the deadline boundary if there is one, else the moment an available-from date opens, else a sentinel far future, which is exactly what puts undated rows last inside their band. Priority strictly dominates the date: a C due tomorrow still ranks below an undated A.

The sort is stable, so items tying on both keys keep the order the snapshot handed over, which is file order for a flat list and DFS order for a walked tree. Callers that want file/DFS order untouched simply do not call this.

func (*Queries) RecentRejects added in v1.9.0

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

RecentRejects is the shared answer to "which declines can still be restored": every CANCELLED task carrying the decline marker, live first then recently archived, newest decline first. The CLI's `--rejected` scope and the TUI's toggle both read THIS, so "recent" is one rule with one implementation.

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) SectionKind added in v1.18.0

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

SectionKind is the role of a live section by id, or ok=false when the id is not a live section.

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) Sections added in v1.18.0

func (q *Queries) Sections() []SectionInfo

Sections is every live section in file order.

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.

func (*Queries) UpdatedAt added in v1.18.0

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

UpdatedAt is the instant of the task's stored last-write stamp. The device half of the stamp is sync bookkeeping and is dropped; a missing or malformed stamp answers false.

type SectionInfo added in v1.18.0

type SectionInfo struct {
	ID        string
	Title     string
	ParentID  string
	Kind      string
	Body      string
	HasBody   bool
	State     string
	Closed    string
	HasClosed bool
}

SectionInfo is one live section's own fields plus its role.

Kind is structural: an "area" here is any top-level section that is not a reserved list, whether or not it holds open work today. The Projects listing's narrower sense — an area appears only while it has open work — is a rule about that listing, not about the section.

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.

type ViewGroup added in v1.18.0

type ViewGroup struct {
	Block string
	Key   string
	Label string
	Items []store.Item
}

ViewGroup is one bucket of a named view. Block is empty except in the inbox, where it names which of the two queues the group belongs to.

type ViewQuery added in v1.18.0

type ViewQuery struct {
	View           string
	Queries        *Queries
	UrgentDays     int
	ShowDeferred   bool
	ContextFilters []string
	// ShowClosed reveals DONE and CANCELLED rows in the views whose rule keeps
	// them out by default — Outline and Projects. It is off in the zero value
	// and off out of NewViewQuery, so a caller that has never heard of the
	// toggle gets the working view rather than the graveyard.
	ShowClosed bool
}

ViewQuery is the canonical semantic query for both the flat and the tree row builders — the port of Tui::Views::Query.

It owns per-view eligibility, classification and grouping, and item ordering. Tree builders only decide which matching nodes become anchors and then render their descendants; they never re-decide what a view means. That split is what keeps the Agenda tab and `tasks agenda` from drifting apart.

func NewViewQuery added in v1.18.0

func NewViewQuery(view string, queries *Queries, urgentDays int, showDeferred bool,
	contextFilters []string) ViewQuery

NewViewQuery builds the query for one view. Closed rows start hidden; a caller that wants them says so with ShowingClosed.

func (ViewQuery) ContextMatch added in v1.18.0

func (q ViewQuery) ContextMatch(item store.Item) bool

ContextMatch is true when no context filter is active, or the item carries any selected context. Contexts are one OR facet; the view and text predicates compose by AND.

func (ViewQuery) Eligible added in v1.18.0

func (q ViewQuery) Eligible(item store.Item) bool

Eligible is view-only eligibility: the per-view state/date rule, and then availability.

The active context filter is deliberately NOT folded in here. Agenda anchors a root when ANY subtree item is eligible, and an undated @work parent whose only dates sit on untagged children must keep that thread. Context is a separate predicate; Matching is the conjunction.

The two conjuncts are ordered cheap-first on purpose: the view rule reads fields already on the Item, while the availability test walks task ancestors.

func (ViewQuery) GroupItems added in v1.18.0

func (q ViewQuery) GroupItems(items []store.Item) map[string][]*Node

GroupItems adapts the flat item path onto the node-shaped grouping API by wrapping each item in a throwaway node. The alternative is two copies of the grouping policy, one per shape, and they would drift.

func (ViewQuery) GroupItemsInOrder added in v1.18.0

func (q ViewQuery) GroupItemsInOrder(items []store.Item) []Group

GroupItemsInOrder buckets items by GroupKeys, PRESERVING the order they were given inside each bucket, and returns the buckets in the view's group order.

It is the approvals queue's path: that list is already ranked by the core's shared triage order, and re-sorting a bucket by the view's own key would throw that ranking away. Eligibility is the caller's — the queue's rows are PROPOSED and no view rule admits them.

func (ViewQuery) GroupKeys added in v1.18.0

func (q ViewQuery) GroupKeys(item store.Item) []string

GroupKeys is the group or groups an item belongs to. A task with several contexts appears once per context in the Next view — which is exactly why selection has to follow an id AND an occurrence, not an id alone.

func (ViewQuery) GroupedNodes added in v1.18.0

func (q ViewQuery) GroupedNodes(nodes []*Node) map[string][]*Node

GroupedNodes buckets nodes by GroupKeys and sorts each bucket.

func (ViewQuery) Matching added in v1.18.0

func (q ViewQuery) Matching(item store.Item) bool

Matching is the composite the filtered views select and anchor on.

func (ViewQuery) Select added in v1.18.0

func (q ViewQuery) Select(items []store.Item) []store.Item

Select keeps the matching items, in the order given.

func (ViewQuery) SelectNodes added in v1.18.0

func (q ViewQuery) SelectNodes(nodes []*Node) []*Node

SelectNodes and SortNodes are the tree-mode twins: the same policy applied to nodes through their items.

func (ViewQuery) ShowingClosed added in v1.18.0

func (q ViewQuery) ShowingClosed(show bool) ViewQuery

ShowingClosed returns the same query with the closed-row toggle set. It is a separate builder rather than a seventh constructor argument so the reveal stays opt-in for every caller that never mentions it.

func (ViewQuery) Sort added in v1.18.0

func (q ViewQuery) Sort(items []store.Item) []store.Item

Sort orders items by the view's key. STABLE, deliberately: Ruby's sort_by is not, and Wave 1 already had to fix one list whose tie order was whatever introsort left behind. A list that permutes under an unrelated edit is how a user completes the wrong row.

func (ViewQuery) SortNodes added in v1.18.0

func (q ViewQuery) SortNodes(nodes []*Node) []*Node

SortNodes orders nodes by their items' view key, stably.

func (ViewQuery) SortedGroups added in v1.18.0

func (q ViewQuery) SortedGroups(groups map[string][]*Node) []Group

SortedGroups orders the buckets. Most views order by key text; Projects orders by the soonest date anywhere in the bucket, then by key, and Inbox borrows that same sequence outright — see orderGroups.

func (ViewQuery) TemporalSortKey added in v1.18.0

func (q ViewQuery) TemporalSortKey(item store.Item) float64

TemporalSortKey is the INSTANT a dated item comes due, as a float so an undated item can sort last by being +Inf. A deadline sorts by the moment it stops being on time; an available-from date sorts by the moment it opens.

func (ViewQuery) ViewRule added in v1.18.0

func (q ViewQuery) ViewRule(item store.Item) bool

ViewRule is the per-view state and date test, availability aside.

Outline and Projects are the two rules that read a toggle rather than only the item, because what they exclude is a CHOICE rather than a property of the row. Outline is the whole live tree with PROPOSED taken out unconditionally — undecided work belongs to Inbox/Approvals — and closed work taken out until the reader asks for it, because a triaged section is otherwise mostly cancelled leftovers nobody has swept. Projects is the same question from the other end: the tab is a commitment listing, so it anchors on open work and widens to finished work on request. Spelling both here rather than inside the row builders is what lets a headless dump hide the same rows the tabs do.

Jump to

Keyboard shortcuts

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