@oss-autopilot/core 3.31.5 → 3.32.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.
@@ -12,6 +12,7 @@ import { wrapUntrustedContent } from '../core/untrusted-content.js';
12
12
  import { computeStrategy, shouldComputeStrategy } from '../core/strategy.js';
13
13
  import { warn } from '../core/logger.js';
14
14
  import { emptyPRCountsResult } from '../core/github-stats.js';
15
+ import { findRepoTransfers } from '../core/repo-score-manager.js';
15
16
  import { updateMonthlyAnalytics } from './dashboard-data.js';
16
17
  import { deduplicateDigest, compactActionableIssues, compactRepoGroups, buildStalenessWarning, } from '../formatters/json.js';
17
18
  import { reconcileMergedPRsWithList } from './merge-loop.js';
@@ -162,6 +163,7 @@ async function fetchPRData(prMonitor, token, warnings) {
162
163
  const { repos: mergedCounts, monthlyCounts, monthlyOpenedCounts: openedFromMerged } = mergedResult;
163
164
  const { repos: closedCounts, monthlyCounts: monthlyClosedCounts, monthlyOpenedCounts: openedFromClosed, } = closedResult;
164
165
  return {
166
+ searchedPRs: [...mergedResult.searchedPRs, ...closedResult.searchedPRs],
165
167
  prs,
166
168
  failures,
167
169
  mergedCounts,
@@ -180,13 +182,20 @@ async function fetchPRData(prMonitor, token, warnings) {
180
182
  * Applies stale repo reset, updates merged/closed counts, computes and stores
181
183
  * repo signals from open PR data, refreshes star counts, and syncs trusted projects.
182
184
  */
183
- async function updateRepoScores(prMonitor, prs, mergedCounts, closedCounts, warnings) {
185
+ async function updateRepoScores(prMonitor, prs, mergedCounts, closedCounts, searchedPRs, warnings) {
184
186
  const stateManager = getStateManager();
185
187
  // Batch all synchronous score mutations for a single disk write.
186
188
  // Per-repo try-catch: a single corrupted repo should not prevent updates to others.
187
189
  // Outer try-catch: save failure should not crash the daily check (in-memory mutations still apply).
188
190
  try {
189
191
  batchOnFreshBaseline(stateManager, () => {
192
+ // Re-key transferred/renamed repos before anything reads repoScores, so
193
+ // the old name isn't zeroed here and then re-bumped from stored PR URLs
194
+ // on the next load (which double counted its merges in getStats).
195
+ const stored = [...stateManager.getMergedPRs(), ...stateManager.getClosedPRs()];
196
+ for (const [from, to] of findRepoTransfers(stored, searchedPRs)) {
197
+ stateManager.renameRepo(from, to);
198
+ }
190
199
  // Reset stale repos first (so excluded/removed repos get zeroed).
191
200
  // Guard: if the API returned zero results but we have existing repos with merged PRs,
192
201
  // skip the reset to avoid wiping scores due to transient API failures.
@@ -634,9 +643,9 @@ async function executeDailyCheckInternal(token) {
634
643
  (loadRecovery.rejectedPath ? `; rejected file preserved at ${loadRecovery.rejectedPath}` : '')));
635
644
  }
636
645
  // Phase 1: Fetch all PR data from GitHub
637
- const { prs, failures, mergedCounts, closedCounts, monthlyCounts, monthlyClosedCounts, openedFromMerged, openedFromClosed, recentlyClosedPRs, recentlyMergedPRs, commentedIssues, } = await fetchPRData(prMonitor, token, warnings);
646
+ const { prs, failures, mergedCounts, closedCounts, searchedPRs, monthlyCounts, monthlyClosedCounts, openedFromMerged, openedFromClosed, recentlyClosedPRs, recentlyMergedPRs, commentedIssues, } = await fetchPRData(prMonitor, token, warnings);
638
647
  // Phase 2: Update repo scores (signals, star counts, trust sync)
639
- await updateRepoScores(prMonitor, prs, mergedCounts, closedCounts, warnings);
648
+ await updateRepoScores(prMonitor, prs, mergedCounts, closedCounts, searchedPRs, warnings);
640
649
  // Phase 3: Persist monthly analytics and store merged/closed PR history.
641
650
  // try-catch: analytics are supplementary — save failure should not crash the daily check.
642
651
  try {
@@ -12,6 +12,15 @@ export interface PRCountsResult<R> {
12
12
  monthlyCounts: Record<string, number>;
13
13
  monthlyOpenedCounts: Record<string, number>;
14
14
  dailyActivityCounts: Record<string, number>;
15
+ /**
16
+ * Every non-own PR the search returned (before the star filter), as
17
+ * URL + title. Lets the daily run spot repos that were transferred or
18
+ * renamed since a stored PR was recorded (see findRepoTransfers).
19
+ */
20
+ searchedPRs: Array<{
21
+ url: string;
22
+ title: string;
23
+ }>;
15
24
  }
16
25
  /** Returns an empty PRCountsResult. Used as the fallback when stats fetches fail or username is empty. */
17
26
  export declare function emptyPRCountsResult<R>(): PRCountsResult<R>;
@@ -17,7 +17,7 @@ export const PR_COUNTS_CACHE_TTL_MS = 24 * 60 * 60 * 1000;
17
17
  const MAX_PAGINATION_PAGES = 3;
18
18
  /** Returns an empty PRCountsResult. Used as the fallback when stats fetches fail or username is empty. */
19
19
  export function emptyPRCountsResult() {
20
- return { repos: new Map(), monthlyCounts: {}, monthlyOpenedCounts: {}, dailyActivityCounts: {} };
20
+ return { repos: new Map(), monthlyCounts: {}, monthlyOpenedCounts: {}, dailyActivityCounts: {}, searchedPRs: [] };
21
21
  }
22
22
  /** Type guard for deserialized cache data — prevents crashes on corrupt/stale cache. */
23
23
  function isCachedPRCounts(v) {
@@ -56,6 +56,7 @@ async function fetchUserPRCounts(octokit, githubUsername, query, label, accumula
56
56
  monthlyCounts: cached.monthlyCounts,
57
57
  monthlyOpenedCounts: cached.monthlyOpenedCounts,
58
58
  dailyActivityCounts: cached.dailyActivityCounts,
59
+ searchedPRs: Array.isArray(cached.searchedPRs) ? cached.searchedPRs : [],
59
60
  };
60
61
  }
61
62
  debug(MODULE, `Fetching ${label} PR counts for @${githubUsername}...`);
@@ -63,6 +64,7 @@ async function fetchUserPRCounts(octokit, githubUsername, query, label, accumula
63
64
  const monthlyCounts = {};
64
65
  const monthlyOpenedCounts = {};
65
66
  const dailyActivityCounts = {};
67
+ const searchedPRs = [];
66
68
  let page = 1;
67
69
  let fetched = 0;
68
70
  let totalCount;
@@ -86,6 +88,7 @@ async function fetchUserPRCounts(octokit, githubUsername, query, label, accumula
86
88
  // Skip own repos (PRs to your own repos aren't OSS contributions)
87
89
  if (isOwnRepo(owner, githubUsername))
88
90
  continue;
91
+ searchedPRs.push({ url: item.html_url, title: item.title ?? '' });
89
92
  // Skip repos below the minimum star threshold (#576).
90
93
  // Repos with unknown star counts (not yet fetched) are also excluded (fail-closed).
91
94
  if (starFilter && isBelowMinStars(starFilter.knownStarCounts.get(repo), starFilter.minStars)) {
@@ -133,8 +136,9 @@ async function fetchUserPRCounts(octokit, githubUsername, query, label, accumula
133
136
  monthlyCounts,
134
137
  monthlyOpenedCounts,
135
138
  dailyActivityCounts,
139
+ searchedPRs,
136
140
  });
137
- return { repos, monthlyCounts, monthlyOpenedCounts, dailyActivityCounts };
141
+ return { repos, monthlyCounts, monthlyOpenedCounts, dailyActivityCounts, searchedPRs };
138
142
  }
139
143
  /**
140
144
  * Fetch merged PR counts and latest merge dates per repository for the configured user.
@@ -90,6 +90,31 @@ export interface Stats {
90
90
  * the array count is higher (never decreases). Returns true if any updates were made.
91
91
  */
92
92
  export declare function reconcilePRCounts(state: AgentState, mergedPRs: StoredMergedPR[], closedPRs: StoredClosedPR[]): boolean;
93
+ /**
94
+ * Detect repos that GitHub now reports under a different owner/name.
95
+ *
96
+ * Stored PR URLs keep whatever repo name was current when they were
97
+ * recorded. After a transfer or rename, the search API returns the same PR
98
+ * under the new name, so the repo is scored under both keys and counted
99
+ * twice. A stored PR whose URL the search did not return, but whose PR
100
+ * number and title match a search hit in another repo, marks a transfer.
101
+ *
102
+ * @returns map of old repo (`owner/repo`) to the repo GitHub now reports
103
+ */
104
+ export declare function findRepoTransfers(stored: ReadonlyArray<{
105
+ url: string;
106
+ title: string;
107
+ }>, searched: ReadonlyArray<{
108
+ url: string;
109
+ title: string;
110
+ }>): Map<string, string>;
111
+ /**
112
+ * Move a transferred repo's history to its new name: rewrite stored PR URLs
113
+ * and drop (or re-key) the old repoScores entry so it stops double counting.
114
+ * When both names hold the same PR, the rewritten entry wins because it
115
+ * carries the older ledger stamps.
116
+ */
117
+ export declare function renameRepo(state: AgentState, from: string, to: string): void;
93
118
  /**
94
119
  * Compute aggregate statistics from the current state.
95
120
  */
@@ -272,6 +272,70 @@ function reconcileField(state, countsByRepo, field) {
272
272
  }
273
273
  return updated;
274
274
  }
275
+ /**
276
+ * Detect repos that GitHub now reports under a different owner/name.
277
+ *
278
+ * Stored PR URLs keep whatever repo name was current when they were
279
+ * recorded. After a transfer or rename, the search API returns the same PR
280
+ * under the new name, so the repo is scored under both keys and counted
281
+ * twice. A stored PR whose URL the search did not return, but whose PR
282
+ * number and title match a search hit in another repo, marks a transfer.
283
+ *
284
+ * @returns map of old repo (`owner/repo`) to the repo GitHub now reports
285
+ */
286
+ export function findRepoTransfers(stored, searched) {
287
+ const searchedUrls = new Set(searched.map((pr) => pr.url));
288
+ const repoByPR = new Map();
289
+ for (const pr of searched) {
290
+ const parsed = parseGitHubUrl(pr.url);
291
+ if (!parsed || !pr.title)
292
+ continue;
293
+ repoByPR.set(`${parsed.number}\0${pr.title}`, `${parsed.owner}/${parsed.repo}`);
294
+ }
295
+ const transfers = new Map();
296
+ for (const pr of stored) {
297
+ const parsed = searchedUrls.has(pr.url) || !pr.title ? null : parseGitHubUrl(pr.url);
298
+ if (!parsed)
299
+ continue;
300
+ const from = `${parsed.owner}/${parsed.repo}`;
301
+ const to = repoByPR.get(`${parsed.number}\0${pr.title}`);
302
+ if (to && to !== from)
303
+ transfers.set(from, to);
304
+ }
305
+ return transfers;
306
+ }
307
+ /**
308
+ * Move a transferred repo's history to its new name: rewrite stored PR URLs
309
+ * and drop (or re-key) the old repoScores entry so it stops double counting.
310
+ * When both names hold the same PR, the rewritten entry wins because it
311
+ * carries the older ledger stamps.
312
+ */
313
+ export function renameRepo(state, from, to) {
314
+ const fromPrefix = `https://github.com/${from}/`;
315
+ const toPrefix = `https://github.com/${to}/`;
316
+ const rewrite = (prs) => {
317
+ if (!prs?.some((pr) => pr.url.startsWith(fromPrefix)))
318
+ return prs;
319
+ const moved = new Set();
320
+ const out = prs.map((pr) => {
321
+ if (!pr.url.startsWith(fromPrefix))
322
+ return pr;
323
+ const url = toPrefix + pr.url.slice(fromPrefix.length);
324
+ moved.add(url);
325
+ return { ...pr, url };
326
+ });
327
+ return out.filter((pr, i) => !moved.has(pr.url) || prs[i].url.startsWith(fromPrefix));
328
+ };
329
+ state.mergedPRs = rewrite(state.mergedPRs);
330
+ state.closedPRs = rewrite(state.closedPRs);
331
+ const oldScore = state.repoScores[from];
332
+ if (oldScore) {
333
+ if (!Object.hasOwn(state.repoScores, to))
334
+ state.repoScores[to] = { ...oldScore, repo: to };
335
+ delete state.repoScores[from];
336
+ }
337
+ debug(MODULE, `Renamed transferred repo ${from} → ${to}`);
338
+ }
275
339
  /**
276
340
  * Compute aggregate statistics from the current state.
277
341
  */
@@ -450,6 +450,8 @@ export declare class StateManager {
450
450
  getLowScoringRepos(maxScore?: number): string[];
451
451
  /** Returns aggregate contribution statistics (merge rate, PR counts, repo breakdown). */
452
452
  getStats(): Stats;
453
+ /** Move a transferred repo's stored PRs and score to its new name. See repoScoring.renameRepo. */
454
+ renameRepo(from: string, to: string): void;
453
455
  /**
454
456
  * Reconcile repoScores merged/closed counts with the stored PR arrays.
455
457
  * Bumps counters when the array has more PRs than the counter tracks.
@@ -1036,6 +1036,11 @@ export class StateManager {
1036
1036
  getStats() {
1037
1037
  return repoScoring.getStats(this.state);
1038
1038
  }
1039
+ /** Move a transferred repo's stored PRs and score to its new name. See repoScoring.renameRepo. */
1040
+ renameRepo(from, to) {
1041
+ repoScoring.renameRepo(this.state, from, to);
1042
+ this.autoSave();
1043
+ }
1039
1044
  /**
1040
1045
  * Reconcile repoScores merged/closed counts with the stored PR arrays.
1041
1046
  * Bumps counters when the array has more PRs than the counter tracks.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oss-autopilot/core",
3
- "version": "3.31.5",
3
+ "version": "3.32.0",
4
4
  "description": "CLI and core library for managing open source contributions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -55,7 +55,7 @@
55
55
  "@octokit/plugin-retry": "^8.1.1",
56
56
  "@octokit/plugin-throttling": "^11.0.5",
57
57
  "@octokit/rest": "^22.0.1",
58
- "@oss-scout/core": "^1.10.2",
58
+ "@oss-scout/core": "^1.11.0",
59
59
  "commander": "^15.0.0",
60
60
  "zod": "^4.6.7"
61
61
  },