Skip to content

feat(step): add alias command for user-defined command templates - #1348

Merged
max-sixty merged 9 commits into
mainfrom
alias
Mar 8, 2026
Merged

max-sixty merged 9 commits into
mainfrom
alias

Conversation

@max-sixty

@max-sixty max-sixty commented Mar 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Adds wt step <alias-name> for running user-defined command templates configured in [aliases] sections of user or project config
  • Aliases support the same template variables as hooks ({{ branch }}, {{ worktree }}, etc.) plus custom --var KEY=VALUE variables
  • Project-config aliases require the same command approval flow as project hooks; user-config aliases are trusted. --dry-run skips approval since it's a read-only preview
  • Alias names matching built-in step commands are filtered from the "available" list in error messages (shadowed by the built-in)
  • Introduces Phase enum (Hook(HookType) | Alias) replacing the old hook_type + phase_override pattern in the approval system
  • Renames HookCommand to ApprovableCommand since it now covers both hooks and aliases

Test plan

  • Unit tests for AliasOptions::parse (name-only, --dry-run, --yes, --var, empty key rejection, positional arg rejection)
  • Integration tests for alias execution, dry-run (without --yes), exit code propagation
  • Integration tests for shadowing (filtered from available list)
  • Integration tests for user/project config merging
  • Integration tests for approval flow (project prompts, user skips, override skips, already-approved, --yes bypass, decline)
  • Unit tests for merge_alias_maps coverage
  • Sync test: BUILTIN_STEP_COMMANDS matches actual StepCommand clap variants

This was written by Claude Code on behalf of max-sixty

Aliases are configured in `[aliases]` sections of user config or project
config and invoked via `wt step <name>`. They support the same template
variables as hooks ({{ branch }}, {{ worktree_path }}, etc.), --dry-run
to preview expanded commands, and --var KEY=VALUE for extra variables.

User config overrides project config on name collision. Feature is marked
experimental in documentation.

Co-Authored-By: Claude <[email protected]>
Aliases named after built-in subcommands (commit, push, rebase, etc.)
are silently ignored because clap dispatches built-ins first. Now emits
a warning so users know the alias will never run.

Co-Authored-By: Claude <[email protected]>
The merge_alias_maps function in sections.rs was uncovered, causing
codecov/patch to report below-target coverage on changed lines.

Co-Authored-By: Claude <[email protected]>
Project-config aliases now require the same approval flow as project hooks.
User-config aliases remain trusted and skip approval. When a user overrides
a project alias, the user version is trusted.

Adds --yes/-y flag to bypass approval in CI/CD environments.

Co-Authored-By: Claude <[email protected]>

@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.

Clean feature addition. The alias system integrates well with the existing hook infrastructure — reusing template expansion, the approval flow, and run_command_streaming. Test coverage is thorough across all the important scenarios (approval matrix, user/project merge, shadowing, exit codes, dry-run).

A few observations:

Observations (3 items)
  1. phase_override on HookCommand — The HookCommand struct now carries a phase_override: Option<String> and a dummy hook_type: HookType::PostCreate that's documented as "unused for display." This works but makes HookCommand aware of a concept (alias) that's outside its original domain. An alternative would be a small enum (Phase { Hook(HookType), Alias }) that replaces both fields, though that's a larger refactor and probably not worth it for a single use case today. Fine as-is with the comment.

  2. Shadowing check runs on every alias invocation — step_alias iterates all aliases to check for built-in shadows every time, even when the user is running a non-shadowed alias. The warning is useful, but it means someone with test = "cargo test" in their config will see the warning on every wt step deploy invocation — not just when they try to run test. This could become noisy. Worth considering whether to only warn when the requested alias itself is shadowed, or at config-load time.

  3. --yes on alias-only approval doesn't save — This is intentional and tested (test_alias_approval_yes_bypasses), matching the hook behavior. Just noting it's consistent.

CI is green across all platforms (lint, test linux/macOS/windows, code-coverage, codecov/patch all pass).

Looks good to merge.

…ation

Shadowed aliases (names matching built-in step commands) are now filtered
from the "available" list in error messages rather than emitting a warning
on every alias invocation.

Co-Authored-By: Claude <[email protected]>
worktrunk-bot
worktrunk-bot previously approved these changes Mar 8, 2026

@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.

CI is failing due to a rustfmt formatting issue introduced by removing warning_message from the import. The remaining imports are short enough for a single line. The test failures cascade from the same pre-commit lint check — cargo fmt fixes it.

Comment thread src/commands/alias.rs Resolved
@worktrunk-bot
worktrunk-bot dismissed their stale review March 8, 2026 01:28

CI failing - rustfmt issue

max-sixty and others added 2 commits March 7, 2026 19:44
…eCommand

Replace the `hook_type` + `phase_override: Option<String>` pair with a
`Phase` enum (`Hook(HookType)` | `Alias`). Eliminates the dummy
`HookType::PostCreate` value and the stringly-typed override.

Rename `HookCommand` to `ApprovableCommand` to reflect its broader role.

Co-Authored-By: Claude <[email protected]>
- Simplify approve_alias: let approve_command_batch handle the
  is_command_approved check instead of duplicating it
- Skip approval for --dry-run (read-only preview doesn't need permission)
- Reject empty --var keys (e.g., --var =value)
- Fix error message: "Unexpected argument" instead of "Unknown flag" for
  positional args
- Add BUILTIN_STEP_COMMANDS sync test to catch drift from StepCommand enum
- Document --yes, approval requirement, and shadowing in alias help text
- Add [aliases] section to wt.example.toml project config template

Co-Authored-By: Claude <[email protected]>

@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.

The Phase enum refactor is a clean improvement — ApprovableCommand with Phase::Hook(HookType) | Phase::Alias is much better than the old hook_type + phase_override pattern. The rename from HookCommand to ApprovableCommand accurately reflects its expanded scope.

The rest of the incremental changes (project config aliases field, user config merge logic, merge_alias_maps, approval flow integration) are straightforward and well-tested.

@max-sixty
max-sixty merged commit 55bc918 into main Mar 8, 2026
22 checks passed
@max-sixty
max-sixty deleted the alias branch March 8, 2026 05:46
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