nixvim-config/config/plugins/cmp/codecompanion.nix

196 lines
4.8 KiB
Nix

{...}: {
plugins.codecompanion = {
enable = true;
# Configuration options for CodeCompanion
settings = {
# Customize the UI of the chat buffer
display.chat.window = {
layout = "vertical";
position = "right";
width = 0.25;
};
# Setup ollama adapter for self-hosted LLM
adapters = {
http = {
"ollama:qwen2.5-coder" = {
__raw = ''
function()
return require('codecompanion.adapters').extend('ollama', {
name = "ollama:qwen2.5-coder",
env = {
url = "http://127.0.0.1:11434",
},
schema = {
model = {
default = "qwen2.5-coder:7b",
},
num_ctx = {
default = 32768,
},
},
})
end
'';
};
"ollama:deepseek-r1" = {
__raw = ''
function()
return require('codecompanion.adapters').extend('ollama', {
name = "ollama:deepseek-r1",
env = {
url = "http://127.0.0.1:11434",
},
schema = {
model = {
default = "deepseek-r1:8b",
},
num_ctx = {
default = 131072,
},
},
})
end
'';
};
"ollama:gemma3" = {
__raw = ''
function()
return require('codecompanion.adapters').extend('ollama', {
name = "ollama:gemma3",
env = {
url = "http://127.0.0.1:11434",
},
schema = {
model = {
default = "gemma3:4b",
},
num_ctx = {
default = 131072,
},
},
})
end
'';
};
"ollama:qwen3" = {
__raw = ''
function()
return require('codecompanion.adapters').extend('ollama', {
name = "ollama:qwen3",
env = {
url = "http://127.0.0.1:11434",
},
schema = {
model = {
default = "qwen3:8b",
},
num_ctx = {
default = 40960,
},
},
})
end
'';
};
"ollama:llama3" = {
__raw = ''
function()
return require('codecompanion.adapters').extend('ollama', {
name = "ollama:llama3",
env = {
url = "http://127.0.0.1:11434",
},
schema = {
model = {
default = "llama3:8b",
},
num_ctx = {
default = 8192,
},
},
})
end
'';
};
# Disable default adapters
opts.show_defaults = false;
};
acp = {
# Disable default adapters
opts.show_defaults = false;
};
};
# Global options for CodeCompanion
opts = {
log_level = "TRACE";
send_code = true;
use_default_actions = true;
use_default_prompts = true;
};
# Interaction strategies
strategies = {
agent = {
adapter = "ollama:qwen2.5-coder";
};
chat = {
adapter = "ollama:qwen2.5-coder";
};
inline = {
adapter = "ollama:qwen2.5-coder";
};
};
};
};
keymaps = [
# Main toggle for the CodeCompanion plugin
{
mode = ["n" "v"];
key = "<leader>c";
action = "<Nop>";
options = {
desc = "+companion";
};
}
# Toggle the chat buffer on/off
{
mode = ["n" "v"];
key = "<leader>cc";
action = "<cmd>CodeCompanionChat Toggle<cr>";
options = {
desc = "Toggle chat";
};
}
# Open the actions palette
{
mode = ["n" "v"];
key = "<leader>cA";
action = "<cmd>CodeCompanionActions<cr>";
options = {
desc = "Open actions palette";
};
}
# Add selected text to the chat buffer
{
mode = ["v"];
key = "<leader>ca";
action = "<cmd>CodeCompanionChat Add<cr>";
options = {
desc = "Add selected text to chat";
};
}
];
}