Trace commits to tasks

Refuse a commit that doesn’t point at a task, then ask which tasks changed a file before you edit it.

git blame shows you a line and the subject “fix(auth): reject expired sessions”. That subject doesn’t say which task asked for the change, what problem it fixed or what it left out. An agent about to edit the file cannot answer any of them.

Config

examples/api-service/.mindtape/config.toml

[commits]
trailer = "Refs"

Behavior

Add a commit-msg hook that runs mt check --commit-msg. From then on git refuses a commit without a Refs: trailer and accepts it with one, and touches() finds the task behind the changed file:

$ cat >.git/hooks/commit-msg <<'EOF'
#!/bin/sh
exec mt check --commit-msg "$1"
EOF
$ chmod +x .git/hooks/commit-msg
$ git commit -am "fix(auth): reject expired sessions on token refresh"
error: .git/COMMIT_EDITMSG: commits.rules.name-task-in-refs-trailer: name the task this commit works on in a `Refs: <stem>` footer
error: 1 commit message problem
$ git commit -am "fix(auth): reject expired sessions on token refresh" -m "Refs: reject-expired-sessions-on-token-refresh"
ok: commit message valid
[main 062269d] fix(auth): reject expired sessions on token refresh
1 file changed, 3 insertions(+)
$ 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

The trailer and the rules

[commits] trailer sets the trailer that names task stems. A stem is the task’s file name without .typ, as Concepts explains. The project also extends the mindtape:tasks rule pack, as Require a task shape shows. The pack’s name-task-in-refs-trailer rule refuses a commit that doesn’t point at a task, unless the commit changes only task sources or starts with fixup!, squash! or amend!. A template, a reserved .mindtape or .git path and a symlink do not make a commit task-only, while a markerless .typ under a task root does. The pack’s squash-every-autosquash-commit rule refuses such a commit once it is in a range, so mt check --commits catches a fixup that was not squashed. mt check --commit-msg also refuses a stem that no task has and that matches no [commits] external-refs pattern. Commit rules covers the rule fields, and Packs shows how to drop the rule.

Anyone can skip a hook with --no-verify, so run mt check --commits in CI on the commits a push contains. Commit rules shows how.

touches("<path>") matches each task named in the trailer of a commit that changed the path. Filter language covers it.

This repo checks every commit message against .mindtape/config.toml.