Skip to content

codecompanion: extension support - #1115

Open
midischwarz12 wants to merge 1 commit into
NotAShelf:mainfrom
midischwarz12:codecompanion-extensions
Open

codecompanion: extension support#1115
midischwarz12 wants to merge 1 commit into
NotAShelf:mainfrom
midischwarz12:codecompanion-extensions

Conversation

@midischwarz12

@midischwarz12 midischwarz12 commented Aug 29, 2025

Copy link
Copy Markdown
Contributor

Sanity Checking

  • I have updated the [changelog] as per my changes
  • I have tested, and self-reviewed my code
  • My changes fit guidelines found in [hacking nvf]
  • Style and consistency
    • I ran Alejandra to format my code (nix fmt)
    • My code conforms to the [editorconfig] configuration of the project
    • My changes are consistent with the rest of the codebase
  • If new changes are particularly complex:
    • My code includes comments in particularly complex areas
    • I have added a section in the manual
    • (For breaking changes) I have included a migration guide
  • Package(s) built:
    • .#nix (default package)
    • .#maximal
    • .#docs-html (manual, must build)
    • .#docs-linkcheck (optional, please build if adding links)
  • Tested on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin

Add a 👍 reaction to pull requests you find important.

@github-actions

github-actions Bot commented Aug 29, 2025

Copy link
Copy Markdown

🚀 Live preview deployed from bf485ab

View it here:

Debug Information

Triggered by: midischwarz12

HEAD at: codecompanion-extensions

Reruns: 1352

Soliprem
Soliprem previously approved these changes Aug 29, 2025
Comment on lines +299 to +303
extensions = mkOption {
type = nullOr luaInline;
default = null;
description = "Extensions for codecompanion";

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be converted to nil by default. Does code-companion really support this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NotAShelf I'm not 100% sure how nvf is turning these options into lua code. I couldn't find where it traverses these and generates lua. But I kind of assumed that if it was null, it wouldn't generate the luaInLine at all. I think that's what happens with the adapter options.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did test this with the extensions set. And it seemed to work. I probably should test this with the extensions unset as well though.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@midischwarz12

Copy link
Copy Markdown
Contributor Author

Ah, okay. This is ready. But there is a merge conflict with the release notes. So I'll have to go resolve this real quick.

@midischwarz12
midischwarz12 force-pushed the codecompanion-extensions branch from 92d5f7b to dcde353 Compare September 2, 2025 13:29
@midischwarz12

Copy link
Copy Markdown
Contributor Author

@NotAShelf Ready to merge

github-actions Bot pushed a commit that referenced this pull request Sep 2, 2025
'';
};

extensions = mkOption {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you have Fundamentally Misunderstood how setupOpts is supposed to work. Normally, the setupOpts attribute set ({}) converts to a Lua table. In the documentation section you can find how Nix primitives are converted to Lua.

In this case,adding extensions is not strictly necessary; the setupOpts table is freeform and the user can already pass

extensions = { /* nix here */}

and it would be converted to the Lua expression. With type = luaInline, howevr, the user can ONLY pass inline Lua values, which defeats the purpose of using nvf. The type should be attrsOf anything, and to justify the addition of an option I'd like you to

  1. Add an example in mkOption
  2. Better utilize description.

Otherwise there is no need for this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I'm misunderstanding. I read through the docs you sent when you sent them previously. But from what I remember, there were quite a few call backs for these plugins and made more sense to just have inline lua.

I'll poke around more and look into doing this without the explicit inline extension option.


[midischwarz12](https://github.com/midischwarz12):

- Add extension support for [codecompanion-nvim].

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Add extension support is" misleading; we already hid it, it was just implicit. Better describe the change per my comment in the Nix section.

@midischwarz12 midischwarz12 Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "we already hid it"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe "explicit codecompanion-nvim extension option" would be more accurate then?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

had* it

@github-actions
github-actions Bot deleted the codecompanion-extensions branch February 15, 2026 05:22
@TafkaMax

Copy link
Copy Markdown

Would this allow to install codecompanion-history with NVF? I wish to use codecompanion-history to save my stuff.

@TafkaMax

Copy link
Copy Markdown

+1 for this feature, I would like to install codecompanion extensions. For example this one: https://github.com/ravitemer/codecompanion-history.nvim

@TafkaMax

TafkaMax commented Jul 9, 2026

Copy link
Copy Markdown

@midischwarz12 Hi, as you are the author of this pull request. Is there another way to use extensions for codecompanion when using nvf other than this PR? I really would like to save my prompts using codecompanion-history plugin.

Is there are reason this PR has been silent for a while?

@TafkaMax

Copy link
Copy Markdown

I read through the PR and it seems currently I can already add the extension to my codecompanion. How would I do it exactly?

I see underneath NVF is using lazy.nvim so the history plugin already has some docs regarding it. But guidance would be appreciated :)

E.g. does everything go under.

codecompanion-nvim = {
  setupOpts = {
    extensions = {}
  }
}

?

@TafkaMax

Copy link
Copy Markdown

I think I have cracked how to add the config, but how would one install the extension itself?

image

@TafkaMax

Copy link
Copy Markdown

So the config part in codecompanion-nvim would look like this?

 codecompanion-nvim = {
            enable = true;
            setupOpts = {
              extensions = lib.generators.mkLuaInline ''
                {
                  history = {
                    enabled = true,
                    opts = {
                      -- Keymap to open history from chat buffer (default: gh)
                      keymap = "gh",
                      -- Keymap to save the current chat manually (when auto_save is disabled)
                      save_chat_keymap = "sc",
                      -- Save all chats by default (disable to save only manually using 'sc')
                      auto_save = true,
                      -- Number of days after which chats are automatically deleted (0 to disable)
                      expiration_days = 0,
                      -- Picker interface (auto resolved to a valid picker)
                      picker = "telescope", --- ("telescope", "snacks", "fzf-lua", or "default")
                      ---Optional filter function to control which chats are shown when browsing
                      chat_filter = nil, -- function(chat_data) return boolean end
                      -- Customize picker keymaps (optional)
                      picker_keymaps = {
                          rename = { n = "r", i = "<M-r>" },
                          delete = { n = "d", i = "<M-d>" },
                          duplicate = { n = "<C-y>", i = "<C-y>" },
                      },
                      ---Automatically generate titles for new chats
                      auto_generate_title = true,
                      title_generation_opts = {
                          ---Adapter for generating titles (defaults to current chat adapter)
                          adapter = nil, -- "copilot"
                          ---Model for generating titles (defaults to current chat model)
                          model = nil, -- "gpt-4o"
                          ---Number of user prompts after which to refresh the title (0 to disable)
                          refresh_every_n_prompts = 0, -- e.g., 3 to refresh after every 3rd user prompt
                          ---Maximum number of times to refresh the title (default: 3)
                          max_refreshes = 3,
                          format_title = function(original_title)
                              -- this can be a custom function that applies some custom
                              -- formatting to the title.
                              return original_title
                          end
                      },
                      ---On exiting and entering neovim, loads the last chat on opening chat
                      continue_last_chat = false,
                      ---When chat is cleared with `gx` delete the chat from history
                      delete_on_clearing_chat = false,
                      ---Directory path to save the chats
                      dir_to_save = vim.fn.stdpath("data") .. "/codecompanion-history",
                      ---Enable detailed logging for history extension
                      enable_logging = false,

                      -- Summary system
                      summary = {
                          -- Keymap to generate summary for current chat (default: "gcs")
                          create_summary_keymap = "gcs",
                          -- Keymap to browse summaries (default: "gbs")
                          browse_summaries_keymap = "gbs",

                          generation_opts = {
                              adapter = nil, -- defaults to current chat adapter
                              model = nil, -- defaults to current chat model
                              context_size = 90000, -- max tokens that the model supports
                              include_references = true, -- include slash command content
                              include_tool_outputs = true, -- include tool execution results
                              system_prompt = nil, -- custom system prompt (string or function)
                              format_summary = nil, -- custom function to format generated summary e.g to remove <think/> tags from summary
                          },
                      },

                      -- Memory system (requires VectorCode CLI)
                      memory = {
                          -- Automatically index summaries when they are generated
                          auto_create_memories_on_summary_generation = true,
                          -- Path to the VectorCode executable
                          vectorcode_exe = "vectorcode",
                          -- Tool configuration
                          tool_opts = {
                              -- Default number of memories to retrieve
                              default_num = 10
                          },
                          -- Enable notifications for indexing progress
                          notify = true,
                          -- Index all existing memories on startup
                          -- (requires VectorCode 0.6.12+ for efficient incremental indexing)
                          index_on_startup = false,
                      },
                    }
                  }
                }
              '';
            }
}

I suppose?

@TafkaMax

Copy link
Copy Markdown

OK I think this helped me build the extension

      programs.nvf.settings.vim = {
        extraPlugins = {
          codecompanion-history = {
            package = pkgs.vimPlugins.codecompanion-history or (pkgs.vimUtils.buildVimPlugin {
              name = "codecompanion-history";
              src = pkgs.fetchFromGitHub {
                owner = "ravitemer"; # Adjust if using a different fork/repository
                repo = "codecompanion-history.nvim";
                rev = "main";
                hash = "sha256-SnzpyXqrAf60Vs7JbwuHmAJ/TNON8wwqNyPN3EGc2Og="; # Update with actual hash
              };
              # Supply codecompanion as a dependency for runtime & build time
              # dependencies = [ pkgs.vimPlugins.codecompanion-nvim ];
              # Disable the automated require check during package compilation
              doCheck = false;
            });
          };
        };
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants