@oss-autopilot/core 3.42.5 → 3.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/dist/cli-pre-action.js +8 -3
  2. package/dist/cli-registry.js +272 -25
  3. package/dist/cli.bundle.cjs +183 -154
  4. package/dist/commands/check-integration.js +1 -0
  5. package/dist/commands/cleanup.d.ts +76 -0
  6. package/dist/commands/cleanup.js +269 -0
  7. package/dist/commands/comments.d.ts +6 -0
  8. package/dist/commands/comments.js +6 -2
  9. package/dist/commands/config.js +37 -5
  10. package/dist/commands/daily-dismiss-filter.d.ts +7 -0
  11. package/dist/commands/daily-dismiss-filter.js +17 -1
  12. package/dist/commands/daily-ledger.d.ts +122 -0
  13. package/dist/commands/daily-ledger.js +225 -0
  14. package/dist/commands/daily-recent-prs.d.ts +26 -0
  15. package/dist/commands/daily-recent-prs.js +55 -0
  16. package/dist/commands/daily.d.ts +2 -1
  17. package/dist/commands/daily.js +59 -89
  18. package/dist/commands/dashboard-cache.d.ts +2 -0
  19. package/dist/commands/dashboard-cache.js +33 -8
  20. package/dist/commands/dashboard-data.js +71 -36
  21. package/dist/commands/dashboard-gist-sync.js +3 -1
  22. package/dist/commands/dashboard-lifecycle.js +1 -1
  23. package/dist/commands/dashboard-process.d.ts +14 -1
  24. package/dist/commands/dashboard-process.js +46 -7
  25. package/dist/commands/dashboard-server.js +89 -23
  26. package/dist/commands/detect-formatters.js +1 -0
  27. package/dist/commands/dismiss.js +5 -2
  28. package/dist/commands/doctor.d.ts +15 -1
  29. package/dist/commands/doctor.js +73 -5
  30. package/dist/commands/draft.d.ts +77 -0
  31. package/dist/commands/draft.js +218 -0
  32. package/dist/commands/eval.js +1 -0
  33. package/dist/commands/guidelines.d.ts +23 -1
  34. package/dist/commands/guidelines.js +49 -4
  35. package/dist/commands/index.d.ts +24 -4
  36. package/dist/commands/index.js +15 -3
  37. package/dist/commands/issue-thread.d.ts +46 -0
  38. package/dist/commands/issue-thread.js +123 -0
  39. package/dist/commands/ledger-backfill.d.ts +9 -0
  40. package/dist/commands/ledger-backfill.js +44 -1
  41. package/dist/commands/list-mark-done.d.ts +2 -1
  42. package/dist/commands/list-mark-done.js +3 -1
  43. package/dist/commands/list-move-tier.d.ts +2 -1
  44. package/dist/commands/list-move-tier.js +3 -1
  45. package/dist/commands/local-repos.js +10 -5
  46. package/dist/commands/locate-issue-list.d.ts +40 -17
  47. package/dist/commands/locate-issue-list.js +148 -88
  48. package/dist/commands/move.js +7 -1
  49. package/dist/commands/overnight-handoff.d.ts +17 -7
  50. package/dist/commands/overnight-handoff.js +36 -14
  51. package/dist/commands/overnight-push-prep.d.ts +13 -8
  52. package/dist/commands/overnight-push-prep.js +106 -34
  53. package/dist/commands/overnight-tool-rules.d.ts +54 -0
  54. package/dist/commands/overnight-tool-rules.js +217 -0
  55. package/dist/commands/overnight.d.ts +5 -6
  56. package/dist/commands/overnight.js +61 -140
  57. package/dist/commands/parse-list.js +7 -1
  58. package/dist/commands/policy.d.ts +86 -0
  59. package/dist/commands/policy.js +263 -0
  60. package/dist/commands/pr-preflight.d.ts +43 -0
  61. package/dist/commands/pr-preflight.js +294 -0
  62. package/dist/commands/repo-vet.d.ts +9 -0
  63. package/dist/commands/repo-vet.js +36 -11
  64. package/dist/commands/scout-bridge.js +18 -8
  65. package/dist/commands/search.js +7 -0
  66. package/dist/commands/setup.d.ts +3 -3
  67. package/dist/commands/setup.js +46 -18
  68. package/dist/commands/skip-add.js +10 -1
  69. package/dist/commands/startup.d.ts +5 -3
  70. package/dist/commands/startup.js +65 -49
  71. package/dist/commands/state-cmd.d.ts +2 -0
  72. package/dist/commands/state-cmd.js +5 -1
  73. package/dist/commands/stats.js +1 -0
  74. package/dist/commands/status.js +1 -0
  75. package/dist/commands/strategy.js +1 -0
  76. package/dist/commands/vet-list.d.ts +6 -0
  77. package/dist/commands/vet-list.js +25 -0
  78. package/dist/commands/vet.d.ts +12 -0
  79. package/dist/commands/vet.js +118 -1
  80. package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
  81. package/dist/core/anti-llm-policy.d.ts +3 -0
  82. package/dist/core/anti-llm-policy.js +3 -0
  83. package/dist/core/auth.js +2 -0
  84. package/dist/core/ci-analysis.d.ts +7 -2
  85. package/dist/core/ci-analysis.js +76 -21
  86. package/dist/core/commit-date.d.ts +19 -0
  87. package/dist/core/commit-date.js +17 -0
  88. package/dist/core/config-registry.js +11 -5
  89. package/dist/core/contributing.d.ts +2 -3
  90. package/dist/core/contributing.js +2 -3
  91. package/dist/core/daily-logic.d.ts +27 -5
  92. package/dist/core/daily-logic.js +57 -19
  93. package/dist/core/errors.d.ts +37 -3
  94. package/dist/core/errors.js +54 -5
  95. package/dist/core/gist-health.d.ts +15 -3
  96. package/dist/core/gist-health.js +8 -0
  97. package/dist/core/gist-state-store.d.ts +24 -4
  98. package/dist/core/gist-state-store.js +97 -46
  99. package/dist/core/github-stats.d.ts +104 -16
  100. package/dist/core/github-stats.js +282 -97
  101. package/dist/core/http-cache.d.ts +0 -10
  102. package/dist/core/http-cache.js +0 -19
  103. package/dist/core/index.d.ts +12 -5
  104. package/dist/core/index.js +15 -5
  105. package/dist/core/issue-conversation.d.ts +8 -2
  106. package/dist/core/issue-conversation.js +31 -12
  107. package/dist/core/local-config.d.ts +95 -0
  108. package/dist/core/local-config.js +271 -0
  109. package/dist/core/merged-pr-notes.d.ts +2 -2
  110. package/dist/core/pagination.d.ts +55 -0
  111. package/dist/core/pagination.js +59 -0
  112. package/dist/core/paths.d.ts +7 -0
  113. package/dist/core/paths.js +9 -0
  114. package/dist/core/pr-assembly.js +6 -2
  115. package/dist/core/pr-graphql.d.ts +37 -3
  116. package/dist/core/pr-graphql.js +73 -12
  117. package/dist/core/pr-monitor.d.ts +29 -12
  118. package/dist/core/pr-monitor.js +71 -23
  119. package/dist/core/pr-preflight.d.ts +113 -0
  120. package/dist/core/pr-preflight.js +364 -0
  121. package/dist/core/pr-quality-rubric.d.ts +0 -6
  122. package/dist/core/pr-quality-rubric.js +0 -8
  123. package/dist/core/pr-template.d.ts +2 -0
  124. package/dist/core/pr-template.js +5 -1
  125. package/dist/core/repo-policy.d.ts +105 -0
  126. package/dist/core/repo-policy.js +400 -0
  127. package/dist/core/repo-score-manager.d.ts +48 -0
  128. package/dist/core/repo-score-manager.js +111 -1
  129. package/dist/core/review-analysis.d.ts +34 -19
  130. package/dist/core/review-analysis.js +67 -10
  131. package/dist/core/reviewed-prs-fetch.js +11 -29
  132. package/dist/core/reviewed-prs.js +8 -15
  133. package/dist/core/stale-data.d.ts +41 -0
  134. package/dist/core/stale-data.js +115 -0
  135. package/dist/core/state-persistence.d.ts +62 -27
  136. package/dist/core/state-persistence.js +338 -117
  137. package/dist/core/state-schema.d.ts +113 -210
  138. package/dist/core/state-schema.js +165 -80
  139. package/dist/core/state.d.ts +60 -8
  140. package/dist/core/state.js +192 -46
  141. package/dist/core/status-determination.js +26 -8
  142. package/dist/core/strategy.js +3 -1
  143. package/dist/core/types.d.ts +22 -1
  144. package/dist/core/types.js +1 -0
  145. package/dist/core/untrusted-content.d.ts +30 -11
  146. package/dist/core/untrusted-content.js +77 -42
  147. package/dist/core/urls.d.ts +9 -0
  148. package/dist/core/urls.js +18 -0
  149. package/dist/dashboard/assets/{chart-panel-DPKNBUts.js → chart-panel-C_C1lFTI.js} +1 -1
  150. package/dist/dashboard/assets/{index-B25bZOYX.js → index-B--H66Jk.js} +1 -1
  151. package/dist/dashboard/index.html +1 -1
  152. package/dist/formatters/json.d.ts +262 -6
  153. package/dist/formatters/json.js +77 -1
  154. package/package.json +1 -1
  155. package/dist/core/ci-enforced-tools.d.ts +0 -35
  156. package/dist/core/ci-enforced-tools.js +0 -109
  157. package/dist/core/comment-decision.d.ts +0 -79
  158. package/dist/core/comment-decision.js +0 -82
  159. package/dist/core/extraction-categories.d.ts +0 -55
  160. package/dist/core/extraction-categories.js +0 -108
  161. package/dist/core/follow-up-history.d.ts +0 -40
  162. package/dist/core/follow-up-history.js +0 -71
  163. package/dist/core/issue-effort.d.ts +0 -29
  164. package/dist/core/issue-effort.js +0 -47
  165. package/dist/core/maintainer-hints.d.ts +0 -23
  166. package/dist/core/maintainer-hints.js +0 -36
  167. package/dist/core/workflow-state.d.ts +0 -56
  168. package/dist/core/workflow-state.js +0 -101
@@ -11,6 +11,7 @@
11
11
  */
12
12
  import { z } from 'zod';
13
13
  import { CLOSE_REASONS, SELF_CLOSE_REASONS } from './close-reason.js';
14
+ import { issueRefKey, parseGitHubUrl } from './urls.js';
14
15
  /**
15
16
  * An enum that also accepts values it does not know (#1831): a newer release
16
17
  * may add a value, and a strict enum would make this release reject the whole
@@ -19,6 +20,10 @@ import { CLOSE_REASONS, SELF_CLOSE_REASONS } from './close-reason.js';
19
20
  function openEnum(_values) {
20
21
  return z.custom((v) => typeof v === 'string');
21
22
  }
23
+ /** Narrows an {@link openEnum} value to the values this release knows (#2005). */
24
+ export function isKnownValue(values, value) {
25
+ return values.includes(value);
26
+ }
22
27
  // ── 1. Enum / union schemas ───────────────────────────────────────────
23
28
  export const IssueStatusSchema = z.enum(['candidate', 'claimed', 'in_progress', 'pr_submitted']);
24
29
  export const FetchedPRStatusSchema = z.enum(['needs_addressing', 'waiting_on_maintainer']);
@@ -168,50 +173,6 @@ export const StoredClosedPRSchema = z
168
173
  selfCloseReason: openEnum(SELF_CLOSE_REASONS).optional(),
169
174
  })
170
175
  .passthrough();
171
- export const AnalyzedIssueConversationSchema = z.object({
172
- url: z.string(),
173
- repo: z.string(),
174
- analyzedAt: z.string(),
175
- });
176
- /**
177
- * One entry in a PR's follow-up history (#1277). Tier matches the
178
- * cadence labels in `skills/pr-etiquette/SKILL.md` (light_check_in
179
- * for 7-13 days, direct_check_in for 14-29 days, final_check_in for
180
- * 30+ days). The `draftPath` is optional so an entry recorded from a
181
- * direct `gh pr comment` (no draft) still validates.
182
- */
183
- export const FollowUpEntrySchema = z.object({
184
- tier: z.enum(['light_check_in', 'direct_check_in', 'final_check_in']),
185
- timestamp: z.string().datetime(),
186
- draftPath: z.string().optional(),
187
- });
188
- /**
189
- * Pause-point snapshot for resumable workflows (#1280). When the user
190
- * picks "Done for now" inside `draft-first-workflow.md`,
191
- * `work-through-issues.md`, or `pre-commit-review.md`, the workflow
192
- * records its position here. The next `/oss` run consults this state
193
- * and offers "Resume / Restart / Discard" instead of restarting from
194
- * the beginning.
195
- *
196
- * `stepData` is intentionally typed as `Record<string, unknown>` so
197
- * each workflow can persist whatever per-step context it needs to
198
- * resume cleanly (compliance-gap skip list, last review pass count,
199
- * etc.) without forcing a tagged-union schema in shared state.
200
- */
201
- export const WorkflowStateSchema = z.object({
202
- workflowName: z.enum(['draft-first', 'work-through-issues', 'pre-commit-review']),
203
- currentStep: z.string(),
204
- branchName: z.string().optional(),
205
- issueContext: z
206
- .object({
207
- title: z.string(),
208
- url: z.string(),
209
- })
210
- .optional(),
211
- completedSteps: z.array(z.string()).default([]),
212
- stepData: z.record(z.string(), z.unknown()).default({}),
213
- lastUpdatedAt: z.string().datetime(),
214
- });
215
176
  // ── 3. Contribution schemas ──────────────────────────────────────────
216
177
  export const ContributionGuidelinesSchema = z.object({
217
178
  branchNamingConvention: z.string().optional(),
@@ -247,7 +208,7 @@ export const TrackedIssueSchema = z.object({
247
208
  repo: z.string(),
248
209
  number: z.number(),
249
210
  title: z.string(),
250
- status: IssueStatusSchema,
211
+ status: openEnum(IssueStatusSchema.options),
251
212
  labels: z.array(z.string()),
252
213
  createdAt: z.string(),
253
214
  updatedAt: z.string(),
@@ -261,19 +222,21 @@ export const ShelvedPRRefSchema = z.object({
261
222
  title: z.string(),
262
223
  repo: z.string(),
263
224
  daysSinceActivity: z.number(),
264
- status: FetchedPRStatusSchema,
225
+ status: openEnum(FetchedPRStatusSchema.options),
265
226
  });
266
227
  export const StatusOverrideSchema = z.object({
267
- status: FetchedPRStatusSchema,
228
+ status: openEnum(FetchedPRStatusSchema.options),
268
229
  setAt: z.string(),
269
230
  lastActivityAt: z.string(),
270
231
  });
271
232
  // ── 5. Config schema ─────────────────────────────────────────────────
233
+ /** What was true of a PR when it was shelved; see `config.shelvedPRInfo`. */
234
+ const ShelvedPRInfoSchema = z.object({ at: z.string(), reasons: z.array(z.string()).optional() });
272
235
  export const AgentConfigSchema = z
273
236
  .object({
274
237
  setupComplete: z.boolean().default(false),
275
238
  setupCompletedAt: z.string().optional(),
276
- persistence: z.enum(['local', 'gist']).default('local'),
239
+ persistence: openEnum(['local', 'gist']).default('local'),
277
240
  maxActivePRs: z.number().default(10),
278
241
  /**
279
242
  * Per-repo open-PR caps (core/repo-cap.ts). Discovery leaves out a repo
@@ -306,7 +269,7 @@ export const AgentConfigSchema = z
306
269
  complexIssues: openEnum(['off', 'warm']).default('off'),
307
270
  languages: z.array(z.string()).default(['typescript', 'javascript']),
308
271
  labels: z.array(z.string()).default(['good first issue', 'help wanted']),
309
- scope: z.array(IssueScopeSchema).optional(),
272
+ scope: z.array(openEnum(IssueScopeSchema.options)).optional(),
310
273
  excludeRepos: z.array(z.string()).default([]),
311
274
  excludeOrgs: z.array(z.string()).optional(),
312
275
  /**
@@ -341,6 +304,19 @@ export const AgentConfigSchema = z
341
304
  includeDocIssues: z.boolean().default(true),
342
305
  aiPolicyBlocklist: z.array(z.string()).default(['matplotlib/matplotlib']),
343
306
  shelvedPRUrls: z.array(z.string()).default([]),
307
+ /**
308
+ * `issueRefKey` of a shelved PR -> what was true when it was shelved
309
+ * (#1922): `at` is the ISO shelve time, `reasons` every action reason the
310
+ * PR had then (`shelveReasonsOf`; empty when it needed nothing). The daily
311
+ * run auto-unshelves a shelved PR that needs addressing only for
312
+ * maintainer activity newer than `at` or a reason not in `reasons`, so
313
+ * shelving a PR that already needs addressing sticks. `reasons` is unset
314
+ * when the PR was not in the last digest at shelve time; the next daily
315
+ * run fills it in, and nothing changes it after that. Entries shelved
316
+ * before the key existed have no record and keep the old rule (unshelved
317
+ * as soon as they need addressing).
318
+ */
319
+ shelvedPRInfo: z.record(z.string(), ShelvedPRInfoSchema).default({}),
344
320
  dismissedIssues: z.record(z.string(), z.string()).default({}),
345
321
  /**
346
322
  * PR URL -> head SHA the PR had when its review follow-up was dismissed
@@ -354,9 +330,9 @@ export const AgentConfigSchema = z
354
330
  statusOverrides: z.record(z.string(), StatusOverrideSchema).optional(),
355
331
  issueListPath: z.string().optional(),
356
332
  skippedIssuesPath: z.string().optional(),
357
- projectCategories: z.array(ProjectCategorySchema).default([]),
333
+ projectCategories: z.array(openEnum(ProjectCategorySchema.options)).default([]),
358
334
  preferredOrgs: z.array(z.string()).default([]),
359
- diffTool: DiffToolSchema.default('inline'),
335
+ diffTool: openEnum(DiffToolSchema.options).default('inline'),
360
336
  diffToolCustomCommand: z.string().optional(),
361
337
  /**
362
338
  * Extract per-repo learnings from freshly merged PRs automatically at
@@ -365,18 +341,18 @@ export const AgentConfigSchema = z
365
341
  */
366
342
  autoExtractLearnings: z.boolean().default(true),
367
343
  /**
368
- * No effect since the hook was removed in #1642; kept for state-file
369
- * compatibility.
344
+ * @deprecated Not read since the hook was removed in #1642; kept for
345
+ * state-file compatibility. Will be removed in the next major version.
370
346
  */
371
347
  autoFormatBeforePush: z.boolean().default(false),
372
348
  /**
373
- * No effect since the hook was removed in #1642; kept for state-file
374
- * compatibility.
349
+ * @deprecated Not read since the hook was removed in #1642; kept for
350
+ * state-file compatibility. Will be removed in the next major version.
375
351
  */
376
352
  trustOwnRepoWrites: z.boolean().default(false),
377
353
  /**
378
- * No effect since the hook was removed in #1642; kept for state-file
379
- * compatibility.
354
+ * @deprecated Not read since the hook was removed in #1642; kept for
355
+ * state-file compatibility. Will be removed in the next major version.
380
356
  */
381
357
  healthCheckFreshnessMinutes: z.number().int().positive().default(30),
382
358
  /**
@@ -406,7 +382,73 @@ export const AgentConfigSchema = z
406
382
  // Passthrough (#1831): a newer release's config fields survive this
407
383
  // version's load/save. Retired fields must be dropped explicitly instead.
408
384
  .passthrough()
409
- .transform(({ snoozedPRs: _retired, ...config }) => config);
385
+ .transform(({ snoozedPRs: _retired, ...config }) => foldRefKeys(config));
386
+ /** ISO stamp to ms for ranking; an unparseable stamp ranks last. */
387
+ function stampRank(at) {
388
+ const ms = Date.parse(at);
389
+ return Number.isNaN(ms) ? -Infinity : ms;
390
+ }
391
+ /**
392
+ * Group the keys of a URL-keyed map that name the same issue or PR (#2001):
393
+ * owner/repo casing, `/issues/N` vs `/pull/N`. Each group keeps the value
394
+ * `rank` scores highest (the first on a tie) under the key an older client
395
+ * sharing the Gist most likely looks up by exact match: the `/pull/` form,
396
+ * which GitHub reports for a PR, else the first key.
397
+ */
398
+ function groupByRef(map, rank) {
399
+ const groups = new Map();
400
+ for (const [key, value] of Object.entries(map)) {
401
+ const ref = issueRefKey(key) ?? key;
402
+ const group = groups.get(ref);
403
+ if (!group) {
404
+ groups.set(ref, { key, value, source: key });
405
+ continue;
406
+ }
407
+ if (parseGitHubUrl(group.key)?.type !== 'pull' && parseGitHubUrl(key)?.type === 'pull')
408
+ group.key = key;
409
+ if (rank(value) > rank(group.value)) {
410
+ group.source = key;
411
+ group.value = value;
412
+ }
413
+ }
414
+ return groups;
415
+ }
416
+ /** The map `groups` folds `map` into; `map` itself when nothing folded. */
417
+ function foldedMap(map, groups) {
418
+ if (groups.size === Object.keys(map).length)
419
+ return map;
420
+ return Object.fromEntries(Array.from(groups.values(), (group) => [group.key, group.value]));
421
+ }
422
+ /**
423
+ * Fold duplicate keys of `dismissedIssues`, `dismissedPRHeads` and
424
+ * `statusOverrides` on load (#2001), newest stamp kept. A dismissed PR keeps
425
+ * only the head recorded under the key its winning dismiss stamp came from:
426
+ * a newest dismiss without a head means the head was cleared.
427
+ */
428
+ function foldRefKeys(config) {
429
+ const dismissGroups = groupByRef(config.dismissedIssues, stampRank);
430
+ const dismissedPRHeads = {};
431
+ const headGroups = groupByRef(config.dismissedPRHeads, () => 0);
432
+ for (const [ref, group] of headGroups) {
433
+ const dismiss = dismissGroups.get(ref);
434
+ if (!dismiss) {
435
+ dismissedPRHeads[group.key] = group.value;
436
+ continue;
437
+ }
438
+ if (Object.hasOwn(config.dismissedPRHeads, dismiss.source)) {
439
+ dismissedPRHeads[dismiss.key] = config.dismissedPRHeads[dismiss.source];
440
+ }
441
+ }
442
+ const overrides = config.statusOverrides;
443
+ return {
444
+ ...config,
445
+ dismissedIssues: foldedMap(config.dismissedIssues, dismissGroups),
446
+ dismissedPRHeads,
447
+ ...(overrides && {
448
+ statusOverrides: foldedMap(overrides, groupByRef(overrides, (override) => stampRank(override.setAt))),
449
+ }),
450
+ };
451
+ }
410
452
  // ── 6. Cache schemas ─────────────────────────────────────────────────
411
453
  export const LocalRepoCacheSchema = z.object({
412
454
  repos: z.record(z.string(), z.object({
@@ -469,7 +511,7 @@ export const FetchedPRSchema = z
469
511
  url: z.string(),
470
512
  repo: z.string(),
471
513
  number: z.number(),
472
- status: FetchedPRStatusSchema,
514
+ status: openEnum(FetchedPRStatusSchema.options),
473
515
  })
474
516
  .passthrough();
475
517
  /**
@@ -481,6 +523,10 @@ export const FetchedPRSchema = z
481
523
  * core schema, and `.passthrough()` preserves the enrichment fields on parse
482
524
  * output. This mirrors the pre-#1456 `z.array(z.any())` static contract
483
525
  * while actually validating the fields the dashboard dereferences.
526
+ * One limit (#2005): `status` is an open enum here, so a persisted entry can
527
+ * carry a status a newer release added although `FetchedPR['status']` is
528
+ * closed. Readers of the persisted digest compare against known values and
529
+ * treat anything else as needing attention, so nothing is hidden.
484
530
  */
485
531
  const FetchedPRArraySchema = z.array(FetchedPRSchema);
486
532
  /**
@@ -495,7 +541,8 @@ function derivePartitions(raw) {
495
541
  return raw;
496
542
  return {
497
543
  ...raw,
498
- needsAddressingPRs: openPRs.filter((pr) => pr?.status === 'needs_addressing'),
544
+ // A status a newer release added counts as needing attention (#2005).
545
+ needsAddressingPRs: openPRs.filter((pr) => pr?.status !== 'waiting_on_maintainer'),
499
546
  waitingOnMaintainerPRs: openPRs.filter((pr) => pr?.status === 'waiting_on_maintainer'),
500
547
  };
501
548
  }
@@ -559,7 +606,7 @@ export const OvernightImplementAttemptSchema = z
559
606
  .object({
560
607
  url: z.string(),
561
608
  attemptedAt: z.string(),
562
- outcome: z.enum(['prepared', 'blocked']),
609
+ outcome: openEnum(['prepared', 'blocked']),
563
610
  note: z.string().optional(),
564
611
  })
565
612
  .passthrough();
@@ -653,10 +700,44 @@ export function malformedWorkClaimCount(raw, parsed) {
653
700
  * kept (root, config, repoScores, the outcome ledger and pick snapshots,
654
701
  * lastOvernight, searchRotation) are `.passthrough()`; schemas regenerated on
655
702
  * every run (lastDigest) or rarely extended still strip. Persisted enums that
656
- * grow (closeReason, pick source) accept unknown strings via {@link openEnum}.
703
+ * grow (closeReason, pick source, statuses, config modes; #2005) accept unknown strings via {@link openEnum}.
657
704
  * Inferred types drop the passthrough index signature ({@link KnownKeys}) so a
658
705
  * misspelled key still fails to compile.
706
+ *
707
+ * Retired root fields are dropped from the schema, not stripped: passthrough
708
+ * keeps an older client's `analyzedIssueConversations`, `prFollowUpHistory`
709
+ * and `workflowState` verbatim (#1948), so that client still parses its own data.
659
710
  */
711
+ /** One user approval of a repo's stored guidelines text (#1929). */
712
+ export const GuidelinesReviewSchema = z.object({
713
+ reviewedAt: z.string(),
714
+ /** Hex SHA-256 of the guidelines markdown the user approved. */
715
+ sha256: z.string(),
716
+ });
717
+ /** Longest quoted source line or disclosure text a repo policy keeps (#1953): the text is from other people's repos. */
718
+ export const POLICY_QUOTE_MAX = 200;
719
+ /**
720
+ * Per-repo contribution policy (#1953). Only enumerated values plus short
721
+ * quoted source lines: policy text comes from files in other people's repos.
722
+ */
723
+ const PolicyQuoteSchema = z.string().max(POLICY_QUOTE_MAX);
724
+ const PolicySourceSchema = z.object({ file: z.string().max(100), quotedLine: PolicyQuoteSchema });
725
+ const CommitRuleIdSchema = z.string().regex(/^[a-z0-9-]{1,40}$/);
726
+ export const RepoPolicySchema = z.object({
727
+ aiPolicy: z.enum(['allowed', 'disclosure-required', 'banned', 'unknown']),
728
+ /** The line the repo asks for, quoted from its docs. Untrusted: fence it before handing it to an agent. */
729
+ disclosureText: PolicyQuoteSchema.optional(),
730
+ cla: z.enum(['none', 'required', 'unknown']),
731
+ /** Short ids such as `conventional-commits`, `dco-signoff`, `no-closing-keyword-in-commit`. */
732
+ commitRules: z.array(CommitRuleIdSchema).max(10),
733
+ prGate: z.enum(['none', 'claim-first', 'maintainer-label', 'collaborators-only', 'unknown']),
734
+ maxOpenAiPRs: z.number().int().positive().optional(),
735
+ /** Where each rule came from. `quotedLine` is untrusted. */
736
+ source: z.array(PolicySourceSchema).max(10),
737
+ /** True once the user set it with `policy set`; vet never overwrites such a record. */
738
+ reviewedByUser: z.boolean(),
739
+ updatedAt: z.string(),
740
+ });
660
741
  export const AgentStateSchema = z
661
742
  .object({
662
743
  version: z.literal(4),
@@ -681,25 +762,7 @@ export const AgentStateSchema = z
681
762
  localRepoCache: LocalRepoCacheSchema.optional(),
682
763
  mergedPRs: z.array(StoredMergedPRSchema).optional(),
683
764
  closedPRs: z.array(StoredClosedPRSchema).optional(),
684
- analyzedIssueConversations: z.array(AnalyzedIssueConversationSchema).optional(),
685
765
  activeIssues: z.array(TrackedIssueSchema).default([]),
686
- /**
687
- * Per-PR follow-up history (#1277). Keyed by PR URL. Each entry
688
- * records a tier-bucketed follow-up that the user drafted (and
689
- * presumably posted via `draft-review-post`). The dormant-pr
690
- * workflow reads this before drafting to enforce the
691
- * one-follow-up-per-timeframe rule documented in
692
- * `skills/pr-etiquette/SKILL.md`.
693
- */
694
- prFollowUpHistory: z.record(z.string(), z.array(FollowUpEntrySchema)).optional(),
695
- /**
696
- * Pause-point snapshot for resumable workflows (#1280). Set when
697
- * the user picks "Done for now" mid-workflow; cleared when the
698
- * workflow completes or the user explicitly discards. The router
699
- * reads this on every `/oss` invocation and offers Resume /
700
- * Restart / Discard when present.
701
- */
702
- workflowState: WorkflowStateSchema.optional(),
703
766
  /**
704
767
  * Durable search seen-set for result rotation (#1528). Issue URLs surfaced
705
768
  * by recent searches, with the timestamp they were last surfaced. Fed into
@@ -730,6 +793,28 @@ export const AgentStateSchema = z
730
793
  * entries are ignored on read and pruned on write.
731
794
  */
732
795
  workClaims: WorkClaimListSchema,
796
+ /**
797
+ * User review stamps for stored per-repo guidelines (#1929), keyed by
798
+ * `owner/repo`. Written only by `guidelines store`, which requires the
799
+ * caller to assert the user approved the exact text. The hash ties the
800
+ * stamp to that text: a guidelines file rewritten by a client that predates
801
+ * the review requirement no longer matches and reads as unreviewed.
802
+ * Optional so state written by older clients still parses. Entries are
803
+ * kept as written and validated one at a time on read
804
+ * (`StateManager.getGuidelinesReview`), so an entry this release cannot
805
+ * read counts as "not reviewed" for that repo only and is not dropped on
806
+ * the next save.
807
+ */
808
+ guidelinesReviews: z.record(z.string(), z.unknown()).optional().catch(undefined),
809
+ /**
810
+ * Per-repo contribution policies (#1953), keyed by lowercase `owner/repo`.
811
+ * Written by `vet` (reviewedByUser: false) and `policy set` (true). Kept as
812
+ * written and validated per entry on read (`StateManager.getRepoPolicy`),
813
+ * like `guidelinesReviews`, so an entry a newer release wrote is not
814
+ * dropped here. `config.aiPolicyBlocklist` stays the older ban list and is
815
+ * read as `aiPolicy: 'banned'` on top of these (core/repo-policy.ts).
816
+ */
817
+ repoPolicies: z.record(z.string(), z.unknown()).optional().catch(undefined),
733
818
  })
734
819
  .passthrough();
735
820
  /** Top-level state keys this release does not know, i.e. written by another (usually newer) release (#1831). */
@@ -3,8 +3,10 @@
3
3
  * Thin coordinator that delegates persistence to state-persistence.ts
4
4
  * and scoring logic to repo-score-manager.ts.
5
5
  */
6
- import { AgentState, TrackedIssue, RepoScore, RepoScoreUpdate, DailyDigest, LocalRepoCache, StatusOverride, FetchedPRStatus, StoredMergedPR, StoredClosedPR, SearchSeenEntry, PickSnapshot, OvernightRecord, SearchRotation, WorkClaim } from './types.js';
6
+ import { AgentState, TrackedIssue, RepoScore, RepoScoreUpdate, DailyDigest, StatusOverride, FetchedPRStatus, StoredMergedPR, StoredClosedPR, SearchSeenEntry, PickSnapshot, OvernightRecord, SearchRotation, WorkClaim } from './types.js';
7
+ import { type GuidelinesReview, type RepoPolicy } from './state-schema.js';
7
8
  import { type LoadRecoveryInfo } from './state-persistence.js';
9
+ import * as repoScoring from './repo-score-manager.js';
8
10
  import type { Stats } from './repo-score-manager.js';
9
11
  import { GistStateStore } from './gist-state-store.js';
10
12
  /** Gist file that carries the rendered overnight report across machines (#1698). */
@@ -71,7 +73,7 @@ export interface StalenessInfo {
71
73
  export declare class StateManager {
72
74
  protected state: AgentState;
73
75
  protected inMemoryOnly: boolean;
74
- private lastLoadedMtimeMs;
76
+ private lastLoadedFileId;
75
77
  private _batching;
76
78
  private _batchDirty;
77
79
  protected gistStore: GistStateStore | null;
@@ -163,6 +165,8 @@ export declare class StateManager {
163
165
  * `isGistDegraded()` at each call site.
164
166
  *
165
167
  * Composes the same primitive fields those accessors expose:
168
+ * - no gist store + config names a mode this release does not know →
169
+ * `unknown-mode` (#2005)
166
170
  * - no gist store + config asks for gist → `configured-but-local`
167
171
  * - gist store attached but disarmed (#1443) → `bootstrap-degraded`
168
172
  * (`since` comes from the staleness marker the degraded bootstrap seeds)
@@ -190,6 +194,12 @@ export declare class StateManager {
190
194
  * Throws when not in Gist mode.
191
195
  */
192
196
  deleteGuidelines(repo: string): void;
197
+ /** Record that the user approved the guidelines text hashing to `sha256` for `repo` (#1929). */
198
+ markGuidelinesReviewed(repo: string, sha256: string, reviewedAt: string): void;
199
+ /** The review stamp for `repo`, or undefined when none is recorded or the entry is unreadable (#1929). */
200
+ getGuidelinesReview(repo: string): GuidelinesReview | undefined;
201
+ /** Store `policy` for `repo` (#1953), or delete the record when `policy` is null. Keys are lowercase. */
202
+ setRepoPolicy(repo: string, policy: RepoPolicy | null): void;
193
203
  /** List repos with non-empty guidelines stored in the Gist. */
194
204
  listGuidelinesRepos(): string[];
195
205
  /**
@@ -277,10 +287,10 @@ export declare class StateManager {
277
287
  */
278
288
  setMonthlyOpenedCounts(counts: Record<string, number>): void;
279
289
  /**
280
- * Update the local repository cache.
281
- * @param cache - Local repository cache mapping repo names to paths
290
+ * Drop the synced copy of the local repository cache. The cache is
291
+ * per-machine and lives in `local-config.json` (#1950).
282
292
  */
283
- setLocalRepoCache(cache: LocalRepoCache): void;
293
+ clearSyncedLocalRepoCache(): void;
284
294
  /** Returns all stored merged PRs (sorted by merge date descending via addMergedPRs). */
285
295
  getMergedPRs(): StoredMergedPR[];
286
296
  /**
@@ -320,7 +330,8 @@ export declare class StateManager {
320
330
  * this prevents the bad data from reaching disk in the first place).
321
331
  *
322
332
  * Re-seen URLs upgrade the stored entry's missing ledger fields in place
323
- * (#1461) — see {@link addMergedPRs} for the full semantics.
333
+ * (#1461) — see {@link addMergedPRs} for the full semantics. URLs already
334
+ * in the merged ledger are skipped (#1923).
324
335
  *
325
336
  * @param prs - Closed PRs to add (duplicates by URL upgrade in place)
326
337
  * @returns count of entries added vs. dropped (invalid URL)
@@ -329,6 +340,20 @@ export declare class StateManager {
329
340
  added: number;
330
341
  dropped: number;
331
342
  };
343
+ /**
344
+ * Remove closed-ledger entries that are open again (`openUrls`) or sit in
345
+ * the merged ledger, lowering the affected repos' closed counts with them
346
+ * (#1923). See repoScoring.evictClosedPRs.
347
+ * @returns the number of entries removed
348
+ */
349
+ evictClosedPRs(openUrls: Iterable<string>): number;
350
+ /**
351
+ * Remove ledger rows and repoScores entries for repositories in
352
+ * `config.untrackedOrgs` and for `privateRepos`, which must hold only
353
+ * repositories GitHub reported private in this run (#1924). See
354
+ * repoScoring.evictExcludedRepos.
355
+ */
356
+ evictExcludedRepos(privateRepos: Iterable<string>): repoScoring.EvictedRepos;
332
357
  /** Returns the most recent close date, used as a watermark for incremental fetching. */
333
358
  getClosedPRWatermark(): string | undefined;
334
359
  /**
@@ -417,15 +442,30 @@ export declare class StateManager {
417
442
  /**
418
443
  * Shelve a PR URL, hiding it from daily digest and capacity.
419
444
  * @param url - The PR URL to shelve
445
+ * @param reasons - The PR's action reasons right now (`shelveReasonsOf`), when known
420
446
  * @returns true if newly shelved, false if already shelved
421
447
  */
422
- shelvePR(url: string): boolean;
448
+ shelvePR(url: string, reasons?: string[]): boolean;
449
+ /**
450
+ * Index of a PR in `shelvedPRUrls`, matched through {@link issueRefKey} so
451
+ * a URL typed in different casing or with a trailing slash still finds the
452
+ * entry (#1922). -1 when not shelved.
453
+ */
454
+ private shelvedIndex;
423
455
  /**
424
456
  * Unshelve a PR URL, restoring it to daily digest.
425
457
  * @param url - The PR URL to unshelve
426
458
  * @returns true if removed from shelf, false if not shelved
427
459
  */
428
460
  unshelvePR(url: string): boolean;
461
+ /**
462
+ * Fill in the action reasons of a shelve record that has none yet (#1922):
463
+ * the PR was not in the digest when it was shelved, so the first daily run
464
+ * that sees it records them. Never changes reasons already recorded: a
465
+ * reason that clears and comes back was there at shelve time and is not
466
+ * new. No-op for a PR without a shelve record.
467
+ */
468
+ fillShelvedPRReasons(url: string, reasons: string[]): void;
429
469
  /**
430
470
  * Check if a PR is currently shelved.
431
471
  * @param url - The PR URL to check
@@ -470,7 +510,10 @@ export declare class StateManager {
470
510
  * @param url - The PR URL to check
471
511
  */
472
512
  getDismissedPRHead(url: string): string | undefined;
473
- /** Record or (with `undefined`) drop the dismiss head for `url`; no save. */
513
+ /**
514
+ * Record or (with `undefined`) drop the dismiss head for `url`, replacing
515
+ * any head stored under another form of the same PR's URL (#2001); no save.
516
+ */
474
517
  private setDismissedPRHead;
475
518
  /**
476
519
  * Set a manual status override for a PR. Auto-clears when the PR has new activity.
@@ -674,6 +717,15 @@ export type GistPersistenceStatus =
674
717
  * A later call may recover. */
675
718
  | 'degraded';
676
719
  export declare function ensureGistPersistence(token: string | null): Promise<GistPersistenceStatus>;
720
+ /**
721
+ * The warning for a persistence mode a newer release wrote (#2005), or null.
722
+ * {@link ensureGistPersistence} reads such a mode as `'local-mode'`, so entry
723
+ * points add this to their output: writes will not reach the Gist the newer
724
+ * client syncs through. Reads state.json, or the state cache when state.json
725
+ * is absent, as ensureGistPersistence does; any other read failure is that
726
+ * function's to report.
727
+ */
728
+ export declare function unknownPersistenceModeWarning(): string | null;
677
729
  /**
678
730
  * Best-effort gist bootstrap for entry points WITHOUT the auth gate (#1431):
679
731
  * the CLI's localOnly commands (shelve/move/dismiss/override/config/setup/...)