# Filter language

The expression language `mt ls` and `mt rm` use to select tasks, with its fields, operators and functions.

A filter is a boolean expression over task fields. You pass one to `mt ls` and `mt rm`, and write one in config for [views](https://mlavrinenko.github.io/mindtape/named-sets/index.md#views), `[[tasks.rules]]`, `[[on.flip]]`, `[[on.rm]]` and `[[on.add]]` hooks. The examples on this page ran in `examples/api-service`, a sample backend project’s backlog:

```
$ mt ls '!terminal'
SLUG#  STATUS    READY       PRIORITY  DUE         TITLE
zpz    proposed  ▶ ready     🔴 red    2026-10-02  Index the orders by customer
qre    wip       ▶ ready     🟡 amber              Reject expired sessions on token refresh
05c    proposed  ▶ ready     🟡 amber  2026-10-05  Rotate the JWT signing key
ygv    proposed  ▶ ready     🟡 amber  2026-10-03  Document the webhook retry policy
re8    proposed  ▶ ready     🟡 amber              Add a Redis client to the app state
8f7    wip       ▶ ready     🟡 amber              Harden session tokens
r5y    proposed  ▶ ready     🟢 green  2026-10-30  Send a welcome email after signup
4ze    proposed  ▶ ready     🟢 green  2026-10-20  Replace the deprecated search client
9ds    proposed  🔒 blocked  🟡 amber              Verify webhooks with the acme-pay SDK
2q0    proposed  🔒 blocked  🟢 green              Throttle failed logins per IP

10 of 14 tasks · your filter
```

## Fields

| Field | Value |
| --- | --- |
| `status` | The status name. It sorts by position in the [status legend](https://mlavrinenko.github.io/mindtape/statuses/index.md). |
| `status.name` | The name of the status stamp, sorted alphabetically. |
| `status.date` | The ISO date of the status stamp. |
| `status.note` | The note of the status stamp. |
| `status.index` | The status’s 0-based position in the legend, as a number. A status outside the legend has none. |
| `priority` | Numbers. A [framework](https://mlavrinenko.github.io/mindtape/priority/index.md) priority reads as its score. |
| `difficulty` | Numbers. A [framework](https://mlavrinenko.github.io/mindtape/priority/index.md) difficulty reads as its score. |
| `kind`, `title`, `id`, `assignee` | Text. |
| `due`, `start`, `reviewed` | ISO dates, compared as text, as in `due < now()`. |
| `path` | The task file’s path from the project root, with `/` on every platform. |
| `dir` | The folder part of `path`, from the project root with `/` on every platform. Empty only for a task at the project root itself. |
| `depth` | How many folders deep the file sits under its root, 0 in the root itself. |
| `role` | Matches when the assignee has that role in `[[actors]]`. It doesn’t sort. |
| `topo`, `blocks` | The task’s place in the dependency graph, described below. |
| `children` | The number of [`parent`](https://mlavrinenko.github.io/mindtape/links/index.md) children. |
| `progress` | The finished share of the children, from 0 to 1. A task with no children has none. |
| `estimate.<unit>` | One [estimate](https://mlavrinenko.github.io/mindtape/estimates/index.md) unit, as a number. It doesn’t sort. |
| `estimate` | The estimate dict. Only `has()` and `miss()` read it, as in `has(estimate, "days")`. It doesn’t sort. |
| `tags` | The written and derived tags. `has(tags, "frontend")` reads them, and `contains` searches them. It doesn’t sort. |
| `derived.<name>` | A field a [collector](https://mlavrinenko.github.io/mindtape/config/index.md#derived-fields) computes. A scalar compares and sorts. A list or record does not. Read a list’s length with `len()` or its paths with `count_paths()`, and read a record field as `derived.<name>.<field>`. |
| `x-<ns>` | An extension field, whether `[tasks.fields]` declares it. Text, a number or a boolean compares like any field. A list equals nothing, so use `has(field, value)` to read it. A dict takes only `has()` and `miss()`. If a filter in the config uses an undeclared one while `[tasks.fields]` declares others, `mt` warns at load and suggests the nearest declared name. |

A field name may contain `-` between two letters or digits, as in `estimate.src-files` and `x-goals`. Any other `-` is a minus sign. If you set `[tasks.estimate] units`, a filter may use only those units.

`mt ls` shows a `file` column, but `file` isn’t a field, and a filter that names it fails. Use `path`. `dir` is the folder part of `path`, from the project root with `/` on every platform. It is empty only for a task at the project root itself.

## Operators

`==`, `!=`, `<`, `>`, `<=` and `>=` compare. `&&`, `||` and `!` combine, and parentheses group:

```
$ mt ls 'kind == "fix" || (kind == "feat" && count_paths(derived.changes, "@source") <= 2)'
SLUG#  STATUS    READY       PRIORITY  DUE         TITLE
zpz    proposed  ▶ ready     🔴 red    2026-10-02  Index the orders by customer
qre    wip       ▶ ready     🟡 amber              Reject expired sessions on token refresh
2q0    proposed  🔒 blocked  🟢 green              Throttle failed logins per IP
9y9    done                                        Add request IDs to log lines
q57    done                                        Fix the 404 page typo

5 of 14 tasks · your filter
```

The left side of a comparison is a field or a count. The right side is a literal, `now()`, another field or a count. Two numbers compare as numbers.

A field the task doesn’t have is unequal to every value and orders against none. `kind != "bug"` matches a task with no `kind`, while `kind == "bug"` and `kind < "bug"` don’t, so `==` and `!=` split the backlog in two with nothing left over. `miss(field)` selects the tasks without the field.

`!` flips the answer after the comparison, so `!(field <= 2)` isn’t `field > 2`. The finished tasks here have no estimate, and only the second filter lets them through:

```
$ mt ls 'estimate.src-files > 2'
SLUG#  STATUS    PRIORITY  DUE         TITLE
re8    proposed  🟡 amber              Add a Redis client to the app state
r5y    proposed  🟢 green  2026-10-30  Send a welcome email after signup
4ze    proposed  🟢 green  2026-10-20  Replace the deprecated search client

3 of 14 tasks · your filter
$ mt ls '!(estimate.src-files <= 2)'
SLUG#  STATUS    PRIORITY  DUE         TITLE
re8    proposed  🟡 amber              Add a Redis client to the app state
r5y    proposed  🟢 green  2026-10-30  Send a welcome email after signup
4ze    proposed  🟢 green  2026-10-20  Replace the deprecated search client
9y9    done                            Add request IDs to log lines
q57    done                            Fix the 404 page typo
yre    done                            Pin the Rust toolchain in CI
c1m    done                            Upgrade the axum web framework

7 of 14 tasks · your filter
```

`now()` is today’s date. `stale()`, `now()` and the overdue marker read the same date, which `MINDTAPE_NOW` pins (see [Environment variables](https://mlavrinenko.github.io/mindtape/config/index.md)).

## Functions

| Function | Matches |
| --- | --- |
| `has(field)`, `miss(field)` | The task has the field, or doesn’t. |
| `has(field, value)` | The field’s list contains the value, its scalar equals it, or its dict has it as a key. `tags` and `estimate` read this way too. |
| `exists` | Inside `head(...)`, `staged(...)` or `worktree(...)` in a [task-scope commit rule](https://mlavrinenko.github.io/mindtape/commit-rules/index.md#task-scope): the commit state includes the task’s file. Any other filter refuses it. |
| `has_tag("name")` | The task has the tag, written or [derived](https://mlavrinenko.github.io/mindtape/derived-tags/index.md). |
| `contains("text")` | The text appears in the title, the id or the body, ignoring case. `[ls] contains-fields` changes those fields. |
| `contains("text", field, ...)` | The text appears in one of the named fields. `note` (every link note) and `tags` are searchable too. |
| `starts_with("text", field)` | The named text field starts with the text, ignoring case. It takes exactly one field, with no default haystack. |
| `old("field")` | The field’s value before any `[[on.add]]` hook ran, read as a value. It can appear inside `matches()`, `word()` or `in_dict()`, and only an add hook’s `when` has one. It refuses every field the draft cannot answer, such as `id`, `path`, `dir`, `file` and `derived.<name>`. |
| `stale(N)` | The task wasn’t reviewed in the last N days. With no `reviewed` date, its status date counts. |
| `links("kind")` | The task has a [`links:`](https://mlavrinenko.github.io/mindtape/links/index.md) edge of that kind. |
| `in_view("name")`, `@name` | The named [view](https://mlavrinenko.github.io/mindtape/named-sets/index.md)’s filter matches. |
| `ready`, `blocked`, `terminal` | Described below. Write them bare or as `ready()`. |
| `len(field)` | How many items a list field contains. A missing field counts zero. |
| `count_paths(field, ...sets)` | How many distinct, normalized paths a `["path"]` field has inside the path sets, which are globs or `@name` sets as in `changed()`. |
| `changed("states", ...globs)` | How many distinct paths git reports changed in those states, inside the globs. A count, so it appears in a comparison. |
| `count(expr)` | How many loaded tasks match the expression. A count too. |

```sh
mt ls 'has(estimate) && miss(assignee)'
mt ls 'contains("redis")'                 # title, id and body
mt ls 'contains("redis", title)'          # title only
mt ls 'links("depends-on")'
mt ls 'stale(7) && !terminal'
mt ls '@default && kind == "feat"'
```

`starts_with("text", field)` names one field, and the text must open it. The check folds case like `contains()`. A mixed-case needle matches too.

```
$ mt ls 'starts_with("FiX", title)'
SLUG#  STATUS  TITLE
q57    done    Fix the 404 page typo

1 of 14 tasks · your filter
```

Two more test forms exist only in an [add hook](https://mlavrinenko.github.io/mindtape/hooks/index.md#add-hooks)’s `when`. `template == "name"` and `template != "name"` compare the template `mt add` used, `from_template("name")` is the same test as `==`, and `old("field")` reads the task before any add hook ran. The three template tests are config errors anywhere else. `old()` refuses outside an add `when`.

One field may have `"alpha"` on one task and `("alpha", "gamma")` on another. `x-machine == "alpha"` matches only the first, and `has(x-machine, "alpha")` matches both.

`into("status")` matches when a change moves the task into that status. It works only in an [`[[on.flip]]`](https://mlavrinenko.github.io/mindtape/hooks/index.md) `when` and in a task-scope [`[[commits.rules]]`](https://mlavrinenko.github.io/mindtape/commit-rules/index.md) entry, because those are the only places a status change exists. That page lists the other functions a task-scope commit rule reads.

## Text functions

Three functions read text, and each takes a field, `word(...)` or an add hook’s `old("field")` as its text. `word(value, n)` is the n-th word of a text value, counting from 1, with punctuation trimmed from both ends, so `"Fix: the slug"` has `Fix` as its first word. It returns text, so it only appears as an argument. `matches(value, "regex")` matches a Rust `regex` pattern anywhere in the text. `in_dict("name", text)` matches when the text is in the named [dictionary](https://mlavrinenko.github.io/mindtape/named-sets/index.md). Like `contains()`, `matches()` and `in_dict()` also read `body`, `note` and `tags`. The last example then finds a task that still has a template’s placeholder line:

```sh
mt ls 'in_dict("verbs", word(title, 1))'
mt ls '!matches(word(title, 1), "ing$")'
mt ls 'in_dict("mindtape-verbs", word(title, 1)) || matches(title, "^`")'
mt ls 'matches(body, "(?m)^- TODO:")'
```

`api-service` extends the [`mindtape:tasks`](https://mlavrinenko.github.io/mindtape/packs/index.md) pack, which declares the `verbs` dictionary. Without the pack, use the built-in `mindtape-verbs`, or declare your own `[dicts.verbs]`.

`word()` splits on whitespace and ignores Typst markup. A title that opens with a code span, such as ``mt ls` prints paths`, has `mt` as its first word, so the last example above lets `matches()` accept it.

`matches()` and `in_dict()` don’t match a value that isn’t there, such as a missing field or a word past the end of the title. That’s how `==` reads one, so `!matches(...)` does match it. Anything else wrong is an error that states the problem, such as an unknown dictionary, a pattern `regex` refuses, a number where text belongs, or a wrong argument count. `mt ls` exits `2`:

```
$ mt ls 'in_dict("verb", word(title, 1))'
error: unknown dict: 'verb' in filter 'in_dict("verb", word(title, 1))'
hint: did you mean verbs?
hint: use one of: mindtape-dev-verbs, mindtape-verbs, services, source, verbs
```

`mt` also runs each filter saved in config once when it loads the config, so a view or rule with a bad expression fails by name before any listing. A status that no `[[tasks.status]]` entry declares is a bad expression too: `status == "wpi"` fails and suggests `wip`, rather than returning an empty result.

## Dependencies and counts

`ready` matches an open task whose dependencies are all in a [terminal](https://mlavrinenko.github.io/mindtape/statuses/index.md#the-default-legend) status. Its [`waits-on` checkers](https://mlavrinenko.github.io/mindtape/wait-on-upstream/index.md) must all say the wait is over. `blocked` matches an open task with at least one dependency that isn’t, including a missing one, or with a checker that says it still waits or can’t tell. A task in a terminal status is neither, and `terminal` matches it. `mt ls` lists ready tasks first.

The `why` column lists what each blocked task waits on:

```
$ mt ls blocked --columns title,why
TITLE                                  WHY
Verify webhooks with the acme-pay SDK  waits on: locked:acme-pay@2.4.0 (acme-pay 2.3.2 is locked)
Throttle failed logins per IP          waits on: add-redis-client (proposed)

2 of 14 tasks · your filter
```

`count(expr)` is how many loaded tasks match `expr`. It’s a number, so it appears in a comparison. It counts every loaded task, whatever the rest of the filter selects, so a rule such as a [work-in-progress cap](https://mlavrinenko.github.io/mindtape/rules/index.md) can compare it on every task. `count()` works where `mt` loads the full set: `mt ls`, `mt rm`, views, `[[tasks.rules]]`, `[[on.flip]]` and `[[on.rm]]`. A `required` filter can’t use it, and `mt` refuses one that does when it loads the config.

`topo` is a task’s level in the dependency graph. A task with no dependency in the loaded set is at level 0, and any other task is one level above its deepest dependency. `topo` ignores status, so ascending `topo` is an order in which every task comes after what it depends on. Unrelated tasks share a level.

`blocks` counts the open tasks that wait on this one, directly or through other tasks. A priority framework scores each task on its own, so a cheap decision that five tasks wait on can score low. `blocks` shows what finishing it unblocks. A finished task doesn’t block anything, and `blocks` falls as work closes.

A dependency is a `depends-on` edge, or an edge of a [custom kind](https://mlavrinenko.github.io/mindtape/links/index.md) marked `blocking = true`. `ready`, `blocked`, `topo` and `blocks` all read them. An edge to a task that isn’t loaded counts as unmet for `blocked`, and `topo` and `blocks` ignore it. `mt check` refuses a dependency cycle, and neither rank loops on one.

```sh
mt ls ready
mt ls 'count(status == "wip") > 1 && status == "wip"'
mt ls 'blocks > 0'
mt ls 'topo == 0 && !terminal'
```

## Changed files

`changed("states", "glob", ...)` counts the distinct paths git reports changed, so it appears in a comparison, such as `changed("staged+worktree", "@source") <= count_paths(derived.changes, "@source")`. [Split oversized tasks](https://mlavrinenko.github.io/mindtape/split-oversized-tasks/index.md) shows that rule, and [Estimates](https://mlavrinenko.github.io/mindtape/estimates/index.md) compares the same count with a filed estimate. A rename counts once, at its new path. A glob written `"@name"` stands for the entries of the `[dicts.name]` set, which must declare `case = "exact"`, so a rule and a commit rule can share one path list.

| State | Counts a path that |
| --- | --- |
| `staged` | differs in the index from `HEAD`. |
| `worktree` | differs in the working tree from the index, or git doesn’t track it. |
| `staged+worktree` | is in either. A path in both counts once. |

Globs match paths from the repository root, and `**` crosses folders. With no glob, every path counts. A glob starting with `!` excludes paths another glob admits.

## Commits that touched a file

`touches("path")` matches the tasks named by the [`[commits] trailer`](https://mlavrinenko.github.io/mindtape/commit-rules/index.md) of any commit that changed the path. The path is relative to the repository root:

```
$ git --no-pager log -1 --format=%B
fix(auth): check expires_at on refresh

Refs: reject-expired-sessions-on-token-refresh
$ mt ls 'touches("src/auth/session.rs")'
SLUG#  STATUS  PRIORITY  TITLE
qre    wip     🟡 amber  Reject expired sessions on token refresh

1 of 14 tasks · your filter
```

A trailer may refer to a task by [stem](https://mlavrinenko.github.io/mindtape/concepts/index.md#identity) (`Refs: parser`) or by path (`Refs: tasks/parser.typ`). A task `mt mv` renamed still matches its old stem, through the renames git records. A stem outside the loaded set belongs to a retired task. It doesn’t match anything, and `mt ls --json` lists it under `retired`. A ref that only matches [`[commits] external-refs`](https://mlavrinenko.github.io/mindtape/commit-rules/index.md#the-trailer) identifies no task, so `touches()` ignores it.

The first `touches()` in a command reads the history with one `git log`. `mt` caches the result in `.mindtape/cache/` until `HEAD` or the trailer key changes. A command that skips `touches()` doesn’t run git.

`changed()` and `touches()` need a git repository. Outside one, a filter typed on the command line fails and prints git’s reason, and `mt` reports a rule that reads git once as skipped. Loading a config never runs git. Git runs read-only (`--no-optional-locks`) and at most once per command.

## Sort and limit

`--sort` takes `field`, `field:asc` or `field:desc`. Repeat it to add keys: the first key is primary, and each later key breaks a tie. Every field in the table sorts except `role`, `estimate.<unit>`, `estimate` and `tags`. An `x-<ns>` list or dict sorts as a missing value, last. `ready` sorts too: ready, then blocked, then terminal. Any other direction, such as `priority:up`, is an error. `[ls] default-sort` takes the same specs.

`topo` and `blocks` produce ties, so a second `--sort` decides within each level. `-n` cuts the list after the filter and the sort, so it keeps the top of the order you asked for:

```sh
mt ls --sort status.date:desc
mt ls --sort topo --sort priority:desc
mt ls --sort blocks:desc -n 1
```

## Without a filter

A bare `mt ls` tries the project’s [`[[ls.rules]]`](https://mlavrinenko.github.io/mindtape/cli/ls/index.md#conditional-rules) first. If none matches, it applies the default view: the view `[ls] default-view` names, or `[views.default]`. The built-in default view is `!terminal && (miss(start) || start <= now())`, the open tasks whose start date has passed or that have none. An empty filter, `mt ls ''`, matches every task. A bare `mt rm` applies `[rm] default-filter`, which is `terminal`.

Required fields use the same language. See [Required fields](https://mlavrinenko.github.io/mindtape/rules/index.md).

> **Note:** `mt` parses a filter and walks the parse tree itself. A filter never runs as code.
