Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions hooks/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -30,10 +31,16 @@ export function buildCaptureHandler(
event: Record<string, unknown>,
ctx: Record<string, unknown>,
) => {
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
}
Expand Down
6 changes: 6 additions & 0 deletions hooks/recall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -179,6 +180,11 @@ export function buildRecallHandler(
event: Record<string, unknown>,
ctx?: Record<string, unknown>,
) => {
const trigger = ctx?.trigger as string | undefined
if (!isInteractiveTrigger(trigger)) {
return
}

const rawPrompt = event.prompt as string | undefined
if (!rawPrompt || rawPrompt.length < 5) return

Expand Down
10 changes: 10 additions & 0 deletions hooks/trigger.ts
Original file line number Diff line number Diff line change
@@ -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)
}
Loading