fix(hooks): normalize whitespace before matching the classifier notice

isClassifierNotice now collapses whitespace runs itself, so the
session-end hook drops a notice wrapped across lines the same way the
LLM summary path already did.

Assisted-by: Claude <noreply@anthropic.com>
This commit is contained in:
Rahul Selvaraj committed 2026-11-11 18:33:02 +08:00
1 parent 882ba18c10
commit dd9f8abb0c
3 files changed
+24 -2

No files matched your search

+3 -2
View File
@@ -35,10 +35,11 @@ function getContextThreshold() {
/**
* True when a user-turn text is the harness notice left after a
* safety-classifier stop. Anchored to the whole message so user text that
* quotes or follows the notice is kept.
* quotes or follows the notice is kept. Whitespace runs (including
* newlines) are collapsed first so every caller matches the same text.
*/
function isClassifierNotice(text) {
return CLASSIFIER_NOTICE.test(text);
return CLASSIFIER_NOTICE.test(String(text).replace(/\s+/g, ' ').trim());
}
/**
+12
View File
@@ -105,6 +105,17 @@ function testNoticeOnlyTranscript() {
});
}
function testDropsMultilineClassifierNotice() {
const wrapped = CLASSIFIER_NOTICE_TEXT.replace('safety classifier', 'safety\nclassifier');
withTranscript('3867eeee-ffff-4aaa-8bbb-cccccccc3867', [
JSON.stringify({ type: 'user', content: 'Refactor the config loader' }),
JSON.stringify({ type: 'user', content: wrapped }),
], out => {
assert.ok(out.includes('- Refactor the config loader'), `expected the real user task in:\n${out}`);
assert.ok(!/safety\s+classifier/.test(out), `wrapped notice must not be summarized:\n${out}`);
});
}
function testKeepsMessageQuotingNotice() {
const userText = 'Why did I see "Your response above was stopped by a safety classifier" earlier?';
withTranscript('3867cccc-dddd-4eee-8fff-aaaaaaaa3867', [JSON.stringify({ type: 'user', content: userText })], out => {
@@ -116,6 +127,7 @@ function runClassifierNoticeTests() {
const results = [
test('drops safety-classifier notices from summary tasks', testDropsClassifierNotice),
test('drops the longer classifier notice from summary tasks', testDropsLongClassifierNotice),
test('drops a classifier notice wrapped across lines', testDropsMultilineClassifierNotice),
test('writes no summary for a transcript holding only a classifier notice', testNoticeOnlyTranscript),
test('keeps a user message that only mentions the classifier notice', testKeepsMessageQuotingNotice),
];
+9
View File
@@ -196,6 +196,15 @@ test('isClassifierNotice matches only the whole notice', () => {
assert.strictEqual(isClassifierNotice('Why did I see "Your response above was stopped by a safety classifier"?'), false);
});
test('drops a classifier notice wrapped across lines', () => {
const wrapped = CLASSIFIER_NOTICE_LONG_TEXT.replace('safety classifier', 'safety\nclassifier').replace(' The rest', ' \nThe rest');
assert.strictEqual(isClassifierNotice(wrapped), true);
const p = writeTranscript([userEntry('Refactor the config loader'), userEntry(wrapped), assistantEntry('Done.')]);
const result = extractConversationText(p);
assert.ok(result.includes('Refactor the config loader'));
assert.ok(!result.includes('withheld') && !result.includes('safety classifier'), result);
});
// --- getContextRemainingPct ---
console.log('\ngetContextRemainingPct:');