neovim: CodeCompanion session id from git repo+branch; extract plugin module (#24) #26

Closed
hermes-bot wants to merge 1 commit from issue-24-codecompanion-session-id into main
Member

Closes #24.

What

  1. Session id from repo + branch — X-Hermes-Session-Id is now a function (hermes_session_id) instead of a static string. CodeCompanion's set_env_vars (adapters/utils/init.lua) evaluates function header values on every request, so the id is recomputed per message:
    • nvim-<repo>-<branch> via git rev-parse --show-toplevel + --abbrev-ref HEAD (vim.system, no shell quoting issues, ~1-5 ms per send).
    • Non-git directories fall back to the old nvim-<cwd-name> behaviour.
    • Detached HEAD yields a stable nvim-<repo>-HEAD; branch names are sanitized to ASCII-safe header chars (feature/foo bar → feature-foo-bar).
    • This answers the issue's second question: yes, it tracks repo/branch changes with no autocmd — the id switches on the next message after a git switch/:cd.
  2. Refactor — the whole codecompanion block (strategies, interactions, hermes adapter) and its three keymaps (<leader>a, <leader>ac, <leader>ae) move from users/modules/neovim/default.nix to users/modules/neovim/plugins/codecompanion.nix, imported from plugins/default.nix, matching how telescope/lsp/cmp are structured. No behaviour change in the settings themselves (only the trailing-whitespace nit on run_command was cleaned).

Verification

  • Embedded Lua __raw block parses (luaparser, Lua 5.4 grammar).
  • All three touched .nix files pass nix-instantiate --parse (nix 2.32.2).
  • Behaviour to be confirmed by @rpickler's test session per the issue.

Plan reference: #24 (comment)

Closes #24. ## What 1. **Session id from repo + branch** — `X-Hermes-Session-Id` is now a *function* (`hermes_session_id`) instead of a static string. CodeCompanion's `set_env_vars` (`adapters/utils/init.lua`) evaluates function header values on **every** request, so the id is recomputed per message: - `nvim-<repo>-<branch>` via `git rev-parse --show-toplevel` + `--abbrev-ref HEAD` (`vim.system`, no shell quoting issues, ~1-5 ms per send). - Non-git directories fall back to the old `nvim-<cwd-name>` behaviour. - Detached HEAD yields a stable `nvim-<repo>-HEAD`; branch names are sanitized to ASCII-safe header chars (`feature/foo bar` → `feature-foo-bar`). - This answers the issue's second question: yes, it tracks repo/branch changes with **no autocmd** — the id switches on the next message after a `git switch`/`:cd`. 2. **Refactor** — the whole `codecompanion` block (strategies, interactions, hermes adapter) and its three keymaps (`<leader>a`, `<leader>ac`, `<leader>ae`) move from `users/modules/neovim/default.nix` to `users/modules/neovim/plugins/codecompanion.nix`, imported from `plugins/default.nix`, matching how telescope/lsp/cmp are structured. No behaviour change in the settings themselves (only the trailing-whitespace nit on `run_command` was cleaned). ## Verification - Embedded Lua `__raw` block parses (luaparser, Lua 5.4 grammar). - All three touched `.nix` files pass `nix-instantiate --parse` (nix 2.32.2). - Behaviour to be confirmed by @rpickler's test session per the issue. Plan reference: https://git.richardpickler.com/richardpickler.com/nixos/issues/24#issuecomment-517
X-Hermes-Session-Id is now a function evaluated by CodeCompanion on
every request (set_env_vars evaluates function header values), so the
id tracks repo/branch switches without an autocmd. Outside a git repo
it falls back to the old cwd-name behaviour.

Also refactor codecompanion (plugin config + keymaps) out of
users/modules/neovim/default.nix into plugins/codecompanion.nix,
matching how telescope/lsp/cmp are defined.
Owner

Merged as part of #25

Merged as part of #25
rpickler closed this pull request 2026-10-17 04:55:18 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
richardpickler.com/nixos!26
No description provided.