summaryrefslogtreecommitdiff
path: root/panto-herdr/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'panto-herdr/init.lua')
-rw-r--r--panto-herdr/init.lua35
1 files changed, 27 insertions, 8 deletions
diff --git a/panto-herdr/init.lua b/panto-herdr/init.lua
index dffef51..cc0b527 100644
--- a/panto-herdr/init.lua
+++ b/panto-herdr/init.lua
@@ -11,10 +11,22 @@ return {
local panto = require("panto")
local uv = require("luv")
- local seq = 0
+ -- Herdr orders reports by source and sequence. Seed each process from
+ -- wall time so a restarted panto cannot be shadowed by the prior
+ -- process's larger sequence numbers.
+ local seq = os.time() * 1000000
local last_state
local last_status
+ local function spawn(args)
+ local handle
+ pcall(function()
+ handle = uv.spawn("herdr", { args = args, stdio = { nil, nil, nil } }, function()
+ if handle then handle:close() end
+ end)
+ end)
+ end
+
local function report(state, status)
if state == last_state and status == last_status then return end
last_state, last_status = state, status
@@ -28,19 +40,25 @@ return {
"--seq", tostring(seq),
}
if status then
- args[#args + 1] = "--custom-status"
+ args[#args + 1] = "--message"
args[#args + 1] = status
end
- local handle
- pcall(function()
- handle = uv.spawn("herdr", { args = args, stdio = { nil, nil, nil } }, function()
- if handle then handle:close() end
- end)
- end)
+ spawn(args)
+ end
+
+ local function release()
+ seq = seq + 1
+ spawn({
+ "pane", "release-agent", pane_id,
+ "--source", "panto:extension",
+ "--agent", "panto",
+ "--seq", tostring(seq),
+ })
end
panto.ext.on("session_start", function() report("idle") end)
+ panto.ext.on("session_ready", function() report("idle") end)
panto.ext.on("user_message", function() report("working", "thinking") end)
panto.ext.on("thinking", function() report("working", "thinking") end)
panto.ext.on("compaction", function() report("working", "compacting") end)
@@ -49,5 +67,6 @@ return {
end)
panto.ext.on("assistant_text", function() report("working", "responding") end)
panto.ext.on("assistant_text_complete", function() report("idle") end)
+ panto.ext.on("session_end", release)
end,
}