From 4ffff8d4c7f96f640597326ab793a4652df7acce Mon Sep 17 00:00:00 2001 From: Afloat Date: Tue, 17 Nov 2026 14:04:52 +0800 Subject: [PATCH] fix(instincts): align alias boundaries and disambiguate Go prose --- scripts/lib/instinct-relevance.js | 16 +++++++++------- tests/lib/instinct-relevance.test.js | 10 ++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/lib/instinct-relevance.js b/scripts/lib/instinct-relevance.js index a746aadba..bea89f6b9 100644 --- a/scripts/lib/instinct-relevance.js +++ b/scripts/lib/instinct-relevance.js @@ -113,10 +113,10 @@ function detectStackKeywords(projectRoot, projectInfo) { function tokenize(value) { return String(value || '') .toLowerCase() - .replace(/\bc#(?![a-z0-9#])/g, 'csharp') - .replace(/\bf#(?![a-z0-9#])/g, 'fsharp') - .replace(/\bnext\.js\b/g, 'nextjs') - .replace(/\bnest\.js\b/g, 'nestjs') + .replace(/(^|[^a-z0-9])c#(?![a-z0-9#])/g, '$1csharp') + .replace(/(^|[^a-z0-9])f#(?![a-z0-9#])/g, '$1fsharp') + .replace(/(^|[^a-z0-9])next\.js(?![a-z0-9])/g, '$1nextjs') + .replace(/(^|[^a-z0-9])nest\.js(?![a-z0-9])/g, '$1nestjs') .split(/[^a-z0-9]+/) .filter(Boolean); } @@ -130,13 +130,15 @@ function tokenize(value) { */ function instinctMatchesStack(instinct, stackKeywords) { if (!instinct || !stackKeywords || stackKeywords.size === 0) return false; - const tokens = new Set([ + const explicitTokens = new Set([ ...tokenize(instinct.domain), - ...tokenize(instinct.trigger), ...tokenize(instinct.stack), ]); + const tokens = new Set([...explicitTokens, ...tokenize(instinct.trigger)]); + // In prose, the capitalized language name distinguishes Go from the verb. + const hasGoAlias = explicitTokens.has('go') || /(^|[^a-zA-Z0-9])Go(?![a-zA-Z0-9])/.test(String(instinct.trigger || '')); for (const keyword of stackKeywords) { - if (tokens.has(keyword) || (keyword === 'golang' && tokens.has('go'))) return true; + if (tokens.has(keyword) || (keyword === 'golang' && hasGoAlias)) return true; } return false; } diff --git a/tests/lib/instinct-relevance.test.js b/tests/lib/instinct-relevance.test.js index c52d51868..f598dcb98 100644 --- a/tests/lib/instinct-relevance.test.js +++ b/tests/lib/instinct-relevance.test.js @@ -81,6 +81,16 @@ function runAliasTests() { assert.strictEqual(instinctMatchesStack({ trigger: 'edit next.json' }, new Set(['nextjs'])), false); assert.strictEqual(instinctMatchesStack({ trigger: 'nest.json settings' }, new Set(['nestjs'])), false); assert.strictEqual(instinctMatchesStack({ trigger: 'good practices' }, new Set(['golang'])), false); + for (const [value, keyword] of [ + ['next.js_routes', 'nextjs'], ['use_nest.js', 'nestjs'], + ['use_C#', 'csharp'], ['F#_functions', 'fsharp'], + ]) { + assert.strictEqual(instinctMatchesStack({ trigger: value }, new Set([keyword])), true, value); + } + assert.strictEqual(instinctMatchesStack({ trigger: 'when changes go live' }, new Set(['golang'])), false); + assert.strictEqual(instinctMatchesStack({ trigger: 'when writing Go tests' }, new Set(['golang'])), true); + assert.strictEqual(instinctMatchesStack({ domain: 'go' }, new Set(['golang'])), true); + assert.strictEqual(instinctMatchesStack({ stack: 'GO' }, new Set(['golang'])), true); })) passed++; else failed++; return { passed, failed };