worktrunk icon indicating copy to clipboard operation
worktrunk copied to clipboard

Turn deprecated `commits` squash template variable into an error (after 2026-09-06)

Open worktrunk-bot opened this issue 5 months ago • 7 comments

Background

wt step squash / wt merge build the squash commit-message prompt from a minijinja template. Two variables expose the commits being squashed:

  • commits — a list of bare commit subject strings (the original variable).
  • commit_details — a list of { subject, body } objects (added in #2983 to expose commit bodies).

commit_details is a strict superset: {{ commit.subject }} reproduces what commits gave, and .body is newly available. To converge on a single richer variable, we are deprecating commits.

Deprecation cycle

  1. Now (deprecated): PR #2985 switches the default squash template, docs, and example config to commit_details + .subject. commits still works, but a squash template that references it emits a one-time deprecation warning. Because the shape changes (string → object), the migration is not a mechanical rename — a template must change {{ commit }} to {{ commit.subject }} by hand, so wt config update does not auto-rewrite it.
  2. After 2026-09-06 (this issue): turn a squash template that references commits into a hard error (rather than silently rendering an empty/changed value), pointing users at commit_details.
  3. Future (separate issue): once commits is fully retired, optionally re-introduce commits as the list-of-objects form (aliasing commit_details), so the natural name carries the richer data.

Scope of this issue (step 2)

  • [ ] Detect commits usage in the rendered squash template and bail! with a clear message instead of warning.
  • [ ] Update docs/help to drop the deprecated commits row (or mark it removed).
  • [ ] Add/adjust tests covering the error path.

Filed per maintainer request in https://github.com/max-sixty/worktrunk/pull/2983#issuecomment-4637273025.

worktrunk-bot avatar Jun 06 '26 03:06 worktrunk-bot

When the deprecation becomes an error, the message should name the replacement variable and identify the configuration file or template containing commits. A migration test using an existing config would verify both the cutoff behavior and the suggested replacement. It may also be worth documenting whether the date is tied to a release rather than wall-clock time, so older binaries remain deterministic.

hiSandog avatar Jul 11 '26 05:07 hiSandog

Good points — a couple worth grounding against the current code, since the implementation moved a bit from the plan in the issue body.

On the date being release- vs wall-clock-tied: it's a release milestone, not a runtime check. There's no now() > 2026-09-06 gate anywhere near this deprecation — the commits handling runs entirely through the standard config-deprecation framework (DEPRECATED_VARS), which has no date input. So determinism is already preserved: a given binary always behaves the same regardless of wall-clock, and an older binary keeps warning-and-rendering forever — the hard error only appears in whatever release lands step 2. Agree it's worth saying that explicitly so nobody expects a self-activating cutoff.

On naming the replacement + the config file (your first point): the framework already warns per config path and per (old → new) pair, so the "name commit_details, point at the file" behavior is mostly a matter of reusing that plumbing for the bail! in step 2 rather than new machinery.

One divergence that affects your migration-test point: contrary to plan-1's "not a mechanical rename / wt config update does not auto-rewrite it", the shipped code makes commits → commit_details a mechanical UpdateOnly rewrite — safe because a bare-printed commit_details element renders as its subject, so {% for c in commit_details %}{{ c }} is identical to the old {% for c in commits %}. So wt config update does migrate it today, and step 2's error mainly catches configs that never ran update. Your migration-test suggestion lands on a real gap: the test_warning_fires_iff_update_changes battery currently exercises template-var rewrite via repo_root, not commits specifically.

Sources

worktrunk-bot avatar Jul 11 '26 05:07 worktrunk-bot

I'll take the removal step here. Current main still supplies commits when rendering prompts. I'll reject references to that removed variable with a clear commit_details and template-location hint, keep wt config update able to migrate existing configs, and cover the command error and migration paths. The change will be tied to the release that includes it, not to a runtime date check.

fzlzjerry avatar Sep 11 '26 07:09 fzlzjerry

Thanks for picking this up. Three notes from current main (b3e60b8) — the last one is worth a maintainer answer before you invest in the error path, since it could change the shape of the whole change.

The docs half is already done. #2985 removed the commits row from after_long_help in src/cli/mod.rs and its generated mirrors, so the variable isn't documented anywhere today. What's actually left in scope is the error path plus tests.

The error can't just be a bail! at render time. CLAUDE.md keeps all config deprecation in one layer (src/config/deprecation.rs), and commits is one of five rows in DEPRECATED_VARS that share a single UpdateOnly(migrate_template_vars_doc) rule with repo_root, worktree, main_worktree, and main_worktree_path. Erroring on commits alone means splitting it out of that shared rule, and reconciling it with test_warning_fires_iff_update_changes — the pinned invariant is "a warning fires exactly when wt config update would change the file", and a row that errors rather than warns needs an explicit answer for both halves of that. Your goal of keeping wt config update able to migrate is compatible with erroring on load (error, and point at wt config update as the fix), but the iff battery has to be taught the new shape rather than just extended.

The premise for step 2 no longer holds, which may make it the wrong step. The issue body justified the hard error as better "than silently rendering an empty/changed value". That isn't what happens today: commits is still rendered at src/llm.rs#L708 as the list of subject strings, and a commit_details element renders as its bare subject (CommitDetailValue::render), so an unmigrated template produces exactly the output it always did. A hard error would therefore break configs that currently render correctly, purely to converge on one name. Step 3 in the issue — re-introduce commits as an alias of commit_details — would instead let the old name keep working and carry .subject/.body, needing no error at all and collapsing steps 2 and 3 into one change.

Which of those the project wants is a maintainer call, not mine; the plan in the issue body predates the implementation that landed in #2985. I'd ask on this thread before building, because the two paths share almost no code.

worktrunk-bot avatar Sep 11 '26 07:09 worktrunk-bot

The retirement landed on main in #4080 (b1e0871), by a different mechanism than the plan in the issue body — worth recording here before anyone invests in the error path.

Rather than making a commits reference a hard error, #4080 stopped supplying the variable at all and moved the rename into the load-path deprecation layer. commits is now a row in RETIRED_VARS under a DeprecationRule::Structural rule, so {{ commits }} → {{ commit_details }} is rewritten in the in-memory config on every load, before serde parses, with the deprecation warning still firing and still pointing at wt config update to write the rename into the file. build_prompt supplies only commit_details.

That answers the failure mode the issue opens with. The reason the rewrite had to move to load rather than stay UpdateOnly is in the RETIRED_VARS docstring: build_prompt renders under minijinja's default UndefinedBehavior::Lenient, which iterates an undefined value as an empty sequence — so an unmigrated squash template reaching the renderer would have silently dropped its commit list rather than erroring. The same commit retired main_worktree, repo_root, worktree and main_worktree_path the same way.

So step 2's checklist is satisfied in substance (commits no longer renders anything), but not literally — there is no bail!, and an unmigrated template keeps working. @max-sixty, this is the open question: is the auto-rewrite the end state, or do you still want a hard error once the rewrite has been out for a release? Leaving the issue open for that call.

@fzlzjerry — heads up, since you'd picked up the removal step: the "current main still supplies commits" premise no longer holds, so there's no removal left to do unless the answer above is "hard error".

Two leftover references to the retired names

Both are stale docstrings the retirement missed; neither affects behavior.

  • src/config/user/accessors.rs#L232-L233 — format_path's argument doc still says main_worktree "supplies both {{ main_worktree }} and {{ repo }}". #4080 deleted the vars.insert("main_worktree", …) line directly below it; only repo is supplied now.
  • src/config/commands.rs#L43 — Command::template's doc offers {{ worktree }} as an example variable; it's retired to worktree_path.

Not opening a PR for these yet — the bot already has six PRs open and they're competing for review; happy to send them whenever the queue drains or if you'd rather have them now.

worktrunk-bot avatar Sep 16 '26 06:09 worktrunk-bot

fix those references, add a TODO to remove the vars in 3 months

max-sixty avatar Sep 16 '26 17:09 max-sixty

Both docstrings are fixed and the TODO is in #4139, dated 2026-12-16 — three months on from #4080.

One constraint the TODO records, because it makes "remove the vars" non-uniform: dropping a RETIRED_VARS row stops the rename, so the old name has to fail loudly on its own before the row can go. repo_root, worktree, main_worktree, and main_worktree_path already do — hook, alias, and worktree-path templates expand under SemiStrict, so an undefined name is an error there. commits doesn't: build_prompt renders under minijinja's Lenient, which iterates an undefined value as an empty sequence, so dropping that row on its own would go back to silently emptying a squash prompt's commit list. So that row needs build_prompt to reject the name itself first — i.e. the step-2 hard error this issue opens with, which is still the open call on this thread.

worktrunk-bot avatar Sep 16 '26 17:09 worktrunk-bot