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
This commit is contained in:
Helmut Januschka 2026-01-03 22:00:22 +01:00 committed by Mario Zechner
parent 650d8f2615
commit 274d4a6247
2 changed files with 8 additions and 12 deletions

View file

@ -293,19 +293,15 @@ export default function planModeHook(pi: HookAPI) {
// Filter out stale plan mode context messages from LLM context // Filter out stale plan mode context messages from LLM context
// This ensures the agent only sees the CURRENT state (plan mode on/off) // 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 }> }) => { pi.on("context", async (event) => {
// Remove any previous plan-mode-context or plan-execution-context messages // Only filter when NOT in plan mode (i.e., when executing)
// They'll be re-injected with current state via before_agent_start if (planModeEnabled) return;
// Remove any previous plan-mode-context messages
const filtered = event.messages.filter((m) => { const filtered = event.messages.filter((m) => {
if (m.role === "user" && Array.isArray(m.content)) { if (m.role === "user" && Array.isArray(m.content)) {
// Check for our custom message types in user messages const hasOldContext = m.content.some(
const hasOldContext = (m.content as Array<{ type: string; text?: string }>).some( (c) => c.type === "text" && c.text.includes("[PLAN MODE ACTIVE]"),
(c) =>
c.type === "text" &&
c.text &&
(c.text.includes("[PLAN MODE ACTIVE]") ||
c.text.includes("[PLAN MODE DISABLED") ||
c.text.includes("[EXECUTING PLAN]")),
); );
if (hasOldContext) return false; if (hasOldContext) return false;
} }

View file

@ -577,7 +577,7 @@ export type HookEvent =
*/ */
export interface ContextEventResult { export interface ContextEventResult {
/** Modified messages to send instead of the original */ /** Modified messages to send instead of the original */
messages?: Message[]; messages?: AgentMessage[];
} }
/** /**