aboutsummaryrefslogtreecommitdiff
path: root/src/integration/assets/opencode/herdr-agent-state.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/integration/assets/opencode/herdr-agent-state.js')
-rw-r--r--src/integration/assets/opencode/herdr-agent-state.js31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/integration/assets/opencode/herdr-agent-state.js b/src/integration/assets/opencode/herdr-agent-state.js
index 6836227b..a46d1d88 100644
--- a/src/integration/assets/opencode/herdr-agent-state.js
+++ b/src/integration/assets/opencode/herdr-agent-state.js
@@ -2,7 +2,7 @@
// managed by herdr; reinstalling or updating the integration overwrites this file.
// add custom hooks/plugins beside this file instead of editing it.
// HERDR_INTEGRATION_ID=opencode
-// HERDR_INTEGRATION_VERSION=6
+// HERDR_INTEGRATION_VERSION=7
import net from "node:net";
@@ -10,6 +10,11 @@ const SOURCE = "herdr:opencode";
const AGENT = "opencode";
let reportSeq = Date.now() * 1000;
+// Subagent (task tool) sessions carry a parentID; the main agent session does
+// not. Their lifecycle events would otherwise clobber the pane's real state, so
+// learn child session ids from session.created/updated and drop their reports.
+const childSessions = new Set();
+
function nextReportSeq() {
reportSeq += 1;
return reportSeq;
@@ -81,11 +86,15 @@ function request(method, params) {
});
}
-function reportSession(sessionID) {
+function reportSession(sessionID, sessionStartSource) {
if (!sessionID) {
return Promise.resolve();
}
- return request("pane.report_agent_session", { agent_session_id: sessionID });
+ const params = { agent_session_id: sessionID };
+ if (sessionStartSource) {
+ params.session_start_source = sessionStartSource;
+ }
+ return request("pane.report_agent_session", params);
}
function reportState(state, sessionID) {
@@ -107,6 +116,9 @@ export const HerdrAgentStatePlugin = async () => {
return {
"chat.message": async ({ sessionID }) => {
+ if (sessionID && childSessions.has(sessionID)) {
+ return;
+ }
await reportState("working", sessionID);
},
event: async ({ event }) => {
@@ -114,8 +126,21 @@ export const HerdrAgentStatePlugin = async () => {
const properties = event?.properties ?? {};
const sessionID = sessionIDFromProperties(properties);
+ const info = properties.info;
+ if (info?.id && info.parentID) {
+ childSessions.add(info.id);
+ }
+ if (sessionID && childSessions.has(sessionID)) {
+ return;
+ }
+
switch (type) {
case "session.created":
+ // A root session.created is a genuine new-session start (subagent
+ // creates are dropped above). Signal it so herdr replaces the pane's
+ // prior session id instead of treating the change as cross-talk.
+ await reportSession(sessionID, "new");
+ break;
case "session.updated":
await reportSession(sessionID);
break;