# Limit work in progress

Allow one milestone and one task in progress, and refuse to start a task before the tasks it depends on are done.

Three tasks in progress at once leave parts of all three in the working tree, and no commit can name just one. Starting a task while its dependency is open means writing code against a client that doesn’t exist yet.

## Config

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

```toml
tasks.status = [
  { value = "proposed" },
  { value = "wip", unblocked = true },
  { value = "done", terminal = true, unblocked = true },
]

[[tasks.rules]]
name = "one-milestone"
when = 'status == "wip" && kind == "milestone"'
assert = 'count(status == "wip" && kind == "milestone") <= 1'
message = "close the open milestone before you open another"
severity = "error"

[[tasks.rules]]
name = "one-task"
when = 'status == "wip" && kind != "milestone"'
assert = 'count(status == "wip" && kind != "milestone") <= 1'
message = "finish the task in progress before you start another"
severity = "error"
```

## Behavior

The milestone “Harden session tokens” and one task under it are in progress, so `mt wip` won’t start a second task. It also won’t start a task that waits on an open dependency, and `mt ls blocked` tells you which one:

```
$ mt ls 'status == "wip"' --columns title,children,progress
TITLE                                     CHILDREN  PROGRESS
Reject expired sessions on token refresh            
Harden session tokens                     2         0/2

2 of 14 tasks · your filter
$ mt wip add-redis-client
error: tasks/add-redis-client.typ:2: rules.one-task: finish the task in progress before you start another
note: tasks/reject-expired-sessions-on-token-refresh.typ:2: rules.one-task: finish the task in progress before you start another
$ mt wip throttle-failed-logins-per-ip
error: status requires an unblocked task: 'wip'
hint: finish what it waits on first, or pass --force to skip this check
note: waits on: add-redis-client (proposed)
$ 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
```

## Rule details

A milestone groups tasks and stays open until they’re done, and it can span sessions. It has a cap of its own. The `one-milestone` rule uses `count()` to count the milestones in `wip`, and fails when there’s more than one. `one-task` does the same for every other task, one with no `kind` included, because a missing field equals no value. Every command that writes a task checks the rules first. [Rules](https://mlavrinenko.github.io/mindtape/rules/index.md) covers work-in-progress caps, and [Filter language](https://mlavrinenko.github.io/mindtape/filters/index.md) covers `count()`.

A task records its milestone with a `parent` link, and `mt ls` counts a milestone’s tasks in its `children` and `progress` columns. [Task links](https://mlavrinenko.github.io/mindtape/links/index.md) covers the edge kinds.

`tasks.status` lists the statuses a task may have. `terminal = true` marks `done` as the status that ends a task. `unblocked = true` on `wip` makes `mt wip` refuse a task while a `depends-on` edge links to a task that isn’t done. On `done`, it makes `mt done` refuse a milestone with an open child. `--force` overrides both. `mt ls blocked` and its `why` column list each waiting task and what it waits on. [Statuses](https://mlavrinenko.github.io/mindtape/statuses/index.md) covers terminal and unblocked statuses.

This repo caps its own work in progress the same way in [`.mindtape/config.toml`](https://github.com/mlavrinenko/mindtape/blob/main/.mindtape/config.toml).
