diff --git a/hooks/capture.ts b/hooks/capture.ts index ea6d63f..7db96a8 100644 --- a/hooks/capture.ts +++ b/hooks/capture.ts @@ -2,6 +2,7 @@ import type { SupermemoryClient } from "../client.ts" import type { SupermemoryConfig } from "../config.ts" import { log } from "../logger.ts" import { buildDocumentId, stripInboundMetadata } from "../memory.ts" +import { isInteractiveTrigger } from "./trigger.ts" const SKIPPED_PROVIDERS = ["exec-event", "cron-event", "heartbeat"] @@ -30,10 +31,16 @@ export function buildCaptureHandler( event: Record, ctx: Record, ) => { + const trigger = ctx.trigger as string | undefined + if (!isInteractiveTrigger(trigger)) { + return + } + log.info( `agent_end fired: provider="${ctx.messageProvider}" success=${event.success}`, ) const provider = ctx.messageProvider as string + if (SKIPPED_PROVIDERS.includes(provider)) { return } diff --git a/hooks/recall.ts b/hooks/recall.ts index d6d80c8..2a16fae 100644 --- a/hooks/recall.ts +++ b/hooks/recall.ts @@ -2,6 +2,7 @@ import type { ProfileSearchResult, SupermemoryClient } from "../client.ts" import type { SupermemoryConfig } from "../config.ts" import { log } from "../logger.ts" import { stripInboundMetadata } from "../memory.ts" +import { isInteractiveTrigger } from "./trigger.ts" function formatRelativeTime(isoTimestamp: string): string { try { @@ -179,6 +180,11 @@ export function buildRecallHandler( event: Record, ctx?: Record, ) => { + const trigger = ctx?.trigger as string | undefined + if (!isInteractiveTrigger(trigger)) { + return + } + const rawPrompt = event.prompt as string | undefined if (!rawPrompt || rawPrompt.length < 5) return diff --git a/hooks/trigger.ts b/hooks/trigger.ts new file mode 100644 index 0000000..19e726e --- /dev/null +++ b/hooks/trigger.ts @@ -0,0 +1,10 @@ +const INTERACTIVE_TRIGGERS = new Set(["user", "manual"]) + +export function isInteractiveTrigger(trigger: string | undefined): boolean { + // Keep this allowlist in sync with OpenClaw's agent trigger values. + // "user" and "manual" are interactive; automated triggers such as + // "heartbeat", "cron", "memory", and "overflow" should skip memory hooks. + // Undefined preserves legacy behavior for OpenClaw versions that do not + // provide ctx.trigger yet. + return !trigger || INTERACTIVE_TRIGGERS.has(trigger) +}