@oss-autopilot/core 3.35.0 → 3.36.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 (37) hide show
  1. package/dist/cli-registry.js +24 -1
  2. package/dist/cli.bundle.cjs +125 -114
  3. package/dist/commands/daily.js +5 -2
  4. package/dist/commands/repo-cap.d.ts +10 -0
  5. package/dist/commands/repo-cap.js +23 -0
  6. package/dist/commands/scout-bridge.js +8 -2
  7. package/dist/commands/search.js +7 -1
  8. package/dist/commands/setup.js +6 -4
  9. package/dist/commands/vet-list.js +2 -0
  10. package/dist/commands/vet.js +2 -0
  11. package/dist/core/ci-analysis.js +14 -1
  12. package/dist/core/comment-utils.d.ts +5 -2
  13. package/dist/core/comment-utils.js +11 -3
  14. package/dist/core/config-registry.js +12 -0
  15. package/dist/core/daily-logic.d.ts +3 -1
  16. package/dist/core/daily-logic.js +11 -3
  17. package/dist/core/index.d.ts +1 -1
  18. package/dist/core/index.js +1 -1
  19. package/dist/core/pr-assembly.d.ts +11 -1
  20. package/dist/core/pr-assembly.js +21 -4
  21. package/dist/core/pr-attention.d.ts +14 -0
  22. package/dist/core/pr-attention.js +18 -0
  23. package/dist/core/pr-graphql.d.ts +31 -1
  24. package/dist/core/pr-graphql.js +49 -5
  25. package/dist/core/pr-monitor.d.ts +37 -0
  26. package/dist/core/pr-monitor.js +42 -0
  27. package/dist/core/repo-cap.d.ts +46 -0
  28. package/dist/core/repo-cap.js +102 -0
  29. package/dist/core/review-analysis.d.ts +64 -0
  30. package/dist/core/review-analysis.js +92 -1
  31. package/dist/core/state-schema.d.ts +12 -0
  32. package/dist/core/state-schema.js +9 -0
  33. package/dist/core/status-determination.js +11 -11
  34. package/dist/core/types.d.ts +32 -2
  35. package/dist/formatters/json.d.ts +25 -0
  36. package/dist/formatters/json.js +13 -0
  37. package/package.json +1 -1
@@ -39,6 +39,10 @@ export const THREAD_COMMENTS_CAP = 20;
39
39
  * contexts than this is sent to REST so a failing check beyond the cap can't be
40
40
  * silently dropped and mislabel the PR as passing. */
41
41
  export const CI_CONTEXTS_CAP = 100;
42
+ /** Newest timeline events (commits, force-pushes, review requests, labels)
43
+ * requested per PR. Only the newest non-contributor event matters for the
44
+ * dormancy clock, so overflow is not routed to REST. */
45
+ export const TIMELINE_CAP = 50;
42
46
  /**
43
47
  * GraphQL reports a GitHub App as `__typename: 'Bot'` with a bare login, where
44
48
  * REST reports the same account as `login: 'name[bot]'`. Restore the REST spelling
@@ -47,6 +51,32 @@ export const CI_CONTEXTS_CAP = 100;
47
51
  function restLogin(actor) {
48
52
  return actor.__typename === 'Bot' && !actor.login.endsWith('[bot]') ? `${actor.login}[bot]` : actor.login;
49
53
  }
54
+ /** REST-shaped `user` (login + type) for a GraphQL actor, so REST and GraphQL agree on bots. */
55
+ function restUser(actor) {
56
+ return actor ? { login: restLogin(actor), type: actor.__typename } : null;
57
+ }
58
+ /** Flatten timeline nodes into activity events (commits yield author and committer). */
59
+ function toActivityEvents(nodes) {
60
+ return nodes.flatMap((n) => {
61
+ if (n.__typename === 'PullRequestCommit') {
62
+ const c = n.commit;
63
+ if (!c)
64
+ return [];
65
+ return [
66
+ { login: c.author?.user?.login, at: c.authoredDate, isPush: true },
67
+ { login: c.committer?.user?.login, at: c.committedDate, isPush: true },
68
+ ];
69
+ }
70
+ return [
71
+ {
72
+ login: n.actor ? restLogin(n.actor) : null,
73
+ type: n.actor?.__typename,
74
+ at: n.createdAt,
75
+ isPush: n.__typename === 'HeadRefForcePushedEvent',
76
+ },
77
+ ];
78
+ });
79
+ }
50
80
  const PR_FIELDS = `
51
81
  databaseId
52
82
  number
@@ -58,11 +88,11 @@ const PR_FIELDS = `
58
88
  updatedAt
59
89
  comments(last: ${COMMENTS_CAP}) {
60
90
  totalCount
61
- nodes { author { login __typename } body createdAt }
91
+ nodes { author { login __typename } authorAssociation body createdAt }
62
92
  }
63
93
  reviews(last: ${REVIEWS_CAP}) {
64
94
  totalCount
65
- nodes { databaseId state body submittedAt author { login __typename } }
95
+ nodes { databaseId state body submittedAt author { login __typename } authorAssociation }
66
96
  }
67
97
  reviewThreads(last: ${REVIEW_THREADS_CAP}) {
68
98
  totalCount
@@ -74,12 +104,22 @@ const PR_FIELDS = `
74
104
  body
75
105
  createdAt
76
106
  author { login __typename }
107
+ authorAssociation
77
108
  replyTo { databaseId }
78
109
  pullRequestReview { databaseId }
79
110
  }
80
111
  }
81
112
  }
82
113
  }
114
+ timelineItems(last: ${TIMELINE_CAP}, itemTypes: [PULL_REQUEST_COMMIT, HEAD_REF_FORCE_PUSHED_EVENT, REVIEW_REQUESTED_EVENT, LABELED_EVENT]) {
115
+ nodes {
116
+ __typename
117
+ ... on PullRequestCommit { commit { authoredDate committedDate author { user { login } } committer { user { login } } } }
118
+ ... on HeadRefForcePushedEvent { createdAt actor { login __typename } }
119
+ ... on ReviewRequestedEvent { createdAt actor { login __typename } }
120
+ ... on LabeledEvent { createdAt actor { login __typename } }
121
+ }
122
+ }
83
123
  commits(last: 1) {
84
124
  nodes {
85
125
  commit {
@@ -172,7 +212,8 @@ export function normalizePRNode(node) {
172
212
  return { kind: 'overflow' };
173
213
  }
174
214
  const comments = node.comments.nodes.map((c) => ({
175
- user: c.author ? { login: restLogin(c.author) } : null,
215
+ user: restUser(c.author),
216
+ author_association: c.authorAssociation,
176
217
  body: c.body,
177
218
  created_at: c.createdAt,
178
219
  }));
@@ -181,7 +222,8 @@ export function normalizePRNode(node) {
181
222
  const reviews = node.reviews.nodes
182
223
  .filter((r) => r.state !== 'PENDING')
183
224
  .map((r) => ({
184
- user: r.author ? { login: restLogin(r.author) } : null,
225
+ user: restUser(r.author),
226
+ author_association: r.authorAssociation,
185
227
  body: r.body,
186
228
  submitted_at: r.submittedAt,
187
229
  state: r.state,
@@ -189,7 +231,8 @@ export function normalizePRNode(node) {
189
231
  }));
190
232
  const reviewComments = node.reviewThreads.nodes.flatMap((thread) => thread.comments.nodes.map((c) => ({
191
233
  id: c.databaseId ?? 0,
192
- user: c.author ? { login: restLogin(c.author) } : null,
234
+ user: restUser(c.author),
235
+ author_association: c.authorAssociation,
193
236
  body: c.body,
194
237
  created_at: c.createdAt,
195
238
  in_reply_to_id: c.replyTo?.databaseId ?? undefined,
@@ -213,6 +256,7 @@ export function normalizePRNode(node) {
213
256
  comments,
214
257
  reviews,
215
258
  reviewComments,
259
+ activityEvents: toActivityEvents(node.timelineItems?.nodes ?? []),
216
260
  ciStatus: toCIStatus(commit),
217
261
  commitInfo,
218
262
  },
@@ -13,6 +13,7 @@
13
13
  * - status-determination.ts: PR status classification logic
14
14
  */
15
15
  import { FetchedPR, DailyDigest, ClosedPR, MergedPR, StarFilter } from './types.js';
16
+ import { type ActivityEvent } from './review-analysis.js';
16
17
  import { type PRCountsResult } from './github-stats.js';
17
18
  export { computeDisplayLabel } from './display-utils.js';
18
19
  export { categorizeCIStatus, classifyCICheck, classifyFailingChecks, getCIStatus } from './ci-analysis.js';
@@ -87,6 +88,14 @@ export declare class PRMonitor {
87
88
  * the computed status is identical regardless of transport.
88
89
  */
89
90
  private fetchPRDetails;
91
+ /**
92
+ * REST counterpart of the GraphQL `timelineItems` selection: commits (author
93
+ * and committer) plus force-push / review-request / label events, used for
94
+ * the maintainer-activity dormancy clock. Non-critical: rate-limit and auth
95
+ * errors propagate, anything else degrades to no events (comments and
96
+ * reviews still drive the clock).
97
+ */
98
+ private fetchActivityEvents;
90
99
  /**
91
100
  * Fetch the HEAD commit's author date and login via REST `repos.getCommit`.
92
101
  * Rate-limit errors propagate (silently swallowing them produces misleading
@@ -150,3 +159,31 @@ export declare class PRMonitor {
150
159
  */
151
160
  updateRepoScoreFromObservedPR(repo: string, wasMerged: boolean): Promise<void>;
152
161
  }
162
+ interface RestTimelineEvent {
163
+ event?: string;
164
+ created_at?: string;
165
+ actor?: {
166
+ login?: string;
167
+ type?: string;
168
+ } | null;
169
+ }
170
+ interface RestPRCommit {
171
+ author?: {
172
+ login?: string;
173
+ type?: string;
174
+ } | null;
175
+ committer?: {
176
+ login?: string;
177
+ type?: string;
178
+ } | null;
179
+ commit: {
180
+ author?: {
181
+ date?: string;
182
+ } | null;
183
+ committer?: {
184
+ date?: string;
185
+ } | null;
186
+ };
187
+ }
188
+ /** Map REST timeline events and PR commits into {@link ActivityEvent}s (mirrors the GraphQL mapping). */
189
+ export declare function restActivityEvents(timeline: RestTimelineEvent[], commits: RestPRCommit[]): ActivityEvent[];
@@ -365,6 +365,7 @@ export class PRMonitor {
365
365
  }
366
366
  const ghPR = prResponse.data;
367
367
  const reviews = reviewsResult.items;
368
+ const activityEvents = await this.fetchActivityEvents(owner, repo, number);
368
369
  const ciStatus = await getCIStatus(this.octokit, owner, repo, ghPR.head.sha);
369
370
  // The commit date is only consulted (and only fetched) when the PR has an
370
371
  // unresponded maintainer comment or a changes-requested review — the shared
@@ -388,9 +389,32 @@ export class PRMonitor {
388
389
  comments,
389
390
  reviews,
390
391
  reviewComments,
392
+ activityEvents,
391
393
  ciStatus,
392
394
  }, config, commitInfo);
393
395
  }
396
+ /**
397
+ * REST counterpart of the GraphQL `timelineItems` selection: commits (author
398
+ * and committer) plus force-push / review-request / label events, used for
399
+ * the maintainer-activity dormancy clock. Non-critical: rate-limit and auth
400
+ * errors propagate, anything else degrades to no events (comments and
401
+ * reviews still drive the clock).
402
+ */
403
+ async fetchActivityEvents(owner, repo, number) {
404
+ try {
405
+ const [timeline, commits] = await Promise.all([
406
+ paginateAllDetailed((page) => this.octokit.issues.listEventsForTimeline({ owner, repo, page, issue_number: number, per_page: 100 })),
407
+ paginateAllDetailed((page) => this.octokit.pulls.listCommits({ owner, repo, page, pull_number: number, per_page: 100 })),
408
+ ]);
409
+ return restActivityEvents(timeline.items, commits.items);
410
+ }
411
+ catch (err) {
412
+ if (isRateLimitOrAuthError(err))
413
+ throw err;
414
+ warn(MODULE, `Failed to fetch timeline for ${owner}/${repo}#${number}: ${errorMessage(err)}`);
415
+ return [];
416
+ }
417
+ }
394
418
  /**
395
419
  * Fetch the HEAD commit's author date and login via REST `repos.getCommit`.
396
420
  * Rate-limit errors propagate (silently swallowing them produces misleading
@@ -443,6 +467,7 @@ export class PRMonitor {
443
467
  comments: data.comments,
444
468
  reviews: data.reviews,
445
469
  reviewComments: data.reviewComments,
470
+ activityEvents: data.activityEvents,
446
471
  ciStatus: data.ciStatus,
447
472
  }, config, data.commitInfo);
448
473
  }
@@ -581,3 +606,20 @@ export class PRMonitor {
581
606
  }
582
607
  }
583
608
  }
609
+ /** Timeline event kinds whose actor marks maintainer engagement. */
610
+ const ACTIVITY_TIMELINE_EVENTS = new Set(['head_ref_force_pushed', 'review_requested', 'labeled']);
611
+ /** Map REST timeline events and PR commits into {@link ActivityEvent}s (mirrors the GraphQL mapping). */
612
+ export function restActivityEvents(timeline, commits) {
613
+ const events = timeline
614
+ .filter((e) => e.event && ACTIVITY_TIMELINE_EVENTS.has(e.event))
615
+ .map((e) => ({
616
+ login: e.actor?.login,
617
+ type: e.actor?.type,
618
+ at: e.created_at,
619
+ isPush: e.event === 'head_ref_force_pushed',
620
+ }));
621
+ for (const c of commits) {
622
+ events.push({ login: c.author?.login, type: c.author?.type, at: c.commit.author?.date, isPush: true }, { login: c.committer?.login, type: c.committer?.type, at: c.commit.committer?.date, isPush: true });
623
+ }
624
+ return events;
625
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Per-repo open-PR cap. First PRs into a repo merge less often than later
3
+ * ones, so discovery leaves a repo out once the user has
4
+ * `maxOpenPRsColdRepo` open PRs there while none of their PRs in it have
5
+ * merged, or `maxOpenPRsPerRepo` open PRs in any repo (off by default).
6
+ * 0 disables either cap.
7
+ *
8
+ * Discovery counts open PRs from the last digest (`state.lastDigest.openPRs`),
9
+ * as fresh as the last `daily` run. The `repo-cap` command passes a live
10
+ * count from GitHub instead.
11
+ */
12
+ import type { AgentState } from './state-schema.js';
13
+ export interface RepoCapStatus {
14
+ repo: string;
15
+ openPRCount: number;
16
+ /** Where `openPRCount` came from: the last digest, or a live GitHub search. */
17
+ countSource: 'digest' | 'github';
18
+ mergedPRCount: number;
19
+ /** True while the user has no merged PR in this repo, so the cold cap applies. */
20
+ cold: boolean;
21
+ /** The cap that applies (0 = no cap). */
22
+ cap: number;
23
+ atCap: boolean;
24
+ /** The repo is in `config.excludeRepos`. */
25
+ excluded: boolean;
26
+ /** Human-readable reason, set when `atCap` or `excluded`. */
27
+ reason?: string;
28
+ }
29
+ /** Open-PR counts from the last digest, keyed by lowercased owner/repo. */
30
+ export declare function openPRCountsByRepo(state: Readonly<AgentState>): Map<string, number>;
31
+ /**
32
+ * Cap status for one repo. `openPRCount` defaults to the digest count; pass a
33
+ * live count (with `countSource: 'github'`) to override it.
34
+ */
35
+ export declare function getRepoCapStatus(state: Readonly<AgentState>, repo: string, live?: {
36
+ openPRCount: number;
37
+ }): RepoCapStatus;
38
+ /**
39
+ * Repos (owner/repo, first spelling seen in the digest) at their open-PR cap,
40
+ * from the last digest. Discovery passes these to scout as excluded repos.
41
+ */
42
+ export declare function reposAtCap(state: Readonly<AgentState>): string[];
43
+ /** `{ repoCap }` when the repo is at cap or excluded, else `{}`; spread into vet output. */
44
+ export declare function repoCapField(state: Readonly<AgentState>, repo: string): {
45
+ repoCap?: RepoCapStatus;
46
+ };
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Per-repo open-PR cap. First PRs into a repo merge less often than later
3
+ * ones, so discovery leaves a repo out once the user has
4
+ * `maxOpenPRsColdRepo` open PRs there while none of their PRs in it have
5
+ * merged, or `maxOpenPRsPerRepo` open PRs in any repo (off by default).
6
+ * 0 disables either cap.
7
+ *
8
+ * Discovery counts open PRs from the last digest (`state.lastDigest.openPRs`),
9
+ * as fresh as the last `daily` run. The `repo-cap` command passes a live
10
+ * count from GitHub instead.
11
+ */
12
+ import { parseGitHubUrl } from './urls.js';
13
+ /** Open-PR counts from the last digest, keyed by lowercased owner/repo. */
14
+ export function openPRCountsByRepo(state) {
15
+ const counts = new Map();
16
+ const openPRs = state.lastDigest?.openPRs;
17
+ if (!openPRs)
18
+ return counts;
19
+ for (const pr of openPRs) {
20
+ const key = pr.repo.toLowerCase();
21
+ counts.set(key, (counts.get(key) ?? 0) + 1);
22
+ }
23
+ return counts;
24
+ }
25
+ function mergedCount(state, repo) {
26
+ const key = repo.toLowerCase();
27
+ const scoreEntry = Object.entries(state.repoScores ?? {}).find(([r]) => r.toLowerCase() === key)?.[1];
28
+ const fromScore = scoreEntry?.mergedPRCount ?? 0;
29
+ if (fromScore > 0)
30
+ return fromScore;
31
+ // Fall back to the outcome ledger: repoScores can lag behind it.
32
+ return (state.mergedPRs ?? []).filter((pr) => {
33
+ const parsed = parseGitHubUrl(pr.url);
34
+ return parsed !== null && `${parsed.owner}/${parsed.repo}`.toLowerCase() === key;
35
+ }).length;
36
+ }
37
+ /** The tighter of the caps that apply (0 = none). */
38
+ function applicableCap(config, isCold) {
39
+ const { maxOpenPRsPerRepo = 0, maxOpenPRsColdRepo = 0 } = config;
40
+ const caps = [maxOpenPRsPerRepo, isCold ? maxOpenPRsColdRepo : 0].filter((c) => c > 0);
41
+ return caps.length > 0 ? Math.min(...caps) : 0;
42
+ }
43
+ function capReason(status) {
44
+ const reasons = [];
45
+ if (status.excluded)
46
+ reasons.push(`${status.repo} is in excludeRepos`);
47
+ if (status.atCap) {
48
+ const coldNote = status.cold ? ' for a repo where none of your PRs have merged yet' : '';
49
+ reasons.push(`${status.repo} has ${status.openPRCount} open PR(s), at the cap of ${status.cap}${coldNote}`);
50
+ }
51
+ return reasons.length > 0 ? reasons.join('; ') : undefined;
52
+ }
53
+ /**
54
+ * Cap status for one repo. `openPRCount` defaults to the digest count; pass a
55
+ * live count (with `countSource: 'github'`) to override it.
56
+ */
57
+ export function getRepoCapStatus(state, repo, live) {
58
+ // ponytail: tolerate partial states (test fixtures, hand-built mocks); a
59
+ // parsed AgentState always has these defaults.
60
+ const config = state.config ?? {};
61
+ const openPRCount = live?.openPRCount ?? openPRCountsByRepo(state).get(repo.toLowerCase()) ?? 0;
62
+ const merged = mergedCount(state, repo);
63
+ const isCold = merged === 0;
64
+ const limit = applicableCap(config, isCold);
65
+ const status = {
66
+ repo,
67
+ openPRCount,
68
+ countSource: live ? 'github' : 'digest',
69
+ mergedPRCount: merged,
70
+ cold: isCold,
71
+ cap: limit,
72
+ atCap: limit > 0 && openPRCount >= limit,
73
+ excluded: (config.excludeRepos ?? []).some((r) => r.toLowerCase() === repo.toLowerCase()),
74
+ };
75
+ const reason = capReason(status);
76
+ return reason ? { ...status, reason } : status;
77
+ }
78
+ /**
79
+ * Repos (owner/repo, first spelling seen in the digest) at their open-PR cap,
80
+ * from the last digest. Discovery passes these to scout as excluded repos.
81
+ */
82
+ export function reposAtCap(state) {
83
+ const openPRs = state.lastDigest?.openPRs;
84
+ if (!openPRs)
85
+ return [];
86
+ const seen = new Set();
87
+ const capped = [];
88
+ for (const pr of openPRs) {
89
+ const key = pr.repo.toLowerCase();
90
+ if (seen.has(key))
91
+ continue;
92
+ seen.add(key);
93
+ if (getRepoCapStatus(state, pr.repo).atCap)
94
+ capped.push(pr.repo);
95
+ }
96
+ return capped;
97
+ }
98
+ /** `{ repoCap }` when the repo is at cap or excluded, else `{}`; spread into vet output. */
99
+ export function repoCapField(state, repo) {
100
+ const status = getRepoCapStatus(state, repo);
101
+ return status.reason ? { repoCap: status } : {};
102
+ }
@@ -9,7 +9,9 @@ export interface ReviewComment {
9
9
  id: number;
10
10
  user?: {
11
11
  login?: string;
12
+ type?: string | null;
12
13
  } | null;
14
+ author_association?: string | null;
13
15
  body?: string | null;
14
16
  created_at: string;
15
17
  in_reply_to_id?: number;
@@ -84,12 +86,14 @@ export declare function getFirstMaintainerResponseAt(comments: Array<{
84
86
  export declare function checkUnrespondedComments(comments: Array<{
85
87
  user?: {
86
88
  login?: string;
89
+ type?: string | null;
87
90
  } | null;
88
91
  body?: string | null;
89
92
  created_at: string;
90
93
  }>, reviews: Array<{
91
94
  user?: {
92
95
  login?: string;
96
+ type?: string | null;
93
97
  } | null;
94
98
  body?: string | null;
95
99
  submitted_at?: string | null;
@@ -99,3 +103,63 @@ export declare function checkUnrespondedComments(comments: Array<{
99
103
  hasUnrespondedComment: boolean;
100
104
  lastMaintainerComment?: FetchedPR['lastMaintainerComment'];
101
105
  };
106
+ /** A non-comment PR event: a commit, force-push, review request or label. */
107
+ export interface ActivityEvent {
108
+ login?: string | null;
109
+ /** REST `user.type` / GraphQL `__typename` of the actor (`'Bot'` for apps). */
110
+ type?: string | null;
111
+ at?: string | null;
112
+ /**
113
+ * True for commits and force-pushes. A push by a bot still counts as
114
+ * maintainer activity (a maintainer's own GitHub App pushing fixes), unless
115
+ * the bot is an auto-fixer or dependency bot in {@link PUSH_BOT_DENYLIST}.
116
+ */
117
+ isPush?: boolean;
118
+ }
119
+ /**
120
+ * Minimum gap since the previous activity (maintainer or contributor) for a
121
+ * contributor comment to count as a "ping". A same-day reply to a maintainer
122
+ * is conversation, not a nudge.
123
+ */
124
+ export declare const PING_MIN_GAP_DAYS = 7;
125
+ type ActorFields = {
126
+ user?: {
127
+ login?: string;
128
+ type?: string | null;
129
+ } | null;
130
+ author_association?: string | null;
131
+ };
132
+ /**
133
+ * Latest maintainer activity on a PR, falling back to `createdAt` when no
134
+ * maintainer has engaged, plus the number of contributor pings since then.
135
+ *
136
+ * Maintainer activity is any of:
137
+ * - an issue comment by an OWNER / MEMBER / COLLABORATOR, so drive-by "+1"
138
+ * comments don't reset the clock (when the association is unknown, as on
139
+ * older data, any non-contributor non-bot author counts);
140
+ * - a review or inline review comment by any non-contributor non-bot user
141
+ * (codeowners often show as CONTRIBUTOR);
142
+ * - a commit authored or committed by someone else, or a force-push by
143
+ * someone else, including bots such as a maintainer's own GitHub App,
144
+ * except auto-fixer / dependency bots ({@link PUSH_BOT_DENYLIST});
145
+ * - a review request or label by a non-contributor non-bot actor.
146
+ *
147
+ * Staleness is measured from this timestamp rather than `updatedAt`, because
148
+ * `updatedAt` is bumped by the contributor's own follow-ups and rebases, so a
149
+ * PR the maintainers have ignored for months never looked dormant.
150
+ *
151
+ * A contributor comment counts as a ping only when it comes at least
152
+ * {@link PING_MIN_GAP_DAYS} after the previous activity (the maintainer
153
+ * activity or the contributor's own previous comment).
154
+ */
155
+ export declare function getLastMaintainerActivity(comments: Array<ActorFields & {
156
+ created_at: string;
157
+ }>, reviews: Array<ActorFields & {
158
+ submitted_at?: string | null;
159
+ }>, reviewComments: Array<ActorFields & {
160
+ created_at: string;
161
+ }>, events: ActivityEvent[], username: string, createdAt: string): {
162
+ lastMaintainerActivityAt: string;
163
+ authorPingsSinceMaintainerActivity: number;
164
+ };
165
+ export {};
@@ -145,6 +145,7 @@ export function checkUnrespondedComments(comments, reviews, reviewComments, user
145
145
  const author = comment.user?.login || 'unknown';
146
146
  timeline.push({
147
147
  author,
148
+ userType: comment.user?.type,
148
149
  body: comment.body || '',
149
150
  createdAt: comment.created_at,
150
151
  isUser: author.toLowerCase() === usernameLower,
@@ -174,6 +175,7 @@ export function checkUnrespondedComments(comments, reviews, reviewComments, user
174
175
  : '(posted inline review comments)');
175
176
  timeline.push({
176
177
  author,
178
+ userType: review.user?.type,
177
179
  body: resolvedBody,
178
180
  createdAt: review.submitted_at,
179
181
  isUser: author.toLowerCase() === usernameLower,
@@ -197,7 +199,7 @@ export function checkUnrespondedComments(comments, reviews, reviewComments, user
197
199
  continue; // Skip user's own comments
198
200
  if (item.author === 'unknown')
199
201
  continue; // Skip deleted/null accounts
200
- if (isBotAuthor(item.author))
202
+ if (isBotAuthor(item.author, item.userType))
201
203
  continue; // Skip bots
202
204
  const itemTime = new Date(item.createdAt);
203
205
  if (!lastUserCommentTime || itemTime > lastUserCommentTime) {
@@ -221,3 +223,92 @@ export function checkUnrespondedComments(comments, reviews, reviewComments, user
221
223
  lastMaintainerComment,
222
224
  };
223
225
  }
226
+ /**
227
+ * Bots whose pushes are automation, not maintainer engagement. Compared
228
+ * case-insensitively with any `[bot]` suffix stripped.
229
+ */
230
+ const PUSH_BOT_DENYLIST = new Set([
231
+ 'pre-commit-ci',
232
+ 'autofix-ci',
233
+ 'prettier-ci',
234
+ 'github-actions',
235
+ 'dependabot',
236
+ 'renovate',
237
+ 'web-flow',
238
+ ]);
239
+ /** Author associations that mark a commenter as a repo maintainer. */
240
+ const MAINTAINER_ASSOCIATIONS = new Set(['OWNER', 'MEMBER', 'COLLABORATOR']);
241
+ /**
242
+ * Minimum gap since the previous activity (maintainer or contributor) for a
243
+ * contributor comment to count as a "ping". A same-day reply to a maintainer
244
+ * is conversation, not a nudge.
245
+ */
246
+ export const PING_MIN_GAP_DAYS = 7;
247
+ /**
248
+ * Latest maintainer activity on a PR, falling back to `createdAt` when no
249
+ * maintainer has engaged, plus the number of contributor pings since then.
250
+ *
251
+ * Maintainer activity is any of:
252
+ * - an issue comment by an OWNER / MEMBER / COLLABORATOR, so drive-by "+1"
253
+ * comments don't reset the clock (when the association is unknown, as on
254
+ * older data, any non-contributor non-bot author counts);
255
+ * - a review or inline review comment by any non-contributor non-bot user
256
+ * (codeowners often show as CONTRIBUTOR);
257
+ * - a commit authored or committed by someone else, or a force-push by
258
+ * someone else, including bots such as a maintainer's own GitHub App,
259
+ * except auto-fixer / dependency bots ({@link PUSH_BOT_DENYLIST});
260
+ * - a review request or label by a non-contributor non-bot actor.
261
+ *
262
+ * Staleness is measured from this timestamp rather than `updatedAt`, because
263
+ * `updatedAt` is bumped by the contributor's own follow-ups and rebases, so a
264
+ * PR the maintainers have ignored for months never looked dormant.
265
+ *
266
+ * A contributor comment counts as a ping only when it comes at least
267
+ * {@link PING_MIN_GAP_DAYS} after the previous activity (the maintainer
268
+ * activity or the contributor's own previous comment).
269
+ */
270
+ export function getLastMaintainerActivity(comments, reviews, reviewComments, events, username, createdAt) {
271
+ const usernameLower = username.toLowerCase();
272
+ let latest = createdAt;
273
+ let latestMs = Date.parse(createdAt);
274
+ const consider = (login, type, at, isPush = false) => {
275
+ if (!login || !at)
276
+ return;
277
+ const lower = login.toLowerCase();
278
+ if (lower === usernameLower)
279
+ return;
280
+ if (isPush ? PUSH_BOT_DENYLIST.has(lower.replace(/\[bot\]$/, '')) : isBotAuthor(login, type))
281
+ return;
282
+ const ms = Date.parse(at);
283
+ if (ms > latestMs) {
284
+ latest = at;
285
+ latestMs = ms;
286
+ }
287
+ };
288
+ for (const c of comments) {
289
+ const association = c.author_association;
290
+ if (association && !MAINTAINER_ASSOCIATIONS.has(association))
291
+ continue;
292
+ consider(c.user?.login, c.user?.type, c.created_at);
293
+ }
294
+ for (const r of reviews)
295
+ consider(r.user?.login, r.user?.type, r.submitted_at);
296
+ for (const c of reviewComments)
297
+ consider(c.user?.login, c.user?.type, c.created_at);
298
+ for (const e of events)
299
+ consider(e.login, e.type, e.at, e.isPush);
300
+ const authorCommentTimes = comments
301
+ .filter((c) => c.user?.login?.toLowerCase() === usernameLower)
302
+ .map((c) => Date.parse(c.created_at))
303
+ .filter((ms) => ms > latestMs);
304
+ authorCommentTimes.sort((a, b) => a - b);
305
+ const minGapMs = PING_MIN_GAP_DAYS * 86_400_000;
306
+ let previousMs = latestMs;
307
+ let authorPingsSinceMaintainerActivity = 0;
308
+ for (const ms of authorCommentTimes) {
309
+ if (ms - previousMs >= minGapMs)
310
+ authorPingsSinceMaintainerActivity++;
311
+ previousMs = ms;
312
+ }
313
+ return { lastMaintainerActivityAt: latest, authorPingsSinceMaintainerActivity };
314
+ }
@@ -289,6 +289,8 @@ export declare const AgentConfigSchema: z.ZodPipe<z.ZodObject<{
289
289
  gist: "gist";
290
290
  }>>;
291
291
  maxActivePRs: z.ZodDefault<z.ZodNumber>;
292
+ maxOpenPRsPerRepo: z.ZodDefault<z.ZodNumber>;
293
+ maxOpenPRsColdRepo: z.ZodDefault<z.ZodNumber>;
292
294
  dormantThresholdDays: z.ZodDefault<z.ZodNumber>;
293
295
  approachingDormantDays: z.ZodDefault<z.ZodNumber>;
294
296
  maxIssueAgeDays: z.ZodDefault<z.ZodNumber>;
@@ -355,6 +357,8 @@ export declare const AgentConfigSchema: z.ZodPipe<z.ZodObject<{
355
357
  setupComplete: boolean;
356
358
  persistence: "local" | "gist";
357
359
  maxActivePRs: number;
360
+ maxOpenPRsPerRepo: number;
361
+ maxOpenPRsColdRepo: number;
358
362
  dormantThresholdDays: number;
359
363
  approachingDormantDays: number;
360
364
  maxIssueAgeDays: number;
@@ -403,6 +407,8 @@ export declare const AgentConfigSchema: z.ZodPipe<z.ZodObject<{
403
407
  setupComplete: boolean;
404
408
  persistence: "local" | "gist";
405
409
  maxActivePRs: number;
410
+ maxOpenPRsPerRepo: number;
411
+ maxOpenPRsColdRepo: number;
406
412
  dormantThresholdDays: number;
407
413
  approachingDormantDays: number;
408
414
  maxIssueAgeDays: number;
@@ -677,6 +683,8 @@ export declare const AgentStateSchema: z.ZodObject<{
677
683
  gist: "gist";
678
684
  }>>;
679
685
  maxActivePRs: z.ZodDefault<z.ZodNumber>;
686
+ maxOpenPRsPerRepo: z.ZodDefault<z.ZodNumber>;
687
+ maxOpenPRsColdRepo: z.ZodDefault<z.ZodNumber>;
680
688
  dormantThresholdDays: z.ZodDefault<z.ZodNumber>;
681
689
  approachingDormantDays: z.ZodDefault<z.ZodNumber>;
682
690
  maxIssueAgeDays: z.ZodDefault<z.ZodNumber>;
@@ -743,6 +751,8 @@ export declare const AgentStateSchema: z.ZodObject<{
743
751
  setupComplete: boolean;
744
752
  persistence: "local" | "gist";
745
753
  maxActivePRs: number;
754
+ maxOpenPRsPerRepo: number;
755
+ maxOpenPRsColdRepo: number;
746
756
  dormantThresholdDays: number;
747
757
  approachingDormantDays: number;
748
758
  maxIssueAgeDays: number;
@@ -791,6 +801,8 @@ export declare const AgentStateSchema: z.ZodObject<{
791
801
  setupComplete: boolean;
792
802
  persistence: "local" | "gist";
793
803
  maxActivePRs: number;
804
+ maxOpenPRsPerRepo: number;
805
+ maxOpenPRsColdRepo: number;
794
806
  dormantThresholdDays: number;
795
807
  approachingDormantDays: number;
796
808
  maxIssueAgeDays: number;
@@ -247,6 +247,15 @@ export const AgentConfigSchema = z
247
247
  setupCompletedAt: z.string().optional(),
248
248
  persistence: z.enum(['local', 'gist']).default('local'),
249
249
  maxActivePRs: z.number().default(10),
250
+ /**
251
+ * Per-repo open-PR caps (core/repo-cap.ts). Discovery leaves out a repo
252
+ * once the user has this many open PRs there; the cold cap applies while
253
+ * none of their PRs in the repo have merged (first PRs merge less often).
254
+ * The warm cap is off by default so it never blocks repos that merge.
255
+ * 0 disables either.
256
+ */
257
+ maxOpenPRsPerRepo: z.number().int().min(0).default(0),
258
+ maxOpenPRsColdRepo: z.number().int().min(0).default(1),
250
259
  dormantThresholdDays: z.number().default(30),
251
260
  approachingDormantDays: z.number().default(25),
252
261
  maxIssueAgeDays: z.number().default(90),