@@ -38,23 +38,14 @@ function isInboundContextHeaderLine(line: string): boolean {
3838 return t . length > INBOUND_CONTEXT_MARKER . length && t . endsWith ( INBOUND_CONTEXT_MARKER ) ;
3939}
4040
41- // Pre-compiled fast-path regex — avoids line-by-line parse when no blocks present.
42- // Active-memory's bare Context: sentinel is valid only as a complete line.
43- const SENTINEL_SUBSTRING_ALTERNATIVES = [ INBOUND_CONTEXT_MARKER , ...MESSAGE_TOOL_DELIVERY_HINTS ]
44- . map ( ( sentinel ) => sentinel . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) )
45- . join ( "|" ) ;
46- const ACTIVE_MEMORY_HEADER_ESCAPED = ACTIVE_MEMORY_CONTEXT_HEADER . replace (
47- / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g,
48- "\\$&" ,
49- ) ;
50- const SENTINEL_FAST_RE = new RegExp (
51- `${ SENTINEL_SUBSTRING_ALTERNATIVES } |^[ \t]*${ ACTIVE_MEMORY_HEADER_ESCAPED } [ \t]*$` ,
52- "m" ,
53- ) ;
54-
5541/** Fast check for whether text contains any inbound metadata sentinel. */
5642export function hasInboundMetadataSentinel ( text : string ) : boolean {
57- return Boolean ( text && SENTINEL_FAST_RE . test ( text ) ) ;
43+ return (
44+ text . includes ( INBOUND_CONTEXT_MARKER ) ||
45+ MESSAGE_TOOL_DELIVERY_HINTS . some ( ( hint ) => text . includes ( hint ) ) ||
46+ // Active-memory's bare Context: sentinel is valid only as a complete line.
47+ ( text . includes ( ACTIVE_MEMORY_CONTEXT_HEADER ) && / ^ [ \t ] * C o n t e x t : [ \t ] * $ / m. test ( text ) )
48+ ) ;
5849}
5950
6051function isMessageToolDeliveryHintLine ( line : string ) : boolean {
@@ -212,7 +203,7 @@ export function stripInboundMetadata(text: string): string {
212203 }
213204
214205 const withoutTimestamp = text . replace ( LEADING_TIMESTAMP_PREFIX_RE , "" ) ;
215- if ( ! SENTINEL_FAST_RE . test ( withoutTimestamp ) ) {
206+ if ( ! hasInboundMetadataSentinel ( withoutTimestamp ) ) {
216207 return withoutTimestamp ;
217208 }
218209
@@ -282,7 +273,7 @@ export function stripInboundMetadata(text: string): string {
282273
283274/** Strips only leading inbound metadata blocks while preserving later user text. */
284275export function stripLeadingInboundMetadata ( text : string ) : string {
285- if ( ! text || ! SENTINEL_FAST_RE . test ( text ) ) {
276+ if ( ! hasInboundMetadataSentinel ( text ) ) {
286277 return text ;
287278 }
288279
0 commit comments