Commands
learn.py
Reads the review comments on your pull requests through the GitHub CLI and turns them into rule drafts, linked to the comments they came from.
Agent or script?
Through the agent,
learn_from_reviews hands over the comments and the agent decides which are real conventions and rewrites them. This script does no judging: the wording is the reviewers', tidied. Use it to see the raw material, or when you want drafts without an agent.Requirements
- The GitHub CLI
gh, installed and logged in (gh auth login). Lore uses your existing session and sends nothing else anywhere. - A project whose folder is a checkout of the repository you review;
ghruns inside it to find the repository from the git remote.
Synopsis
python3 learn.py --name myapp # preview the actionable review comments (last 90 days)
python3 learn.py --name myapp --save # store them as PENDING rules
python3 learn.py --name myapp --pr 120 # read exactly one pull request
python3 learn.py --name myapp --pr 124-130 --pr 12,15
python3 learn.py --name myapp --since 30 --min-repeats 3 --reviewer alice --repo owner/name
Options
| Option | Default | Meaning |
|---|---|---|
--name NAME required | The project. | |
--save | off | Store the proposals as pending rules. Without it nothing is saved. |
--pr N | Read only these pull requests: 12, 12,15 or 15-18; repeatable; at most 50. The PRs are read in full and --since is ignored. | |
--since DAYS | 90 | Without --pr: only comments from the last N days (1–3650). |
--min-repeats N | 1 | Similar comments needed for a proposal. 1 means every actionable comment; use 3 to see only feedback that keeps coming back. |
--min-prs N | 1 | Distinct pull requests the similar comments must span. |
--limit N | 300 | Most comments to read (10–1000). |
--repo OWNER/NAME | the checkout's remote | Read this repository instead. |
--reviewer LOGIN | Only comments by this reviewer; repeatable. | |
--include-bots | off | Also use comments written by bots. |
--include-external | off | Also use comments by people outside the repository's team. By default only owners, members and collaborators count. |
--include-seen | off | Propose comments that were proposed before too. |
How it works
- Fetch. It asks GitHub for the repository's inline review comments (or those of the named pull requests) through
gh api. - Filter. It drops replies in a thread, bot comments, comments by people outside the team, and comments that contain hidden characters. Praise, acknowledgements and anything shorter than three meaningful words is not actionable and is skipped.
- Group. Comments that ask for the same thing are grouped by shared words, with some normalisation (
db=database,UserRepository=user repository,logger=logging). Paraphrases that share few words can stay separate. - Draft. Each group becomes one proposal: the most representative comment, tidied into an instruction ("Please add a return type here" becomes "Add a return type here."). Groups that seem to ask for opposite things are flagged in the evidence.
- Scope. A section if all the comments were in one, else one file extension, else everywhere.
- Remember. Saved proposals record their comment links;
review-ledger.jsonremembers them, so re-running only shows new feedback and a rejected proposal stays rejected.
Example
$ python3 learn.py --name myapp --pr 41
Read 2 review comment(s) from pull request(s) #41.
[section:src/api] Don't query the database from the controller, go through the repository.
1 similar review comments on 1 PRs (#41)
- https://github.com/acme/shop/pull/41#discussion_r1 “Please don't query the database from the controller, go through the repository.”
1 proposal(s). Re-run with --save to store them as pending rules.
Notes
- The wording is not yours yet. Reword with
review.py editor in the UI before approving. - Only inline review comments are used, not pull-request descriptions, general PR comments or review summaries.
- The comments are untrusted text written by other people. That is why outsiders are excluded by default and why proposals start pending.
- A rejected proposal stays rejected.
--include-seenignores that memory, or delete~/.lore/<name>/review-ledger.json. - Errors are plain. "gh is not installed" or "gh auth login" means install or log in; a bad PR number says "bad pull request". Exit status 2.