/** * Fail-closed delivery gate for the external-content security envelope. The * envelope (`wrapExternalContent`) is prompt armor — it must never reach a * user, yet a model that echoes its prompt can hand the whole armor block to a * callback (live Discord leak 2026-08-02, tj-2dc95f75456876). Detection alone * proved insufficient: the tripwire reported the leak after the message * shipped. This guard runs at every pre-send seam core owns — the visible * callback wrap in `services/message.ts`, the mandatory * `outgoing_before_deliver` pipeline phase, and `sendMessageToTarget` — and * BLOCKS the send, replacing the text with a short honest notice while * `runtime.reportError` carries the clamped original for observability. The * MESSAGE_SENT tripwire in basic-capabilities stays as secondary, * report-only coverage for deliveries that bypass these seams. * * Blocking is deliberately variant-tolerant (`containsExternalEnvelopeMaterial`: * NFKC-folded, case-insensitive, partial/quoted/reference echoes): a user * asking about the marker syntax loses that one reply to the notice, which is * the accepted cost of never shipping armor. * * Streaming coverage: the message-service chunk seam holds a per-stream latch * ({@link createOutboundEnvelopeStreamLatch}) that stops chunk forwarding * (user stream callback + `model_stream_chunk` hook re-emission) once the * accumulated text reads as envelope material. KNOWN-OPEN seams: * chunks forwarded before the needle completes are already delivered (a * stream cannot be recalled), and `useModel`'s own `model_stream_chunk` * emission (`source: "use_model"`, runtime.ts) fires upstream of the latch * for direct-streaming callers outside the message service. The MESSAGE_SENT * tripwire in basic-capabilities is the report-only coverage for whatever * escapes those edges. */ import type { Media } from "../types/primitives.js"; import type { IAgentRuntime } from "../types/runtime.js"; /** * What a blocked delivery says instead of the leaked envelope. Honest about * what happened without echoing any of the blocked material. */ export declare const ENVELOPE_LEAK_NOTICE = "i caught an internal formatting leak and stopped it \u2014 try again."; /** * Report a blocked envelope delivery. One shape for every seam so the error * ring is greppable by scope and the preview never re-broadcasts a multi-KB * envelope. */ export declare function reportOutboundEnvelopeBlock(runtime: Pick, blockedText: string, seam: string): void; /** * Gate outbound text at a delivery seam. Clean text passes through untouched; * text carrying envelope material is replaced with {@link ENVELOPE_LEAK_NOTICE} * and reported. Never throws (reportError is the no-throw diagnostic * boundary), so a detected leak degrades to the notice instead of killing the * turn. */ export declare function guardOutboundEnvelopeText(runtime: Pick, text: string, seam: string): string; /** * Gate attachment text at a delivery seam. A callback can carry text only in * `attachment.text` (for example a voice attachment) while its top-level * `text` is empty — a text-only guard waves the armor through inside the * attachment. Attachments whose text carries * envelope material are dropped (there is no honest partial form of a leaked * attachment) and each drop is reported; clean input returns the same array * reference so callers can cheaply detect "nothing blocked". */ export declare function guardOutboundEnvelopeAttachments(runtime: Pick, attachments: Media[], seam: string): Media[]; /** * Per-stream latch for chunked deliveries. Returns a predicate over the * accumulated stream text: false while the stream is clean, true from the * moment the accumulation reads as envelope material — reported once on the * trip, then latched so the caller can stop forwarding every subsequent * chunk. Latching (rather than re-testing) matters because the envelope * needle, once present, stays present in the accumulation, and a per-chunk * re-report would flood the error ring token by token. */ export declare function createOutboundEnvelopeStreamLatch(runtime: Pick, seam: string): (accumulated: string) => boolean;