Skip to content

fix(tools): pass the component first in close_tab and getDiagnostics log calls - #366

Merged
ThomasK33 merged 3 commits into
mainfrom
fix/tool-logger-component
Oct 31, 2026
Merged

ThomasK33 merged 3 commits into
mainfrom
fix/tool-logger-component

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

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_tab and getDiagnostics handlers 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) and tools/get_diagnostics.lua (4 calls) pass "close_tab" or "getDiagnostics" first. The message text stays the same.
  • tests/unit/tools/tool_log_lines_spec.lua drives every log call in both handlers through the real logger. It checks that each line that reaches nvim_echo history or vim.notify names the tool as the component and has a message. It fails on main.
  • The error handling example in ARCHITECTURE.md made the same mistake. It now passes a component first.

Scope

Blast Radius

Only log output changes. At the default info level, users see the close_tab success 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-nvim harness at log_level = "debug". The client called close_tab with an unknown tab and with no tab_name, then getDiagnostics with no uri and with an open file's uri. Lines from :messages:

    before (main 3cdaba9)
    [ClaudeCode] [close_tab handler called] [DEBUG]
    [ClaudeCode] [Missing required parameter: tab_name] [ERROR]
    [ClaudeCode] [getDiagnostics handler called] [DEBUG]
    [ClaudeCode] [Getting diagnostics for bufnr: 1] [DEBUG]
    
    after
    [ClaudeCode] [close_tab] [DEBUG] close_tab handler called
    [ClaudeCode] [close_tab] [ERROR] Missing required parameter: tab_name
    [ClaudeCode] [getDiagnostics] [DEBUG] getDiagnostics handler called
    [ClaudeCode] [getDiagnostics] [DEBUG] Getting diagnostics for bufnr: 1
    
  • busted -v tests/unit/tools/tool_log_lines_spec.lua gives 2 failures with the fix removed and 2 passes with it. A luacov run shows that the spec reaches all 16 calls.

  • mise run check and mise run test pass (798 successes, 0 failures).


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

…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`_
@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 Oct 31, 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-10-31T23:16:58.221814Z 5fe3cef Manual request
🔒 Security Review ✅ Completed 2026-10-31T23:17:09.554969Z 5fe3cef 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. Delightful!

Reviewed commit: 48a2a73b03

ℹ️ 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: 48a2a73b03

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.

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`_
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 5fe3cef9ac

ℹ️ 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: 5fe3cef9ac

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 Oct 31, 2026
Merged via the queue into main with commit 3dc8ced Oct 31, 2026
5 checks passed
@ThomasK33
ThomasK33 deleted the fix/tool-logger-component branch October 31, 2026 23:29
ThomasK33 added a commit to joshmedeski/claudecode.nvim that referenced this pull request Nov 10, 2026
…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:

![main: the user's README.md buffer is
gone](https://github.com/user-attachments/assets/0b1550b4-86ee-4b29-830b-b4b2176fdcdd)

   this PR after the same calls:

![this PR: the user's README.md buffer
stays](https://github.com/user-attachments/assets/8fbedf45-b8ac-4044-9d68-dcd0a9d7a1a4)

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`_
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