From 420f1f051fea35a7dcdf8d593d206decee929515 Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Mon, 10 Aug 2026 04:45:52 -0700 Subject: [PATCH] fix(insights): stop counting prose 'wrong answer' as a user correction --- src/workflow-insights.ts | 7 ++++++- tests/workflow-insights.test.ts | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/workflow-insights.ts b/src/workflow-insights.ts index a51c37eb..3407fc92 100644 --- a/src/workflow-insights.ts +++ b/src/workflow-insights.ts @@ -20,7 +20,12 @@ export const USER_CORRECTION_PATTERNS: RegExp[] = [ /\byou (?:missed|forgot|misunderstood|broke)\b/i, /\brevert (?:that|it|this|your|the last|the change)\b/i, /\bundo (?:that|it|this|your|the last|the change)\b/i, - /\bwrong (?:file|approach|place|method|function|answer|way|direction)\b/i, + // "answer" is deliberately absent from the noun list: injected skill/system + // prose lands in the user-message slot and reads as ordinary writing where + // "the wrong answer" is an idiom ("a well-composed page is never the wrong + // answer" counted 4 phantom corrections on real data). The other nouns are + // concrete work artifacts that prose rarely uses with "wrong". + /\bwrong (?:file|approach|place|method|function|way|direction)\b/i, /\bstill (?:wrong|broken|failing|not working)\b/i, ] diff --git a/tests/workflow-insights.test.ts b/tests/workflow-insights.test.ts index e900d206..2e44687e 100644 --- a/tests/workflow-insights.test.ts +++ b/tests/workflow-insights.test.ts @@ -119,12 +119,25 @@ describe('scanUserCorrections', () => { 'undo the migration when done', 'the build is failing, can you fix it', 'what went wrong here', + // Verbatim from an injected skill prompt that counted 4 phantom + // corrections on real data: "wrong answer" is prose idiom, not a + // correction, which is why "answer" is not in the wrong- list. + 'When unsure: a well-composed page is never the wrong answer; an over-designed visual identity sometimes is.', ] const p = project([session('s1', phrases.map(m => turn({ userMessage: m })))]) const r = scanUserCorrections([p]) expect(r.corrections).toBe(0) }) + it('still flags concrete wrong- follow-ups', () => { + const p = project([session('s1', [ + turn({ userMessage: 'rename the helper' }), + turn({ userMessage: 'you edited the wrong file' }), + turn({ userMessage: "that's the wrong approach, use the cache" }), + ])]) + expect(scanUserCorrections([p]).corrections).toBe(2) + }) + it('ignores continuation turns with no fresh prompt', () => { const p = project([session('s1', [ turn({ userMessage: 'build the feature' }),