# Split oversized tasks

Cap how many source files a task may touch when it takes judgment, so a big design gets split before it’s filed.

Someone files “Sign in with Google and GitHub” as one task. The change touches the config, the routes, the auth module and a migration. The diff is too big to review, and when a test fails, you can’t tell which part broke it. A task that touches a few files gives you a diff you can read, and a failing test shows which part of that diff broke.

A rename is different. It touches every file that mentions the type, but it’s one decision, and splitting it only copies that decision into more than one task. So the cap only applies to work that takes judgment.

## Config

The `changes` collector reads the first backticked path on every Changes bullet, so `derived.changes` is the plan the task already has. `judgment-stays-small` counts the paths that fall inside the `source` set:

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

```toml
[[tasks.rules]]
name = "judgment-stays-small"
when = "!terminal && difficulty >= 3"
assert = 'count_paths(derived.changes, "@source") <= 5'
message = "split the decision from the mechanical edits, so each task plans 5 source files or fewer"
severity = "error"

[[tasks.collectors]]
name = "changes"
when = "!terminal"
query = { section = "Changes", pattern = "(?m)^\\s*-\\s+`([^`]+)`" }
returns = ["path"]

[tasks.estimate]
units = ["src-files"]
required = false
[dicts.source]
case = "exact"
values = ["**"]
```

## Behavior

The sign-in task takes judgment and its Changes section names 7 source files, so `mt add` refuses it. The rename covers its 12 files through one glob, `src/**/*.rs`, and `mt add` files it. A glob counts once, and mechanical work has no cap.

```
$ mt add -f - <<'EOF'
title: Sign in with Google and GitHub
difficulty: 6
as-is: |
  Login offers only a password form, so a Google user must make a password first.

  + Open `/login`.
  + 🔴 It offers only a password form. A user who signed up with Google has to make a password first.
to-be: |
  - 🟢 `/login` offers Google and GitHub buttons, and the callback logs the user in.
changes: |
  - `Cargo.toml`: add the `oauth2` crate.
  - `src/config.rs`: read each provider's client ID and secret.
  - `src/auth/oauth.rs`, new: the authorization-code flow.
  - `src/auth/providers.rs`, new: the Google and GitHub endpoints and scopes.
  - `src/auth/login.rs`: log in the user the callback names.
  - `src/routes.rs`: mount `/auth/{provider}/callback`.
  - `migrations/0007_identities.sql`, new: link each provider account to a user.
out-of-scope: |
  - Sign in with Apple.
EOF
error: <new task from template 'task'>:2: rules.judgment-stays-small: split the decision from the mechanical edits, so each task plans 5 source files or fewer
$ mt add -f - <<'EOF'
title: Rename the User type to Account
difficulty: 1
as-is: |
  The type is `User`, while the API, the database and the UI say account.

  + Grep `src/` for `User`.
  + 🔴 The type is `User`, while the API, the database and the UI say account.
to-be: |
  - 🟢 The type is `Account` everywhere, and no behavior changes.
changes: |
  - `src/**/*.rs`: rename `User` to `Account` in each of the 12 files that name it.
out-of-scope: |
  - The `users` table, which keeps its name.
EOF
wrote tasks/rename-the-user-type-to-account.typ (fys)
next: mt eval fys
```

The refused `mt add` exits `1` and doesn’t write a file.

## Rule details

`difficulty` rates how much judgment a task takes, from 0 for a mechanical edit to 9 for an open question. The template has a difficulty field and fills in 3 when you don’t rate the task. A task filed without a rating gets the cap. [Priority](https://mlavrinenko.github.io/mindtape/priority/index.md#difficulty) covers the scale.

The `judgment-stays-small` rule reads `count_paths(derived.changes, "@source")`: the distinct paths in the Changes section that fall inside the project’s `source` path set. Its `when` picks the open tasks rated 3 and up, so a closed task is not collected and a mechanical one has no cap. For a ladder, add a rule for each rung, such as `difficulty >= 6` with a cap of 2. With `severity = "error"`, every command that writes a task refuses one that breaks a rule. If you edit a task file by hand, `mt check` fails on it instead. [Rules](https://mlavrinenko.github.io/mindtape/rules/index.md) covers the rule keys, and [Filter language](https://mlavrinenko.github.io/mindtape/filters/index.md) covers the expressions.

`[tasks.estimate]` allows one unit, `src-files`, and leaves it optional. The unit stays so a task filed with `estimate.src-files` remains valid, while a new task declares its plan once, in Changes. Every Changes bullet starts with one backticked path. A terminal status, such as `done`, ends a task. [Statuses](https://mlavrinenko.github.io/mindtape/statuses/index.md) says which statuses are terminal, and [Estimates](https://mlavrinenko.github.io/mindtape/estimates/index.md) lists the other estimate keys.

The budget rule in `mindtape:budget` compares the files git reports changed with the same count, so `mt check` warns you when the work outgrows the plan. [Estimates](https://mlavrinenko.github.io/mindtape/estimates/index.md) shows that budget.

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