taskfilter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package taskfilter parses the structured token grammar shared by every surface that filters tasks: the TUI filter bar, saved views, `ty list --view`, and the HTTP API.

The grammar is deliberately small and greppable:

status:blocked      is:blocked        only blocked tasks
status:in-progress  is:in-progress    queued + processing
status:open         is:open           anything not done/archived
is:pinned           is:unpinned       pin state
is:workflow         is:task           workflow steps vs standalone tasks
has:pr              no:pr             tasks with/without a pull request
tag:release                           tasks carrying a comma-separated tag
[project]                             project tag (OR'd across tags)
@mona                                 the machine a task ran on (OR'd)

Repeating a status token ORs the statuses together, so "status:in-progress status:blocked" is "the things I'm working on right now" — the view the list mode was built for.

Everything the grammar does not recognise is left alone and handed back as the free-text remainder, so callers keep whatever keyword matching they already do (the TUI fuzzy-scores it; the CLI does a substring match).

Index

Constants

View Source
const (
	KindWorkflow = "workflow"
	KindTask     = "task"
)

Kind values for the is:workflow / is:task token.

Variables

This section is empty.

Functions

func StatusTokens

func StatusTokens() []string

StatusTokens returns the accepted status:/is: status names in a stable order, for help text and shell completion.

Types

type Query

type Query struct {
	// Statuses is the set of task statuses to keep. Empty means "any status".
	Statuses []string
	// Kind is KindWorkflow, KindTask, or "" for both.
	Kind string
	// Pinned, when set, requires the task's pin state to match.
	Pinned *bool
	// HasPR, when set, requires the task to have (or not have) a pull request.
	HasPR *bool
	// Tags are tag names the task must carry — all of them, so repeating
	// tag: narrows rather than widens (unlike status:, which ORs).
	Tags []string
	// Projects are the [project] tags to keep, OR'd together. Names are
	// lowercased; resolve aliases before matching (see ResolveProjects).
	Projects []string
	// PartialProject is a trailing unclosed "[proj" the user is still typing.
	// Only the TUI's autocomplete cares; Match ignores it.
	PartialProject string
	// Hosts are the `@host` tokens — the machine a task ran on — OR'd together.
	// A bare "@" is the empty string and means "ran on some other machine".
	Hosts []string
	// LocalHost is this machine's short name, which is what lets `@mona` mean
	// the same thing on mona as anywhere else: a task that ran here carries no
	// placement target at all, so without it the local machine would be the one
	// host in the fleet you could not name. Set it with WithLocalHost.
	LocalHost string
	// Keyword is the free text left after every recognised token was removed.
	Keyword string
}

Query holds the structured predicates parsed out of a filter string. The zero value matches every task, so callers can apply it unconditionally.

func Parse

func Parse(raw string) Query

Parse extracts every structured token from raw and returns the resulting Query. Unrecognised text — including [project] tags, which are parsed into Projects — ends up in Keyword.

Tokens are matched case-insensitively; the keyword remainder keeps its original case so callers can decide how to fold it.

func (Query) Filter

func (q Query) Filter(tasks []*db.Task) []*db.Task

Filter returns the tasks matching the whole query, preserving input order.

func (Query) HasStructured

func (q Query) HasStructured() bool

HasStructured reports whether any non-keyword predicate is set. The TUI uses this to decide whether the structured pass can change the result at all.

func (Query) IsZero

func (q Query) IsZero() bool

IsZero reports whether the query constrains nothing at all — no structured predicate, no project, no keyword. Callers use it to skip filtering entirely.

func (Query) Match

func (q Query) Match(t *db.Task) bool

Match reports whether a task satisfies the structured predicates. It deliberately ignores Projects and Keyword: those are matched (and, in the TUI, fuzzy-ranked) by the caller, which owns alias resolution and scoring.

func (Query) MatchAll

func (q Query) MatchAll(t *db.Task) bool

MatchAll applies every predicate — structured, project, and keyword. This is the whole meaning of a saved view outside the TUI.

func (Query) MatchKeyword

func (q Query) MatchKeyword(t *db.Task) bool

MatchKeyword reports whether a task matches the free-text remainder by plain substring, across the fields a person would search: id, title, body, summary and project. The TUI replaces this with fuzzy ranking; the CLI and API use it as-is so a saved view means the same thing everywhere.

func (Query) MatchProject

func (q Query) MatchProject(t *db.Task) bool

MatchProject reports whether a task's project satisfies the [project] tags. Names are compared case-insensitively; pass already-resolved project names (see ResolveProjects) so aliases like "ol" work.

func (Query) ResolveProjects

func (q Query) ResolveProjects(resolve func(string) string) Query

ResolveProjects rewrites project tags through resolve, which maps a name or alias to the canonical project name. A resolver that returns "" leaves the name untouched, so an unknown project still filters (to nothing) rather than silently widening the view to everything.

func (Query) Rest

func (q Query) Rest() string

Rest returns the query with every structured token removed: the [project] tags followed by the free-text keyword, followed by any half-typed tag.

It exists so a caller with its own matcher for the unstructured part — the TUI, which fuzzy-ranks rather than substring-matches — can hand that matcher exactly the text it understands, without having to know which tokens this package consumed. The partial tag is emitted last because an unclosed "[" swallows the remainder of the string by definition.

func (Query) WithLocalHost

func (q Query) WithLocalHost(name string) Query

WithLocalHost names this machine for `@host` matching.

Jump to

Keyboard shortcuts

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