Skip to content

Commit 16a7921

Browse files
committed
Add turtle.nvim Lua client
1 parent 2f5f0e3 commit 16a7921

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
local M = {}
2+
3+
local function agentctl_args(...)
4+
local args = { 'turtle-agentctl', '--stdio' }
5+
for _, value in ipairs({ ... }) do
6+
if value ~= nil and value ~= '' then
7+
table.insert(args, value)
8+
end
9+
end
10+
return args
11+
end
12+
13+
local function notify_payload(title, payload)
14+
local text = vim.fn.json_encode(payload)
15+
vim.notify(title .. '\n' .. text, vim.log.levels.INFO)
16+
end
17+
18+
local function run_agentctl(title, ...)
19+
local args = agentctl_args(...)
20+
vim.system(args, { text = true }, function(result)
21+
vim.schedule(function()
22+
if result.code ~= 0 then
23+
vim.notify(title .. ' failed\n' .. (result.stderr or result.stdout or ''), vim.log.levels.ERROR)
24+
return
25+
end
26+
local ok, payload = pcall(vim.json.decode, result.stdout)
27+
if ok then
28+
notify_payload(title, payload)
29+
else
30+
vim.notify(title .. '\n' .. result.stdout, vim.log.levels.INFO)
31+
end
32+
end)
33+
end)
34+
end
35+
36+
function M.ping()
37+
run_agentctl('TurtleTerm ping', 'ping')
38+
end
39+
40+
function M.sessions()
41+
run_agentctl('TurtleTerm sessions', 'sessions')
42+
end
43+
44+
function M.inspect(session_id)
45+
run_agentctl('TurtleTerm inspect', 'inspect', session_id)
46+
end
47+
48+
function M.summarize(session_id)
49+
run_agentctl('TurtleTerm summarize', 'summarize', session_id)
50+
end
51+
52+
function M.propose(command)
53+
if command == nil or command == '' then
54+
vim.notify('TurtlePropose requires a command', vim.log.levels.ERROR)
55+
return
56+
end
57+
run_agentctl('TurtleTerm propose', 'propose', command)
58+
end
59+
60+
function M.request_execution(command)
61+
if command == nil or command == '' then
62+
vim.notify('TurtleRequestExecution requires a command', vim.log.levels.ERROR)
63+
return
64+
end
65+
run_agentctl('TurtleTerm request execution', 'request-execution', command)
66+
end
67+
68+
function M.receipts(session_id)
69+
run_agentctl('TurtleTerm receipts', 'receipts', session_id)
70+
end
71+
72+
return M

0 commit comments

Comments
 (0)