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
- Variables
- func ClosedStates() []string
- func DayBucket(days int, scheduled bool) string
- func Headline(item store.Item) string
- func Important(item store.Item) bool
- func OpenStates() []string
- func OutlineHiddenClosedCount(node *Node, showClosed bool) int
- func OutlineRenders(node *Node, showClosed bool) bool
- func OutlineShownCount(node *Node, showClosed bool) int
- func OutlineShows(node *Node, showClosed bool) bool
- func Quadrant(item store.Item, today temporal.Date, urgentDays int) string
- func Recurring(item store.Item) bool
- func ReservedListTitle(title string) bool
- func ResolveUrgentDays(options ...Option) int
- func SectionActionRefusal(kind, action string) string
- func StateOrder() []string
- func Urgent(item store.Item, today temporal.Date, urgentDays int) bool
- type APITime
- type Availability
- type Group
- type NamedViewOptions
- type NamedViewResult
- type Node
- type Option
- type OutlineCounts
- type OutlineNode
- type Override
- type ProjectView
- type Queries
- func (q *Queries) APITimeFor(value temporal.Value, present bool) (APITime, bool)
- func (q *Queries) AgendaBucket(item store.Item) string
- func (q *Queries) AgendaItems() []store.Item
- func (q *Queries) AgentReady(item store.Item) bool
- func (q *Queries) ArchiveItems() []store.Item
- func (q *Queries) ArchivedOn(item store.Item) (string, bool)
- func (q *Queries) AvailabilityAfter(item store.Item, override Override) Availability
- func (q *Queries) AvailabilityFor(item store.Item) Availability
- func (q *Queries) Body(item store.Item) []string
- func (q *Queries) CarriesLink(item store.Item, raw string) bool
- func (q *Queries) Context() temporal.Context
- func (q *Queries) Created(item store.Item) (string, bool)
- func (q *Queries) DeadlineValue(item store.Item) (temporal.Value, bool)
- func (q *Queries) Deferred(item store.Item) bool
- func (q *Queries) FindLive(id string) (store.Item, bool)
- func (q *Queries) InboxItems() []store.Item
- func (q *Queries) LeadAnchorValue(item store.Item) (temporal.Value, bool)
- func (q *Queries) LeadOpens(item store.Item) (temporal.Date, bool)
- func (q *Queries) LeadOpensAt(item store.Item) (time.Time, bool)
- func (q *Queries) LeadOpensValue(item store.Item) (temporal.Value, bool)
- func (q *Queries) LeadWindowValue(item store.Item) (temporal.Value, bool)
- func (q *Queries) Links(item store.Item) []links.Link
- func (q *Queries) List(filter query.Filter) []store.Item
- func (q *Queries) LiveItems() []store.Item
- func (q *Queries) NamedView(name string, options NamedViewOptions) (NamedViewResult, bool)
- func (q *Queries) NextItems() []store.Item
- func (q *Queries) NodeFor(item store.Item) *Node
- func (q *Queries) Outline(showClosed bool) []OutlineNode
- func (q *Queries) PrimaryDate(item store.Item) (temporal.Date, string, temporal.Value, bool)
- func (q *Queries) PriorityThenDueBefore(left, right store.Item) bool
- func (q *Queries) Project(item store.Item) (string, bool)
- func (q *Queries) ProjectView(id string) (ProjectView, bool)
- func (q *Queries) Projects() []ProjectView
- func (q *Queries) ProjectsIncluding(includeClosed bool) []ProjectView
- func (q *Queries) QuadrantFor(item store.Item) (string, bool)
- func (q *Queries) QuadrantItems() []store.Item
- func (q *Queries) QuadrantOf(item store.Item, urgentDays int) string
- func (q *Queries) RankByPriorityThenDue(items []store.Item) []store.Item
- func (q *Queries) RecentRejects() []store.Item
- func (q *Queries) Record(item store.Item) (record.Record, bool)
- func (q *Queries) ReservedLists() []ProjectView
- func (q *Queries) ScheduledValue(item store.Item) (temporal.Value, bool)
- func (q *Queries) SectionKind(id string) (string, bool)
- func (q *Queries) SectionView(id string) (ProjectView, bool)
- func (q *Queries) Sections() []SectionInfo
- func (q *Queries) Snapshot() *store.Snapshot
- func (q *Queries) Today() temporal.Date
- func (q *Queries) Tree() Tree
- func (q *Queries) UpdatedAt(item store.Item) (time.Time, bool)
- type SectionInfo
- type Tree
- type ViewGroup
- type ViewQuery
- func (q ViewQuery) ContextMatch(item store.Item) bool
- func (q ViewQuery) Eligible(item store.Item) bool
- func (q ViewQuery) GroupItems(items []store.Item) map[string][]*Node
- func (q ViewQuery) GroupItemsInOrder(items []store.Item) []Group
- func (q ViewQuery) GroupKeys(item store.Item) []string
- func (q ViewQuery) GroupedNodes(nodes []*Node) map[string][]*Node
- func (q ViewQuery) Matching(item store.Item) bool
- func (q ViewQuery) Select(items []store.Item) []store.Item
- func (q ViewQuery) SelectNodes(nodes []*Node) []*Node
- func (q ViewQuery) ShowingClosed(show bool) ViewQuery
- func (q ViewQuery) Sort(items []store.Item) []store.Item
- func (q ViewQuery) SortNodes(nodes []*Node) []*Node
- func (q ViewQuery) SortedGroups(groups map[string][]*Node) []Group
- func (q ViewQuery) TemporalSortKey(item store.Item) float64
- func (q ViewQuery) ViewRule(item store.Item) bool
Constants ¶
const ( AgendaOverdue = "overdue" AgendaToday = "today" AgendaTomorrow = "tomorrow" AgendaLater = "later" )
The agenda's day buckets, by key.
const ( BlockApprovals = "approvals" BlockInbox = "inbox" )
Inbox blocks: the intake tab is two queues, one above the other.
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.
const ( OutlineSectionNode = "section" OutlineTaskNode = "task" )
Outline node kinds.
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.
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.
const DefaultUrgentDays = 3
DefaultUrgentDays is the deadline window that counts as urgent.
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.
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.
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 ¶
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.
var NamedViews = []string{ViewAgenda, ViewNext, ViewQuadrants, ViewInbox}
NamedViews are the views NamedView answers. Projects has its own resource and the outline its own shape (see Outline), so neither is here.
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
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 ¶
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 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
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
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
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
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 Recurring ¶
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
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
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
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.
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 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
// 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
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) OpenProject ¶
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 ¶
Project is the nearest ancestor headline: a task's project, or a subtask's parent task.
func (*Node) ProjectSection ¶ added in v1.17.0
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) TopLevelSection ¶ added in v1.17.0
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
WithDocLinkPatterns supplies the configured `doc_link_patterns`: URL shapes classified as the `doc` system ahead of any host row.
func WithLinkConfig ¶
WithLinkConfig supplies the configured shorthand templates (`link.<name>`) and self-hosted system hosts (`system.<name>`).
func WithUrgentDays ¶ added in v1.18.0
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 ¶
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 ¶
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
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 ¶
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
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 ¶
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
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 ¶
Body is the item's own body lines. It never includes a child's body — children are separate records.
func (*Queries) CarriesLink ¶ added in v1.19.0
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) Created ¶ added in v1.18.0
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 (*Queries) FindLive ¶
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 ¶
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 ¶
LeadAnchorValue is the stamp a lead is measured back from: the deadline when there is one, otherwise the available-from date.
func (*Queries) LeadOpens ¶
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 ¶
LeadOpensAt is the same window as an instant, which is the only shape a clock lead can be expressed in.
func (*Queries) LeadOpensValue ¶
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 ¶
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 (*Queries) Links ¶
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 ¶
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 ¶
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 ¶
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) 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
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
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 ¶
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
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 ¶
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 ¶
QuadrantOf classifies against this reader's own today.
func (*Queries) RankByPriorityThenDue ¶ added in v1.9.0
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
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) 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 ¶
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
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 ¶
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 ¶
Today is the reader's own calendar day, which every date-sensitive read is measured against.
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 ViewGroup ¶ added in v1.18.0
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
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
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
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
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
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
GroupedNodes buckets nodes by GroupKeys and sorts each bucket.
func (ViewQuery) Matching ¶ added in v1.18.0
Matching is the composite the filtered views select and anchor on.
func (ViewQuery) SelectNodes ¶ added in v1.18.0
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
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
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
SortNodes orders nodes by their items' view key, stably.
func (ViewQuery) SortedGroups ¶ added in v1.18.0
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
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
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.