# Tie work to your goals

Make every task say how it serves your goals, and refuse one that helps none of them.

Someone opens a task to rewrite the logging. The work is tidy, but the task serves none of your goals, and a week passes before anyone asks why.

The core keeps the mechanism, not the policy. A task body can emit metadata markers, and a `[[tasks.rules]] check` with `field = "markers"` hands them to a Typst function your project writes. The goal DSL is project Typst. The blocks below are `examples/goals`, a project whose tasks rate two goals and whose check refuses a task that helps neither.

## Declare the goals

A goal value carries the infinitive a task writes after `to:`, the gerund it writes after `from:`, and the sentence a render shows. The project keeps its registry in `goals.typ`:

```typ
// goals.typ: the goals every task rates
#let goals = (
  answer-fast: goal(
    to: "answer fast",
    from: "answering fast",
    title: "The app answers fast",
  ),
  avoid-lock-in: goal(
    to: "avoid lock-in",
    from: "avoiding lock-in",
    title: "Nothing traps a switcher",
  ),
)
```

The helpers are project Typst too. `goal(...)` derives the name a task writes, and each verdict emits one marker under a `goal` discriminator:

```typ
// goal-dsl.typ: one value, named by its infinitive
// The name a task writes: the kebab of the goal's infinitive, so "answer fast"
// is `answer-fast`. The title keeps its capitals; the name never does.
#let _kebab(to) = {
  assert(
    type(to) == str and to != "",
    message: "goal() takes its infinitive as a non-empty string",
  )
  lower(to).split(" ").filter(word => word != "").join("-")
}

// A goal value: `to` is the infinitive a task writes after `to:`, `from` the
// gerund it writes after `from:`, and `title` the sentence a render shows.
#let goal(to: none, from: none, title: none) = (
  name: _kebab(to),
  to: to,
  from: from,
  title: title,
)
```

```typ
// goal-dsl.typ: one marker per verdict
// A goal the task helps, and why. The reason is the trailing content block.
#let Helps(reason, to: none) = (
  _marker((
    goal: _rated(to, "Helps", "to"),
    effect: "helps",
    reason: reason,
  ))
    + reason
)

// A goal the task hinders, and from which direction.
#let Hinders(reason, from: none) = (
  _marker((
    goal: _rated(from, "Hinders", "from"),
    effect: "hinders",
    reason: reason,
  ))
    + reason
)

// The goals the task leaves alone, one neutral marker each. A neutral verdict
// needs no reason.
#let Neutral(..goals) = {
  let markers = ()
  let names = ()
  for value in goals.pos() {
    assert(
      type(value) == dictionary and "name" in value,
      message: "Neutral() takes goal values from goals.typ, not " + repr(value),
    )
    markers.push(_marker((
      goal: value.name,
      effect: "neutral",
      reason: none,
    )))
    names.push(value.name)
  }
  if names.len() == 0 { return markers.join() }
  markers.join() + [Neutral: #names.join(", ")]
}
```

## Check the markers

`check-goal-over(goals, markers)` reads the reserved `markers` input: every metadata marker in the body, in document order. It returns one string per problem, so `mt` names every missing goal at once:

```typ
// goal-dsl.typ: one message per problem
// `[[tasks.rules]] check` entry point for `field = "markers"`: every goal once,
// with a reason on a helps or hinders, and at least one helps.
#let check-goal-over(goals, markers) = {
  let known = goals.keys()
  let messages = ()
  let rated = ()
  let helped = false
  let values = markers
    .map(marker => marker.at("value", default: none))
    .filter(value => (
      type(value) == dictionary and value.at("marker", default: none) == "goal"
    ))
  for value in values {
    let name = value.at("goal", default: none)
    if name not in known {
      messages.push(
        "unknown goal `" + str(name) + "`; known: " + known.join(", "),
      )
      continue
    }
    if name in rated { messages.push("goal `" + name + "` is rated twice") }
    rated.push(name)
    let effect = value.at("effect", default: none)
    if effect not in ("helps", "hinders", "neutral") {
      messages.push(
        "goal `"
          + name
          + "` has unknown effect `"
          + str(effect)
          + "`; use `helps`, `hinders` or `neutral`",
      )
      continue
    }
    if effect == "helps" { helped = true }
    if effect != "neutral" {
      let reason = str(value.at("reason", default: "")).trim()
      if reason.split().filter(word => word != "").len() < 3 {
        messages.push(
          "goal `"
            + name
            + "` says "
            + effect
            + " but not why; write the reason in a sentence",
        )
      }
    }
  }
  for name in known {
    if name not in rated { messages.push("goal `" + name + "` is not rated") }
  }
  if not helped {
    messages.push("the task helps no goal; if nothing justifies it, cancel it")
  }
  messages
}
```

`lib.typ` wraps the check with this project’s registry, and the config names that file and function beside `field = "markers"`:

```typ
// lib.typ: the rule's entry point
#import "goal-dsl.typ": check-goal-over
#import "goals.typ": goals

// `markers` is the task body's metadata markers, the reserved `check` input.
#let check-goals(markers) = check-goal-over(goals, markers)
```

[`examples/goals/.mindtape/config.toml`](https://github.com/mlavrinenko/mindtape/blob/main/examples/goals/.mindtape/config.toml)

```toml
# The check reads the body's metadata markers, not a field the task sets.
[[tasks.rules]]
name = "goals"
when = "!terminal"
check = { typst = "lib.typ", function = "check-goals", field = "markers" }
severity = "error"
```

## Rate a task

A task imports the calls and writes `== Goals`, one verdict per goal. `Helps` takes the goal it serves and a reason, and `Neutral` leaves a goal alone:

```typ
// tasks/ship-the-search-index.typ: helps one goal and leaves the other alone
#import "@local/mindtape:0.5.0": *
#import "/goal-calls.typ": *

#show: task.with(
  title: "Ship the search index",
  status: proposed(2026, 6, 29),
)

= Summary

Search scans every note on every keystroke, and a large folder pauses after
the first letter.

== Goals

+ #Helps(to: answer-fast)[results appear while the query is still being typed].
+ #Neutral(avoid-lock-in).
```

The example’s task template carries the whole section in one `goals` raw slot, and rates every goal neutral unless you answer for it. Add a goal to the registry, and the next `mt add` asks for its verdict.

## See it refuse

The template’s default leaves both goals neutral, so `mt add` refuses a task that helps none of them, and files it once the goals slot says how it helps:

```
$ cat task.yaml
title: Search the archive
summary: |
  The archive search box returns nothing after the first page.
$ mt add -f task.yaml
error: <new task from template 'task'>:4: rules.goals: the task helps no goal; if nothing justifies it, cancel it
$ mt add -f task.yaml
wrote tasks/search-the-archive.typ (bg0)
next: mt eval bg0
```

## Check functions

`check` runs a Typst function you write on one input of each task the rule’s `when` matches. Each string the function returns is one error, so `mt` names every problem at once. [Self-validating tasks](https://mlavrinenko.github.io/mindtape/self-validating-tasks/index.md) covers a field your project adds. This recipe reads `markers`, the one input the core reserves. The [goals example](https://github.com/mlavrinenko/mindtape/tree/main/examples/goals) is the whole project: the module, the registry, the wrapper, the template and two tasks.

This repo rates every open task against its product and process goals in [`.mindtape/config.toml`](https://github.com/mlavrinenko/mindtape/blob/main/.mindtape/config.toml), with its own module in [`truth/goal-dsl.typ`](https://github.com/mlavrinenko/mindtape/blob/main/truth/goal-dsl.typ).
