aboutsummaryrefslogtreecommitdiff
path: root/src/integration/assets/opencode/herdr-agent-state.js
diff options
context:
space:
mode:
authorCan Celik <ogulcancelik@gmail.com>2026-04-01 21:00:09 +0300
committerCan Celik <ogulcancelik@gmail.com>2026-04-01 23:05:34 +0300
commit28fb23cdaf4fce03ed6dbfcb4bb13be324b181ac (patch)
tree0f33866cb872917d049bc8a38b857b5b8b0dd2b7 /src/integration/assets/opencode/herdr-agent-state.js
parentca4270b31fe93c180f7321cb4006cb5e7307d889 (diff)
feat: add claude, codex, and opencode integrations
Diffstat (limited to 'src/integration/assets/opencode/herdr-agent-state.js')
-rw-r--r--src/integration/assets/opencode/herdr-agent-state.js99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/integration/assets/opencode/herdr-agent-state.js b/src/integration/assets/opencode/herdr-agent-state.js
new file mode 100644
index 00000000..8dbaa0d8
--- /dev/null
+++ b/src/integration/assets/opencode/herdr-agent-state.js
@@ -0,0 +1,99 @@
+import net from "node:net";
+
+const SOURCE = "herdr:opencode";
+
+function reportState(action) {
+ const paneId = process.env.HERDR_PANE_ID;
+ const socketPath = process.env.HERDR_SOCKET_PATH;
+
+ if (!paneId || !socketPath) {
+ return Promise.resolve();
+ }
+
+ const requestId = `${SOURCE}:${Date.now()}:${Math.floor(Math.random() * 1_000_000)
+ .toString()
+ .padStart(6, "0")}`;
+ const request = {
+ id: requestId,
+ method: action === "release" ? "pane.release_agent" : "pane.report_agent",
+ params:
+ action === "release"
+ ? {
+ pane_id: paneId,
+ source: SOURCE,
+ agent: "opencode",
+ }
+ : {
+ pane_id: paneId,
+ source: SOURCE,
+ agent: "opencode",
+ state: action,
+ },
+ };
+
+ return new Promise((resolve) => {
+ const client = net.createConnection(socketPath, () => {
+ client.write(`${JSON.stringify(request)}\n`);
+ });
+
+ const finish = () => {
+ client.destroy();
+ resolve();
+ };
+
+ client.setTimeout(500, finish);
+ client.on("data", finish);
+ client.on("error", finish);
+ client.on("end", finish);
+ client.on("close", resolve);
+ });
+}
+
+export const HerdrAgentStatePlugin = async () => {
+ if (
+ process.env.HERDR_ENV !== "1" ||
+ !process.env.HERDR_SOCKET_PATH ||
+ !process.env.HERDR_PANE_ID
+ ) {
+ return {};
+ }
+
+ return {
+ event: async ({ event }) => {
+ const type = event?.type;
+ const properties = event?.properties ?? {};
+
+ switch (type) {
+ case "permission.asked":
+ await reportState("blocked");
+ break;
+ case "permission.replied": {
+ const reply = properties.reply ?? properties.response;
+ if (reply === "reject") {
+ await reportState("idle");
+ } else if (reply === "once" || reply === "always") {
+ await reportState("working");
+ }
+ break;
+ }
+ case "session.status": {
+ const status =
+ typeof properties.status === "string"
+ ? properties.status
+ : properties.status?.type;
+ if (status === "busy" || status === "retry") {
+ await reportState("working");
+ } else if (status === "idle") {
+ await reportState("idle");
+ }
+ break;
+ }
+ case "session.idle":
+ await reportState("idle");
+ break;
+ default:
+ break;
+ }
+ },
+ };
+};