@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
@@ -116,6 +116,8 @@ export declare const StoredMergedPRSchema: z.ZodObject<{
116
116
  firstMaintainerResponseAt: z.ZodOptional<z.ZodString>;
117
117
  commentsFetchedAt: z.ZodOptional<z.ZodString>;
118
118
  learningsExtractedAt: z.ZodOptional<z.ZodString>;
119
+ learningsProposedAt: z.ZodOptional<z.ZodISODateTime>;
120
+ learningsProposedOn: z.ZodOptional<z.ZodString>;
119
121
  }, z.core.$loose>;
120
122
  export declare const StoredClosedPRSchema: z.ZodObject<{
121
123
  closeReason: z.ZodOptional<z.ZodCustom<"unknown" | "rejected" | (string & {}) | "ai-policy" | "superseded" | "stale" | "self-closed", "unknown" | "rejected" | (string & {}) | "ai-policy" | "superseded" | "stale" | "self-closed">>;
@@ -147,6 +149,8 @@ export declare const StoredClosedPRSchema: z.ZodObject<{
147
149
  firstMaintainerResponseAt: z.ZodOptional<z.ZodString>;
148
150
  commentsFetchedAt: z.ZodOptional<z.ZodString>;
149
151
  learningsExtractedAt: z.ZodOptional<z.ZodString>;
152
+ learningsProposedAt: z.ZodOptional<z.ZodISODateTime>;
153
+ learningsProposedOn: z.ZodOptional<z.ZodString>;
150
154
  }, z.core.$loose>;
151
155
  export declare const ContributionGuidelinesSchema: z.ZodObject<{
152
156
  branchNamingConvention: z.ZodOptional<z.ZodString>;
@@ -251,6 +255,8 @@ export declare const AgentConfigSchema: z.ZodPipe<z.ZodObject<{
251
255
  maxOpenPRsPerRepo: z.ZodDefault<z.ZodNumber>;
252
256
  maxOpenPRsColdRepo: z.ZodDefault<z.ZodNumber>;
253
257
  maxConcurrentImplementations: z.ZodDefault<z.ZodNumber>;
258
+ maxNewPrsPerDay: z.ZodOptional<z.ZodNumber>;
259
+ maxNewForksPerDay: z.ZodOptional<z.ZodNumber>;
254
260
  dormantThresholdDays: z.ZodDefault<z.ZodNumber>;
255
261
  approachingDormantDays: z.ZodDefault<z.ZodNumber>;
256
262
  maxIssueAgeDays: z.ZodDefault<z.ZodNumber>;
@@ -274,6 +280,7 @@ export declare const AgentConfigSchema: z.ZodPipe<z.ZodObject<{
274
280
  minStars: z.ZodDefault<z.ZodNumber>;
275
281
  includeDocIssues: z.ZodDefault<z.ZodBoolean>;
276
282
  aiPolicyBlocklist: z.ZodDefault<z.ZodArray<z.ZodString>>;
283
+ keepForks: z.ZodDefault<z.ZodArray<z.ZodString>>;
277
284
  shelvedPRUrls: z.ZodDefault<z.ZodArray<z.ZodString>>;
278
285
  shelvedPRInfo: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
279
286
  at: z.ZodString;
@@ -326,6 +333,7 @@ export declare const AgentConfigSchema: z.ZodPipe<z.ZodObject<{
326
333
  minStars: number;
327
334
  includeDocIssues: boolean;
328
335
  aiPolicyBlocklist: string[];
336
+ keepForks: string[];
329
337
  shelvedPRUrls: string[];
330
338
  shelvedPRInfo: Record<string, {
331
339
  at: string;
@@ -343,6 +351,8 @@ export declare const AgentConfigSchema: z.ZodPipe<z.ZodObject<{
343
351
  slmTriageModel: string;
344
352
  slmTriageHost: string;
345
353
  setupCompletedAt?: string | undefined;
354
+ maxNewPrsPerDay?: number | undefined;
355
+ maxNewForksPerDay?: number | undefined;
346
356
  scope?: ("advanced" | (string & {}) | "beginner" | "intermediate")[] | undefined;
347
357
  excludeOrgs?: string[] | undefined;
348
358
  starredReposLastFetched?: string | undefined;
@@ -383,6 +393,7 @@ export declare const AgentConfigSchema: z.ZodPipe<z.ZodObject<{
383
393
  minStars: number;
384
394
  includeDocIssues: boolean;
385
395
  aiPolicyBlocklist: string[];
396
+ keepForks: string[];
386
397
  shelvedPRUrls: string[];
387
398
  shelvedPRInfo: Record<string, {
388
399
  at: string;
@@ -400,6 +411,8 @@ export declare const AgentConfigSchema: z.ZodPipe<z.ZodObject<{
400
411
  slmTriageModel: string;
401
412
  slmTriageHost: string;
402
413
  setupCompletedAt?: string | undefined;
414
+ maxNewPrsPerDay?: number | undefined;
415
+ maxNewForksPerDay?: number | undefined;
403
416
  scope?: ("advanced" | (string & {}) | "beginner" | "intermediate")[] | undefined;
404
417
  excludeOrgs?: string[] | undefined;
405
418
  starredReposLastFetched?: string | undefined;
@@ -615,6 +628,11 @@ export declare const WorkClaimSchema: z.ZodObject<{
615
628
  runId: z.ZodOptional<z.ZodString>;
616
629
  finishedAt: z.ZodOptional<z.ZodString>;
617
630
  }, z.core.$loose>;
631
+ /** One PR the tool opened (#1911), recorded at creation for the pacing caps. */
632
+ export declare const RecentNewPRSchema: z.ZodObject<{
633
+ url: z.ZodString;
634
+ openedAt: z.ZodString;
635
+ }, z.core.$loose>;
618
636
  /** How many entries of `raw.workClaims` the lenient parse dropped as malformed (#1856); 0 when none or no list. */
619
637
  export declare function malformedWorkClaimCount(raw: unknown, parsed: {
620
638
  workClaims: readonly unknown[];
@@ -641,6 +659,8 @@ export declare const GuidelinesReviewSchema: z.ZodObject<{
641
659
  }, z.core.$strip>;
642
660
  /** Longest quoted source line or disclosure text a repo policy keeps (#1953): the text is from other people's repos. */
643
661
  export declare const POLICY_QUOTE_MAX = 200;
662
+ /** Longest gate label a repo policy keeps; GitHub caps a label name at 50 characters. */
663
+ export declare const GATE_LABEL_MAX = 50;
644
664
  export declare const RepoPolicySchema: z.ZodObject<{
645
665
  aiPolicy: z.ZodEnum<{
646
666
  unknown: "unknown";
@@ -662,6 +682,7 @@ export declare const RepoPolicySchema: z.ZodObject<{
662
682
  "maintainer-label": "maintainer-label";
663
683
  "collaborators-only": "collaborators-only";
664
684
  }>;
685
+ gateLabel: z.ZodOptional<z.ZodString>;
665
686
  maxOpenAiPRs: z.ZodOptional<z.ZodNumber>;
666
687
  source: z.ZodArray<z.ZodObject<{
667
688
  file: z.ZodString;
@@ -697,6 +718,8 @@ export declare const AgentStateSchema: z.ZodObject<{
697
718
  maxOpenPRsPerRepo: z.ZodDefault<z.ZodNumber>;
698
719
  maxOpenPRsColdRepo: z.ZodDefault<z.ZodNumber>;
699
720
  maxConcurrentImplementations: z.ZodDefault<z.ZodNumber>;
721
+ maxNewPrsPerDay: z.ZodOptional<z.ZodNumber>;
722
+ maxNewForksPerDay: z.ZodOptional<z.ZodNumber>;
700
723
  dormantThresholdDays: z.ZodDefault<z.ZodNumber>;
701
724
  approachingDormantDays: z.ZodDefault<z.ZodNumber>;
702
725
  maxIssueAgeDays: z.ZodDefault<z.ZodNumber>;
@@ -720,6 +743,7 @@ export declare const AgentStateSchema: z.ZodObject<{
720
743
  minStars: z.ZodDefault<z.ZodNumber>;
721
744
  includeDocIssues: z.ZodDefault<z.ZodBoolean>;
722
745
  aiPolicyBlocklist: z.ZodDefault<z.ZodArray<z.ZodString>>;
746
+ keepForks: z.ZodDefault<z.ZodArray<z.ZodString>>;
723
747
  shelvedPRUrls: z.ZodDefault<z.ZodArray<z.ZodString>>;
724
748
  shelvedPRInfo: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
725
749
  at: z.ZodString;
@@ -772,6 +796,7 @@ export declare const AgentStateSchema: z.ZodObject<{
772
796
  minStars: number;
773
797
  includeDocIssues: boolean;
774
798
  aiPolicyBlocklist: string[];
799
+ keepForks: string[];
775
800
  shelvedPRUrls: string[];
776
801
  shelvedPRInfo: Record<string, {
777
802
  at: string;
@@ -789,6 +814,8 @@ export declare const AgentStateSchema: z.ZodObject<{
789
814
  slmTriageModel: string;
790
815
  slmTriageHost: string;
791
816
  setupCompletedAt?: string | undefined;
817
+ maxNewPrsPerDay?: number | undefined;
818
+ maxNewForksPerDay?: number | undefined;
792
819
  scope?: ("advanced" | (string & {}) | "beginner" | "intermediate")[] | undefined;
793
820
  excludeOrgs?: string[] | undefined;
794
821
  starredReposLastFetched?: string | undefined;
@@ -829,6 +856,7 @@ export declare const AgentStateSchema: z.ZodObject<{
829
856
  minStars: number;
830
857
  includeDocIssues: boolean;
831
858
  aiPolicyBlocklist: string[];
859
+ keepForks: string[];
832
860
  shelvedPRUrls: string[];
833
861
  shelvedPRInfo: Record<string, {
834
862
  at: string;
@@ -846,6 +874,8 @@ export declare const AgentStateSchema: z.ZodObject<{
846
874
  slmTriageModel: string;
847
875
  slmTriageHost: string;
848
876
  setupCompletedAt?: string | undefined;
877
+ maxNewPrsPerDay?: number | undefined;
878
+ maxNewForksPerDay?: number | undefined;
849
879
  scope?: ("advanced" | (string & {}) | "beginner" | "intermediate")[] | undefined;
850
880
  excludeOrgs?: string[] | undefined;
851
881
  starredReposLastFetched?: string | undefined;
@@ -950,6 +980,8 @@ export declare const AgentStateSchema: z.ZodObject<{
950
980
  firstMaintainerResponseAt: z.ZodOptional<z.ZodString>;
951
981
  commentsFetchedAt: z.ZodOptional<z.ZodString>;
952
982
  learningsExtractedAt: z.ZodOptional<z.ZodString>;
983
+ learningsProposedAt: z.ZodOptional<z.ZodISODateTime>;
984
+ learningsProposedOn: z.ZodOptional<z.ZodString>;
953
985
  }, z.core.$loose>>>;
954
986
  closedPRs: z.ZodOptional<z.ZodArray<z.ZodObject<{
955
987
  closeReason: z.ZodOptional<z.ZodCustom<"unknown" | "rejected" | (string & {}) | "ai-policy" | "superseded" | "stale" | "self-closed", "unknown" | "rejected" | (string & {}) | "ai-policy" | "superseded" | "stale" | "self-closed">>;
@@ -981,6 +1013,8 @@ export declare const AgentStateSchema: z.ZodObject<{
981
1013
  firstMaintainerResponseAt: z.ZodOptional<z.ZodString>;
982
1014
  commentsFetchedAt: z.ZodOptional<z.ZodString>;
983
1015
  learningsExtractedAt: z.ZodOptional<z.ZodString>;
1016
+ learningsProposedAt: z.ZodOptional<z.ZodISODateTime>;
1017
+ learningsProposedOn: z.ZodOptional<z.ZodString>;
984
1018
  }, z.core.$loose>>>;
985
1019
  activeIssues: z.ZodDefault<z.ZodArray<z.ZodObject<{
986
1020
  id: z.ZodNumber;
@@ -1087,6 +1121,11 @@ export declare const AgentStateSchema: z.ZodObject<{
1087
1121
  runId?: string | undefined;
1088
1122
  finishedAt?: string | undefined;
1089
1123
  }[], unknown[]>>;
1124
+ recentNewPRs: z.ZodPipe<z.ZodOptional<z.ZodUnknown>, z.ZodTransform<{
1125
+ [x: string]: unknown;
1126
+ url: string;
1127
+ openedAt: string;
1128
+ }[] | undefined, unknown>>;
1090
1129
  guidelinesReviews: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
1091
1130
  repoPolicies: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
1092
1131
  }, z.core.$loose>;
@@ -145,6 +145,14 @@ export const StoredMergedPRSchema = z
145
145
  commentsFetchedAt: z.string().datetime().optional(),
146
146
  /** When the host last ran LLM extraction over this PR's comment bundle (#867). */
147
147
  learningsExtractedAt: z.string().datetime().optional(),
148
+ /**
149
+ * When a guideline proposal built from this PR was written for review
150
+ * (#2041). The proposal file is machine-local, so `learningsProposedOn`
151
+ * names the machine holding it; another machine does not re-extract.
152
+ */
153
+ learningsProposedAt: z.iso.datetime().optional(),
154
+ /** Machine id (`~/.oss-autopilot/machine-id`) of the machine holding the proposal (#2041). */
155
+ learningsProposedOn: z.string().optional(),
148
156
  ...LedgerPredictionFields,
149
157
  })
150
158
  .passthrough();
@@ -166,6 +174,14 @@ export const StoredClosedPRSchema = z
166
174
  commentsFetchedAt: z.string().datetime().optional(),
167
175
  /** When the host last ran LLM extraction over this PR's comment bundle (#867). */
168
176
  learningsExtractedAt: z.string().datetime().optional(),
177
+ /**
178
+ * When a guideline proposal built from this PR was written for review
179
+ * (#2041). The proposal file is machine-local, so `learningsProposedOn`
180
+ * names the machine holding it; another machine does not re-extract.
181
+ */
182
+ learningsProposedAt: z.iso.datetime().optional(),
183
+ /** Machine id (`~/.oss-autopilot/machine-id`) of the machine holding the proposal (#2041). */
184
+ learningsProposedOn: z.string().optional(),
169
185
  ...LedgerPredictionFields,
170
186
  /** Why it closed unmerged (#1824), set by ledger-backfill. */
171
187
  closeReason: openEnum(CLOSE_REASONS).optional(),
@@ -254,6 +270,15 @@ export const AgentConfigSchema = z
254
270
  * one-implementation-per-worktree rule still applies.
255
271
  */
256
272
  maxConcurrentImplementations: z.number().int().min(0).default(2),
273
+ /**
274
+ * Optional pacing caps (#1911, core/pacing.ts): new PRs to repos the user
275
+ * does not own, and new forks, per rolling 24 hours. Unset (or 0) means
276
+ * no cap. Optional with no default, so a state without them parses
277
+ * unchanged; the config schema is passthrough, so an older client that
278
+ * does not know them keeps them on save.
279
+ */
280
+ maxNewPrsPerDay: z.number().int().min(0).optional(),
281
+ maxNewForksPerDay: z.number().int().min(0).optional(),
257
282
  dormantThresholdDays: z.number().default(30),
258
283
  approachingDormantDays: z.number().default(25),
259
284
  maxIssueAgeDays: z.number().default(90),
@@ -303,6 +328,13 @@ export const AgentConfigSchema = z
303
328
  minStars: z.number().default(50),
304
329
  includeDocIssues: z.boolean().default(true),
305
330
  aiPolicyBlocklist: z.array(z.string()).default(['matplotlib/matplotlib']),
331
+ /**
332
+ * Forks (owner/repo, or the parent's owner/repo) `fork-prune` must never
333
+ * delete: forks the user develops in directly (#1912). Matched
334
+ * case-insensitively. A safeguard: MCP cannot set it and an unattended
335
+ * run cannot shrink it.
336
+ */
337
+ keepForks: z.array(z.string()).default([]),
306
338
  shelvedPRUrls: z.array(z.string()).default([]),
307
339
  /**
308
340
  * `issueRefKey` of a shelved PR -> what was true when it was shelved
@@ -688,6 +720,23 @@ const WorkClaimListSchema = z
688
720
  const parsed = WorkClaimSchema.safeParse(claim);
689
721
  return parsed.success ? [parsed.data] : [];
690
722
  }));
723
+ /** One PR the tool opened (#1911), recorded at creation for the pacing caps. */
724
+ export const RecentNewPRSchema = z.object({ url: z.string(), openedAt: z.string() }).loose();
725
+ /**
726
+ * `state.recentNewPRs`, parsed one entry at a time like `workClaims`: an
727
+ * entry this release cannot read is dropped instead of rejecting the state.
728
+ * Dropping only lowers a pacing count.
729
+ */
730
+ const RecentNewPRListSchema = z
731
+ .unknown()
732
+ .optional()
733
+ // Not a list at all (null, a string, an object) reads as no records, never as a corrupt state.
734
+ .transform((entries) => Array.isArray(entries)
735
+ ? entries.flatMap((entry) => {
736
+ const parsed = RecentNewPRSchema.safeParse(entry);
737
+ return parsed.success ? [parsed.data] : [];
738
+ })
739
+ : undefined);
691
740
  /** How many entries of `raw.workClaims` the lenient parse dropped as malformed (#1856); 0 when none or no list. */
692
741
  export function malformedWorkClaimCount(raw, parsed) {
693
742
  const stored = raw !== null && typeof raw === 'object' ? raw.workClaims : undefined;
@@ -716,6 +765,8 @@ export const GuidelinesReviewSchema = z.object({
716
765
  });
717
766
  /** Longest quoted source line or disclosure text a repo policy keeps (#1953): the text is from other people's repos. */
718
767
  export const POLICY_QUOTE_MAX = 200;
768
+ /** Longest gate label a repo policy keeps; GitHub caps a label name at 50 characters. */
769
+ export const GATE_LABEL_MAX = 50;
719
770
  /**
720
771
  * Per-repo contribution policy (#1953). Only enumerated values plus short
721
772
  * quoted source lines: policy text comes from files in other people's repos.
@@ -725,12 +776,20 @@ const PolicySourceSchema = z.object({ file: z.string().max(100), quotedLine: Pol
725
776
  const CommitRuleIdSchema = z.string().regex(/^[a-z0-9-]{1,40}$/);
726
777
  export const RepoPolicySchema = z.object({
727
778
  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. */
779
+ /**
780
+ * The disclosure line the user recorded with `policy set --disclosure-text` (#2040); the repo's own rule
781
+ * stays in `source`. Older releases stored a doc excerpt here, which `storedPolicy` drops on read. Fence it.
782
+ */
729
783
  disclosureText: PolicyQuoteSchema.optional(),
730
784
  cla: z.enum(['none', 'required', 'unknown']),
731
785
  /** Short ids such as `conventional-commits`, `dco-signoff`, `no-closing-keyword-in-commit`. */
732
786
  commitRules: z.array(CommitRuleIdSchema).max(10),
733
787
  prGate: z.enum(['none', 'claim-first', 'maintainer-label', 'collaborators-only', 'unknown']),
788
+ /**
789
+ * The issue label a `maintainer-label` gate waits for, recorded by the user with `policy set --gate-label`
790
+ * (#2040). vet never sets it: which label is the gate is not read from repo text. Fence it.
791
+ */
792
+ gateLabel: z.string().max(GATE_LABEL_MAX).optional(),
734
793
  maxOpenAiPRs: z.number().int().positive().optional(),
735
794
  /** Where each rule came from. `quotedLine` is untrusted. */
736
795
  source: z.array(PolicySourceSchema).max(10),
@@ -793,6 +852,14 @@ export const AgentStateSchema = z
793
852
  * entries are ignored on read and pruned on write.
794
853
  */
795
854
  workClaims: WorkClaimListSchema,
855
+ /**
856
+ * PRs the tool opened in the last 24 hours (#1911), recorded by
857
+ * `work release --pr <url>` right after `gh pr create`, so the pacing
858
+ * caps count a PR before the next `daily` picks it up. Pruned to the
859
+ * window on every write. Optional; the root schema is passthrough, so an
860
+ * older client keeps the list when it saves.
861
+ */
862
+ recentNewPRs: RecentNewPRListSchema,
796
863
  /**
797
864
  * User review stamps for stored per-repo guidelines (#1929), keyed by
798
865
  * `owner/repo`. Written only by `guidelines store`, which requires the
@@ -374,6 +374,12 @@ export declare class StateManager {
374
374
  * No-op when no PR with that URL is stored.
375
375
  */
376
376
  markPRLearningsExtracted(url: string, extractedAt: string): void;
377
+ /**
378
+ * Stamp a written guideline proposal on the merged or closed PR matching
379
+ * `url` (#2041). `machineId` is omitted when this machine has none.
380
+ * No-op when no PR with that URL is stored.
381
+ */
382
+ markPRLearningsProposed(url: string, proposedAt: string, machineId: string | undefined): void;
377
383
  /**
378
384
  * Merge partial config updates into the current configuration.
379
385
  * @param config - Partial config object to merge
@@ -603,6 +609,13 @@ export declare class StateManager {
603
609
  session?: string;
604
610
  kind?: string;
605
611
  }, nowMs?: number): string[];
612
+ /**
613
+ * Record a PR the tool just opened (#1911) so the pacing caps count it
614
+ * before the next `daily`. Idempotent per URL (the first open time is
615
+ * kept); entries older than the 24-hour window are pruned in the same write.
616
+ * @returns true when the PR was not recorded yet
617
+ */
618
+ recordNewPR(url: string, nowMs?: number): boolean;
606
619
  setStatusOverride(url: string, status: FetchedPRStatus, lastActivityAt: string): void;
607
620
  /**
608
621
  * Remove a manual status override for a PR.
@@ -629,6 +642,14 @@ export declare class StateManager {
629
642
  * @param updates - Partial score fields to merge
630
643
  */
631
644
  updateRepoScore(repo: string, updates: RepoScoreUpdate): void;
645
+ /** Record each repo's outcome evidence; see repoScoring.restoreUnchangedEvaluations. */
646
+ snapshotRepoOutcomes(): repoScoring.OutcomeSnapshot;
647
+ /**
648
+ * Put back `lastEvaluatedAt` for repos whose outcome evidence ends where
649
+ * `snapshot` found it, so a count written in several steps that nets to no
650
+ * change does not count as a re-evaluation (#2045).
651
+ */
652
+ restoreUnchangedEvaluations(snapshot: repoScoring.OutcomeSnapshot): void;
632
653
  /** Returns repository names that have at least one merged PR. */
633
654
  getReposWithMergedPRs(): string[];
634
655
  /** Returns repository names with open PRs but no merged PRs yet. */
@@ -6,6 +6,7 @@
6
6
  import * as fs from 'node:fs';
7
7
  import { AgentStateSchema, GuidelinesReviewSchema } from './state-schema.js';
8
8
  import { activeWorkClaims, finishWorkClaim, workClaimKey } from './work-claims.js';
9
+ import { PACING_WINDOW_MS, isoAt } from './pacing.js';
9
10
  import { serializeState } from './state-prune.js';
10
11
  import { loadState, saveState, reloadStateIfChanged, createFreshState, atomicWriteFileSync, assertNotNewerVersion, warnMalformedWorkClaims, } from './state-persistence.js';
11
12
  import * as repoScoring from './repo-score-manager.js';
@@ -983,6 +984,22 @@ export class StateManager {
983
984
  this.autoSave();
984
985
  }
985
986
  }
987
+ /**
988
+ * Stamp a written guideline proposal on the merged or closed PR matching
989
+ * `url` (#2041). `machineId` is omitted when this machine has none.
990
+ * No-op when no PR with that URL is stored.
991
+ */
992
+ markPRLearningsProposed(url, proposedAt, machineId) {
993
+ const entry = this.state.mergedPRs?.find((pr) => pr.url === url) ?? this.state.closedPRs?.find((pr) => pr.url === url);
994
+ if (!entry)
995
+ return;
996
+ entry.learningsProposedAt = proposedAt;
997
+ if (machineId === undefined)
998
+ delete entry.learningsProposedOn;
999
+ else
1000
+ entry.learningsProposedOn = machineId;
1001
+ this.autoSave();
1002
+ }
986
1003
  // === Configuration ===
987
1004
  /**
988
1005
  * Merge partial config updates into the current configuration.
@@ -1449,6 +1466,23 @@ export class StateManager {
1449
1466
  }
1450
1467
  return released;
1451
1468
  }
1469
+ /**
1470
+ * Record a PR the tool just opened (#1911) so the pacing caps count it
1471
+ * before the next `daily`. Idempotent per URL (the first open time is
1472
+ * kept); entries older than the 24-hour window are pruned in the same write.
1473
+ * @returns true when the PR was not recorded yet
1474
+ */
1475
+ recordNewPR(url, nowMs = Date.now()) {
1476
+ const key = url.toLowerCase();
1477
+ // A stamp from a host whose clock runs ahead is stored as now, so it ages out like the others.
1478
+ const kept = (this.state.recentNewPRs ?? [])
1479
+ .map((e) => (Date.parse(e.openedAt) > nowMs ? { ...e, openedAt: isoAt(nowMs) } : e))
1480
+ .filter((e) => Date.parse(e.openedAt) > nowMs - PACING_WINDOW_MS);
1481
+ const isNew = kept.every((e) => e.url.toLowerCase() !== key);
1482
+ this.state.recentNewPRs = isNew ? [...kept, { url, openedAt: isoAt(nowMs) }] : kept;
1483
+ this.autoSave();
1484
+ return isNew;
1485
+ }
1452
1486
  setStatusOverride(url, status, lastActivityAt) {
1453
1487
  if (!this.state.config.statusOverrides) {
1454
1488
  this.state.config.statusOverrides = {};
@@ -1512,6 +1546,19 @@ export class StateManager {
1512
1546
  repoScoring.updateRepoScore(this.state, repo, updates);
1513
1547
  this.autoSave();
1514
1548
  }
1549
+ /** Record each repo's outcome evidence; see repoScoring.restoreUnchangedEvaluations. */
1550
+ snapshotRepoOutcomes() {
1551
+ return repoScoring.snapshotOutcomes(this.state);
1552
+ }
1553
+ /**
1554
+ * Put back `lastEvaluatedAt` for repos whose outcome evidence ends where
1555
+ * `snapshot` found it, so a count written in several steps that nets to no
1556
+ * change does not count as a re-evaluation (#2045).
1557
+ */
1558
+ restoreUnchangedEvaluations(snapshot) {
1559
+ if (repoScoring.restoreUnchangedEvaluations(this.state, snapshot) > 0)
1560
+ this.autoSave();
1561
+ }
1515
1562
  /** Returns repository names that have at least one merged PR. */
1516
1563
  getReposWithMergedPRs() {
1517
1564
  return repoScoring.getReposWithMergedPRs(this.state);
@@ -194,21 +194,23 @@ function determinePrimaryStatus(input) {
194
194
  const commitDate = resolveContributorCommitDate(input);
195
195
  // Priority order: needs_addressing (response/changes/ci/conflict/checklist) > waiting_on_maintainer (review/merge/addressed/ci_blocked)
196
196
  if (hasUnrespondedComment) {
197
- if (isCommentAddressedByCommit(commitDate, lastMaintainerCommentDate, latestChangesRequestedDate)) {
198
- if (ciStatus === 'failing' && hasActionableCIFailure)
199
- return { status: 'needs_addressing', actionReason: 'failing_ci', stalenessTier };
200
- // Non-actionable CI failures (infrastructure, fork, auth) don't block changes_addressed —
201
- // the contributor can't fix them, so the relevant status is "waiting for re-review" (#502)
202
- return { status: 'waiting_on_maintainer', waitReason: 'changes_addressed', stalenessTier };
203
- }
204
197
  // An unresponded comment its own author's approval settles is an
205
198
  // approval/LGTM note (e.g. a re-approval dated after the contributor's last
206
199
  // commit), not a request for changes. It needs no contributor response, so
207
200
  // the PR is waiting to be merged: don't trap it in needs_response (#1507).
208
- // Any other comment on an approved PR still needs one (#1920).
201
+ // Any other comment on an approved PR still needs one (#1920). Checked
202
+ // before the addressed-by-commit branch: once the commenter has approved
203
+ // the commit that answered them, the PR awaits merge, not re-review (#2044).
209
204
  if (isCommentSettledByApproval(input)) {
210
205
  return { status: 'waiting_on_maintainer', waitReason: 'pending_merge', stalenessTier };
211
206
  }
207
+ if (isCommentAddressedByCommit(commitDate, lastMaintainerCommentDate, latestChangesRequestedDate)) {
208
+ if (ciStatus === 'failing' && hasActionableCIFailure)
209
+ return { status: 'needs_addressing', actionReason: 'failing_ci', stalenessTier };
210
+ // Non-actionable CI failures (infrastructure, fork, auth) don't block changes_addressed —
211
+ // the contributor can't fix them, so the relevant status is "waiting for re-review" (#502)
212
+ return { status: 'waiting_on_maintainer', waitReason: 'changes_addressed', stalenessTier };
213
+ }
212
214
  return { status: 'needs_addressing', actionReason: 'needs_response', stalenessTier };
213
215
  }
214
216
  // Review requested changes but no unresponded comment.
@@ -113,9 +113,9 @@ export declare function fenceFetchedPR<T extends FenceablePR>(pr: T): T;
113
113
  export declare function fenceFetchedPRTitles<T extends FenceableTitledPR>(pr: T): T;
114
114
  /**
115
115
  * Fence every non-empty PR/issue title and branch-ref string anywhere in an
116
- * MCP tool result (#1931). Tool results reach an arbitrary MCP host LLM
117
- * that never sees the "Prompt Injection Awareness" block, the same reason
118
- * {@link fenceFetchedPRTitles} exists for resources and prompts, but tool
116
+ * MCP tool result (#1931), and each label of an issue or PR row (#2046).
117
+ * Tool results reach an arbitrary MCP host LLM that never sees the "Prompt
118
+ * Injection Awareness" block, the same reason {@link fenceFetchedPRTitles} exists for resources and prompts, but tool
119
119
  * payloads have no single shape, so this walks the whole value and matches
120
120
  * by key. Field names and types are unchanged; only the string values gain
121
121
  * the fence. Never skips a value that already looks fenced: an attacker can
@@ -197,11 +197,24 @@ function titleLabel(obj) {
197
197
  }
198
198
  return 'github';
199
199
  }
200
+ /**
201
+ * The `labels` of an issue or PR row (an object with a numeric `number` and a
202
+ * string `url`): set by the repo's maintainers, so fenced like titles (#2046).
203
+ * Rows without both keys are left alone, so the user's own configured
204
+ * `labels` (config, setup) stay raw.
205
+ */
206
+ function fenceRowLabels(obj, labels, label) {
207
+ if (typeof obj.number !== 'number' || typeof obj.url !== 'string')
208
+ return labels.map((l) => fenceTitlesDeep(l));
209
+ return labels.map((name) => typeof name === 'string' && name !== ''
210
+ ? wrapUntrustedContent(name, label, { source: 'issue-label' })
211
+ : fenceTitlesDeep(name));
212
+ }
200
213
  /**
201
214
  * Fence every non-empty PR/issue title and branch-ref string anywhere in an
202
- * MCP tool result (#1931). Tool results reach an arbitrary MCP host LLM
203
- * that never sees the "Prompt Injection Awareness" block, the same reason
204
- * {@link fenceFetchedPRTitles} exists for resources and prompts, but tool
215
+ * MCP tool result (#1931), and each label of an issue or PR row (#2046).
216
+ * Tool results reach an arbitrary MCP host LLM that never sees the "Prompt
217
+ * Injection Awareness" block, the same reason {@link fenceFetchedPRTitles} exists for resources and prompts, but tool
205
218
  * payloads have no single shape, so this walks the whole value and matches
206
219
  * by key. Field names and types are unchanged; only the string values gain
207
220
  * the fence. Never skips a value that already looks fenced: an attacker can
@@ -222,14 +235,19 @@ export function fenceTitlesDeep(value) {
222
235
  const label = titleLabel(obj);
223
236
  const out = {};
224
237
  for (const [key, field] of Object.entries(obj)) {
225
- const source = TITLE_KEY_SOURCES.get(key);
226
- out[key] =
227
- source !== undefined && typeof field === 'string' && field !== ''
228
- ? wrapUntrustedContent(field, label, { source })
229
- : fenceTitlesDeep(field);
238
+ out[key] = fenceEntry(obj, key, field, label);
230
239
  }
231
240
  return out;
232
241
  }
242
+ /** One entry of a result object `obj`, fenced by {@link fenceTitlesDeep}'s rules. */
243
+ function fenceEntry(obj, key, field, label) {
244
+ if (key === 'labels' && Array.isArray(field))
245
+ return fenceRowLabels(obj, field, label);
246
+ const source = TITLE_KEY_SOURCES.get(key);
247
+ return source !== undefined && typeof field === 'string' && field !== ''
248
+ ? wrapUntrustedContent(field, label, { source })
249
+ : fenceTitlesDeep(field);
250
+ }
233
251
  /**
234
252
  * Provenance preamble for stored per-repo guidelines (#1455). Guidelines are
235
253
  * LLM-distilled from a corpus of public PR comments — an untrusted source —
@@ -85,3 +85,27 @@ export declare function splitRepo(repoFullName: string): {
85
85
  export declare function isOwnRepo(owner: string, username: string): boolean;
86
86
  /** True when `owner` is listed in `config.untrackedOrgs` (case-insensitive). */
87
87
  export declare function isUntrackedOrg(owner: string, untrackedOrgs?: readonly string[]): boolean;
88
+ /** GitHub's PR body limit. */
89
+ export declare const MAX_BODY_CHARS = 65536;
90
+ /**
91
+ * Markdown with its HTML comments and code (fenced and inline) blanked out:
92
+ * the text GitHub links refs in, and where PR templates keep example
93
+ * `Fixes #123` lines. Each match of
94
+ * `/<!--[\s\S]*?-->|```[\s\S]*?```|(`+)[^`]*\1/g` becomes one space, but in
95
+ * linear time: that regex rescans to the end from every unclosed opener.
96
+ */
97
+ export declare function stripNonProse(markdown: string): string;
98
+ /** One closing reference: `repo` is the `owner/repo` the text names, null for a bare `#N`. */
99
+ export interface ClosingRef {
100
+ repo: string | null;
101
+ number: number;
102
+ }
103
+ /**
104
+ * Issues `text` closes with a GitHub closing keyword (#2048), in order of
105
+ * appearance. With `markdown` (a PR body), HTML comments and code are
106
+ * skipped and only the first {@link MAX_BODY_CHARS} characters are read, as
107
+ * GitHub links nothing there; without it (a commit message) every line counts.
108
+ */
109
+ export declare function findClosingRefs(text: string, options?: {
110
+ markdown?: boolean;
111
+ }): ClosingRef[];
package/dist/core/urls.js CHANGED
@@ -138,3 +138,79 @@ export function isUntrackedOrg(owner, untrackedOrgs = []) {
138
138
  const ownerLower = owner.toLowerCase();
139
139
  return untrackedOrgs.some((org) => org.toLowerCase() === ownerLower);
140
140
  }
141
+ /** GitHub's PR body limit. */
142
+ export const MAX_BODY_CHARS = 65_536;
143
+ function commentEnd(text, i, closers) {
144
+ if (!closers.comment || !text.startsWith('<!--', i))
145
+ return -1;
146
+ const close = text.indexOf('-->', i + 4);
147
+ if (close === -1)
148
+ closers.comment = false;
149
+ return close === -1 ? -1 : close + 3;
150
+ }
151
+ function fenceEnd(text, i, closers) {
152
+ if (!closers.fence || !text.startsWith('```', i))
153
+ return -1;
154
+ const close = text.indexOf('```', i + 3);
155
+ if (close === -1)
156
+ closers.fence = false;
157
+ return close === -1 ? -1 : close + 3;
158
+ }
159
+ /** A run of N backticks closed by the next N; failing that, half the run closes the other half. */
160
+ function codeSpanEnd(text, i) {
161
+ let run = 0;
162
+ while (text[i + run] === '`')
163
+ run++;
164
+ if (run === 0)
165
+ return -1;
166
+ const close = text.indexOf('`', i + run);
167
+ if (close !== -1 && text.startsWith('`'.repeat(run), close))
168
+ return close + run;
169
+ return run >= 2 ? i + 2 * Math.floor(run / 2) : -1;
170
+ }
171
+ /**
172
+ * Markdown with its HTML comments and code (fenced and inline) blanked out:
173
+ * the text GitHub links refs in, and where PR templates keep example
174
+ * `Fixes #123` lines. Each match of
175
+ * `/<!--[\s\S]*?-->|```[\s\S]*?```|(`+)[^`]*\1/g` becomes one space, but in
176
+ * linear time: that regex rescans to the end from every unclosed opener.
177
+ */
178
+ export function stripNonProse(markdown) {
179
+ const closers = { comment: true, fence: true };
180
+ let out = '';
181
+ let prose = 0;
182
+ let i = 0;
183
+ while (i < markdown.length) {
184
+ const end = Math.max(commentEnd(markdown, i, closers), fenceEnd(markdown, i, closers));
185
+ const span = end === -1 ? codeSpanEnd(markdown, i) : end;
186
+ if (span === -1) {
187
+ i++;
188
+ }
189
+ else {
190
+ out += `${markdown.slice(prose, i)} `;
191
+ prose = span;
192
+ i = span;
193
+ }
194
+ }
195
+ return out + markdown.slice(prose);
196
+ }
197
+ /**
198
+ * GitHub's closing keyword (close, closes, closed, fix, fixes, fixed, resolve,
199
+ * resolves, resolved; any case), an optional colon, then one ref: `#12`,
200
+ * `owner/repo#12` or an issue URL. Each ref needs its own keyword, as on
201
+ * GitHub, so `Fixes #1, #2` closes only #1.
202
+ */
203
+ const CLOSING_REF_RE = /\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)(?::\s*|\s+)(?:https?:\/\/github\.com\/([\w.-]+\/[\w.-]+)\/issues\/(\d+)|([\w.-]+\/[\w.-]+)?#(\d+))\b/gi;
204
+ /**
205
+ * Issues `text` closes with a GitHub closing keyword (#2048), in order of
206
+ * appearance. With `markdown` (a PR body), HTML comments and code are
207
+ * skipped and only the first {@link MAX_BODY_CHARS} characters are read, as
208
+ * GitHub links nothing there; without it (a commit message) every line counts.
209
+ */
210
+ export function findClosingRefs(text, options = {}) {
211
+ const scanned = options.markdown ? stripNonProse(text.slice(0, MAX_BODY_CHARS)) : text;
212
+ return Array.from(scanned.matchAll(CLOSING_REF_RE), (m) => ({
213
+ repo: m[1] ?? m[3] ?? null,
214
+ number: Number(m[2] ?? m[4]),
215
+ }));
216
+ }