@oss-autopilot/core 3.42.5 → 3.43.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 (168) hide show
  1. package/dist/cli-pre-action.js +8 -3
  2. package/dist/cli-registry.js +272 -25
  3. package/dist/cli.bundle.cjs +183 -154
  4. package/dist/commands/check-integration.js +1 -0
  5. package/dist/commands/cleanup.d.ts +76 -0
  6. package/dist/commands/cleanup.js +269 -0
  7. package/dist/commands/comments.d.ts +6 -0
  8. package/dist/commands/comments.js +6 -2
  9. package/dist/commands/config.js +37 -5
  10. package/dist/commands/daily-dismiss-filter.d.ts +7 -0
  11. package/dist/commands/daily-dismiss-filter.js +17 -1
  12. package/dist/commands/daily-ledger.d.ts +122 -0
  13. package/dist/commands/daily-ledger.js +225 -0
  14. package/dist/commands/daily-recent-prs.d.ts +26 -0
  15. package/dist/commands/daily-recent-prs.js +55 -0
  16. package/dist/commands/daily.d.ts +2 -1
  17. package/dist/commands/daily.js +59 -89
  18. package/dist/commands/dashboard-cache.d.ts +2 -0
  19. package/dist/commands/dashboard-cache.js +33 -8
  20. package/dist/commands/dashboard-data.js +71 -36
  21. package/dist/commands/dashboard-gist-sync.js +3 -1
  22. package/dist/commands/dashboard-lifecycle.js +1 -1
  23. package/dist/commands/dashboard-process.d.ts +14 -1
  24. package/dist/commands/dashboard-process.js +46 -7
  25. package/dist/commands/dashboard-server.js +89 -23
  26. package/dist/commands/detect-formatters.js +1 -0
  27. package/dist/commands/dismiss.js +5 -2
  28. package/dist/commands/doctor.d.ts +15 -1
  29. package/dist/commands/doctor.js +73 -5
  30. package/dist/commands/draft.d.ts +77 -0
  31. package/dist/commands/draft.js +218 -0
  32. package/dist/commands/eval.js +1 -0
  33. package/dist/commands/guidelines.d.ts +23 -1
  34. package/dist/commands/guidelines.js +49 -4
  35. package/dist/commands/index.d.ts +24 -4
  36. package/dist/commands/index.js +15 -3
  37. package/dist/commands/issue-thread.d.ts +46 -0
  38. package/dist/commands/issue-thread.js +123 -0
  39. package/dist/commands/ledger-backfill.d.ts +9 -0
  40. package/dist/commands/ledger-backfill.js +44 -1
  41. package/dist/commands/list-mark-done.d.ts +2 -1
  42. package/dist/commands/list-mark-done.js +3 -1
  43. package/dist/commands/list-move-tier.d.ts +2 -1
  44. package/dist/commands/list-move-tier.js +3 -1
  45. package/dist/commands/local-repos.js +10 -5
  46. package/dist/commands/locate-issue-list.d.ts +40 -17
  47. package/dist/commands/locate-issue-list.js +148 -88
  48. package/dist/commands/move.js +7 -1
  49. package/dist/commands/overnight-handoff.d.ts +17 -7
  50. package/dist/commands/overnight-handoff.js +36 -14
  51. package/dist/commands/overnight-push-prep.d.ts +13 -8
  52. package/dist/commands/overnight-push-prep.js +106 -34
  53. package/dist/commands/overnight-tool-rules.d.ts +54 -0
  54. package/dist/commands/overnight-tool-rules.js +217 -0
  55. package/dist/commands/overnight.d.ts +5 -6
  56. package/dist/commands/overnight.js +61 -140
  57. package/dist/commands/parse-list.js +7 -1
  58. package/dist/commands/policy.d.ts +86 -0
  59. package/dist/commands/policy.js +263 -0
  60. package/dist/commands/pr-preflight.d.ts +43 -0
  61. package/dist/commands/pr-preflight.js +294 -0
  62. package/dist/commands/repo-vet.d.ts +9 -0
  63. package/dist/commands/repo-vet.js +36 -11
  64. package/dist/commands/scout-bridge.js +18 -8
  65. package/dist/commands/search.js +7 -0
  66. package/dist/commands/setup.d.ts +3 -3
  67. package/dist/commands/setup.js +46 -18
  68. package/dist/commands/skip-add.js +10 -1
  69. package/dist/commands/startup.d.ts +5 -3
  70. package/dist/commands/startup.js +65 -49
  71. package/dist/commands/state-cmd.d.ts +2 -0
  72. package/dist/commands/state-cmd.js +5 -1
  73. package/dist/commands/stats.js +1 -0
  74. package/dist/commands/status.js +1 -0
  75. package/dist/commands/strategy.js +1 -0
  76. package/dist/commands/vet-list.d.ts +6 -0
  77. package/dist/commands/vet-list.js +25 -0
  78. package/dist/commands/vet.d.ts +12 -0
  79. package/dist/commands/vet.js +118 -1
  80. package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
  81. package/dist/core/anti-llm-policy.d.ts +3 -0
  82. package/dist/core/anti-llm-policy.js +3 -0
  83. package/dist/core/auth.js +2 -0
  84. package/dist/core/ci-analysis.d.ts +7 -2
  85. package/dist/core/ci-analysis.js +76 -21
  86. package/dist/core/commit-date.d.ts +19 -0
  87. package/dist/core/commit-date.js +17 -0
  88. package/dist/core/config-registry.js +11 -5
  89. package/dist/core/contributing.d.ts +2 -3
  90. package/dist/core/contributing.js +2 -3
  91. package/dist/core/daily-logic.d.ts +27 -5
  92. package/dist/core/daily-logic.js +57 -19
  93. package/dist/core/errors.d.ts +37 -3
  94. package/dist/core/errors.js +54 -5
  95. package/dist/core/gist-health.d.ts +15 -3
  96. package/dist/core/gist-health.js +8 -0
  97. package/dist/core/gist-state-store.d.ts +24 -4
  98. package/dist/core/gist-state-store.js +97 -46
  99. package/dist/core/github-stats.d.ts +104 -16
  100. package/dist/core/github-stats.js +282 -97
  101. package/dist/core/http-cache.d.ts +0 -10
  102. package/dist/core/http-cache.js +0 -19
  103. package/dist/core/index.d.ts +12 -5
  104. package/dist/core/index.js +15 -5
  105. package/dist/core/issue-conversation.d.ts +8 -2
  106. package/dist/core/issue-conversation.js +31 -12
  107. package/dist/core/local-config.d.ts +95 -0
  108. package/dist/core/local-config.js +271 -0
  109. package/dist/core/merged-pr-notes.d.ts +2 -2
  110. package/dist/core/pagination.d.ts +55 -0
  111. package/dist/core/pagination.js +59 -0
  112. package/dist/core/paths.d.ts +7 -0
  113. package/dist/core/paths.js +9 -0
  114. package/dist/core/pr-assembly.js +6 -2
  115. package/dist/core/pr-graphql.d.ts +37 -3
  116. package/dist/core/pr-graphql.js +73 -12
  117. package/dist/core/pr-monitor.d.ts +29 -12
  118. package/dist/core/pr-monitor.js +71 -23
  119. package/dist/core/pr-preflight.d.ts +113 -0
  120. package/dist/core/pr-preflight.js +364 -0
  121. package/dist/core/pr-quality-rubric.d.ts +0 -6
  122. package/dist/core/pr-quality-rubric.js +0 -8
  123. package/dist/core/pr-template.d.ts +2 -0
  124. package/dist/core/pr-template.js +5 -1
  125. package/dist/core/repo-policy.d.ts +105 -0
  126. package/dist/core/repo-policy.js +400 -0
  127. package/dist/core/repo-score-manager.d.ts +48 -0
  128. package/dist/core/repo-score-manager.js +111 -1
  129. package/dist/core/review-analysis.d.ts +34 -19
  130. package/dist/core/review-analysis.js +67 -10
  131. package/dist/core/reviewed-prs-fetch.js +11 -29
  132. package/dist/core/reviewed-prs.js +8 -15
  133. package/dist/core/stale-data.d.ts +41 -0
  134. package/dist/core/stale-data.js +115 -0
  135. package/dist/core/state-persistence.d.ts +62 -27
  136. package/dist/core/state-persistence.js +338 -117
  137. package/dist/core/state-schema.d.ts +113 -210
  138. package/dist/core/state-schema.js +165 -80
  139. package/dist/core/state.d.ts +60 -8
  140. package/dist/core/state.js +192 -46
  141. package/dist/core/status-determination.js +26 -8
  142. package/dist/core/strategy.js +3 -1
  143. package/dist/core/types.d.ts +22 -1
  144. package/dist/core/types.js +1 -0
  145. package/dist/core/untrusted-content.d.ts +30 -11
  146. package/dist/core/untrusted-content.js +77 -42
  147. package/dist/core/urls.d.ts +9 -0
  148. package/dist/core/urls.js +18 -0
  149. package/dist/dashboard/assets/{chart-panel-DPKNBUts.js → chart-panel-C_C1lFTI.js} +1 -1
  150. package/dist/dashboard/assets/{index-B25bZOYX.js → index-B--H66Jk.js} +1 -1
  151. package/dist/dashboard/index.html +1 -1
  152. package/dist/formatters/json.d.ts +262 -6
  153. package/dist/formatters/json.js +77 -1
  154. package/package.json +1 -1
  155. package/dist/core/ci-enforced-tools.d.ts +0 -35
  156. package/dist/core/ci-enforced-tools.js +0 -109
  157. package/dist/core/comment-decision.d.ts +0 -79
  158. package/dist/core/comment-decision.js +0 -82
  159. package/dist/core/extraction-categories.d.ts +0 -55
  160. package/dist/core/extraction-categories.js +0 -108
  161. package/dist/core/follow-up-history.d.ts +0 -40
  162. package/dist/core/follow-up-history.js +0 -71
  163. package/dist/core/issue-effort.d.ts +0 -29
  164. package/dist/core/issue-effort.js +0 -47
  165. package/dist/core/maintainer-hints.d.ts +0 -23
  166. package/dist/core/maintainer-hints.js +0 -36
  167. package/dist/core/workflow-state.d.ts +0 -56
  168. package/dist/core/workflow-state.js +0 -101
@@ -8,9 +8,15 @@
8
8
  * Bootstrap flow:
9
9
  * 1. Check for locally stored Gist ID file (`~/.oss-autopilot/gist-id`)
10
10
  * 2. If found, fetch that Gist directly via `GET /gists/:id`
11
- * 3. If not found locally, search the user's Gists for description `oss-autopilot-state`
11
+ * 3. If there is no local ID, or that Gist is gone (404), search the user's
12
+ * Gists for a private one with description `oss-autopilot-state`
12
13
  * 4. If found via search, store the ID locally and fetch it
13
- * 5. If not found anywhere, create a new private Gist with seed files and store the ID
14
+ * 5. Only when the search ran to the end of the list (a page with no
15
+ * `rel="next"` link) and found nothing, create a new private Gist with seed
16
+ * files and store the ID. A failed search degrades to the local cache; an
17
+ * unfinished or ambiguous one (list longer than the search window, or only
18
+ * a public match) throws
19
+ * {@link GistDiscoveryError}. Neither creates a Gist (#1926).
14
20
  * 6. Cache all Gist file contents in memory for session-scoped reads
15
21
  * 7. Write state to a local cache file for fallback
16
22
  *
@@ -46,12 +52,14 @@
46
52
  * a freeform-only push needs no re-read and cannot clobber another file.
47
53
  */
48
54
  import * as fs from 'node:fs';
55
+ import path from 'node:path';
49
56
  import { AgentStateSchema, NEWER_WRITER_HINT, unknownStateKeys } from './state-schema.js';
57
+ import { pruneRejectedCopies } from './stale-data.js';
50
58
  import { serializeState } from './state-prune.js';
51
- import { atomicWriteFileSync, createFreshState, migrateV1ToV2, migrateV2ToV3, migrateV3ToV4, warnMalformedWorkClaims, } from './state-persistence.js';
59
+ import { assertNotNewerVersion, atomicWriteFileSync, createFreshState, migrateV1ToV2, migrateV2ToV3, migrateV3ToV4, warnMalformedWorkClaims, } from './state-persistence.js';
52
60
  import { getGistIdPath, getStateCachePath } from './paths.js';
53
61
  import { debug, warn } from './logger.js';
54
- import { ConfigurationError, GistPermissionError, GistConcurrencyError, GistCorruptError, GistFileSizeError, isRateLimitError, isTransientNetworkError, errorMessage, } from './errors.js';
62
+ import { ConfigurationError, GistPermissionError, GistConcurrencyError, GistCorruptError, GistDiscoveryError, GistFileSizeError, NewerStateVersionError, getHttpStatusCode, isRateLimitError, isTransientNetworkError, errorMessage, } from './errors.js';
55
63
  const MODULE = 'gist-store';
56
64
  /**
57
65
  * Extract the ETag header from an Octokit response, tolerating both lower-
@@ -74,6 +82,7 @@ function preserveRejectedGistContent(raw, gistId) {
74
82
  try {
75
83
  const rejectedPath = `${getStateCachePath()}.rejected-${Date.now()}`;
76
84
  fs.writeFileSync(rejectedPath, raw, { encoding: 'utf8', mode: 0o600 });
85
+ pruneRejectedCopies(path.dirname(rejectedPath));
77
86
  return rejectedPath;
78
87
  }
79
88
  catch (err) {
@@ -158,15 +167,15 @@ export class GistStateStore {
158
167
  return { gistId: localId, state, created: false };
159
168
  }
160
169
  catch (err) {
161
- // A corrupt or permission-broken Gist must surface immediately
162
- // (#1367): falling through to search would either re-find the same
163
- // corrupt Gist or silently abandon it and create a fresh one.
164
- if (err instanceof ConfigurationError)
170
+ // Only a 404 (the saved Gist is gone) falls through to search.
171
+ // Anything else goes to the outer catch: corrupt, permission and
172
+ // rate-limit errors surface (#1367), and a transient failure
173
+ // degrades. Searching after a transient failure could end in
174
+ // creating a Gist and overwriting the saved ID (#1926).
175
+ if (getHttpStatusCode(err) !== 404)
165
176
  throw err;
166
- if (isRateLimitError(err))
167
- throw err;
168
- warn(MODULE, `Failed to fetch Gist ${localId}, will search/create`, err);
169
- // Fall through to search
177
+ this.gistId = null;
178
+ warn(MODULE, `Saved Gist ${localId} no longer exists, searching for the state Gist`, err);
170
179
  }
171
180
  }
172
181
  // Step 2: Search user's Gists by description
@@ -196,12 +205,12 @@ export class GistStateStore {
196
205
  throw err;
197
206
  if (isRateLimitError(err))
198
207
  throw err;
199
- // All API paths failed — enter degraded mode. Disarm the remote write
208
+ // The Gist could not be reached: enter degraded mode. Disarm the remote write
200
209
  // path first: a degraded store never verified its Gist, so it must
201
210
  // never be able to push to one (#1367).
202
211
  this.gistId = null;
203
212
  this.lastFetchedEtag = null;
204
- warn(MODULE, 'All Gist API paths failed, entering degraded mode', err);
213
+ warn(MODULE, 'Gist bootstrap failed, entering degraded mode', err);
205
214
  // Try reading from local cache file
206
215
  const cachePath = getStateCachePath();
207
216
  let cacheRaw = null;
@@ -209,6 +218,7 @@ export class GistStateStore {
209
218
  if (fs.existsSync(cachePath)) {
210
219
  cacheRaw = fs.readFileSync(cachePath, 'utf8');
211
220
  let obj = JSON.parse(cacheRaw);
221
+ assertNotNewerVersion(obj, 'local state cache');
212
222
  // Chain migrations
213
223
  if (typeof obj === 'object' && obj !== null) {
214
224
  const record = obj;
@@ -226,6 +236,8 @@ export class GistStateStore {
226
236
  }
227
237
  }
228
238
  catch (cacheErr) {
239
+ if (cacheErr instanceof NewerStateVersionError)
240
+ throw cacheErr;
229
241
  // Promote to warn (#1201) and preserve corrupt cache so fresh-state
230
242
  // fallback doesn't silently destroy recoverable data on next push.
231
243
  if (cacheRaw) {
@@ -261,14 +273,11 @@ export class GistStateStore {
261
273
  return { gistId: localId, state, created: false, migrated: false };
262
274
  }
263
275
  catch (err) {
264
- // See bootstrap(): corrupt/permission/rate-limit errors surface
265
- // immediately rather than falling through (#1367).
266
- if (err instanceof ConfigurationError)
267
- throw err;
268
- if (isRateLimitError(err))
276
+ // See bootstrap(): only a 404 falls through to search (#1367, #1926).
277
+ if (getHttpStatusCode(err) !== 404)
269
278
  throw err;
270
- warn(MODULE, `bootstrapWithMigration: failed to fetch Gist ${localId}, will search/create`, err);
271
- // Fall through to search
279
+ this.gistId = null;
280
+ warn(MODULE, `bootstrapWithMigration: saved Gist ${localId} no longer exists, searching`, err);
272
281
  }
273
282
  }
274
283
  // Step 2: Search user's Gists by description
@@ -293,11 +302,11 @@ export class GistStateStore {
293
302
  throw err;
294
303
  if (isRateLimitError(err))
295
304
  throw err;
296
- // All API paths failed — enter degraded mode with the push path
297
- // disarmed (see bootstrap()).
305
+ // The Gist could not be reached: enter degraded mode with the push
306
+ // path disarmed (see bootstrap()).
298
307
  this.gistId = null;
299
308
  this.lastFetchedEtag = null;
300
- warn(MODULE, 'bootstrapWithMigration: all Gist API paths failed, entering degraded mode', err);
309
+ warn(MODULE, 'bootstrapWithMigration: Gist bootstrap failed, entering degraded mode', err);
301
310
  // Try reading from local cache file
302
311
  const cachePath = getStateCachePath();
303
312
  let cacheRaw = null;
@@ -305,6 +314,7 @@ export class GistStateStore {
305
314
  if (fs.existsSync(cachePath)) {
306
315
  cacheRaw = fs.readFileSync(cachePath, 'utf8');
307
316
  let obj = JSON.parse(cacheRaw);
317
+ assertNotNewerVersion(obj, 'local state cache');
308
318
  // Chain migrations
309
319
  if (typeof obj === 'object' && obj !== null) {
310
320
  const record = obj;
@@ -322,6 +332,8 @@ export class GistStateStore {
322
332
  }
323
333
  }
324
334
  catch (cacheErr) {
335
+ if (cacheErr instanceof NewerStateVersionError)
336
+ throw cacheErr;
325
337
  if (cacheRaw) {
326
338
  const rejectedPath = preserveRejectedGistContent(cacheRaw, 'local-cache');
327
339
  warn(MODULE, `bootstrapWithMigration: local cache failed to parse: ${cacheErr instanceof Error ? cacheErr.message : String(cacheErr)}. ` +
@@ -521,6 +533,9 @@ export class GistStateStore {
521
533
  // would hit the same wall, so surface it as-is.
522
534
  if (readErr instanceof GistFileSizeError)
523
535
  throw readErr;
536
+ // Nor is a Gist from a newer release: the answer is to update, not to re-run (#1951).
537
+ if (readErr instanceof NewerStateVersionError)
538
+ throw readErr;
524
539
  if (isRateLimitError(readErr))
525
540
  throw readErr;
526
541
  throw new GistConcurrencyError(preReadEtag, null);
@@ -605,6 +620,9 @@ export class GistStateStore {
605
620
  return { status: 'refreshed' };
606
621
  }
607
622
  catch (err) {
623
+ // Not a failed fetch: the Gist is fine and this client is too old for it (#1951).
624
+ if (err instanceof NewerStateVersionError)
625
+ throw err;
608
626
  const error = err instanceof Error ? err : new Error(String(err));
609
627
  warn(MODULE, `refreshFromGist failed: ${error.message}`);
610
628
  this.lastRefreshError = error;
@@ -750,6 +768,7 @@ export class GistStateStore {
750
768
  }
751
769
  try {
752
770
  let obj = JSON.parse(raw);
771
+ assertNotNewerVersion(obj, 'Gist state');
753
772
  // Chain migrations using shared helpers from state-persistence
754
773
  if (typeof obj === 'object' && obj !== null) {
755
774
  const record = obj;
@@ -768,6 +787,8 @@ export class GistStateStore {
768
787
  return state;
769
788
  }
770
789
  catch (err) {
790
+ if (err instanceof NewerStateVersionError)
791
+ throw err;
771
792
  const rejectedPath = preserveRejectedGistContent(raw, this.gistId ?? 'unknown');
772
793
  warn(MODULE, `Gist state.json failed to parse — refusing to overwrite with fresh state. ` +
773
794
  `Corrupt content preserved at: ${rejectedPath ?? '(could not preserve)'}`);
@@ -775,30 +796,60 @@ export class GistStateStore {
775
796
  }
776
797
  }
777
798
  /**
778
- * Search the authenticated user's Gists for one with the well-known description.
779
- * Pages through up to 10 pages (100 Gists per page) to find it.
799
+ * Search the authenticated user's Gists for the private one with the
800
+ * well-known description. Pages through up to 10 pages (100 Gists per page).
801
+ * The list has ended when a response carries no `rel="next"` Link header;
802
+ * page length is not used, since a short page need not be the last.
803
+ *
804
+ * Returns `null` only when the search ran to the end of the list and found
805
+ * no Gist with the description. The callers create a new Gist on `null`, so
806
+ * anything short of that must not read as "no Gist exists" or this machine
807
+ * forks onto an empty one (#1926): API errors propagate, and a list longer
808
+ * than the search window or a public-only match throws
809
+ * {@link GistDiscoveryError}.
780
810
  */
781
811
  async searchForGist() {
782
- try {
783
- const maxPages = 10;
784
- for (let page = 1; page <= maxPages; page++) {
785
- const { data: gists } = await this.octokit.gists.list({ per_page: 100, page });
786
- if (gists.length === 0)
787
- break;
788
- const match = gists.find((g) => g.description === GIST_DESCRIPTION);
789
- if (match) {
790
- return match.id;
791
- }
792
- }
793
- }
794
- catch (err) {
795
- // A rate-limited search must not read as "no Gist found" — bootstrap
796
- // would proceed to create a duplicate Gist while throttled (#1367).
797
- if (isRateLimitError(err))
798
- throw err;
799
- warn(MODULE, 'Failed to search Gists by description', err);
800
- }
801
- return null;
812
+ const maxPages = 10;
813
+ const perPage = 100;
814
+ let publicId;
815
+ let hasReachedEnd = false;
816
+ for (let page = 1; !hasReachedEnd && page <= maxPages; page++) {
817
+ const { data: gists, headers } = await this.octokit.gists.list({ per_page: perPage, page });
818
+ const matches = gists.filter((g) => g.description === GIST_DESCRIPTION);
819
+ const [first, ...rest] = matches.filter((g) => !g.public);
820
+ if (first)
821
+ return this.pickStateGist(first, rest);
822
+ publicId ??= matches[0]?.id;
823
+ hasReachedEnd = !headers?.link?.includes('rel="next"');
824
+ }
825
+ if (hasReachedEnd && !publicId)
826
+ return null;
827
+ const idHint = `to ${getGistIdPath()}`;
828
+ if (hasReachedEnd) {
829
+ throw new GistDiscoveryError(`Found a public Gist (${publicId}) with the "${GIST_DESCRIPTION}" description. A public Gist is not ` +
830
+ `adopted automatically. To keep using it, write its ID ${idHint}; to start fresh, delete that Gist.`);
831
+ }
832
+ const publicNote = publicId
833
+ ? ` A public Gist with that description (${publicId}) was seen; it is not adopted automatically, ` +
834
+ `but writing its ID there keeps using it.`
835
+ : '';
836
+ throw new GistDiscoveryError(`Searched the first ${maxPages * perPage} Gists without finding a private "${GIST_DESCRIPTION}" Gist or ` +
837
+ `reaching the end of the list, so no new Gist was created. Write the state Gist's ID (the last path ` +
838
+ `segment of its URL) ${idHint}.${publicNote}`);
839
+ }
840
+ /** Pick the oldest of the private state Gists found on a page, warning when there are several. */
841
+ pickStateGist(first, rest) {
842
+ let chosen = first;
843
+ for (const g of rest) {
844
+ if (Date.parse(g.created_at) < Date.parse(chosen.created_at))
845
+ chosen = g;
846
+ }
847
+ if (rest.length > 0) {
848
+ const others = [first, ...rest].filter((g) => g !== chosen).map((g) => g.id);
849
+ warn(MODULE, `Found ${others.length + 1} private "${GIST_DESCRIPTION}" Gists. Using the oldest, ${chosen.id}; ` +
850
+ `ignoring ${others.join(', ')}. Delete the others, or write ${chosen.id} to ${getGistIdPath()}.`);
851
+ }
852
+ return chosen.id;
802
853
  }
803
854
  /**
804
855
  * Create a new private Gist with seed files and store it in memory.
@@ -25,6 +25,27 @@ export declare function closingIssueUrl(body: string | null | undefined, prUrl:
25
25
  * appearance; HTML comments and code are ignored like in `closingIssueUrl`.
26
26
  */
27
27
  export declare function mentionedIssueUrls(title: string | null | undefined, body: string | null | undefined, prUrl: string): string[];
28
+ /** The search scope every ledger and count query shares; see {@link externalPRScope}. */
29
+ export interface ExternalPRScope {
30
+ /** Qualifiers to append to `is:pr <state>`. */
31
+ query: string;
32
+ /**
33
+ * True when `query` excludes every untracked organisation, so the search's
34
+ * `total_count` is the number of PRs the ledger may hold. False when the
35
+ * list did not fit GitHub's limits: results must still be filtered with
36
+ * `isUntrackedOrg`, and the total is an overcount.
37
+ */
38
+ isExact: boolean;
39
+ }
40
+ /**
41
+ * Which of the user's PRs the ledgers and their counts cover: public
42
+ * repositories only, not the user's own, and not organisations in
43
+ * `config.untrackedOrgs` (the user's employer). One fragment, so the merged
44
+ * and closed ledger fetches and the count searches cannot drift apart: a
45
+ * count taken over a wider set than the ledger can hold would report a gap
46
+ * no back-fill closes.
47
+ */
48
+ export declare function externalPRScope(username: string, untrackedOrgs?: readonly string[]): ExternalPRScope;
28
49
  /** Return type shared by both merged and closed PR count functions. */
29
50
  export interface PRCountsResult<R> {
30
51
  repos: Map<string, R>;
@@ -45,6 +66,14 @@ export interface PRCountsResult<R> {
45
66
  * so `repos` undercounts and a repo missing from it may still have PRs.
46
67
  */
47
68
  truncated: boolean;
69
+ /**
70
+ * GitHub's `total_count` for the search: every PR in {@link externalPRScope},
71
+ * before the star filter and whatever the pagination cap. Absent when
72
+ * unknown (failed fetch, a result cached before the field existed, or
73
+ * untracked organisations that did not fit in the query), which is not the
74
+ * same as zero.
75
+ */
76
+ totalCount?: number;
48
77
  }
49
78
  /** Returns an empty PRCountsResult. Used as the fallback when stats fetches fail or username is empty. */
50
79
  export declare function emptyPRCountsResult<R>(): PRCountsResult<R>;
@@ -52,7 +81,7 @@ export declare function emptyPRCountsResult<R>(): PRCountsResult<R>;
52
81
  * Fetch merged PR counts and latest merge dates per repository for the configured user.
53
82
  * Also builds a monthly histogram of all merges for the contribution timeline.
54
83
  */
55
- export declare function fetchUserMergedPRCounts(octokit: Octokit, githubUsername: string, starFilter?: StarFilter): Promise<PRCountsResult<{
84
+ export declare function fetchUserMergedPRCounts(octokit: Octokit, githubUsername: string, starFilter?: StarFilter, untrackedOrgs?: readonly string[]): Promise<PRCountsResult<{
56
85
  count: number;
57
86
  lastMergedAt: string;
58
87
  }>>;
@@ -60,7 +89,18 @@ export declare function fetchUserMergedPRCounts(octokit: Octokit, githubUsername
60
89
  * Fetch closed-without-merge PR counts per repository for the configured user.
61
90
  * Used to populate closedWithoutMergeCount in repo scores for accurate merge rate.
62
91
  */
63
- export declare function fetchUserClosedPRCounts(octokit: Octokit, githubUsername: string, starFilter?: StarFilter): Promise<PRCountsResult<number>>;
92
+ export declare function fetchUserClosedPRCounts(octokit: Octokit, githubUsername: string, starFilter?: StarFilter, untrackedOrgs?: readonly string[]): Promise<PRCountsResult<number>>;
93
+ /**
94
+ * A recently merged or recently closed PR list that is missing entries
95
+ * (#1928): the recent-list truncation. Not the count-search truncation of
96
+ * the all-time merged and closed counts (`PRCountsResult.truncated`).
97
+ */
98
+ export interface RecentListTruncation {
99
+ /** Short form for lists of degraded operations, e.g. `recently merged PR search truncated (300 of 450)`. */
100
+ label: string;
101
+ /** Full sentence for logs and the daily warnings. */
102
+ message: string;
103
+ }
64
104
  /**
65
105
  * Fetch PRs closed without merge in the last N days.
66
106
  * Returns lightweight ClosedPR objects for surfacing in the daily digest.
@@ -68,7 +108,7 @@ export declare function fetchUserClosedPRCounts(octokit: Octokit, githubUsername
68
108
  export declare function fetchRecentlyClosedPRs(octokit: Octokit, config: {
69
109
  githubUsername: string;
70
110
  untrackedOrgs?: string[];
71
- }, days?: number): Promise<ClosedPR[]>;
111
+ }, days?: number, truncations?: RecentListTruncation[]): Promise<ClosedPR[]>;
72
112
  /**
73
113
  * Fetch PRs merged in the last N days.
74
114
  * Returns lightweight MergedPR objects for surfacing as wins in the dashboard.
@@ -76,21 +116,69 @@ export declare function fetchRecentlyClosedPRs(octokit: Octokit, config: {
76
116
  export declare function fetchRecentlyMergedPRs(octokit: Octokit, config: {
77
117
  githubUsername: string;
78
118
  untrackedOrgs?: string[];
79
- }, days?: number): Promise<MergedPR[]>;
119
+ }, days?: number, truncations?: RecentListTruncation[]): Promise<MergedPR[]>;
80
120
  /**
81
- * Fetch merged PRs since a watermark date for incremental storage.
82
- * If no watermark is provided (first-ever fetch), fetches all merged PRs (up to pagination cap).
83
- * Returns StoredMergedPR[] (url, title, mergedAt, openedAt) for state persistence.
121
+ * Most PRs a ledger gap fetch takes in one run (the Search API's own cap for
122
+ * a single query). A search matching more returns nothing: the caller stores
123
+ * no rows, so the ledger's newest entry stays where it was, the next run asks
124
+ * for the same range, and `ledger-backfill` (no limit) is the way out.
84
125
  */
85
- export declare function fetchMergedPRsSince(octokit: Octokit, config: {
86
- githubUsername: string;
87
- }, since?: string): Promise<StoredMergedPR[]>;
126
+ export declare const LEDGER_GAP_MAX_RESULTS = 1000;
127
+ /** What the daily run and the dashboard report when a merged-ledger gap fetch is truncated. */
128
+ export declare const MERGED_LEDGER_TRUNCATED_MESSAGE: string;
129
+ /** What the daily run and the dashboard report when a closed-ledger gap fetch is truncated. */
130
+ export declare const CLOSED_LEDGER_TRUNCATED_MESSAGE: string;
88
131
  /**
89
- * Fetch closed-without-merge PRs since a watermark date for incremental storage.
90
- * If no watermark is provided (first-ever fetch), fetches all closed PRs (up to pagination cap).
91
- * Returns StoredClosedPR[] (url, title, closedAt, openedAt) for state persistence.
92
- * Uses `is:unmerged` to exclude merged PRs (which are also "closed" in GitHub's model).
132
+ * A ledger with fewer rows than this that is short of GitHub's all-time count
133
+ * is refetched from the start (#1504, #1925): a recent row stored ahead of the
134
+ * history behind it would otherwise hide that history from every gap fetch.
135
+ * Past it a short ledger keeps its watermark, so a contributor whose count
136
+ * legitimately exceeds the ledger doesn't refetch everything on every run;
137
+ * the count warning and `ledger-backfill` cover that case.
93
138
  */
94
- export declare function fetchClosedPRsSince(octokit: Octokit, config: {
139
+ export declare const LEDGER_BACKFILL_CEILING = 300;
140
+ /**
141
+ * The watermark a ledger gap fetch starts from: undefined (all time) when the
142
+ * ledger holds `stored` rows, fewer than `allTimeCount` and under
143
+ * {@link LEDGER_BACKFILL_CEILING}; otherwise `watermark`. An unknown count
144
+ * keeps the watermark.
145
+ */
146
+ export declare function gapFetchWatermark(watermark: string | undefined, stored: number, allTimeCount: number | undefined): string | undefined;
147
+ /** Result of a since-watermark ledger fetch. */
148
+ export interface PRsSinceResult<T> {
149
+ /** Every matching PR. Empty when `truncated`: a partial range is never returned. */
150
+ prs: T[];
151
+ /** The search matched more than the caller's limit, so the range was not fetched. */
152
+ truncated: boolean;
153
+ }
154
+ /**
155
+ * The search bound for a ledger watermark (its newest stored date): one
156
+ * overlap earlier, at second precision. An absent or unparseable watermark
157
+ * gives undefined, which means "all time".
158
+ */
159
+ export declare function withLedgerOverlap(watermark?: string): string | undefined;
160
+ /** What a ledger fetch reads from the user's config. */
161
+ export interface LedgerFetchConfig {
95
162
  githubUsername: string;
96
- }, since?: string): Promise<StoredClosedPR[]>;
163
+ /** Organisations whose PRs are never stored (the user's employer). */
164
+ untrackedOrgs?: readonly string[];
165
+ }
166
+ /**
167
+ * The one fetch that fills the merged-PR ledger (#1924), shared by the daily
168
+ * run, the dashboard and `ledger-backfill`: every merged PR updated since
169
+ * `watermark` (the ledger's newest `mergedAt`) minus a one-day overlap, or
170
+ * all of them when there is no watermark.
171
+ *
172
+ * `truncated` (more than `maxResults` matches) returns no rows. Callers must
173
+ * then add nothing newer to the ledger, so its watermark does not move past
174
+ * the range that was not fetched. `ledger-backfill` passes `Infinity`.
175
+ */
176
+ export declare function fetchMergedPRsSince(octokit: Octokit, config: LedgerFetchConfig, watermark?: string, maxResults?: number): Promise<PRsSinceResult<StoredMergedPR>>;
177
+ /**
178
+ * The closed-without-merge mirror of {@link fetchMergedPRsSince} (#1925),
179
+ * shared by the daily run, the dashboard and `ledger-backfill`: every closed
180
+ * PR updated since `watermark` (the ledger's newest `closedAt`) minus a
181
+ * one-day overlap, or all of them when there is no watermark. Same
182
+ * `truncated` contract: no rows, so the watermark does not move.
183
+ */
184
+ export declare function fetchClosedPRsSince(octokit: Octokit, config: LedgerFetchConfig, watermark?: string, maxResults?: number): Promise<PRsSinceResult<StoredClosedPR>>;