summaryrefslogtreecommitdiff
path: root/acp.lua
diff options
context:
space:
mode:
Diffstat (limited to 'acp.lua')
-rw-r--r--acp.lua32
1 files changed, 26 insertions, 6 deletions
diff --git a/acp.lua b/acp.lua
index f401a70..bf3919d 100644
--- a/acp.lua
+++ b/acp.lua
@@ -177,6 +177,28 @@ function M.usage(u)
if i+o==t and r+w<=i then i=i-r-w elseif i+o+r+w~=t then return end
return {input=i,output=o,cache_read=r,cache_write=w,reasoning=h}
end
+-- agy 1.5.22 keeps only the first ~191 KB of a user message, including text
+-- split across content or resource blocks. systemPrompt.append has no such cap
+-- and persists across session/resume, so an oversized reseed carries the older
+-- history there. Returns that head and the newest tail of at most `room` bytes,
+-- cut before a transcript entry when one starts in the tail's first half and
+-- never inside a UTF-8 character. head..tail == text.
+M.message_bytes = 160000
+function M.history_split(text, room)
+ if room >= #text then return '', text end
+ if room <= 0 then return text, '' end
+ local at = #text - room + 1
+ local entry = text:find('\n\n[', math.max(at - 2, 1), true)
+ if entry and entry + 2 - at <= room // 2 then at = entry + 2
+ else while (text:byte(at) or 0) & 0xC0 == 0x80 do at = at + 1 end end
+ return text:sub(1, at - 1), text:sub(at)
+end
+local function add_usage(total, u)
+ if not u then return total end
+ if not total then return u end
+ for k, v in pairs(u) do total[k] = total[k] + v end
+ return total
+end
function M.launch(s, first, resume_id)
local cancel_check
local child, pid, stdin, stdout, waiting, timer, serial=nil,nil,nil,nil,nil,uv.new_timer(),0
@@ -280,10 +302,7 @@ function M.launch(s, first, resume_id)
end
local reason=({end_turn='end_turn',max_tokens='max_tokens'})[r.stopReason]
assert(reason,'Turn stopped: '..tostring(r.stopReason))
- local usage=M.usage(r.usage)
- if steer_usage then
- if usage then for k,v in pairs(steer_usage) do usage[k]=usage[k]+v end else usage=steer_usage end
- end
+ local usage=add_usage(M.usage(r.usage),steer_usage)
s.prompting=false; s.complete(last_steer and last_steer.reason or reason,usage); steer_usage,last_steer=nil,nil
end
s.submit=function(text) step(coroutine.create(turn),text) end
@@ -301,9 +320,10 @@ function M.launch(s, first, resume_id)
assert((caps.sessionCapabilities or {}).resume,'ACP resume unavailable'); params.sessionId=resume_id
session=call('session/resume',params); assert(not session.sessionId or session.sessionId==resume_id,'Wrong resumed session'); s.session=resume_id
else
- if s.instructions~='' then
+ local append=s.instructions..(s.record or '')
+ if append~='' then
assert(((((caps._meta or {}).antigravity or {}).systemPrompt or {}).append)==true,'Rig instruction append unavailable')
- params._meta.antigravity={systemPrompt={append=s.instructions}}
+ params._meta.antigravity={systemPrompt={append=append}}
end
session=call('session/new',params); assert(type(session.sessionId)=='string' and #session.sessionId>0,'Missing session ID'); s.session=session.sessionId
end