mirror of
https://github.com/Yeachan-Heo/oh-my-claudecode.git
synced 2026-10-19 01:39:52 -05:00
fix(model-routing): stop halving the indented code-block count (#3364)
countCodeBlocks() summed fenced blocks with Math.floor(indentedBlocks / 2), but the indented-block regex already coalesces each contiguous run of indented lines into a single match — so indentedBlocks is already the block count. The divisor discarded half of it: a prompt with one indented code block scored 0, silently dropping its lexical-complexity signal (scorer.ts gates on codeBlockCount > 0) and able to nudge borderline prompts one model tier too low. Drop the /2 so indented blocks count 1:1, matching the fenced path. Adds regression tests for one- and two-indented-block prompts; both fail on the old code and pass on the fix. Existing fenced-block test is unaffected. Constraint: sole consumer is the `codeBlockCount > 0` gate in scorer.ts Rejected: rework the regex to match per indented line | regex is correct as-is, the divisor is the defect Confidence: high Scope-risk: narrow Not-tested: prompts mixing fenced and indented blocks in one string
This commit is contained in:
1 parent
7e0c61e3bd
commit
da2ee4f327
2 files changed
+15
-1
No files matched your search
@@ -62,6 +62,18 @@ describe('Signal Extraction', () => {
|
||||
expect(signals.codeBlockCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should count a single indented code block', () => {
|
||||
const prompt = 'Here is code:\n const x = 1;\n return x;\ndone';
|
||||
const signals = extractLexicalSignals(prompt);
|
||||
expect(signals.codeBlockCount).toBe(1);
|
||||
});
|
||||
|
||||
it('should count two separate indented code blocks', () => {
|
||||
const prompt = 'First:\n const a = 1;\n\nSecond:\n const b = 2;';
|
||||
const signals = extractLexicalSignals(prompt);
|
||||
expect(signals.codeBlockCount).toBe(2);
|
||||
});
|
||||
|
||||
it('should detect architecture keywords', () => {
|
||||
const signals = extractLexicalSignals('We need to refactor the architecture');
|
||||
expect(signals.hasArchitectureKeywords).toBe(true);
|
||||
|
||||
@@ -107,8 +107,10 @@ function countFilePaths(prompt: string): number {
|
||||
*/
|
||||
function countCodeBlocks(prompt: string): number {
|
||||
const fencedBlocks = (prompt.match(/```[\s\S]*?```/g) || []).length;
|
||||
// The indented-block regex coalesces each contiguous run of indented lines
|
||||
// into a single match, so `indentedBlocks` is already the block count.
|
||||
const indentedBlocks = (prompt.match(/(?:^|\n)(?:\s{4}|\t)[^\n]+(?:\n(?:\s{4}|\t)[^\n]+)*/g) || []).length;
|
||||
return fencedBlocks + Math.floor(indentedBlocks / 2);
|
||||
return fencedBlocks + indentedBlocks;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user