@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
@@ -4,20 +4,20 @@
4
4
  * and scoring logic to repo-score-manager.ts.
5
5
  */
6
6
  import * as fs from 'node:fs';
7
- import { AgentStateSchema } from './state-schema.js';
7
+ import { AgentStateSchema, GuidelinesReviewSchema } from './state-schema.js';
8
8
  import { activeWorkClaims, finishWorkClaim, workClaimKey } from './work-claims.js';
9
9
  import { serializeState } from './state-prune.js';
10
- import { loadState, saveState, reloadStateIfChanged, createFreshState, atomicWriteFileSync, warnMalformedWorkClaims, } from './state-persistence.js';
10
+ import { loadState, saveState, reloadStateIfChanged, createFreshState, atomicWriteFileSync, assertNotNewerVersion, warnMalformedWorkClaims, } from './state-persistence.js';
11
11
  import * as repoScoring from './repo-score-manager.js';
12
12
  import { debug, warn } from './logger.js';
13
- import { errorMessage, ConfigurationError, ConcurrencyError, GistConcurrencyError, isTransientNetworkError, GistFileSizeError, GIST_FILE_SIZE_REMEDY, } from './errors.js';
13
+ import { errorMessage, ConfigurationError, ConcurrencyError, NewerStateVersionError, StateLockTimeoutError, GistConcurrencyError, isTransientNetworkError, GistDiscoveryError, GistFileSizeError, GIST_FILE_SIZE_REMEDY, } from './errors.js';
14
14
  import { GistStateStore } from './gist-state-store.js';
15
15
  import * as guidelinesStoreModule from './guidelines-store.js';
16
16
  /** Gist file that carries the rendered overnight report across machines (#1698). */
17
17
  export const OVERNIGHT_REPORT_DOCUMENT = 'overnight-report.md';
18
- import { renderGistWarning } from './gist-health.js';
18
+ import { renderGistWarning, renderUnknownModeWarning } from './gist-health.js';
19
19
  import { getStatePath, getStateCachePath, getGistIdPath } from './paths.js';
20
- import { parseGitHubUrl, issueRefKey } from './urls.js';
20
+ import { parseGitHubUrl, issueRefKey, findRefKey } from './urls.js';
21
21
  export { acquireLock, releaseLock, atomicWriteFileSync } from './state-persistence.js';
22
22
  const MODULE = 'state';
23
23
  /**
@@ -163,7 +163,7 @@ function notSynced(callerModule, err) {
163
163
  export class StateManager {
164
164
  state;
165
165
  inMemoryOnly;
166
- lastLoadedMtimeMs = 0;
166
+ lastLoadedFileId = null;
167
167
  _batching = false;
168
168
  _batchDirty = false;
169
169
  gistStore = null;
@@ -189,7 +189,7 @@ export class StateManager {
189
189
  else {
190
190
  const result = loadState();
191
191
  this.state = result.state;
192
- this.lastLoadedMtimeMs = result.mtimeMs;
192
+ this.lastLoadedFileId = result.fileId;
193
193
  this.loadRecovery = result.recovery ?? null;
194
194
  this.tryReconcilePRCounts();
195
195
  }
@@ -379,10 +379,12 @@ export class StateManager {
379
379
  }
380
380
  // Local file mode with optimistic compare-and-swap.
381
381
  try {
382
- this.lastLoadedMtimeMs = saveState(this.state, this.lastLoadedMtimeMs);
382
+ this.lastLoadedFileId = saveState(this.state, this.lastLoadedFileId);
383
383
  }
384
384
  catch (err) {
385
- if (err instanceof ConcurrencyError && options.allowReloadAndLoseMutation) {
385
+ // A lock timeout is no external write: there is nothing to reload, and the mutation must not be dropped.
386
+ const isExternalWrite = err instanceof ConcurrencyError && !(err instanceof StateLockTimeoutError);
387
+ if (isExternalWrite && options.allowReloadAndLoseMutation) {
386
388
  warn(MODULE, `Concurrent external write detected; reloading and discarding in-memory mutation. ${err.message}`);
387
389
  this.reloadIfChanged();
388
390
  return;
@@ -436,6 +438,8 @@ export class StateManager {
436
438
  * `isGistDegraded()` at each call site.
437
439
  *
438
440
  * Composes the same primitive fields those accessors expose:
441
+ * - no gist store + config names a mode this release does not know →
442
+ * `unknown-mode` (#2005)
439
443
  * - no gist store + config asks for gist → `configured-but-local`
440
444
  * - gist store attached but disarmed (#1443) → `bootstrap-degraded`
441
445
  * (`since` comes from the staleness marker the degraded bootstrap seeds)
@@ -443,6 +447,10 @@ export class StateManager {
443
447
  */
444
448
  getGistHealth() {
445
449
  if (this.gistStore === null) {
450
+ const mode = this.state.config.persistence;
451
+ if (mode !== 'local' && mode !== 'gist') {
452
+ return { mode: 'local', degraded: { mode, cause: 'unknown-mode', recoverable: false } };
453
+ }
446
454
  return {
447
455
  mode: 'local',
448
456
  degraded: this.state.config.persistence === 'gist' ? { cause: 'configured-but-local', recoverable: true } : null,
@@ -491,6 +499,23 @@ export class StateManager {
491
499
  guidelinesStoreModule.deleteGuidelines(this.gistStore, repo);
492
500
  this.autoSave();
493
501
  }
502
+ /** Record that the user approved the guidelines text hashing to `sha256` for `repo` (#1929). */
503
+ markGuidelinesReviewed(repo, sha256, reviewedAt) {
504
+ this.state.guidelinesReviews = { ...this.state.guidelinesReviews, [repo]: { reviewedAt, sha256 } };
505
+ this.autoSave();
506
+ }
507
+ /** The review stamp for `repo`, or undefined when none is recorded or the entry is unreadable (#1929). */
508
+ getGuidelinesReview(repo) {
509
+ const parsed = GuidelinesReviewSchema.safeParse(this.state.guidelinesReviews?.[repo]);
510
+ return parsed.success ? parsed.data : undefined;
511
+ }
512
+ /** Store `policy` for `repo` (#1953), or delete the record when `policy` is null. Keys are lowercase. */
513
+ setRepoPolicy(repo, policy) {
514
+ const key = repo.toLowerCase();
515
+ const rest = Object.fromEntries(Object.entries(this.state.repoPolicies ?? {}).filter(([k]) => k !== key));
516
+ this.state.repoPolicies = policy ? { ...rest, [key]: policy } : rest;
517
+ this.autoSave();
518
+ }
494
519
  /** List repos with non-empty guidelines stored in the Gist. */
495
520
  listGuidelinesRepos() {
496
521
  return guidelinesStoreModule.listGuidelinesRepos(this.gistStore);
@@ -510,11 +535,11 @@ export class StateManager {
510
535
  return false;
511
536
  if (this.gistStore)
512
537
  return false; // Gist is the source of truth; skip local file reload
513
- const result = reloadStateIfChanged(this.lastLoadedMtimeMs);
538
+ const result = reloadStateIfChanged(this.lastLoadedFileId);
514
539
  if (!result)
515
540
  return false;
516
541
  this.state = result.state;
517
- this.lastLoadedMtimeMs = result.mtimeMs;
542
+ this.lastLoadedFileId = result.fileId;
518
543
  this.loadRecovery = result.recovery ?? null;
519
544
  this.tryReconcilePRCounts();
520
545
  return true;
@@ -637,9 +662,13 @@ export class StateManager {
637
662
  let rawState;
638
663
  try {
639
664
  rawState = JSON.parse(raw);
665
+ assertNotNewerVersion(rawState, 'Gist state');
640
666
  this.state = AgentStateSchema.parse(rawState);
641
667
  }
642
668
  catch (err) {
669
+ // Not a bad payload: staying on old in-memory state would push it over the newer Gist.
670
+ if (err instanceof NewerStateVersionError)
671
+ throw err;
643
672
  warn(MODULE, `Failed to parse refreshed Gist state: ${errorMessage(err)}`);
644
673
  // Same reasoning as the missing-file branch: parse failure leaves us
645
674
  // on stale in-memory state, so flag it.
@@ -743,11 +772,13 @@ export class StateManager {
743
772
  this.autoSave();
744
773
  }
745
774
  /**
746
- * Update the local repository cache.
747
- * @param cache - Local repository cache mapping repo names to paths
775
+ * Drop the synced copy of the local repository cache. The cache is
776
+ * per-machine and lives in `local-config.json` (#1950).
748
777
  */
749
- setLocalRepoCache(cache) {
750
- this.state.localRepoCache = cache;
778
+ clearSyncedLocalRepoCache() {
779
+ if (this.state.localRepoCache === undefined)
780
+ return;
781
+ delete this.state.localRepoCache;
751
782
  this.autoSave();
752
783
  }
753
784
  // === Merged PR Storage ===
@@ -798,6 +829,8 @@ export class StateManager {
798
829
  this.state.mergedPRs.push(...newPRs);
799
830
  this.state.mergedPRs.sort((a, b) => b.mergedAt.localeCompare(a.mergedAt));
800
831
  debug(MODULE, `Added ${newPRs.length} merged PRs (total: ${this.state.mergedPRs.length})`);
832
+ // A PR that merged after being recorded closed leaves the closed ledger (#1923).
833
+ repoScoring.evictClosedPRs(this.state, []);
801
834
  this.tryReconcilePRCounts();
802
835
  this.autoSave();
803
836
  return { added: newPRs.length, dropped };
@@ -830,7 +863,8 @@ export class StateManager {
830
863
  * this prevents the bad data from reaching disk in the first place).
831
864
  *
832
865
  * Re-seen URLs upgrade the stored entry's missing ledger fields in place
833
- * (#1461) — see {@link addMergedPRs} for the full semantics.
866
+ * (#1461) — see {@link addMergedPRs} for the full semantics. URLs already
867
+ * in the merged ledger are skipped (#1923).
834
868
  *
835
869
  * @param prs - Closed PRs to add (duplicates by URL upgrade in place)
836
870
  * @returns count of entries added vs. dropped (invalid URL)
@@ -839,7 +873,10 @@ export class StateManager {
839
873
  if (prs.length === 0)
840
874
  return { added: 0, dropped: 0 };
841
875
  const { valid: unpicked, dropped } = filterValidUrlEntries(prs, 'closed');
842
- const valid = unpicked.map((pr) => this.withPick(pr));
876
+ // A merged PR is never closed-without-merge: skip it so a caller holding
877
+ // a pre-eviction copy of the closed ledger cannot put it back (#1923).
878
+ const mergedUrls = new Set(this.getMergedPRs().map((pr) => pr.url));
879
+ const valid = unpicked.filter((pr) => !mergedUrls.has(pr.url)).map((pr) => this.withPick(pr));
843
880
  if (valid.length === 0)
844
881
  return { added: 0, dropped };
845
882
  if (!this.state.closedPRs)
@@ -866,6 +903,30 @@ export class StateManager {
866
903
  this.autoSave();
867
904
  return { added: newPRs.length, dropped };
868
905
  }
906
+ /**
907
+ * Remove closed-ledger entries that are open again (`openUrls`) or sit in
908
+ * the merged ledger, lowering the affected repos' closed counts with them
909
+ * (#1923). See repoScoring.evictClosedPRs.
910
+ * @returns the number of entries removed
911
+ */
912
+ evictClosedPRs(openUrls) {
913
+ const evicted = repoScoring.evictClosedPRs(this.state, openUrls);
914
+ if (evicted > 0)
915
+ this.autoSave();
916
+ return evicted;
917
+ }
918
+ /**
919
+ * Remove ledger rows and repoScores entries for repositories in
920
+ * `config.untrackedOrgs` and for `privateRepos`, which must hold only
921
+ * repositories GitHub reported private in this run (#1924). See
922
+ * repoScoring.evictExcludedRepos.
923
+ */
924
+ evictExcludedRepos(privateRepos) {
925
+ const evicted = repoScoring.evictExcludedRepos(this.state, privateRepos);
926
+ if (evicted.untrackedOrgRows + evicted.privateRows + evicted.repos > 0)
927
+ this.autoSave();
928
+ return evicted;
929
+ }
869
930
  /** Returns the most recent close date, used as a watermark for incremental fetching. */
870
931
  getClosedPRWatermark() {
871
932
  return this.state.closedPRs?.[0]?.closedAt || undefined;
@@ -1069,18 +1130,36 @@ export class StateManager {
1069
1130
  /**
1070
1131
  * Shelve a PR URL, hiding it from daily digest and capacity.
1071
1132
  * @param url - The PR URL to shelve
1133
+ * @param reasons - The PR's action reasons right now (`shelveReasonsOf`), when known
1072
1134
  * @returns true if newly shelved, false if already shelved
1073
1135
  */
1074
- shelvePR(url) {
1136
+ shelvePR(url, reasons) {
1075
1137
  if (!this.state.config.shelvedPRUrls) {
1076
1138
  this.state.config.shelvedPRUrls = [];
1077
1139
  }
1078
- if (this.state.config.shelvedPRUrls.includes(url)) {
1079
- return false;
1140
+ // Record every shelve, a repeat included (#1922): the daily run compares
1141
+ // maintainer activity and the action reasons against this, so re-shelving
1142
+ // a PR acknowledges everything up to now.
1143
+ const now = new Date();
1144
+ this.state.config.shelvedPRInfo = {
1145
+ ...this.state.config.shelvedPRInfo,
1146
+ [issueRefKey(url) ?? url]: { at: now.toISOString(), reasons },
1147
+ };
1148
+ const isNew = this.shelvedIndex(url) === -1;
1149
+ if (isNew) {
1150
+ this.state.config.shelvedPRUrls.push(url);
1080
1151
  }
1081
- this.state.config.shelvedPRUrls.push(url);
1082
1152
  this.autoSave();
1083
- return true;
1153
+ return isNew;
1154
+ }
1155
+ /**
1156
+ * Index of a PR in `shelvedPRUrls`, matched through {@link issueRefKey} so
1157
+ * a URL typed in different casing or with a trailing slash still finds the
1158
+ * entry (#1922). -1 when not shelved.
1159
+ */
1160
+ shelvedIndex(url) {
1161
+ const key = issueRefKey(url);
1162
+ return (this.state.config.shelvedPRUrls ?? []).findIndex((u) => (key ? issueRefKey(u) === key : u === url));
1084
1163
  }
1085
1164
  /**
1086
1165
  * Unshelve a PR URL, restoring it to daily digest.
@@ -1088,24 +1167,38 @@ export class StateManager {
1088
1167
  * @returns true if removed from shelf, false if not shelved
1089
1168
  */
1090
1169
  unshelvePR(url) {
1091
- if (!this.state.config.shelvedPRUrls) {
1092
- return false;
1093
- }
1094
- const index = this.state.config.shelvedPRUrls.indexOf(url);
1170
+ const index = this.shelvedIndex(url);
1095
1171
  if (index === -1) {
1096
1172
  return false;
1097
1173
  }
1098
1174
  this.state.config.shelvedPRUrls.splice(index, 1);
1175
+ if (this.state.config.shelvedPRInfo) {
1176
+ delete this.state.config.shelvedPRInfo[issueRefKey(url) ?? url];
1177
+ }
1099
1178
  this.autoSave();
1100
1179
  return true;
1101
1180
  }
1181
+ /**
1182
+ * Fill in the action reasons of a shelve record that has none yet (#1922):
1183
+ * the PR was not in the digest when it was shelved, so the first daily run
1184
+ * that sees it records them. Never changes reasons already recorded: a
1185
+ * reason that clears and comes back was there at shelve time and is not
1186
+ * new. No-op for a PR without a shelve record.
1187
+ */
1188
+ fillShelvedPRReasons(url, reasons) {
1189
+ const info = this.state.config.shelvedPRInfo?.[issueRefKey(url) ?? url];
1190
+ if (!info || info.reasons)
1191
+ return;
1192
+ info.reasons = reasons;
1193
+ this.autoSave();
1194
+ }
1102
1195
  /**
1103
1196
  * Check if a PR is currently shelved.
1104
1197
  * @param url - The PR URL to check
1105
1198
  * @returns true if the PR is shelved
1106
1199
  */
1107
1200
  isPRShelved(url) {
1108
- return this.state.config.shelvedPRUrls?.includes(url) ?? false;
1201
+ return this.shelvedIndex(url) !== -1;
1109
1202
  }
1110
1203
  // === Dismiss / Undismiss Issues ===
1111
1204
  /**
@@ -1127,11 +1220,14 @@ export class StateManager {
1127
1220
  if (!this.state.config.dismissedIssues) {
1128
1221
  this.state.config.dismissedIssues = {};
1129
1222
  }
1130
- if (url in this.state.config.dismissedIssues && !options.refresh) {
1223
+ // An existing entry for the same issue or PR keeps its key (#2001).
1224
+ const existing = findRefKey(this.state.config.dismissedIssues, url);
1225
+ if (existing !== undefined && !options.refresh) {
1131
1226
  return false;
1132
1227
  }
1133
- this.state.config.dismissedIssues[url] = timestamp;
1134
- this.setDismissedPRHead(url, options.headSha);
1228
+ const key = existing ?? url;
1229
+ this.state.config.dismissedIssues[key] = timestamp;
1230
+ this.setDismissedPRHead(key, options.headSha);
1135
1231
  this.autoSave();
1136
1232
  return true;
1137
1233
  }
@@ -1142,11 +1238,12 @@ export class StateManager {
1142
1238
  * @returns true if undismissed, false if not currently dismissed
1143
1239
  */
1144
1240
  undismissIssue(url) {
1145
- if (!this.state.config.dismissedIssues || !(url in this.state.config.dismissedIssues)) {
1241
+ const key = findRefKey(this.state.config.dismissedIssues, url);
1242
+ if (key === undefined) {
1146
1243
  return false;
1147
1244
  }
1148
- delete this.state.config.dismissedIssues[url];
1149
- this.setDismissedPRHead(url, undefined);
1245
+ delete this.state.config.dismissedIssues[key];
1246
+ this.setDismissedPRHead(key, undefined);
1150
1247
  this.autoSave();
1151
1248
  return true;
1152
1249
  }
@@ -1155,7 +1252,9 @@ export class StateManager {
1155
1252
  * @param url - The issue URL to check
1156
1253
  */
1157
1254
  getIssueDismissedAt(url) {
1158
- return this.state.config.dismissedIssues?.[url];
1255
+ const dismissed = this.state.config.dismissedIssues;
1256
+ const key = findRefKey(dismissed, url);
1257
+ return key === undefined ? undefined : dismissed[key];
1159
1258
  }
1160
1259
  /**
1161
1260
  * The head SHA recorded when a reviewed PR's follow-up was dismissed
@@ -1164,17 +1263,23 @@ export class StateManager {
1164
1263
  * @param url - The PR URL to check
1165
1264
  */
1166
1265
  getDismissedPRHead(url) {
1167
- return this.state.config.dismissedPRHeads?.[url];
1266
+ const heads = this.state.config.dismissedPRHeads;
1267
+ const key = findRefKey(heads, url);
1268
+ return key === undefined ? undefined : heads[key];
1168
1269
  }
1169
- /** Record or (with `undefined`) drop the dismiss head for `url`; no save. */
1270
+ /**
1271
+ * Record or (with `undefined`) drop the dismiss head for `url`, replacing
1272
+ * any head stored under another form of the same PR's URL (#2001); no save.
1273
+ */
1170
1274
  setDismissedPRHead(url, headSha) {
1171
1275
  if (!this.state.config.dismissedPRHeads) {
1172
1276
  this.state.config.dismissedPRHeads = {};
1173
1277
  }
1174
- if (headSha === undefined) {
1175
- delete this.state.config.dismissedPRHeads[url];
1278
+ const existing = findRefKey(this.state.config.dismissedPRHeads, url);
1279
+ if (existing !== undefined) {
1280
+ delete this.state.config.dismissedPRHeads[existing];
1176
1281
  }
1177
- else {
1282
+ if (headSha !== undefined) {
1178
1283
  this.state.config.dismissedPRHeads[url] = headSha;
1179
1284
  }
1180
1285
  }
@@ -1348,7 +1453,8 @@ export class StateManager {
1348
1453
  if (!this.state.config.statusOverrides) {
1349
1454
  this.state.config.statusOverrides = {};
1350
1455
  }
1351
- this.state.config.statusOverrides[url] = {
1456
+ // An existing override for the same PR keeps its key (#2001).
1457
+ this.state.config.statusOverrides[findRefKey(this.state.config.statusOverrides, url) ?? url] = {
1352
1458
  status,
1353
1459
  setAt: new Date().toISOString(),
1354
1460
  lastActivityAt,
@@ -1361,10 +1467,11 @@ export class StateManager {
1361
1467
  * @returns true if an override was removed, false if none existed
1362
1468
  */
1363
1469
  clearStatusOverride(url) {
1364
- if (!this.state.config.statusOverrides || !(url in this.state.config.statusOverrides)) {
1470
+ const key = findRefKey(this.state.config.statusOverrides, url);
1471
+ if (!this.state.config.statusOverrides || key === undefined) {
1365
1472
  return false;
1366
1473
  }
1367
- delete this.state.config.statusOverrides[url];
1474
+ delete this.state.config.statusOverrides[key];
1368
1475
  this.autoSave();
1369
1476
  return true;
1370
1477
  }
@@ -1375,7 +1482,9 @@ export class StateManager {
1375
1482
  * @returns The override if still valid, undefined otherwise
1376
1483
  */
1377
1484
  getStatusOverride(url, currentUpdatedAt) {
1378
- const override = this.state.config.statusOverrides?.[url];
1485
+ const overrides = this.state.config.statusOverrides;
1486
+ const key = findRefKey(overrides, url);
1487
+ const override = key === undefined ? undefined : overrides?.[key];
1379
1488
  if (!override)
1380
1489
  return undefined;
1381
1490
  // Auto-clear if the PR has new activity since the override was set
@@ -1604,7 +1713,9 @@ export async function ensureGistPersistence(token) {
1604
1713
  function peekGistArtifacts() {
1605
1714
  try {
1606
1715
  const raw = fs.readFileSync(getStateCachePath(), 'utf8');
1607
- return JSON.parse(raw)?.config?.persistence === 'gist' ? 'gist' : 'local';
1716
+ return JSON.parse(raw)?.config?.persistence === 'gist'
1717
+ ? 'gist'
1718
+ : 'local';
1608
1719
  }
1609
1720
  catch (err) {
1610
1721
  if (err.code !== 'ENOENT') {
@@ -1620,6 +1731,37 @@ function peekGistArtifacts() {
1620
1731
  return 'unreadable';
1621
1732
  }
1622
1733
  }
1734
+ /**
1735
+ * The warning for a persistence mode a newer release wrote (#2005), or null.
1736
+ * {@link ensureGistPersistence} reads such a mode as `'local-mode'`, so entry
1737
+ * points add this to their output: writes will not reach the Gist the newer
1738
+ * client syncs through. Reads state.json, or the state cache when state.json
1739
+ * is absent, as ensureGistPersistence does; any other read failure is that
1740
+ * function's to report.
1741
+ */
1742
+ export function unknownPersistenceModeWarning() {
1743
+ for (const file of [getStatePath(), getStateCachePath()]) {
1744
+ let raw;
1745
+ try {
1746
+ raw = fs.readFileSync(file, 'utf8');
1747
+ }
1748
+ catch (err) {
1749
+ if (err.code === 'ENOENT')
1750
+ continue;
1751
+ return null;
1752
+ }
1753
+ let parsed;
1754
+ try {
1755
+ parsed = JSON.parse(raw);
1756
+ }
1757
+ catch {
1758
+ return null;
1759
+ }
1760
+ const mode = parsed?.config?.persistence;
1761
+ return typeof mode === 'string' && mode !== 'local' && mode !== 'gist' ? renderUnknownModeWarning(mode) : null;
1762
+ }
1763
+ return null;
1764
+ }
1623
1765
  /**
1624
1766
  * Best-effort gist bootstrap for entry points WITHOUT the auth gate (#1431):
1625
1767
  * the CLI's localOnly commands (shelve/move/dismiss/override/config/setup/...)
@@ -1659,13 +1801,17 @@ export async function bootstrapGistBestEffort(fetchToken) {
1659
1801
  if (err instanceof GistFileSizeError) {
1660
1802
  reason = `Gist initialization failed (${errorMessage(err)}). To fix it, ${GIST_FILE_SIZE_REMEDY}.`;
1661
1803
  }
1662
- else if (err instanceof ConfigurationError) {
1804
+ else if (err instanceof ConfigurationError &&
1805
+ !(err instanceof GistDiscoveryError) &&
1806
+ !(err instanceof NewerStateVersionError)) {
1807
+ // A GistDiscoveryError or a newer-version error carries its own remedy; the scope hint would mislead (#1926).
1663
1808
  reason = `Gist initialization failed (${errorMessage(err)}) — fix the Gist setup (check the token's gist scope, or run state-show / setup) before relying on sync`;
1664
1809
  }
1665
1810
  cause = { reason };
1666
1811
  }
1812
+ // Local mode, or a mode a newer release added, which runs local (#2005).
1667
1813
  if (cause === null)
1668
- return null;
1814
+ return unknownPersistenceModeWarning();
1669
1815
  return renderGistWarning(cause);
1670
1816
  }
1671
1817
  /**
@@ -105,6 +105,25 @@ function isChangesAddressedByCommit(commitDate, changesRequestedDate) {
105
105
  return false;
106
106
  return commitMs >= changesRequestedMs;
107
107
  }
108
+ /**
109
+ * Whether approval settles every unanswered maintainer comment, so the PR is
110
+ * just waiting to be merged (#1507): it is approved, CI is passing or unknown,
111
+ * and each comment's author has a standing approval submitted at or after that
112
+ * comment (the approving review's own note, or feedback its author then
113
+ * approved). Someone else's approval never settles a comment, and neither does
114
+ * the commenter's own earlier approval: both leave a question nobody answered
115
+ * (#1920).
116
+ *
117
+ * Fails closed (returns `false`) when the comments are not listed or a date is
118
+ * missing or unparseable: the safe direction is to surface the comment.
119
+ */
120
+ function isCommentSettledByApproval(input) {
121
+ const { reviewDecision, ciStatus, unansweredComments = [] } = input;
122
+ if (reviewDecision !== 'approved' || (ciStatus !== 'passing' && ciStatus !== 'unknown'))
123
+ return false;
124
+ return (unansweredComments.length > 0 &&
125
+ unansweredComments.every((c) => normalizeToEpochMs(c.createdAt) <= normalizeToEpochMs(c.authorApprovalDate)));
126
+ }
108
127
  /**
109
128
  * Collect all applicable action reasons independently, without short-circuiting (#675).
110
129
  * Used alongside the priority-based decision tree to surface secondary issues.
@@ -118,12 +137,10 @@ function collectAllActionReasons(input) {
118
137
  const { ciStatus, hasMergeConflict, hasUnrespondedComment, reviewDecision, lastMaintainerCommentDate, latestChangesRequestedDate, hasActionableCIFailure = true, } = input;
119
138
  const commitDate = resolveContributorCommitDate(input);
120
139
  const reasons = [];
121
- // An unresponded maintainer comment on an already-approved, passing/unknown
122
- // PR is an approval/LGTM note, not a request for action — it needs no
123
- // contributor response and the PR is just awaiting merge (#1507).
124
- const approvedAndMergeable = reviewDecision === 'approved' && (ciStatus === 'passing' || ciStatus === 'unknown');
140
+ // Unresponded maintainer comments their authors' approvals settle need no
141
+ // contributor response: the PR is just awaiting merge (#1507, #1920).
125
142
  if (hasUnrespondedComment &&
126
- !approvedAndMergeable &&
143
+ !isCommentSettledByApproval(input) &&
127
144
  !isCommentAddressedByCommit(commitDate, lastMaintainerCommentDate, latestChangesRequestedDate)) {
128
145
  reasons.push('needs_response');
129
146
  }
@@ -184,11 +201,12 @@ function determinePrimaryStatus(input) {
184
201
  // the contributor can't fix them, so the relevant status is "waiting for re-review" (#502)
185
202
  return { status: 'waiting_on_maintainer', waitReason: 'changes_addressed', stalenessTier };
186
203
  }
187
- // An unresponded comment on an already-approved, passing/unknown PR is an
204
+ // An unresponded comment its own author's approval settles is an
188
205
  // approval/LGTM note (e.g. a re-approval dated after the contributor's last
189
206
  // commit), not a request for changes. It needs no contributor response, so
190
- // the PR is waiting to be merged — don't trap it in needs_response (#1507).
191
- if (reviewDecision === 'approved' && (ciStatus === 'passing' || ciStatus === 'unknown')) {
207
+ // the PR is waiting to be merged: don't trap it in needs_response (#1507).
208
+ // Any other comment on an approved PR still needs one (#1920).
209
+ if (isCommentSettledByApproval(input)) {
192
210
  return { status: 'waiting_on_maintainer', waitReason: 'pending_merge', stalenessTier };
193
211
  }
194
212
  return { status: 'needs_addressing', actionReason: 'needs_response', stalenessTier };
@@ -13,6 +13,7 @@
13
13
  * doing X well, here's a growth opportunity") stays in the agent
14
14
  * prompt.
15
15
  */
16
+ import { findRefKey } from './urls.js';
16
17
  /** Minimum tracked PR history before strategy output is meaningful (#1243). */
17
18
  export const STRATEGY_MIN_PRS = 10;
18
19
  /** How many top-N items each "primary" / "favorite" list returns. */
@@ -133,7 +134,8 @@ function activityAt(pr) {
133
134
  function effectiveStatus(pr, state) {
134
135
  if (typeof pr.url !== 'string')
135
136
  return pr.status;
136
- const override = state.config.statusOverrides?.[pr.url];
137
+ const overrides = state.config.statusOverrides;
138
+ const override = overrides?.[findRefKey(overrides, pr.url) ?? pr.url];
137
139
  if (!override)
138
140
  return pr.status;
139
141
  const lastActivity = activityAt(pr);
@@ -2,7 +2,7 @@
2
2
  * Core types for the Open Source Contribution Agent
3
3
  */
4
4
  import type { FetchedPRStatus, RepoSignals, TrackedIssue, IssueVettingResult, IssueScope, DiffTool, AgentConfig, AgentState } from './state-schema.js';
5
- export type { IssueStatus, FetchedPRStatus, ProjectCategory, IssueScope, DiffTool, RepoSignals, RepoScore, StoredMergedPR, StoredClosedPR, AnalyzedIssueConversation, ContributionGuidelines, IssueVettingResult, TrackedIssue, ShelvedPRRef, StatusOverride, AgentConfig, LocalRepoCache, ClosedPR, MergedPR, DailyDigest, AgentState, SearchSeenEntry, PickSnapshot, OvernightPrepared, OvernightRecord, OvernightImplementAttempt, SearchRotation, WorkClaim, WorkClaimKind, WorkClaimStatus, } from './state-schema.js';
5
+ export type { IssueStatus, FetchedPRStatus, ProjectCategory, IssueScope, DiffTool, RepoSignals, RepoScore, StoredMergedPR, StoredClosedPR, ContributionGuidelines, IssueVettingResult, TrackedIssue, ShelvedPRRef, StatusOverride, AgentConfig, LocalRepoCache, ClosedPR, MergedPR, DailyDigest, AgentState, SearchSeenEntry, PickSnapshot, OvernightPrepared, OvernightRecord, OvernightImplementAttempt, SearchRotation, WorkClaim, WorkClaimKind, WorkClaimStatus, } from './state-schema.js';
6
6
  /** CI pipeline status for a PR's latest commit. */
7
7
  export type CIStatus = 'passing' | 'failing' | 'pending' | 'unknown';
8
8
  /**
@@ -98,6 +98,16 @@ export interface DetermineStatusInput {
98
98
  contributorUsername?: string;
99
99
  lastMaintainerCommentDate?: string;
100
100
  latestChangesRequestedDate?: string;
101
+ /**
102
+ * Every unanswered maintainer comment, each with the time its author
103
+ * submitted their own standing approval, if they have one. On an approved PR
104
+ * a comment still needs a response unless its author approved at or after
105
+ * writing it (#1920).
106
+ */
107
+ unansweredComments?: Array<{
108
+ createdAt: string;
109
+ authorApprovalDate?: string;
110
+ }>;
101
111
  /** True if at least one failing CI check is classified as 'actionable'. */
102
112
  hasActionableCIFailure?: boolean;
103
113
  }
@@ -381,7 +391,18 @@ export declare const INITIAL_STATE: AgentState;
381
391
  export declare const PROJECT_CATEGORIES: ("nonprofit" | "devtools" | "infrastructure" | "web-frameworks" | "data-ml" | "education")[];
382
392
  export declare const ISSUE_SCOPES: ("advanced" | "beginner" | "intermediate")[];
383
393
  export declare const DIFF_TOOLS: readonly DiffTool[];
394
+ /** @deprecated Since #1948; nothing reads it. Will be removed in the next major version. */
384
395
  export declare const SCOPE_LABELS: Record<IssueScope, string[]>;
396
+ /**
397
+ * Shape of the retired `analyzedIssueConversations` state entries.
398
+ *
399
+ * @deprecated Since #1948; the state field is no longer read or written. Will be removed in the next major version.
400
+ */
401
+ export interface AnalyzedIssueConversation {
402
+ url: string;
403
+ repo: string;
404
+ analyzedAt: string;
405
+ }
385
406
  /** Priority tier for issue search results. Ordered: merged_pr > preferred_org > starred > normal. */
386
407
  export type SearchPriority = 'merged_pr' | 'preferred_org' | 'starred' | 'normal';
387
408
  export interface IssueCandidate {
@@ -18,6 +18,7 @@ export const INITIAL_STATE = AgentStateSchema.parse({ version: 4 });
18
18
  export const PROJECT_CATEGORIES = ProjectCategorySchema.options;
19
19
  export const ISSUE_SCOPES = IssueScopeSchema.options;
20
20
  export const DIFF_TOOLS = DiffToolSchema.options;
21
+ /** @deprecated Since #1948; nothing reads it. Will be removed in the next major version. */
21
22
  export const SCOPE_LABELS = {
22
23
  beginner: ['good first issue', 'help wanted', 'easy', 'up-for-grabs', 'first-timers-only', 'beginner'],
23
24
  intermediate: ['enhancement', 'feature', 'feature-request', 'contributions welcome'],