Files
mcp-memory/gemini-integration.lua
T

73 lines
3.3 KiB
Lua

-- gemini-integration.lua
-- Registers the active Neovim instance for the Antigravity MCP Server
vim.api.nvim_create_autocmd({"VimEnter", "FocusGained", "BufEnter", "BufWritePost"}, {
callback = function(ev)
-- Only register if Neovim has an active UI attached (ignore headless/embedded instances)
if #vim.api.nvim_list_uis() > 0 then
local server_name = vim.v.servername
if server_name then
-- 1. Legacy Disk Write (Fallback)
local home = os.getenv("HOME") or os.getenv("USERPROFILE")
if home then
os.execute("mkdir -p " .. home .. "/.gemini")
local path = home .. "/.gemini/active_nvim.txt"
local f = io.open(path, "w")
if f then
f:write(server_name)
f:close()
end
end
-- 2. V2 Telemetry Push (WebSockets & Cross-OS Sync via Rust Server)
local file = vim.api.nvim_buf_get_name(0)
local cursor = vim.api.nvim_win_get_cursor(0)
local row, col = cursor[1], cursor[2]
local payload = string.format(
'{"session_id": "%s", "event": "%s", "file": "%s", "line": %d, "col": %d}',
server_name:gsub("\\", "\\\\"), ev.event, file:gsub("\\", "\\\\"), row, col
)
local current_buf = ev.buf
vim.fn.jobstart({
"curl", "-s", "-X", "POST", "http://127.0.0.1:3000/nvim/telemetry",
"-H", "Content-Type: application/json",
"-d", payload
}, {
stdout_buffered = true,
on_stdout = function(_, data)
if data and #data > 0 then
local raw = table.concat(data, "")
if raw ~= "" then
local ok, resp = pcall(vim.fn.json_decode, raw)
if ok and resp and (resp.tech_debts or resp.adrs) then
vim.schedule(function()
if _G.gemini and _G.gemini.project_knowledge then
_G.gemini.project_knowledge(resp.tech_debts, resp.adrs, current_buf)
end
end)
end
end
end
end,
})
-- 3. UDP Mirroring (Native fast sync)
local uv = vim.uv or vim.loop
local client = uv.new_udp()
if client then
client:send(payload, "127.0.0.1", 3002, function(err)
client:close()
end)
end
end
end
end,
desc = "Register active Neovim instance for Gemini CLI",
})
-- Load UI & Keymaps
local is_win = vim.fn.has("win32") == 1
local ui_path = is_win and "C:/Users/reazul.ashraf/workspace/rust/mcp-memory/gemini-ui.lua" or "/mnt/c/Users/reazul.ashraf/workspace/rust/mcp-memory/gemini-ui.lua"
local ui = dofile(ui_path)
ui.setup()
_G.gemini = ui -- Expose globally so Agent can call it via execute_lua