-
Notifications
You must be signed in to change notification settings - Fork 0
feat(review-kit): strip the model's preamble from the review #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+102
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| export { | ||
| defineReviewAgent, | ||
| idempotencyMarker, | ||
| reviewBody, | ||
| reviewInput, | ||
| reviewMountPaths, | ||
| REVIEW_KIT_VERSION, | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ import { | |||||||||||||||||||||||||||||||||||||||||||
| defineReviewPersona, | ||||||||||||||||||||||||||||||||||||||||||||
| prDiff, | ||||||||||||||||||||||||||||||||||||||||||||
| readPullRequest, | ||||||||||||||||||||||||||||||||||||||||||||
| reviewBody, | ||||||||||||||||||||||||||||||||||||||||||||
| reviewInput | ||||||||||||||||||||||||||||||||||||||||||||
| } from './index.js'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { createReviewHandler } from './agent.js'; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -651,3 +652,59 @@ async function withRelayfileTransportEnv( | |||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| test('reviewBody strips the model preamble and keeps the review', () => { | ||||||||||||||||||||||||||||||||||||||||||||
| // Shape observed in production: the harness stdout carries the model's | ||||||||||||||||||||||||||||||||||||||||||||
| // thinking, then the review. Only the review should reach the PR. | ||||||||||||||||||||||||||||||||||||||||||||
| const output = [ | ||||||||||||||||||||||||||||||||||||||||||||
| 'Evidence confirmed. The 8 probe commits added only comment lines.', | ||||||||||||||||||||||||||||||||||||||||||||
| 'I have all evidence needed. Writing the review now.', | ||||||||||||||||||||||||||||||||||||||||||||
| '', | ||||||||||||||||||||||||||||||||||||||||||||
| '**Verdict: Blocker.** Second stat-math path outside lib/aggregates.ts.', | ||||||||||||||||||||||||||||||||||||||||||||
| '', | ||||||||||||||||||||||||||||||||||||||||||||
| '- **Blocker** — `lib/recentForm.ts:15` — duplicate math. Fix: use computeStandings.' | ||||||||||||||||||||||||||||||||||||||||||||
| ].join('\n'); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| const body = reviewBody(output); | ||||||||||||||||||||||||||||||||||||||||||||
| assert.ok(body.startsWith('**Verdict: Blocker.**'), 'must open on the verdict line'); | ||||||||||||||||||||||||||||||||||||||||||||
| assert.ok(!body.includes('Evidence confirmed'), 'preamble must be gone'); | ||||||||||||||||||||||||||||||||||||||||||||
| assert.ok(!body.includes('Writing the review now'), 'narration must be gone'); | ||||||||||||||||||||||||||||||||||||||||||||
| assert.ok(body.includes('lib/recentForm.ts:15'), 'findings must survive'); | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| test('reviewBody cuts at the LAST verdict line so a drafted review loses to the real one', () => { | ||||||||||||||||||||||||||||||||||||||||||||
| // A model that drafts before writing emits two verdict lines; the real | ||||||||||||||||||||||||||||||||||||||||||||
| // review is the final one. | ||||||||||||||||||||||||||||||||||||||||||||
| const output = [ | ||||||||||||||||||||||||||||||||||||||||||||
| '**Verdict: Note.** draft — I might downgrade this.', | ||||||||||||||||||||||||||||||||||||||||||||
| 'Actually, checking the published-only rule changes it.', | ||||||||||||||||||||||||||||||||||||||||||||
| '**Verdict: Blocker.** ignores the published-only filter.' | ||||||||||||||||||||||||||||||||||||||||||||
| ].join('\n'); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| assert.equal(reviewBody(output), '**Verdict: Blocker.** ignores the published-only filter.'); | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| test('reviewBody passes through a body with no verdict line', () => { | ||||||||||||||||||||||||||||||||||||||||||||
| // The model ignored the format. A malformed review still beats silence — | ||||||||||||||||||||||||||||||||||||||||||||
| // for an advisory agent, silence reads as approval. | ||||||||||||||||||||||||||||||||||||||||||||
| assert.equal(reviewBody('no verdict here, just prose'), 'no verdict here, just prose'); | ||||||||||||||||||||||||||||||||||||||||||||
| assert.equal(reviewBody(' '), ''); | ||||||||||||||||||||||||||||||||||||||||||||
| assert.equal(reviewBody(''), ''); | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+687
to
+693
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure the robustness of the updated
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| test('reviewBody tolerates how the model bolds the verdict line', () => { | ||||||||||||||||||||||||||||||||||||||||||||
| // The charter asks for one exact form and production emits it, but a strict | ||||||||||||||||||||||||||||||||||||||||||||
| // pattern fails open in the worst way: an unmatched line publishes the whole | ||||||||||||||||||||||||||||||||||||||||||||
| // preamble. Tolerate the variants LLMs actually drift to. | ||||||||||||||||||||||||||||||||||||||||||||
| assert.equal(reviewBody('thinking\n**Verdict**: Blocker'), '**Verdict**: Blocker'); | ||||||||||||||||||||||||||||||||||||||||||||
| assert.equal(reviewBody('thinking\n**Verdict:** Blocker'), '**Verdict:** Blocker'); | ||||||||||||||||||||||||||||||||||||||||||||
| assert.equal(reviewBody('thinking\n**Verdict** : Blocker'), '**Verdict** : Blocker'); | ||||||||||||||||||||||||||||||||||||||||||||
| assert.equal(reviewBody('thinking\n**verdict:** Blocker'), '**verdict:** Blocker'); | ||||||||||||||||||||||||||||||||||||||||||||
| assert.equal(reviewBody('thinking\n**VERDICT**: Blocker'), '**VERDICT**: Blocker'); | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| test('reviewBody ignores a verdict mentioned mid-line, not at a line start', () => { | ||||||||||||||||||||||||||||||||||||||||||||
| // The ^ anchor is what keeps prose about a verdict from being mistaken for one. | ||||||||||||||||||||||||||||||||||||||||||||
| const prose = 'I think the **Verdict:** below is too harsh, reconsidering.'; | ||||||||||||||||||||||||||||||||||||||||||||
| assert.equal(reviewBody(prose), prose); | ||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current regular expression
/^\*\*Verdict:/gmuis quite strict and might fail to match common variations in LLM outputs. For example, LLMs often output**Verdict**: Blocker(with the colon outside the bold asterisks),**Verdict:** Blocker(with the colon inside but closed bold), or use different casing like**verdict**:or**VERDICT**:.Updating the regex to be case-insensitive and to support optional closing asterisks and spaces before the colon makes the preamble stripping much more robust against non-deterministic model formatting.