Files
openclaw/src/auto-reply/send-policy.ts
HansY 3b1f8e3461 fix: strip inbound metadata before slash command detection (#58674)
Slash commands like /model and /new were silently ignored when the inbound
message body included metadata prefix blocks (Conversation info, Sender info,
timestamps) injected by buildInboundUserContextPrefix. The command detection
functions (hasControlCommand, isControlCommandMessage, parseSendPolicyCommand)
now call stripInboundMetadata before normalizeCommandBody so embedded slash
commands are correctly recognized.
2026-04-01 10:17:20 +01:00

47 lines
1.3 KiB
TypeScript

import { normalizeCommandBody } from "./commands-registry.js";
import { stripInboundMetadata } from "./reply/strip-inbound-meta.js";
export type SendPolicyOverride = "allow" | "deny";
export function normalizeSendPolicyOverride(raw?: string | null): SendPolicyOverride | undefined {
const value = raw?.trim().toLowerCase();
if (!value) {
return undefined;
}
if (value === "allow" || value === "on") {
return "allow";
}
if (value === "deny" || value === "off") {
return "deny";
}
return undefined;
}
export function parseSendPolicyCommand(raw?: string): {
hasCommand: boolean;
mode?: SendPolicyOverride | "inherit";
} {
if (!raw) {
return { hasCommand: false };
}
const trimmed = raw.trim();
if (!trimmed) {
return { hasCommand: false };
}
const stripped = stripInboundMetadata(trimmed);
const normalized = normalizeCommandBody(stripped);
const match = normalized.match(/^\/send(?:\s+([a-zA-Z]+))?\s*$/i);
if (!match) {
return { hasCommand: false };
}
const token = match[1]?.trim().toLowerCase();
if (!token) {
return { hasCommand: true };
}
if (token === "inherit" || token === "default" || token === "reset") {
return { hasCommand: true, mode: "inherit" };
}
const mode = normalizeSendPolicyOverride(token);
return { hasCommand: true, mode };
}