summaryrefslogtreecommitdiff
path: root/acp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'acp.lua')
-rw-r--r--acp.lua15
1 files changed, 10 insertions, 5 deletions
diff --git a/acp.lua b/acp.lua
index 18dfaa7..9e648b9 100644
--- a/acp.lua
+++ b/acp.lua
@@ -107,7 +107,7 @@ M.probe = verified
-- agy discovers named agents under <gemini-dir>/config/agents. Declare the
-- relay on the agent itself: session/new MCP servers need not be inherited by
-- custom agents. Never edit the user's agents or global MCP configuration.
-local function relay(s) return {name='pantograph',command='/usr/bin/nc',args={'-U',s.dir..'/mcp'}} end
+local function relay(s) return {name='pantograph',command='/usr/bin/nc',args={'-U',s.dir..'/mcp'},timeoutSeconds=1800} end
local function install_agent(s, profile)
local dir=profile
for _,part in ipairs({'config','agents'}) do
@@ -183,7 +183,7 @@ function M.launch(s, first, resume_id)
assert(not waiting,'Overlapping ACP requests'); serial=serial+1; request_id=serial; waiting=coroutine.running()
idle=(method=='session/prompt' or method=='authenticate') and 600000 or 60000
activity(); timer:start(1000,1000,function()
- if s.call then activity() elseif uv.now()>=deadline then s.fail('ACP timeout: '..method) end
+ if s.call or s.issued then activity() elseif uv.now()>=deadline then s.fail('ACP timeout: '..method) end
end)
send({id=serial,method=method,params=params}); return coroutine.yield()
end
@@ -271,6 +271,13 @@ function M.launch(s, first, resume_id)
advertised()
turn(first)
end
+ -- ACP may finish while Panto still owns a tool execution. Join both
+ -- sides before committing the turn (including any boundary steering).
+ s.settle=function()
+ if primary_reply and not s.issued and not next(steering) then
+ local co,result=waiting,primary_reply; waiting,primary_reply=nil,nil; timer:stop(); step(co,result)
+ end
+ end
local function receive(q)
assert(q.jsonrpc=='2.0','Invalid ACP envelope')
if not q.method then
@@ -286,9 +293,7 @@ function M.launch(s, first, resume_id)
else
assert(q.id==request_id and not primary_reply,'Unexpected ACP reply'); primary_reply=assert(q.result)
end
- if primary_reply and not next(steering) then
- local co,result=waiting,primary_reply; waiting,primary_reply=nil,nil; timer:stop(); step(co,result)
- end
+ s.settle()
return
end
local p=q.params or {}; local ours=s.session and p.sessionId==s.session