diff options
Diffstat (limited to 'extensions')
| -rw-r--r-- | extensions/antigravity-acp.lua | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/extensions/antigravity-acp.lua b/extensions/antigravity-acp.lua index cdeb38a..d994cb3 100644 --- a/extensions/antigravity-acp.lua +++ b/extensions/antigravity-acp.lua @@ -50,18 +50,40 @@ local function rpc(s,c,q) local result if q.method=='initialize' then result={protocolVersion='2025-06-18',capabilities={tools={}},serverInfo={name='pantograph',version='0.1'}} elseif q.method=='ping' then result={} - elseif q.method=='tools/list' then s.listed=true; result={tools=s.list} + elseif q.method=='tools/list' then + -- result_part stays out of s.list, which is part of the checkpoint signature. + s.listed=true; local tools=json.array({}); for i,t in ipairs(s.list) do tools[i]=t end + tools[#tools+1]=catalog.part_tool; result={tools=tools} elseif q.method=='tools/call' then local args=q.params or {}; local tool=s.by[args.name]; local v=args.arguments if v==nil then v={} end - if not tool then return fail(-32602,'Tool unavailable') end - local ok,why=catalog.arguments(tool.schema,v); if not ok then return fail(-32602,why or 'Tool arguments rejected') end - if not s.prompting or s.cancelling then return fail(-32000,'No human turn pending') end - if s.call then return fail(-32000,'Another Panto tool call is pending') end - s.seq=s.seq+1; s.call={id=q.id,tag=s.dir:match('[^/]+$')..'-'..s.seq,name=tool.name,input=json.encode(v)}; s.notify(); return + if args.name==catalog.part_tool.name then + -- Answered here, not dispatched: Panto's transcript already holds the whole result. + if not catalog.arguments(catalog.part_tool.inputSchema,v) then return fail(-32602,'Tool arguments rejected') end + local pages; for _,r in ipairs(s.results) do if r.n==v.result then pages=r.pages end end + local text=pages and pages[v.part] and catalog.part(pages,v.result,v.part) + result={isError=not text,content=json.array({{type='text',text=text or (pages and ('Result %d has parts 1 to %d.'):format(v.result,#pages) + or 'That result is no longer held: only the 8 most recent large results of the running session are kept. Run the original tool again, asking for less output if it can.')}})} + else + if not tool then return fail(-32602,'Tool unavailable') end + local ok,why=catalog.arguments(tool.schema,v); if not ok then return fail(-32602,why or 'Tool arguments rejected') end + if not s.prompting or s.cancelling then return fail(-32000,'No human turn pending') end + if s.call then return fail(-32000,'Another Panto tool call is pending') end + s.seq=s.seq+1; s.call={id=q.id,tag=s.dir:match('[^/]+$')..'-'..s.seq,name=tool.name,input=json.encode(v)}; s.notify(); return + end else return fail(-32601,'Unsupported method') end send(c,{id=q.id,result=result}) end +-- Text over agy's MCP result cap goes out in parts; see catalog.result_bytes. +local function paged(s,parts) + local texts,out={},json.array({}) + for _,v in ipairs(parts) do if v.type=='text' then texts[#texts+1]=v.text else out[#out+1]=v end end + local text=table.concat(texts,'\n\n'); if #text<=catalog.result_bytes then return parts end + -- Clock-based so a number quoted by a natively resumed session never names a newer relay's result. + local pages,n=catalog.pages(text),math.max(os.time(),(s.results[#s.results] or {n=0}).n+1) + s.results[#s.results+1]={n=n,pages=pages}; if #s.results>8 then table.remove(s.results,1) end + table.insert(out,1,{type='text',text=catalog.part(pages,n,1)}); return out +end -- ACP tool notifications are observations, NOT Panto tool invocations. Keep -- a small live component for the current/last prompt; never enter tool dispatch. local function native_activity(s) @@ -74,7 +96,8 @@ local function native_activity(s) if not row then local name=u.name or (type(u.title)=='string' and u.title:match('^Run ([%w_.-]+)$')) if type(name)~='string' or #name>96 or not name:match('^[%w_.-]+$') then return end - if s.by[name:match('^mcp_pantograph_(.+)$') or false] then return end + local relayed=name:match('^mcp_pantograph_(.+)$') + if relayed and (s.by[relayed] or relayed==catalog.part_tool.name) then return end row={id=id,name=name,status='reported'}; rows[#rows+1]=row if #rows>6 then table.remove(rows,1) end end @@ -95,7 +118,7 @@ local function native_activity(s) end local function start(req,by,list,signature) local dir=assert(uv.fs_mkdtemp('/tmp/panto-antigravity-XXXXXX')) - local s={sid=req.context,dir=dir,server=uv.new_pipe(false),by=by,list=list,seq=0,notify=req.notify}; active=s + local s={sid=req.context,dir=dir,server=uv.new_pipe(false),by=by,list=list,seq=0,results={},notify=req.notify}; active=s s.fail=function(msg) if active~=s then return end s.error=tostring(msg):gsub('[%c]',' '):sub(1,512) @@ -214,7 +237,7 @@ end,activate=function() elseif v.type=='media' and v.media_type:match('^image/') then parts[#parts+1]={type='image',mimeType=v.media_type,data=v.data} else failed=true; parts[#parts+1]={type='text',text='Unsupported tool result content'} end end - send(s.peer,{id=awaiting.id,result={isError=failed,content=parts}}); s.call=nil + send(s.peer,{id=awaiting.id,result={isError=failed,content=paged(s,parts)}}); s.call=nil end s.issued=nil; s.settle() elseif s and s.pending then |
