fix: count only non-comment lines in command-sequence detection - #2175
Open
Osamaali313 wants to merge 1 commit into
Open
fix: count only non-comment lines in command-sequence detection#2175Osamaali313 wants to merge 1 commit into
Osamaali313 wants to merge 1 commit into
Conversation
_isCommandSequence classifies a fenced code block as a shell command sequence
(to execute) vs a file (to write). Its numerator filters out comment/empty
lines, but the denominator used lines.length (all lines), so the comment says
"more than 70% of non-comment lines" while the math divides by every line.
A normal command block with explanatory comments, e.g.
# Install dependencies
npm install
# Start the dev server
npm run dev
is 2/2 = 100% commands by the intended rule but computed 2/4 = 50%, failing the
0.7 threshold and being misclassified as a file to write instead of run. Divide
by the non-comment line count to match the documented behavior, and guard the
all-comment case against a 0/0 = NaN comparison.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
EnhancedStreamingMessageParser._isCommandSequencedecides whether a fenced code block is a shell command sequence (to execute) or a file (to write), by what fraction of lines look like commands. The numerator already excludes comment/empty lines, but the denominator usedlines.length(every line):The comment says "70% of non-comment lines", but the math divides by all lines. So comment lines dilute the ratio. A normal command snippet with explanatory comments:
is
2/2 = 100%commands by the intended rule, but computes2/4 = 50%, falls below the0.7threshold, and is misclassified as a file to write instead of shell commands to run — the exact "code written to files instead of executed" failure this enhanced parser was built to address.Fix
Compute the ratio over non-comment, non-empty lines (matching the comment/intent), and guard the all-comment case against
0/0 = NaN:Testing
Added a regression test to
message-parser.spec.ts(a comment-interleaved bash block is detected asshell). It fails onmain(the block isn't recognized →onActionOpennever fires for ashellaction) and passes with the fix.pnpm typecheckandpnpm lintpass (pre-commit hook green).