import { spawn } from "node:child_process";
const HOOK_PATH = {{HOOK_PATH_JSON}};
const ALLOW = ["runId", "sessionId", "sessionKey", "reason", "messageCount", "success"];
function forward(type, ev, ctx) {
try {
const payload = { type };
for (const k of ALLOW) {
const v = ctx && ctx[k] !== undefined ? ctx[k] : ev && ev[k];
if (v !== undefined) payload[k] = v;
}
payload._pid = process.pid;
const proc = spawn(HOOK_PATH, ["--source", "openclaw"], {
stdio: ["pipe", "ignore", "ignore"],
detached: true,
});
proc.on("error", () => {});
proc.stdin.on("error", () => {});
proc.stdin.write(JSON.stringify(payload) + "\n");
proc.stdin.end();
proc.unref(); } catch (_) {
}
}
const HOOKS = [
"gateway_start",
"gateway_stop",
"session_start",
"session_end",
"before_agent_run",
"agent_end",
];
export default {
id: "pixtuoid",
name: "Pixtuoid",
register(api) {
for (const h of HOOKS) {
try {
api.on(h, (ev, ctx) => {
forward(h, ev, ctx);
return undefined;
});
} catch (_) {
}
}
},
};