From 274d4a6247f10c14cd1eca8fd0b3073d98eb80f0 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Sat, 3 Jan 2026 22:00:22 +0100 Subject: [PATCH] fix(hooks): fix ContextEventResult.messages type to AgentMessage[] - Was incorrectly typed as Message[] which caused filtered messages to be ignored - Context event filter in plan-mode hook should now properly remove stale [PLAN MODE ACTIVE] messages --- .../coding-agent/examples/hooks/plan-mode.ts | 18 +++++++----------- packages/coding-agent/src/core/hooks/types.ts | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/packages/coding-agent/examples/hooks/plan-mode.ts b/packages/coding-agent/examples/hooks/plan-mode.ts index d8901c11..848194d5 100644 --- a/packages/coding-agent/examples/hooks/plan-mode.ts +++ b/packages/coding-agent/examples/hooks/plan-mode.ts @@ -293,19 +293,15 @@ export default function planModeHook(pi: HookAPI) { // Filter out stale plan mode context messages from LLM context // This ensures the agent only sees the CURRENT state (plan mode on/off) - (pi as any).on("context", async (event: { messages: Array<{ role: string; content: unknown }> }) => { - // Remove any previous plan-mode-context or plan-execution-context messages - // They'll be re-injected with current state via before_agent_start + pi.on("context", async (event) => { + // Only filter when NOT in plan mode (i.e., when executing) + if (planModeEnabled) return; + + // Remove any previous plan-mode-context messages const filtered = event.messages.filter((m) => { if (m.role === "user" && Array.isArray(m.content)) { - // Check for our custom message types in user messages - const hasOldContext = (m.content as Array<{ type: string; text?: string }>).some( - (c) => - c.type === "text" && - c.text && - (c.text.includes("[PLAN MODE ACTIVE]") || - c.text.includes("[PLAN MODE DISABLED") || - c.text.includes("[EXECUTING PLAN]")), + const hasOldContext = m.content.some( + (c) => c.type === "text" && c.text.includes("[PLAN MODE ACTIVE]"), ); if (hasOldContext) return false; } diff --git a/packages/coding-agent/src/core/hooks/types.ts b/packages/coding-agent/src/core/hooks/types.ts index 8ddec584..6305872f 100644 --- a/packages/coding-agent/src/core/hooks/types.ts +++ b/packages/coding-agent/src/core/hooks/types.ts @@ -577,7 +577,7 @@ export type HookEvent = */ export interface ContextEventResult { /** Modified messages to send instead of the original */ - messages?: Message[]; + messages?: AgentMessage[]; } /**