# Require a task shape

Refuse a task that doesn’t say where it starts, what done looks like and which files change.

A task says “Paginate the audit log” and nothing else. Whoever picks it up has to find the bug again, guess what done means and hunt for the files. Guess wrong and you build the wrong thing.

## Config

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

```toml
extends = ["mindtape:tasks"]
# As if you wrote these rules yourself, plus 42 more:
#
# [[tasks.body.content.rules]]
# name = "open-as-is-with-the-essence"
# path = ["AS-IS"]
# assert = { must-match = "(?m)\\A\\s*[A-Z][^\\n]{10,120}[.:]\\s*$" }
# when = "!terminal"
# message = "open AS-IS with one plain line that carries the essence, then the numbered steps"
#
# [[tasks.body.content.rules]]
# name = "write-as-is-as-numbered-steps"
# path = ["AS-IS"]
# assert = { must-match = "(?m)^\\s*(\\+|\\d+\\.)\\s" }
# when = "!terminal"
# message = "write AS-IS as numbered steps anyone can follow"
#
# [[tasks.body.content.rules]]
# name = "open-to-be-bullet-with-green"
# path = ["TO-BE"]
# assert = { must-match = "(?m)^\\s*- 🟢" }
# when = "!terminal"
# message = "say how it should work as bullets opening with 🟢"
#
# [[tasks.body.content.rules]]
# name = "name-path-in-changes"
# path = ["Changes"]
# assert = { must-match = "(?m)^[ \\t]*-[ \\t]+`[^`]+`" }
# when = "!terminal"
# message = "list Changes as bullets naming the `path` each one touches"
#
# [[tasks.body.content.rules]]
# name = "start-every-changes-bullet-with-path"
# path = ["Changes"]
# assert = { must-not-match = "(?m)^[ \\t]*-[ \\t]+[^`\\n]" }
# when = "!terminal"
# message = "start every Changes bullet with one backticked path, then what changes there"
#
# [[tasks.body.content.rules]]
# name = "write-changes-plan"
# path = ["Changes"]
# assert = "non-empty"
# when = "!terminal"
# message = "write the plan under Changes, one backticked path per bullet"
```

## Behavior

`mt add` refuses a task with sections left out. Fill them in, write `AS-IS` as one sentence instead of steps, and `mt add` refuses it again:

```
$ mt add -f - <<'EOF'
title: Paginate the audit log endpoint
as-is: GET /audit returns every row, and on production the response is 40 MB.
EOF
error: missing required slots: 'to-be', 'changes', 'out-of-scope'
hint: pass each with --set name=value, or with -f
hint: run mt add --describe to see the slots
$ mt add -f - <<'EOF'
title: Paginate the audit log endpoint
as-is: GET /audit returns every row, and on production the response is 40 MB.
to-be: |
  - 🟢 `GET /audit` returns 100 rows and a `next` cursor for the page after them.
changes: |
  - `src/audit/routes.rs`: read `cursor` and `limit` from the query string.
  - `src/audit/store.rs`: select one page, ordered by `id`.
out-of-scope: |
  - Filtering the audit log by user.
EOF
error: <new task from template 'task'>:9: body.content.rules.write-as-is-as-numbered-steps: write AS-IS as numbered steps anyone can follow
note: section `AS-IS` must match `(?m)^\s*(\+|\d+\.)\s`
error: <new task from template 'task'>:9: body.content.rules.mark-defect-step-with-red: open the step that shows the defect with 🔴
note: section `AS-IS` must match `(?m)^\s*(\+|\d+\.)\s+🔴`
```

`mt add` writes a file only after both checks pass. A missing slot exits `2`, and a broken rule exits `1`.

## Tags

Four tags tune the shape. `[tasks.tags] allowed` lists them, and `mt config show --resolved` shows the rules that read them:

| Tag | What it says |
| --- | --- |
| raw(“stateful”) | The change keeps state. The task has one Rollback section saying how to undo it. |
| raw(“stateless”) | The change doesn’t keep state. The task has no Rollback. |
| raw(“no-repro”) | The `AS-IS` has no runnable repro. The tag waives the fenced block. |
| raw(“no-ui-ux”) | The `TO-BE` has no screen or output to show. The tag waives the fenced example. |

The `statefulness` and `examples` parameters turn the tag rule and the two fenced examples on. Both are off in the example. A task without one of these tags still passes.

## Templates and rules

Each project template defines each section as a slot, a value that `mt add` fills in. `mt add` refuses a fill that leaves a slot out, and the pack’s rules refuse one left empty. `mt add --describe` lists the slots, each with a prompt and an example. [Templates & slots](https://mlavrinenko.github.io/mindtape/templates/index.md) covers both.

`extends` adopts the `mindtape:tasks` [rule pack](https://mlavrinenko.github.io/mindtape/packs/index.md), a set of rules that comes with `mt`. Its rules require `AS-IS`, `TO-BE`, Changes and Out of scope, in that order. A `fix` also has Environment, a `feat` or a `decision` includes Alternatives, a `docs` task has Source of truth, and a task tagged `stateful` has Rollback. `AS-IS` opens with one plain line that carries the essence, then numbered steps, with 🔴 on the step that shows the bug. Each `TO-BE` bullet opens with 🟢, and each Changes bullet starts with one backticked path. Changes is never empty. A question left in `TO-BE`, Changes or Out of scope fails, so ask it before you file, while a `?` in code passes. If you edit a task by hand, `mt check` runs the same rules on it. [Packs](https://mlavrinenko.github.io/mindtape/packs/index.md) lists every rule in the pack and shows how to drop one, and [Rules](https://mlavrinenko.github.io/mindtape/rules/index.md) covers body rules.

This repo extends the same pack in [`.mindtape/config.toml`](https://github.com/mlavrinenko/mindtape/blob/main/.mindtape/config.toml).
