Skip to content

Refactor approvals into separate file with deprecation migration - #1042

Merged
max-sixty merged 12 commits into
mainfrom
958
Feb 16, 2026
Merged

max-sixty merged 12 commits into
mainfrom
958

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

  • Moves approved hook commands from config.toml to a dedicated approvals.toml file, enabling dotfile management of config.toml without carrying per-project approval state
  • Adds deprecation detection for stale approved-commands entries in config.toml — wt config show generates a migration file and shows a diff + mv command; other commands show a brief warning
  • Updates all CLI help text, docs, FAQ, and example config to reference approvals.toml

Test plan

  • 512 unit tests pass (including 12 new deprecation detection/migration tests)
  • 309 related integration tests pass (approval, help, config_show, hook_show, post_start, remove, user_hooks, shell_wrapper, doc sync)
  • All lints pass (pre-commit run --all-files)
  • Snapshot tests reviewed for correct migration diffs and updated help text

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

max-sixty and others added 2 commits February 15, 2026 13:34
Approved commands are now stored in `~/.config/worktrunk/approvals.toml`,
independent of user config. This enables dotfile management of
`config.toml` without exposing machine-local trust state.

The `Approvals` type provides the same mutation interface as
`UserConfig` (approve/revoke commands, file locking) but stores
exclusively approval data. For backward compatibility, approvals
are silently read from `config.toml` if `approvals.toml` doesn't exist.

All command approval code now uses `Approvals::load()` and passes
`&approvals` to `approve_command_batch()`. Tests use isolated
`test_approvals_path()` to prevent pollution of user approvals.
Approved commands moved to approvals.toml in the previous commit but
stale entries in config.toml were silently ignored. Now `wt config show`
detects them, generates a migration file that removes the entries, and
shows a diff + mv command. Other commands show a brief warning.

Also updates all CLI help text, docs, and FAQ to reference
approvals.toml as the storage location, and migrates all test configs
to use write_test_approvals() for approved-commands content.

Co-Authored-By: Claude <[email protected]>
# Conflicts:
#	src/commands/command_approval.rs
#	src/commands/hook_commands.rs
#	src/commands/merge.rs
Address PR review feedback:
- Document why `load_from_config_fallback()` uses `get_config_path()` while
  `reload_from()` uses sibling derivation, and why both converge in production
- Add `test_load_from_config_file` testing the extraction logic
- Add `test_mutation_picks_up_config_toml_fallback` testing the full mutation
  path with config.toml fallback (no approvals.toml → reads config.toml →
  preserves existing commands alongside new one)
- Inline `get_config_path` import (only used in `#[cfg(not(test))]` block)

Co-Authored-By: Claude <[email protected]>
Replace two separate fallback implementations (load_from_config_fallback
via get_config_path, and reload_from via sibling derivation) with a
single load_with_fallback(path) that both load() and reload_from() use.

The shared helper derives config.toml as a sibling of the approvals
file, which is always correct since get_approvals_path() derives
approvals.toml as a sibling of config.toml.

Co-Authored-By: Claude <[email protected]>
Shell wrapper tests only passed WORKTRUNK_CONFIG_PATH to the binary,
so it derived the approvals path from config and found approved-commands
in config.toml, triggering the new deprecation warnings. This broke
4 snapshot tests and likely caused 6 timeouts on CI.

Fix: pass WORKTRUNK_APPROVALS_PATH alongside WORKTRUNK_CONFIG_PATH in
all shell wrapper test environments (build_shell_script, build_test_env_vars,
and custom script builders for all shell types). Migrate all approved-commands
writes from test_config_path() to write_test_approvals().

Co-Authored-By: Claude <[email protected]>
Rustdoc interprets `[projects]` as a broken intra-doc link.
Escape with `\[...\]` to treat as literal text.

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

Copy link
Copy Markdown
Contributor

Review: Refactor approvals into separate file with deprecation migration

This is a well-structured separation of concerns — moving machine-local trust state (approved-commands) out of config.toml into a dedicated approvals.toml enables dotfile management of user config without carrying per-project approval state. The design choices are sound.

Overall: Looks good. A few observations below, none blocking.

Design observations (5 items)

1. Fallback derivation under WORKTRUNK_APPROVALS_PATH

load_with_fallback derives the config.toml fallback path via path.with_file_name("config.toml"). When WORKTRUNK_APPROVALS_PATH is set to an arbitrary location, this sibling derivation may not find the real config.toml. This is fine in practice since: (a) production derives both paths from the same config dir, (b) the env var is primarily for testing where no fallback is needed, and (c) the fallback gracefully returns empty. Just noting it's a documented assumption worth keeping in mind if the env var ever gets production use.

2. Backward compatibility is well handled

The silent fallback-on-read / write-to-new-file-on-mutate approach is clean. Users with existing approved-commands in config.toml will have them silently honored until any approval mutation creates approvals.toml, at which point it becomes authoritative. The deprecation detection + migration file generation in wt config show gives users a clear path to clean up.

3. UserProjectOverrides::is_empty() change is correct

Removing approved_commands.is_empty() from the check is right since approvals no longer belong in config.toml. The only callers of this method were the old approval mutation code (now removed). The field itself is kept for backward-compatible deserialization, which is the correct approach.

4. Lock reuse via acquire_config_lock

Approvals::with_locked_mutation reuses acquire_config_lock from user::mutation. The lock file path is derived from the approvals path (e.g., approvals.toml.lock), which is distinct from config.toml.lock. This correctly prevents contention between config and approval mutations while still protecting concurrent approval writes.

5. save_to always rewrites the full file

Unlike config.toml which preserves comments via toml_edit round-tripping, save_to builds a fresh document from the in-memory Approvals struct. This is acceptable for a machine-generated file, but means any manually added comments in approvals.toml would be lost on the next mutation. The file isn't user-edited, so this is fine.

Minor suggestions (3 items)

1. format_multiline_array is now duplicated

The helper was moved from UserConfig::format_multiline_array (private in persistence.rs) to a module-level format_multiline_array in approvals.rs. Both implementations are identical. If the persistence.rs version is now dead code (since approved-commands are no longer serialized to config.toml), this is clean. But if any other config serialization still uses the old one, there's an opportunity to deduplicate into a shared utility. Looking at the diff, the old one was removed — so this is fine as-is.

2. approved_commands field still in UserProjectOverrides

The field is kept with skip_serializing_if = "Vec::is_empty" for backward-compatible parsing. Consider adding a doc comment noting it's deprecated (parse-only) to prevent future contributors from accidentally writing to it. The existing comment on is_empty() partially covers this, but a comment on the field itself would be clearer.

3. Test cleanup: write_test_config calls split nicely

Several tests that previously combined worktree-path and approvals in a single write_test_config call now correctly split into write_test_config (for config) + write_test_approvals (for approvals). The template escape cleanup in write_test_config calls (removing {{{{/}}}} double-escaping from format strings) is a nice readability improvement.

Repository owner deleted a comment from github-actions Bot Feb 16, 2026
Repository owner deleted a comment from github-actions Bot Feb 16, 2026
Repository owner deleted a comment from github-actions Bot Feb 16, 2026
Repository owner deleted a comment from github-actions Bot Feb 16, 2026
Repository owner deleted a comment from github-actions Bot Feb 16, 2026
…y tests

- e2e_shell_post_start: write approved-commands to approvals.toml
  instead of config.toml (fixes 5 timeout failures from unanswered
  approval prompts)
- approval_pty permission test: use a subdirectory for the read-only
  approvals path so the temp root stays writable for .zshrc and other
  test files

Co-Authored-By: Claude <[email protected]>
Add tests covering error paths, edge cases, and new deprecation features:
- approvals.rs: load_from_file parse errors, load_from_config_file parse
  errors, load_from_path nonexistent, revoke on nonexistent projects,
  clear_all when empty, save_to with empty project, revoke_project with
  empty commands
- deprecation.rs: remove_approved_commands with invalid TOML,
  format_deprecation_details with approved_commands flag,
  write_migration_file with approved_commands

Co-Authored-By: Claude <[email protected]>
max-sixty and others added 2 commits February 16, 2026 14:29
Adversarial review found a normalization bug: revoke_command used exact
string matching while is_command_approved normalizes template variables.
Rather than fix a method with no production callers, remove it entirely.
Production code uses revoke_project (removes all approvals for a project)
and clear_all.

Rewrote test_concurrent_revoke_preserves_all_changes to use revoke_project.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit 600da71 into main Feb 16, 2026
21 checks passed
@max-sixty
max-sixty deleted the 958 branch February 16, 2026 22:54
max-sixty added a commit to goodtune/worktrunk that referenced this pull request Feb 17, 2026
…-sixty#1042)

* Refactor approvals into separate file

Approved commands are now stored in `~/.config/worktrunk/approvals.toml`,
independent of user config. This enables dotfile management of
`config.toml` without exposing machine-local trust state.

The `Approvals` type provides the same mutation interface as
`UserConfig` (approve/revoke commands, file locking) but stores
exclusively approval data. For backward compatibility, approvals
are silently read from `config.toml` if `approvals.toml` doesn't exist.

All command approval code now uses `Approvals::load()` and passes
`&approvals` to `approve_command_batch()`. Tests use isolated
`test_approvals_path()` to prevent pollution of user approvals.

* Add deprecation warning for approved-commands in config.toml

Approved commands moved to approvals.toml in the previous commit but
stale entries in config.toml were silently ignored. Now `wt config show`
detects them, generates a migration file that removes the entries, and
shows a diff + mv command. Other commands show a brief warning.

Also updates all CLI help text, docs, and FAQ to reference
approvals.toml as the storage location, and migrates all test configs
to use write_test_approvals() for approved-commands content.

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

* fix: document fallback path asymmetry and add config.toml fallback tests

Address PR review feedback:
- Document why `load_from_config_fallback()` uses `get_config_path()` while
  `reload_from()` uses sibling derivation, and why both converge in production
- Add `test_load_from_config_file` testing the extraction logic
- Add `test_mutation_picks_up_config_toml_fallback` testing the full mutation
  path with config.toml fallback (no approvals.toml → reads config.toml →
  preserves existing commands alongside new one)
- Inline `get_config_path` import (only used in `#[cfg(not(test))]` block)

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

* refactor: single fallback path for config.toml approvals

Replace two separate fallback implementations (load_from_config_fallback
via get_config_path, and reload_from via sibling derivation) with a
single load_with_fallback(path) that both load() and reload_from() use.

The shared helper derives config.toml as a sibling of the approvals
file, which is always correct since get_approvals_path() derives
approvals.toml as a sibling of config.toml.

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

* fix(tests): pass WORKTRUNK_APPROVALS_PATH in shell wrapper tests

Shell wrapper tests only passed WORKTRUNK_CONFIG_PATH to the binary,
so it derived the approvals path from config and found approved-commands
in config.toml, triggering the new deprecation warnings. This broke
4 snapshot tests and likely caused 6 timeouts on CI.

Fix: pass WORKTRUNK_APPROVALS_PATH alongside WORKTRUNK_CONFIG_PATH in
all shell wrapper test environments (build_shell_script, build_test_env_vars,
and custom script builders for all shell types). Migrate all approved-commands
writes from test_config_path() to write_test_approvals().

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

* fix(docs): escape brackets in doc comments for rustdoc

Rustdoc interprets `[projects]` as a broken intra-doc link.
Escape with `\[...\]` to treat as literal text.

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

* fix(tests): migrate approvals in e2e_shell_post_start and approval_pty tests

- e2e_shell_post_start: write approved-commands to approvals.toml
  instead of config.toml (fixes 5 timeout failures from unanswered
  approval prompts)
- approval_pty permission test: use a subdirectory for the read-only
  approvals path so the temp root stays writable for .zshrc and other
  test files

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

* test: improve coverage for approvals and deprecation modules

Add tests covering error paths, edge cases, and new deprecation features:
- approvals.rs: load_from_file parse errors, load_from_config_file parse
  errors, load_from_path nonexistent, revoke on nonexistent projects,
  clear_all when empty, save_to with empty project, revoke_project with
  empty commands
- deprecation.rs: remove_approved_commands with invalid TOML,
  format_deprecation_details with approved_commands flag,
  write_migration_file with approved_commands

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

* refactor: remove unused revoke_command from Approvals

Adversarial review found a normalization bug: revoke_command used exact
string matching while is_command_approved normalizes template variables.
Rather than fix a method with no production callers, remove it entirely.
Production code uses revoke_project (removes all approvals for a project)
and clear_all.

Rewrote test_concurrent_revoke_preserves_all_changes to use revoke_project.

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

---------

Co-authored-by: Claude <[email protected]>
max-sixty added a commit that referenced this pull request Feb 17, 2026
* feat: add system-wide config file support

Load organization-wide defaults from a system config file before user
config, allowing companies to distribute shared preferences via
configuration management.

Config loading order (later overrides earlier):
1. System config (organization defaults)
2. User config (personal preferences)
3. Environment variables

System config search locations:
- $WORKTRUNK_SYSTEM_CONFIG_PATH (explicit override)
- $XDG_CONFIG_DIRS directories (colon-separated)
- Linux: /etc/xdg/worktrunk/config.toml
- macOS: /Library/Application Support/worktrunk/config.toml
- Windows: %PROGRAMDATA%\worktrunk\config.toml

Uses the same format as user config. Visible in `wt config show`.

https://claude.ai/code/session_01FeQXY5Hu8STpn5DZPvkxWC

* fix: apply cargo fmt formatting

Apply rustfmt formatting to fix CI lint failures:
- Split long `pub use` statement across multiple lines in `mod.rs`
- Condense multi-line path building to single line in `path.rs`
- Format long string assignment in `tests.rs`
- Improve method chaining formatting in integration tests

* fix: ensure consistent system config path in tests across platforms

Add `WORKTRUNK_SYSTEM_CONFIG_PATH` to test environment setup to prevent
platform-specific system config paths from appearing in snapshots.

Changes:
- Set `WORKTRUNK_SYSTEM_CONFIG_PATH=/etc/xdg/worktrunk/config.toml` in `configure_wt_cmd()` (TestRepo)
- Set `WORKTRUNK_SYSTEM_CONFIG_PATH=/etc/xdg/worktrunk/config.toml` in `configure_cli_command()` (standalone tests)
- Add filter for non-canonicalized macOS temp paths (`/var/folders/...`)

This ensures tests show consistent "Not found (optional)" for system config
across Linux, macOS, and Windows, preventing snapshot mismatches.

* style: apply cargo fmt to tests/common/mod.rs

https://claude.ai/code/session_01FeQXY5Hu8STpn5DZPvkxWC

* fix: add WORKTRUNK_SYSTEM_CONFIG_PATH to PTY test environment

Add `WORKTRUNK_SYSTEM_CONFIG_PATH` to `test_env_vars()` to ensure PTY-based
tests (like switch picker) have consistent system config behavior across platforms.

Without this, PTY tests would fall back to platform-specific system config
paths, causing test output to vary between Linux, macOS, and Windows.

* refactor: remove #[cfg(test)] guards from config path resolution

Eliminate all test/non-test cfg annotations from path.rs. Both user
config and system config now use the same pattern: env var check first,
then platform default. Test isolation relies on env vars set by
TestRepo (WORKTRUNK_CONFIG_PATH, WORKTRUNK_SYSTEM_CONFIG_PATH), which
already covered integration tests.

Delete system_config_search_dirs() (fragile double-.parent() hack),
replace with default_system_config_path() that returns the env var
or first platform default.

Co-authored-by: Claude <[email protected]>

* test: add integration tests for XDG_CONFIG_DIRS and platform default paths

Cover the system config resolution paths that were previously behind
#[cfg(not(test))] and never tested: XDG_CONFIG_DIRS lookup (found and
not-found cases), and platform default display path fallback.

Co-authored-by: Claude <[email protected]>

* test: add coverage for system config edge cases in config show

Add tests for empty system config (hint message), invalid system config
(TOML parse error display), and unknown keys warning during config loading.
These exercise the render_system_config() and config loading paths.

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

* docs: reduce system config prominence in config page

System config is a niche feature for organizations. Replace the dedicated
section, TOML example, and table row with a single sentence pointing to
`wt config show`. Env vars remain in the table for discoverability.

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

* fix: update powershell test snapshot for system config section

Test from main needed its snapshot updated to include the new
SYSTEM CONFIG section in config show output.

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

* fix(config): resolve list timeout from per-project config (#1063)

* refactor(list): move timeout resolution into collect

Move raw_timeout extraction from handle_list into the collect function's
config resolution phase. This simplifies the public API by removing an
unused field from ShowConfig::DeferredToParallel and consolidates timeout
logic (including the --full override) into a single location where it can
access the merged project-specific config.

* refactor(config): add repo.config() for resolved config access

Add Repository::config() -> &ResolvedConfig and
Repository::user_config() -> &UserConfig, both lazily loaded and cached
in RepoCache. This makes correct config resolution the default path —
callers use repo.config() and get project-specific overrides applied
automatically.

Migrate wt list / wt select to use repo.config() instead of receiving
&UserConfig as a parameter. This removes the manual config resolution
that led to the timeout_ms bug (reading global config instead of merged
project-specific config).

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

* refactor(select): move config resolution into handle_select

Move CLI flag + config resolution from callers into handle_select(),
which already creates a Repository. This simplifies main.rs callers
and improves coverage on changed lines (callers in untestable
terminal paths now have minimal code).

Also switch select's post-selection switch to repo.user_config()
instead of UserConfig::load().

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

---------

Co-authored-by: Claude <[email protected]>

* feat(switch): enrich error hints with --execute context (#1064)

* feat(switch): enrich error hints with --execute and trailing args context

When `wt switch --execute=<cmd> -- <args>` fails (branch not found, already
exists, path exists), error hints now include the full command context so
users can copy-paste the suggested fix directly.

Also fixes `suggest_command()` to place flags before positional args (and
before any `--` separator), preventing flags from being treated as positional
args when dash-prefixed branches are involved.

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

* fix(coverage): remove unreachable -- separator branch in apply()

Clap's `#[arg(last = true)]` on execute_args means `--` always routes
to execute_args, so a dash-prefixed branch can't coexist with --execute
via the CLI. The suggested command never has a pre-existing `--`
separator when SwitchSuggestionCtx is applied, making this branch
dead code.

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

---------

Co-authored-by: Claude <[email protected]>

* Refactor approvals into separate file with deprecation migration (#1042)

* Refactor approvals into separate file

Approved commands are now stored in `~/.config/worktrunk/approvals.toml`,
independent of user config. This enables dotfile management of
`config.toml` without exposing machine-local trust state.

The `Approvals` type provides the same mutation interface as
`UserConfig` (approve/revoke commands, file locking) but stores
exclusively approval data. For backward compatibility, approvals
are silently read from `config.toml` if `approvals.toml` doesn't exist.

All command approval code now uses `Approvals::load()` and passes
`&approvals` to `approve_command_batch()`. Tests use isolated
`test_approvals_path()` to prevent pollution of user approvals.

* Add deprecation warning for approved-commands in config.toml

Approved commands moved to approvals.toml in the previous commit but
stale entries in config.toml were silently ignored. Now `wt config show`
detects them, generates a migration file that removes the entries, and
shows a diff + mv command. Other commands show a brief warning.

Also updates all CLI help text, docs, and FAQ to reference
approvals.toml as the storage location, and migrates all test configs
to use write_test_approvals() for approved-commands content.

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

* fix: document fallback path asymmetry and add config.toml fallback tests

Address PR review feedback:
- Document why `load_from_config_fallback()` uses `get_config_path()` while
  `reload_from()` uses sibling derivation, and why both converge in production
- Add `test_load_from_config_file` testing the extraction logic
- Add `test_mutation_picks_up_config_toml_fallback` testing the full mutation
  path with config.toml fallback (no approvals.toml → reads config.toml →
  preserves existing commands alongside new one)
- Inline `get_config_path` import (only used in `#[cfg(not(test))]` block)

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

* refactor: single fallback path for config.toml approvals

Replace two separate fallback implementations (load_from_config_fallback
via get_config_path, and reload_from via sibling derivation) with a
single load_with_fallback(path) that both load() and reload_from() use.

The shared helper derives config.toml as a sibling of the approvals
file, which is always correct since get_approvals_path() derives
approvals.toml as a sibling of config.toml.

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

* fix(tests): pass WORKTRUNK_APPROVALS_PATH in shell wrapper tests

Shell wrapper tests only passed WORKTRUNK_CONFIG_PATH to the binary,
so it derived the approvals path from config and found approved-commands
in config.toml, triggering the new deprecation warnings. This broke
4 snapshot tests and likely caused 6 timeouts on CI.

Fix: pass WORKTRUNK_APPROVALS_PATH alongside WORKTRUNK_CONFIG_PATH in
all shell wrapper test environments (build_shell_script, build_test_env_vars,
and custom script builders for all shell types). Migrate all approved-commands
writes from test_config_path() to write_test_approvals().

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

* fix(docs): escape brackets in doc comments for rustdoc

Rustdoc interprets `[projects]` as a broken intra-doc link.
Escape with `\[...\]` to treat as literal text.

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

* fix(tests): migrate approvals in e2e_shell_post_start and approval_pty tests

- e2e_shell_post_start: write approved-commands to approvals.toml
  instead of config.toml (fixes 5 timeout failures from unanswered
  approval prompts)
- approval_pty permission test: use a subdirectory for the read-only
  approvals path so the temp root stays writable for .zshrc and other
  test files

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

* test: improve coverage for approvals and deprecation modules

Add tests covering error paths, edge cases, and new deprecation features:
- approvals.rs: load_from_file parse errors, load_from_config_file parse
  errors, load_from_path nonexistent, revoke on nonexistent projects,
  clear_all when empty, save_to with empty project, revoke_project with
  empty commands
- deprecation.rs: remove_approved_commands with invalid TOML,
  format_deprecation_details with approved_commands flag,
  write_migration_file with approved_commands

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

* refactor: remove unused revoke_command from Approvals

Adversarial review found a normalization bug: revoke_command used exact
string matching while is_command_approved normalizes template variables.
Rather than fix a method with no production callers, remove it entirely.
Production code uses revoke_project (removes all approvals for a project)
and clear_all.

Rewrote test_concurrent_revoke_preserves_all_changes to use revoke_project.

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

---------

Co-authored-by: Claude <[email protected]>

* refactor: consolidate shell escaping on shell_escape, drop shlex (#1065)

Both `shell_escape` and `shlex` were used for shell quoting. `shell_escape`
is the project standard (~10 files); `shlex` was only used in 2 call sites
for `try_quote()`. Consolidate on the single crate.

Co-authored-by: Claude <[email protected]>

* fix(test): wait for item content in switch picker PTY tests (#1066)

* fix(test): wait for item content in switch picker PTY tests

On macOS CI under heavy load, skim may render the prompt and header
line before item rows, causing wait_for_stable (500ms threshold) to
capture the screen too early — before branch entries appear.

Fix by passing expected content to the pre-abort wait, ensuring the
test waits until items are actually rendered. This matches the pattern
already used by test_switch_picker_respects_list_config.

Also harden test_switch_picker_with_multiple_worktrees with the same
pattern as a preventive measure.

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

* fix(switch): replace remaining shlex reference with shell_escape

Commit 8ba5cd8 dropped the shlex dependency but missed one call site
at handle_switch.rs:154 (the suggestion context builder). Also update
the stale comment in error.rs.

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

---------

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <[email protected]>

* feat(switch): add AI summary preview tab (#1049)

* feat(switch): add AI summary preview tab (tab 5)

Add a fifth preview mode to `wt switch` that shows AI-generated branch
summaries using the configured [commit.generation] LLM command. Summaries
use commit-message format (imperative subject + body) and render through
the standard markdown help renderer for consistent styling.

- Background thread generates summaries in parallel for all branches
- Disk cache in .git/wt-cache/summaries/ with hash-based invalidation
- Graceful fallback: config hint when LLM not configured, dim "no changes"
  for default branch
- Shortened tab labels to fit 5 tabs: 1:diff | 2:log | 3:main | 4:upstream | 5:summary

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

* fix: resolve merge conflicts from jj revert

After merging main (which reverted jj support), fix two issues:
- Resolve config to access commit_generation (handle_select no longer
  receives resolved config directly)
- Restore pub(crate) visibility on execute_llm_command

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

* test: add cache and rendering tests for summary module

Add tests for cache round-trip, hash invalidation, file path
sanitization, directory structure, and pre-styled text rendering
to improve codecov/patch coverage.

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

* test: add integration test for summary tab and expand cache tests

- Add PTY test for tab 5 showing config hint when LLM not configured
- Add cache round-trip, invalidation, sanitized path, and dir tests
- Add pre-styled text rendering test for dim "no changes" messages

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

* test(summary): add coverage for diff computation and LLM generation

Add 10 new unit tests covering `compute_combined_diff`,
`generate_summary`, `generate_all_summaries`, and the single-line
`render_summary` path. Uses real temp git repos with shell-stub LLM
commands (following existing patterns from merge integration tests).

Also refactors test helpers to share git command setup and repo
initialization, eliminating duplication between test cases.

Co-authored-by: Claude <[email protected]>

* fix(summary): handle missing default branch + add coverage tests

- compute_combined_diff no longer bails when default_branch() returns
  None — wraps branch diff in if-let, preserving working tree diff
- Fix test to use exotic branch name so default_branch() actually
  returns None (infer_default_branch_locally checks "main"/"master"/etc)
- Add unit tests for items.rs Summary tab paths (main worktree, feature
  branch, cache hit/miss, compute_preview delegation)
- Add error path tests for write_cache (unwritable path, permission
  failure)

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

* fix(summary): address PR review feedback

- Remove is_main() shortcut from compute_summary_preview — was checking
  main worktree (git concept) not default branch (different concept)
- Add unicode visual cues to tab labels: 1:diff±, 3:main↕, 4:upstream⇅
- Move summary_items clone closer to its consumer in mod.rs

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

* fix(ci): revert unicode tab cues — ambiguous East Asian Width

Characters ±, ↕, ⇅ have East Asian Width "Ambiguous" which skim
renders as double-width on CI, shifting [N/M] alignment by 3 chars.
Revert to plain labels for cross-platform consistency.

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

* fix(switch): restore unicode symbols in tab labels

Restore ±, ↕, ⇅ symbols to tab labels (1:diff±, 3:main↕, 4:upstream⇅).
These characters are used throughout the codebase and haven't shown
width issues in practice.

Co-authored-by: Maximilian Roos <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>

* refactor(summary): bound concurrent LLM calls with Semaphore

Use the project's existing Semaphore (from src/sync.rs) to limit
concurrent LLM calls to 8 — same pattern as HEAVY_OPS_SEMAPHORE
and CMD_SEMAPHORE.

Co-authored-by: Maximilian Roos <[email protected]>

* fix(switch): adjust snapshot spacing for unicode tab symbols

skim-tuikit uses width_cjk() for header layout, which treats
East Asian Width "Ambiguous" characters (±, ↕) as double-width.
This shifts [N/M] left by 3 columns. Update snapshots to match.

Co-authored-by: Maximilian Roos <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>

* fix(test): normalize tab bar padding for cross-platform unicode widths

Skim right-aligns the [N/M] count indicator with padding that varies
depending on whether unicode chars (±, ↕, ⇅) are rendered as single
or double width. Normalize this padding in the snapshot filter so
tests pass regardless of the terminal's East Asian Width handling.

Co-authored-by: Maximilian Roos <[email protected]>

* fix(switch): restore original tab titles, add 5th summary tab

Revert tab labels 1-4 to their original format ("1: HEAD±", "2: log",
"3: main…±", "4: remote⇅") and add "5: summary" as a new 5th tab.

Co-authored-by: Maximilian Roos <[email protected]>

* fix(test): handle skim count overlap with summary tab label

When the 5 restored tab labels use ambiguous-width unicode symbols (±, …, ⇅),
skim's width_cjk() treats them as double-width, leaving insufficient space for
the count indicator. This causes the count to overlap with "summary" (e.g.,
"summary1/4") or truncate it ("summar1/28"). Add a targeted regex filter that
normalizes this overlap before the generic whitespace-padded count filter runs.

Co-authored-by: Maximilian Roos <[email protected]>

* fix(test): avoid typos lint on truncated word in snapshot regex

Use `summary?` (optional `y`) instead of `summar` to avoid the typos
spell checker flagging the partial word.

Co-authored-by: Maximilian Roos <[email protected]>

* fix(ci): restructure review skill workflow and fix dead sticky comment (#1056)

- Reorder as explicit numbered workflow: pre-flight checks before
  expensive diff analysis to avoid redundant work
- Remove redundant "read CLAUDE.md" (already in system prompt)
- Filter dedup check by bot identity so human approvals don't
  cause the bot to skip its review
- Accept brief approval bodies (matches actual bot behavior)
- Replace {owner}/{repo} placeholders with derived $REPO variable
- Add --paginate on comment fetching for large PRs
- Remove sticky comment references from skill (bot puts feedback
  in review bodies, not stdout — sticky comment stopped working
  after PAT switch in #1052)
- Add TODO on use_sticky_comment in workflow
- Restore gh pr comment prohibition with correct justification

Co-authored-by: Claude <[email protected]>

* fix(shell): harden nushell wrapper and improve diagnostics (#1059)

* fix(shell): harden nushell wrapper and improve diagnostics

- Move LAST_EXIT_CODE capture inside do{} block so it reflects the
  actual command exit code, not a subsequent operation
- Wrap directive processing in try/catch to ensure temp file cleanup
  on error
- Include nushell vendor autoload paths in scan_for_detection_details
  so `wt config show` reports nushell integration status
- Add "nu" to the supported shells hint shown on unsupported shells
- Fix detection tests to use actual nushell config line patterns
- Document why non-cd directives delegate to sh -c

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

* refactor(shell): remove try/catch from nushell directive cleanup

Drop error-path cleanup for the temp directive file. On error, the file
persists in /tmp as a useful debugging artifact (the OS cleans it up).
This matches bash and fish which already use a single rm on the happy
path with no error wrapping.

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

---------

Co-authored-by: Claude <[email protected]>

* fix(shell): PowerShell wrapper swallows -D flag as -Debug (#1057)

* fix(shell): PowerShell wrapper swallows -D flag as -Debug (#885)

The `[Parameter(ValueFromRemainingArguments)]` attribute promoted the
wrapper to an "advanced function", which adds common parameters like
-Debug and -Verbose. PowerShell then consumed `-D` as `-Debug` instead
of passing it to wt.exe — so `wt remove -D` silently lost the flag.

Replace with `$args` (automatic variable for simple functions) which
passes all arguments through unchanged.

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

* fix(test): use .ps1 mock for cross-platform PowerShell test

The shell script mock (#!/bin/sh) doesn't work on Windows. Use a .ps1
script instead — pwsh can invoke it directly with &, and pwsh is already
required for this test.

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

* style: apply cargo fmt to PowerShell test

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

---------

Co-authored-by: Claude <[email protected]>

* fix(ci): use empty body for LGTM approvals instead of fluff (#1060)

The review bot was generating summary prose like "Clean hardening of
the nushell wrapper..." when it had no issues to raise. An empty
approval is less noisy — the thumbs-up reaction is sufficient signal.

Co-authored-by: Claude <[email protected]>

* fix(list): handle empty repos (no commits) gracefully (#1058)

* fix(list): handle empty repos (no commits) gracefully

Skip commit-dependent tasks for unborn branches (null OID) using a
COMMIT_TASKS constant, following the existing EXPENSIVE_TASKS pattern.
Filter null OIDs from timestamp batching, accept unborn default branch
in validation, and render empty commit/age cells instead of garbage.

Closes #885

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

* fix: address codecov/patch coverage gaps

- Remove unreachable COMMIT_TASKS check from work_items_for_branch (null
  OIDs only appear in worktree HEAD, never in git for-each-ref)
- Restructure json_output null OID handling to eliminate dead branch
- Pre-set default branch config in test to exercise is_unborn_head_branch path

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

* fix: remove unused BranchRef::has_commits() (dead code)

Only WorktreeInfo::has_commits() is called in the dispatch code.
BranchRef::has_commits() was never referenced, causing a codecov gap.

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

---------

Co-authored-by: Claude <[email protected]>

* refactor(switch): unify preview mode handling

All 5 preview modes now follow the same cache → compute → post-process
path in preview_for_mode, eliminating the Summary early-return special
case. Summary precomputation uses rayon (queued after tabs 1-4) instead
of a separate std::thread::spawn + thread::scope wrapper.

Threading simplified from:
  rayon::spawn × (N × 4)      ← tabs 1-4
  std::thread::spawn           ← wrapper
    └── std::thread::scope     ← N scoped threads
        └── LLM_SEMAPHORE      ← rate limit

To:
  rayon::spawn × (N × 4)      ← tabs 1-4 (queued first)
  rayon::spawn × N             ← summaries (queued last, semaphore inside)

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

* feat(switch): gate summary tab behind [list] summary config

Summary generation is opt-in via `[list] summary = true` (default: false)
to avoid surprise LLM calls for users who have `[commit.generation]`
configured. Both settings are required for summaries to fire.

Adds documentation for the feature in switch help, FAQ (commands we run),
and llm-commits page (new "Picker summaries" section).

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

* fix: use ResolvedConfig directly after main merge

The merge with main changed handle_select to receive ResolvedConfig
instead of UserConfig, so the .resolved() call is no longer needed.

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

* test: update summary preview snapshot for config hint

The hint text now includes [list] summary = true in addition to the
[commit.generation] example.

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

* fix: replace missed shlex::try_quote with shell_escape

The shlex removal in #1065 missed one call site in the switch suggestion
context builder. Replace with shell_escape::escape to match the rest of
the codebase.

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

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Maximilian Roos <[email protected]>

* fix: replace missed shlex::try_quote call with shell_escape (#1067)

The shlex crate removal in #1065 missed one call site in
handle_switch.rs that still used shlex::try_quote for escaping
--execute flag values in error suggestions.

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <[email protected]>

* Improve CI reviewer: resolve threads, skip trivial re-approval, default to suggestions (#1068)

Three changes to the worktrunk-review skill:

- Resolve handled suggestions: after review, check unresolved bot threads via
  GraphQL and resolve any where the issue was addressed
- Skip re-approval for trivial changes: when bot already approved a prior
  revision and new changes are under ~20 lines with no new logic, the existing
  approval stands — skip to thread resolution and exit
- Default to code suggestions: reframe GitHub suggestion format as the default
  for specific fixes, not just an option

Co-authored-by: Claude <[email protected]>

* fix: update snapshots and PTY tests after merge from main

Update config_show snapshots to include new env vars from main
(WORKTRUNK_APPROVALS_PATH, WORKTRUNK_TEST_NUSHELL_ENV, etc.) and
system config section in output.

Add write_test_config("") to PTY merge tests to suppress the commit
generation prompt that fires when claude is on PATH.

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

* Refactor system config handling to only show section when found

When no system config file exists, `config show` now displays an optional
system config hint under USER CONFIG instead of a separate empty SYSTEM
CONFIG section. This improves UX by reducing visual clutter while still
informing users where to place a system config file if desired.

Also consolidates system config directory lookup logic into a single
`system_config_dirs()` function that properly handles XDG_CONFIG_DIRS
environment variable precedence per XDG spec.

* fix: improve review findings and add hooks merge semantics tests

- Simplify system_config_dirs() return type (remove unused xdg_was_set bool)
- Fix two integration tests with empty assertion loops (wrong field name,
  no linked worktrees)
- Add end-to-end tests for system/user hooks merge behavior:
  - Deep merge preserves differently-named hooks from both configs
  - Same-named hooks: user replaces system
  - Untouched hook types from system config are preserved
- Rename misleading unit test to clarify Merge trait scope (global→project only)

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

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: Maximilian Roos <[email protected]>
Co-authored-by: Maximilian Roos <[email protected]>
Co-authored-by: worktrunk-bot <[email protected]>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Maximilian Roos <[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