2025-04-14 15:20:54 +01:00
|
|
|
|
require('helpers').edit_cf('pa', '/lua/plugins/codecompanion.lua')
|
2025-04-14 11:38:42 +01:00
|
|
|
|
|
2025-04-29 17:22:28 +01:00
|
|
|
|
vim.cmd [[cab cc CodeCompanion]]
|
|
|
|
|
|
|
2025-04-13 22:53:08 +01:00
|
|
|
|
return {
|
|
|
|
|
|
'olimorris/codecompanion.nvim',
|
2025-04-15 20:48:35 +01:00
|
|
|
|
opts = function(_, opts)
|
|
|
|
|
|
opts.adapters = {
|
2025-04-17 08:53:20 +01:00
|
|
|
|
gpt = function()
|
2025-04-14 15:20:54 +01:00
|
|
|
|
return require('codecompanion.adapters').extend('copilot', {
|
|
|
|
|
|
schema = {
|
|
|
|
|
|
model = {
|
2025-05-05 07:25:00 +01:00
|
|
|
|
default = 'gpt-4.1',
|
2025-04-14 15:20:54 +01:00
|
|
|
|
},
|
2025-04-17 08:53:20 +01:00
|
|
|
|
max_tokens = {
|
|
|
|
|
|
default = 1000000,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
end,
|
|
|
|
|
|
flash = function()
|
|
|
|
|
|
return require('codecompanion.adapters').extend('copilot', {
|
|
|
|
|
|
schema = {
|
|
|
|
|
|
model = {
|
|
|
|
|
|
default = 'gemini-2.0-flash',
|
|
|
|
|
|
},
|
|
|
|
|
|
max_tokens = {
|
|
|
|
|
|
default = 1000000,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
end,
|
|
|
|
|
|
gemini = function()
|
|
|
|
|
|
return require('codecompanion.adapters').extend('copilot', {
|
|
|
|
|
|
schema = {
|
|
|
|
|
|
model = {
|
|
|
|
|
|
default = 'gemini-2.5-pro',
|
|
|
|
|
|
},
|
|
|
|
|
|
max_tokens = {
|
|
|
|
|
|
default = 1000000,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
end,
|
|
|
|
|
|
sonnet = function()
|
|
|
|
|
|
return require('codecompanion.adapters').extend('copilot', {
|
|
|
|
|
|
schema = {
|
|
|
|
|
|
model = {
|
|
|
|
|
|
default = 'claude-3.7-sonnet',
|
|
|
|
|
|
},
|
|
|
|
|
|
max_tokens = {
|
|
|
|
|
|
default = 1000000,
|
|
|
|
|
|
},
|
2025-04-14 15:20:54 +01:00
|
|
|
|
},
|
|
|
|
|
|
})
|
|
|
|
|
|
end,
|
2025-04-15 20:48:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
opts.display = {
|
2025-04-14 15:20:54 +01:00
|
|
|
|
chat = {
|
|
|
|
|
|
show_settings = true,
|
2025-05-08 07:59:46 +01:00
|
|
|
|
start_in_insert_mode = false,
|
2025-04-14 15:20:54 +01:00
|
|
|
|
},
|
2025-04-15 20:48:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
opts.strategies = {
|
|
|
|
|
|
chat = {
|
2025-04-29 17:22:28 +01:00
|
|
|
|
adapter = 'gpt',
|
2025-04-15 20:48:35 +01:00
|
|
|
|
slash_commands = {
|
|
|
|
|
|
codebase = require('vectorcode.integrations').codecompanion.chat.make_slash_command(),
|
|
|
|
|
|
},
|
|
|
|
|
|
tools = {
|
|
|
|
|
|
vectorcode = {
|
|
|
|
|
|
description = 'Run VectorCode to retrieve the project context.',
|
|
|
|
|
|
callback = require('vectorcode.integrations').codecompanion.chat.make_tool(),
|
|
|
|
|
|
},
|
2025-05-05 07:25:00 +01:00
|
|
|
|
['cmd_runner'] = {
|
|
|
|
|
|
opts = {
|
|
|
|
|
|
requires_approval = false,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
roles = {
|
|
|
|
|
|
---@type string|fun(adapter: CodeCompanion.Adapter): string
|
|
|
|
|
|
llm = function(adapter)
|
|
|
|
|
|
return 'CodeCompanion (' .. adapter.formatted_name .. ': ' .. adapter.parameters.model .. ')'
|
|
|
|
|
|
end,
|
|
|
|
|
|
},
|
|
|
|
|
|
keymaps = {
|
|
|
|
|
|
send = {
|
|
|
|
|
|
modes = { n = '<C-s>', i = '<C-s>' },
|
|
|
|
|
|
},
|
|
|
|
|
|
close = {
|
|
|
|
|
|
modes = { n = '<C-c>', i = '<C-c>' },
|
|
|
|
|
|
},
|
2025-04-15 20:48:35 +01:00
|
|
|
|
},
|
|
|
|
|
|
},
|
2025-04-17 08:53:20 +01:00
|
|
|
|
inline = {
|
|
|
|
|
|
adapter = 'flash',
|
|
|
|
|
|
},
|
2025-04-15 20:48:35 +01:00
|
|
|
|
}
|
2025-05-05 07:25:00 +01:00
|
|
|
|
|
|
|
|
|
|
opts.extensions = {
|
|
|
|
|
|
mcphub = {
|
|
|
|
|
|
callback = 'mcphub.extensions.codecompanion',
|
|
|
|
|
|
opts = {
|
|
|
|
|
|
show_result_in_chat = true,
|
|
|
|
|
|
make_vars = true,
|
|
|
|
|
|
make_slash_commands = true,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
opts.system_prompt = function(opts)
|
|
|
|
|
|
local language = opts.language or 'English'
|
|
|
|
|
|
return string.format(
|
|
|
|
|
|
[[You are an AI programming assistant named "CodeCompanion". You are currently plugged into the Neovim text editor on a user's machine.
|
|
|
|
|
|
|
|
|
|
|
|
Your core tasks include:
|
|
|
|
|
|
- Answering general programming questions.
|
|
|
|
|
|
- Explaining how the code in a Neovim buffer works.
|
|
|
|
|
|
- Reviewing the selected code from a Neovim buffer.
|
|
|
|
|
|
- Generating unit tests for the selected code.
|
|
|
|
|
|
- Proposing fixes for problems in the selected code.
|
|
|
|
|
|
- Scaffolding code for a new workspace.
|
|
|
|
|
|
- Finding relevant code to the user's query.
|
|
|
|
|
|
- Proposing fixes for test failures.
|
|
|
|
|
|
- Answering questions about Neovim.
|
|
|
|
|
|
- Running tools.
|
|
|
|
|
|
|
|
|
|
|
|
You must:
|
|
|
|
|
|
- Follow the user's requirements carefully and to the letter.
|
|
|
|
|
|
- Keep your answers short and impersonal, especially if the user's context is outside your core tasks.
|
|
|
|
|
|
- Minimize additional prose unless clarification is needed.
|
|
|
|
|
|
- Use Markdown formatting in your answers.
|
|
|
|
|
|
- Include the programming language name at the start of each Markdown code block.
|
|
|
|
|
|
- Avoid including line numbers in code blocks.
|
|
|
|
|
|
- Avoid wrapping the whole response in triple backticks.
|
|
|
|
|
|
- Only return code that's directly relevant to the task at hand. You may omit code that isn’t necessary for the solution.
|
|
|
|
|
|
- Avoid using H1, H2 or H3 headers in your responses as these are reserved for the user.
|
|
|
|
|
|
- Use actual line breaks in your responses; only use "\n" when you want a literal backslash followed by 'n'.
|
|
|
|
|
|
- All non-code text responses must be written in the %s language indicated.
|
|
|
|
|
|
- Multiple, different tools can be called as part of the same response.
|
|
|
|
|
|
|
|
|
|
|
|
When given a task:
|
|
|
|
|
|
1. Think step-by-step and, unless the user requests otherwise or the task is very simple, describe your plan in detailed pseudocode.
|
|
|
|
|
|
2. Output the final code in a single code block, ensuring that only relevant code is included.
|
|
|
|
|
|
3. End your response with a short suggestion for the next user turn that directly supports continuing the conversation.
|
|
|
|
|
|
4. Provide exactly one complete reply per conversation turn.
|
|
|
|
|
|
5. If necessary, execute multiple tools in a single turn.]],
|
|
|
|
|
|
language
|
|
|
|
|
|
)
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
opts.prompt_library = {
|
|
|
|
|
|
['Code Expert'] = {
|
|
|
|
|
|
strategy = 'chat',
|
|
|
|
|
|
description = 'Get some special adcvice from an LLM.',
|
|
|
|
|
|
opts = {
|
|
|
|
|
|
mapping = '<Leader>ce',
|
|
|
|
|
|
modes = { 'v' },
|
|
|
|
|
|
short_name = 'expert',
|
|
|
|
|
|
auto_submit = true,
|
|
|
|
|
|
stop_context_insertion = true,
|
|
|
|
|
|
user_prompt = true,
|
|
|
|
|
|
},
|
|
|
|
|
|
prompts = {
|
|
|
|
|
|
{
|
|
|
|
|
|
role = 'system',
|
|
|
|
|
|
content = function(context)
|
|
|
|
|
|
return 'I want you to act as a senior'
|
|
|
|
|
|
.. context.filetype
|
|
|
|
|
|
.. 'developer I will ask you specific questions and I want you to return concise explanations and codeblock examples.'
|
|
|
|
|
|
end,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
role = 'user',
|
|
|
|
|
|
content = function(context)
|
|
|
|
|
|
local text = require('codecompanion.helpers.actions').get_code(context.start_line, context.end_line)
|
|
|
|
|
|
|
|
|
|
|
|
return 'I have the following code:\n\n```' .. context.filetype .. '\n' .. text .. '\n```\n\n'
|
|
|
|
|
|
end,
|
|
|
|
|
|
opts = {
|
|
|
|
|
|
contains_code = true,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
['Games Master'] = {
|
|
|
|
|
|
strategy = 'chat',
|
|
|
|
|
|
description = 'A personal Games Master Assistant.',
|
|
|
|
|
|
opts = {
|
|
|
|
|
|
mapping = '<Leader>cd',
|
|
|
|
|
|
modes = { 'n' },
|
|
|
|
|
|
short_name = 'gm',
|
|
|
|
|
|
auto_submit = false,
|
|
|
|
|
|
stop_context_insertion = false,
|
|
|
|
|
|
user_prompt = false,
|
|
|
|
|
|
is_default = true,
|
2025-05-05 07:28:57 +01:00
|
|
|
|
adapter = {
|
2025-05-05 07:25:00 +01:00
|
|
|
|
temperature = 1,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
prompts = {
|
|
|
|
|
|
{
|
|
|
|
|
|
role = 'system',
|
|
|
|
|
|
content = function(context)
|
|
|
|
|
|
return [[
|
|
|
|
|
|
You are a personal Games Master Assistant. You are currently plugged in to the Neovim text editor on a user's machine.
|
|
|
|
|
|
|
|
|
|
|
|
Your core tasks include:
|
|
|
|
|
|
- Crafting engaging role playing sessions
|
|
|
|
|
|
- Building immersive and authentic worlds
|
|
|
|
|
|
- Creating compelling characters for the players to interact with and drive the story
|
|
|
|
|
|
- Reviewing session summaries and building on them
|
|
|
|
|
|
- Providing advice on how to bring sessions to life
|
|
|
|
|
|
- Create exciting encounters to challenge the players
|
|
|
|
|
|
- Encounters can be combat, social, or exploration based
|
|
|
|
|
|
- There should always be a story reason for the encounter
|
|
|
|
|
|
- Combine player character backgrounds and motivations into the world
|
|
|
|
|
|
- Build tension and drama into the game
|
|
|
|
|
|
- Ensure each session provides opportunities for the players to engage with and drive the story
|
|
|
|
|
|
|
|
|
|
|
|
You must:
|
|
|
|
|
|
- Follow the user's requirements carefully and to the letter.
|
|
|
|
|
|
- Keep answers focused on the task at hand.
|
|
|
|
|
|
- Provide original ideas and suggestions.
|
|
|
|
|
|
- Use Markdown formatting in your answers.
|
|
|
|
|
|
- Use actual line breaks instead of '\n' in your response to begin new lines.
|
|
|
|
|
|
- Use '\n' only when you want a literal backslash followed by a character 'n'.
|
|
|
|
|
|
- All responses must be written in English.
|
|
|
|
|
|
- Multiple, different tools can be called as part of the same response.
|
|
|
|
|
|
- Help sessions be fast paced and fun.
|
|
|
|
|
|
- Ensure there are multiple soltuions to each problem.
|
|
|
|
|
|
- Avoid railroading the players.
|
|
|
|
|
|
|
|
|
|
|
|
When given a task:
|
|
|
|
|
|
1. Consider the existing world and characters. Use tools to gather information that may be relevant.
|
|
|
|
|
|
2. Provide exactly one complete reply per conversation turn.
|
|
|
|
|
|
3. If necessary, execute multiple tools in a single turn.
|
|
|
|
|
|
]]
|
|
|
|
|
|
end,
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
role = 'user',
|
|
|
|
|
|
content = function(context)
|
|
|
|
|
|
return ''
|
|
|
|
|
|
end,
|
|
|
|
|
|
opts = {
|
|
|
|
|
|
contains_code = false,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
2025-04-15 20:48:35 +01:00
|
|
|
|
end,
|
2025-04-13 22:53:08 +01:00
|
|
|
|
dependencies = {
|
|
|
|
|
|
'nvim-lua/plenary.nvim',
|
|
|
|
|
|
'nvim-treesitter/nvim-treesitter',
|
2025-04-15 20:48:35 +01:00
|
|
|
|
'Davidyz/VectorCode',
|
2025-05-05 07:25:00 +01:00
|
|
|
|
'ravitemer/mcphub.nvim',
|
2025-04-13 22:53:08 +01:00
|
|
|
|
},
|
|
|
|
|
|
}
|