fix: bypass DM sessions without metadata and make tool globally visible #4

Merged
hzhang merged 5 commits from fix/dm-bypass-and-tool-visibility into feat/whispergate-mvp 2026-02-27 15:30:12 +00:00
Showing only changes of commit 75d659787c - Show all commits

View File

@@ -25,8 +25,24 @@ export type Decision = {
reason: string; reason: string;
}; };
/**
* Strip trailing OpenClaw metadata blocks from the prompt to get the actual message content.
* The prompt format is: [prepend instruction]\n\n[message]\n\nConversation info (untrusted metadata):\n```json\n{...}\n```\n\nSender (untrusted metadata):\n```json\n{...}\n```
*/
function stripTrailingMetadata(input: string): string {
// Remove all trailing "XXX (untrusted metadata):\n```json\n...\n```" blocks
let text = input;
// eslint-disable-next-line no-constant-condition
while (true) {
const m = text.match(/\n*[A-Z][^\n]*\(untrusted metadata\):\s*```json\s*[\s\S]*?```\s*$/);
if (!m) break;
text = text.slice(0, text.length - m[0].length);
}
return text;
}
function getLastChar(input: string): string { function getLastChar(input: string): string {
const t = input.trim(); const t = stripTrailingMetadata(input).trim();
return t.length ? t[t.length - 1] : ""; return t.length ? t[t.length - 1] : "";
} }