Skip to content

Improve shell integration detection robustness - #362

Merged
max-sixty merged 6 commits into
mainfrom
detection
Jan 2, 2026
Merged

max-sixty merged 6 commits into
mainfrom
detection

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

Changes

First commit: Fix git wt detection (#348)

The old detection searched for git-wt config shell init but missed git wt config shell init (with space). User NikiforovAll had eval "$(command git wt config shell init bash)" which wasn't detected, causing incorrect "restart shell to activate" messages.

Second commit: Adversarial testing

Ran 4 rounds of adversarial testing with 8 subagents to find edge cases:

Bugs fixed:

  • git-wt bypassed ALL position checks → my-git-wt matched incorrectly
  • git wt space form had no boundary check → agit wt matched incorrectly
  • _wt_lazy_complete used simple contains() → my_wt_lazy_complete matched
  • WORKTRUNK_BIN:-wt} had no prefix check → MY_WORKTRUNK_BIN:-wt} matched

Documented acceptable limitations:

Detection is only used when shell wrapper is NOT active. Once the shell is restarted, WORKTRUNK_DIRECTIVE_FILE is set and no detection is needed. False negatives only affect:

  • wt config show status display
  • Warning before shell restart ("not installed" vs "restart to activate")
  • wt config shell uninstall (lines might not be found)

Test plan

  • 519 unit tests pass
  • Pre-commit lints pass
  • CI passes

🤖 Generated with Claude Code

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

max-sixty and others added 6 commits January 1, 2026 11:58
Fix detection of shell integration when invoked as `git wt` (with space)
vs `git-wt` (with hyphen). The old detection only looked for the exact
pattern `{cmd} config shell init`, so `git-wt` detection missed lines like:

  eval "$(command git wt config shell init bash)"

Now `git-wt` detection matches both `git-wt` and `git wt` patterns, since
git dispatches `git wt` to the `git-wt` binary.

Also adds prefix exclusion for `wt` detection so it doesn't false-positive
on `git wt` lines, and function marker detection for Fish conf.d files.

Fixes #348

Co-Authored-By: Claude <[email protected]>
Run 4 rounds of adversarial testing with subagents to find false positives
and false negatives in the detection logic.

## Bugs Fixed

- `git-wt` bypassed position checks: `my-git-wt` incorrectly matched
- `git wt` space form had no boundary check: `agit wt` incorrectly matched
- `_wt_lazy_complete` used simple contains(): `my_wt_lazy_complete` matched
- `WORKTRUNK_BIN:-wt}` had no prefix check: `MY_WORKTRUNK_BIN:-wt}` matched

## Documented Acceptable Limitations

False negatives (detection only used when wrapper inactive):
- POSIX `.` command, zsh `=()`, PowerShell `iex` alias
- Path-prefixed binaries, line continuations, heredoc context

False positive risks (rare in practice):
- PowerShell block comments, subshell execution, uncalled wrapper functions

Added 15 new tests covering the fixed bugs and edge cases.

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

Add urlencoding crate to support generating GitHub issue URLs with pre-filled content for shell integration detection false negatives.

Introduce `scan_for_detection_details()` function that returns matched integration lines and unmatched candidates (lines containing the command but not detected). Use this in `wt config show` to:
- Display matched shell integration lines inline under configured shells
- Identify and report potential false negatives with a GitHub issue link
- Help users debug shell integration problems

Add `format_bash_with_gutter()` styling function for displaying shell code snippets.
- Remove function marker detection (~300 lines) - only eval/source patterns needed
- Consolidate file scanning into single scan_file() helper
- Add line numbers to shell integration output (file:line format)
- Use urlencoding crate instead of hand-rolled encoder

Output now shows clickable locations like:
  ○ Already configured shell extension & completions for zsh @ ~/.zshrc:5

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

Co-Authored-By: Claude <[email protected]>
Covers the code path that shows warnings when shell config contains
`wt` but it's not detected as valid integration (potential false negative).

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

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.

Unable to change directory on Windows GitBash with chell integration enabled

1 participant