an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions
HTML agent-harnessagent-orchestrationagentsai-agentsautonomous-agentsclaude-codecodexcoding-agentsdesktop-appdeveloper-toolselectrongemini-cliharnessharness-engineeringlocal-firstmemorymulti-agentopencodeorchestrationtypescript
fix(hooks): add typed hook event payload contract
hsien weiecbf6b1f8230
diff --git a/src/main/hooks.ts b/src/main/hooks.tsindex 0db1e667..f51dfd19 100644--- a/src/main/hooks.ts+++ b/src/main/hooks.ts@@ -18,6 +18,7 @@ import type { HarnessConfig } from './config';import type { ControlRegistry } from './control';import type { CircuitBreaker } from './breaker';import { estimateCostUsd } from './pricing';+import { validateHookEvent } from '../shared/hookEvents';interface HookPayload {hook_event_name?: string;@@ -326,7 +327,7 @@ export class HookServer {}private emit(agentId: string | undefined, event: string, p: HookPayload, blocked = false): void {- this.getWebContents()?.send('hive:hookEvent', {+ const payload = {agentId,event,tool: p.tool_name,@@ -334,6 +335,11 @@ export class HookServer {source: p.source,message: p.message,blocked- });+ };+ if (!validateHookEvent(payload)) {+ console.warn('[hive] rejected invalid hook event:', event);+ return;+ }+ this.getWebContents()?.send('hive:hookEvent', payload);}}diff --git a/src/preload/index.ts b/src/preload/index.tsindex 82605467..02b32d93 100644--- a/src/preload/index.ts+++ b/src/preload/index.ts@@ -10,6 +10,8 @@ import type { ToolStatus } from '../shared/toolCatalog';export type { ToolStatus } from '../shared/toolCatalog';import type { HeroPayload } from '../shared/heroPayload';export type { HeroPayload } from '../shared/heroPayload';+import type { HookEvent } from '../shared/hookEvents';+export type { HookEvent } from '../shared/hookEvents';import type { LocalSkill, CatalogSkill } from '../main/skills';export type { LocalSkill, CatalogSkill } from '../main/skills';import type {@@ -845,9 +847,9 @@ const api = {ipcRenderer.invoke('hive:send', msg, from),onHiveHookEvent: (- cb: (e: { agentId?: string; event: string; tool?: string; notificationType?: string; source?: string; message?: string; blocked?: boolean }) => void+ cb: (e: HookEvent) => void): (() => void) => {- const listener = (_e: IpcRendererEvent, payload: { agentId?: string; event: string; tool?: string; notificationType?: string; source?: string; message?: string; blocked?: boolean }) => cb(payload);+ const listener = (_e: IpcRendererEvent, payload: HookEvent) => cb(payload);ipcRenderer.on('hive:hookEvent', listener);return () => ipcRenderer.removeListener('hive:hookEvent', listener);},diff --git a/src/shared/hookEvents.ts b/src/shared/hookEvents.tsnew file mode 100644index 00000000..47020b87--- /dev/null+++ b/src/shared/hookEvents.ts@@ -0,0 +1,30 @@+/** Renderer-facing hook event shared across the Electron IPC boundary. */+export interface HookEvent {+ agentId?: string;+ event: string;+ tool?: string;+ notificationType?: string;+ source?: string;+ message?: string;+ blocked?: boolean;+}++const OPTIONAL_STRING_FIELDS = ['tool', 'notificationType', 'source', 'message'] as const;++/** Validate an untrusted payload before it crosses the Electron IPC boundary. */+export function validateHookEvent(value: unknown): value is HookEvent {+ if (typeof value !== 'object' || value === null || Array.isArray(value)) return false;++ const candidate = value as Record<string, unknown>;+ if (typeof candidate.event !== 'string' || candidate.event.length === 0) return false;+ if (+ candidate.agentId !== undefined &&+ (typeof candidate.agentId !== 'string' || candidate.agentId.length === 0)+ ) return false;++ for (const field of OPTIONAL_STRING_FIELDS) {+ if (candidate[field] !== undefined && typeof candidate[field] !== 'string') return false;+ }++ return candidate.blocked === undefined || typeof candidate.blocked === 'boolean';+}