@oss-autopilot/core 3.43.0 → 3.44.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 (100) hide show
  1. package/dist/cli-registry.js +160 -6
  2. package/dist/cli.bundle.cjs +207 -180
  3. package/dist/commands/check-integration.js +4 -1
  4. package/dist/commands/cleanup.d.ts +6 -2
  5. package/dist/commands/cleanup.js +72 -7
  6. package/dist/commands/comments.d.ts +8 -1
  7. package/dist/commands/comments.js +11 -3
  8. package/dist/commands/config.d.ts +2 -0
  9. package/dist/commands/config.js +26 -1
  10. package/dist/commands/daily-ledger.d.ts +33 -5
  11. package/dist/commands/daily-ledger.js +36 -13
  12. package/dist/commands/daily-render.d.ts +2 -1
  13. package/dist/commands/daily-render.js +4 -1
  14. package/dist/commands/daily.d.ts +3 -0
  15. package/dist/commands/daily.js +25 -5
  16. package/dist/commands/dashboard-data.js +70 -61
  17. package/dist/commands/dashboard-lifecycle.d.ts +36 -8
  18. package/dist/commands/dashboard-lifecycle.js +131 -38
  19. package/dist/commands/dashboard-process.d.ts +35 -0
  20. package/dist/commands/dashboard-process.js +65 -5
  21. package/dist/commands/dismiss.js +7 -6
  22. package/dist/commands/doctor.js +1 -8
  23. package/dist/commands/fork-prune.d.ts +58 -0
  24. package/dist/commands/fork-prune.js +247 -0
  25. package/dist/commands/guidelines.d.ts +46 -1
  26. package/dist/commands/guidelines.js +111 -12
  27. package/dist/commands/index.d.ts +5 -0
  28. package/dist/commands/index.js +5 -0
  29. package/dist/commands/overnight-push-prep.d.ts +2 -1
  30. package/dist/commands/overnight-push-prep.js +3 -3
  31. package/dist/commands/policy.d.ts +5 -1
  32. package/dist/commands/policy.js +14 -1
  33. package/dist/commands/pr-create.d.ts +48 -0
  34. package/dist/commands/pr-create.js +200 -0
  35. package/dist/commands/pr-preflight.d.ts +28 -2
  36. package/dist/commands/pr-preflight.js +63 -9
  37. package/dist/commands/setup.js +120 -36
  38. package/dist/commands/startup.d.ts +7 -0
  39. package/dist/commands/startup.js +17 -0
  40. package/dist/commands/status.js +5 -0
  41. package/dist/commands/validation.d.ts +5 -0
  42. package/dist/commands/validation.js +5 -0
  43. package/dist/commands/vet-list.js +2 -2
  44. package/dist/commands/vet.d.ts +8 -0
  45. package/dist/commands/vet.js +15 -1
  46. package/dist/commands/work.d.ts +4 -0
  47. package/dist/commands/work.js +34 -11
  48. package/dist/core/commit-date.d.ts +31 -5
  49. package/dist/core/commit-date.js +36 -8
  50. package/dist/core/compliance-score.d.ts +3 -0
  51. package/dist/core/compliance-score.js +13 -9
  52. package/dist/core/config-registry.d.ts +27 -2
  53. package/dist/core/config-registry.js +83 -2
  54. package/dist/core/daily-logic.d.ts +4 -1
  55. package/dist/core/daily-logic.js +13 -2
  56. package/dist/core/fork-prune.d.ts +149 -0
  57. package/dist/core/fork-prune.js +333 -0
  58. package/dist/core/gist-state-store.js +4 -8
  59. package/dist/core/github-stats.d.ts +7 -1
  60. package/dist/core/github-stats.js +15 -15
  61. package/dist/core/index.d.ts +1 -1
  62. package/dist/core/index.js +1 -1
  63. package/dist/core/local-config.js +2 -3
  64. package/dist/core/pacing.d.ts +41 -0
  65. package/dist/core/pacing.js +115 -0
  66. package/dist/core/pr-assembly.d.ts +2 -0
  67. package/dist/core/pr-graphql.d.ts +16 -1
  68. package/dist/core/pr-graphql.js +15 -3
  69. package/dist/core/pr-monitor.d.ts +6 -0
  70. package/dist/core/pr-monitor.js +46 -10
  71. package/dist/core/pr-preflight.d.ts +41 -0
  72. package/dist/core/pr-preflight.js +406 -17
  73. package/dist/core/prose-script.d.ts +72 -0
  74. package/dist/core/prose-script.js +223 -0
  75. package/dist/core/repo-policy.d.ts +8 -2
  76. package/dist/core/repo-policy.js +34 -6
  77. package/dist/core/repo-score-manager.d.ts +18 -0
  78. package/dist/core/repo-score-manager.js +29 -0
  79. package/dist/core/review-analysis.d.ts +15 -2
  80. package/dist/core/review-analysis.js +22 -5
  81. package/dist/core/stale-data.d.ts +44 -7
  82. package/dist/core/stale-data.js +46 -8
  83. package/dist/core/state-persistence.js +2 -4
  84. package/dist/core/state-schema.d.ts +39 -0
  85. package/dist/core/state-schema.js +68 -1
  86. package/dist/core/state.d.ts +21 -0
  87. package/dist/core/state.js +47 -0
  88. package/dist/core/status-determination.js +10 -8
  89. package/dist/core/untrusted-content.d.ts +3 -3
  90. package/dist/core/untrusted-content.js +26 -8
  91. package/dist/core/urls.d.ts +24 -0
  92. package/dist/core/urls.js +76 -0
  93. package/dist/dashboard/assets/chart-panel-B-nLVgzQ.js +3 -0
  94. package/dist/dashboard/assets/index-5IvMGokL.js +55 -0
  95. package/dist/dashboard/index.html +1 -1
  96. package/dist/formatters/json.d.ts +171 -5
  97. package/dist/formatters/json.js +79 -0
  98. package/package.json +6 -6
  99. package/dist/dashboard/assets/chart-panel-C_C1lFTI.js +0 -3
  100. package/dist/dashboard/assets/index-B--H66Jk.js +0 -55
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Optional pacing caps (#1911): at most `maxNewPrsPerDay` new PRs and
3
+ * `maxNewForksPerDay` new forks in any rolling 24 hours. Both are unset by
4
+ * default, and nothing here runs then.
5
+ *
6
+ * Counts come from local state only, never a GitHub search:
7
+ * - PRs: those the tool recorded when it opened them (`recentNewPRs`,
8
+ * written by `work release --pr`), plus the open PRs of the last digest
9
+ * (`createdAt`) and the merged and closed PRs the digest and the outcome
10
+ * ledger record (`openedAt`), once per URL. A PR opened outside the tool
11
+ * counts once a `daily` run has seen it.
12
+ * - Forks: state records no fork creation. A fork is made for the first PR
13
+ * into a repo, so a counted PR that is the earliest known PR in its repo
14
+ * counts as one new fork. This is a soft limit: a fork made without a PR
15
+ * is not seen, and the first PR into a repo forked long ago counts.
16
+ * PRs to the user's own repos never count.
17
+ */
18
+ import type { AgentState } from './state-schema.js';
19
+ export declare const PACING_WINDOW_MS: number;
20
+ export interface PacingCount {
21
+ cap: number;
22
+ /** New PRs (or forks) in the 24 hours ending now. */
23
+ count: number;
24
+ atCap: boolean;
25
+ /** When the count drops below the cap again; null when it is below the cap now. */
26
+ freesAt: string | null;
27
+ }
28
+ export interface PacingStatus {
29
+ /** Present when `maxNewPrsPerDay` is set above 0. */
30
+ prs?: PacingCount;
31
+ /** Present when `maxNewForksPerDay` is set above 0. */
32
+ forks?: PacingCount;
33
+ /** When the digest the counts come from was made; null before the first `daily` run. */
34
+ countedAt: string | null;
35
+ }
36
+ /** ISO time of an epoch-ms value. */
37
+ export declare function isoAt(ms: number): string;
38
+ /** The pacing caps that are set, with their counts; null when neither is set. */
39
+ export declare function getPacingStatus(state: Readonly<AgentState>, nowMs?: number): PacingStatus | null;
40
+ /** One line per set cap, e.g. `3/5 new PRs in the last 24h`; empty when no cap is set. */
41
+ export declare function pacingLines(pacing: PacingStatus | null): string[];
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Optional pacing caps (#1911): at most `maxNewPrsPerDay` new PRs and
3
+ * `maxNewForksPerDay` new forks in any rolling 24 hours. Both are unset by
4
+ * default, and nothing here runs then.
5
+ *
6
+ * Counts come from local state only, never a GitHub search:
7
+ * - PRs: those the tool recorded when it opened them (`recentNewPRs`,
8
+ * written by `work release --pr`), plus the open PRs of the last digest
9
+ * (`createdAt`) and the merged and closed PRs the digest and the outcome
10
+ * ledger record (`openedAt`), once per URL. A PR opened outside the tool
11
+ * counts once a `daily` run has seen it.
12
+ * - Forks: state records no fork creation. A fork is made for the first PR
13
+ * into a repo, so a counted PR that is the earliest known PR in its repo
14
+ * counts as one new fork. This is a soft limit: a fork made without a PR
15
+ * is not seen, and the first PR into a repo forked long ago counts.
16
+ * PRs to the user's own repos never count.
17
+ */
18
+ import { isOwnRepo, parseGitHubUrl } from './urls.js';
19
+ export const PACING_WINDOW_MS = 24 * 60 * 60 * 1000;
20
+ /** ISO time of an epoch-ms value. */
21
+ export function isoAt(ms) {
22
+ const date = new Date(ms);
23
+ return date.toISOString();
24
+ }
25
+ /** Each recorded PR's URL with its open time, from the digest and the outcome ledger. */
26
+ function recordedPRs(state) {
27
+ const digest = state.lastDigest;
28
+ return [
29
+ ...(state.recentNewPRs ?? []).map((pr) => ({ url: pr.url, at: pr.openedAt })),
30
+ ...(digest?.openPRs ?? []).map((pr) => ({ url: pr.url, at: pr.createdAt })),
31
+ ...(digest?.recentlyMergedPRs ?? []).map((pr) => ({ url: pr.url, at: pr.openedAt })),
32
+ ...(digest?.recentlyClosedPRs ?? []).map((pr) => ({ url: pr.url, at: pr.openedAt })),
33
+ ...(state.mergedPRs ?? []).map((pr) => ({ url: pr.url, at: pr.openedAt })),
34
+ ...(state.closedPRs ?? []).map((pr) => ({ url: pr.url, at: pr.openedAt })),
35
+ ];
36
+ }
37
+ /** Epoch ms of a stamp; null when absent or unparseable. */
38
+ function parseTime(at) {
39
+ const ms = at ? Date.parse(at) : NaN;
40
+ return Number.isNaN(ms) ? null : ms;
41
+ }
42
+ /** Every PR to a repo the user does not own, once each, with when it was opened (null when not recorded). */
43
+ function knownPRs(state, login) {
44
+ const byUrl = new Map();
45
+ for (const { url, at } of recordedPRs(state)) {
46
+ const parsed = parseGitHubUrl(url);
47
+ const key = url.toLowerCase();
48
+ const isOwn = parsed !== null && login !== '' && isOwnRepo(parsed.owner, login);
49
+ // A dated record wins over an undated one for the same PR.
50
+ if (parsed && !isOwn && byUrl.get(key)?.openedAtMs == null) {
51
+ byUrl.set(key, { repo: `${parsed.owner}/${parsed.repo}`.toLowerCase(), openedAtMs: parseTime(at) });
52
+ }
53
+ }
54
+ return byUrl;
55
+ }
56
+ /**
57
+ * Open times inside the window ending at `nowMs`; a PR opened exactly 24 hours ago is out.
58
+ * A time in the future (another host's clock runs ahead) counts as now: the PR exists.
59
+ */
60
+ function inWindow(times, nowMs) {
61
+ const clamped = times.map((t) => Math.min(t, nowMs));
62
+ // eslint-disable-next-line unicorn/no-array-sort -- sorts the fresh array filter() returns; toSorted needs lib es2023, which core does not target
63
+ return clamped.filter((t) => t > nowMs - PACING_WINDOW_MS).sort((a, b) => a - b);
64
+ }
65
+ /** New forks: the earliest known PR of each repo. A PR without an open time is older than any dated one. */
66
+ function forkTimes(prs) {
67
+ const earliest = new Map();
68
+ for (const pr of prs.values()) {
69
+ const seen = earliest.get(pr.repo);
70
+ const isEarlier = seen === undefined || pr.openedAtMs === null || (seen !== null && pr.openedAtMs < seen);
71
+ if (isEarlier)
72
+ earliest.set(pr.repo, pr.openedAtMs);
73
+ }
74
+ const times = [];
75
+ for (const t of earliest.values())
76
+ if (t !== null)
77
+ times.push(t);
78
+ return times;
79
+ }
80
+ function pacingCount(cap, times, nowMs) {
81
+ const counted = inWindow(times, nowMs);
82
+ const count = counted.length;
83
+ // Below the cap again once the (count - cap + 1) oldest have left the window.
84
+ const freesAt = count >= cap ? isoAt(counted[count - cap] + PACING_WINDOW_MS) : null;
85
+ return { atCap: freesAt !== null, cap, count, freesAt };
86
+ }
87
+ /** The pacing caps that are set, with their counts; null when neither is set. */
88
+ export function getPacingStatus(state, nowMs = Date.now()) {
89
+ const { maxNewPrsPerDay = 0, maxNewForksPerDay = 0, githubUsername = '' } = state.config ?? {};
90
+ if (maxNewPrsPerDay <= 0 && maxNewForksPerDay <= 0)
91
+ return null;
92
+ const prs = knownPRs(state, githubUsername);
93
+ const dated = [];
94
+ for (const pr of prs.values())
95
+ if (pr.openedAtMs !== null)
96
+ dated.push(pr.openedAtMs);
97
+ return {
98
+ ...(maxNewPrsPerDay > 0 && { prs: pacingCount(maxNewPrsPerDay, dated, nowMs) }),
99
+ ...(maxNewForksPerDay > 0 && { forks: pacingCount(maxNewForksPerDay, forkTimes(prs), nowMs) }),
100
+ countedAt: state.lastDigestAt ?? null,
101
+ };
102
+ }
103
+ function pacingLine(c, what) {
104
+ const until = c.freesAt ? `, at the cap until ${c.freesAt}` : '';
105
+ return `${c.count}/${c.cap} new ${what} in the last 24h${until}`;
106
+ }
107
+ /** One line per set cap, e.g. `3/5 new PRs in the last 24h`; empty when no cap is set. */
108
+ export function pacingLines(pacing) {
109
+ if (!pacing)
110
+ return [];
111
+ return [
112
+ ...(pacing.prs ? [pacingLine(pacing.prs, 'PRs')] : []),
113
+ ...(pacing.forks ? [pacingLine(pacing.forks, 'forks')] : []),
114
+ ];
115
+ }
@@ -32,6 +32,8 @@ export interface AssemblyReview {
32
32
  submitted_at?: string | null;
33
33
  state?: string | null;
34
34
  id?: number;
35
+ /** The head commit the review was submitted against. */
36
+ commit_id?: string | null;
35
37
  }
36
38
  /**
37
39
  * Normalized, transport-agnostic PR signals consumed by {@link assembleFetchedPR}.
@@ -24,7 +24,7 @@
24
24
  */
25
25
  import type { Octokit } from '@octokit/rest';
26
26
  import { CIStatusResult } from './types.js';
27
- import type { ActivityEvent, ReviewComment } from './review-analysis.js';
27
+ import { type ActivityEvent, type ReviewComment } from './review-analysis.js';
28
28
  import type { AssemblyComment, AssemblyReview, CommitInfo } from './pr-assembly.js';
29
29
  /** PRs per aliased GraphQL query. GitHub recommends modest batch sizes; ~10 keeps
30
30
  * each query cheap (~1 point) and well under node/complexity limits. */
@@ -109,6 +109,7 @@ interface GraphQLActor {
109
109
  __typename?: string;
110
110
  }
111
111
  type GraphQLGitActor = {
112
+ email?: string | null;
112
113
  user: {
113
114
  login: string;
114
115
  } | null;
@@ -154,9 +155,15 @@ interface GraphQLCommitNode {
154
155
  authoredDate: string | null;
155
156
  committedDate: string | null;
156
157
  author: {
158
+ email?: string | null;
157
159
  user: GraphQLActor | null;
158
160
  } | null;
159
161
  committer: GraphQLGitActor;
162
+ parents?: {
163
+ nodes: Array<{
164
+ oid: string;
165
+ }>;
166
+ };
160
167
  status: {
161
168
  state: string;
162
169
  contexts: Array<{
@@ -199,6 +206,14 @@ interface GraphQLPullRequestNode {
199
206
  submittedAt: string | null;
200
207
  author: GraphQLActor | null;
201
208
  authorAssociation?: string | null;
209
+ commit?: {
210
+ oid: string;
211
+ parents: {
212
+ nodes: Array<{
213
+ oid: string;
214
+ }>;
215
+ };
216
+ } | null;
202
217
  }>;
203
218
  };
204
219
  reviewThreads: {
@@ -23,6 +23,7 @@
23
23
  * - A missing / inaccessible / malformed PR node → REST.
24
24
  */
25
25
  import { computeCIStatus } from './ci-analysis.js';
26
+ import { getChangesRequestedCommitSha } from './review-analysis.js';
26
27
  import { commitDateOf } from './commit-date.js';
27
28
  import { isRateLimitOrAuthError, errorMessage } from './errors.js';
28
29
  import { warn } from './logger.js';
@@ -117,7 +118,7 @@ const PR_FIELDS = `
117
118
  }
118
119
  reviews(last: ${REVIEWS_CAP}) {
119
120
  totalCount
120
- nodes { databaseId state body submittedAt author { login __typename } authorAssociation }
121
+ nodes { databaseId state body submittedAt author { login __typename } authorAssociation commit { oid parents(first: 1) { nodes { oid } } } }
121
122
  }
122
123
  reviewThreads(last: ${REVIEW_THREADS_CAP}) {
123
124
  totalCount
@@ -151,8 +152,9 @@ const PR_FIELDS = `
151
152
  oid
152
153
  authoredDate
153
154
  committedDate
154
- author { user { login } }
155
- committer { user { login } }
155
+ author { email user { login } }
156
+ committer { email user { login } }
157
+ parents(first: 1) { nodes { oid } }
156
158
  status { state contexts { context state description } }
157
159
  statusCheckRollup {
158
160
  contexts(first: ${CI_CONTEXTS_CAP}) {
@@ -261,6 +263,7 @@ export function normalizePRNode(node) {
261
263
  submitted_at: r.submittedAt,
262
264
  state: r.state,
263
265
  id: r.databaseId ?? undefined,
266
+ commit_id: r.commit?.oid ?? null,
264
267
  }));
265
268
  const reviewComments = node.reviewThreads.nodes.flatMap((thread) => thread.comments.nodes.map((c) => ({
266
269
  id: c.databaseId ?? 0,
@@ -272,12 +275,21 @@ export function normalizePRNode(node) {
272
275
  pull_request_review_id: c.pullRequestReview?.databaseId ?? null,
273
276
  })));
274
277
  const commit = node.commits.nodes[0]?.commit;
278
+ // The commit the latest change request was made against and its parent: a
279
+ // head rebased off that parent has not addressed the review (#2042).
280
+ const reviewedSha = getChangesRequestedCommitSha(reviews);
281
+ const reviewedCommit = node.reviews.nodes.find((r) => r.commit?.oid === reviewedSha)?.commit;
275
282
  const commitInfo = {
276
283
  date: commitDateOf({
277
284
  authorDate: commit?.authoredDate,
278
285
  committerDate: commit?.committedDate,
279
286
  authorLogin: commit?.author?.user?.login,
280
287
  committerLogin: commit?.committer?.user?.login,
288
+ authorEmail: commit?.author?.email,
289
+ committerEmail: commit?.committer?.email,
290
+ parentSha: commit?.parents?.nodes[0]?.oid,
291
+ reviewedParentSha: reviewedCommit?.parents.nodes[0]?.oid,
292
+ reviewedSha,
281
293
  }),
282
294
  author: commit?.author?.user?.login ?? undefined,
283
295
  };
@@ -132,6 +132,12 @@ export declare class PRMonitor {
132
132
  * failures degrade to `undefined` so the PR is still returned.
133
133
  */
134
134
  private fetchCommitInfo;
135
+ /**
136
+ * First parent of a commit, or undefined when it cannot be fetched (a
137
+ * force-pushed-away commit GitHub no longer serves): the date rule then
138
+ * treats the rebase as unknown (#2042). Rate-limit and auth errors propagate.
139
+ */
140
+ private fetchFirstParentSha;
135
141
  /**
136
142
  * Assemble a {@link FetchedPR} from GraphQL-batched {@link NormalizedPRData}.
137
143
  * No network calls: the batch already carries the commit info, so it is
@@ -21,8 +21,9 @@ import { paginateAllDetailed } from './pagination.js';
21
21
  import { debug, warn, timed } from './logger.js';
22
22
  import { getHttpCache, cachedRequest } from './http-cache.js';
23
23
  import { getCIStatus } from './ci-analysis.js';
24
+ import { getChangesRequestedCommitSha } from './review-analysis.js';
24
25
  import { fetchCompareStatus as fetchCompareStatusImpl, fetchReviewedOpenPRs as fetchReviewedOpenPRsImpl, fetchReviewedPRActivity as fetchReviewedPRActivityImpl, } from './reviewed-prs-fetch.js';
25
- import { commitDateOf } from './commit-date.js';
26
+ import { commitDateOf, isOwnRewrite } from './commit-date.js';
26
27
  import { assembleFetchedPR } from './pr-assembly.js';
27
28
  import { batchFetchPRDetails, MERGEABLE_RETRY_DELAY_MS, PR_FETCH_LOG, } from './pr-graphql.js';
28
29
  import { fetchUserMergedPRCounts as fetchUserMergedPRCountsImpl, fetchUserClosedPRCounts as fetchUserClosedPRCountsImpl, fetchRecentlyClosedPRs as fetchRecentlyClosedPRsImpl, fetchRecentlyMergedPRs as fetchRecentlyMergedPRsImpl, } from './github-stats.js';
@@ -53,6 +54,22 @@ function fulfilledValue(result) {
53
54
  throw result.reason;
54
55
  return result.value;
55
56
  }
57
+ function firstParentSha(data) {
58
+ return data.parents?.[0]?.sha;
59
+ }
60
+ /** The date-rule inputs of a REST `repos.getCommit` response (#1919, #2042). */
61
+ function restCommitDates(data, reviewedSha) {
62
+ return {
63
+ authorDate: data.commit.author?.date,
64
+ committerDate: data.commit.committer?.date,
65
+ authorLogin: data.author?.login,
66
+ committerLogin: data.committer?.login,
67
+ authorEmail: data.commit.author?.email,
68
+ committerEmail: data.commit.committer?.email,
69
+ parentSha: firstParentSha(data),
70
+ reviewedSha,
71
+ };
72
+ }
56
73
  /**
57
74
  * Fetches and enriches open PRs from GitHub for the configured user.
58
75
  *
@@ -406,9 +423,10 @@ export class PRMonitor {
406
423
  // pipeline decides via `needCommitDate` and invokes this thunk lazily.
407
424
  // A PR with a status override is the exception: override auto-clear keys
408
425
  // on the commit date (#1713), so fetch it up front for those PRs only.
426
+ const reviewedSha = getChangesRequestedCommitSha(reviews);
409
427
  const commitInfo = findRefKey(config.statusOverrides, prUrl)
410
- ? await this.fetchCommitInfo(owner, repo, ghPR.head.sha)
411
- : () => this.fetchCommitInfo(owner, repo, ghPR.head.sha);
428
+ ? await this.fetchCommitInfo(owner, repo, ghPR.head.sha, reviewedSha)
429
+ : () => this.fetchCommitInfo(owner, repo, ghPR.head.sha, reviewedSha);
412
430
  return assembleFetchedPR({
413
431
  prUrl,
414
432
  owner,
@@ -468,16 +486,17 @@ export class PRMonitor {
468
486
  * status, e.g. needs_changes when changes were addressed) (#469); other
469
487
  * failures degrade to `undefined` so the PR is still returned.
470
488
  */
471
- async fetchCommitInfo(owner, repo, sha) {
489
+ async fetchCommitInfo(owner, repo, sha, reviewedSha) {
472
490
  try {
473
491
  const res = await this.octokit.repos.getCommit({ owner, repo, ref: sha });
492
+ const dates = restCommitDates(res.data, reviewedSha);
493
+ // The reviewed commit's parent only matters for the author's own rewrite
494
+ // of a commit other than the reviewed one, so fetch it only then.
495
+ if (reviewedSha && reviewedSha !== sha && isOwnRewrite(dates)) {
496
+ dates.reviewedParentSha = await this.fetchFirstParentSha(owner, repo, reviewedSha);
497
+ }
474
498
  return {
475
- date: commitDateOf({
476
- authorDate: res.data.commit.author?.date,
477
- committerDate: res.data.commit.committer?.date,
478
- authorLogin: res.data.author?.login,
479
- committerLogin: res.data.committer?.login,
480
- }),
499
+ date: commitDateOf(dates),
481
500
  // GitHub user login of the commit author (may differ from git author)
482
501
  author: res.data.author?.login,
483
502
  };
@@ -498,6 +517,23 @@ export class PRMonitor {
498
517
  return undefined;
499
518
  }
500
519
  }
520
+ /**
521
+ * First parent of a commit, or undefined when it cannot be fetched (a
522
+ * force-pushed-away commit GitHub no longer serves): the date rule then
523
+ * treats the rebase as unknown (#2042). Rate-limit and auth errors propagate.
524
+ */
525
+ async fetchFirstParentSha(owner, repo, sha) {
526
+ try {
527
+ const res = await this.octokit.repos.getCommit({ owner, repo, ref: sha });
528
+ return firstParentSha(res.data);
529
+ }
530
+ catch (err) {
531
+ if (isRateLimitOrAuthError(err))
532
+ throw err;
533
+ warn(MODULE, `Failed to fetch reviewed commit ${owner}/${repo}@${sha.slice(0, 7)}: ${errorMessage(err)}`);
534
+ return undefined;
535
+ }
536
+ }
501
537
  /**
502
538
  * Assemble a {@link FetchedPR} from GraphQL-batched {@link NormalizedPRData}.
503
539
  * No network calls: the batch already carries the commit info, so it is
@@ -8,6 +8,8 @@
8
8
  * needs); the verdict and the output shape do not change.
9
9
  */
10
10
  import type { IssueVerification } from './issue-verification.js';
11
+ import type { PacingStatus } from './pacing.js';
12
+ import { type RepoScripts } from './prose-script.js';
11
13
  import type { RepoCapStatus } from './repo-cap.js';
12
14
  import { type RepoPolicy } from './repo-policy.js';
13
15
  export type PreflightStatus = 'pass' | 'warn' | 'fail' | 'skipped';
@@ -70,10 +72,28 @@ export interface PreflightFacts {
70
72
  github: PreflightGitHubFacts | null;
71
73
  issue: IssueVerification | null;
72
74
  cap: RepoCapStatus | null;
75
+ /** The pacing caps that are set, counted from local state (#1911); null when neither is set. */
76
+ pacing: PacingStatus | null;
73
77
  /** The repo's contribution policy (`effectivePolicy`: stored record plus the blocklist); null when none is recorded. */
74
78
  policy: RepoPolicy | null;
75
79
  /** The user has no merged PR in the repo. */
76
80
  isFirstContribution: boolean;
81
+ /** The staged PR body (`--body-file`); null when none was given. */
82
+ prBody: string | null;
83
+ /** The scripts the repo's README and CONTRIBUTING are written in; null when not read (no GitHub, or no staged text). */
84
+ repoScripts: RepoScripts | null;
85
+ /** The repo's PR template (`--template-file`); body lines found in it are not counted as prose. */
86
+ prTemplate: string | null;
87
+ /** The staged PR title (`--title-file`); null when none was given. */
88
+ prTitle: string | null;
89
+ /** `--allow-script-mismatch`: a script mismatch warns instead of failing. */
90
+ allowScriptMismatch: boolean;
91
+ /** The PR will be opened as a draft (`--draft`). */
92
+ isDraft: boolean;
93
+ /** The issue's label names, read only for a `maintainer-label` gate; null when not read. */
94
+ issueLabels: string[] | null;
95
+ /** Why the label read failed. */
96
+ labelsError: string | null;
77
97
  }
78
98
  /** Past this many commits behind, the drift check warns even when no upstream commit touches the branch's files. */
79
99
  export declare const BEHIND_WARN_THRESHOLD = 20;
@@ -92,6 +112,13 @@ export declare function checkWorkingTree(facts: PreflightFacts): PreflightCheck;
92
112
  export declare function checkCompetingWork(facts: PreflightFacts): PreflightCheck;
93
113
  /** The user's own open-PR cap and `excludeRepos`, as `repo-cap` reports them. Runs only for an issue: it gates a new PR. */
94
114
  export declare function checkRepoCap(facts: PreflightFacts): PreflightCheck;
115
+ /**
116
+ * The optional pacing caps (#1911). Runs only for an issue, like `repo-cap`:
117
+ * it gates a new PR, never a push to an existing one. The fork cap applies
118
+ * when the PR needs a new fork: no remote of the user's and no push access.
119
+ * A `fail` here defers the PR: the branch stays local and nothing is lost.
120
+ */
121
+ export declare function checkPacing(facts: PreflightFacts): PreflightCheck;
95
122
  /**
96
123
  * The repo's contribution policy (#1953): `banned` fails, a rule the PR has
97
124
  * not met warns with the action that meets it. Quoted repo text arrives fenced.
@@ -103,6 +130,20 @@ export declare function checkRepoPolicy(facts: PreflightFacts): PreflightCheck;
103
130
  * reviewed only warns. Commit subjects arrive fenced.
104
131
  */
105
132
  export declare function checkCommitRules(facts: PreflightFacts): PreflightCheck;
133
+ /** The title opens with a work-in-progress marker (#1910, #2087). */
134
+ export declare function hasWipMarker(title: string): boolean;
135
+ /**
136
+ * The staged title and body are ready to publish (#1910): the body says
137
+ * something beyond what the PR template brings ({@link bodyProse}), and a
138
+ * PR that is not a draft has no WIP marker in its title. Nothing is filled in.
139
+ */
140
+ export declare function checkPrDescription(facts: PreflightFacts): PreflightCheck;
141
+ /**
142
+ * The staged title and body are in the script the repo writes in (#1909). A
143
+ * script check, not language detection: Latin-script languages are not told
144
+ * apart. Without the repo's docs, English (Latin script) is assumed and said so.
145
+ */
146
+ export declare function checkPrLanguage(facts: PreflightFacts): PreflightCheck;
106
147
  /** Every check, in output order. A new check is added here. */
107
148
  export declare const PREFLIGHT_CHECKS: ReadonlyArray<(facts: PreflightFacts) => PreflightCheck>;
108
149
  /** `fail` when any check fails, else `warn` when any warns, else `pass`. Skipped checks do not count. */