Files
nvim/lua/plugins/ai.lua
T

89 lines
3.1 KiB
Lua

-- Completion: minuet against a local Ollama, no cloud fallback.
-- Agent: sidekick hosts my own agent CLI in a terminal split.
local full = vim.g.profile == "full"
local endpoint = vim.env.MINUET_ENDPOINT or "http://127.0.0.1:11434"
local function allowed(buf)
buf = buf or vim.api.nvim_get_current_buf()
local name = vim.api.nvim_buf_get_name(buf)
local base = vim.fs.basename(name)
return not (
vim.b[buf].bigfile
or vim.bo[buf].filetype == "gitcommit"
or base:match("^%.env")
or name:match("/secrets/")
)
end
local function agent(fn, opts)
return function()
require("sidekick.cli")[fn](vim.tbl_extend("force", { name = "agent" }, opts or {}))
end
end
return {
{
"milanglacier/minuet-ai.nvim",
cond = full,
lazy = true, -- loaded by blink.cmp
dependencies = { "nvim-lua/plenary.nvim" },
keys = {
{ "<leader>ta", "<cmd>Minuet blink toggle<cr>", desc = "Toggle AI completion" },
},
opts = {
provider = "openai_fim_compatible",
n_completions = 1,
context_window = 4096,
throttle = 1000,
debounce = 400,
request_timeout = 3,
enable_predicates = {
function()
return allowed()
end,
},
provider_options = {
openai_fim_compatible = {
name = "ollama",
api_key = "TERM", -- Ollama needs no key; any set env var works
end_point = endpoint .. "/v1/completions",
model = "qwen2.5-coder:3b",
optional = { max_tokens = 56, top_p = 0.9 },
-- default template: Ollama builds the FIM prompt itself from `prompt` + `suffix`
},
},
},
},
{
"folke/sidekick.nvim",
cond = full,
keys = {
{ "<C-.>", function() require("sidekick.cli").focus() end, desc = "Focus agent", mode = { "n", "t", "i", "x" } },
{ "<leader>aa", agent("toggle", { focus = true }), desc = "Toggle agent" },
{ "<leader>as", function() require("sidekick.cli").select() end, desc = "Select CLI session" },
{ "<leader>at", agent("send", { msg = "{this}" }), desc = "Send this", mode = { "n", "x" } },
{ "<leader>af", agent("send", { msg = "{file}" }), desc = "Send file" },
{ "<leader>av", agent("send", { msg = "{selection}" }), desc = "Send selection", mode = "x" },
{ "<leader>ap", agent("prompt"), desc = "Pick prompt", mode = { "n", "x" } },
{ "<leader>ad", function() require("sidekick.cli").close() end, desc = "Detach session" },
},
opts = {
nes = { enabled = false }, -- needs Copilot
cli = {
watch = true,
mux = { enabled = false },
win = { layout = "right", split = { width = 80 } },
tools = {
agent = { cmd = vim.split(vim.env.NVIM_AGENT_CMD or "agent", " ", { trimempty = true }) },
},
prompts = {
review = "Review the current git diff (run `git diff`) for bugs, risks and simplifications.",
explain = "Explain {this}",
fix = "Fix these diagnostics in {file}:\n{diagnostics}",
tests = "Write tests for {this}",
},
},
},
},
}