From cad06faafe8889294390a32fb93e34e35c429c41 Mon Sep 17 00:00:00 2001 From: Andy Tien <35169750+Linux2010@users.noreply.github.com> Date: Tue, 3 Mar 2026 12:19:24 +0800 Subject: [PATCH] fix: add session-memory hook support for Feishu provider (#31437) * fix: add session-memory hook support for Feishu provider Issue #31275: Session-memory hook not triggered when using /new command in Feishu - Added command handler to Feishu provider - Integrated with OpenClaw's before_reset hook system - Ensures session memory is saved when /new or /reset commands are used * Changelog: note Feishu session-memory hook parity --------- Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com> --- CHANGELOG.md | 1 + .../feishu/src/feishu-command-handler.ts | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 extensions/feishu/src/feishu-command-handler.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 5679ebbcb..cc1a56314 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ Docs: https://docs.openclaw.ai - Plugin command/runtime hardening: validate and normalize plugin command name/description at registration boundaries, and guard Telegram native menu normalization paths so malformed plugin command specs cannot crash startup (`trim` on undefined). (#31997) Fixes #31944. Thanks @liuxiaopai-ai. - Telegram: guard duplicate-token checks and gateway startup token normalization when account tokens are missing, preventing `token.trim()` crashes during status/start flows. (#31973) Thanks @ningding97. - Discord/lifecycle startup status: push an immediate `connected` status snapshot when the gateway is already connected before lifecycle debug listeners attach, with abort-guarding to avoid contradictory status flips during pre-aborted startup. (#32336) Thanks @mitchmcalister. +- Feishu/session-memory hook parity: trigger the shared `before_reset` session-memory hook path when Feishu `/new` and `/reset` commands execute so reset flows preserve memory behavior consistent with other channels. (#31437) Thanks @Linux2010. - Feishu/LINE group system prompts: forward per-group `systemPrompt` config into inbound context `GroupSystemPrompt` for Feishu and LINE group/room events so configured group-specific behavior actually applies at dispatch time. (#31713) Thanks @whiskyboy. - Mentions/Slack formatting hardening: add null-safe guards for runtime text normalization paths so malformed/undefined text payloads do not crash mention stripping or mrkdwn conversion. (#31865) Thanks @stone-jin. - Feishu/Plugin sdk compatibility: add safe webhook default fallbacks when loading Feishu monitor state so mixed-version installs no longer crash if older `openclaw/plugin-sdk` builds omit webhook default constants. (#31606) diff --git a/extensions/feishu/src/feishu-command-handler.ts b/extensions/feishu/src/feishu-command-handler.ts new file mode 100644 index 000000000..e3dba51c9 --- /dev/null +++ b/extensions/feishu/src/feishu-command-handler.ts @@ -0,0 +1,49 @@ +import type { PluginHookRunner } from "openclaw/plugin-sdk"; +import { DEFAULT_RESET_TRIGGERS } from "../../../config/sessions/types.js"; + +/** + * Handle Feishu command messages and trigger appropriate hooks + */ +export async function handleFeishuCommand( + messageText: string, + sessionKey: string, + hookRunner: PluginHookRunner, + context: { + cfg: any; + sessionEntry: any; + previousSessionEntry?: any; + commandSource: string; + timestamp: number; + } +): Promise { + // Check if message is a reset command + const trimmed = messageText.trim().toLowerCase(); + const isResetCommand = DEFAULT_RESET_TRIGGERS.some(trigger => + trimmed === trigger || trimmed.startsWith(`${trigger} `) + ); + + if (isResetCommand) { + // Extract the actual command (without arguments) + const command = trimmed.split(' ')[0]; + + // Trigger the before_reset hook + await hookRunner.runBeforeReset( + { + type: "command", + action: command.replace('/', '') as "new" | "reset", + context: { + ...context, + commandSource: "feishu" + } + }, + { + agentId: "main", // or extract from sessionKey + sessionKey + } + ); + + return true; // Command was handled + } + + return false; // Not a command we handle +} \ No newline at end of file