@oss-autopilot/core 3.43.0 → 3.44.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 (100) hide show
  1. package/dist/cli-registry.js +160 -6
  2. package/dist/cli.bundle.cjs +207 -180
  3. package/dist/commands/check-integration.js +4 -1
  4. package/dist/commands/cleanup.d.ts +6 -2
  5. package/dist/commands/cleanup.js +72 -7
  6. package/dist/commands/comments.d.ts +8 -1
  7. package/dist/commands/comments.js +11 -3
  8. package/dist/commands/config.d.ts +2 -0
  9. package/dist/commands/config.js +26 -1
  10. package/dist/commands/daily-ledger.d.ts +33 -5
  11. package/dist/commands/daily-ledger.js +36 -13
  12. package/dist/commands/daily-render.d.ts +2 -1
  13. package/dist/commands/daily-render.js +4 -1
  14. package/dist/commands/daily.d.ts +3 -0
  15. package/dist/commands/daily.js +25 -5
  16. package/dist/commands/dashboard-data.js +70 -61
  17. package/dist/commands/dashboard-lifecycle.d.ts +36 -8
  18. package/dist/commands/dashboard-lifecycle.js +131 -38
  19. package/dist/commands/dashboard-process.d.ts +35 -0
  20. package/dist/commands/dashboard-process.js +65 -5
  21. package/dist/commands/dismiss.js +7 -6
  22. package/dist/commands/doctor.js +1 -8
  23. package/dist/commands/fork-prune.d.ts +58 -0
  24. package/dist/commands/fork-prune.js +247 -0
  25. package/dist/commands/guidelines.d.ts +46 -1
  26. package/dist/commands/guidelines.js +111 -12
  27. package/dist/commands/index.d.ts +5 -0
  28. package/dist/commands/index.js +5 -0
  29. package/dist/commands/overnight-push-prep.d.ts +2 -1
  30. package/dist/commands/overnight-push-prep.js +3 -3
  31. package/dist/commands/policy.d.ts +5 -1
  32. package/dist/commands/policy.js +14 -1
  33. package/dist/commands/pr-create.d.ts +48 -0
  34. package/dist/commands/pr-create.js +200 -0
  35. package/dist/commands/pr-preflight.d.ts +28 -2
  36. package/dist/commands/pr-preflight.js +63 -9
  37. package/dist/commands/setup.js +120 -36
  38. package/dist/commands/startup.d.ts +7 -0
  39. package/dist/commands/startup.js +17 -0
  40. package/dist/commands/status.js +5 -0
  41. package/dist/commands/validation.d.ts +5 -0
  42. package/dist/commands/validation.js +5 -0
  43. package/dist/commands/vet-list.js +2 -2
  44. package/dist/commands/vet.d.ts +8 -0
  45. package/dist/commands/vet.js +15 -1
  46. package/dist/commands/work.d.ts +4 -0
  47. package/dist/commands/work.js +34 -11
  48. package/dist/core/commit-date.d.ts +31 -5
  49. package/dist/core/commit-date.js +36 -8
  50. package/dist/core/compliance-score.d.ts +3 -0
  51. package/dist/core/compliance-score.js +13 -9
  52. package/dist/core/config-registry.d.ts +27 -2
  53. package/dist/core/config-registry.js +83 -2
  54. package/dist/core/daily-logic.d.ts +4 -1
  55. package/dist/core/daily-logic.js +13 -2
  56. package/dist/core/fork-prune.d.ts +149 -0
  57. package/dist/core/fork-prune.js +333 -0
  58. package/dist/core/gist-state-store.js +4 -8
  59. package/dist/core/github-stats.d.ts +7 -1
  60. package/dist/core/github-stats.js +15 -15
  61. package/dist/core/index.d.ts +1 -1
  62. package/dist/core/index.js +1 -1
  63. package/dist/core/local-config.js +2 -3
  64. package/dist/core/pacing.d.ts +41 -0
  65. package/dist/core/pacing.js +115 -0
  66. package/dist/core/pr-assembly.d.ts +2 -0
  67. package/dist/core/pr-graphql.d.ts +16 -1
  68. package/dist/core/pr-graphql.js +15 -3
  69. package/dist/core/pr-monitor.d.ts +6 -0
  70. package/dist/core/pr-monitor.js +46 -10
  71. package/dist/core/pr-preflight.d.ts +41 -0
  72. package/dist/core/pr-preflight.js +406 -17
  73. package/dist/core/prose-script.d.ts +72 -0
  74. package/dist/core/prose-script.js +223 -0
  75. package/dist/core/repo-policy.d.ts +8 -2
  76. package/dist/core/repo-policy.js +34 -6
  77. package/dist/core/repo-score-manager.d.ts +18 -0
  78. package/dist/core/repo-score-manager.js +29 -0
  79. package/dist/core/review-analysis.d.ts +15 -2
  80. package/dist/core/review-analysis.js +22 -5
  81. package/dist/core/stale-data.d.ts +44 -7
  82. package/dist/core/stale-data.js +46 -8
  83. package/dist/core/state-persistence.js +2 -4
  84. package/dist/core/state-schema.d.ts +39 -0
  85. package/dist/core/state-schema.js +68 -1
  86. package/dist/core/state.d.ts +21 -0
  87. package/dist/core/state.js +47 -0
  88. package/dist/core/status-determination.js +10 -8
  89. package/dist/core/untrusted-content.d.ts +3 -3
  90. package/dist/core/untrusted-content.js +26 -8
  91. package/dist/core/urls.d.ts +24 -0
  92. package/dist/core/urls.js +76 -0
  93. package/dist/dashboard/assets/chart-panel-B-nLVgzQ.js +3 -0
  94. package/dist/dashboard/assets/index-5IvMGokL.js +55 -0
  95. package/dist/dashboard/index.html +1 -1
  96. package/dist/formatters/json.d.ts +171 -5
  97. package/dist/formatters/json.js +79 -0
  98. package/package.json +6 -6
  99. package/dist/dashboard/assets/chart-panel-C_C1lFTI.js +0 -3
  100. package/dist/dashboard/assets/index-B--H66Jk.js +0 -55
@@ -5,7 +5,8 @@
5
5
  import * as path from 'node:path';
6
6
  import { execFileSync } from 'node:child_process';
7
7
  import { debug } from '../core/index.js';
8
- import { errorMessage } from '../core/errors.js';
8
+ import { ValidationError, errorMessage } from '../core/errors.js';
9
+ import { BRANCH_NAME_PATTERN } from './validation.js';
9
10
  /** File extensions we consider "code" that should be imported/referenced */
10
11
  const CODE_EXTENSIONS = new Set([
11
12
  '.ts',
@@ -68,6 +69,8 @@ function suggestEntryPoints(newFile, existingFiles) {
68
69
  // eslint-disable-next-line @typescript-eslint/require-await -- async keeps the Promise-returning contract callers rely on; the body has no await yet
69
70
  export async function runCheckIntegration(options) {
70
71
  const base = options.base;
72
+ if (!BRANCH_NAME_PATTERN.test(base))
73
+ throw new ValidationError(`Invalid base branch name: ${base}`);
71
74
  // Get new files added in this branch vs base
72
75
  let newFiles;
73
76
  try {
@@ -9,7 +9,10 @@
9
9
  *
10
10
  * 1. it is a direct child of `worktrees/`, a real directory (not a symlink)
11
11
  * with a name the preparer creates, and it resolves inside the data dir;
12
- * 2. it is the root of a linked Git worktree (`.git` is a file);
12
+ * 2. it is the root of a linked Git worktree (`.git` is a file), its own
13
+ * config names no clean or process filter, no config names a promisor
14
+ * remote, and it holds no submodule, so the checks below neither run a
15
+ * filter the worktree chose nor fetch (#2047);
13
16
  * 3. `git status --porcelain --untracked-files=all` is empty: no modified and
14
17
  * no untracked files, whatever `status.showUntrackedFiles` says;
15
18
  * 4. HEAD is contained in a remote-tracking ref, so no commit lives only here;
@@ -36,7 +39,8 @@
36
39
  * recreates it on demand.
37
40
  * - `doctor` reports counts only, not sizes or ages; the detail is here.
38
41
  */
39
- export declare const WORKTREE_MIN_AGE_DAYS = 14;
42
+ import { WORKTREE_MIN_AGE_DAYS } from '../core/stale-data.js';
43
+ export { WORKTREE_MIN_AGE_DAYS };
40
44
  /** Ignored paths under a directory with one of these names are rebuildable, not work. */
41
45
  export declare const BUILD_OUTPUT: Set<string>;
42
46
  export type WorktreeAction = 'removed' | 'would-remove' | 'kept';
@@ -9,7 +9,10 @@
9
9
  *
10
10
  * 1. it is a direct child of `worktrees/`, a real directory (not a symlink)
11
11
  * with a name the preparer creates, and it resolves inside the data dir;
12
- * 2. it is the root of a linked Git worktree (`.git` is a file);
12
+ * 2. it is the root of a linked Git worktree (`.git` is a file), its own
13
+ * config names no clean or process filter, no config names a promisor
14
+ * remote, and it holds no submodule, so the checks below neither run a
15
+ * filter the worktree chose nor fetch (#2047);
13
16
  * 3. `git status --porcelain --untracked-files=all` is empty: no modified and
14
17
  * no untracked files, whatever `status.showUntrackedFiles` says;
15
18
  * 4. HEAD is contained in a remote-tracking ref, so no commit lives only here;
@@ -40,9 +43,9 @@ import * as fs from 'node:fs';
40
43
  import path from 'node:path';
41
44
  import { assertAttended, errorMessage } from '../core/errors.js';
42
45
  import { resolveDataDir } from '../core/paths.js';
43
- import { DAY_MS, WORKTREE_NAME, isInside, pruneRejectedCopies, staleRejectedCopies } from '../core/stale-data.js';
44
- import { git } from './overnight-push-prep.js';
45
- export const WORKTREE_MIN_AGE_DAYS = 14;
46
+ import { DAY_MS, WORKTREE_MIN_AGE_DAYS, WORKTREE_NAME, isInside, pruneRejectedCopies, staleRejectedCopies, } from '../core/stale-data.js';
47
+ import { GIT_TIMEOUT_MS, git } from './overnight-push-prep.js';
48
+ export { WORKTREE_MIN_AGE_DAYS };
46
49
  /** Ignored paths under a directory with one of these names are rebuildable, not work. */
47
50
  export const BUILD_OUTPUT = new Set(['node_modules', 'dist', 'build', 'target', 'coverage', '.venv']);
48
51
  // Every call, the removal included: no index lock for a read, no
@@ -50,6 +53,9 @@ export const BUILD_OUTPUT = new Set(['node_modules', 'dist', 'build', 'target',
50
53
  // always count (`worktree remove` runs its own status and would otherwise
51
54
  // honour `status.showUntrackedFiles=no` and delete them).
52
55
  const SAFE_GIT = ['--no-optional-locks', '-c', 'core.fsmonitor=false', '-c', 'status.showUntrackedFiles=all'];
56
+ // The environment form of `--no-lazy-fetch`, which Git before 2.44 rejects as
57
+ // an unknown option; older Git ignores the variable.
58
+ const NO_LAZY_FETCH = { GIT_NO_LAZY_FETCH: '1' };
53
59
  const IN_PROGRESS = [
54
60
  'rebase-merge',
55
61
  'rebase-apply',
@@ -64,7 +70,7 @@ const REMOVE_TIMEOUT_MS = 10 * 60_000;
64
70
  const MAX_NAMED_PATHS = 3;
65
71
  const COMMIT_MESSAGE_SUFFIX = '.commit-msg.txt';
66
72
  function gitOut(worktree, args) {
67
- return git(worktree, [...SAFE_GIT, ...args]).trim();
73
+ return git(worktree, [...SAFE_GIT, ...args], GIT_TIMEOUT_MS, NO_LAZY_FETCH).trim();
68
74
  }
69
75
  function gitDirOf(dir) {
70
76
  return gitOut(dir, ['rev-parse', '--absolute-git-dir']);
@@ -86,7 +92,66 @@ function refusal(dataDir, dir) {
86
92
  const toplevel = gitOut(dir, ['rev-parse', '--show-toplevel']);
87
93
  if (fs.realpathSync(toplevel) !== fs.realpathSync(dir))
88
94
  return 'not the root of its git worktree';
89
- return null;
95
+ return programsInRepoConfig(dir) ?? lazyFetch(dir) ?? submodules(dir);
96
+ }
97
+ /** `[scope, key]` for every config key matching `pattern`, includes followed. Reads no objects. */
98
+ function configKeys(dir, pattern) {
99
+ let entries;
100
+ try {
101
+ entries = gitOut(dir, ['config', '--show-scope', '--name-only', '-z', '--get-regexp', pattern]).split('\0');
102
+ }
103
+ catch (err) {
104
+ // Exit 1: no key matched.
105
+ if (err?.status === 1)
106
+ return [];
107
+ throw err;
108
+ }
109
+ const keys = [];
110
+ for (let i = 0; i + 1 < entries.length; i += 2)
111
+ keys.push([entries[i], entries[i + 1]]);
112
+ return keys;
113
+ }
114
+ const FILTER_PROGRAM = String.raw `^(filter\..+\.(clean|process)|lfs\.extension\..+\.(clean|smudge))$`;
115
+ /**
116
+ * A clean or process filter defined in the repository's own config (#2047).
117
+ * `status`, and the one `worktree remove` runs, re-hash a file whose stat data
118
+ * changed through its filter, so a tick that wrote `filter.<x>.clean` and a
119
+ * matching `info/attributes` line would run its program here while the
120
+ * worktree still reports clean. Only the local and worktree scopes count
121
+ * (includes they pull in report as local): a driver from the user's own global
122
+ * or system config, such as Git LFS, is theirs; an `lfs.extension` program in
123
+ * the repository's config, which that driver may run, is not.
124
+ */
125
+ function programsInRepoConfig(dir) {
126
+ const keys = configKeys(dir, FILTER_PROGRAM)
127
+ .filter(([scope]) => scope === 'local' || scope === 'worktree')
128
+ .map(([, key]) => key);
129
+ return keys.length > 0 ? `repository config names a filter program git would run: ${keys.join(', ')}` : null;
130
+ }
131
+ const LAZY_FETCH = String.raw `^(extensions\.partialclone|remote\..+\.(promisor|partialclonefilter))$`;
132
+ /**
133
+ * A promisor remote (#2047): `extensions.partialClone`,
134
+ * `remote.<name>.promisor` or `remote.<name>.partialCloneFilter`, each of
135
+ * which makes one on its own. Any command that finds an object missing (a
136
+ * dangling remote-tracking ref for `for-each-ref --contains`, a reflog entry,
137
+ * the HEAD tree for `status`) fetches it from that remote, which runs the
138
+ * remote's `uploadpack`, `core.sshCommand` or credential helper: programs the
139
+ * repository's config chooses. Every scope counts, since the promisor flag
140
+ * can sit in the user's config while the program comes from the repository's.
141
+ * `GIT_NO_LAZY_FETCH` on every call is a second layer, not relied on.
142
+ */
143
+ function lazyFetch(dir) {
144
+ const keys = configKeys(dir, LAZY_FETCH).map(([, key]) => key);
145
+ return keys.length > 0 ? `config names a promisor remote git would fetch from: ${keys.join(', ')}` : null;
146
+ }
147
+ /**
148
+ * `status` runs inside each submodule, under that submodule's own config,
149
+ * which the check above does not read. `worktree remove` refuses a worktree
150
+ * with submodules anyway, so refusing first loses nothing.
151
+ */
152
+ function submodules(dir) {
153
+ const hasGitlink = /^160000 /m.test(gitOut(dir, ['ls-files', '--stage']));
154
+ return hasGitlink ? 'contains submodules (git would run status under their config)' : null;
90
155
  }
91
156
  /** Whole days since the directory itself or the worktree's index last changed. */
92
157
  function idleDays(dir, now) {
@@ -180,7 +245,7 @@ function removalFailure(err) {
180
245
  /** Judged removable and then not removed: an error, not a keep. */
181
246
  function remove(report) {
182
247
  try {
183
- git(report.path, [...SAFE_GIT, 'worktree', 'remove', report.path], REMOVE_TIMEOUT_MS);
248
+ git(report.path, [...SAFE_GIT, 'worktree', 'remove', report.path], REMOVE_TIMEOUT_MS, NO_LAZY_FETCH);
184
249
  }
185
250
  catch (err) {
186
251
  const reason = removalFailure(err);
@@ -7,26 +7,33 @@ export { type CommentsOutput, type PostOutput, type ClaimOutput } from '../forma
7
7
  interface CommentsOptions {
8
8
  prUrl: string;
9
9
  showBots?: boolean;
10
+ /** Keep the user's own comments and reviews, and reviews with no body, for flows that read the whole thread (#2046). */
11
+ includeOwn?: boolean;
10
12
  }
11
13
  interface PostOptions {
12
14
  url: string;
13
15
  message: string;
14
16
  /** When set, refuse unless `message` hashes to it: the text the user approved via `draft show` (#1930). */
15
17
  expectSha256?: string;
18
+ /** CLI `--allow-script-mismatch` only: post despite a script mismatch, reported as a warning (#1909). */
19
+ allowScriptMismatch?: boolean;
16
20
  }
17
21
  interface ClaimOptions {
18
22
  issueUrl: string;
19
23
  message?: string;
20
24
  /** When set, refuse unless the claim message hashes to it (#1930). */
21
25
  expectSha256?: string;
26
+ /** CLI `--allow-script-mismatch` only: claim despite a script mismatch, reported as a warning (#1909). */
27
+ allowScriptMismatch?: boolean;
22
28
  }
23
29
  /**
24
30
  * Fetch all comments, reviews, and inline review comments for a PR.
25
- * Filters out the user's own comments and optionally bot comments.
31
+ * Filters out the user's own comments (unless `includeOwn`) and optionally bot comments.
26
32
  *
27
33
  * @param options - Comment fetch options
28
34
  * @param options.prUrl - Full GitHub PR URL
29
35
  * @param options.showBots - Include bot comments (default: false)
36
+ * @param options.includeOwn - Include the user's own comments and reviews, and verdict-only reviews (default: false)
30
37
  * @returns Categorized comments with review, inline, and discussion sections
31
38
  * @throws {ValidationError} If the URL is not a valid GitHub PR URL
32
39
  */
@@ -6,6 +6,7 @@ import { getStateManager, getOctokit, parseGitHubUrl, requireGitHubToken, maybeC
6
6
  import { wrapUntrustedContent } from '../core/untrusted-content.js';
7
7
  import { ValidationError, assertAttended, isRateLimitOrAuthError } from '../core/errors.js';
8
8
  import { warn } from '../core/logger.js';
9
+ import { checkRepoScript } from '../core/prose-script.js';
9
10
  const MODULE = 'comments';
10
11
  import { paginateAllDetailed } from '../core/pagination.js';
11
12
  import { buildStalenessWarning } from '../formatters/json.js';
@@ -13,11 +14,12 @@ import { validateUrl, validateMessage, validateGitHubUrl, PR_URL_PATTERN, ISSUE_
13
14
  import { assertSha256 } from './draft.js';
14
15
  /**
15
16
  * Fetch all comments, reviews, and inline review comments for a PR.
16
- * Filters out the user's own comments and optionally bot comments.
17
+ * Filters out the user's own comments (unless `includeOwn`) and optionally bot comments.
17
18
  *
18
19
  * @param options - Comment fetch options
19
20
  * @param options.prUrl - Full GitHub PR URL
20
21
  * @param options.showBots - Include bot comments (default: false)
22
+ * @param options.includeOwn - Include the user's own comments and reviews, and verdict-only reviews (default: false)
21
23
  * @returns Categorized comments with review, inline, and discussion sections
22
24
  * @throws {ValidationError} If the URL is not a valid GitHub PR URL
23
25
  */
@@ -80,7 +82,7 @@ export async function runComments(options) {
80
82
  // non-canonical-case configured username must not leak the user's own
81
83
  // comments into "needs response" (#1456). Mirrors review-analysis.ts
82
84
  // and issue-conversation.ts.
83
- if (c.user.login?.toLowerCase() === username?.toLowerCase())
85
+ if (!options.includeOwn && c.user.login?.toLowerCase() === username?.toLowerCase())
84
86
  return false;
85
87
  if (c.user.type === 'Bot' && !options.showBots)
86
88
  return false;
@@ -93,7 +95,9 @@ export async function runComments(options) {
93
95
  .filter(filterComment)
94
96
  .sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
95
97
  const relevantReviews = reviews
96
- .filter((r) => filterComment(r) && r.body && r.body.trim())
98
+ // A verdict-only review (bare APPROVE / REQUEST_CHANGES) has no body: kept
99
+ // with includeOwn, for flows that read the user's earlier verdict (#2046).
100
+ .filter((r) => filterComment(r) && (options.includeOwn || r.body?.trim()))
97
101
  .sort((a, b) => new Date(b.submitted_at || 0).getTime() - new Date(a.submitted_at || 0).getTime());
98
102
  // Fence every third-party body at this boundary: the output feeds agents
99
103
  // directly (CLI --json, the MCP `comments` tool, and the `respond-to-pr`
@@ -174,6 +178,7 @@ export async function runPost(options) {
174
178
  }
175
179
  const { owner, repo, number } = parsed;
176
180
  const octokit = getOctokit(token);
181
+ const scriptMismatchWarning = await checkRepoScript(octokit, { owner, repo }, options.message, options.allowScriptMismatch === true);
177
182
  const { data: comment } = await octokit.issues.createComment({
178
183
  owner,
179
184
  repo,
@@ -183,6 +188,7 @@ export async function runPost(options) {
183
188
  return {
184
189
  commentUrl: comment.html_url,
185
190
  url: options.url,
191
+ ...(scriptMismatchWarning && { scriptMismatchWarning }),
186
192
  };
187
193
  }
188
194
  /** The comment `claim` posts when no message is given; the MCP approval form shows this exact text. */
@@ -211,6 +217,7 @@ export async function runClaim(options) {
211
217
  }
212
218
  const { owner, repo, number } = parsed;
213
219
  const octokit = getOctokit(token);
220
+ const scriptMismatchWarning = await checkRepoScript(octokit, { owner, repo }, message, options.allowScriptMismatch === true);
214
221
  // Fetch the real issue title + labels so the tracked entry has useful metadata
215
222
  // rather than a permanent "(claimed)" placeholder that never gets backfilled
216
223
  // (#1056 M24). Best-effort: if the fetch fails, fall back to the placeholder
@@ -281,5 +288,6 @@ export async function runClaim(options) {
281
288
  issueUrl: options.issueUrl,
282
289
  ...(gistSyncWarning && { gistSyncWarning }),
283
290
  ...(stateSaveWarning && { stateSaveWarning }),
291
+ ...(scriptMismatchWarning && { scriptMismatchWarning }),
284
292
  };
285
293
  }
@@ -13,6 +13,8 @@ export interface ConfigSetOutput {
13
13
  success: true;
14
14
  key: string;
15
15
  value: string;
16
+ /** Setup's warnings for a setup-scoped key, e.g. list entries it skipped. */
17
+ warnings?: string[];
16
18
  /** Set when the post-mutation Gist checkpoint failed; the local mutation succeeded (#1440). */
17
19
  gistSyncWarning?: string;
18
20
  }
@@ -2,10 +2,11 @@
2
2
  * Config command
3
3
  * Shows or updates configuration
4
4
  */
5
- import { CONFIG_KEY_REGISTRY, formatUnknownKeyError, getStateManager, maybeCheckpoint, } from '../core/index.js';
5
+ import { CONFIG_KEY_REGISTRY, formatUnknownKeyError, getKeyDef, getStateManager, maybeCheckpoint, } from '../core/index.js';
6
6
  import { ValidationError } from '../core/errors.js';
7
7
  import { MACHINE_PATH_KEYS, getMachinePath, getMachinePathSource, getMachineScanPaths, setMachinePath, } from '../core/local-config.js';
8
8
  import { ISSUE_SCOPES, DIFF_TOOLS } from '../core/types.js';
9
+ import { runSetup } from './setup.js';
9
10
  import { validateGitHubUsername } from './validation.js';
10
11
  const MODULE = 'config';
11
12
  function validateScope(value) {
@@ -74,6 +75,11 @@ export async function runConfig(options) {
74
75
  throw new Error('Value required');
75
76
  }
76
77
  const { key, value } = options;
78
+ // `config --list-keys` and the MCP tool's key enum advertise setup-scoped
79
+ // keys too, so apply them through setup's validators (#1887, #1913).
80
+ if (getKeyDef(key)?.settableVia === 'setup') {
81
+ return runSetupKey(key, value);
82
+ }
77
83
  const apply = () => applyConfigKey(stateManager, key, value);
78
84
  apply();
79
85
  // Push the config mutation to the Gist in gist mode (no-op locally).
@@ -82,6 +88,25 @@ export async function runConfig(options) {
82
88
  const gistSyncWarning = await maybeCheckpoint(stateManager, MODULE, apply);
83
89
  return { success: true, key, value, ...(gistSyncWarning && { gistSyncWarning }) };
84
90
  }
91
+ /**
92
+ * Set a setup-scoped key via `setup --set key=value`. Setup skips some
93
+ * values without storing anything (e.g. `complete` with anything but
94
+ * `true`); that is an error here, never a success (#1887).
95
+ */
96
+ async function runSetupKey(key, value) {
97
+ const result = await runSetup({ set: [`${key}=${value}`] });
98
+ if (!('settings' in result) || result.settings[key] === undefined) {
99
+ const hint = getKeyDef(key)?.valueHint;
100
+ throw new ValidationError(`${key} was not changed: "${value}" is not a value it accepts (expected ${hint}).`);
101
+ }
102
+ return {
103
+ success: true,
104
+ key,
105
+ value: result.settings[key],
106
+ ...(result.warnings && { warnings: result.warnings }),
107
+ ...(result.gistSyncWarning && { gistSyncWarning: result.gistSyncWarning }),
108
+ };
109
+ }
85
110
  /**
86
111
  * Apply one config key. Reads the current config fresh so the Gist conflict
87
112
  * path can re-run it on a refreshed baseline without stale array merges.
@@ -45,6 +45,14 @@ export declare function syncLedgersWithGitHub(stateManager: LedgerStateManager,
45
45
  * transferred repositories keep their rows.
46
46
  */
47
47
  export declare function applyRepoMetadata(stateManager: Pick<StateManagerLike, 'updateRepoScore' | 'evictExcludedRepos'>, repoMetadata: ReadonlyMap<string, RepoMetadata>, warnings: DailyWarning[]): void;
48
+ /**
49
+ * Drop what is stored about repositories whose PRs are never tracked (#1924):
50
+ * those in `config.untrackedOrgs`, and `privateRepos`. The daily run learns
51
+ * which repositories are private from its metadata read (applyRepoMetadata);
52
+ * the dashboard refresh has no such read and passes none, so it removes only
53
+ * the untracked organisations' rows.
54
+ */
55
+ export declare function evictNeverTrackedRepos(stateManager: Pick<StateManagerLike, 'evictExcludedRepos'>, privateRepos: readonly string[]): void;
48
56
  /**
49
57
  * Zero `closedWithoutMergeCount` for repos the closed-PR count search no
50
58
  * longer returns, mirroring the stale reset daily does for merged counts.
@@ -62,11 +70,27 @@ export declare function resetStaleClosedCounts(stateManager: Pick<StateManagerLi
62
70
  export type MergedLedgerGap = PRsSinceResult<StoredMergedPR> | undefined;
63
71
  /** This run's closed-ledger gap fetch; undefined when the fetch failed. */
64
72
  export type ClosedLedgerGap = PRsSinceResult<StoredClosedPR> | undefined;
73
+ /** How a gap fetch treats a failure. */
74
+ export interface LedgerGapOptions {
75
+ /**
76
+ * Errors to rethrow instead of recording. The dashboard refresh passes
77
+ * isRateLimitOrAuthError, since those abort the whole refresh there; the
78
+ * daily run records every failure and carries on.
79
+ */
80
+ rethrowIf?: (error: unknown) => boolean;
81
+ }
65
82
  /**
66
83
  * Fetch every merged PR since the ledger's newest entry (#1924). The recent
67
84
  * list daily shows covers seven days, so after a longer pause it alone left
68
85
  * the merges in between out of the ledger for good. Must run before anything
69
- * in this run adds to the merged ledger: the watermark is read here.
86
+ * in this run adds to the merged ledger: the watermark is read here. Shared
87
+ * by the daily run and the dashboard refresh, so both follow one rule.
88
+ *
89
+ * A ledger left short of `allTimeCount` (seeded ahead of its history, #1504)
90
+ * is fetched from the start while it is under the backfill ceiling (see
91
+ * gapFetchWatermark), the same rule as the closed ledger. Past the ceiling,
92
+ * or with an unknown count, the gap fetch starts at the watermark and
93
+ * storeMergedLedger points at `ledger-backfill`.
70
94
  *
71
95
  * A failed or truncated fetch is recorded in `warnings`, and
72
96
  * {@link storeMergedLedger} then stores nothing, so the next run asks for the
@@ -74,7 +98,7 @@ export type ClosedLedgerGap = PRsSinceResult<StoredClosedPR> | undefined;
74
98
  * ledger, so the "extract learnings" nudge, which counts ledger rows of
75
99
  * recent merges, is also held back for them.
76
100
  */
77
- export declare function fetchMergedLedgerGap(octokit: Octokit, stateManager: Pick<StateManagerLike, 'getState' | 'getMergedPRWatermark'>, warnings: DailyWarning[]): Promise<MergedLedgerGap>;
101
+ export declare function fetchMergedLedgerGap(octokit: Octokit, stateManager: Pick<StateManagerLike, 'getState' | 'getMergedPRWatermark' | 'getMergedPRs'>, warnings: DailyWarning[], allTimeCount: number | undefined, options?: LedgerGapOptions): Promise<MergedLedgerGap>;
78
102
  /**
79
103
  * The closed-ledger mirror of {@link fetchMergedLedgerGap} (#1925). Without
80
104
  * it the recent closed list seeded a fresh ledger with last week's closes,
@@ -86,7 +110,7 @@ export declare function fetchMergedLedgerGap(octokit: Octokit, stateManager: Pic
86
110
  * from the start while it is under the backfill ceiling (see
87
111
  * gapFetchWatermark), so it heals without a manual `ledger-backfill`.
88
112
  */
89
- export declare function fetchClosedLedgerGap(octokit: Octokit, stateManager: Pick<StateManagerLike, 'getState' | 'getClosedPRWatermark' | 'getClosedPRs'>, warnings: DailyWarning[], allTimeCount: number | undefined): Promise<ClosedLedgerGap>;
113
+ export declare function fetchClosedLedgerGap(octokit: Octokit, stateManager: Pick<StateManagerLike, 'getState' | 'getClosedPRWatermark' | 'getClosedPRs'>, warnings: DailyWarning[], allTimeCount: number | undefined, options?: LedgerGapOptions): Promise<ClosedLedgerGap>;
90
114
  /** What a store step takes besides the gap. */
91
115
  interface StoreLedgerInput {
92
116
  /** Previous run's digest: best-effort first-response and review state for the new rows (#1461). */
@@ -105,18 +129,22 @@ interface StoreLedgerInput {
105
129
  *
106
130
  * Then compares the ledger with GitHub's all-time merged count (see
107
131
  * checkLedgerCount).
132
+ *
133
+ * @returns how many rows addMergedPRs dropped for an invalid URL (0 when nothing was stored)
108
134
  */
109
135
  export declare function storeMergedLedger(stateManager: Pick<StateManagerLike, 'addMergedPRs' | 'getMergedPRs'>, input: StoreLedgerInput & {
110
136
  gap: MergedLedgerGap;
111
137
  recentlyMergedPRs: ReadonlyArray<MergedPR>;
112
- }): void;
138
+ }): number;
113
139
  /**
114
140
  * The closed-ledger mirror of {@link storeMergedLedger} (#1925): the gap
115
141
  * plus the recent closed list, stored only when the gap was fetched whole,
116
142
  * then checked against GitHub's all-time closed-without-merge count.
143
+ *
144
+ * @returns how many rows addClosedPRs dropped for an invalid URL (0 when nothing was stored)
117
145
  */
118
146
  export declare function storeClosedLedger(stateManager: Pick<StateManagerLike, 'addClosedPRs' | 'getClosedPRs'>, input: StoreLedgerInput & {
119
147
  gap: ClosedLedgerGap;
120
148
  recentlyClosedPRs: ReadonlyArray<ClosedPR>;
121
- }): void;
149
+ }): number;
122
150
  export {};
@@ -69,6 +69,16 @@ export function applyRepoMetadata(stateManager, repoMetadata, warnings) {
69
69
  });
70
70
  warn(MODULE, `[METADATA_UPDATES_FAILED] ${failures} of ${repoMetadata.size} metadata update(s) failed.`);
71
71
  }
72
+ evictNeverTrackedRepos(stateManager, privateRepos);
73
+ }
74
+ /**
75
+ * Drop what is stored about repositories whose PRs are never tracked (#1924):
76
+ * those in `config.untrackedOrgs`, and `privateRepos`. The daily run learns
77
+ * which repositories are private from its metadata read (applyRepoMetadata);
78
+ * the dashboard refresh has no such read and passes none, so it removes only
79
+ * the untracked organisations' rows.
80
+ */
81
+ export function evictNeverTrackedRepos(stateManager, privateRepos) {
72
82
  const evicted = stateManager.evictExcludedRepos(privateRepos);
73
83
  if (evicted.untrackedOrgRows + evicted.privateRows + evicted.repos > 0) {
74
84
  warn(MODULE, `Removed PRs that are never tracked: ${evicted.untrackedOrgRows} ledger row(s) in untracked organisations, ` +
@@ -103,13 +113,15 @@ export function resetStaleClosedCounts(stateManager, closedCounts, wasSearchTrun
103
113
  }
104
114
  }
105
115
  /** Run one gap fetch, recording a failure or truncation in `warnings`. */
106
- async function fetchLedgerGap(kind, fetch, truncatedMessage, warnings) {
116
+ async function fetchLedgerGap(kind, fetch, truncatedMessage, warnings, options) {
107
117
  const operation = `fetch ${kind} PRs for the ledger`;
108
118
  let gap;
109
119
  try {
110
120
  gap = await fetch();
111
121
  }
112
122
  catch (error) {
123
+ if (options.rethrowIf?.(error))
124
+ throw error;
113
125
  recordWarning(warnings, 'fetch', operation, error);
114
126
  }
115
127
  if (gap?.truncated)
@@ -143,7 +155,14 @@ function checkLedgerCount(kind, stored, allTimeCount, warnings) {
143
155
  * Fetch every merged PR since the ledger's newest entry (#1924). The recent
144
156
  * list daily shows covers seven days, so after a longer pause it alone left
145
157
  * the merges in between out of the ledger for good. Must run before anything
146
- * in this run adds to the merged ledger: the watermark is read here.
158
+ * in this run adds to the merged ledger: the watermark is read here. Shared
159
+ * by the daily run and the dashboard refresh, so both follow one rule.
160
+ *
161
+ * A ledger left short of `allTimeCount` (seeded ahead of its history, #1504)
162
+ * is fetched from the start while it is under the backfill ceiling (see
163
+ * gapFetchWatermark), the same rule as the closed ledger. Past the ceiling,
164
+ * or with an unknown count, the gap fetch starts at the watermark and
165
+ * storeMergedLedger points at `ledger-backfill`.
147
166
  *
148
167
  * A failed or truncated fetch is recorded in `warnings`, and
149
168
  * {@link storeMergedLedger} then stores nothing, so the next run asks for the
@@ -151,10 +170,10 @@ function checkLedgerCount(kind, stored, allTimeCount, warnings) {
151
170
  * ledger, so the "extract learnings" nudge, which counts ledger rows of
152
171
  * recent merges, is also held back for them.
153
172
  */
154
- export function fetchMergedLedgerGap(octokit, stateManager, warnings) {
173
+ export function fetchMergedLedgerGap(octokit, stateManager, warnings, allTimeCount, options = {}) {
155
174
  const { config } = stateManager.getState();
156
- const watermark = stateManager.getMergedPRWatermark();
157
- return fetchLedgerGap('merged', () => fetchMergedPRsSince(octokit, config, watermark), MERGED_LEDGER_TRUNCATED_MESSAGE, warnings);
175
+ const watermark = gapFetchWatermark(stateManager.getMergedPRWatermark(), stateManager.getMergedPRs().length, allTimeCount);
176
+ return fetchLedgerGap('merged', () => fetchMergedPRsSince(octokit, config, watermark), MERGED_LEDGER_TRUNCATED_MESSAGE, warnings, options);
158
177
  }
159
178
  /**
160
179
  * The closed-ledger mirror of {@link fetchMergedLedgerGap} (#1925). Without
@@ -167,10 +186,10 @@ export function fetchMergedLedgerGap(octokit, stateManager, warnings) {
167
186
  * from the start while it is under the backfill ceiling (see
168
187
  * gapFetchWatermark), so it heals without a manual `ledger-backfill`.
169
188
  */
170
- export function fetchClosedLedgerGap(octokit, stateManager, warnings, allTimeCount) {
189
+ export function fetchClosedLedgerGap(octokit, stateManager, warnings, allTimeCount, options = {}) {
171
190
  const { config } = stateManager.getState();
172
191
  const watermark = gapFetchWatermark(stateManager.getClosedPRWatermark(), stateManager.getClosedPRs().length, allTimeCount);
173
- return fetchLedgerGap('closed', () => fetchClosedPRsSince(octokit, config, watermark), CLOSED_LEDGER_TRUNCATED_MESSAGE, warnings);
192
+ return fetchLedgerGap('closed', () => fetchClosedPRsSince(octokit, config, watermark), CLOSED_LEDGER_TRUNCATED_MESSAGE, warnings, options);
174
193
  }
175
194
  /** Fields both ledgers fill the same way from a fetched or recent row. */
176
195
  function ledgerFields(pr, previousDigest) {
@@ -193,33 +212,37 @@ function ledgerFields(pr, previousDigest) {
193
212
  *
194
213
  * Then compares the ledger with GitHub's all-time merged count (see
195
214
  * checkLedgerCount).
215
+ *
216
+ * @returns how many rows addMergedPRs dropped for an invalid URL (0 when nothing was stored)
196
217
  */
197
218
  export function storeMergedLedger(stateManager, input) {
198
219
  const { gap, previousDigest } = input;
199
220
  if (!gap || gap.truncated)
200
- return;
221
+ return 0;
201
222
  const rows = [...input.recentlyMergedPRs, ...gap.prs].map((pr) => ({
202
223
  ...ledgerFields(pr, previousDigest),
203
224
  mergedAt: pr.mergedAt,
204
225
  }));
205
- if (rows.length > 0)
206
- stateManager.addMergedPRs(rows);
226
+ const dropped = rows.length > 0 ? stateManager.addMergedPRs(rows).dropped : 0;
207
227
  checkLedgerCount('merged', stateManager.getMergedPRs().length, input.allTimeCount, input.warnings);
228
+ return dropped;
208
229
  }
209
230
  /**
210
231
  * The closed-ledger mirror of {@link storeMergedLedger} (#1925): the gap
211
232
  * plus the recent closed list, stored only when the gap was fetched whole,
212
233
  * then checked against GitHub's all-time closed-without-merge count.
234
+ *
235
+ * @returns how many rows addClosedPRs dropped for an invalid URL (0 when nothing was stored)
213
236
  */
214
237
  export function storeClosedLedger(stateManager, input) {
215
238
  const { gap, previousDigest } = input;
216
239
  if (!gap || gap.truncated)
217
- return;
240
+ return 0;
218
241
  const rows = [...input.recentlyClosedPRs, ...gap.prs].map((pr) => ({
219
242
  ...ledgerFields(pr, previousDigest),
220
243
  closedAt: pr.closedAt,
221
244
  }));
222
- if (rows.length > 0)
223
- stateManager.addClosedPRs(rows);
245
+ const dropped = rows.length > 0 ? stateManager.addClosedPRs(rows).dropped : 0;
224
246
  checkLedgerCount('closed', stateManager.getClosedPRs().length, input.allTimeCount, input.warnings);
247
+ return dropped;
225
248
  }
@@ -14,6 +14,7 @@
14
14
  * Tests for these renderers live alongside the aggregations test
15
15
  * (daily-logic.test.ts) — pure rendering, easy to assert on string output.
16
16
  */
17
+ import { type PacingStatus } from '../core/pacing.js';
17
18
  import type { CapacityAssessment, CommentedIssue, CommentedIssueWithResponse, DailyDigest, MaintainerActionHint } from '../core/types.js';
18
19
  import type { AttentionSummary } from '../core/pr-attention.js';
19
20
  /**
@@ -31,7 +32,7 @@ export declare function formatBriefSummary(digest: DailyDigest, issueCount: numb
31
32
  * Used in JSON output for Claude to display verbatim — includes all PR sections,
32
33
  * issue replies, and capacity status.
33
34
  */
34
- export declare function formatSummary(digest: DailyDigest, capacity: CapacityAssessment, issueResponses?: CommentedIssueWithResponse[]): string;
35
+ export declare function formatSummary(digest: DailyDigest, capacity: CapacityAssessment, issueResponses?: CommentedIssueWithResponse[], pacing?: PacingStatus | null): string;
35
36
  /**
36
37
  * Print digest to console as plain text. Unified renderer: uses the same
37
38
  * section ordering as {@link formatSummary} but outputs plain text with
@@ -15,6 +15,7 @@
15
15
  * (daily-logic.test.ts) — pure rendering, easy to assert on string output.
16
16
  */
17
17
  import { formatRelativeTime } from '../core/dates.js';
18
+ import { pacingLines } from '../core/pacing.js';
18
19
  /**
19
20
  * Format a maintainer action hint as a human-readable label.
20
21
  */
@@ -58,7 +59,7 @@ export function formatBriefSummary(digest, issueCount, issueResponseCount = 0, a
58
59
  * Used in JSON output for Claude to display verbatim — includes all PR sections,
59
60
  * issue replies, and capacity status.
60
61
  */
61
- export function formatSummary(digest, capacity, issueResponses = []) {
62
+ export function formatSummary(digest, capacity, issueResponses = [], pacing = null) {
62
63
  const lines = [];
63
64
  lines.push('## OSS Dashboard', '', `\u{1F4CA} **${digest.summary.totalActivePRs} Active PRs** | ${digest.summary.totalMergedAllTime} Merged | ${digest.summary.mergeRate}% Merge Rate`, '✓ Dashboard generated — say "open dashboard" to view in browser', '');
64
65
  if (digest.needsAddressingPRs.length > 0) {
@@ -121,6 +122,8 @@ export function formatSummary(digest, capacity, issueResponses = []) {
121
122
  ? `${capacity.activePRCount}/${capacity.maxActivePRs} PRs`
122
123
  : `${capacity.activePRCount} PRs, no limit`;
123
124
  lines.push(`**Capacity:** ${capacityIcon} ${capacityLabel} (${countLabel}${shelvedNote})`);
125
+ for (const line of pacingLines(pacing))
126
+ lines.push(`**Pacing:** ${line}`);
124
127
  return lines.join('\n');
125
128
  }
126
129
  /**
@@ -9,6 +9,7 @@
9
9
  import { type WorkClaim, type ClosedPRStatusUpdate, type MergedPRNotes, type ReviewedPRFollowUp, type AttentionSummary, type DailyDigest, type CommentedIssue, type PRCheckFailure, type RepoGroup } from '../core/index.js';
10
10
  import { type StrategyResult } from '../core/strategy.js';
11
11
  import { type DailyOutput, type DailyWarning, type CapacityAssessment, type ActionableIssue, type ActionMenu, type MergedPRListUpdate, type PendingLearnings } from '../formatters/json.js';
12
+ import { type PacingStatus } from '../core/pacing.js';
12
13
  export { applyStatusOverrides, computeRepoSignals, groupPRsByRepo, assessCapacity, collectActionableIssues, computeActionMenu, toShelvedPRRef, CRITICAL_STATUSES, } from '../core/index.js';
13
14
  export { formatBriefSummary, formatSummary, printDigest } from './daily-render.js';
14
15
  /**
@@ -74,6 +75,8 @@ export interface DailyCheckResult {
74
75
  * {@link DailyOutput.workClaims}.
75
76
  */
76
77
  workClaims?: WorkClaim[];
78
+ /** Pacing counts (#1911); set only when a pacing cap is set. See {@link DailyOutput.pacing}. */
79
+ pacing?: PacingStatus;
77
80
  }
78
81
  /**
79
82
  * Convert a full DailyCheckResult to the compact DailyOutput for JSON serialization (#287).