@oss-autopilot/core 3.38.0 → 3.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/cli-registry.js +7 -4
  2. package/dist/cli.bundle.cjs +139 -132
  3. package/dist/commands/daily-dismiss-filter.d.ts +37 -0
  4. package/dist/commands/daily-dismiss-filter.js +80 -0
  5. package/dist/commands/daily-merged-pr-notes.d.ts +27 -0
  6. package/dist/commands/daily-merged-pr-notes.js +166 -0
  7. package/dist/commands/daily-reviewed-prs.d.ts +41 -0
  8. package/dist/commands/daily-reviewed-prs.js +270 -0
  9. package/dist/commands/daily-warnings.d.ts +28 -0
  10. package/dist/commands/daily-warnings.js +37 -0
  11. package/dist/commands/daily.d.ts +22 -1
  12. package/dist/commands/daily.js +287 -107
  13. package/dist/commands/dashboard-cache.js +9 -2
  14. package/dist/commands/dashboard-data.js +40 -20
  15. package/dist/commands/dashboard-gist-sync.d.ts +4 -0
  16. package/dist/commands/dashboard-gist-sync.js +5 -1
  17. package/dist/commands/dismiss.d.ts +25 -5
  18. package/dist/commands/dismiss.js +38 -10
  19. package/dist/commands/overnight.js +14 -1
  20. package/dist/commands/scout-bridge.js +4 -1
  21. package/dist/commands/validation.d.ts +11 -0
  22. package/dist/commands/validation.js +16 -0
  23. package/dist/core/checklist-analysis.js +34 -0
  24. package/dist/core/closed-pr-status.d.ts +73 -0
  25. package/dist/core/closed-pr-status.js +113 -0
  26. package/dist/core/comment-decision.d.ts +10 -3
  27. package/dist/core/comment-decision.js +13 -5
  28. package/dist/core/comment-utils.d.ts +38 -1
  29. package/dist/core/comment-utils.js +124 -1
  30. package/dist/core/concurrency.d.ts +6 -0
  31. package/dist/core/concurrency.js +13 -0
  32. package/dist/core/daily-logic.d.ts +13 -1
  33. package/dist/core/daily-logic.js +59 -2
  34. package/dist/core/engaged-issues.d.ts +93 -0
  35. package/dist/core/engaged-issues.js +183 -0
  36. package/dist/core/errors.d.ts +4 -0
  37. package/dist/core/errors.js +10 -0
  38. package/dist/core/github-stats.d.ts +10 -0
  39. package/dist/core/github-stats.js +35 -0
  40. package/dist/core/index.d.ts +10 -5
  41. package/dist/core/index.js +9 -4
  42. package/dist/core/issue-conversation.d.ts +83 -12
  43. package/dist/core/issue-conversation.js +306 -118
  44. package/dist/core/merged-pr-notes.d.ts +192 -0
  45. package/dist/core/merged-pr-notes.js +340 -0
  46. package/dist/core/pr-assembly.js +3 -0
  47. package/dist/core/pr-monitor.d.ts +62 -0
  48. package/dist/core/pr-monitor.js +113 -3
  49. package/dist/core/reviewed-prs-fetch.d.ts +91 -0
  50. package/dist/core/reviewed-prs-fetch.js +271 -0
  51. package/dist/core/reviewed-prs.d.ts +244 -0
  52. package/dist/core/reviewed-prs.js +380 -0
  53. package/dist/core/state-persistence.js +4 -23
  54. package/dist/core/state-schema.d.ts +6 -0
  55. package/dist/core/state-schema.js +9 -0
  56. package/dist/core/state.d.ts +70 -8
  57. package/dist/core/state.js +101 -10
  58. package/dist/core/types.d.ts +47 -0
  59. package/dist/core/urls.d.ts +13 -0
  60. package/dist/core/urls.js +16 -0
  61. package/dist/formatters/json.d.ts +186 -1
  62. package/dist/formatters/json.js +78 -0
  63. package/package.json +1 -1
@@ -0,0 +1,244 @@
1
+ /**
2
+ * Review follow-ups (#1857): open PRs the user reviewed or commented on but
3
+ * did not author, where the author has moved the thread since.
4
+ *
5
+ * `/oss` only tracked PRs the user authored, so a reviewer never heard when
6
+ * the author pushed fixes or asked them something, and had to build the
7
+ * compare URL by hand. This module decides, for one reviewed PR and its
8
+ * fetched activity, whether anything happened after the user's last review
9
+ * or comment that asks for another look:
10
+ * - the author (or anyone else who is not the user or a bot) pushed a
11
+ * non-merge commit after the review;
12
+ * - the author posted a comment, review or inline review comment after it;
13
+ * - anyone other than the user addressed them: a reply in one of the user's
14
+ * inline threads, a quote of the user's own prose, or an @mention. These
15
+ * are the "questions for you".
16
+ *
17
+ * "Pushed after the review" is decided by position, not by date, whenever
18
+ * the review names the head it was made against (`commit_id` on reviews
19
+ * and inline comments): Git dates say when a commit was written, not when
20
+ * it was pushed, so the commits after the reviewed one in the PR's commit
21
+ * list are the new ones. The reviewed SHA also lets the daily phase ask
22
+ * GitHub for `<reviewedSha>...<headSha>`, and the scan flags the cases where
23
+ * that range would mislead: the reviewed commit is gone from the list
24
+ * (`rebased`), upstream was merged in after it (`mergedUpstream`), or the
25
+ * user's last word was a plain comment that names no head (`baseUnknown`).
26
+ *
27
+ * Pure logic only. Fetching lives in reviewed-prs-fetch.ts behind
28
+ * `PRMonitor.fetchReviewedOpenPRs`, `PRMonitor.fetchReviewedPRActivity`
29
+ * and `PRMonitor.fetchCompareStatus`; orchestration, the compare call, the
30
+ * dismiss check and the warnings live in commands/daily-reviewed-prs.ts.
31
+ */
32
+ /** Commits listed per entry; the compare URL has the rest. */
33
+ export declare const REVIEWED_PR_MAX_COMMITS = 25;
34
+ /** Questions listed per entry, oldest first; the thread has the rest. */
35
+ export declare const REVIEWED_PR_MAX_QUESTIONS = 10;
36
+ export type ReviewedPRQuestionKind = 'comment' | 'review' | 'review_comment';
37
+ /** Why a comment counts as addressed to the user. */
38
+ export type ReviewedPRQuestionReason = 'reply' | 'quote' | 'mention';
39
+ /** A comment on a reviewed PR that is addressed to the user. */
40
+ export interface ReviewedPRQuestion {
41
+ author: string;
42
+ createdAt: string;
43
+ kind: ReviewedPRQuestionKind;
44
+ reason: ReviewedPRQuestionReason;
45
+ /** First 200 characters of the comment body. */
46
+ excerpt: string;
47
+ /** Link to the comment on github.com, when the API returned one. */
48
+ url?: string;
49
+ }
50
+ /** One non-merge commit pushed after the user's last review or comment. */
51
+ export interface ReviewedPRCommit {
52
+ sha: string;
53
+ /** GitHub login of the commit author; `unknown` when no account is linked. */
54
+ author: string;
55
+ date: string;
56
+ /** Commit subject line, first 200 characters. */
57
+ subject: string;
58
+ }
59
+ /** A PR the user reviewed where the author has moved the thread since. */
60
+ export interface ReviewedPRFollowUp {
61
+ prUrl: string;
62
+ repo: string;
63
+ number: number;
64
+ title: string;
65
+ /** GitHub login of the PR author. */
66
+ author: string;
67
+ /** When the user last reviewed or commented on the PR. */
68
+ reviewedAt: string;
69
+ /**
70
+ * Head SHA the user's last review or inline comment was made against
71
+ * (`commit_id`). Absent when their last word was a plain comment, which
72
+ * names no head; `baseUnknown` then says whether that matters.
73
+ */
74
+ reviewedSha?: string;
75
+ headSha: string;
76
+ /**
77
+ * `<reviewedSha>...<headSha>`, set only when GitHub confirmed
78
+ * `reviewedSha` is an ancestor of the head and none of `rebased`,
79
+ * `mergedUpstream` or `baseUnknown` applies, so the range shows exactly
80
+ * what changed since the review.
81
+ */
82
+ compareRange?: string;
83
+ /** github.com compare page for `compareRange`. */
84
+ compareUrl?: string;
85
+ /**
86
+ * The reviewed commit is gone from the PR's commit list or is no longer
87
+ * an ancestor of the head (force-push or rebase). There is no honest
88
+ * range; read `commits`, which were then picked by date.
89
+ */
90
+ rebased: boolean;
91
+ /**
92
+ * A merge commit follows the reviewed one (upstream merged into the
93
+ * branch), so `<reviewedSha>...<headSha>` would include the upstream
94
+ * changes. No range; read the per-commit diffs of `commits`.
95
+ */
96
+ mergedUpstream: boolean;
97
+ /**
98
+ * The reviewed commit's place in the PR's commit list is unknown and
99
+ * commits were pushed since: the user's last word was a plain comment,
100
+ * which names no head, or (rarely) `reviewedSha` is known but the commit
101
+ * list was cut at GitHub's cap before reaching it. `commits` were then
102
+ * picked by date, which can miss a cherry-pick or rebased fix carrying an
103
+ * older date, and no range is offered. False when nothing was pushed or
104
+ * when `reviewedSha` was found in the list.
105
+ */
106
+ baseUnknown: boolean;
107
+ /**
108
+ * Non-merge commits by someone other than the user or a bot after the
109
+ * review, oldest first; capped. The commits after `reviewedSha` in the
110
+ * PR's commit list when it is known and still there, else those dated
111
+ * after `reviewedAt`.
112
+ */
113
+ commits: ReviewedPRCommit[];
114
+ /** Commits dropped from `commits` by the cap. */
115
+ moreCommits: number;
116
+ /** Comments by the PR author after `reviewedAt` (questions included). */
117
+ authorComments: number;
118
+ /** Comments addressed to the user after `reviewedAt`, oldest first; capped. */
119
+ questions: ReviewedPRQuestion[];
120
+ /** Questions dropped from `questions` by the cap. */
121
+ moreQuestions: number;
122
+ /**
123
+ * Newest date among the commits and comments that qualified the PR; the
124
+ * dismiss stamp is compared with this. Can predate `reviewedAt` when the
125
+ * only new work is a commit carrying an old author date (cherry-pick).
126
+ */
127
+ latestActivityAt: string;
128
+ /**
129
+ * Newest comment, review or inline comment that qualified the PR (an
130
+ * author reply or a question for the user); absent when only commits did.
131
+ * A dismiss that recorded the PR's head is compared with this: with the
132
+ * head unchanged, only a comment after the dismiss brings the PR back.
133
+ */
134
+ latestCommentAt?: string;
135
+ }
136
+ /** What the search returned for one reviewed PR. */
137
+ export interface ReviewedPRRef {
138
+ url: string;
139
+ repo: string;
140
+ number: number;
141
+ title: string;
142
+ /** GitHub login of the PR author. */
143
+ author: string;
144
+ /** Search API `updated_at`; moves on any activity, so a dismiss at or after it has nothing new to show. */
145
+ updatedAt: string;
146
+ }
147
+ /** The account behind a comment, review or inline comment, as Octokit returns it. */
148
+ export interface ReviewedPRActor {
149
+ user?: {
150
+ login?: string;
151
+ type?: string | null;
152
+ } | null;
153
+ }
154
+ /**
155
+ * Everything on a reviewed PR the scan reads, in the shapes the Octokit
156
+ * endpoints return (structural, so responses assign directly).
157
+ */
158
+ export interface ReviewedPRActivity {
159
+ pr: {
160
+ headSha: string;
161
+ /** `open` for everything the search returned; anything else is skipped (closed between search and fetch). */
162
+ state: string;
163
+ author?: string;
164
+ title?: string;
165
+ };
166
+ comments: Array<ReviewedPRActor & {
167
+ id?: number;
168
+ body?: string | null;
169
+ created_at: string;
170
+ html_url?: string;
171
+ }>;
172
+ reviews: Array<ReviewedPRActor & {
173
+ id?: number;
174
+ body?: string | null;
175
+ submitted_at?: string | null;
176
+ state?: string | null;
177
+ commit_id?: string | null;
178
+ html_url?: string;
179
+ }>;
180
+ reviewComments: Array<ReviewedPRActor & {
181
+ id?: number;
182
+ body?: string | null;
183
+ created_at: string;
184
+ commit_id?: string | null;
185
+ in_reply_to_id?: number;
186
+ /** The review the comment was submitted with; draft comments of the user's own PENDING review carry its id. */
187
+ pull_request_review_id?: number | null;
188
+ html_url?: string;
189
+ }>;
190
+ /** Oldest first, in branch order (GitHub's `listCommits`); the last entry is the head. */
191
+ commits: Array<{
192
+ sha: string;
193
+ author?: {
194
+ login?: string;
195
+ type?: string | null;
196
+ } | null;
197
+ /** GitHub account that last rewrote the commit (`web-flow` for rebases done on github.com). */
198
+ committer?: {
199
+ login?: string;
200
+ type?: string | null;
201
+ } | null;
202
+ commit: {
203
+ message?: string | null;
204
+ author?: {
205
+ date?: string | null;
206
+ } | null;
207
+ committer?: {
208
+ date?: string | null;
209
+ } | null;
210
+ };
211
+ /** More than one parent marks a merge commit ("Update branch"), which carries no new work. */
212
+ parents?: Array<{
213
+ sha?: string;
214
+ }>;
215
+ }>;
216
+ /**
217
+ * Lists cut short by a pagination cap, as `PRMonitor.fetchReviewedPRActivity`
218
+ * reports them. The daily phase drops such PRs before the scan; the scan
219
+ * still reads it so a `commits` cut is never mistaken for a rebase.
220
+ */
221
+ truncatedLists?: ReviewedPRActivityList[];
222
+ }
223
+ /** The lists `PRMonitor.fetchReviewedPRActivity` fetches, as named in truncation warnings. */
224
+ export type ReviewedPRActivityList = 'comments' | 'reviews' | 'review comments' | 'commits';
225
+ /**
226
+ * Scan one reviewed PR's activity. Returns the follow-up when something
227
+ * after the user's last comment, review or inline comment asks for another
228
+ * look, or null when:
229
+ * - the user never commented or reviewed (the search can return a PR whose
230
+ * only comment of theirs was deleted), or the PR is no longer open;
231
+ * - nothing happened since: no non-merge commit by a non-bot account other
232
+ * than the user, no non-reaction comment by the PR author, and no comment
233
+ * addressed to the user (reply in one of their inline threads, quote of
234
+ * their prose, @mention) by anyone who is not the user or a bot;
235
+ * - the user's only words on the PR were reactions ("+1", "same here"):
236
+ * then pushes and author replies are not for them, and only a comment
237
+ * addressed to them counts.
238
+ *
239
+ * `rebased`, `mergedUpstream` and `baseUnknown` come from the commit list
240
+ * (see `commitsSince`); `compareRange` and `compareUrl` are left for the
241
+ * daily phase, which asks GitHub whether `reviewedSha` is still an ancestor
242
+ * of the head when none of the three applies.
243
+ */
244
+ export declare function scanReviewedPR(ref: ReviewedPRRef, activity: ReviewedPRActivity, username: string): ReviewedPRFollowUp | null;
@@ -0,0 +1,380 @@
1
+ /**
2
+ * Review follow-ups (#1857): open PRs the user reviewed or commented on but
3
+ * did not author, where the author has moved the thread since.
4
+ *
5
+ * `/oss` only tracked PRs the user authored, so a reviewer never heard when
6
+ * the author pushed fixes or asked them something, and had to build the
7
+ * compare URL by hand. This module decides, for one reviewed PR and its
8
+ * fetched activity, whether anything happened after the user's last review
9
+ * or comment that asks for another look:
10
+ * - the author (or anyone else who is not the user or a bot) pushed a
11
+ * non-merge commit after the review;
12
+ * - the author posted a comment, review or inline review comment after it;
13
+ * - anyone other than the user addressed them: a reply in one of the user's
14
+ * inline threads, a quote of the user's own prose, or an @mention. These
15
+ * are the "questions for you".
16
+ *
17
+ * "Pushed after the review" is decided by position, not by date, whenever
18
+ * the review names the head it was made against (`commit_id` on reviews
19
+ * and inline comments): Git dates say when a commit was written, not when
20
+ * it was pushed, so the commits after the reviewed one in the PR's commit
21
+ * list are the new ones. The reviewed SHA also lets the daily phase ask
22
+ * GitHub for `<reviewedSha>...<headSha>`, and the scan flags the cases where
23
+ * that range would mislead: the reviewed commit is gone from the list
24
+ * (`rebased`), upstream was merged in after it (`mergedUpstream`), or the
25
+ * user's last word was a plain comment that names no head (`baseUnknown`).
26
+ *
27
+ * Pure logic only. Fetching lives in reviewed-prs-fetch.ts behind
28
+ * `PRMonitor.fetchReviewedOpenPRs`, `PRMonitor.fetchReviewedPRActivity`
29
+ * and `PRMonitor.fetchCompareStatus`; orchestration, the compare call, the
30
+ * dismiss check and the warnings live in commands/daily-reviewed-prs.ts.
31
+ */
32
+ import { isBotAuthor, isQuoteReplyTo, isReactionOnlyComment, proseWithoutCode } from './comment-utils.js';
33
+ import { debug } from './logger.js';
34
+ const MODULE = 'reviewed-prs';
35
+ /** Longest excerpt carried in the digest; matches `lastMaintainerComment`. */
36
+ const EXCERPT_LENGTH = 200;
37
+ /** Commits listed per entry; the compare URL has the rest. */
38
+ export const REVIEWED_PR_MAX_COMMITS = 25;
39
+ /** Questions listed per entry, oldest first; the thread has the rest. */
40
+ export const REVIEWED_PR_MAX_QUESTIONS = 10;
41
+ function parseMs(value) {
42
+ if (!value)
43
+ return undefined;
44
+ const ms = Date.parse(value);
45
+ return Number.isNaN(ms) ? undefined : ms;
46
+ }
47
+ function excerptOf(body) {
48
+ const flat = body.replaceAll(/\s+/g, ' ').trim();
49
+ return flat.length > EXCERPT_LENGTH ? `${flat.slice(0, EXCERPT_LENGTH)}...` : flat;
50
+ }
51
+ function byTime(a, b) {
52
+ return Date.parse(a.createdAt) - Date.parse(b.createdAt);
53
+ }
54
+ function isUserLogin(login, usernameLower) {
55
+ return login?.toLowerCase() === usernameLower;
56
+ }
57
+ /** `@login` as a whole token: not inside an email, a handle like `@login-bot`, or a path. */
58
+ function mentionPattern(username) {
59
+ const escaped = username.replaceAll(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`);
60
+ return new RegExp(String.raw `(?<![\w-])@${escaped}(?![\w-])`, 'i');
61
+ }
62
+ /** One thread entry, or undefined when its timestamp is missing or unreadable. */
63
+ function toThreadEntry({ at, body, commitId, ...rest }) {
64
+ const atMs = parseMs(at);
65
+ if (!at || atMs === undefined)
66
+ return undefined;
67
+ return { ...rest, at, atMs, body: body ?? '', ...(commitId && { commitId }) };
68
+ }
69
+ /**
70
+ * The comment-shaped activity as one stream. GitHub returns the
71
+ * authenticated user's own PENDING review (unsubmitted, `submitted_at`
72
+ * null) and can return its draft comments (`pull_request_review_id` of that
73
+ * review); neither has been said yet, so both are left out rather than
74
+ * counted as the user's last word.
75
+ */
76
+ function threadEntries(activity) {
77
+ const pendingReviewIds = new Set(activity.reviews.filter((r) => r.state === 'PENDING' && r.id !== undefined).map((r) => r.id));
78
+ const inputs = [
79
+ ...activity.comments.map((c) => ({
80
+ actor: c,
81
+ body: c.body,
82
+ at: c.created_at,
83
+ kind: 'comment',
84
+ url: c.html_url,
85
+ })),
86
+ ...activity.reviews
87
+ .filter((r) => r.state !== 'PENDING')
88
+ .map((r) => ({
89
+ actor: r,
90
+ body: r.body,
91
+ at: r.submitted_at,
92
+ kind: 'review',
93
+ url: r.html_url,
94
+ commitId: r.commit_id,
95
+ })),
96
+ ...activity.reviewComments
97
+ .filter((c) => c.pull_request_review_id == null || !pendingReviewIds.has(c.pull_request_review_id))
98
+ .map((c) => ({
99
+ actor: c,
100
+ body: c.body,
101
+ at: c.created_at,
102
+ kind: 'review_comment',
103
+ url: c.html_url,
104
+ threadId: c.in_reply_to_id ?? c.id,
105
+ commitId: c.commit_id,
106
+ })),
107
+ ];
108
+ return inputs.map((input) => toThreadEntry(input)).filter((entry) => entry !== undefined);
109
+ }
110
+ function scanUser(entries, usernameLower) {
111
+ const user = { reviewed: false, threadLastMs: new Map(), bodies: [] };
112
+ for (const entry of entries) {
113
+ if (!isUserLogin(entry.actor.user?.login, usernameLower))
114
+ continue;
115
+ if (!user.last || entry.atMs > user.last.atMs)
116
+ user.last = entry;
117
+ if (entry.kind !== 'comment' || !isReactionOnlyComment(entry.body))
118
+ user.reviewed = true;
119
+ if (entry.body.trim())
120
+ user.bodies.push(entry.body);
121
+ if (entry.threadId !== undefined) {
122
+ user.threadLastMs.set(entry.threadId, Math.max(user.threadLastMs.get(entry.threadId) ?? -Infinity, entry.atMs));
123
+ }
124
+ }
125
+ return user;
126
+ }
127
+ /**
128
+ * The date a commit was pushed under: the committer date when the author
129
+ * also committed it (their own amend or rebase moved it, which is the
130
+ * force-push case this feature exists for), the author date when someone
131
+ * else rewrote it (a maintainer's rebase does not make the author's old
132
+ * work new). Either falls back to the other when missing.
133
+ */
134
+ function commitDateOf(entry) {
135
+ const authorDate = entry.commit.author?.date;
136
+ const committerDate = entry.commit.committer?.date;
137
+ const login = entry.author?.login?.toLowerCase();
138
+ const isOwnRewrite = login !== undefined && entry.committer?.login?.toLowerCase() === login;
139
+ return isOwnRewrite ? (committerDate ?? authorDate) : (authorDate ?? committerDate);
140
+ }
141
+ /** More than one parent: an "Update branch" or upstream merge, which carries no new work of its own. */
142
+ function isMergeCommit(entry) {
143
+ return (entry.parents?.length ?? 0) > 1;
144
+ }
145
+ /** A dated non-merge commit, or undefined for a merge commit or one without a usable date. */
146
+ function toDatedCommit(entry, usernameLower) {
147
+ if (isMergeCommit(entry))
148
+ return undefined;
149
+ const date = commitDateOf(entry);
150
+ const atMs = parseMs(date);
151
+ if (!date || atMs === undefined)
152
+ return undefined;
153
+ const login = entry.author?.login;
154
+ return {
155
+ date,
156
+ atMs,
157
+ sha: entry.sha,
158
+ author: login ?? 'unknown',
159
+ subject: excerptOf((entry.commit.message ?? '').split('\n', 1)[0]),
160
+ isUser: isUserLogin(login, usernameLower),
161
+ isBot: login !== undefined && isBotAuthor(login, entry.author?.type),
162
+ };
163
+ }
164
+ /** Non-merge commits with a usable date, by non-bot accounts other than the user, in list order. */
165
+ function othersCommits(commits, usernameLower) {
166
+ return commits
167
+ .map((entry) => toDatedCommit(entry, usernameLower))
168
+ .filter((commit) => commit !== undefined)
169
+ .filter((commit) => !commit.isUser && !commit.isBot);
170
+ }
171
+ /**
172
+ * A review or inline comment names the head it was made against
173
+ * (`commit_id`), so the commits after it in the PR's commit list (oldest
174
+ * first, branch order) are the new ones whatever their dates say: Git dates
175
+ * record when a commit was written, not when it was pushed, so a
176
+ * cherry-pick or a rebased fix can carry a date older than the review.
177
+ * When the reviewed commit is gone from the list the branch was rebased or
178
+ * force-pushed; dates are all that is left, and `rebased` says so. A merge
179
+ * commit after the reviewed one means upstream was merged in, so a compare
180
+ * range would show upstream's changes too (`mergedUpstream`).
181
+ *
182
+ * A plain comment names no head: its commits are the ones dated after it,
183
+ * and `baseUnknown` is set when there are any, so the workflow knows the
184
+ * list is approximate and offers no range. The same applies when the
185
+ * reviewed commit is missing from a list that was cut by a pagination cap
186
+ * (`activity.truncatedLists` names `commits`): the newest commits are the
187
+ * ones missing, so the reviewed one may simply be past the cut, and that is
188
+ * not a rebase.
189
+ */
190
+ function commitsSince(activity, last, usernameLower) {
191
+ const datedAfterLast = () => othersCommits(activity.commits, usernameLower).filter((commit) => commit.atMs > last.atMs);
192
+ const reviewedSha = last.commitId;
193
+ if (reviewedSha === undefined) {
194
+ const pushed = datedAfterLast();
195
+ return { pushed, rebased: false, mergedUpstream: false, baseUnknown: pushed.length > 0 };
196
+ }
197
+ const index = activity.commits.findIndex((commit) => commit.sha === reviewedSha);
198
+ if (index === -1) {
199
+ const pushed = datedAfterLast();
200
+ if (activity.truncatedLists?.includes('commits')) {
201
+ return { reviewedSha, pushed, rebased: false, mergedUpstream: false, baseUnknown: pushed.length > 0 };
202
+ }
203
+ return { reviewedSha, pushed, rebased: true, mergedUpstream: false, baseUnknown: false };
204
+ }
205
+ const after = activity.commits.slice(index + 1);
206
+ return {
207
+ reviewedSha,
208
+ pushed: othersCommits(after, usernameLower),
209
+ rebased: false,
210
+ mergedUpstream: after.some((commit) => isMergeCommit(commit)),
211
+ baseUnknown: false,
212
+ };
213
+ }
214
+ /**
215
+ * Why an entry is addressed to the user, or undefined when it is not. An
216
+ * @mention counts only in the author's own prose: not inside a quoted line,
217
+ * a code fence or an inline code span (someone else's words, or a literal).
218
+ */
219
+ function questionReason(entry, user, mention) {
220
+ if (entry.threadId !== undefined) {
221
+ const userLastMs = user.threadLastMs.get(entry.threadId);
222
+ if (userLastMs !== undefined && entry.atMs > userLastMs)
223
+ return 'reply';
224
+ }
225
+ if (user.bodies.some((body) => isQuoteReplyTo(entry.body, body)))
226
+ return 'quote';
227
+ if (mention.test(proseWithoutCode(entry.body)))
228
+ return 'mention';
229
+ return undefined;
230
+ }
231
+ /** Newest-timestamp tracker over the activity that qualifies the PR. */
232
+ function latestTracker() {
233
+ let latest = { at: '', atMs: -Infinity };
234
+ return {
235
+ note: (at, atMs) => {
236
+ if (atMs > latest.atMs)
237
+ latest = { at, atMs };
238
+ },
239
+ at: () => latest.at,
240
+ };
241
+ }
242
+ /**
243
+ * Whether `entry` counts, and why: `question` when it is addressed to the
244
+ * user, `author` when it is a non-reaction reply by the PR author, or
245
+ * nothing for everyone else (the user, bots, bystanders not addressing them).
246
+ */
247
+ function classifyEntry(entry, { usernameLower, authorLower, user, mention }) {
248
+ const login = entry.actor.user?.login;
249
+ const text = entry.body.trim();
250
+ if (!login || !text || isUserLogin(login, usernameLower) || isBotAuthor(login, entry.actor.user?.type)) {
251
+ return undefined;
252
+ }
253
+ const reason = questionReason(entry, user, mention);
254
+ const isAuthorReply = login.toLowerCase() === authorLower && !isReactionOnlyComment(text);
255
+ if (!reason && !isAuthorReply)
256
+ return undefined;
257
+ return { reason, isAuthorReply, text };
258
+ }
259
+ /** The comment activity after the user's last word, with `pushed` folded into `latestAt`. */
260
+ function collectActivitySince(entries, pushed, context) {
261
+ const reviewedMs = context.user.last?.atMs ?? Infinity;
262
+ const latest = latestTracker();
263
+ const latestComment = latestTracker();
264
+ for (const commit of pushed)
265
+ latest.note(commit.date, commit.atMs);
266
+ const questions = [];
267
+ let authorComments = 0;
268
+ for (const entry of entries) {
269
+ const verdict = entry.atMs > reviewedMs ? classifyEntry(entry, context) : undefined;
270
+ if (!verdict)
271
+ continue;
272
+ if (verdict.isAuthorReply)
273
+ authorComments++;
274
+ latest.note(entry.at, entry.atMs);
275
+ latestComment.note(entry.at, entry.atMs);
276
+ if (verdict.reason) {
277
+ const { kind, at: createdAt, url } = entry;
278
+ const login = entry.actor.user?.login ?? 'unknown';
279
+ questions.push({
280
+ kind,
281
+ createdAt,
282
+ author: login,
283
+ reason: verdict.reason,
284
+ excerpt: excerptOf(verdict.text),
285
+ ...(url !== undefined && { url }),
286
+ });
287
+ }
288
+ }
289
+ questions.sort(byTime);
290
+ return { authorComments, questions, latestAt: latest.at(), latestCommentAt: latestComment.at() };
291
+ }
292
+ /** Reasons the scan skips a PR before looking at what happened since the review. */
293
+ function skipReason(activity, author, username) {
294
+ if (activity.pr.state !== 'open')
295
+ return `state is ${activity.pr.state}, not open`;
296
+ if (isUserLogin(author, username.toLowerCase()))
297
+ return 'authored by the user';
298
+ return null;
299
+ }
300
+ /** Why nothing is reported for a scanned PR, or null when the follow-up stands. */
301
+ function quietReason(since, pushed, user, username) {
302
+ if (since.questions.length > 0)
303
+ return null;
304
+ if (!user.reviewed)
305
+ return `${username} only reacted on it and nobody addressed them`;
306
+ if (pushed === 0 && since.authorComments === 0)
307
+ return 'nothing since the review';
308
+ return null;
309
+ }
310
+ /**
311
+ * Scan one reviewed PR's activity. Returns the follow-up when something
312
+ * after the user's last comment, review or inline comment asks for another
313
+ * look, or null when:
314
+ * - the user never commented or reviewed (the search can return a PR whose
315
+ * only comment of theirs was deleted), or the PR is no longer open;
316
+ * - nothing happened since: no non-merge commit by a non-bot account other
317
+ * than the user, no non-reaction comment by the PR author, and no comment
318
+ * addressed to the user (reply in one of their inline threads, quote of
319
+ * their prose, @mention) by anyone who is not the user or a bot;
320
+ * - the user's only words on the PR were reactions ("+1", "same here"):
321
+ * then pushes and author replies are not for them, and only a comment
322
+ * addressed to them counts.
323
+ *
324
+ * `rebased`, `mergedUpstream` and `baseUnknown` come from the commit list
325
+ * (see `commitsSince`); `compareRange` and `compareUrl` are left for the
326
+ * daily phase, which asks GitHub whether `reviewedSha` is still an ancestor
327
+ * of the head when none of the three applies.
328
+ */
329
+ export function scanReviewedPR(ref, activity, username) {
330
+ const author = activity.pr.author ?? ref.author;
331
+ const skip = skipReason(activity, author, username);
332
+ if (skip !== null) {
333
+ debug(MODULE, `Skipping ${ref.url}: ${skip}`);
334
+ return null;
335
+ }
336
+ const usernameLower = username.toLowerCase();
337
+ const entries = threadEntries(activity);
338
+ const user = scanUser(entries, usernameLower);
339
+ if (!user.last) {
340
+ debug(MODULE, `Skipping ${ref.url}: no comment or review by ${username}`);
341
+ return null;
342
+ }
343
+ const { pushed, reviewedSha, rebased, mergedUpstream, baseUnknown } = commitsSince(activity, user.last, usernameLower);
344
+ const since = collectActivitySince(entries, pushed, {
345
+ user,
346
+ usernameLower,
347
+ authorLower: author.toLowerCase(),
348
+ mention: mentionPattern(username),
349
+ });
350
+ const quiet = quietReason(since, pushed.length, user, username);
351
+ if (quiet !== null) {
352
+ debug(MODULE, `Skipping ${ref.url}: ${quiet}`);
353
+ return null;
354
+ }
355
+ return {
356
+ author,
357
+ rebased,
358
+ mergedUpstream,
359
+ baseUnknown,
360
+ prUrl: ref.url,
361
+ repo: ref.repo,
362
+ number: ref.number,
363
+ title: activity.pr.title ?? ref.title,
364
+ reviewedAt: user.last.at,
365
+ ...(reviewedSha !== undefined && { reviewedSha }),
366
+ headSha: activity.pr.headSha,
367
+ commits: pushed.slice(0, REVIEWED_PR_MAX_COMMITS).map(({ sha, author: login, date, subject }) => ({
368
+ sha,
369
+ date,
370
+ subject,
371
+ author: login,
372
+ })),
373
+ moreCommits: Math.max(0, pushed.length - REVIEWED_PR_MAX_COMMITS),
374
+ authorComments: since.authorComments,
375
+ questions: since.questions.slice(0, REVIEWED_PR_MAX_QUESTIONS),
376
+ moreQuestions: Math.max(0, since.questions.length - REVIEWED_PR_MAX_QUESTIONS),
377
+ latestActivityAt: since.latestAt,
378
+ ...(since.latestCommentAt !== '' && { latestCommentAt: since.latestCommentAt }),
379
+ };
380
+ }
@@ -411,29 +411,10 @@ export function loadState() {
411
411
  debug(MODULE, 'Migrated and validated state saved');
412
412
  }
413
413
  const state = parsed.data;
414
- // Strip PR URLs from dismissedIssues (PR dismiss removed).
415
- // This filters values inside a known field — Zod .strip() only removes unknown keys.
416
- try {
417
- let needsCleanupSave = false;
418
- if (state.config.dismissedIssues) {
419
- const PR_URL_RE = /\/pull\/\d+$/;
420
- for (const url of Object.keys(state.config.dismissedIssues)) {
421
- if (PR_URL_RE.test(url)) {
422
- delete state.config.dismissedIssues[url];
423
- needsCleanupSave = true;
424
- }
425
- }
426
- }
427
- if (needsCleanupSave) {
428
- atomicWriteFileSync(statePath, serializeState(state), 0o600);
429
- mtimeMs = safeGetMtimeMs(statePath); // our own write, as above
430
- warn(MODULE, 'Cleaned up dismissed PR URLs from persisted state');
431
- }
432
- }
433
- catch (cleanupError) {
434
- warn(MODULE, `Failed to clean up removed features from state: ${errorMessage(cleanupError)}`);
435
- // Continue with loaded state — cleanup will be retried on next load
436
- }
414
+ // `config.dismissedIssues` keys are issue AND PR URLs: `dismiss` accepts
415
+ // a merged PR's URL for the merged-PR notes nudge (#1861). The former
416
+ // "PR dismiss removed" load-time strip of `/pull/N` keys is gone; it
417
+ // would have undone every PR dismiss on the next load.
437
418
  // Log appropriate message based on version
438
419
  const repoCount = Object.keys(state.repoScores).length;
439
420
  debug(MODULE, `Loaded state v${state.version}: ${repoCount} repo scores tracked`);