@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
@@ -3,7 +3,7 @@
3
3
  * Handles GitHub API calls, PR grouping, stats computation, and monthly chart data.
4
4
  * Consumed by the dashboard HTTP server (dashboard-server.ts) for the SPA API.
5
5
  */
6
- import { getStateManager, PRMonitor, IssueConversationMonitor, getOctokit, CRITICAL_STATUSES, applyStatusOverrides, toShelvedPRRef, buildStarFilter, firstMaintainerResponseFromDigest, lastReviewStateFromDigest, } from '../core/index.js';
6
+ import { getStateManager, PRMonitor, IssueConversationMonitor, getOctokit, CRITICAL_STATUSES, applyStatusOverrides, collectEngagedIssues, toShelvedPRRef, buildStarFilter, firstMaintainerResponseFromDigest, lastReviewStateFromDigest, } from '../core/index.js';
7
7
  import { errorMessage, isRateLimitOrAuthError } from '../core/errors.js';
8
8
  import { warn } from '../core/logger.js';
9
9
  import { emptyPRCountsResult, fetchMergedPRsSince, fetchClosedPRsSince } from '../core/github-stats.js';
@@ -165,6 +165,14 @@ export function updateMonthlyAnalytics(prs, monthlyCounts, monthlyClosedCounts,
165
165
  }
166
166
  return failures;
167
167
  }
168
+ /**
169
+ * The partial-data banner entry for the issue monitor's notices (#1862): the
170
+ * direct-fetch cap, a gone issue, a truncated thread. The monitor already
171
+ * logged each one; the banner lists operations, so they collapse to one label.
172
+ */
173
+ function engagedScanLabels(issueMonitorWarnings) {
174
+ return issueMonitorWarnings.length > 0 ? ['scan engaged issues'] : [];
175
+ }
168
176
  /**
169
177
  * Fetch fresh dashboard data from GitHub.
170
178
  * Returns the digest and commented issues, updating state as a side effect.
@@ -217,7 +225,7 @@ export async function fetchDashboardData(token) {
217
225
  return fallback;
218
226
  };
219
227
  };
220
- const [{ prs, failures, warnings: fetchWarnings }, recentlyClosedPRs, recentlyMergedPRs, mergedResult, closedResult, fetchedIssues, newMergedPRs, newClosedPRs,] = await Promise.all([
228
+ const [{ prs, failures, warnings: fetchWarnings }, recentlyClosedPRs, recentlyMergedPRs, mergedResult, closedResult, newMergedPRs, newClosedPRs,] = await Promise.all([
221
229
  prMonitor.fetchUserOpenPRs(),
222
230
  prMonitor.fetchRecentlyClosedPRs().catch(trackingCatch('fetch recently closed PRs', [])),
223
231
  prMonitor.fetchRecentlyMergedPRs().catch(trackingCatch('fetch recently merged PRs', [])),
@@ -227,27 +235,39 @@ export async function fetchDashboardData(token) {
227
235
  prMonitor
228
236
  .fetchUserClosedPRCounts(starFilter)
229
237
  .catch(trackingCatch('fetch closed PR counts', emptyPRCountsResult())),
230
- // Issue conversation fetch has custom messaging based on the error content, so it keeps its bespoke catch.
231
- issueMonitor.fetchCommentedIssues().catch((error) => {
232
- if (isRateLimitOrAuthError(error))
233
- throw error;
234
- const msg = errorMessage(error);
235
- if (msg.includes('No GitHub username configured')) {
236
- warn(MODULE, `Issue conversation tracking requires setup: ${msg}`);
237
- }
238
- else {
239
- warn(MODULE, `Issue conversation fetch failed: ${msg}`);
240
- partialFailures.push('fetch issue conversations');
241
- }
242
- return {
243
- issues: [],
244
- failures: [{ issueUrl: 'N/A', error: `Issue conversation fetch failed: ${msg}` }],
245
- };
246
- }),
247
238
  fetchMergedPRsSince(octokit, config, mergedFetchSince).catch(trackingCatch('fetch merged PRs for storage', [])),
248
239
  fetchClosedPRsSince(octokit, config, closedWatermark).catch(trackingCatch('fetch closed PRs for storage', [])),
249
240
  ]);
250
- const commentedIssues = fetchedIssues.issues;
241
+ // Issue conversations run after the PR lists: the engaged set (#1862)
242
+ // needs the open, recently closed and recently merged PRs. The fetch has
243
+ // custom messaging based on the error content, so it keeps its bespoke catch.
244
+ const engaged = collectEngagedIssues({
245
+ recentlyClosedPRs,
246
+ recentlyMergedPRs,
247
+ claims: stateManager.getState().activeIssues,
248
+ openPRs: prs,
249
+ ledgerClosedPRs: stateManager.getClosedPRs(),
250
+ ledgerMergedPRs: stateManager.getMergedPRs(),
251
+ });
252
+ const fetchedIssues = await issueMonitor.fetchCommentedIssues({ engaged }).catch((error) => {
253
+ if (isRateLimitOrAuthError(error))
254
+ throw error;
255
+ const msg = errorMessage(error);
256
+ if (msg.includes('No GitHub username configured')) {
257
+ warn(MODULE, `Issue conversation tracking requires setup: ${msg}`);
258
+ }
259
+ else {
260
+ warn(MODULE, `Issue conversation fetch failed: ${msg}`);
261
+ partialFailures.push('fetch issue conversations');
262
+ }
263
+ return {
264
+ issues: [],
265
+ failures: [{ issueUrl: 'N/A', error: `Issue conversation fetch failed: ${msg}` }],
266
+ warnings: [],
267
+ };
268
+ });
269
+ const { issues: commentedIssues, warnings: issueMonitorWarnings } = fetchedIssues;
270
+ partialFailures.push(...engagedScanLabels(issueMonitorWarnings));
251
271
  if (fetchedIssues.failures.length > 0) {
252
272
  warn(MODULE, `${fetchedIssues.failures.length} issue conversation check(s) failed`);
253
273
  }
@@ -39,6 +39,10 @@ export declare class GistSyncCoordinator {
39
39
  /** Push-before-pull (#1417): an un-pushed mutation would be silently
40
40
  * reverted by the next Gist pull. Retry the checkpoint first so a recovered
41
41
  * network turns the pending warning into a real push before any pull runs.
42
+ * Also pushes saves that never recorded a warning: fetchDashboardData
43
+ * writes the digest and merged/closed caches through save() with no
44
+ * checkpoint, and the pull right after it reverted them and raised the
45
+ * "un-pushed changes" stale banner on every refresh.
42
46
  * No-op when nothing is pending. */
43
47
  flushPendingGistSync(): Promise<void>;
44
48
  /** One health snapshot from the one source (#1444). Defensive: this is an
@@ -110,9 +110,13 @@ export class GistSyncCoordinator {
110
110
  /** Push-before-pull (#1417): an un-pushed mutation would be silently
111
111
  * reverted by the next Gist pull. Retry the checkpoint first so a recovered
112
112
  * network turns the pending warning into a real push before any pull runs.
113
+ * Also pushes saves that never recorded a warning: fetchDashboardData
114
+ * writes the digest and merged/closed caches through save() with no
115
+ * checkpoint, and the pull right after it reverted them and raised the
116
+ * "un-pushed changes" stale banner on every refresh.
113
117
  * No-op when nothing is pending. */
114
118
  async flushPendingGistSync() {
115
- if (this.pendingGistSyncWarnings.length === 0)
119
+ if (this.pendingGistSyncWarnings.length === 0 && !this.manager.hasUnpushedChanges())
116
120
  return;
117
121
  this.recordGistSyncOutcome(await maybeCheckpoint(this.manager, this.module));
118
122
  }
@@ -2,6 +2,14 @@
2
2
  * Dismiss/Undismiss commands
3
3
  * Manages dismissing issue notifications without posting a comment.
4
4
  * Dismissed URLs resurface automatically when new responses arrive after the dismiss timestamp.
5
+ *
6
+ * PR URLs are accepted too: dismissing a merged PR's URL declines the
7
+ * "merged PR with maintainer notes" nudge (#1861), and dismissing a PR the
8
+ * user reviewed declines its review follow-up (#1857), for the activity
9
+ * posted so far, with the same stamp-based resurfacing when newer activity
10
+ * lands. A review follow-up dismissed with `--head <sha>` also records the
11
+ * PR's head, so a push (new head) brings it back while bot, label and
12
+ * bystander updates do not; see `daily-reviewed-prs.ts`.
5
13
  */
6
14
  export interface DismissOutput {
7
15
  dismissed: boolean;
@@ -19,21 +27,33 @@ export interface UndismissOutput {
19
27
  * Dismiss an issue's reply notifications without posting a comment.
20
28
  * The dismissal auto-resurfaces when new responses arrive after the dismiss timestamp.
21
29
  *
30
+ * A PR URL is always re-stamped: the merged-PR notes and review follow-up
31
+ * phases compare the stamp with the newest activity, so a second "skip" after
32
+ * newer activity has to move the stamp forward or it would be a no-op. Issue dismissals keep their first
33
+ * stamp (the issue path auto-undismisses on new activity instead).
34
+ *
22
35
  * @param options - Dismiss options
23
- * @param options.url - Full GitHub issue URL
24
- * @returns Whether the issue was newly dismissed (false if already dismissed)
25
- * @throws {ValidationError} If the URL is not a valid GitHub issue URL
36
+ * @param options.url - Full GitHub issue or PR URL
37
+ * @param options.head - For a PR URL: the PR's full head SHA at dismiss time
38
+ * (the review follow-up entry's `headSha`). Recorded so the follow-up stays
39
+ * hidden until the head moves or someone comments after the dismiss.
40
+ * Without it, only the stamp decides, and any update to the PR can resurface it.
41
+ * @returns Whether the issue was newly dismissed (false if already dismissed);
42
+ * always true for a PR URL
43
+ * @throws {ValidationError} If the URL is not a valid GitHub issue or PR URL,
44
+ * if `head` is not a full 40-hex SHA, or if `head` is given with an issue URL
26
45
  */
27
46
  export declare function runDismiss(options: {
28
47
  url: string;
48
+ head?: string;
29
49
  }): Promise<DismissOutput>;
30
50
  /**
31
51
  * Restore a dismissed issue to notifications.
32
52
  *
33
53
  * @param options - Undismiss options
34
- * @param options.url - Full GitHub issue URL
54
+ * @param options.url - Full GitHub issue or PR URL
35
55
  * @returns Whether the issue was undismissed (false if not currently dismissed)
36
- * @throws {ValidationError} If the URL is not a valid GitHub issue URL
56
+ * @throws {ValidationError} If the URL is not a valid GitHub issue or PR URL
37
57
  */
38
58
  export declare function runUndismiss(options: {
39
59
  url: string;
@@ -2,39 +2,67 @@
2
2
  * Dismiss/Undismiss commands
3
3
  * Manages dismissing issue notifications without posting a comment.
4
4
  * Dismissed URLs resurface automatically when new responses arrive after the dismiss timestamp.
5
+ *
6
+ * PR URLs are accepted too: dismissing a merged PR's URL declines the
7
+ * "merged PR with maintainer notes" nudge (#1861), and dismissing a PR the
8
+ * user reviewed declines its review follow-up (#1857), for the activity
9
+ * posted so far, with the same stamp-based resurfacing when newer activity
10
+ * lands. A review follow-up dismissed with `--head <sha>` also records the
11
+ * PR's head, so a push (new head) brings it back while bot, label and
12
+ * bystander updates do not; see `daily-reviewed-prs.ts`.
5
13
  */
6
14
  import { getStateManager, maybeCheckpoint } from '../core/index.js';
7
- import { ISSUE_URL_PATTERN, validateGitHubUrl, validateUrl } from './validation.js';
15
+ import { ValidationError } from '../core/errors.js';
16
+ import { ISSUE_OR_PR_URL_PATTERN, PR_URL_PATTERN, validateCommitSha, validateGitHubUrl, validateUrl, } from './validation.js';
8
17
  const MODULE = 'dismiss';
9
18
  /**
10
19
  * Dismiss an issue's reply notifications without posting a comment.
11
20
  * The dismissal auto-resurfaces when new responses arrive after the dismiss timestamp.
12
21
  *
22
+ * A PR URL is always re-stamped: the merged-PR notes and review follow-up
23
+ * phases compare the stamp with the newest activity, so a second "skip" after
24
+ * newer activity has to move the stamp forward or it would be a no-op. Issue dismissals keep their first
25
+ * stamp (the issue path auto-undismisses on new activity instead).
26
+ *
13
27
  * @param options - Dismiss options
14
- * @param options.url - Full GitHub issue URL
15
- * @returns Whether the issue was newly dismissed (false if already dismissed)
16
- * @throws {ValidationError} If the URL is not a valid GitHub issue URL
28
+ * @param options.url - Full GitHub issue or PR URL
29
+ * @param options.head - For a PR URL: the PR's full head SHA at dismiss time
30
+ * (the review follow-up entry's `headSha`). Recorded so the follow-up stays
31
+ * hidden until the head moves or someone comments after the dismiss.
32
+ * Without it, only the stamp decides, and any update to the PR can resurface it.
33
+ * @returns Whether the issue was newly dismissed (false if already dismissed);
34
+ * always true for a PR URL
35
+ * @throws {ValidationError} If the URL is not a valid GitHub issue or PR URL,
36
+ * if `head` is not a full 40-hex SHA, or if `head` is given with an issue URL
17
37
  */
18
38
  export async function runDismiss(options) {
19
39
  validateUrl(options.url);
20
- validateGitHubUrl(options.url, ISSUE_URL_PATTERN, 'issue');
40
+ validateGitHubUrl(options.url, ISSUE_OR_PR_URL_PATTERN, 'issue or PR');
41
+ const isPR = PR_URL_PATTERN.test(options.url);
42
+ if (!isPR && options.head !== undefined) {
43
+ throw new ValidationError('--head applies to PR URLs only: a dismissed issue has no head commit');
44
+ }
21
45
  const stateManager = getStateManager();
22
46
  const dismissedAt = new Date().toISOString();
23
- const added = stateManager.dismissIssue(options.url, dismissedAt);
24
- const gistSyncWarning = await maybeCheckpoint(stateManager, MODULE, () => stateManager.dismissIssue(options.url, dismissedAt));
47
+ const dismissOptions = {
48
+ refresh: isPR,
49
+ ...(options.head !== undefined && { headSha: validateCommitSha(options.head) }),
50
+ };
51
+ const added = stateManager.dismissIssue(options.url, dismissedAt, dismissOptions);
52
+ const gistSyncWarning = await maybeCheckpoint(stateManager, MODULE, () => stateManager.dismissIssue(options.url, dismissedAt, dismissOptions));
25
53
  return { dismissed: added, url: options.url, ...(gistSyncWarning && { gistSyncWarning }) };
26
54
  }
27
55
  /**
28
56
  * Restore a dismissed issue to notifications.
29
57
  *
30
58
  * @param options - Undismiss options
31
- * @param options.url - Full GitHub issue URL
59
+ * @param options.url - Full GitHub issue or PR URL
32
60
  * @returns Whether the issue was undismissed (false if not currently dismissed)
33
- * @throws {ValidationError} If the URL is not a valid GitHub issue URL
61
+ * @throws {ValidationError} If the URL is not a valid GitHub issue or PR URL
34
62
  */
35
63
  export async function runUndismiss(options) {
36
64
  validateUrl(options.url);
37
- validateGitHubUrl(options.url, ISSUE_URL_PATTERN, 'issue');
65
+ validateGitHubUrl(options.url, ISSUE_OR_PR_URL_PATTERN, 'issue or PR');
38
66
  const stateManager = getStateManager();
39
67
  const removed = stateManager.undismissIssue(options.url);
40
68
  const gistSyncWarning = await maybeCheckpoint(stateManager, MODULE, () => stateManager.undismissIssue(options.url));
@@ -107,6 +107,19 @@ function loadListItems() {
107
107
  return null;
108
108
  }
109
109
  }
110
+ /** How the user is tied to the issue, by engagement reason (#1862). */
111
+ const ENGAGEMENT_LABEL = {
112
+ claim: 'claimed',
113
+ open_pr: 'have an open PR for',
114
+ closed_pr: 'had a PR on',
115
+ merged_pr: 'had a PR on',
116
+ };
117
+ /** Who replied, and whether the user is working on the issue (#1862) or only commented. */
118
+ function issueReplyReason(issue) {
119
+ const who = issue.isFromMaintainer ? 'a maintainer' : issue.lastResponseAuthor;
120
+ const where = issue.engagement ? ENGAGEMENT_LABEL[issue.engagement.reason] : 'commented on';
121
+ return `${who} replied on an issue you ${where}`;
122
+ }
110
123
  /** Pure: split the daily check into prepare vs judgment items. */
111
124
  export function bucketize(daily, languageOf = () => { }) {
112
125
  const prepare = [];
@@ -131,7 +144,7 @@ export function bucketize(daily, languageOf = () => { }) {
131
144
  url: c.url,
132
145
  type: 'issue_reply',
133
146
  label: `[Issue reply] ${c.repo}#${c.number}`,
134
- reason: `${c.isFromMaintainer ? 'a maintainer' : c.lastResponseAuthor} replied on an issue you commented on`,
147
+ reason: issueReplyReason(c),
135
148
  });
136
149
  }
137
150
  return { prepare, judgment };
@@ -8,6 +8,7 @@ import { getStateManager, isLinkedPRStalled, parseGitHubUrl, requireGitHubToken
8
8
  import { SearchRotationSchema } from '../core/state-schema.js';
9
9
  import { computeStrategy } from '../core/strategy.js';
10
10
  import { loadSkippedIssuesDetailed } from './skip-file-parser.js';
11
+ import { ISSUE_URL_PATTERN } from './validation.js';
11
12
  /**
12
13
  * Fraction of search slots reserved for candidates that matched neither
13
14
  * strategy-preferred languages nor repos (#1244). Counterweight against
@@ -95,10 +96,12 @@ export function buildScoutState(diagnostics) {
95
96
  // window lapsed. `undismiss` deletes the map entry, so only current
96
97
  // dismissals are merged. Scout filters by URL alone; repo/number are
97
98
  // best-effort from the URL and title is unknown, same as the skip file.
99
+ // The same map also holds dismissed merged-PR URLs (#1861); those are not
100
+ // issues scout could surface, so only `/issues/` URLs are forwarded.
98
101
  const skippedIssues = [...skippedIssuesLoad.issues];
99
102
  const skippedUrls = new Set(skippedIssues.map((s) => s.url));
100
103
  for (const [url, dismissedAt] of Object.entries(config.dismissedIssues ?? {})) {
101
- if (skippedUrls.has(url))
104
+ if (skippedUrls.has(url) || !ISSUE_URL_PATTERN.test(url))
102
105
  continue;
103
106
  const parsed = parseGitHubUrl(url);
104
107
  skippedIssues.push({
@@ -7,6 +7,12 @@ export declare const PR_URL_PATTERN: RegExp;
7
7
  export declare const ISSUE_URL_PATTERN: RegExp;
8
8
  /** Matches GitHub issue or PR URLs: /issues/123 or /pull/123 */
9
9
  export declare const ISSUE_OR_PR_URL_PATTERN: RegExp;
10
+ /**
11
+ * Matches a full 40-hex commit SHA, as GitHub reports PR heads (#1857). A
12
+ * short SHA is rejected: the daily run compares the recorded head with the
13
+ * PR's full head SHA by equality, so an abbreviated one would never match.
14
+ */
15
+ export declare const COMMIT_SHA_PATTERN: RegExp;
10
16
  /**
11
17
  * Validate a GitHub URL against a pattern. Throws if invalid.
12
18
  */
@@ -16,6 +22,11 @@ export declare function validateGitHubUrl(url: string, pattern: RegExp, entityTy
16
22
  * Returns the URL if valid, throws if too long.
17
23
  */
18
24
  export declare function validateUrl(url: string): string;
25
+ /**
26
+ * Validate a full commit SHA (40 hex digits). Returns it lowercased, throws
27
+ * if abbreviated or malformed.
28
+ */
29
+ export declare function validateCommitSha(sha: string): string;
19
30
  /**
20
31
  * Validate that a PR/issue number is a positive integer within bounds.
21
32
  * Returns the number if valid, throws if invalid.
@@ -9,6 +9,12 @@ export const PR_URL_PATTERN = /^https:\/\/github\.com\/[^/]+\/[^/]+\/pull\/\d+$/
9
9
  export const ISSUE_URL_PATTERN = /^https:\/\/github\.com\/[^/]+\/[^/]+\/issues\/\d+$/;
10
10
  /** Matches GitHub issue or PR URLs: /issues/123 or /pull/123 */
11
11
  export const ISSUE_OR_PR_URL_PATTERN = /^https:\/\/github\.com\/[^/]+\/[^/]+\/(issues|pull)\/\d+$/;
12
+ /**
13
+ * Matches a full 40-hex commit SHA, as GitHub reports PR heads (#1857). A
14
+ * short SHA is rejected: the daily run compares the recorded head with the
15
+ * PR's full head SHA by equality, so an abbreviated one would never match.
16
+ */
17
+ export const COMMIT_SHA_PATTERN = /^[0-9a-f]{40}$/i;
12
18
  /** Maximum allowed URL length */
13
19
  const MAX_URL_LENGTH = 2048;
14
20
  /** Maximum allowed PR/issue number */
@@ -40,6 +46,16 @@ export function validateUrl(url) {
40
46
  }
41
47
  return url;
42
48
  }
49
+ /**
50
+ * Validate a full commit SHA (40 hex digits). Returns it lowercased, throws
51
+ * if abbreviated or malformed.
52
+ */
53
+ export function validateCommitSha(sha) {
54
+ if (!COMMIT_SHA_PATTERN.test(sha)) {
55
+ throw new ValidationError(`Invalid commit SHA: ${sha}. Expected the full 40-character hex SHA`);
56
+ }
57
+ return sha.toLowerCase();
58
+ }
43
59
  /**
44
60
  * Validate that a PR/issue number is a positive integer within bounds.
45
61
  * Returns the number if valid, throws if invalid.
@@ -54,6 +54,16 @@ const ANY_CHECKBOX_RE = /^.*- \[[ x]\].*$/i;
54
54
  * where exactly one option should be selected. (#1718)
55
55
  */
56
56
  const TYPE_OF_CHANGE_RE = /type\s+of\s+change|kind\s+of\s+change|category/i;
57
+ /**
58
+ * Matches headings whose first checkbox run is a pick-one semver choice
59
+ * (Patch / Minor / Major) even without a pick-one comment (#1853). Only that
60
+ * first run is exempt; later boxes in the section still count.
61
+ */
62
+ const RELEASE_IMPACT_HEADING_RE = /\brelease\s+impact\b|\bsemver\b|\bversion\s+bump\b/i;
63
+ /** A top-level box that opens with a semver option: "- [x] **Patch**: ...". */
64
+ const SEMVER_OPTION_RE = /^- \[[ x]\]\s*(?:\*\*)?(?:patch|minor|major|none)\b/i;
65
+ /** An indented line that wraps the checkbox line above it. */
66
+ const CONTINUATION_RE = /^\s+\S/;
57
67
  /**
58
68
  * Split a PR body into sections delimited by markdown headings.
59
69
  * Content before the first heading is returned as a section with heading = null.
@@ -158,6 +168,27 @@ function collectRunExemptLineIndices(lines) {
158
168
  }
159
169
  return exempt;
160
170
  }
171
+ /**
172
+ * Semver pick-one run under a release-impact heading (#1853): the semver option
173
+ * boxes that open the section's first checkbox run, past blank and indented
174
+ * wrap lines. Any other line ends the run, and a first box that is not a semver
175
+ * option exempts nothing, so ordinary required boxes under the heading count.
176
+ */
177
+ function markFirstRunPickOneExempt(lines, exempt) {
178
+ const runStart = lines.findIndex((l) => ANY_CHECKBOX_RE.test(l));
179
+ if (runStart === -1 || !SEMVER_OPTION_RE.test(lines[runStart]))
180
+ return;
181
+ let runEnd = runStart + 1;
182
+ for (let j = runEnd; j < lines.length; j++) {
183
+ const line = lines[j];
184
+ const isOption = SEMVER_OPTION_RE.test(line);
185
+ if (isOption)
186
+ runEnd = j + 1;
187
+ if (!isOption && (ANY_CHECKBOX_RE.test(line) || (line.trim() !== '' && !CONTINUATION_RE.test(line))))
188
+ break;
189
+ }
190
+ markPickOneRunExempt(lines, runStart, runEnd, exempt);
191
+ }
161
192
  /**
162
193
  * Analyze a single checkbox section and return its effective counts.
163
194
  * Returns null if the section should be entirely skipped.
@@ -177,6 +208,9 @@ function analyzeSectionItems(section) {
177
208
  return { checked, nonConditionalUnchecked: 0 };
178
209
  // Pick-one groups (#1760) and runs under a conditional lead-in line (#1796).
179
210
  const runExempt = collectRunExemptLineIndices(section.lines);
211
+ if (section.heading !== null && RELEASE_IMPACT_HEADING_RE.test(section.heading)) {
212
+ markFirstRunPickOneExempt(section.lines, runExempt);
213
+ }
180
214
  const nonConditionalUnchecked = section.lines.filter((l, idx) => /^.*- \[ \].*$/.test(l) && !isConditionalChecklistItem(l) && !runExempt.has(idx));
181
215
  return { checked, nonConditionalUnchecked: nonConditionalUnchecked.length };
182
216
  }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Status updates for issues whose PR closed without merge (#1863).
3
+ *
4
+ * When the user closes their own PR unmerged, the write-up usually stays in
5
+ * the PR thread while the linked issue still shows their "I'll work on this"
6
+ * as the latest word. The daily run turns such closes into a one-off nudge:
7
+ * draft a short status comment on the linked issue (the user posts it
8
+ * themselves) and release the local claim so the issue re-enters the
9
+ * commented-issue monitor instead of reading as in progress.
10
+ *
11
+ * Pure selection logic lives here: which recently closed PRs still have a
12
+ * live successor, which fall outside the window, and which link the same
13
+ * issue. Everything that needs GitHub (who closed the PR, whether the user
14
+ * has commented since) sits in `PRMonitor.fetchPRClosedBy` and
15
+ * `IssueConversationMonitor.hasUserCommentSince`, orchestrated by daily.ts.
16
+ *
17
+ * URLs are compared through `issueRefKey`, so `Org/Repo` and `org/repo`,
18
+ * trailing slashes and `#fragment`s all name the same issue.
19
+ */
20
+ import type { ClosedPR } from './types.js';
21
+ /**
22
+ * How long after the close a PR may prompt a status update. Matches the
23
+ * default lookback of `PRMonitor.fetchRecentlyClosedPRs`; re-checked here
24
+ * because that search is bounded on `updated`, not on the close date.
25
+ */
26
+ export declare const CLOSED_PR_STATUS_WINDOW_DAYS = 7;
27
+ /** One closed-unmerged PR whose linked issue still needs a status update. */
28
+ export interface ClosedPRStatusUpdate {
29
+ /** The PR that closed without merge; its closing comment seeds the draft. */
30
+ prUrl: string;
31
+ /** Issue the PR claimed to close, parsed from its body. */
32
+ issueUrl: string;
33
+ /** When the PR closed; the status comment must land after this. */
34
+ closedAt: string;
35
+ }
36
+ /**
37
+ * Any PR of the user's that may supersede a closed one: open PRs
38
+ * (`FetchedPR`, which also carry `mentionedIssueUrls`), recently merged PRs,
39
+ * or merged-ledger entries (issue link only).
40
+ */
41
+ export interface IssueLinkedPR {
42
+ url: string;
43
+ /** Issue the PR closes via a closing keyword. */
44
+ issueUrl?: string;
45
+ /** Every issue/PR the title and body mention, keyword or not (open PRs only). */
46
+ mentionedIssueUrls?: readonly string[];
47
+ }
48
+ /** A recently closed PR with a parsed issue link. */
49
+ export type ClosedPRStatusCandidate = ClosedPR & {
50
+ issueUrl: string;
51
+ };
52
+ /**
53
+ * Pick the recently closed PRs that should prompt a status update.
54
+ *
55
+ * Drops, in this order:
56
+ * - PRs with no parsed issue link (nothing to update) or an issue URL that
57
+ * does not parse.
58
+ * - PRs whose `closedAt` is unparseable or older than
59
+ * {@link CLOSED_PR_STATUS_WINDOW_DAYS} relative to `now`. The search behind
60
+ * `recentlyClosedPRs` is bounded on `updated`, so a stale close that just
61
+ * got a comment can come back.
62
+ * - Superseded PRs: another of the user's PRs in `otherPRs` closes the same
63
+ * issue, or mentions the issue or the closed PR anywhere in its title or
64
+ * body (`#N`, `owner/repo#N`, or the URL). The issue thread then already
65
+ * has a live successor and the claim stays. Superseding is the safe
66
+ * direction, so any mention counts, closing keyword or not.
67
+ *
68
+ * When several closed PRs link the same issue, only the latest close
69
+ * survives so the user is asked about each issue once.
70
+ */
71
+ export declare function selectClosedPRStatusCandidates(recentlyClosedPRs: readonly ClosedPR[], otherPRs: readonly IssueLinkedPR[], now?: Date): ClosedPRStatusCandidate[];
72
+ /** Project a candidate onto the digest shape. */
73
+ export declare function toClosedPRStatusUpdate(pr: ClosedPRStatusCandidate): ClosedPRStatusUpdate;
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Status updates for issues whose PR closed without merge (#1863).
3
+ *
4
+ * When the user closes their own PR unmerged, the write-up usually stays in
5
+ * the PR thread while the linked issue still shows their "I'll work on this"
6
+ * as the latest word. The daily run turns such closes into a one-off nudge:
7
+ * draft a short status comment on the linked issue (the user posts it
8
+ * themselves) and release the local claim so the issue re-enters the
9
+ * commented-issue monitor instead of reading as in progress.
10
+ *
11
+ * Pure selection logic lives here: which recently closed PRs still have a
12
+ * live successor, which fall outside the window, and which link the same
13
+ * issue. Everything that needs GitHub (who closed the PR, whether the user
14
+ * has commented since) sits in `PRMonitor.fetchPRClosedBy` and
15
+ * `IssueConversationMonitor.hasUserCommentSince`, orchestrated by daily.ts.
16
+ *
17
+ * URLs are compared through `issueRefKey`, so `Org/Repo` and `org/repo`,
18
+ * trailing slashes and `#fragment`s all name the same issue.
19
+ */
20
+ import { issueRefKey } from './urls.js';
21
+ import { debug } from './logger.js';
22
+ const MODULE = 'closed-pr-status';
23
+ /**
24
+ * How long after the close a PR may prompt a status update. Matches the
25
+ * default lookback of `PRMonitor.fetchRecentlyClosedPRs`; re-checked here
26
+ * because that search is bounded on `updated`, not on the close date.
27
+ */
28
+ export const CLOSED_PR_STATUS_WINDOW_DAYS = 7;
29
+ const WINDOW_MS = CLOSED_PR_STATUS_WINDOW_DAYS * 24 * 60 * 60 * 1000;
30
+ function toSuccessor(other) {
31
+ const keys = new Set();
32
+ const closes = other.issueUrl && issueRefKey(other.issueUrl);
33
+ if (closes)
34
+ keys.add(closes);
35
+ if (other.mentionedIssueUrls) {
36
+ for (const mention of other.mentionedIssueUrls) {
37
+ const key = issueRefKey(mention);
38
+ if (key)
39
+ keys.add(key);
40
+ }
41
+ }
42
+ return { url: other.url, selfKey: issueRefKey(other.url) ?? other.url, keys };
43
+ }
44
+ /**
45
+ * The normalized issue key a closed PR should be nudged about, or null when
46
+ * it should be left alone (reason debug-logged). See
47
+ * {@link selectClosedPRStatusCandidates} for the rules.
48
+ */
49
+ function eligibleIssueKey(pr, successors, nowMs) {
50
+ if (pr.issueUrl === undefined)
51
+ return null;
52
+ const issueKey = issueRefKey(pr.issueUrl);
53
+ if (!issueKey) {
54
+ debug(MODULE, `Skipping ${pr.url}: issue URL ${pr.issueUrl} does not parse`);
55
+ return null;
56
+ }
57
+ const closedMs = Date.parse(pr.closedAt);
58
+ if (Number.isNaN(closedMs)) {
59
+ debug(MODULE, `Skipping ${pr.url}: closedAt ${JSON.stringify(pr.closedAt)} does not parse`);
60
+ return null;
61
+ }
62
+ if (nowMs - closedMs > WINDOW_MS) {
63
+ debug(MODULE, `Skipping ${pr.url}: closed ${pr.closedAt}, outside the ${CLOSED_PR_STATUS_WINDOW_DAYS}-day window`);
64
+ return null;
65
+ }
66
+ const prKey = issueRefKey(pr.url);
67
+ const selfKey = prKey ?? pr.url;
68
+ const wanted = prKey === null ? [issueKey] : [issueKey, prKey];
69
+ const successor = successors.find((other) => other.selfKey !== selfKey && wanted.some((key) => other.keys.has(key)));
70
+ if (successor) {
71
+ debug(MODULE, `Skipping ${pr.url}: superseded by ${successor.url}`);
72
+ return null;
73
+ }
74
+ return issueKey;
75
+ }
76
+ /**
77
+ * Pick the recently closed PRs that should prompt a status update.
78
+ *
79
+ * Drops, in this order:
80
+ * - PRs with no parsed issue link (nothing to update) or an issue URL that
81
+ * does not parse.
82
+ * - PRs whose `closedAt` is unparseable or older than
83
+ * {@link CLOSED_PR_STATUS_WINDOW_DAYS} relative to `now`. The search behind
84
+ * `recentlyClosedPRs` is bounded on `updated`, so a stale close that just
85
+ * got a comment can come back.
86
+ * - Superseded PRs: another of the user's PRs in `otherPRs` closes the same
87
+ * issue, or mentions the issue or the closed PR anywhere in its title or
88
+ * body (`#N`, `owner/repo#N`, or the URL). The issue thread then already
89
+ * has a live successor and the claim stays. Superseding is the safe
90
+ * direction, so any mention counts, closing keyword or not.
91
+ *
92
+ * When several closed PRs link the same issue, only the latest close
93
+ * survives so the user is asked about each issue once.
94
+ */
95
+ export function selectClosedPRStatusCandidates(recentlyClosedPRs, otherPRs, now = new Date()) {
96
+ const successors = otherPRs.map((other) => toSuccessor(other));
97
+ const nowMs = now.getTime();
98
+ const latestPerIssue = new Map();
99
+ for (const pr of recentlyClosedPRs) {
100
+ const issueKey = eligibleIssueKey(pr, successors, nowMs);
101
+ if (issueKey === null)
102
+ continue;
103
+ const current = latestPerIssue.get(issueKey);
104
+ if (!current || Date.parse(pr.closedAt) > Date.parse(current.closedAt)) {
105
+ latestPerIssue.set(issueKey, pr);
106
+ }
107
+ }
108
+ return Array.from(latestPerIssue, ([, pr]) => pr);
109
+ }
110
+ /** Project a candidate onto the digest shape. */
111
+ export function toClosedPRStatusUpdate(pr) {
112
+ return { prUrl: pr.url, issueUrl: pr.issueUrl, closedAt: pr.closedAt };
113
+ }
@@ -15,7 +15,12 @@
15
15
  * #1243 (strategy), #1252 (pr-quality-rubric), and #1264 (issue-effort /
16
16
  * maintainer-hints).
17
17
  */
18
- export type FeedbackCategory = 'code_request' | 'question' | 'explanation_request' | 'style_request' | 'design_discussion' | 'approval_with_nit' | 'formatting_complaint';
18
+ export type FeedbackCategory = 'code_request' | 'question' | 'explanation_request' | 'style_request' | 'design_discussion' | 'approval_with_nit' | 'formatting_complaint'
19
+ /**
20
+ * A maintainer comment whose main content is thanks or praise (not a polite
21
+ * opener on a request); always gets a short acknowledgment (#1852).
22
+ */
23
+ | 'appreciation';
19
24
  export interface FeedbackClassification {
20
25
  category: FeedbackCategory;
21
26
  /**
@@ -54,14 +59,16 @@ export interface CommentDecisionResult {
54
59
  * - Skip the comment entirely when ALL of these are true:
55
60
  * 1. Every piece of maintainer feedback that requested code changes
56
61
  * has a corresponding code change.
57
- * 2. No question was asked.
62
+ * 2. No question was asked and no maintainer thanks or praise is
63
+ * waiting for an acknowledgment.
58
64
  * 3. Nothing was intentionally left unchanged (a "yes the maintainer
59
65
  * asked but I did not change it" item always needs explanation).
60
66
  * 4. The diff makes the fix self-evident — modeled here as the
61
67
  * `allRequestedChangesAddressed` flag the caller passes in.
62
68
  *
63
69
  * - Draft a comment if ANY of these are true:
64
- * 1. The maintainer asked a question.
70
+ * 1. The maintainer asked a question, or thanked or praised the
71
+ * contributor (#1852).
65
72
  * 2. The feedback is conceptual or design-level (the diff alone
66
73
  * cannot answer "why").
67
74
  * 3. Something was intentionally left unchanged (`needsComment: true`