Next

Choose which review comments an agent may post

Agent buildEasy12 minMicrosoft and Anthropic style

Your task

An agent does a first pass on every pull request before a person reviews it. It drafts more comments than anyone wants to read, so a filter decides which ones get posted.

Write select_pr_comments(comments, max_comments, min_severity): the rule your agent follows to choose what to post.

  • comments (list of str): the agent's draft comments, each written category|severity|id, for example "missing-tests|8|c1".
  • max_comments (int): the most comments one pull request may get.
  • min_severity (int): the lowest severity worth posting.
  • Return the ids of the comments to post, in the order they are posted.

Rules:

  1. Split each draft on |. One that does not have exactly 3 fields is dropped.
  2. Drop it unless its category is exactly missing-tests, dead-code, null-handling or doc-mismatch. Fields are used as written, with no trimming, and case matters: Missing-Tests is dropped.
  3. Drop it unless its severity is one or more digits, 0 to 9 only. So x, -1 and an empty severity are dropped.
  4. Drop it if its severity is below min_severity. A severity equal to min_severity stays.
  5. Post at most max_comments of the rest, highest severity first. Drafts with equal severity keep their input order. A max_comments of 0 or less posts nothing.

Ids come back exactly as written, repeats included.

Examples

select_pr_comments(comments: list[str], max_comments: int, min_severity: int) -> list[str]
Example 1
Inputselect_pr_comments(["missing-tests|8|c1", "architecture|9|c2", "dead-code|5|c3", "naming|7|c4", "null-handling|6|c5"], 5, 4)
Output["c1", "c5", "c3"]
Example 2
Inputselect_pr_comments(["doc-mismatch|3|d1", "missing-tests|9|d2"], 5, 4)
Output["d2"]
Example 3
Inputselect_pr_comments(["missing-tests|4|a", "dead-code|9|b", "null-handling|7|c", "doc-mismatch|6|d", "missing-tests|8|e", "dead-code|5|f"], 3, 1)
Output["b", "e", "c"]