Skip to content

feat(alias): dispatch aliases from top-level wt <name> - #2266

Merged
max-sixty merged 1 commit into
mainfrom
alias
Apr 16, 2026
Merged

max-sixty merged 1 commit into
mainfrom
alias

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

wt deploy now resolves deploy against configured aliases before falling through to a wt-deploy PATH binary. Built-ins still win (clap matches before alias dispatch ever runs), and wt step <name> keeps working at runtime — only the docs cut over to the new form.

Why

wt deploy reads better than wt step deploy, and aliases as first-class commands lower friction for using them as everyday shortcuts.

Precedence

built-in (clap) → alias (user/project config, merged) → wt-<name> PATH binary → "unrecognized subcommand" error.

User config wins over PATH binaries because aliases are how users customize wt — same model as git, where [alias] entries shadow git-foo externals.

Navigating the diff

  • src/commands/alias.rs — refactored step_alias to share run_alias with the new try_alias(name, rest) -> Result<Option<()>>. Returns Ok(None) when the name isn't a configured alias or when not in a git repo; propagates config-load errors so a broken wt.toml fails loudly instead of silently turning into "unrecognized subcommand". Argument parsing is gated on alias-membership, so unrelated args meant for an external binary don't surface as alias parse errors. New alias_names_for_suggestions() mixes alias names into "did you mean" hints. HelpContext enum lets the help splice annotate "(shadowed by built-in)" against the right level (top-level builtins for wt --help, step builtins for wt step --help). The user-facing "shadow warning" was removed entirely — under the new model an alias named commit runs fine via wt commit, only wt step commit is shadowed.
  • src/commands/external.rs — handle_external_command calls try_alias first, then PATH lookup, then unrecognized-subcommand error. Suggestions include alias names. Non-UTF-8 args bypass alias dispatch (alias parser requires UTF-8; binary subcommands get raw OsStr).
  • src/help.rs + src/main.rs — early-parse pass returns Option<HelpContext>; help splice fires for both wt --help and wt step --help.
  • src/completion.rs — aliases injected at the top level in addition to step.
  • src/cli/mod.rs — long Aliases section moved out of Step::after_long_help into hand-authored docs/content/extending.md. New sync test test_top_level_builtins_match_clap keeps the TOP_LEVEL_BUILTINS constant aligned with the Cli enum.

Tests

3221 tests pass, lints clean. New integration tests: test_top_level_alias_dispatch, test_top_level_alias_with_step_builtin_name, test_top_level_alias_did_you_mean. Removed test_step_alias_shadows_builtin_plural (warning gone). Reframed test_step_alias_shadows_builtin to verify shadow filtering of typo suggestions instead. Completion tests now isolate user config via WORKTRUNK_CONFIG_PATH=/dev/null — project config isolation is a noted gap (commented inline).

🤖 Generated with Claude Code

`wt deploy` now resolves `deploy` against configured aliases before
falling through to a `wt-deploy` PATH binary. Built-ins still win
(clap matches before alias dispatch), but aliases beat externals.
`wt step <name>` continues to work at runtime; only documentation
moves to the new form.

Help splices the Aliases section into both `wt --help` and
`wt step --help`, with "(shadowed by built-in)" annotations
contextual to each level. Typo suggestions include alias names.
Completion injects aliases at the top level too.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit a1be564 into main Apr 16, 2026
25 checks passed
@max-sixty
max-sixty deleted the alias branch April 16, 2026 21:56
max-sixty added a commit that referenced this pull request Apr 16, 2026
Adds a `WORKTRUNK_PROJECT_CONFIG_PATH` environment variable that
overrides the project config path, mirroring the existing
`WORKTRUNK_CONFIG_PATH` (user) and `WORKTRUNK_SYSTEM_CONFIG_PATH`
(system) overrides.

Uses it to fully isolate completion tests in `shell_wrapper.rs`, which
previously only isolated user and system config. After PR #2266 made
aliases appear as completion candidates, any `[aliases]` added to this
repo's own `.config/wt.toml` would silently pollute completion snapshots.

Co-Authored-By: Claude <[email protected]>
max-sixty added a commit that referenced this pull request Apr 16, 2026
Adds a \`WORKTRUNK_PROJECT_CONFIG_PATH\` environment variable that
overrides the project config path, mirroring the existing
\`WORKTRUNK_CONFIG_PATH\` (user) and \`WORKTRUNK_SYSTEM_CONFIG_PATH\`
(system) overrides. Missing files at the overridden path resolve to no
project config — same as a missing \`.config/wt.toml\` today.

Uses it to fully isolate completion tests in
\`tests/integration_tests/shell_wrapper.rs\`, which previously only
isolated user and system config. After #2266 made aliases appear as
top-level completion candidates at \`wt <Tab>\`, any \`[aliases]\` added
to this repo's own \`.config/wt.toml\` would silently pollute completion
snapshots. The helper \`set_empty_user_config\` is renamed
\`set_empty_configs\` and now points all three env vars at
\`/dev/null\`.

Also cleans up \`wt config show --format=json\` to use
\`project_config_path()\` for the \`project.path\` field (was hardcoded
\`.config/wt.toml\`), so the override is reflected in both path and
config.

\`configure_cli_command\` intentionally leaves
\`WORKTRUNK_PROJECT_CONFIG_PATH\` unset — the \`WORKTRUNK_*\` env_remove
loop prevents host leakage, and setting it would break tests that rely
on the default \`.config/wt.toml\` lookup in their own test repo.
Completion tests opt in explicitly via \`set_empty_configs\`.

## Test plan

- [x] \`cargo run --quiet --bin wt -- hook pre-merge --yes\` — 3222/3222
green
- [x] New integration test \`test_project_config_path_env_var_override\`
covers override-to-different-file and override-to-missing-file

Co-authored-by: Claude <[email protected]>
max-sixty added a commit that referenced this pull request Apr 16, 2026
After PR #2266 merged, two sites computed Jaro-Winkler "did you mean"
suggestions with the same 0.7 threshold, descending sort, and (mostly)
the same dedupe needs: `similar_subcommands` in
`src/commands/external.rs` (top-level dispatch) and the inline scoring
inside `unknown_step_command_exit` in `src/commands/alias.rs` (`wt step`
dispatch). This pulls the scoring loop into a `did_you_mean` helper
alongside `format_command_label` in `commands/mod.rs`, and has both
sites delegate to it.

The helper's docstring pins the 0.7 threshold to clap's internal
`did_you_mean` so future maintainers know not to drift. The `alias.rs`
site gains harmless dedupe — no shadowing collisions reach that point
because shadowed names are filtered out before the call.

Behavior is unchanged: same threshold, same sort order, same outputs.
The five `similar_subcommands_*` unit tests in `external.rs` and the two
`test_*_alias_did_you_mean` integration tests pass unchanged.

> _This was written by Claude Code on behalf of @max-sixty_

Co-authored-by: Claude <[email protected]>
@max-sixty max-sixty mentioned this pull request Apr 18, 2026
4 tasks done
max-sixty added a commit that referenced this pull request Apr 18, 2026
## Summary

`-y, --yes` is now a top-level global clap flag. It moves off every
subcommand's clap args and lives once on `Cli`, so `wt -y <anything>`,
`wt <anything> --yes`, and `wt --yes <anything>` all skip any approval
or confirmation prompt for that invocation.

## Why

Follow-up to the top-level alias dispatch (#2266). The long-term plan is
to unify approval-bypass behavior — `-y` should be a true global rather
than duplicated across switch, remove, merge, commit, squash, prune, all
ten hook subcommands, shell install/uninstall, plugin install/uninstall,
and config update. A single canonical flag removes ~50 lines of
duplicated clap definitions and one source of drift.

## Call-site survey

Approval and confirmation prompt sources, as surfaced by `rg -l
'approve_|requires_approval|confirm_'`:

- `approve_hooks` / `approve_hooks_filtered` — reads `ctx.yes`, already
threaded via `CommandContext::new(..., yes)`. No change needed; the
global now feeds those call sites from `handle_*_command` in `main.rs`.
- `approve_command_batch` (merge, config `hook approvals add`) — takes
`yes: bool`. Receives the global.
- `approve_alias_commands` — takes `yes: bool`. Receives `global_yes ||
opts.yes` (see "Alias compat" below).
- `handle_configure_shell` / `handle_unconfigure_shell` /
`handle_config_update` / `handle_claude_install[_statusline]` /
`handle_claude_uninstall` / `handle_opencode_install` /
`handle_opencode_uninstall` — take `yes: bool` for confirmation-prompt
bypass. All receive the global.

## Alias compat

`AliasOptions` is hand-rolled (not clap) so it doesn't conflict with the
clap global. Its post-alias `--yes` parsing is intentionally preserved
here — `run_alias` does `let skip_approval = global_yes || opts.yes;` so
both `wt -y deploy` and `wt deploy --yes` work unchanged. Removing the
post-alias form is a separate cleanup, tracked by the user's long-term
simplification plan.

## Navigating the diff

- `src/cli/mod.rs` — new `yes: bool` on `Cli` with `global = true`,
`short = 'y'`, `help_heading = "Global Options"`, `display_order = 103`
(slots after `-v`). Removed the per-command `yes` field from
`SwitchArgs`, `RemoveArgs`, `MergeArgs`.
- `src/cli/step.rs` — removed `yes` from `CommitArgs`, `SquashArgs`, and
`StepCommand::Prune`. Also dropped `help_heading = "Automation"` from
the four step subcommands where the group was left with a single flag
(`commit`, `squash`, `for-each`, `prune`); those flags now render under
default Options instead of a single-item group.
- `src/cli/hook.rs` — removed `yes` from all ten hook subcommands
(`pre-switch`, `post-switch`, `pre-start`, `post-start`, `pre-commit`,
`post-commit`, `pre-merge`, `post-merge`, `pre-remove`, `post-remove`).
`--yes` stays in `KNOWN_HOOK_LONG_FLAGS` so the shorthand rewriter still
recognizes it as a real flag rather than a template variable.
- `src/cli/config.rs` — removed `yes` from
`ConfigShellCommand::Install/Uninstall`, `ConfigCommand::Update` (and
its now-redundant `conflicts_with = "yes"` on `--print`),
`ConfigPluginsOpencodeCommand::Install/Uninstall`,
`ConfigPluginsClaudeCommand::Install/Uninstall/InstallStatusline`.
- `src/main.rs` — `dispatch_command` takes `yes: bool`; each
`handle_*_command` accepts and threads it. `Cli` destructure adds `yes`.
- `src/commands/alias.rs` — `try_alias`, `step_alias`, `run_alias` take
`global_yes: bool`. `run_alias` OR's with `opts.yes` before calling
`approve_alias_commands`.
- `src/commands/custom.rs` — `handle_custom_command` accepts and passes
the global to `try_alias`.
- `docs/content/` + `skills/worktrunk/reference/` — auto-generated from
`--help-page`; the global appears under "Global Options" on every
subcommand.
- `tests/integration_tests/approval_ui.rs` — six new tests:
`test_global_yes_before_subcommand`, `test_global_yes_for_hook`,
`test_global_yes_for_alias`, `test_post_alias_yes_still_works`,
`test_global_yes_for_step_alias`,
`test_global_yes_on_command_without_approval`.

## Notes

- Does not remove `AliasOptions::yes` — deferred cleanup per the task
brief.
- Snapshot churn (~27 help files) is the expected fallout of adding a
global flag; each subcommand's `--help` now shows `-y, --yes` under
Global Options.

## Test plan

- [x] 3242 tests pass (`cargo run -- hook pre-merge --yes`)
- [x] Lints clean (clippy, cargo fmt, pre-commit)
- [x] Doc sync test passes after regeneration
- [x] New approval_ui tests cover before-subcommand, after-subcommand,
alias, post-alias, step-alias, and no-approval positions

> _This was written by Claude Code on behalf of Maximilian_

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Co-authored-by: worktrunk-bot <[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