@@ -130,24 +130,17 @@ export function stripEnvelopeMetadata(text: string): string {
130130 // inline content on the same line (e.g. "[Subagent Task] Reply with brief ack.").
131131 // Also matches when the wrapper prefix is on its own line ("]\n" = no content after ]).
132132 const WRAPPER_LINE_RE = / ^ \[ (?: S u b a g e n t C o n t e x t | S u b a g e n t T a s k ) \] (?: \s | $ | \n ) ? / i;
133- const BOILERPLATE_RE = / ^ (?: R e s u l t s a u t o - a n n o u n c e t o y o u r r e q u e s t e r \. ? | d o n o t b u s y - p o l l f o r s t a t u s \. ? | R e p l y w i t h a b r i e f a c k n o w l e d g m e n t o n l y \. ? | D o n o t u s e a n y m e m o r y t o o l s \. ? ) $ / i ;
133+ const BOILERPLATE_RE = / ^ (?: R e s u l t s a u t o - a n n o u n c e t o y o u r r e q u e s t e r \. ? | d o n o t b u s y - p o l l f o r s t a t u s \. ? | R e p l y w i t h a b r i e f a c k n o w l e d g m e n t o n l y \. ? | D o n o t u s e a n y m e m o r y t o o l s \. ? ) $ / im ;
134134 const SUBAGENT_RUNNING_RE = / Y o u a r e r u n n i n g a s a s u b a g e n t \b / i;
135135
136136 const originalLines = text . split ( "\n" ) ;
137137
138- // Pre-scan: determine if there are leading wrappers AND actual user content.
139- // Used to decide whether to strip boilerplate in the leading zone.
138+ // Pre-scan: determine if there are leading wrappers.
139+ // Needed to decide whether boilerplate in the leading zone should be stripped
140+ // (boilerplate without a wrapper prefix is preserved — it may be legitimate user text).
140141 const hasLeadingWrapper = originalLines . some ( ( rawLine ) =>
141142 WRAPPER_LINE_RE . test ( rawLine . trim ( ) )
142143 ) ;
143- const hasActualUserContent = originalLines . some ( ( rawLine ) => {
144- const trimmed = rawLine . trim ( ) ;
145- return (
146- trimmed !== "" &&
147- ! WRAPPER_LINE_RE . test ( trimmed ) &&
148- ! BOILERPLATE_RE . test ( trimmed )
149- ) ;
150- } ) ;
151144
152145 // Single-pass state machine: find leading zone end and build result simultaneously.
153146 // Key: "You are running as a subagent..." on its own line AFTER a wrapper prefix
@@ -165,23 +158,22 @@ export function stripEnvelopeMetadata(text: string): string {
165158
166159 if ( isWrapper ) {
167160 prevWasWrapper = true ;
168- stillInLeadingZone = true ;
169161 result . push ( "" ) ; // strip wrapper
170162 continue ;
171163 }
172164
173165 if ( stillInLeadingZone ) {
174166 if ( isBoilerplate ) {
175- // Boilerplate in leading zone — strip if there are leading wrappers + user content
176- prevWasWrapper = false ;
177- result . push ( hasLeadingWrapper && hasActualUserContent ? "" : rawLine ) ;
167+ // Boilerplate in leading zone — strip only when there was a wrapper prefix.
168+ // This preserves standalone boilerplate text that happens to match the
169+ // boilerplate pattern but has no wrapper context.
170+ result . push ( hasLeadingWrapper ? "" : rawLine ) ;
178171 continue ;
179172 }
180173
181174 if ( isSubagentContent ) {
182175 // Multiline wrapper: "You are running as a subagent..." on its own line
183- // after a wrapper prefix — strip it
184- prevWasWrapper = false ;
176+ // after a wrapper prefix — strip it; keep prevWasWrapper true
185177 result . push ( "" ) ; // strip
186178 continue ;
187179 }
0 commit comments