Skip to content

Commit 4e3af31

Browse files
committed
fix: stripEnvelopeMetadata - blank line, wrapper guard, SUBAGENT regex
- Must Fix 1: blank lines no longer exit leading zone (prevents boilerplate leak) - N2: isWrapper now gated on stillInLeadingZone (strips only in leading zone) - N4: SUBAGENT_RUNNING_RE anchored with ^ (prevents quoted/cited false-positive) - N3: hasLeadingWrapper pre-scan retained as safety guard (preserves standalone boilerplate protection) All 20 tests pass.
1 parent 36f0a5a commit 4e3af31

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/smart-extractor.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@ export function stripEnvelopeMetadata(text: string): string {
8080
// Also matches when the wrapper prefix is on its own line ("]\n" = no content after ]).
8181
const WRAPPER_LINE_RE = /^\[(?:Subagent Context|Subagent Task)\](?:\s|$|\n)?/i;
8282
const BOILERPLATE_RE = /^(?:Results auto-announce to your requester\.?|do not busy-poll for status\.?|Reply with a brief acknowledgment only\.?|Do not use any memory tools\.?)$/im;
83-
const SUBAGENT_RUNNING_RE = /You are running as a subagent\b/i;
83+
// Anchor to start of line — prevents quoted/cited false-positives
84+
const SUBAGENT_RUNNING_RE = /^You are running as a subagent\b/i;
8485

8586
const originalLines = text.split("\n");
8687

8788
// Pre-scan: determine if there are leading wrappers.
8889
// Needed to decide whether boilerplate in the leading zone should be stripped
8990
// (boilerplate without a wrapper prefix is preserved — it may be legitimate user text).
91+
// NOTE: also used as a safety guard for N2 — only strip wrapper lines
92+
// when they appear inside the leading zone.
9093
const hasLeadingWrapper = originalLines.some((rawLine) =>
9194
WRAPPER_LINE_RE.test(rawLine.trim())
9295
);
@@ -105,13 +108,20 @@ export function stripEnvelopeMetadata(text: string): string {
105108
const isBoilerplate = BOILERPLATE_RE.test(trimmed);
106109
const isSubagentContent = prevWasWrapper && SUBAGENT_RUNNING_RE.test(trimmed);
107110

108-
if (isWrapper) {
111+
// Strip wrapper lines only when inside the leading zone (N2 fix)
112+
if (stillInLeadingZone && isWrapper) {
109113
prevWasWrapper = true;
110114
result.push(""); // strip wrapper
111115
continue;
112116
}
113117

114118
if (stillInLeadingZone) {
119+
// Blank line — strip but do NOT exit the leading zone (Must Fix 1 fix)
120+
if (trimmed === "") {
121+
result.push("");
122+
continue;
123+
}
124+
115125
if (isBoilerplate) {
116126
// Boilerplate in leading zone — strip only when there was a wrapper prefix.
117127
// This preserves standalone boilerplate text that happens to match the

0 commit comments

Comments
 (0)