@oss-autopilot/core 3.28.0 → 3.28.1

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 (39) hide show
  1. package/dist/cli-pre-action.d.ts +9 -0
  2. package/dist/cli-pre-action.js +95 -0
  3. package/dist/cli.bundle.cjs +94 -94
  4. package/dist/cli.js +4 -87
  5. package/dist/commands/comments.js +3 -1
  6. package/dist/commands/dashboard-server.js +1 -1
  7. package/dist/commands/dashboard.d.ts +2 -2
  8. package/dist/commands/dashboard.js +13 -5
  9. package/dist/commands/overnight-push-prep.js +4 -0
  10. package/dist/commands/overnight.js +7 -1
  11. package/dist/core/ci-analysis.js +11 -4
  12. package/dist/core/errors.d.ts +17 -0
  13. package/dist/core/errors.js +25 -0
  14. package/dist/core/pr-monitor.d.ts +2 -2
  15. package/dist/core/pr-monitor.js +9 -6
  16. package/dist/core/review-analysis.d.ts +6 -2
  17. package/dist/core/review-analysis.js +13 -4
  18. package/dist/core/types.d.ts +1 -1
  19. package/dist/dashboard/assets/chart-panel-0drzwc3-.js +3 -0
  20. package/dist/dashboard/assets/confetti.module-BYDB1iN2.js +2 -0
  21. package/dist/dashboard/assets/index-C0LCGMVi.js +50 -0
  22. package/dist/dashboard/assets/index-CTiG-vjC.css +1 -0
  23. package/dist/dashboard/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
  24. package/dist/dashboard/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  25. package/dist/dashboard/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
  26. package/dist/dashboard/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
  27. package/dist/dashboard/assets/plus-jakarta-sans-latin-400-normal-BDKaGhyp.woff +0 -0
  28. package/dist/dashboard/assets/plus-jakarta-sans-latin-400-normal-Dhut76fR.woff2 +0 -0
  29. package/dist/dashboard/assets/plus-jakarta-sans-latin-500-normal-Bf-nb4oT.woff2 +0 -0
  30. package/dist/dashboard/assets/plus-jakarta-sans-latin-500-normal-DYtqi0QS.woff +0 -0
  31. package/dist/dashboard/assets/plus-jakarta-sans-latin-600-normal-BR_Ojra4.woff +0 -0
  32. package/dist/dashboard/assets/plus-jakarta-sans-latin-600-normal-DLTa1BUW.woff2 +0 -0
  33. package/dist/dashboard/assets/plus-jakarta-sans-latin-700-normal-CfpNZvy6.woff2 +0 -0
  34. package/dist/dashboard/assets/plus-jakarta-sans-latin-700-normal-DqEcQeE5.woff +0 -0
  35. package/dist/dashboard/assets/plus-jakarta-sans-latin-800-normal-BRNHt2w0.woff +0 -0
  36. package/dist/dashboard/assets/plus-jakarta-sans-latin-800-normal-CusIZhrK.woff2 +0 -0
  37. package/dist/dashboard/favicon.svg +83 -0
  38. package/dist/dashboard/index.html +54 -0
  39. package/package.json +3 -2
package/dist/cli.js CHANGED
@@ -9,8 +9,9 @@
9
9
  * handlers so only the invoked command's dependencies are evaluated.
10
10
  */
11
11
  import { Command } from 'commander';
12
- import { getGitHubTokenAsync, enableDebug, debug, getCLIVersion, stateFileExists } from './core/index.js';
12
+ import { getCLIVersion, stateFileExists } from './core/index.js';
13
13
  import { commands, handleCommandError } from './cli-registry.js';
14
+ import { installPreAction } from './cli-pre-action.js';
14
15
  const VERSION = getCLIVersion();
15
16
  const program = new Command();
16
17
  program
@@ -24,92 +25,8 @@ const localOnlySet = new Set(commands.filter((c) => c.localOnly).map((c) => c.na
24
25
  for (const cmd of commands) {
25
26
  cmd.register(program);
26
27
  }
27
- // Validate GitHub token before running commands that need it
28
- program.hook('preAction', async (thisCommand, actionCommand) => {
29
- // Enable debug logging if --debug flag is set
30
- const globalOpts = thisCommand.opts();
31
- if (globalOpts.debug) {
32
- enableDebug();
33
- debug('cli', `Running command: ${actionCommand.name()}`);
34
- }
35
- // actionCommand is the command being executed (e.g., 'status', 'daily').
36
- // For subcommand groups (e.g. `guidelines view`), Commander returns the
37
- // leaf name `view` — but the registry sets `localOnly` on the parent
38
- // entry `guidelines`. Walk the parent chain so a `localOnly` ancestor
39
- // covers all its leaves (#1208 M2). Without this, `guidelines view` —
40
- // which works fine in local mode (returns storageMode: 'local-unavailable')
41
- // — would still hit the auth gate and fail.
42
- let cmd = actionCommand;
43
- let isLocalOnly = false;
44
- while (cmd) {
45
- if (localOnlySet.has(cmd.name())) {
46
- isLocalOnly = true;
47
- break;
48
- }
49
- cmd = cmd.parent;
50
- }
51
- if (!isLocalOnly) {
52
- const token = await getGitHubTokenAsync();
53
- if (!token) {
54
- // Honor --json at the CLI boundary so machine consumers (plugins, MCP
55
- // stdio harnesses, scripts) get a parseable envelope instead of a
56
- // stderr blob followed by a non-zero exit. Commander has already parsed
57
- // the action's own options, so we check both the action command and the
58
- // raw argv as a fallback (#1056 M20).
59
- const wantsJson = Boolean(actionCommand.opts().json) || process.argv.includes('--json');
60
- if (wantsJson) {
61
- const { outputJsonError } = await import('./formatters/json.js');
62
- outputJsonError('GitHub authentication required. Install gh CLI and run `gh auth login`, or set GITHUB_TOKEN.', 'AUTH_REQUIRED');
63
- }
64
- else {
65
- console.error('Error: GitHub authentication required.');
66
- console.error('');
67
- console.error('Option 1 (Recommended): Install and authenticate GitHub CLI');
68
- console.error(' Install: https://cli.github.com/');
69
- console.error(' Then run: gh auth login');
70
- console.error('');
71
- console.error('Option 2: Set GITHUB_TOKEN environment variable');
72
- console.error(' export GITHUB_TOKEN="your-github-token-here"');
73
- console.error('');
74
- console.error('Then run your command again.');
75
- }
76
- process.exit(1);
77
- }
78
- // Activate Gist persistence if configured, before any command runs.
79
- // Shared helper peeks at the state file and only pre-sets the singleton
80
- // when Gist mode is the configured persistence (#1000). Hard errors
81
- // still throw (#1202); the resolving degraded modes are surfaced in the
82
- // JSON envelope so --json consumers see them too (#1433).
83
- const { ensureGistPersistence, renderGistWarning } = await import('./core/index.js');
84
- const status = await ensureGistPersistence(token);
85
- if (status === 'degraded' || status === 'state-unreadable') {
86
- const { setEnvelopeGistWarning } = await import('./formatters/json.js');
87
- // Shared renderer (#1444). 'degraded' is ensureGistPersistence's
88
- // deliberate conflation of the transient init fallback and a #1443
89
- // degraded bootstrap — rendered as the init-fallback cause, as before.
90
- setEnvelopeGistWarning(renderGistWarning(status === 'degraded' ? 'init-fallback' : 'state-unreadable'));
91
- }
92
- }
93
- else {
94
- // #1431: localOnly skips the AUTH GATE, not gist persistence. Mutating
95
- // localOnly commands (shelve/move/dismiss/override/...) already call
96
- // maybeCheckpoint, which silently no-ops when the singleton never
97
- // bootstrapped — so a gist-configured user's CLI mutations were written
98
- // local-only with no warning and never reached the Gist. Best-effort
99
- // bootstrap; the warning semantics live (and are unit-tested) in
100
- // bootstrapGistBestEffort.
101
- const { bootstrapGistBestEffort } = await import('./core/index.js');
102
- const localOnlyWarning = await bootstrapGistBestEffort(getGitHubTokenAsync);
103
- if (localOnlyWarning) {
104
- console.error(`Warning: ${localOnlyWarning}`);
105
- // Also thread it into the JSON envelope: shelve/move/dismiss --json
106
- // consumers (the agent harness) must see the mutation will not sync —
107
- // stderr alone is invisible to them (#1433).
108
- const { setEnvelopeGistWarning } = await import('./formatters/json.js');
109
- setEnvelopeGistWarning(localOnlyWarning);
110
- }
111
- }
112
- });
28
+ // Debug flag, auth gate and Gist bootstrap (see cli-pre-action.ts).
29
+ installPreAction(program, localOnlySet);
113
30
  // First-run detection: if no subcommand was provided and no state file exists,
114
31
  // show a quick-start guide and exit before Commander displays generic help.
115
32
  const userArgs = process.argv.slice(2);
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { getStateManager, getOctokit, parseGitHubUrl, requireGitHubToken, maybeCheckpoint } from '../core/index.js';
6
6
  import { wrapUntrustedContent } from '../core/untrusted-content.js';
7
- import { ValidationError, isRateLimitOrAuthError } from '../core/errors.js';
7
+ import { ValidationError, assertAttended, isRateLimitOrAuthError } from '../core/errors.js';
8
8
  import { warn } from '../core/logger.js';
9
9
  const MODULE = 'comments';
10
10
  import { paginateAllDetailed } from '../core/pagination.js';
@@ -157,6 +157,7 @@ export async function runComments(options) {
157
157
  * @throws {ValidationError} If the URL or message is invalid
158
158
  */
159
159
  export async function runPost(options) {
160
+ assertAttended('post a comment');
160
161
  validateUrl(options.url);
161
162
  validateGitHubUrl(options.url, ISSUE_OR_PR_URL_PATTERN, 'issue or PR');
162
163
  if (!options.message.trim()) {
@@ -192,6 +193,7 @@ export async function runPost(options) {
192
193
  * @throws {ValidationError} If the URL or message is invalid
193
194
  */
194
195
  export async function runClaim(options) {
196
+ assertAttended('claim an issue');
195
197
  validateUrl(options.issueUrl);
196
198
  validateGitHubUrl(options.issueUrl, ISSUE_URL_PATTERN, 'issue');
197
199
  const token = requireGitHubToken();
@@ -212,7 +212,7 @@ export async function startDashboardServer(options) {
212
212
  // cache after the port is bound, so the startup poller sees us in time.
213
213
  const initialDigest = gistSync.stateManager.getState().lastDigest;
214
214
  if (!initialDigest) {
215
- throw new Error('No dashboard data available. Run the daily check first: GITHUB_TOKEN=$(gh auth token) npm start -- daily');
215
+ throw new Error('No dashboard data available. Run the daily check first: oss-autopilot daily (or /oss in Claude Code)');
216
216
  }
217
217
  const cache = new DashboardCache(initialDigest, (failures) => gistSync.withPendingGistWarnings(failures));
218
218
  // ── Build cached JSON response ───────────────────────────────────────────
@@ -6,8 +6,8 @@ interface ServeOptions {
6
6
  open: boolean;
7
7
  }
8
8
  /**
9
- * Resolve the SPA assets directory from packages/dashboard/dist/.
10
- * Tries multiple strategies to locate it across dev (tsx) and bundled (cjs) modes.
9
+ * Resolve the SPA assets directory. Tries packages/dashboard/dist/ in a
10
+ * checkout (dev via tsx, or the bundle), then the copy shipped in the npm package.
11
11
  */
12
12
  export declare function resolveAssetsDir(): string | null;
13
13
  export declare function serveDashboard(options: ServeOptions): Promise<void>;
@@ -5,8 +5,8 @@ import * as fs from 'node:fs';
5
5
  import * as path from 'node:path';
6
6
  import { getGitHubToken } from '../core/index.js';
7
7
  /**
8
- * Resolve the SPA assets directory from packages/dashboard/dist/.
9
- * Tries multiple strategies to locate it across dev (tsx) and bundled (cjs) modes.
8
+ * Resolve the SPA assets directory. Tries packages/dashboard/dist/ in a
9
+ * checkout (dev via tsx, or the bundle), then the copy shipped in the npm package.
10
10
  */
11
11
  export function resolveAssetsDir() {
12
12
  // Strategy 1: relative to this source file (works in dev with tsx)
@@ -19,7 +19,15 @@ export function resolveAssetsDir() {
19
19
  if (fs.existsSync(path.join(bundlePath, 'index.html'))) {
20
20
  return bundlePath;
21
21
  }
22
- // Strategy 3: resolve the dashboard package via require.resolve
22
+ // Strategy 3: assets shipped inside the published package. `prepublishOnly`
23
+ // copies packages/dashboard/dist to dist/dashboard, next to the CLI bundle,
24
+ // because @oss-autopilot/dashboard itself is private and never on npm. Kept
25
+ // after the checkout paths so a working tree serves its own fresh build.
26
+ const packagedPath = path.resolve(__dirname, 'dashboard');
27
+ if (fs.existsSync(path.join(packagedPath, 'index.html'))) {
28
+ return packagedPath;
29
+ }
30
+ // Strategy 4: resolve the dashboard package via require.resolve
23
31
  try {
24
32
  const dashboardPkgPath = require.resolve('@oss-autopilot/dashboard/package.json');
25
33
  const dashboardDist = path.join(path.dirname(dashboardPkgPath), 'dist');
@@ -39,8 +47,8 @@ export async function serveDashboard(options) {
39
47
  const assetsDir = resolveAssetsDir();
40
48
  if (!assetsDir) {
41
49
  console.error('Could not find dashboard SPA assets.');
42
- console.error('Make sure packages/dashboard has been built:');
43
- console.error(' cd packages/dashboard && pnpm run build');
50
+ console.error('From a git checkout, build them: cd packages/dashboard && pnpm run build');
51
+ console.error('From npm, update to the latest @oss-autopilot/core; older releases did not include them.');
44
52
  process.exit(1);
45
53
  }
46
54
  const token = getGitHubToken();
@@ -19,6 +19,7 @@
19
19
  import { execFileSync } from 'node:child_process';
20
20
  import * as fs from 'node:fs';
21
21
  import { errorMessage, getOctokit, getStateManager, isRateLimitError, maybeCheckpoint, parseGitHubUrl, requireGitHubToken, } from '../core/index.js';
22
+ import { assertAttended } from '../core/errors.js';
22
23
  import { warn } from '../core/logger.js';
23
24
  import { publishReport, writePreparedSection } from './overnight.js';
24
25
  const MODULE = 'overnight-push-prep';
@@ -153,6 +154,9 @@ function skip(entry, reason, target, ref) {
153
154
  }
154
155
  /** Push every prepared branch of the latest overnight run to `prep/*` on the user's fork. */
155
156
  export async function runOvernightPushPrep(options) {
157
+ // A scheduler runs this after the model tick has ended, in its own
158
+ // environment. Inside the tick it must not run at all.
159
+ assertAttended('push prepared branches');
156
160
  const sm = getStateManager();
157
161
  const last = sm.getLastOvernight();
158
162
  if (!last)
@@ -22,6 +22,7 @@ import * as fs from 'node:fs';
22
22
  import * as os from 'node:os';
23
23
  import * as path from 'node:path';
24
24
  import { errorMessage, getStateManager, maybeCheckpoint, parseGitHubUrl, requireGitHubToken } from '../core/index.js';
25
+ import { UNATTENDED_ENV } from '../core/errors.js';
25
26
  import { warn } from '../core/logger.js';
26
27
  import { getReportsDir } from '../core/paths.js';
27
28
  import { detectIssueListPath } from './locate-issue-list.js';
@@ -551,7 +552,12 @@ export function renderLaunchdPlist(options, logPath, settingsPath) {
551
552
  ' <key>EnvironmentVariables</key>',
552
553
  // launchd inherits no shell PATH; include the dir of the node that ran
553
554
  // `schedule` so a version-manager node resolves for the CLI and tests.
554
- ` <dict><key>PATH</key><string>${xmlEscape(`${path.dirname(process.execPath)}:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin`)}</string></dict>`,
555
+ ' <dict>',
556
+ ` <key>PATH</key><string>${xmlEscape(`${path.dirname(process.execPath)}:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin`)}</string>`,
557
+ // The CLI's own GitHub-writing commands refuse while this is set (see
558
+ // assertAttended): `Bash(node *)` has to stay allowed, so the gate is in code.
559
+ ` <key>${UNATTENDED_ENV}</key><string>1</string>`,
560
+ ' </dict>',
555
561
  '</dict>',
556
562
  '</plist>',
557
563
  '',
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { getHttpStatusCode, errorMessage } from './errors.js';
6
6
  import { debug, warn } from './logger.js';
7
+ import { paginateAll } from './pagination.js';
7
8
  /** Return a fresh unknown CI status (avoids shared mutable state between callers). */
8
9
  function unknownCIStatus() {
9
10
  return { status: 'unknown', failingCheckNames: [], failingCheckConclusions: new Map() };
@@ -315,10 +316,16 @@ export async function getCIStatus(octokit, owner, repo, sha) {
315
316
  return unknownCIStatus();
316
317
  try {
317
318
  // Fetch both combined status and check runs in parallel
318
- const [statusResponse, checksResponse] = await Promise.all([
319
- octokit.repos.getCombinedStatusForRef({ owner, repo, ref: sha }),
319
+ const [statusResponse, checkRuns] = await Promise.all([
320
+ // per_page 100: the default page holds 30 statuses, and analyzeCombinedStatus
321
+ // only sees the page it is given.
322
+ octokit.repos.getCombinedStatusForRef({ owner, repo, ref: sha, per_page: 100 }),
320
323
  // 404 is expected for repos without check runs configured; log other errors for debugging
321
- octokit.checks.listForRef({ owner, repo, ref: sha }).catch((err) => {
324
+ // Paginated: the default page is 30 check runs, and a failing check on a
325
+ // later page would otherwise read as passing.
326
+ paginateAll((page) => octokit.checks
327
+ .listForRef({ owner, repo, ref: sha, per_page: 100, page })
328
+ .then((res) => ({ data: res.data.check_runs }))).catch((err) => {
322
329
  const status = getHttpStatusCode(err);
323
330
  // Rate limit errors must propagate — matches listReviewComments pattern (#481)
324
331
  if (status === 429)
@@ -338,7 +345,7 @@ export async function getCIStatus(octokit, owner, repo, sha) {
338
345
  }),
339
346
  ]);
340
347
  const combinedStatus = statusResponse.data;
341
- const allCheckRuns = checksResponse?.data?.check_runs || [];
348
+ const allCheckRuns = checkRuns ?? [];
342
349
  return computeCIStatus(allCheckRuns, combinedStatus);
343
350
  }
344
351
  catch (error) {
@@ -20,6 +20,23 @@ export declare class OssAutopilotError extends Error {
20
20
  export declare class ConfigurationError extends OssAutopilotError {
21
21
  constructor(message: string);
22
22
  }
23
+ /**
24
+ * Set by the scheduled overnight job (see `renderLaunchdPlist`). Any defined
25
+ * value, even an empty one, marks the run as unattended. Nobody
26
+ * is present to approve anything in that run, so the commands that write to
27
+ * GitHub refuse while it is set.
28
+ */
29
+ export declare const UNATTENDED_ENV = "OSS_AUTOPILOT_UNATTENDED";
30
+ /**
31
+ * Refuse a GitHub-writing action during an unattended run.
32
+ *
33
+ * The overnight allowlist has to permit `node`, because the run itself calls
34
+ * this CLI, so a deny rule on the command line cannot keep the model away from
35
+ * `post`, `claim` or `overnight push-prep`. The check lives here instead, where
36
+ * every route to the write (CLI, MCP tool, library import) passes through it.
37
+ * This closes the direct path; it is not a sandbox against arbitrary code.
38
+ */
39
+ export declare function assertAttended(action: string): void;
23
40
  /**
24
41
  * Input validation errors (invalid URLs, out-of-range values).
25
42
  */
@@ -28,6 +28,31 @@ export class ConfigurationError extends OssAutopilotError {
28
28
  this.name = 'ConfigurationError';
29
29
  }
30
30
  }
31
+ /**
32
+ * Set by the scheduled overnight job (see `renderLaunchdPlist`). Any defined
33
+ * value, even an empty one, marks the run as unattended. Nobody
34
+ * is present to approve anything in that run, so the commands that write to
35
+ * GitHub refuse while it is set.
36
+ */
37
+ export const UNATTENDED_ENV = 'OSS_AUTOPILOT_UNATTENDED';
38
+ /**
39
+ * Refuse a GitHub-writing action during an unattended run.
40
+ *
41
+ * The overnight allowlist has to permit `node`, because the run itself calls
42
+ * this CLI, so a deny rule on the command line cannot keep the model away from
43
+ * `post`, `claim` or `overnight push-prep`. The check lives here instead, where
44
+ * every route to the write (CLI, MCP tool, library import) passes through it.
45
+ * This closes the direct path; it is not a sandbox against arbitrary code.
46
+ */
47
+ export function assertAttended(action) {
48
+ // Any defined value counts, including '' and '0'. If a value could switch the
49
+ // guard off, prefixing the command with `${UNATTENDED_ENV}=0` would be the
50
+ // shortest way around it.
51
+ if (process.env[UNATTENDED_ENV] !== undefined) {
52
+ throw new ConfigurationError(`Refusing to ${action} during an unattended run (${UNATTENDED_ENV} is set). ` +
53
+ 'Run it yourself in an interactive session.');
54
+ }
55
+ }
31
56
  /**
32
57
  * Input validation errors (invalid URLs, out-of-range values).
33
58
  */
@@ -40,8 +40,8 @@ export interface FetchPRsResult {
40
40
  * - Post-fetch viewer-mismatch guardrail (configured username differs
41
41
  * from the authenticated viewer when the search returned zero PRs).
42
42
  * - Search API 1000-result truncation (#1057 M25).
43
- * - Per-PR comment pagination truncation (#1456) — newest comments
44
- * dropped, so unresponded-comment detection may be incomplete.
43
+ * - Per-PR comment or review pagination truncation (#1456) — newest entries
44
+ * dropped, so review-decision / unresponded-comment detection may be incomplete.
45
45
  * Callers (daily, dashboard) surface these so users see the signal.
46
46
  */
47
47
  warnings?: string[];
@@ -317,10 +317,13 @@ export class PRMonitor {
317
317
  // Fetch PR data, comments, reviews, and inline review comments in parallel.
318
318
  // listReviewComments is non-critical (used for self-reply detection), so degrade
319
319
  // gracefully on failure rather than dropping the entire PR (#199).
320
- const [prResponse, commentsResult, reviewsResponse, reviewCommentsResult] = await Promise.all([
320
+ const [prResponse, commentsResult, reviewsResult, reviewCommentsResult] = await Promise.all([
321
321
  this.octokit.pulls.get({ owner, repo, pull_number: number }),
322
322
  paginateAllDetailed((page) => this.octokit.issues.listComments({ owner, repo, issue_number: number, per_page: 100, page })),
323
- this.octokit.pulls.listReviews({ owner, repo, pull_number: number }),
323
+ // Paginated: PRs land on this REST path precisely when GraphQL's review
324
+ // cap overflowed, and listReviews returns oldest-first, so an unpaginated
325
+ // call would drop the newest verdicts.
326
+ paginateAllDetailed((page) => this.octokit.pulls.listReviews({ owner, repo, pull_number: number, per_page: 100, page })),
324
327
  paginateAllDetailed((page) => this.octokit.pulls.listReviewComments({ owner, repo, pull_number: number, per_page: 100, page })).catch((err) => {
325
328
  const status = getHttpStatusCode(err);
326
329
  // Rate limit errors must propagate — silently swallowing them hides
@@ -352,14 +355,14 @@ export class PRMonitor {
352
355
  // (#1456): comments arrive oldest-first, so hitting the cap drops the
353
356
  // NEWEST maintainer feedback — status determination (unresponded-comment
354
357
  // detection) may be wrong for this PR.
355
- if (commentsResult.truncated || reviewCommentsResult.truncated) {
356
- const message = `Comment pagination cap reached for ${owner}/${repo}#${number}; the newest comments were not ` +
357
- `fetched and unresponded-comment detection may be incomplete.`;
358
+ if (commentsResult.truncated || reviewsResult.truncated || reviewCommentsResult.truncated) {
359
+ const message = `Comment pagination cap reached for ${owner}/${repo}#${number}; the newest comments or reviews were not ` +
360
+ `fetched and review-decision / unresponded-comment detection may be incomplete.`;
358
361
  warnings?.push(message);
359
362
  warn(MODULE, message);
360
363
  }
361
364
  const ghPR = prResponse.data;
362
- const reviews = reviewsResponse.data;
365
+ const reviews = reviewsResult.items;
363
366
  const ciStatus = await getCIStatus(this.octokit, owner, repo, ghPR.head.sha);
364
367
  // The commit date is only consulted (and only fetched) when the PR has an
365
368
  // unresponded maintainer comment or a changes-requested review — the shared
@@ -17,8 +17,12 @@ export interface ReviewComment {
17
17
  }
18
18
  /**
19
19
  * Determine review decision from reviews list.
20
- * Groups reviews by user, keeping only the latest from each user,
21
- * then checks for CHANGES_REQUESTED or APPROVED states.
20
+ * Groups reviews by user, keeping each user's latest verdict, then checks
21
+ * for CHANGES_REQUESTED or APPROVED states.
22
+ *
23
+ * Only APPROVED, CHANGES_REQUESTED and DISMISSED change a reviewer's standing
24
+ * verdict on GitHub. COMMENTED is also what GitHub records for every inline
25
+ * reply, so it must not overwrite an earlier verdict from the same reviewer.
22
26
  */
23
27
  export declare function determineReviewDecision(reviews: Array<{
24
28
  state?: string | null;
@@ -6,19 +6,28 @@
6
6
  import { isBotAuthor, isAcknowledgmentComment } from './comment-utils.js';
7
7
  /**
8
8
  * Determine review decision from reviews list.
9
- * Groups reviews by user, keeping only the latest from each user,
10
- * then checks for CHANGES_REQUESTED or APPROVED states.
9
+ * Groups reviews by user, keeping each user's latest verdict, then checks
10
+ * for CHANGES_REQUESTED or APPROVED states.
11
+ *
12
+ * Only APPROVED, CHANGES_REQUESTED and DISMISSED change a reviewer's standing
13
+ * verdict on GitHub. COMMENTED is also what GitHub records for every inline
14
+ * reply, so it must not overwrite an earlier verdict from the same reviewer.
11
15
  */
12
16
  export function determineReviewDecision(reviews) {
13
17
  if (reviews.length === 0) {
14
18
  return 'review_required';
15
19
  }
16
- // Group reviews by user, keeping only the latest from each user
20
+ // Group reviews by user, keeping each user's latest verdict
17
21
  const latestByUser = new Map();
18
22
  for (const review of reviews) {
19
23
  const login = review.user?.login;
20
24
  const state = review.state;
21
- if (login && state) {
25
+ if (!login || !state)
26
+ continue;
27
+ if (state === 'DISMISSED') {
28
+ latestByUser.delete(login);
29
+ }
30
+ else if (state === 'APPROVED' || state === 'CHANGES_REQUESTED') {
22
31
  latestByUser.set(login, state);
23
32
  }
24
33
  }
@@ -73,7 +73,7 @@ export interface RepoGroup {
73
73
  repo: string;
74
74
  prs: FetchedPR[];
75
75
  }
76
- /** GitHub's pull request review decision (from the reviewDecision GraphQL field). */
76
+ /** Pull request review decision, computed from the PR's reviews by `determineReviewDecision`. */
77
77
  export type ReviewDecision = 'approved' | 'changes_requested' | 'review_required' | 'unknown';
78
78
  /** Input options for `determineStatus()` (see status-determination.ts). */
79
79
  export interface DetermineStatusInput {