feat(observer): strip <system-reminder> blocks from promptText

Closes brain-retro 2026-05-20 #8 — UserPromptSubmit hook injects
<system-reminder>...</system-reminder> blocks into user.content that
polluted classifyTask / classifyPromptSignal / routing detection.
Now stripped via regex before any analysis.

Completed by controller (Opus) after subagent hit context limit on
1250-line test file. Helper stripSystemReminders + promptText update
were committed by subagent; test cases appended via Bash heredoc.

4 new vitest tests, 290/290 GREEN.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Дмитрий
2026-05-20 13:14:16 +03:00
parent c0e3e901d0
commit ffaeb8f37b
2 changed files with 50 additions and 2 deletions
+43
View File
@@ -1248,3 +1248,46 @@ describe('error event differentiation (Task 7)', () => {
expect(e.summary).toContain('String to replace');
});
});
describe('promptText strips <system-reminder> blocks (Task 8)', () => {
it('classifyTask is not polluted by reminder content', () => {
const transcript = [
JSON.stringify({ sessionId: 's' }),
JSON.stringify({ type: 'user', message: { role: 'user',
content: '<system-reminder>почему как что зачем</system-reminder>\nрефактор биллинга'
}, uuid: 'u1', timestamp: '2026-05-20T00:00:00Z' }),
].join('\n');
const ep = parseTranscript(transcript);
expect(ep.primary_rationale.task_classification).toBe('refactor');
});
it('multiline system-reminder is stripped', () => {
const transcript = [
JSON.stringify({ sessionId: 's' }),
JSON.stringify({ type: 'user', message: { role: 'user',
content: '<system-reminder>\nline 1\nline 2 with почему\n</system-reminder>\nfix баг'
}, uuid: 'u1', timestamp: '2026-05-20T00:00:00Z' }),
].join('\n');
const ep = parseTranscript(transcript);
expect(ep.primary_rationale.task_classification).toBe('bugfix');
});
it('multiple system-reminders all stripped', () => {
const transcript = [
JSON.stringify({ sessionId: 's' }),
JSON.stringify({ type: 'user', message: { role: 'user',
content: '<system-reminder>почему</system-reminder>middle<system-reminder>как</system-reminder>создай фичу'
}, uuid: 'u1', timestamp: '2026-05-20T00:00:00Z' }),
].join('\n');
const ep = parseTranscript(transcript);
expect(ep.primary_rationale.task_classification).toBe('feature');
});
it('content array form also stripped', () => {
const transcript = [
JSON.stringify({ sessionId: 's' }),
JSON.stringify({ type: 'user', message: { role: 'user',
content: [{ type: 'text', text: '<system-reminder>почему как</system-reminder> рефактор' }]
}, uuid: 'u1', timestamp: '2026-05-20T00:00:00Z' }),
].join('\n');
const ep = parseTranscript(transcript);
expect(ep.primary_rationale.task_classification).toBe('refactor');
});
});