Skip to content

feat(alias): route --key=value via template refs, add -- escape, drop --var - #2287

Merged
max-sixty merged 4 commits into
mainfrom
alias-smart-routing
Apr 18, 2026
Merged

max-sixty merged 4 commits into
mainfrom
alias-smart-routing

Conversation

@max-sixty

@max-sixty max-sixty commented Apr 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Replace the alias-arg parser's "every --KEY=VALUE binds; bare --KEY errors" grammar with template-driven routing. A token only binds when the alias's pipeline references {{ KEY }}; otherwise it forwards into {{ args }}. Adds -- as a literal-forward escape and removes the --var KEY=VALUE / --var=KEY=VALUE special cases.

The template already declares which variables it consumes — using that as the routing signal removes both surprise binding (silent env=staging for templates that never reference env) and the unknown-flag error class. Every post-alias token now has a deterministic destination.

Grammar

Tokens after wt <alias> are walked left-to-right:

Token shape Routes to
--KEY=VALUE or --KEY VALUE where the template references {{ KEY }} Bound — KEY becomes the template value
--KEY=VALUE where the template doesn't reference KEY Forwarded literally to {{ args }}
--KEY followed by another --… (or end of args) Forwarded literally to {{ args }}
Bare positional Forwarded to {{ args }}
Anything after -- Forwarded to {{ args }} regardless of shape

--dry-run is the only post-alias built-in. --yes/-y is global only (wt -y <alias>) per #2290 — post-alias --yes falls through the shape rule and forwards as positional. Hyphens in the key canonicalize to underscores before lookup, so --my-var=value binds to {{ my_var }}.

Behavior changes

Input Before After
wt rm --force (no {{ force }} ref) Errored "Unknown flag" Forwards --force to {{ args }}
wt deploy --env staging Errored "Unknown flag" Binds env=staging if referenced; else forwards both to {{ args }}
wt deploy --env=staging (no {{ env }} ref) Silently bound env=staging Forwards --env=staging to {{ args }}
wt foo --var x=1 Bound x=1 via the special --var arm Same as --var=x=1: binds var="x=1" if referenced, else forwards
wt run -- --env=staging --env=staging consumed --env=staging forwarded literally
wt show --branch=override (with {{ branch }} ref) Bound (worked, undocumented) Bound, now documented and tested

Users who relied on --var KEY=VALUE should switch to --KEY=VALUE directly.

Navigating the diff

  • src/commands/alias.rs — AliasOptions::parse rewritten as a left-to-right walk against referenced_vars: &BTreeSet<String>. try_alias and step_alias resolve the alias's CommandConfig first, compute referenced_vars, then parse. step_alias now takes Vec<String> (parses internally) because routing needs the resolved alias.
  • src/config/expansion.rs — new referenced_vars_for_config helper unions template.undeclared_variables(false) across every command in a pipeline.
  • src/main.rs — call site updated for new step_alias signature.
  • tests/integration_tests/step_alias.rs — six new integration tests cover the grammar end-to-end (referenced bind, unreferenced forward, -- escape, multi-step binding, built-in overshadow, space-separated bind). The --var tests are gone.
  • tests/integration_tests/approval_ui.rs — updated test_post_alias_yes_does_not_skip_approval (renamed from main's …_no_longer_supported): under the new grammar --yes doesn't error, it forwards as positional, but still doesn't skip approval.
  • docs/content/extending.md (and auto-synced skill reference) — new "How arguments are routed" section, -- escape documented, built-in overshadow caveat added.

Test plan

  • cargo run -- hook pre-merge --yes (3255 tests, all pass)
  • Unit tests for parse grammar: test_parse_built_in_flags, test_parse_key_value_routing, test_parse_space_separated_routing, test_parse_hyphen_canonicalization, test_parse_literal_forward_escape, test_parse_mixed_pipeline, test_parse_positionals (covers post-alias --yes/-y forwarding), test_referenced_vars_for_config_unions_steps
  • Integration tests for end-to-end routing
  • Doc sync test passes

This was written by Claude Code on behalf of Maximilian

max-sixty and others added 2 commits April 18, 2026 11:32
… --var

Replace the old "every --KEY=VALUE binds; bare --KEY errors" grammar with
template-driven routing: a token only binds if the alias's pipeline
references {{ KEY }}. Otherwise it forwards into {{ args }}. Adds `--`
as a literal-forward escape and removes the `--var KEY=VALUE` /
`--var=KEY=VALUE` special cases — `--KEY=VALUE` covers the same use
case directly.

Co-Authored-By: Claude <[email protected]>
# Conflicts:
#	src/commands/alias.rs
#	src/main.rs

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done — template-driven routing is a much cleaner contract than the old shorthand, and the test coverage (referenced vs unreferenced, space-separated, -- escape, multi-step union, hyphen canonicalization) maps one-to-one with the grammar in the docstring.

One observation (not blocking — this is your call): CLAUDE.md states "Prefer deprecation warnings over silent breaks" for CLI flags. wt foo --var key=value no longer errors on upgrade; it forwards ["--var", "key=value"] into {{ args }} (or silently drops them if the template doesn't reference {{ args }}). A one-cycle deprecation — detecting --var as the leading token post-alias and printing a migration hint — would cushion the break without adding real complexity. Mentioning only because the PR description documents the migration path but the binary itself gives users no signal at the moment they hit the change. If you've already weighed this against the churn of keeping the special case around, disregard.

Minor unrelated: src/cli/hook.rs:41 still cross-references AliasOptions::parse as "alias variable shorthand" — the shorthand form is gone, so the analogy no longer holds. Outside this diff; happy to push a follow-up doc fix.

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Linux CI is failing on cargo insta test --unreferenced reject — not a flake. The test renames in tests/integration_tests/step_alias.rs (test_step_alias_with_var → test_step_alias_binds_referenced_var, test_step_alias_with_shorthand_var → test_step_alias_binds_space_separated_var) left two orphan snapshot files behind:

tests/snapshots/integration__integration_tests__step_alias__step_alias_with_var.snap
tests/snapshots/integration__integration_tests__step_alias__step_alias_with_shorthand_var.snap

Fix is a straight git rm of both. Happy to push the deletion if you'd like.

The two `--var`-form alias tests were deleted in this branch when the
parser stopped special-casing `--var KEY=VALUE`, but their snapshot files
were left behind. Pre-merge runs `cargo insta test --unreferenced reject`,
which trips on orphans.

Co-Authored-By: Claude <[email protected]>
# Conflicts:
#	src/commands/alias.rs
#	src/config/expansion.rs
#	src/config/mod.rs
#	tests/integration_tests/step_alias.rs
@max-sixty
max-sixty merged commit 8e3abf4 into main Apr 18, 2026
23 checks passed
@max-sixty
max-sixty deleted the alias-smart-routing branch April 18, 2026 21:15
max-sixty added a commit that referenced this pull request Apr 18, 2026
…nfig (#2299)

Drops the silent `if let Ok(tmpl) = ...` skip in
`referenced_vars_for_config` so a syntax error in any alias step
surfaces before flags are routed. Previously, a malformed template made
that step contribute no names to the referenced-var set, which silently
changed how `--KEY=VALUE` tokens bound vs. forwarded as positionals —
the deferred expansion path would only surface the syntax error later,
after args may have been routed wrong.

The helper now returns `anyhow::Result<BTreeSet<String>>`; callers in
`try_alias` and `step_alias` propagate with `?`. New unit test covers
the error path.

Follow-up from review of #2287.

> _This was written by Claude Code on behalf of Maximilian_

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants