aboutsummaryrefslogtreecommitdiff
path: root/src/integration
diff options
context:
space:
mode:
Diffstat (limited to 'src/integration')
-rw-r--r--src/integration/assets/opencode/herdr-agent-state.js31
-rw-r--r--src/integration/mod.rs2
2 files changed, 29 insertions, 4 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;
diff --git a/src/integration/mod.rs b/src/integration/mod.rs
index d08ad32e..06561e3d 100644
--- a/src/integration/mod.rs
+++ b/src/integration/mod.rs
@@ -135,7 +135,7 @@ const DROID_REMOVED_LIFECYCLE_HOOK_EVENTS: [(&str, &str); 9] = [
];
const OPENCODE_PLUGIN_INSTALL_NAME: &str = "herdr-agent-state.js";
const OPENCODE_PLUGIN_ASSET: &str = include_str!("assets/opencode/herdr-agent-state.js");
-const OPENCODE_INTEGRATION_VERSION: u32 = 6;
+const OPENCODE_INTEGRATION_VERSION: u32 = 7;
const KILO_PLUGIN_INSTALL_NAME: &str = "herdr-agent-state.js";
const KILO_PLUGIN_ASSET: &str = include_str!("assets/kilo/herdr-agent-state.js");
const KILO_INTEGRATION_VERSION: u32 = 2;