fix: use configured endSymbols in injected prompt and exempt gateway keywords

- buildEndMarkerInstruction() replaces hardcoded END_MARKER_INSTRUCTION,
  dynamically using the resolved policy's endSymbols
- Instruction now explicitly exempts gateway keywords (NO_REPLY, HEARTBEAT_OK)
  from requiring end symbols
- Export resolvePolicy from rules.ts for reuse in before_prompt_build hook
This commit is contained in:
zhi
2026-02-27 15:16:06 +00:00
parent 75d659787c
commit 3749de981f
2 changed files with 13 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
import fs from "node:fs"; import fs from "node:fs";
import path from "node:path"; import path from "node:path";
import type { OpenClawPluginApi } from "openclaw/plugin-sdk"; import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
import { evaluateDecision, type ChannelPolicy, type Decision, type WhisperGateConfig } from "./rules.js"; import { evaluateDecision, resolvePolicy, type ChannelPolicy, type Decision, type WhisperGateConfig } from "./rules.js";
type DiscordControlAction = "channel-private-create" | "channel-private-update" | "member-list"; type DiscordControlAction = "channel-private-create" | "channel-private-update" | "member-list";
@@ -24,7 +24,10 @@ type DebugConfig = {
const sessionDecision = new Map<string, DecisionRecord>(); const sessionDecision = new Map<string, DecisionRecord>();
const MAX_SESSION_DECISIONS = 2000; const MAX_SESSION_DECISIONS = 2000;
const DECISION_TTL_MS = 5 * 60 * 1000; const DECISION_TTL_MS = 5 * 60 * 1000;
const END_MARKER_INSTRUCTION = "你的这次发言必须以🔚作为结尾。"; function buildEndMarkerInstruction(endSymbols: string[]): string {
const symbols = endSymbols.length > 0 ? endSymbols.join("") : "🔚";
return `你的这次发言必须以${symbols}作为结尾。除非你的回复是 gateway 关键词(如 NO_REPLY、HEARTBEAT_OK这些关键词不要加${symbols}`;
}
const policyState: PolicyState = { const policyState: PolicyState = {
filePath: "", filePath: "",
@@ -505,8 +508,14 @@ export default {
return; return;
} }
// Resolve end symbols from config/policy for dynamic instruction
const prompt = ((event as Record<string, unknown>).prompt as string) || "";
const derived = deriveDecisionInputFromPrompt(prompt, ctx.messageProvider);
const policy = resolvePolicy(live, derived.channelId, policyState.channelPolicies);
const instruction = buildEndMarkerInstruction(policy.endSymbols);
api.logger.info(`whispergate: prepend end marker instruction for session=${key}, reason=${rec.decision.reason}`); api.logger.info(`whispergate: prepend end marker instruction for session=${key}, reason=${rec.decision.reason}`);
return { prependContext: END_MARKER_INSTRUCTION }; return { prependContext: instruction };
}); });
}, },
}; };

View File

@@ -46,7 +46,7 @@ function getLastChar(input: string): string {
return t.length ? t[t.length - 1] : ""; return t.length ? t[t.length - 1] : "";
} }
function resolvePolicy(config: WhisperGateConfig, channelId?: string, channelPolicies?: Record<string, ChannelPolicy>) { export function resolvePolicy(config: WhisperGateConfig, channelId?: string, channelPolicies?: Record<string, ChannelPolicy>) {
const globalMode = config.listMode || "human-list"; const globalMode = config.listMode || "human-list";
const globalHuman = config.humanList || config.bypassUserIds || []; const globalHuman = config.humanList || config.bypassUserIds || [];
const globalAgent = config.agentList || []; const globalAgent = config.agentList || [];