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:
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
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";
|
||||
|
||||
@@ -24,7 +24,10 @@ type DebugConfig = {
|
||||
const sessionDecision = new Map<string, DecisionRecord>();
|
||||
const MAX_SESSION_DECISIONS = 2000;
|
||||
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 = {
|
||||
filePath: "",
|
||||
@@ -505,8 +508,14 @@ export default {
|
||||
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}`);
|
||||
return { prependContext: END_MARKER_INSTRUCTION };
|
||||
return { prependContext: instruction };
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ function getLastChar(input: string): string {
|
||||
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 globalHuman = config.humanList || config.bypassUserIds || [];
|
||||
const globalAgent = config.agentList || [];
|
||||
|
||||
Reference in New Issue
Block a user