@oss-autopilot/core 3.34.0 → 3.35.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.
@@ -19,7 +19,7 @@
19
19
  */
20
20
  import * as fs from 'node:fs';
21
21
  import * as path from 'node:path';
22
- import { classifyCloseReason } from '../core/close-reason.js';
22
+ import { classifyCloseReason, classifySelfClose } from '../core/close-reason.js';
23
23
  import { errorMessage, isRateLimitOrAuthError } from '../core/errors.js';
24
24
  import { getOctokit, requireGitHubToken, getStateManager, parseGitHubUrl } from '../core/index.js';
25
25
  import { isGraphqlRateLimited } from '../core/pr-graphql.js';
@@ -135,10 +135,14 @@ export async function runLedgerBackfill(options = {}) {
135
135
  if (!listPath)
136
136
  warnings.push('no curated issue list found; list vet scores were not imported');
137
137
  const lists = listPath ? readListFiles(listPath, warnings) : [];
138
- // 1. GitHub: openedAt, closing issue, close reason, for entries not yet backfilled.
139
- const needsFetch = [...stateManager.getMergedPRs(), ...stateManager.getClosedPRs()]
140
- .filter((e) => !e.backfilledAt)
141
- .map((e) => e.url);
138
+ // 1. GitHub: openedAt, closing issue, close reason, for entries not yet
139
+ // backfilled, plus self-closed entries recorded before selfCloseReason existed.
140
+ const needsFetch = [
141
+ ...stateManager.getMergedPRs().filter((e) => !e.backfilledAt),
142
+ ...stateManager
143
+ .getClosedPRs()
144
+ .filter((e) => !e.backfilledAt || (e.closeReason === 'self-closed' && !e.selfCloseReason)),
145
+ ].map((e) => e.url);
142
146
  const nodes = new Map();
143
147
  let fatal;
144
148
  if (needsFetch.length > 0) {
@@ -185,15 +189,17 @@ export async function runLedgerBackfill(options = {}) {
185
189
  const node = nodes.get(e.url);
186
190
  const closedEvent = node?.timelineItems?.nodes.at(-1);
187
191
  // No closed event in the answer: leave the reason unset rather than guess.
188
- const closeReason = closedEvent
189
- ? classifyCloseReason({
192
+ const context = closedEvent
193
+ ? {
190
194
  author: node?.author?.login,
191
195
  closer: closedEvent.actor?.login,
192
196
  closerIsBot: closedEvent.actor?.__typename === 'Bot',
193
197
  comments: (node?.comments?.nodes ?? []).flatMap((c) => c ? [{ author: c.author?.login, isBot: c.author?.__typename === 'Bot', body: c.body }] : []),
194
- })
198
+ }
195
199
  : undefined;
196
- return { url: e.url, title: e.title, closedAt: e.closedAt, ...recovered(e), closeReason };
200
+ const closeReason = context && classifyCloseReason(context);
201
+ const selfCloseReason = context && (e.closeReason ?? closeReason) === 'self-closed' ? classifySelfClose(context) : undefined;
202
+ return { url: e.url, title: e.title, closedAt: e.closedAt, ...recovered(e), closeReason, selfCloseReason };
197
203
  }));
198
204
  });
199
205
  const after = countFilled([...stateManager.getMergedPRs(), ...stateManager.getClosedPRs()]);
@@ -11,6 +11,12 @@
11
11
  */
12
12
  export declare const CLOSE_REASONS: readonly ["ai-policy", "superseded", "stale", "self-closed", "rejected", "unknown"];
13
13
  export type CloseReason = (typeof CLOSE_REASONS)[number];
14
+ /**
15
+ * Why the author closed their own PR (#1824): the "self-closed" bucket is
16
+ * most closures, and "I withdrew it" hides three different stories.
17
+ */
18
+ export declare const SELF_CLOSE_REASONS: readonly ["superseded", "no-traction", "after-feedback", "no-response"];
19
+ export type SelfCloseReason = (typeof SELF_CLOSE_REASONS)[number];
14
20
  export interface CloseContext {
15
21
  author?: string;
16
22
  /** Login of whoever closed the PR; undefined when GitHub reports no actor (ghost). */
@@ -22,4 +28,9 @@ export interface CloseContext {
22
28
  body: string;
23
29
  }>;
24
30
  }
31
+ /**
32
+ * Split an author-closed PR by what preceded the close. Call only when
33
+ * {@link classifyCloseReason} returned 'self-closed'.
34
+ */
35
+ export declare function classifySelfClose({ author, comments }: CloseContext): SelfCloseReason;
25
36
  export declare function classifyCloseReason({ author, closer, closerIsBot, comments }: CloseContext): CloseReason;
@@ -10,10 +10,38 @@
10
10
  * `rejected` turns out to hide distinct causes worth separating.
11
11
  */
12
12
  export const CLOSE_REASONS = ['ai-policy', 'superseded', 'stale', 'self-closed', 'rejected', 'unknown'];
13
+ /**
14
+ * Why the author closed their own PR (#1824): the "self-closed" bucket is
15
+ * most closures, and "I withdrew it" hides three different stories.
16
+ */
17
+ export const SELF_CLOSE_REASONS = ['superseded', 'no-traction', 'after-feedback', 'no-response'];
13
18
  // Policy phrasing only: a bare "AI" or "Claude" shows up in ordinary review talk.
14
19
  const AI_POLICY_RE = /\b(?:AI|LLM)[- ](?:generated|written|authored|slop|polic(?:y|ies))|(?:generated|written) (?:by|with) (?:an? )?(?:AI|LLM|ChatGPT|Copilot)\b|vibe[- ]?cod|machine[- ]generated/i;
15
- const SUPERSEDED_RE = /clos(?:e|ing) (?:this )?as (?:a )?duplicate|duplicate of #\d+|superseded by|already (?:been )?(?:fixed|merged|addressed|resolved|implemented)|fixed (?:in|by|via) #\d+|in fav(?:ou)?r of #\d+/i;
20
+ const SUPERSEDED_RE = /clos(?:e|ing) (?:this )?as (?:a )?duplicate|duplicate of #\d+|superseded by|already (?:been )?(?:fixed|merged|addressed|resolved|implemented)|fixed (?:in|by|via) #\d+|in favou?r of #\d+/i;
16
21
  const STALE_RE = /marked as stale|clos(?:e|ing) (?:this )?(?:as|due to) (?:stale|inactiv)|no activity (?:for|in)/i;
22
+ // The author's own explanation, phrased the way real closing comments are:
23
+ // "v0.6 covers this", "#1684 landed the same fix", "#1408 is in", "in favor of #6087".
24
+ const AUTHOR_SUPERSEDED = [
25
+ /already (?:been )?(?:fixed|merged|addressed|resolved|implemented|landed|applied|several)/i,
26
+ /cover(?:s|ed) (?:this|everything|the same)|same (?:one-line )?fix|(?:landed|fixed|ships?) the same/i,
27
+ /has (?:landed|shipped)|is in and|(?:fixed|addressed|resolved|landed|applied) (?:upstream|elsewhere)/i,
28
+ /upstream (?:upgrade|commit|fix)|supersed|in favou?r of|replaced by|duplicate/i,
29
+ /no longer (?:needed|relevant|reproduc|applies)/i,
30
+ ];
31
+ // Withdrawn because nobody picked it up.
32
+ const NO_TRACTION_RE = /traction|(?:been )?quiet|unmaintained|actively (?:reviewing|maintained)|not maintained|no (?:response|activity)|keep the queue tidy|sitting in (?:your|the) queue|stale/i;
33
+ /**
34
+ * Split an author-closed PR by what preceded the close. Call only when
35
+ * {@link classifyCloseReason} returned 'self-closed'.
36
+ */
37
+ export function classifySelfClose({ author, comments }) {
38
+ const own = comments.filter((c) => !c.isBot && c.author === author).map((c) => c.body);
39
+ if (own.some((b) => AUTHOR_SUPERSEDED.some((re) => re.test(b))))
40
+ return 'superseded';
41
+ if (own.some((b) => NO_TRACTION_RE.test(b)))
42
+ return 'no-traction';
43
+ return comments.some((c) => !c.isBot && c.author !== author) ? 'after-feedback' : 'no-response';
44
+ }
17
45
  export function classifyCloseReason({ author, closer, closerIsBot, comments }) {
18
46
  const human = comments.filter((c) => !c.isBot && c.author !== author).map((c) => c.body);
19
47
  if (human.some((b) => AI_POLICY_RE.test(b)))
@@ -102,6 +102,7 @@ function collectRows(state) {
102
102
  outcome: 'closed',
103
103
  month: e.closedAt.slice(0, 7),
104
104
  closeReason: e.closeReason,
105
+ selfCloseReason: e.selfCloseReason,
105
106
  }));
106
107
  const dormant = (state.lastDigest?.openPRs ?? [])
107
108
  .filter((pr) => pr.stalenessTier === 'dormant')
@@ -122,7 +123,8 @@ export function computeEvalReport(state, now = new Date()) {
122
123
  const closeReasons = {};
123
124
  const approachClosuresByMonth = {};
124
125
  for (const r of closedRows) {
125
- const reason = r.closeReason ?? 'unclassified';
126
+ // Self-closed splits by what preceded it, e.g. "self-closed: no-response".
127
+ const reason = r.selfCloseReason ? `self-closed: ${r.selfCloseReason}` : (r.closeReason ?? 'unclassified');
126
128
  closeReasons[reason] = (closeReasons[reason] ?? 0) + 1;
127
129
  if ((r.closeReason === 'ai-policy' || r.closeReason === 'rejected') && r.month) {
128
130
  approachClosuresByMonth[r.month] = (approachClosuresByMonth[r.month] ?? 0) + 1;
@@ -46,7 +46,7 @@
46
46
  * a freeform-only push needs no re-read and cannot clobber another file.
47
47
  */
48
48
  import * as fs from 'node:fs';
49
- import { AgentStateSchema } from './state-schema.js';
49
+ import { AgentStateSchema, NEWER_WRITER_HINT, unknownStateKeys } from './state-schema.js';
50
50
  import { serializeState } from './state-prune.js';
51
51
  import { atomicWriteFileSync, createFreshState, migrateV1ToV2, migrateV2ToV3, migrateV3ToV4, } from './state-persistence.js';
52
52
  import { getGistIdPath, getStateCachePath } from './paths.js';
@@ -755,6 +755,9 @@ export class GistStateStore {
755
755
  if (obj.version === 3)
756
756
  obj = migrateV3ToV4(obj);
757
757
  }
758
+ const newer = unknownStateKeys(obj);
759
+ if (newer.length > 0)
760
+ warn(MODULE, `Gist state (fields: ${newer.join(', ')}) ${NEWER_WRITER_HINT}`);
758
761
  return AgentStateSchema.parse(obj);
759
762
  }
760
763
  catch (err) {
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import * as fs from 'node:fs';
7
7
  import * as path from 'node:path';
8
- import { AgentStateSchema } from './state-schema.js';
8
+ import { AgentStateSchema, NEWER_WRITER_HINT, unknownStateKeys } from './state-schema.js';
9
9
  import { serializeState } from './state-prune.js';
10
10
  import { getStatePath, getBackupDir, getDataDir, getLegacyStatePath, getLegacyBackupDir } from './paths.js';
11
11
  import { errorMessage, ConcurrencyError } from './errors.js';
@@ -378,7 +378,11 @@ export function loadState() {
378
378
  wasMigrated = true;
379
379
  }
380
380
  }
381
- // Validate through Zod schema (strips unknown keys in memory; stale keys persist on disk until next save)
381
+ // Validate through Zod schema. Unknown keys pass through (#1831): they
382
+ // come from a newer release and must survive this version's next save.
383
+ const newer = unknownStateKeys(raw);
384
+ if (newer.length > 0)
385
+ warn(MODULE, `State file (fields: ${newer.join(', ')}) ${NEWER_WRITER_HINT}`);
382
386
  const parsed = AgentStateSchema.safeParse(raw);
383
387
  if (!parsed.success) {
384
388
  const summary = parsed.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join('; ');