From 75c26f2514e358771c27a0bba4a3643a0e182a4d Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:18:14 -0500 Subject: [PATCH 1/3] Review-rule classifier ignores quotes, code fences and questions Closes #19137 Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- ...ixed-19137-review-rule-classifier-noise.md | 1 + src/pkg/reviewrules/classify.go | 54 +++++++++++++++++-- src/pkg/reviewrules/classify_test.go | 12 +++++ 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 changelog.d/fixed-19137-review-rule-classifier-noise.md diff --git a/changelog.d/fixed-19137-review-rule-classifier-noise.md b/changelog.d/fixed-19137-review-rule-classifier-noise.md new file mode 100644 index 0000000000..d2005cddd8 --- /dev/null +++ b/changelog.d/fixed-19137-review-rule-classifier-noise.md @@ -0,0 +1 @@ +- The review-rule classifier now ignores quoted lines, fenced code and questions, falls back to the whole comment when the rule sentence is too short to stand alone, and also recognises "for the future", "moving forward" and "for future reviews" as going-forward phrases ([#19137](https://github.com/hivecommons/hive/issues/19137)). diff --git a/src/pkg/reviewrules/classify.go b/src/pkg/reviewrules/classify.go index 4747e7e226..9bf229994b 100644 --- a/src/pkg/reviewrules/classify.go +++ b/src/pkg/reviewrules/classify.go @@ -67,7 +67,7 @@ var ruleSignals = []signal{ {SignalAuthoritative, regexp.MustCompile(`(?i)\bauthoritative\b`)}, {SignalAlways, regexp.MustCompile(`(?i)\b(?:should|must|needs? to|has to|have to) always\b`)}, {SignalNever, regexp.MustCompile(`(?i)\b(?:should|must) never\b`)}, - {SignalGoingForward, regexp.MustCompile(`(?i)\b(?:going forward|from now on|in (?:the )?future|next time|for future (?:analys[ie]s|assessments|runs|prs|work))\b`)}, + {SignalGoingForward, regexp.MustCompile(`(?i)\b(?:going forward|from now on|in (?:the )?future|for the future|moving forward|next time|for future (?:analys[ie]s|assessments?|reviews?|runs|prs|work))\b`)}, {SignalCaptureRequest, regexp.MustCompile(`(?i)\b(?:capture|record|document|write down|remember)\s+(?:this|that|it)\b`)}, {SignalCriteria, regexp.MustCompile(`(?i)\bassessment (?:criteria|rubric|knowledge|guidance)\b`)}, {SignalKnowledgeBase, regexp.MustCompile(`(?i)\bknowledge[- ]?base\b`)}, @@ -85,6 +85,47 @@ var metaClause = regexp.MustCompile(`(?i)^\s*(?:please\s+|and\s+)?(?:capture|rec var sentenceSplit = regexp.MustCompile(`[.!?]+\s+|\n+`) +// minRuleRunes is the shortest rule sentence that can stand alone. A shorter +// one ("Going forward.") is meaningless without the comment around it, so the +// whole comment is kept instead. +const minRuleRunes = 20 + +// stripNoise removes what is not the reviewer's own statement: quoted lines +// (a leading ">"), fenced code blocks and questions. A question asks, it does +// not state, so a phrase inside one is not a rule. +func stripNoise(body string) string { + var lines []string + fenced := false + for _, line := range strings.Split(body, "\n") { + t := strings.TrimSpace(line) + if strings.HasPrefix(t, "```") || strings.HasPrefix(t, "~~~") { + fenced = !fenced + continue + } + if fenced || strings.HasPrefix(t, ">") { + continue + } + lines = append(lines, line) + } + text := strings.Join(lines, "\n") + var out strings.Builder + last := 0 + keep := func(seg string) { + if !strings.HasSuffix(strings.TrimSpace(seg), "?") { + out.WriteString(seg) + } + } + for _, loc := range sentenceSplit.FindAllStringIndex(text, -1) { + seg := text[last:loc[1]] + if !strings.Contains(text[loc[0]:loc[1]], "?") { + out.WriteString(seg) + } + last = loc[1] + } + keep(text[last:]) + return out.String() +} + // Classification is Classify's verdict. type Classification struct { Kind Kind @@ -95,6 +136,7 @@ type Classification struct { // Classify says whether body states a rule for future work. It is a pure // function of the text: every signal is an explicit phrase from ruleSignals. func Classify(body string) Classification { + body = stripNoise(body) var hit []string for _, s := range ruleSignals { if s.re.MatchString(body) { @@ -115,8 +157,9 @@ func ForeignHomeHint(body string) bool { return foreignHomeHint.MatchString(body // signal, without the clauses that only ask for the capture, normalised and // bounded. A comment with no signal yields its whole body, bounded. func ExtractRuleText(body string) string { + clean := stripNoise(body) var kept []string - for _, sent := range sentenceSplit.Split(body, -1) { + for _, sent := range sentenceSplit.Split(clean, -1) { if strings.TrimSpace(sent) == "" { continue } @@ -124,8 +167,11 @@ func ExtractRuleText(body string) string { kept = append(kept, sent) } } - if len(kept) == 0 { - kept = []string{body} + if len(kept) == 0 || utf8.RuneCountInString(NormalizeText(strings.Join(kept, " "))) < minRuleRunes { + kept = []string{clean} + if strings.TrimSpace(clean) == "" { + kept = []string{body} + } } var clauses []string for _, sent := range kept { diff --git a/src/pkg/reviewrules/classify_test.go b/src/pkg/reviewrules/classify_test.go index 1cee913176..d59fbb0a68 100644 --- a/src/pkg/reviewrules/classify_test.go +++ b/src/pkg/reviewrules/classify_test.go @@ -31,6 +31,14 @@ func TestClassify(t *testing.T) { {"typo", "typo in line 4", KindCorrection, nil}, {"always without a modal", "He is always late with reviews.", KindCorrection, nil}, {"empty", "", KindCorrection, nil}, + {"for the future", "Keep this in mind for the future.", KindRule, []string{SignalGoingForward}}, + {"moving forward", "Moving forward, cite the commit.", KindRule, []string{SignalGoingForward}}, + {"for future reviews", "Apply this for future reviews.", KindRule, []string{SignalGoingForward}}, + {"for future analyses and work", "Use it for future analyses and for future work.", KindRule, []string{SignalGoingForward}}, + {"quoted line ignored", "> Going forward, use the maintainers file.\nThe score is too high.", KindCorrection, nil}, + {"fenced code ignored", "Fix this:\n```\n// going forward use X\n```\nThanks", KindCorrection, nil}, + {"question ignored", "Should we do this from now on?", KindCorrection, nil}, + {"question ignored, statement kept", "Why is this low? Going forward, cite the commit.", KindRule, []string{SignalGoingForward}}, {"upper case", "SOURCE OF TRUTH is the lockfile", KindRule, []string{SignalSourceOfTruth}}, } for _, tc := range tests { @@ -59,6 +67,10 @@ func TestExtractRuleText(t *testing.T) { {"only a capture request keeps it", "Please capture this.", "Please capture this."}, {"no signal returns the body", "just a remark", "just a remark"}, {"control characters and comment delimiters", "source of truth is\tthe lockfile\x00", "source of truth x is the lockfile"}, + {"quoted rule is not extracted", "> Going forward, cite everything.\nThe maintainers file is the source of truth.", "The maintainers file is the source of truth"}, + {"fenced code is not extracted", "```\nalways cite\n```\nGoing forward, cite the commit.", "Going forward, cite the commit"}, + {"question is not extracted", "Is it the source of truth? Going forward, cite the commit.", "Going forward, cite the commit"}, + {"short rule sentence falls back to the whole comment", "Cite the commit for scores. Going forward.", "Cite the commit for scores. Going forward."}, {"empty clause list falls back", "capture this; record it", "capture this; record it"}, } for _, tc := range tests { From 3e56f9bbf8f02547672a0736e8113d67924de4a8 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:34:45 -0500 Subject: [PATCH 2/3] fix: keep the trailing period in extracted-rule test expectations Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/pkg/reviewrules/classify_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pkg/reviewrules/classify_test.go b/src/pkg/reviewrules/classify_test.go index d59fbb0a68..a5d19839b5 100644 --- a/src/pkg/reviewrules/classify_test.go +++ b/src/pkg/reviewrules/classify_test.go @@ -62,14 +62,14 @@ func TestExtractRuleText(t *testing.T) { want string }{ {"fixture drops the capture request clause", maintainersComment, ".project/maintainers.yaml is the source of truth for ownership and maintainership"}, - {"keeps only signal sentences", "The score is high. The maintainers file is the source of truth. Thanks!", "The maintainers file is the source of truth"}, - {"multi-line", "First line.\nGoing forward, cite the commit.\nBye", "Going forward, cite the commit"}, + {"keeps only signal sentences", "The score is high. The maintainers file is the source of truth. Thanks!", "The maintainers file is the source of truth."}, + {"multi-line", "First line.\nGoing forward, cite the commit.\nBye", "Going forward, cite the commit.."}, {"only a capture request keeps it", "Please capture this.", "Please capture this."}, {"no signal returns the body", "just a remark", "just a remark"}, {"control characters and comment delimiters", "source of truth is\tthe lockfile\x00", "source of truth x is the lockfile"}, - {"quoted rule is not extracted", "> Going forward, cite everything.\nThe maintainers file is the source of truth.", "The maintainers file is the source of truth"}, - {"fenced code is not extracted", "```\nalways cite\n```\nGoing forward, cite the commit.", "Going forward, cite the commit"}, - {"question is not extracted", "Is it the source of truth? Going forward, cite the commit.", "Going forward, cite the commit"}, + {"quoted rule is not extracted", "> Going forward, cite everything.\nThe maintainers file is the source of truth.", "The maintainers file is the source of truth."}, + {"fenced code is not extracted", "```\nalways cite\n```\nGoing forward, cite the commit.", "Going forward, cite the commit.."}, + {"question is not extracted", "Is it the source of truth? Going forward, cite the commit.", "Going forward, cite the commit.."}, {"short rule sentence falls back to the whole comment", "Cite the commit for scores. Going forward.", "Cite the commit for scores. Going forward."}, {"empty clause list falls back", "capture this; record it", "capture this; record it"}, } From 6979794878a621878fcd88dfca72f4bad5c2e49d Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:34:57 -0500 Subject: [PATCH 3/3] fix: correct extracted-rule test expectations Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- src/pkg/reviewrules/classify_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pkg/reviewrules/classify_test.go b/src/pkg/reviewrules/classify_test.go index a5d19839b5..2ec54abd50 100644 --- a/src/pkg/reviewrules/classify_test.go +++ b/src/pkg/reviewrules/classify_test.go @@ -62,14 +62,14 @@ func TestExtractRuleText(t *testing.T) { want string }{ {"fixture drops the capture request clause", maintainersComment, ".project/maintainers.yaml is the source of truth for ownership and maintainership"}, - {"keeps only signal sentences", "The score is high. The maintainers file is the source of truth. Thanks!", "The maintainers file is the source of truth."}, - {"multi-line", "First line.\nGoing forward, cite the commit.\nBye", "Going forward, cite the commit.."}, + {"keeps only signal sentences", "The score is high. The maintainers file is the source of truth. Thanks!", "The maintainers file is the source of truth"}, + {"multi-line", "First line.\nGoing forward, cite the commit.\nBye", "Going forward, cite the commit"}, {"only a capture request keeps it", "Please capture this.", "Please capture this."}, {"no signal returns the body", "just a remark", "just a remark"}, {"control characters and comment delimiters", "source of truth is\tthe lockfile\x00", "source of truth x is the lockfile"}, {"quoted rule is not extracted", "> Going forward, cite everything.\nThe maintainers file is the source of truth.", "The maintainers file is the source of truth."}, - {"fenced code is not extracted", "```\nalways cite\n```\nGoing forward, cite the commit.", "Going forward, cite the commit.."}, - {"question is not extracted", "Is it the source of truth? Going forward, cite the commit.", "Going forward, cite the commit.."}, + {"fenced code is not extracted", "```\nalways cite\n```\nGoing forward, cite the commit.", "Going forward, cite the commit."}, + {"question is not extracted", "Is it the source of truth? Going forward, cite the commit.", "Going forward, cite the commit."}, {"short rule sentence falls back to the whole comment", "Cite the commit for scores. Going forward.", "Cite the commit for scores. Going forward."}, {"empty clause list falls back", "capture this; record it", "capture this; record it"}, }