/** * Prompt-injection scanner for persistent memory block writes. * * Persistent blocks get injected into the system prompt verbatim every * session. An attacker who can persuade the agent to call * `memory_block({action:'add', content: 'ignore previous instructions...'})` * effectively rewrites the system prompt for all future sessions of * that user. The scanner blocks the most common shapes. * * Pattern source: aligned with hermes-agent `tools/memory_tool.py` * `_MEMORY_THREAT_PATTERNS`, simplified to the highest-signal subset. * The `(?:\\w+\\s+)*` between key tokens prevents trivial bypass via * filler words ("ignore all PRIOR instructions" matches "ignore prior * instructions" matches "ignore the previous given instructions"). * * Failure mode: false positives cost the user a write attempt — the * tool returns a structured error and the agent can retry with * different wording. False negatives let through a real injection, so * we err on the side of catching more. */ export interface SafetyScanResult { safe: boolean; /** When unsafe: the id of the matched pattern. */ matchedPattern?: string; /** When unsafe: the substring of the input that triggered the match. */ matchedText?: string; } /** * Scan a candidate write for prompt-injection patterns. Returns * `{ safe: true }` if no patterns matched, or `{ safe: false, matchedPattern, matchedText }`. */ export declare function scanMemoryWrite(content: string): SafetyScanResult;