Skip to content

fix(visual_commands): leave Select mode after the README's mode = "v" send mapping - #397

Merged
ThomasK33 merged 2 commits into
mainfrom
fix/selection-followups-393
Nov 1, 2026
Merged

ThomasK33 merged 2 commits into
mainfrom
fix/selection-followups-393

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Why

The goal is to clear the open follow-up issues (#393 now, #385, #374, #363 and earlier), one small reviewed PR per bug. Part of #393. This PR handles item 5, the two selection points.

  1. Select mode stayed on after the README's send mapping. README.md documents { "<leader>as", "<cmd>ClaudeCodeSend<cr>", mode = "v" }, which is a :vmap. When a :vmap runs in Select mode, Neovim switches to Visual mode for the mapping and queues K_SELECT after it (handle_mapping in getchar.c). The command's <Esc> ends Visual mode first, so K_SELECT then reselects the area with gv (nv_select in normal.c), and Select mode comes back. The mention was sent, but the user stayed in Select mode, where the next typed key replaces the selected text. Only an :smap left Select mode. The command now feeds gV (no remap) after the <Esc>. gV is Neovim's documented way to stop that reselection (:h gV), and it does nothing outside a Select-mode mapping. The README mapping does not change.
  2. "What the cursor and y treat as one" was not exact. The plugin counts a character with vim.fn.byteidx and charidx, which follow y. Before Neovim 0.11, the cursor and y disagree next to an invalid byte. h jumps over the invalid byte and the composing characters after it, but y takes the invalid byte alone. The docs now say that a character is what y takes, that an invalid byte is a character of its own on every version, and they name the two cases before 0.11 where Neovim differs.

What changed

  • lua/claudecode/visual_commands.lua: exit_visual_and_schedule feeds gV with flags in before it feeds <Esc> with i. Both go in front of the queued keys, so the typeahead becomes <Esc>, gV, then K_SELECT. :ClaudeCodeTreeAdd uses the same wrapper and gets the same fix.
  • tests/integration/select_mode_send_spec.lua (new, real Neovim): presses a :vmap <cmd>ClaudeCodeSend<cr> from Visual mode and from charwise, linewise and blockwise Select mode, and checks the sent lines and that the mode afterwards is n. It also checks that a user's Normal-mode gV mapping does not run. Under busted's mock vim it is pending, like the other real-Neovim specs.
  • lua/claudecode/README.md, PROTOCOL.md: the Select-mode line says the visual path ends Select mode, also for a :vmap. The character definition says y instead of "the cursor and y", adds the invalid byte, and names the two differences before 0.11. Two code comments that made the same cursor claim now say y.

Scope

Only #393 item 5. The selection encoding does not change: no position or text that the plugin sends is different. Item 2 is docs and comments only.

Blast Radius

Every :ClaudeCodeSend and :ClaudeCodeTreeAdd run in Visual or Select mode now also processes gV after its <Esc>. Outside a Select-mode :vmap, gV only clears Neovim's reselect flag, which Neovim sets again when Visual mode next starts. The n flag keeps a user's own gV mapping from running. Keys that the user's mapping puts after <cmd>ClaudeCodeSend<cr> still run after the <Esc>, as before.

Verification

  1. Live session (verify-claudecode-nvim, agent-tty, real Neovim 0.12.3, ws-client.mjs as Claude), with vim.keymap.set("v", "<F6>", "<cmd>ClaudeCodeSend<cr>"), the README's mode = "v" mapping:

    Keys main: mode after this PR: mode after at_mentioned (both)
    v Down <F6> n n lines 1 to 2
    v Down CTRL-G <F6> s n lines 1 to 2
    V Down CTRL-G <F6> S n lines 1 to 2
    gh <F6> s n lines 1 to 1

    The client stays alive in both runs. Screen after v Down CTRL-G <F6>, main and then this PR:

    main: Select mode stays on after the send

    this PR: Normal mode after the send

  2. Headless real-key repro on Neovim 0.8.3, 0.10.4, 0.11.6 and 0.12.3, 8 cases each: Visual and Select mode with :vmap, :smap and :xmap, and a :vmap that chains Ax<Esc> after the send. On main, the 5 :vmap cases from Select mode end in s, S or CTRL-S. On this PR, all 32 runs end in n, send the same lines as main, and the chained Ax<Esc> still edits the buffer.

  3. Red/green: without the fix, the new spec fails its 3 Select-mode tests on 0.8.3 and 0.12.3 (mode after the send is s, S or CTRL-S). With the fix it passes 5 of 5 on 0.8.3, 0.10.4, 0.11.6 and 0.12.3. If gV is fed with remap (i instead of in), the gV mapping test fails.

  4. Character wording (item 2): for every selection whose two ends are cursor stops of l and h, on lines with an invalid byte before composing characters, I compared the plugin's byte range with Neovim's y, with 'selection' inclusive and exclusive. On 0.11.6, 0.12.3 and 0.12.6, 0 of 184 differ. On 0.8.3, 0.9.5 and 0.10.4, 20 of 154 differ, the same 20 on each. 13 have a start or an end on the second byte of a U+0301, where h can stop before 0.11. The plugin moves that position back to the code point's first byte, as the README already says. The other 7 are the exclusive case the docs now name: y leaves out the composing characters after 0xFF.

  5. Gates on the head commit: mise run check (0 warnings), mise run test (952 successes, 0 failures, 3 pending), stylua --check, prettier --check, and scripts/run_integration_tests_individually.sh on 0.8.3 and 0.12.3 (35 successes, 0 failures).


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: xhigh

…nvalid byte

lua/claudecode/README.md and PROTOCOL.md said a selection's end character is
"what the cursor and `y` treat as one". The plugin counts with
vim.fn.byteidx and charidx, which follow `y`. Next to an invalid byte the
cursor and `y` disagree before Neovim 0.11: `h` jumps over the invalid byte
and the composing characters after it, but `y` takes the invalid byte alone.
With 'selection' set to exclusive, that `y` can also leave out composing
characters after an invalid byte when the selection ends right after them,
and the selection keeps them.

Say that the character is what `y` takes, that an invalid byte is a
character of its own on every version, and name the two cases before 0.11.
The code comments that made the same cursor claim now say `y`.

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…ping

README.md documents `{ "<leader>as", "<cmd>ClaudeCodeSend<cr>", mode = "v" }`,
which is a :vmap. When a :vmap runs in Select mode, Neovim switches to
Visual mode for the mapping and queues K_SELECT after it. The command's
<Esc> ends Visual mode first, so K_SELECT then reselects the area with `gv`
and Select mode comes back. The mention was sent, but the user stayed in
Select mode, where the next typed key replaces the selected text.

Feed `gV` (no remap) after the <Esc>. `gV` is Neovim's documented way to
stop that reselection (:h gV), and it does nothing outside a Select-mode
mapping. ClaudeCodeTreeAdd uses the same wrapper and gets the same fix.

A new real-Neovim spec (tests/integration/select_mode_send_spec.lua)
presses a :vmap from Visual mode and from charwise, linewise and blockwise
Select mode. It also checks that a user's Normal-mode `gV` mapping does not
run.

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T10:50:35.430093Z 7f1fcb6 Manual request
🔒 Security Review ✅ Completed 2026-11-01T10:50:57.735578Z 7f1fcb6 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 7f1fcb6893

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 7f1fcb6893

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 46b5aa9 Nov 1, 2026
5 checks passed
@ThomasK33
ThomasK33 deleted the fix/selection-followups-393 branch November 1, 2026 11:10
@github-actions github-actions Bot mentioned this pull request Nov 1, 2026
ThomasK33 added a commit that referenced this pull request Nov 1, 2026
…, #397, #399

check.sh --mutants caught every guard on the tree merged with #394. This merge
changes no fact (all 21 read TRUE) and not the model, so the mutant result
holds. check.sh passes.

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
ThomasK33 added a commit that referenced this pull request Nov 1, 2026
Besides server/client.lua and server/frame.lua, the record takes in the
selection.lua, tools/open_file.lua and visual_commands.lua changes from
#396 and #397, which main had not recorded. None of them reaches diff
state, an openDiff answer, a disconnect or a diff command: the only diff
word in them is open_file's check of a window's 'diff' option.

Part of #393

_Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
ThomasK33 added a commit to joshmedeski/claudecode.nvim that referenced this pull request Nov 10, 2026
…-ordered tests (coder#400)

## Why

The operator goal is to clear the open follow-up issues in this
repository (coder#393 now) with small reviewed PRs. This PR takes coder#393 item
7. Item 6 is in coder#395.

1. **New dirs above `VERIFY_OUT` were refused under a default ACL.**
Since coder#386, `vcn.sh launch` created the evidence path with `mkdir -p -m
700`, which sets only the last dir's mode. Under a parent with a default
ACL, each new dir above it got the ACL's mode (`770`), and the check
after `mkdir` refused the run. This hit a `VERIFY_OUT` more than one
level below such a dir. It also hit a new default parent dir
(`verify-claudecode-nvim`) under such an `XUM_SCRATCH_DIR`. I fixed it
instead of documenting it, because the fix is one loop.
2. **Nothing stopped a spec from registering tests in `pairs()` order.**
LuaJIT seeds its string hash in each process, so `pairs()` visits string
keys in a different order in each run. A spec that registers tests from
such a loop runs them in a different order each time, and the seed that
`mise run test` prints does not repeat that order. coder#386 fixed three such
loops. A fourth one came in with coder#388
(`visual_commands_select_mode_spec.lua`): in 12 runs, its three tests
came in three different orders.

## What changed

- `vcn.sh`: launch runs `mkdir -m 700` on each missing dir of the
evidence path, shallowest first. This replaces the `mkdir -p -m 700` and
its `shellcheck disable`. Two other changes come with it:
- If another launch makes a missing parent dir first, launch uses that
dir, and the check after `mkdir` decides whether it is safe. Before,
`mkdir -p` accepted such a dir.
- Launch now keeps a list of only the dirs it made itself. On a failure
or a refusal, it removes those dirs and never one that another process
made.
- `proof-launch-refusals.sh`:
- `out-made` puts `VERIFY_OUT` two levels below the default-ACL dir and
also checks the middle dir's mode.
- `parent-made-unsafe` expected the old refusal of a new default parent
dir, so I removed it. That dir now goes through the same code as
`out-made`'s middle dir.
- `race` (new) puts a `mkdir` shim on `PATH`. The shim plays another
launch that makes the dir above `VERIFY_OUT` first, group-writable.
Launch must refuse that dir in the check after `mkdir` and leave it in
place.
- `SKILL.md`: the creation mode and the ACL cases.
- `tests/helpers/test_order.lua` (new) is a busted helper, and the new
`.busted` file loads it for every busted run, `mise run test` included.
When a spec registers a test (`describe`, `it` or `pending`), the helper
walks the stack. In each frame of a file in this repository's `tests/`
dir, it looks for a generic `for` loop whose iterator is `next`, which
is what `pairs()` returns. If it finds one, the registration fails with
`<file>:<line> registers "<name>" inside a pairs() loop; loop over an
array with ipairs`. Because it checks at run time, it does not depend on
formatting, comments, one-line loops or strings.
- `tests/unit/test_order_helper_spec.lua` (new) tests the helper. It
covers a loop in the spec, a loop in a calling frame, a loop in code
outside the `tests/` dir, an `ipairs` loop, and a registration after a
loop.
- `tests/unit/visual_commands_select_mode_spec.lua`: the three cases
come from an array now.
- `DEVELOPMENT.md`, `AGENTS.md` and `README.md` (System Verification):
the rule and the guard.

Codex round 1 found two holes in my first version, a text scan
(`scripts/check_test_order.sh`). Round 2 found two more. So I replaced
the scan with the run-time check, and the script is gone. Round 3 found
the remaining two issues: the helper counted any path with a `tests/`
part, and launch aborted when it lost the race for a parent dir. Both
are fixed.

## Scope

coder#393 item 7. No plugin code changes.

## Blast Radius

- **People and agents who run `vcn.sh launch` under a dir with a default
ACL.** A deeper `VERIFY_OUT`, or a new default parent dir, now works and
starts private, where launch refused it before.
- **Contributors.** A spec that registers tests inside a `pairs()` loop
now errors in `mise run test`, and in any `busted` run from the repo
root. The error names the file and line.
- **Run time.** The helper adds about 1 s to the suite under coverage.
In two pairs of runs it took 15.8 s against 14.6 s, and 16.9 s against
15.7 s.

## Verification

| Run | Code | Result |
|
------------------------------------------------------------------------------------------------------------------------------
| ---------------------------------------------- |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| `VERIFY_OUT=<0700 dir with default ACL g::rwx>/mid/deeper/out vcn.sh
launch` | main (c05a629) | exit 1: `…/mid/deeper, above the evidence
dir, is writable by others and not sticky`. The dirs it made are removed
|
| Same | this PR | launch works. After cleanup, `mid`, `mid/deeper` and
`out` are `700`, and every evidence file is `0600` |
| `XUM_SCRATCH_DIR=<0700 dir with that ACL> vcn.sh launch` (new default
parent dir) | main | exit 1: `…/verify-claudecode-nvim is group- or
world-writable` |
| Same | this PR | launch works, and `verify-claudecode-nvim` is `700` |
| `VERIFY_OUT=<dir>/a/<300-character name>` | this PR | `cannot create
…`. The proof dir is empty afterwards, so the `a` that launch made is
removed again |
| `proof-launch-refusals.sh` (red) | 9575ee0, the new `out-made` on
main's `vcn.sh` | `FAIL: out-made: launch failed: vcn: refusing evidence
dir: …/acl/mid, above the evidence dir, is writable by others and not
sticky` |
| `race` case alone (red, Codex round 3 finding) | 3392cd6, the case on
b5c7ec4's `vcn.sh` | exit 1: `cannot create …/race/mid/out` |
| `race` case alone | this PR | exit 1: `…/race/mid, above the evidence
dir, is writable by others and not sticky`. `mid` stays, and `mid/out`
is gone. With a shim that makes `mid` `0700`, launch starts the run |
| `proof-launch-refusals.sh` (green) | this PR (882da0f) | all 18 cases
`PASS` in 78 s on a busy host (56 s before the `race` case, which starts
no run), with an empty `TMPDIR` afterwards |
| The whole suite with the helper | the tree of bf80d11 (main before
coder#386) | 3 errors: `native_terminal_toggle_spec.lua:523` and `:969` and
`diff_bulk_close_reentrancy_spec.lua:71`, the three loops coder#386 fixed |
| `busted tests/unit/visual_commands_select_mode_spec.lua` with the
helper | main's spec (c05a629) | error:
`visual_commands_select_mode_spec.lua:24 registers "runs the visual
handler for a charwise Select-mode selection" inside a pairs() loop;
loop over an array with ipairs` |
| Same | this PR | 3 successes |
| 12 runs of that spec, test order | main / this PR | 3 different orders
/ 1 order |
| `tests/unit/test_order_helper_spec.lua` with each of two helper
mutants (never match `next`, never match a `tests/` frame) | this PR |
each: 1 success, 2 failures |
| Checkout and rocks copied under `<scratch>/tests/claudecode.nvim`,
`busted tests/unit/config_spec.lua` (Codex round 3 finding) | d49b31e /
this PR | 1 error / 16 successes |
| `mise run check`, `mise run test` | this PR (5df456a, with main up to
coder#396 merged) | pass. 967 successes, 0 failures |

Gates on 5df456a: `stylua --check`, `prettier --check`, `shellcheck`,
`shfmt -d` and `treefmt --ci` pass. This PR changes no file under `lua/`
or `plugin/`. On 5df456a, `verify-diff-lifecycle/check.sh` reads STALE
only for main's own unrecorded `selection.lua`, `tools/open_file.lua`
and `visual_commands.lua` changes (coder#396, coder#397). coder#395 re-records them.

Part of coder#393

---

_Generated with [`xum`](https://github.com/coder/xum) • Model:
`anthropic:claude-opus-5-5` • Thinking: `xhigh`_
ThomasK33 added a commit to joshmedeski/claudecode.nvim that referenced this pull request Nov 10, 2026
## Why

The goal is to clear the open follow-up issues (coder#401 now, coder#393, coder#385,
coder#374 and earlier), one small reviewed PR per bug. Part of coder#401. This PR
handles item 1.

`.agents/skills/verify-diff-lifecycle/covered.lock` records the `lua/`
and `plugin/` code that the openDiff lifecycle model was last confirmed
against. `check.sh` reads STALE (exit 3) when that code changed without
a re-record. CI never ran it, so coder#387 and coder#397 merged and left `main`
STALE until a later PR re-recorded the lock.

This PR adds `check.sh --hash-only`, a check that compares the lock with
the code and runs no TLC (the TLA+ model checker). A new CI job,
`covered-lock`, runs it on every PR. The job is advisory: `Required`
does not need it. The lock hashes every `.lua` and `.vim` file under
`lua/` and `plugin/`, so a required check would block every Lua PR,
including open fork PRs, until someone re-records the lock.

## What changed

- `.agents/skills/verify-diff-lifecycle/check.sh`:
- New `--hash-only` flag. It uses the same `coverage()` function and the
same comparison as a full run, so the two cannot disagree. It exits 0
when the lock matches, 3 when it is stale, and 2 on an error. It refuses
any other option.
- A STALE result of `--hash-only` names the next step: run `check.sh
--record` and commit `covered.lock`, or ask a maintainer to.
- `--record` runs no TLC, so it no longer downloads or checks the TLC
jar. Before, it failed offline with `could not download TLC`.
  - A full run does not change.
- `.github/workflows/test.yml`: new `covered-lock` job (checkout, then
`check.sh --hash-only`). `Required` does not need it.
- `DEVELOPMENT.md`: one paragraph on what to do when `covered-lock`
turns red.
- `.agents/skills/verify-diff-lifecycle/SKILL.md`: documents the flag,
the advisory job, and that `--hash-only` and `--record` download
nothing.

## Scope

Only coder#401 item 1. The lock, the model and the code facts do not change.
`covered.lock` still matches `main` (182ee38), so `covered-lock` passes
on this PR.

Not in this PR, tracked as follow-ups:

- Two Lua PRs from the same base both rewrite the `sync` line of
`covered.lock`, so the second one conflicts after the first merges. That
serializes Lua PRs, and a merge queue cannot batch them. The record
needs another design before the job can be required.
- CI checks only that someone re-recorded the lock. It does not run the
model, so a re-record without a model check still turns the job green.

## Blast Radius

The `covered-lock` job shows red on every PR that changes a `.lua` or
`.vim` file under `lua/` or `plugin/` without a re-recorded
`covered.lock`. The PR can still merge, because `Required` does not need
the job. PRs that touch only docs, tests or CI keep the job green. The
job takes a few seconds and needs only bash, git and standard Unix
tools.

## Verification

1. **CI on a stale branch:** I pushed a throwaway branch with this PR's
head plus one comment line added to
`lua/claudecode/visual_commands.lua`. I ran the workflow on it with
`workflow_dispatch` ([run
41309300053](https://github.com/coder/claudecode.nvim/actions/runs/41309300053)),
then deleted the branch. `covered-lock` failed with exit code 3 and
printed one `was:`/`now:` pair, for `visual_commands.lua`. Its last line
was `== RESULT: STALE. Run .agents/skills/verify-diff-lifecycle/check.sh
--record and commit covered.lock, or ask a maintainer to`. `unit-tests`,
both `integration-tests` jobs and `Required` passed. Every other file
hashed the same on the runner as here.
2. **Local red/green on real history**, with this PR's `check.sh`
applied to each tree:

   | Commit | What it is | `--hash-only` |
   | --- | --- | --- |
   | `182ee38` | `main` now | exit 0, matches |
   | `048be6b` | parent of coder#387 | exit 0, matches |
| `c9c4b07` | coder#387 merged | exit 3, STALE: `file
lua/claudecode/tools/open_file.lua` changed |
   | `c05a629` | parent of coder#397 | exit 0, matches |
| `46b5aa9` | coder#397 merged | exit 3, STALE: `selection.lua` and
`visual_commands.lua` changed |

3. **`--record` offline**, on a copy of the tree with one Lua line
changed, no TLC jar in the cache, and HTTPS pointed at a dead proxy: the
old `check.sh --record` exits 2 with `ERROR: could not download TLC
1.7.4`. This PR's `--record` exits 0, downloads nothing, and
`--hash-only` then exits 0.
4. **A full run is unchanged:** `check.sh` on this branch gives PASS.
5. **Gates on the head commit:** `mise run check`, `mise run test` (980
successes, 0 failures), `mise run format-check` (shfmt, shellcheck,
actionlint, zizmor, prettier, stylua).

---
_Generated with [`xum`](https://github.com/coder/xum) • Model:
`anthropic:claude-opus-5-5` • Thinking: `xhigh`_
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.

1 participant