@oss-autopilot/core 3.33.0 → 3.34.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 (86) hide show
  1. package/dist/cli-pre-action.js +20 -20
  2. package/dist/cli-registry.js +59 -23
  3. package/dist/cli.bundle.cjs +140 -129
  4. package/dist/commands/check-integration.d.ts +2 -2
  5. package/dist/commands/comments.js +3 -3
  6. package/dist/commands/compliance-score.js +1 -1
  7. package/dist/commands/config.js +1 -1
  8. package/dist/commands/daily-render.js +6 -13
  9. package/dist/commands/daily.d.ts +1 -2
  10. package/dist/commands/daily.js +8 -4
  11. package/dist/commands/dashboard-cache.js +1 -1
  12. package/dist/commands/dashboard-data.js +7 -6
  13. package/dist/commands/dashboard-lifecycle.js +3 -5
  14. package/dist/commands/dashboard-server.js +3 -3
  15. package/dist/commands/detect-formatters.d.ts +1 -1
  16. package/dist/commands/dismiss.js +2 -2
  17. package/dist/commands/doctor.js +3 -3
  18. package/dist/commands/eval.d.ts +11 -0
  19. package/dist/commands/eval.js +11 -0
  20. package/dist/commands/features.js +1 -1
  21. package/dist/commands/guidelines.js +5 -5
  22. package/dist/commands/index.d.ts +1 -0
  23. package/dist/commands/index.js +1 -0
  24. package/dist/commands/init.js +1 -1
  25. package/dist/commands/ledger-backfill.d.ts +40 -0
  26. package/dist/commands/ledger-backfill.js +216 -0
  27. package/dist/commands/local-repos.d.ts +1 -1
  28. package/dist/commands/overnight.js +13 -18
  29. package/dist/commands/parse-list.d.ts +2 -2
  30. package/dist/commands/parse-list.js +7 -7
  31. package/dist/commands/repo-vet.js +3 -3
  32. package/dist/commands/search.js +9 -10
  33. package/dist/commands/setup.js +8 -8
  34. package/dist/commands/startup.js +1 -1
  35. package/dist/commands/status.d.ts +1 -1
  36. package/dist/commands/vet-list.js +17 -7
  37. package/dist/commands/vet.js +5 -3
  38. package/dist/core/__fixtures__/prompt-injection-payloads.js +1 -1
  39. package/dist/core/anti-llm-policy.js +3 -3
  40. package/dist/core/checklist-analysis.d.ts +3 -0
  41. package/dist/core/checklist-analysis.js +67 -16
  42. package/dist/core/ci-analysis.js +1 -1
  43. package/dist/core/close-reason.d.ts +25 -0
  44. package/dist/core/close-reason.js +28 -0
  45. package/dist/core/comment-decision.js +1 -1
  46. package/dist/core/compliance-score.js +2 -2
  47. package/dist/core/daily-logic.d.ts +12 -0
  48. package/dist/core/daily-logic.js +11 -2
  49. package/dist/core/display-utils.js +1 -1
  50. package/dist/core/errors.js +4 -5
  51. package/dist/core/eval-report.d.ts +55 -0
  52. package/dist/core/eval-report.js +211 -0
  53. package/dist/core/follow-up-history.d.ts +1 -2
  54. package/dist/core/follow-up-history.js +1 -1
  55. package/dist/core/github-stats.d.ts +9 -0
  56. package/dist/core/github-stats.js +27 -1
  57. package/dist/core/guidelines-store.js +2 -2
  58. package/dist/core/http-cache.js +1 -2
  59. package/dist/core/index.d.ts +3 -2
  60. package/dist/core/index.js +3 -2
  61. package/dist/core/issue-conversation.js +1 -1
  62. package/dist/core/issue-effort.js +12 -6
  63. package/dist/core/paths.d.ts +7 -0
  64. package/dist/core/paths.js +25 -3
  65. package/dist/core/pick-snapshot.d.ts +23 -0
  66. package/dist/core/pick-snapshot.js +51 -0
  67. package/dist/core/pr-comments-fetcher.js +1 -1
  68. package/dist/core/review-analysis.js +5 -9
  69. package/dist/core/state-persistence.js +1 -1
  70. package/dist/core/state-schema.d.ts +117 -0
  71. package/dist/core/state-schema.js +48 -0
  72. package/dist/core/state.d.ts +22 -1
  73. package/dist/core/state.js +65 -12
  74. package/dist/core/strategy.js +2 -3
  75. package/dist/core/types.d.ts +1 -1
  76. package/dist/core/untrusted-content.js +9 -9
  77. package/dist/core/urls.js +1 -1
  78. package/dist/dashboard/assets/chart-panel-DPKNBUts.js +3 -0
  79. package/dist/dashboard/assets/{confetti.module-BYDB1iN2.js → confetti.module-D2UmBLOm.js} +1 -1
  80. package/dist/dashboard/assets/index-B25bZOYX.js +55 -0
  81. package/dist/dashboard/index.html +1 -1
  82. package/dist/formatters/json.d.ts +10 -2
  83. package/dist/formatters/json.js +2 -2
  84. package/package.json +1 -1
  85. package/dist/dashboard/assets/chart-panel-CmNIsCjO.js +0 -3
  86. package/dist/dashboard/assets/index-CTKGc-Ns.js +0 -55
@@ -15,6 +15,28 @@ export const PR_COUNTS_CACHE_TTL_MS = 24 * 60 * 60 * 1000;
15
15
  * 3 pages × 100 per_page = 300 results, which covers the vast majority of users.
16
16
  */
17
17
  const MAX_PAGINATION_PAGES = 3;
18
+ const CLOSING_KEYWORD_RE = /\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)(?::\s*|\s+)(?:https:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/issues\/(\d+)|([\w.-]+\/[\w.-]+)?#(\d+))\b/i;
19
+ /** HTML comments and code: where PR templates keep example `Fixes #123` lines. */
20
+ const NON_PROSE_RE = /<!--[\s\S]*?-->|```[\s\S]*?```|(`+)[^`]*\1/g;
21
+ /** GitHub's PR body limit; also bounds NON_PROSE_RE's scan on an unclosed `<!--`. */
22
+ const MAX_BODY_CHARS = 65_536;
23
+ /**
24
+ * Issue URL a PR closes, from the first GitHub closing keyword in its body
25
+ * (#1824): `Fixes #12`, `closes owner/repo#12`, or `resolves <issue url>`.
26
+ * Joins the outcome ledger to vet-time predictions at zero API cost.
27
+ *
28
+ * ponytail: first keyword wins; a PR closing several issues links only the
29
+ * first. Switch to GraphQL `closingIssuesReferences` if that ever matters.
30
+ */
31
+ export function closingIssueUrl(body, prUrl) {
32
+ const m = body?.slice(0, MAX_BODY_CHARS).replace(NON_PROSE_RE, ' ').match(CLOSING_KEYWORD_RE);
33
+ if (!m)
34
+ return undefined;
35
+ const own = extractOwnerRepo(prUrl);
36
+ // A bare `#12` refers to the PR's own repo.
37
+ const target = m[1] ?? m[3] ?? (own && `${own.owner}/${own.repo}`);
38
+ return target ? `https://github.com/${target}/issues/${m[2] ?? m[4]}` : undefined;
39
+ }
18
40
  /** Returns an empty PRCountsResult. Used as the fallback when stats fetches fail or username is empty. */
19
41
  export function emptyPRCountsResult() {
20
42
  return { repos: new Map(), monthlyCounts: {}, monthlyOpenedCounts: {}, dailyActivityCounts: {}, searchedPRs: [] };
@@ -191,7 +213,7 @@ async function fetchRecentPRs(octokit, config, query, label, days, mapItem, date
191
213
  }
192
214
  const sinceDate = new Date();
193
215
  sinceDate.setDate(sinceDate.getDate() - days);
194
- const since = sinceDate.toISOString().split('T')[0]; // YYYY-MM-DD
216
+ const since = sinceDate.toISOString().split('T', 1)[0]; // YYYY-MM-DD
195
217
  debug(MODULE, `Fetching recently ${label} PRs for @${config.githubUsername} (since ${since})...`);
196
218
  const { data } = await octokit.search.issuesAndPullRequests({
197
219
  q: query.replace('{username}', config.githubUsername).replace('{since}', since),
@@ -235,6 +257,7 @@ export async function fetchRecentlyClosedPRs(octokit, config, days = 7) {
235
257
  closedAt: item.closed_at || '',
236
258
  // Free on the search result — feeds the outcome ledger (#1461).
237
259
  openedAt: item.created_at || undefined,
260
+ issueUrl: closingIssueUrl(item.body, item.html_url),
238
261
  }), (item) => item.closed_at);
239
262
  }
240
263
  /**
@@ -255,6 +278,7 @@ export async function fetchRecentlyMergedPRs(octokit, config, days = 7) {
255
278
  mergedAt: mergedAt || item.closed_at || '',
256
279
  // Free on the search result — feeds the outcome ledger (#1461).
257
280
  openedAt: item.created_at || undefined,
281
+ issueUrl: closingIssueUrl(item.body, item.html_url),
258
282
  };
259
283
  }, (item) => item.pull_request?.merged_at || item.closed_at);
260
284
  }
@@ -323,6 +347,7 @@ export async function fetchMergedPRsSince(octokit, config, since) {
323
347
  mergedAt: date,
324
348
  // Free on the search result — feeds the outcome ledger (#1461).
325
349
  openedAt: item.created_at || undefined,
350
+ issueUrl: closingIssueUrl(item.body, item.html_url),
326
351
  }),
327
352
  }, since);
328
353
  }
@@ -344,6 +369,7 @@ export async function fetchClosedPRsSince(octokit, config, since) {
344
369
  closedAt: date,
345
370
  // Free on the search result — feeds the outcome ledger (#1461).
346
371
  openedAt: item.created_at || undefined,
372
+ issueUrl: closingIssueUrl(item.body, item.html_url),
347
373
  }),
348
374
  }, since);
349
375
  }
@@ -15,7 +15,7 @@ export function guidelinesFilename(repo) {
15
15
  throw new OssAutopilotError(`Invalid repo identifier "${repo}". Expected "owner/repo" format.`, 'INVALID_REPO_ID');
16
16
  }
17
17
  // GitHub forbids `/` in owner and repo, so the only `/` is the separator.
18
- const [owner, name] = repo.split('/');
18
+ const [owner, name] = repo.split('/', 2);
19
19
  return `${GUIDELINES_FILE_PREFIX}${owner}--${name}${GUIDELINES_FILE_SUFFIX}`;
20
20
  }
21
21
  /**
@@ -59,7 +59,7 @@ export class GuidelinesNotAvailableError extends OssAutopilotError {
59
59
  */
60
60
  export class GuidelinesTooLargeError extends OssAutopilotError {
61
61
  constructor(byteSize, max = GUIDELINES_MAX_BYTES) {
62
- super(`Guidelines content is ${byteSize} bytes, exceeding the ${max}-byte cap. ` + `Trim or split across categories.`, 'GUIDELINES_TOO_LARGE');
62
+ super(`Guidelines content is ${byteSize} bytes, exceeding the ${max}-byte cap. Trim or split across categories.`, 'GUIDELINES_TOO_LARGE');
63
63
  this.name = 'GuidelinesTooLargeError';
64
64
  }
65
65
  }
@@ -328,8 +328,7 @@ export async function cachedRequest(cache, url, fetcher) {
328
328
  const promise = doFetch();
329
329
  const cleanup = cache.setInflight(url, promise);
330
330
  try {
331
- const result = await promise;
332
- return result;
331
+ return await promise;
333
332
  }
334
333
  finally {
335
334
  cleanup();
@@ -13,13 +13,13 @@ export { wrapUntrustedContent, fenceFetchedPR, fenceFetchedPRTitles, labelGuidel
13
13
  export { getOctokit, checkRateLimit, type RateLimitInfo } from './github.js';
14
14
  export { parseGitHubUrl, splitRepo, isOwnRepo } from './urls.js';
15
15
  export { daysBetween, formatRelativeTime, byDateDescending } from './dates.js';
16
- export { getCLIVersion, getDataDir, getStatePath, getBackupDir, getCacheDir, stateFileExists } from './paths.js';
16
+ export { getCLIVersion, getDataDir, resolveDataDir, getStatePath, getBackupDir, getCacheDir, stateFileExists, } from './paths.js';
17
17
  export { getGitHubToken, getGitHubTokenAsync, requireGitHubToken, resetGitHubTokenCache, detectGitHubUsername, } from './auth.js';
18
18
  export { DEFAULT_CONCURRENCY } from './concurrency.js';
19
19
  export { OssAutopilotError, ConfigurationError, ValidationError, GistPermissionError, ConcurrencyError, GistConcurrencyError, GistFileSizeError, GIST_FILE_SIZE_REMEDY, errorMessage, getHttpStatusCode, isRateLimitError, isRateLimitOrAuthError, nonFatalCatch, resolveErrorCode, } from './errors.js';
20
20
  export { enableDebug, isDebugEnabled, debug, info, warn, timed } from './logger.js';
21
21
  export { HttpCache, getHttpCache, cachedRequest, type CacheEntry } from './http-cache.js';
22
- export { CRITICAL_STATUSES, applyStatusOverrides, computeRepoSignals, groupPRsByRepo, assessCapacity, collectActionableIssues, computeActionMenu, toShelvedPRRef, buildStarFilter, firstMaintainerResponseFromDigest, formatActionHint, formatBriefSummary, formatSummary, printDigest, } from './daily-logic.js';
22
+ export { CRITICAL_STATUSES, applyStatusOverrides, computeRepoSignals, groupPRsByRepo, assessCapacity, collectActionableIssues, computeActionMenu, toShelvedPRRef, buildStarFilter, firstMaintainerResponseFromDigest, lastReviewStateFromDigest, formatActionHint, formatBriefSummary, formatSummary, printDigest, } from './daily-logic.js';
23
23
  export { computeContributionStats, type ContributionStats, type ComputeStatsInput } from './stats.js';
24
24
  export { fetchPRTemplate, type PRTemplateResult } from './pr-template.js';
25
25
  export { classifyLinkedPR, isLinkedPRStalled, STALLED_PR_THRESHOLD_DAYS, type LinkedPR, type LinkedPRClassification, type LinkedPRState, } from './linked-pr-classification.js';
@@ -31,3 +31,4 @@ export { CONFIG_KEY_REGISTRY, type ConfigKeyDef, type SettableVia, isKnownKey, g
31
31
  export { DashboardDataSchema, DashboardStatsSchema, validateDashboardData, type DashboardDataParsed, } from './dashboard-data-schema.js';
32
32
  export { fetchPRCommentBundle, fetchPRCommentBundlesBatch, type PRCommentBundle, type PRReviewEntry, type PRReviewCommentEntry, type PRIssueCommentEntry, } from './pr-comments-fetcher.js';
33
33
  export * from './types.js';
34
+ export { pickSnapshotFromVet, persistPickSnapshots } from './pick-snapshot.js';
@@ -14,13 +14,13 @@ export { wrapUntrustedContent, fenceFetchedPR, fenceFetchedPRTitles, labelGuidel
14
14
  export { getOctokit, checkRateLimit } from './github.js';
15
15
  export { parseGitHubUrl, splitRepo, isOwnRepo } from './urls.js';
16
16
  export { daysBetween, formatRelativeTime, byDateDescending } from './dates.js';
17
- export { getCLIVersion, getDataDir, getStatePath, getBackupDir, getCacheDir, stateFileExists } from './paths.js';
17
+ export { getCLIVersion, getDataDir, resolveDataDir, getStatePath, getBackupDir, getCacheDir, stateFileExists, } from './paths.js';
18
18
  export { getGitHubToken, getGitHubTokenAsync, requireGitHubToken, resetGitHubTokenCache, detectGitHubUsername, } from './auth.js';
19
19
  export { DEFAULT_CONCURRENCY } from './concurrency.js';
20
20
  export { OssAutopilotError, ConfigurationError, ValidationError, GistPermissionError, ConcurrencyError, GistConcurrencyError, GistFileSizeError, GIST_FILE_SIZE_REMEDY, errorMessage, getHttpStatusCode, isRateLimitError, isRateLimitOrAuthError, nonFatalCatch, resolveErrorCode, } from './errors.js';
21
21
  export { enableDebug, isDebugEnabled, debug, info, warn, timed } from './logger.js';
22
22
  export { HttpCache, getHttpCache, cachedRequest } from './http-cache.js';
23
- export { CRITICAL_STATUSES, applyStatusOverrides, computeRepoSignals, groupPRsByRepo, assessCapacity, collectActionableIssues, computeActionMenu, toShelvedPRRef, buildStarFilter, firstMaintainerResponseFromDigest, formatActionHint, formatBriefSummary, formatSummary, printDigest, } from './daily-logic.js';
23
+ export { CRITICAL_STATUSES, applyStatusOverrides, computeRepoSignals, groupPRsByRepo, assessCapacity, collectActionableIssues, computeActionMenu, toShelvedPRRef, buildStarFilter, firstMaintainerResponseFromDigest, lastReviewStateFromDigest, formatActionHint, formatBriefSummary, formatSummary, printDigest, } from './daily-logic.js';
24
24
  export { computeContributionStats } from './stats.js';
25
25
  export { fetchPRTemplate } from './pr-template.js';
26
26
  export { classifyLinkedPR, isLinkedPRStalled, STALLED_PR_THRESHOLD_DAYS, } from './linked-pr-classification.js';
@@ -35,3 +35,4 @@ export { DashboardDataSchema, DashboardStatsSchema, validateDashboardData, } fro
35
35
  // silently drift (#1208 M5).
36
36
  export { fetchPRCommentBundle, fetchPRCommentBundlesBatch, } from './pr-comments-fetcher.js';
37
37
  export * from './types.js';
38
+ export { pickSnapshotFromVet, persistPickSnapshots } from './pick-snapshot.js';
@@ -39,7 +39,7 @@ export class IssueConversationMonitor {
39
39
  const username = config.githubUsername;
40
40
  const cutoffDate = new Date();
41
41
  cutoffDate.setDate(cutoffDate.getDate() - maxDays);
42
- const since = cutoffDate.toISOString().split('T')[0];
42
+ const since = cutoffDate.toISOString().split('T', 1)[0];
43
43
  debug(MODULE, `Fetching commented issues for @${username} (last ${maxDays} days)...`);
44
44
  // Search for open issues the user has commented on, updated within window
45
45
  // Single page (100) is sufficient for most users; log if truncated.
@@ -25,17 +25,23 @@
25
25
  export function computeIssueEffort(type, hintCount) {
26
26
  const hints = Math.max(0, hintCount);
27
27
  switch (type) {
28
- case 'needs_response':
28
+ case 'needs_response': {
29
29
  return hints <= 1 ? 'small' : 'medium';
30
- case 'incomplete_checklist':
30
+ }
31
+ case 'incomplete_checklist': {
31
32
  return 'small';
32
- case 'needs_changes':
33
+ }
34
+ case 'needs_changes': {
33
35
  return hints >= 3 ? 'large' : 'medium';
34
- case 'ci_failing':
36
+ }
37
+ case 'ci_failing': {
35
38
  return 'medium';
36
- case 'merge_conflict':
39
+ }
40
+ case 'merge_conflict': {
37
41
  return 'large';
38
- default:
42
+ }
43
+ default: {
39
44
  return 'medium';
45
+ }
40
46
  }
41
47
  }
@@ -6,6 +6,13 @@
6
6
  *
7
7
  * Extracted from utils.ts under #1116.
8
8
  */
9
+ /**
10
+ * Resolve `~/.oss-autopilot` without creating it. Every path under the data
11
+ * directory goes through here. Tests run under a temp HOME
12
+ * (test-lib/isolate-home.ts); resolving the real one under vitest means a test
13
+ * escaped it and could clobber the user's state, so it throws (#1801).
14
+ */
15
+ export declare function resolveDataDir(): string;
9
16
  /**
10
17
  * Returns the oss-autopilot data directory path, creating it if it does not exist.
11
18
  *
@@ -9,6 +9,29 @@
9
9
  import * as fs from 'node:fs';
10
10
  import * as path from 'node:path';
11
11
  import * as os from 'node:os';
12
+ /** The passwd home directory, independent of `$HOME`; null when there is no passwd entry. */
13
+ function realHomeDir() {
14
+ try {
15
+ return os.userInfo().homedir;
16
+ }
17
+ catch {
18
+ return null;
19
+ }
20
+ }
21
+ /**
22
+ * Resolve `~/.oss-autopilot` without creating it. Every path under the data
23
+ * directory goes through here. Tests run under a temp HOME
24
+ * (test-lib/isolate-home.ts); resolving the real one under vitest means a test
25
+ * escaped it and could clobber the user's state, so it throws (#1801).
26
+ */
27
+ export function resolveDataDir() {
28
+ const home = os.homedir();
29
+ const realHome = process.env.VITEST ? realHomeDir() : null;
30
+ if (realHome !== null && path.resolve(home) === path.resolve(realHome)) {
31
+ throw new Error(`Refusing to use the real home directory (${home}) under vitest`);
32
+ }
33
+ return path.join(home, '.oss-autopilot');
34
+ }
12
35
  /**
13
36
  * Returns the oss-autopilot data directory path, creating it if it does not exist.
14
37
  *
@@ -22,7 +45,7 @@ import * as os from 'node:os';
22
45
  * // "/Users/you/.oss-autopilot"
23
46
  */
24
47
  export function getDataDir() {
25
- const dir = path.join(os.homedir(), '.oss-autopilot');
48
+ const dir = resolveDataDir();
26
49
  if (!fs.existsSync(dir)) {
27
50
  fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
28
51
  }
@@ -111,8 +134,7 @@ export function getStateCachePath() {
111
134
  * `~/.oss-autopilot/` just to check if the user has ever run the tool.
112
135
  */
113
136
  export function stateFileExists() {
114
- const stateFile = path.join(os.homedir(), '.oss-autopilot', 'state.json');
115
- return fs.existsSync(stateFile);
137
+ return fs.existsSync(path.join(resolveDataDir(), 'state.json'));
116
138
  }
117
139
  /**
118
140
  * Return the @oss-autopilot/core version.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Vet-time predictions for calibration (#1824): what `vet` / `vet-list`
3
+ * thought of an issue, kept so the outcome ledger can compare it against how
4
+ * the PR that closed the issue actually ended.
5
+ */
6
+ import type { VetOutput } from '../formatters/json.js';
7
+ import { type StateManager } from './state.js';
8
+ import type { PickSnapshot } from './types.js';
9
+ /**
10
+ * The prediction to keep for a vetted issue, or undefined when the user's own
11
+ * PR is already linked: scout then grades the issue as taken, which is a
12
+ * post-hoc verdict, not the prediction that picked it.
13
+ */
14
+ export declare function pickSnapshotFromVet(vet: VetOutput, source: PickSnapshot['source']): PickSnapshot | undefined;
15
+ /**
16
+ * Persist predictions without ever failing the vet that produced them. `vet`
17
+ * used to be read-only, so a state save here can race another writer; that
18
+ * and a failed Gist push (#1629) come back as envelope fields instead.
19
+ */
20
+ export declare function persistPickSnapshots(stateManager: StateManager, snapshots: PickSnapshot[]): Promise<{
21
+ pickRecordError?: string;
22
+ gistSyncWarning?: string;
23
+ }>;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Vet-time predictions for calibration (#1824): what `vet` / `vet-list`
3
+ * thought of an issue, kept so the outcome ledger can compare it against how
4
+ * the PR that closed the issue actually ended.
5
+ */
6
+ import { errorMessage } from './errors.js';
7
+ import { warn } from './logger.js';
8
+ import { maybeCheckpoint } from './state.js';
9
+ const MODULE = 'pick-snapshot';
10
+ /**
11
+ * The prediction to keep for a vetted issue, or undefined when the user's own
12
+ * PR is already linked: scout then grades the issue as taken, which is a
13
+ * post-hoc verdict, not the prediction that picked it.
14
+ */
15
+ // ponytail: scout reports only the first linked PR, so a standalone `vet` of an
16
+ // issue whose first reference is someone else's PR can still miss the user's
17
+ // own. First-wins in recordPickSnapshots limits this to never-vetted issues.
18
+ export function pickSnapshotFromVet(vet, source) {
19
+ if (vet.linkedPRClassification?.startsWith('user_'))
20
+ return undefined;
21
+ const stars = vet.projectHealth?.stargazersCount;
22
+ return {
23
+ issueUrl: vet.issue.url,
24
+ grade: vet.grade.score,
25
+ recommendation: vet.recommendation,
26
+ // Stars at pick time feed the eval's repo-size cut (#1825); not recoverable later.
27
+ ...(typeof stars === 'number' && { stargazersCount: stars }),
28
+ source,
29
+ capturedAt: new Date().toISOString(),
30
+ };
31
+ }
32
+ /**
33
+ * Persist predictions without ever failing the vet that produced them. `vet`
34
+ * used to be read-only, so a state save here can race another writer; that
35
+ * and a failed Gist push (#1629) come back as envelope fields instead.
36
+ */
37
+ export async function persistPickSnapshots(stateManager, snapshots) {
38
+ if (snapshots.length === 0)
39
+ return {};
40
+ try {
41
+ stateManager.reloadIfChanged();
42
+ stateManager.recordPickSnapshots(snapshots);
43
+ }
44
+ catch (error) {
45
+ const pickRecordError = `Could not record the vet prediction: ${errorMessage(error)}`;
46
+ warn(MODULE, pickRecordError);
47
+ return { pickRecordError };
48
+ }
49
+ const gistSyncWarning = await maybeCheckpoint(stateManager, MODULE);
50
+ return gistSyncWarning ? { gistSyncWarning } : {};
51
+ }
@@ -107,7 +107,7 @@ export async function fetchPRCommentBundle(octokit, prUrl, githubUsername) {
107
107
  body: fence(c.body ?? '', 'pr-issue-comment', c.user?.login ?? '', c.author_association ?? 'NONE'),
108
108
  createdAt: c.created_at ?? '',
109
109
  })),
110
- ...(truncated ? { truncated: true } : {}),
110
+ ...(truncated && { truncated: true }),
111
111
  };
112
112
  }
113
113
  export async function fetchPRCommentBundlesBatch(octokit, prUrls, githubUsername, concurrency = DEFAULT_BATCH_CONCURRENCY) {
@@ -47,10 +47,8 @@ export function determineReviewDecision(reviews) {
47
47
  export function getLatestChangesRequestedDate(reviews) {
48
48
  let latest;
49
49
  for (const review of reviews) {
50
- if (review.state === 'CHANGES_REQUESTED' && review.submitted_at) {
51
- if (!latest || review.submitted_at > latest) {
52
- latest = review.submitted_at;
53
- }
50
+ if (review.state === 'CHANGES_REQUESTED' && review.submitted_at && (!latest || review.submitted_at > latest)) {
51
+ latest = review.submitted_at;
54
52
  }
55
53
  }
56
54
  return latest;
@@ -165,14 +163,12 @@ export function checkUnrespondedComments(comments, reviews, reviewComments, user
165
163
  const author = review.user?.login || 'unknown';
166
164
  // For inline-only COMMENTED reviews, skip pure self-replies (#199).
167
165
  // CHANGES_REQUESTED reviews are always actionable regardless of self-replies.
168
- if (!body && review.state === 'COMMENTED' && review.id != null) {
169
- if (isAllSelfReplies(review.id, reviewComments)) {
170
- continue;
171
- }
166
+ if (!body && review.state === 'COMMENTED' && review.id != null && isAllSelfReplies(review.id, reviewComments)) {
167
+ continue;
172
168
  }
173
169
  // Resolve body: prefer actual text, then inline comment text, then synthetic placeholder
174
170
  const resolvedBody = body ||
175
- (review.id != null ? getInlineCommentBody(review.id, reviewComments) : undefined) ||
171
+ (review.id == null ? undefined : getInlineCommentBody(review.id, reviewComments)) ||
176
172
  (review.state === 'CHANGES_REQUESTED'
177
173
  ? '(requested changes via inline review comments)'
178
174
  : '(posted inline review comments)');
@@ -537,7 +537,7 @@ export function saveState(state, expectedMtimeMs = null) {
537
537
  // Create backup of existing state (best-effort, non-fatal)
538
538
  try {
539
539
  if (fs.existsSync(statePath)) {
540
- const timestamp = new Date().toISOString().replace(/[.:]/g, '-');
540
+ const timestamp = new Date().toISOString().replaceAll(/[.:]/g, '-');
541
541
  const randomSuffix = Math.random().toString(36).slice(2, 8).padEnd(6, '0');
542
542
  const backupFile = path.join(backupDir, `state-${timestamp}-${randomSuffix}.json`);
543
543
  fs.copyFileSync(statePath, backupFile);
@@ -60,7 +60,41 @@ export declare const RepoScoreSchema: z.ZodObject<{
60
60
  stargazersCount: z.ZodOptional<z.ZodNumber>;
61
61
  language: z.ZodOptional<z.ZodNullable<z.ZodString>>;
62
62
  }, z.core.$strip>;
63
+ /**
64
+ * What the tool predicted about an issue when it was vetted (#1824). Recorded
65
+ * by `vet` / `vet-list` keyed by issue URL, then copied onto the outcome
66
+ * ledger entry of the PR that closes that issue, so outcomes can be compared
67
+ * against the prediction that picked them (calibration).
68
+ */
69
+ export declare const PickSnapshotSchema: z.ZodObject<{
70
+ issueUrl: z.ZodString;
71
+ grade: z.ZodNumber;
72
+ recommendation: z.ZodString;
73
+ stargazersCount: z.ZodOptional<z.ZodNumber>;
74
+ source: z.ZodEnum<{
75
+ vet: "vet";
76
+ "vet-list": "vet-list";
77
+ list: "list";
78
+ }>;
79
+ capturedAt: z.ZodOptional<z.ZodString>;
80
+ }, z.core.$strip>;
63
81
  export declare const StoredMergedPRSchema: z.ZodObject<{
82
+ issueUrl: z.ZodOptional<z.ZodString>;
83
+ pick: z.ZodOptional<z.ZodObject<{
84
+ issueUrl: z.ZodString;
85
+ grade: z.ZodNumber;
86
+ recommendation: z.ZodString;
87
+ stargazersCount: z.ZodOptional<z.ZodNumber>;
88
+ source: z.ZodEnum<{
89
+ vet: "vet";
90
+ "vet-list": "vet-list";
91
+ list: "list";
92
+ }>;
93
+ capturedAt: z.ZodOptional<z.ZodString>;
94
+ }, z.core.$strip>>;
95
+ lastReviewDecision: z.ZodOptional<z.ZodString>;
96
+ lastCiStatus: z.ZodOptional<z.ZodString>;
97
+ backfilledAt: z.ZodOptional<z.ZodString>;
64
98
  url: z.ZodString;
65
99
  title: z.ZodString;
66
100
  mergedAt: z.ZodString;
@@ -70,6 +104,30 @@ export declare const StoredMergedPRSchema: z.ZodObject<{
70
104
  learningsExtractedAt: z.ZodOptional<z.ZodString>;
71
105
  }, z.core.$strip>;
72
106
  export declare const StoredClosedPRSchema: z.ZodObject<{
107
+ closeReason: z.ZodOptional<z.ZodEnum<{
108
+ unknown: "unknown";
109
+ rejected: "rejected";
110
+ "ai-policy": "ai-policy";
111
+ superseded: "superseded";
112
+ stale: "stale";
113
+ "self-closed": "self-closed";
114
+ }>>;
115
+ issueUrl: z.ZodOptional<z.ZodString>;
116
+ pick: z.ZodOptional<z.ZodObject<{
117
+ issueUrl: z.ZodString;
118
+ grade: z.ZodNumber;
119
+ recommendation: z.ZodString;
120
+ stargazersCount: z.ZodOptional<z.ZodNumber>;
121
+ source: z.ZodEnum<{
122
+ vet: "vet";
123
+ "vet-list": "vet-list";
124
+ list: "list";
125
+ }>;
126
+ capturedAt: z.ZodOptional<z.ZodString>;
127
+ }, z.core.$strip>>;
128
+ lastReviewDecision: z.ZodOptional<z.ZodString>;
129
+ lastCiStatus: z.ZodOptional<z.ZodString>;
130
+ backfilledAt: z.ZodOptional<z.ZodString>;
73
131
  url: z.ZodString;
74
132
  title: z.ZodString;
75
133
  closedAt: z.ZodString;
@@ -323,6 +381,7 @@ export declare const ClosedPRSchema: z.ZodObject<{
323
381
  closedAt: z.ZodString;
324
382
  closedBy: z.ZodOptional<z.ZodString>;
325
383
  openedAt: z.ZodOptional<z.ZodString>;
384
+ issueUrl: z.ZodOptional<z.ZodString>;
326
385
  }, z.core.$strip>;
327
386
  export declare const MergedPRSchema: z.ZodObject<{
328
387
  url: z.ZodString;
@@ -331,6 +390,7 @@ export declare const MergedPRSchema: z.ZodObject<{
331
390
  title: z.ZodString;
332
391
  mergedAt: z.ZodString;
333
392
  openedAt: z.ZodOptional<z.ZodString>;
393
+ issueUrl: z.ZodOptional<z.ZodString>;
334
394
  }, z.core.$strip>;
335
395
  export declare const DailyDigestSummarySchema: z.ZodObject<{
336
396
  totalActivePRs: z.ZodNumber;
@@ -369,6 +429,7 @@ export declare const DailyDigestSchema: z.ZodPreprocess<z.ZodObject<{
369
429
  closedAt: z.ZodString;
370
430
  closedBy: z.ZodOptional<z.ZodString>;
371
431
  openedAt: z.ZodOptional<z.ZodString>;
432
+ issueUrl: z.ZodOptional<z.ZodString>;
372
433
  }, z.core.$strip>>;
373
434
  recentlyMergedPRs: z.ZodArray<z.ZodObject<{
374
435
  url: z.ZodString;
@@ -377,6 +438,7 @@ export declare const DailyDigestSchema: z.ZodPreprocess<z.ZodObject<{
377
438
  title: z.ZodString;
378
439
  mergedAt: z.ZodString;
379
440
  openedAt: z.ZodOptional<z.ZodString>;
441
+ issueUrl: z.ZodOptional<z.ZodString>;
380
442
  }, z.core.$strip>>;
381
443
  shelvedPRs: z.ZodArray<z.ZodObject<{
382
444
  number: z.ZodNumber;
@@ -599,6 +661,7 @@ export declare const AgentStateSchema: z.ZodObject<{
599
661
  closedAt: z.ZodString;
600
662
  closedBy: z.ZodOptional<z.ZodString>;
601
663
  openedAt: z.ZodOptional<z.ZodString>;
664
+ issueUrl: z.ZodOptional<z.ZodString>;
602
665
  }, z.core.$strip>>;
603
666
  recentlyMergedPRs: z.ZodArray<z.ZodObject<{
604
667
  url: z.ZodString;
@@ -607,6 +670,7 @@ export declare const AgentStateSchema: z.ZodObject<{
607
670
  title: z.ZodString;
608
671
  mergedAt: z.ZodString;
609
672
  openedAt: z.ZodOptional<z.ZodString>;
673
+ issueUrl: z.ZodOptional<z.ZodString>;
610
674
  }, z.core.$strip>>;
611
675
  shelvedPRs: z.ZodArray<z.ZodObject<{
612
676
  number: z.ZodNumber;
@@ -650,6 +714,22 @@ export declare const AgentStateSchema: z.ZodObject<{
650
714
  cachedAt: z.ZodString;
651
715
  }, z.core.$strip>>;
652
716
  mergedPRs: z.ZodOptional<z.ZodArray<z.ZodObject<{
717
+ issueUrl: z.ZodOptional<z.ZodString>;
718
+ pick: z.ZodOptional<z.ZodObject<{
719
+ issueUrl: z.ZodString;
720
+ grade: z.ZodNumber;
721
+ recommendation: z.ZodString;
722
+ stargazersCount: z.ZodOptional<z.ZodNumber>;
723
+ source: z.ZodEnum<{
724
+ vet: "vet";
725
+ "vet-list": "vet-list";
726
+ list: "list";
727
+ }>;
728
+ capturedAt: z.ZodOptional<z.ZodString>;
729
+ }, z.core.$strip>>;
730
+ lastReviewDecision: z.ZodOptional<z.ZodString>;
731
+ lastCiStatus: z.ZodOptional<z.ZodString>;
732
+ backfilledAt: z.ZodOptional<z.ZodString>;
653
733
  url: z.ZodString;
654
734
  title: z.ZodString;
655
735
  mergedAt: z.ZodString;
@@ -659,6 +739,30 @@ export declare const AgentStateSchema: z.ZodObject<{
659
739
  learningsExtractedAt: z.ZodOptional<z.ZodString>;
660
740
  }, z.core.$strip>>>;
661
741
  closedPRs: z.ZodOptional<z.ZodArray<z.ZodObject<{
742
+ closeReason: z.ZodOptional<z.ZodEnum<{
743
+ unknown: "unknown";
744
+ rejected: "rejected";
745
+ "ai-policy": "ai-policy";
746
+ superseded: "superseded";
747
+ stale: "stale";
748
+ "self-closed": "self-closed";
749
+ }>>;
750
+ issueUrl: z.ZodOptional<z.ZodString>;
751
+ pick: z.ZodOptional<z.ZodObject<{
752
+ issueUrl: z.ZodString;
753
+ grade: z.ZodNumber;
754
+ recommendation: z.ZodString;
755
+ stargazersCount: z.ZodOptional<z.ZodNumber>;
756
+ source: z.ZodEnum<{
757
+ vet: "vet";
758
+ "vet-list": "vet-list";
759
+ list: "list";
760
+ }>;
761
+ capturedAt: z.ZodOptional<z.ZodString>;
762
+ }, z.core.$strip>>;
763
+ lastReviewDecision: z.ZodOptional<z.ZodString>;
764
+ lastCiStatus: z.ZodOptional<z.ZodString>;
765
+ backfilledAt: z.ZodOptional<z.ZodString>;
662
766
  url: z.ZodString;
663
767
  title: z.ZodString;
664
768
  closedAt: z.ZodString;
@@ -745,6 +849,18 @@ export declare const AgentStateSchema: z.ZodObject<{
745
849
  url: z.ZodString;
746
850
  lastSeenAt: z.ZodString;
747
851
  }, z.core.$strip>>>;
852
+ pickSnapshots: z.ZodDefault<z.ZodArray<z.ZodObject<{
853
+ issueUrl: z.ZodString;
854
+ grade: z.ZodNumber;
855
+ recommendation: z.ZodString;
856
+ stargazersCount: z.ZodOptional<z.ZodNumber>;
857
+ source: z.ZodEnum<{
858
+ vet: "vet";
859
+ "vet-list": "vet-list";
860
+ list: "list";
861
+ }>;
862
+ capturedAt: z.ZodOptional<z.ZodString>;
863
+ }, z.core.$strip>>>;
748
864
  lastOvernight: z.ZodOptional<z.ZodObject<{
749
865
  runAt: z.ZodString;
750
866
  reportPath: z.ZodString;
@@ -787,6 +903,7 @@ export type ProjectCategory = z.infer<typeof ProjectCategorySchema>;
787
903
  export type IssueScope = z.infer<typeof IssueScopeSchema>;
788
904
  export type DiffTool = z.infer<typeof DiffToolSchema>;
789
905
  export type SearchSeenEntry = z.infer<typeof SearchSeenEntrySchema>;
906
+ export type PickSnapshot = z.infer<typeof PickSnapshotSchema>;
790
907
  export type OvernightPrepared = z.infer<typeof OvernightPreparedSchema>;
791
908
  export type OvernightRecord = z.infer<typeof OvernightRecordSchema>;
792
909
  export type OvernightImplementAttempt = z.infer<typeof OvernightImplementAttemptSchema>;