Repository navigation
fix(tools): pass the component first in close_tab and getDiagnostics log calls - #366
Conversation
…he tool The spec drives every log call in both handlers through the real logger and reads what reaches nvim_echo history and vim.notify. It fails on main, where each line reads "[ClaudeCode] [<message>] [DEBUG]" with an empty message. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
…log calls The logger takes the component name first. These 16 calls passed only the message, so the logger printed it as the component and left the message empty. Each call now passes the tool name as the component. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
The error handling example called logger.error with only a message, the same mistake the tool handlers made. _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
|
@codex review |
|
@codex security review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…buffer (coder#373) ## Why The goal is to clear the open follow-up issues (coder#362 and coder#363 now, coder#350, coder#326 and coder#335 earlier), one small reviewed PR per bug. Part of coder#363. This PR handles items 4 and 5. Item 5: `close_tab` could delete a buffer the user opened. A `tab_name` without both the `✻` and `⧉` markers skipped the diff path. `close_tab` then looked up a buffer with `vim.fn.bufnr(tab_name)`, which also accepts part of a name, or by a file name it took from `tab_name`, and ran `nvim_buf_delete` on it. On main, on Neovim 0.8.3 and 0.12.3: - `README.md` and `✻ [Claude Code] README.md (e18e1e)` (closing marker missing) deleted the user's `README.md` buffer. - `notes` deleted `notes.txt`, and `x/app.lua` deleted `app.lua`. - A diff that `openDiff` opened with a plain `tab_name` such as `plain-tab` stayed open. `close_tab` tried to delete the modified proposed buffer, failed with `-32000`, and Claude's `openDiff` call never got an answer. What the clients do: - Claude Code 2.1.312 calls `close_tab` only with the `tab_name` it gave `openDiff`: `✻ [Claude Code] <file name> (<6 hex>) ⧉`. I read both call sites in the installed CLI bundle. In 2.1.310 and 2.1.311 the call and its error handling look the same. - The VS Code extension (2.1.309) closes only the tab whose label equals `tab_name`. It answers `TAB_CLOSED` even when no tab matches. `close_tab` now always hands `tab_name` to `diff.close_diff_by_tab_name` and never deletes a buffer. A name that matches no diff closes nothing. Item 4: `close_tab` answers `TAB_CLOSED` whether it closed the diff, kept a diff the user accepted for another client, or found no diff. I kept that answer and documented it exactly. A different answer text has no reader. Claude Code 2.1.312 does not read the text: it awaits the call and logs only a call that fails, so the model never sees it. VS Code gives the same answer for "no match", and a client written against VS Code can compare the text with `TAB_CLOSED`. ## What changed - `lua/claudecode/tools/close_tab.lua`: no marker check and no buffer lookup or `nvim_buf_delete`. The handler calls `diff.close_diff_by_tab_name(tab_name, client and client.id or nil)` and answers `TAB_CLOSED`. - `tests/unit/tools/close_tab_spec.lua` (new), through `tools.handle_invoke`: - A diff opened with the plain tab name `plain-tab` closes, and its `openDiff` gets `DIFF_REJECTED`. - `README.md`, `/tmp/project/README.md`, a marked name without `⧉`, and a full marked name with no diff all answer `TAB_CLOSED` and leave the user's buffer. - `tests/unit/tools/tool_log_lines_spec.lua`: I removed the two calls that drove the deleted buffer paths. - `PROTOCOL.md` and `lua/claudecode/tools/README.md`: what `close_tab` closes, and the three cases that answer `TAB_CLOSED`. - `.agents/skills/verify-diff-lifecycle/covered.lock`: re-recorded. See Verification item 4. `diff.lua` does not change. ## Scope Only `close_tab`. `closeAllDiffTabs`, `openDiff`, and the diff lifecycle do not change. The answer text does not change. ## Blast Radius Users whose Claude client sends `close_tab` with a name that matches no open diff. Before, such a name could delete one of their buffers, or fail with `-32000` on a modified one. Now it changes nothing and answers `TAB_CLOSED`. The real Claude Code CLI always sends the name of a diff it opened, so for its diffs nothing changes. A client that opens a diff with a plain `tab_name` now gets its diff closed and its `openDiff` answered by `close_tab`. Before, that diff stayed open. ## Verification 1. **Real Neovim, headless** (`repro.lua`, 0.8.3 and 0.12.3, same result on both): | `close_tab` name | main | this PR | | --- | --- | --- | | `README.md` | deletes `README.md` | keeps it | | `✻ [Claude Code] README.md (e18e1e)` | deletes `README.md` | keeps it | | `notes` | deletes `notes.txt` | keeps it | | `x/app.lua` | deletes `app.lua` | keeps it | | `plain-tab` (diff open with that name) | `-32000`, diff stays, no `openDiff` answer | `TAB_CLOSED`, diff closed, `openDiff` gets `DIFF_REJECTED` | 2. **verify-claudecode-nvim** (agent-tty, real Neovim 0.12.3, `ws-client.mjs` as Claude). The user opens `notes.txt`, `app.lua` and `README.md`, then Claude sends the same `close_tab` calls and two `openDiff` + `close_tab` pairs. - main: all three buffers are gone, and the window shows `[No Name]`. `close_tab plain-tab` answers `-32000`, and the `openDiff` gets no answer within 5 s. The marked name `✻ [Claude Code] app.lua (a1b2c3) ⧉` closes its diff with `DIFF_REJECTED`. - this PR: all three buffers stay listed. Both diffs close, and each `openDiff` gets `DIFF_REJECTED`. 0 active diffs remain, and the client stays alive. main after the `close_tab` calls:  this PR after the same calls:  3. **Unit tests**: `80ca130` adds 2 tests, and both fail on main. One finds the plain-tab diff still open, and the other finds the user's buffer deleted for `README.md`. `b60eacb` makes them pass. `mise run check` (0 warnings), `mise run test` (812 successes, 0 failures), `stylua --check`, and `prettier --check` pass on the head commit. 4. **verify-diff-lifecycle**: every fact reads TRUE, and the model passes (89,205 and 5,269 states). The model already describes `close_tab` as a close by name for any tab (`ClaudeClosesTab` -> `CloseByName`), so the model and its facts do not change. On main the check already read STALE for files changed by coder#364, coder#365, coder#366 and coder#370 (terminal adoption, the `getDiagnostics` and `close_tab` log calls, `openFile`). None of them reaches diff state or an `openDiff` answer. `03ca54a` re-records `covered.lock`, and `check.sh` reads PASS. --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_
Why
The goal is to close the open follow-up issues in this repo with one small, reviewed PR per fix. This PR covers item 4 of #362.
Part of #362
The logger takes the component name first. Every log call in the
close_tabandgetDiagnosticshandlers passed only the message. The logger printed the message as the component, followed by an empty message. Each call now passes the tool name as the component.What changed
tools/close_tab.lua(12 calls) andtools/get_diagnostics.lua(4 calls) pass"close_tab"or"getDiagnostics"first. The message text stays the same.tests/unit/tools/tool_log_lines_spec.luadrives every log call in both handlers through the real logger. It checks that each line that reachesnvim_echohistory orvim.notifynames the tool as the component and has a message. It fails on main.ARCHITECTURE.mdmade the same mistake. It now passes a component first.Scope
lua/found no other call that puts the message in the component slot.Blast Radius
Only log output changes. At the default
infolevel, users see theclose_tabsuccess line and its error lines, which now read[ClaudeCode] [close_tab] [INFO] Successfully closed tab: ...and similar.Verification
Real Neovim 0.12.3 through the
verify-claudecode-nvimharness atlog_level = "debug". The client calledclose_tabwith an unknown tab and with notab_name, thengetDiagnosticswith nouriand with an open file'suri. Lines from:messages:busted -v tests/unit/tools/tool_log_lines_spec.luagives 2 failures with the fix removed and 2 passes with it. A luacov run shows that the spec reaches all 16 calls.mise run checkandmise run testpass (798 successes, 0 failures).Generated with
xum• Model:anthropic:claude-opus-5-5• Thinking:xhigh