@oss-autopilot/core 3.42.5 → 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.
- package/dist/cli-pre-action.js +8 -3
- package/dist/cli-registry.js +428 -27
- package/dist/cli.bundle.cjs +212 -156
- package/dist/commands/check-integration.js +5 -1
- package/dist/commands/cleanup.d.ts +80 -0
- package/dist/commands/cleanup.js +334 -0
- package/dist/commands/comments.d.ts +14 -1
- package/dist/commands/comments.js +17 -5
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +63 -6
- package/dist/commands/daily-dismiss-filter.d.ts +7 -0
- package/dist/commands/daily-dismiss-filter.js +17 -1
- package/dist/commands/daily-ledger.d.ts +150 -0
- package/dist/commands/daily-ledger.js +248 -0
- package/dist/commands/daily-recent-prs.d.ts +26 -0
- package/dist/commands/daily-recent-prs.js +55 -0
- package/dist/commands/daily-render.d.ts +2 -1
- package/dist/commands/daily-render.js +4 -1
- package/dist/commands/daily.d.ts +5 -1
- package/dist/commands/daily.js +83 -93
- package/dist/commands/dashboard-cache.d.ts +2 -0
- package/dist/commands/dashboard-cache.js +33 -8
- package/dist/commands/dashboard-data.js +113 -69
- package/dist/commands/dashboard-gist-sync.js +3 -1
- package/dist/commands/dashboard-lifecycle.d.ts +36 -8
- package/dist/commands/dashboard-lifecycle.js +132 -39
- package/dist/commands/dashboard-process.d.ts +49 -1
- package/dist/commands/dashboard-process.js +111 -12
- package/dist/commands/dashboard-server.js +89 -23
- package/dist/commands/detect-formatters.js +1 -0
- package/dist/commands/dismiss.js +11 -7
- package/dist/commands/doctor.d.ts +15 -1
- package/dist/commands/doctor.js +66 -5
- package/dist/commands/draft.d.ts +77 -0
- package/dist/commands/draft.js +218 -0
- package/dist/commands/eval.js +1 -0
- package/dist/commands/fork-prune.d.ts +58 -0
- package/dist/commands/fork-prune.js +247 -0
- package/dist/commands/guidelines.d.ts +69 -2
- package/dist/commands/guidelines.js +158 -14
- package/dist/commands/index.d.ts +29 -4
- package/dist/commands/index.js +20 -3
- package/dist/commands/issue-thread.d.ts +46 -0
- package/dist/commands/issue-thread.js +123 -0
- package/dist/commands/ledger-backfill.d.ts +9 -0
- package/dist/commands/ledger-backfill.js +44 -1
- package/dist/commands/list-mark-done.d.ts +2 -1
- package/dist/commands/list-mark-done.js +3 -1
- package/dist/commands/list-move-tier.d.ts +2 -1
- package/dist/commands/list-move-tier.js +3 -1
- package/dist/commands/local-repos.js +10 -5
- package/dist/commands/locate-issue-list.d.ts +40 -17
- package/dist/commands/locate-issue-list.js +148 -88
- package/dist/commands/move.js +7 -1
- package/dist/commands/overnight-handoff.d.ts +17 -7
- package/dist/commands/overnight-handoff.js +36 -14
- package/dist/commands/overnight-push-prep.d.ts +14 -8
- package/dist/commands/overnight-push-prep.js +107 -35
- package/dist/commands/overnight-tool-rules.d.ts +54 -0
- package/dist/commands/overnight-tool-rules.js +217 -0
- package/dist/commands/overnight.d.ts +5 -6
- package/dist/commands/overnight.js +61 -140
- package/dist/commands/parse-list.js +7 -1
- package/dist/commands/policy.d.ts +90 -0
- package/dist/commands/policy.js +276 -0
- package/dist/commands/pr-create.d.ts +48 -0
- package/dist/commands/pr-create.js +200 -0
- package/dist/commands/pr-preflight.d.ts +69 -0
- package/dist/commands/pr-preflight.js +348 -0
- package/dist/commands/repo-vet.d.ts +9 -0
- package/dist/commands/repo-vet.js +36 -11
- package/dist/commands/scout-bridge.js +18 -8
- package/dist/commands/search.js +7 -0
- package/dist/commands/setup.d.ts +3 -3
- package/dist/commands/setup.js +160 -48
- package/dist/commands/skip-add.js +10 -1
- package/dist/commands/startup.d.ts +12 -3
- package/dist/commands/startup.js +82 -49
- package/dist/commands/state-cmd.d.ts +2 -0
- package/dist/commands/state-cmd.js +5 -1
- package/dist/commands/stats.js +1 -0
- package/dist/commands/status.js +6 -0
- package/dist/commands/strategy.js +1 -0
- package/dist/commands/validation.d.ts +5 -0
- package/dist/commands/validation.js +5 -0
- package/dist/commands/vet-list.d.ts +6 -0
- package/dist/commands/vet-list.js +26 -1
- package/dist/commands/vet.d.ts +20 -0
- package/dist/commands/vet.js +133 -2
- package/dist/commands/work.d.ts +4 -0
- package/dist/commands/work.js +34 -11
- package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
- package/dist/core/anti-llm-policy.d.ts +3 -0
- package/dist/core/anti-llm-policy.js +3 -0
- package/dist/core/auth.js +2 -0
- package/dist/core/ci-analysis.d.ts +7 -2
- package/dist/core/ci-analysis.js +76 -21
- package/dist/core/commit-date.d.ts +45 -0
- package/dist/core/commit-date.js +45 -0
- package/dist/core/compliance-score.d.ts +3 -0
- package/dist/core/compliance-score.js +13 -9
- package/dist/core/config-registry.d.ts +27 -2
- package/dist/core/config-registry.js +94 -7
- package/dist/core/contributing.d.ts +2 -3
- package/dist/core/contributing.js +2 -3
- package/dist/core/daily-logic.d.ts +30 -5
- package/dist/core/daily-logic.js +68 -19
- package/dist/core/errors.d.ts +37 -3
- package/dist/core/errors.js +54 -5
- package/dist/core/fork-prune.d.ts +149 -0
- package/dist/core/fork-prune.js +333 -0
- package/dist/core/gist-health.d.ts +15 -3
- package/dist/core/gist-health.js +8 -0
- package/dist/core/gist-state-store.d.ts +24 -4
- package/dist/core/gist-state-store.js +98 -51
- package/dist/core/github-stats.d.ts +110 -16
- package/dist/core/github-stats.js +295 -110
- package/dist/core/http-cache.d.ts +0 -10
- package/dist/core/http-cache.js +0 -19
- package/dist/core/index.d.ts +13 -6
- package/dist/core/index.js +16 -6
- package/dist/core/issue-conversation.d.ts +8 -2
- package/dist/core/issue-conversation.js +31 -12
- package/dist/core/local-config.d.ts +95 -0
- package/dist/core/local-config.js +270 -0
- package/dist/core/merged-pr-notes.d.ts +2 -2
- package/dist/core/pacing.d.ts +41 -0
- package/dist/core/pacing.js +115 -0
- package/dist/core/pagination.d.ts +55 -0
- package/dist/core/pagination.js +59 -0
- package/dist/core/paths.d.ts +7 -0
- package/dist/core/paths.js +9 -0
- package/dist/core/pr-assembly.d.ts +2 -0
- package/dist/core/pr-assembly.js +6 -2
- package/dist/core/pr-graphql.d.ts +53 -4
- package/dist/core/pr-graphql.js +87 -14
- package/dist/core/pr-monitor.d.ts +35 -12
- package/dist/core/pr-monitor.js +110 -26
- package/dist/core/pr-preflight.d.ts +154 -0
- package/dist/core/pr-preflight.js +753 -0
- package/dist/core/pr-quality-rubric.d.ts +0 -6
- package/dist/core/pr-quality-rubric.js +0 -8
- package/dist/core/pr-template.d.ts +2 -0
- package/dist/core/pr-template.js +5 -1
- package/dist/core/prose-script.d.ts +72 -0
- package/dist/core/prose-script.js +223 -0
- package/dist/core/repo-policy.d.ts +111 -0
- package/dist/core/repo-policy.js +428 -0
- package/dist/core/repo-score-manager.d.ts +66 -0
- package/dist/core/repo-score-manager.js +140 -1
- package/dist/core/review-analysis.d.ts +49 -21
- package/dist/core/review-analysis.js +89 -15
- package/dist/core/reviewed-prs-fetch.js +11 -29
- package/dist/core/reviewed-prs.js +8 -15
- package/dist/core/stale-data.d.ts +78 -0
- package/dist/core/stale-data.js +153 -0
- package/dist/core/state-persistence.d.ts +62 -27
- package/dist/core/state-persistence.js +338 -119
- package/dist/core/state-schema.d.ts +152 -210
- package/dist/core/state-schema.js +232 -80
- package/dist/core/state.d.ts +81 -8
- package/dist/core/state.js +239 -46
- package/dist/core/status-determination.js +32 -12
- package/dist/core/strategy.js +3 -1
- package/dist/core/types.d.ts +22 -1
- package/dist/core/types.js +1 -0
- package/dist/core/untrusted-content.d.ts +30 -11
- package/dist/core/untrusted-content.js +95 -42
- package/dist/core/urls.d.ts +33 -0
- package/dist/core/urls.js +94 -0
- package/dist/dashboard/assets/chart-panel-B-nLVgzQ.js +3 -0
- package/dist/dashboard/assets/index-5IvMGokL.js +55 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/formatters/json.d.ts +432 -10
- package/dist/formatters/json.js +156 -1
- package/package.json +6 -6
- package/dist/core/ci-enforced-tools.d.ts +0 -35
- package/dist/core/ci-enforced-tools.js +0 -109
- package/dist/core/comment-decision.d.ts +0 -79
- package/dist/core/comment-decision.js +0 -82
- package/dist/core/extraction-categories.d.ts +0 -55
- package/dist/core/extraction-categories.js +0 -108
- package/dist/core/follow-up-history.d.ts +0 -40
- package/dist/core/follow-up-history.js +0 -71
- package/dist/core/issue-effort.d.ts +0 -29
- package/dist/core/issue-effort.js +0 -47
- package/dist/core/maintainer-hints.d.ts +0 -23
- package/dist/core/maintainer-hints.js +0 -36
- package/dist/core/workflow-state.d.ts +0 -56
- package/dist/core/workflow-state.js +0 -101
- package/dist/dashboard/assets/chart-panel-DPKNBUts.js +0 -3
- package/dist/dashboard/assets/index-B25bZOYX.js +0 -55
package/dist/core/gist-health.js
CHANGED
|
@@ -37,3 +37,11 @@ export function renderGistWarning(cause, opts = {}) {
|
|
|
37
37
|
return (`Gist persistence is configured but ${reason}; writes are LOCAL-ONLY and may be ` +
|
|
38
38
|
`overwritten by the next successful Gist sync.${opts.retryHint ? ` ${opts.retryHint}` : ''}`);
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* The warning for a persistence mode a newer release wrote (#2005). This
|
|
42
|
+
* release cannot sync through that mode, so it runs local-only.
|
|
43
|
+
*/
|
|
44
|
+
export function renderUnknownModeWarning(mode) {
|
|
45
|
+
return (`Persistence mode '${mode}' is from a newer release; this client runs LOCAL-ONLY and writes will not sync. ` +
|
|
46
|
+
'Upgrade oss-autopilot.');
|
|
47
|
+
}
|
|
@@ -8,9 +8,15 @@
|
|
|
8
8
|
* Bootstrap flow:
|
|
9
9
|
* 1. Check for locally stored Gist ID file (`~/.oss-autopilot/gist-id`)
|
|
10
10
|
* 2. If found, fetch that Gist directly via `GET /gists/:id`
|
|
11
|
-
* 3. If
|
|
11
|
+
* 3. If there is no local ID, or that Gist is gone (404), search the user's
|
|
12
|
+
* Gists for a private one with description `oss-autopilot-state`
|
|
12
13
|
* 4. If found via search, store the ID locally and fetch it
|
|
13
|
-
* 5.
|
|
14
|
+
* 5. Only when the search ran to the end of the list (a page with no
|
|
15
|
+
* `rel="next"` link) and found nothing, create a new private Gist with seed
|
|
16
|
+
* files and store the ID. A failed search degrades to the local cache; an
|
|
17
|
+
* unfinished or ambiguous one (list longer than the search window, or only
|
|
18
|
+
* a public match) throws
|
|
19
|
+
* {@link GistDiscoveryError}. Neither creates a Gist (#1926).
|
|
14
20
|
* 6. Cache all Gist file contents in memory for session-scoped reads
|
|
15
21
|
* 7. Write state to a local cache file for fallback
|
|
16
22
|
*
|
|
@@ -96,6 +102,7 @@ export interface OctokitLike {
|
|
|
96
102
|
page: number;
|
|
97
103
|
}) => Promise<{
|
|
98
104
|
data: GistListItem[];
|
|
105
|
+
headers?: Record<string, string | undefined>;
|
|
99
106
|
}>;
|
|
100
107
|
create: (params: {
|
|
101
108
|
description: string;
|
|
@@ -133,6 +140,8 @@ export interface OctokitLike {
|
|
|
133
140
|
interface GistListItem {
|
|
134
141
|
id: string;
|
|
135
142
|
description: string | null;
|
|
143
|
+
public: boolean;
|
|
144
|
+
created_at: string;
|
|
136
145
|
}
|
|
137
146
|
/** Shape of a full Gist response (subset). */
|
|
138
147
|
interface GistResponseData {
|
|
@@ -321,10 +330,21 @@ export declare class GistStateStore {
|
|
|
321
330
|
*/
|
|
322
331
|
private parseStateFromCache;
|
|
323
332
|
/**
|
|
324
|
-
* Search the authenticated user's Gists for one with the
|
|
325
|
-
* Pages through up to 10 pages (100 Gists per page)
|
|
333
|
+
* Search the authenticated user's Gists for the private one with the
|
|
334
|
+
* well-known description. Pages through up to 10 pages (100 Gists per page).
|
|
335
|
+
* The list has ended when a response carries no `rel="next"` Link header;
|
|
336
|
+
* page length is not used, since a short page need not be the last.
|
|
337
|
+
*
|
|
338
|
+
* Returns `null` only when the search ran to the end of the list and found
|
|
339
|
+
* no Gist with the description. The callers create a new Gist on `null`, so
|
|
340
|
+
* anything short of that must not read as "no Gist exists" or this machine
|
|
341
|
+
* forks onto an empty one (#1926): API errors propagate, and a list longer
|
|
342
|
+
* than the search window or a public-only match throws
|
|
343
|
+
* {@link GistDiscoveryError}.
|
|
326
344
|
*/
|
|
327
345
|
private searchForGist;
|
|
346
|
+
/** Pick the oldest of the private state Gists found on a page, warning when there are several. */
|
|
347
|
+
private pickStateGist;
|
|
328
348
|
/**
|
|
329
349
|
* Create a new private Gist with seed files and store it in memory.
|
|
330
350
|
*/
|
|
@@ -8,9 +8,15 @@
|
|
|
8
8
|
* Bootstrap flow:
|
|
9
9
|
* 1. Check for locally stored Gist ID file (`~/.oss-autopilot/gist-id`)
|
|
10
10
|
* 2. If found, fetch that Gist directly via `GET /gists/:id`
|
|
11
|
-
* 3. If
|
|
11
|
+
* 3. If there is no local ID, or that Gist is gone (404), search the user's
|
|
12
|
+
* Gists for a private one with description `oss-autopilot-state`
|
|
12
13
|
* 4. If found via search, store the ID locally and fetch it
|
|
13
|
-
* 5.
|
|
14
|
+
* 5. Only when the search ran to the end of the list (a page with no
|
|
15
|
+
* `rel="next"` link) and found nothing, create a new private Gist with seed
|
|
16
|
+
* files and store the ID. A failed search degrades to the local cache; an
|
|
17
|
+
* unfinished or ambiguous one (list longer than the search window, or only
|
|
18
|
+
* a public match) throws
|
|
19
|
+
* {@link GistDiscoveryError}. Neither creates a Gist (#1926).
|
|
14
20
|
* 6. Cache all Gist file contents in memory for session-scoped reads
|
|
15
21
|
* 7. Write state to a local cache file for fallback
|
|
16
22
|
*
|
|
@@ -47,11 +53,12 @@
|
|
|
47
53
|
*/
|
|
48
54
|
import * as fs from 'node:fs';
|
|
49
55
|
import { AgentStateSchema, NEWER_WRITER_HINT, unknownStateKeys } from './state-schema.js';
|
|
56
|
+
import { preserveRejected } from './stale-data.js';
|
|
50
57
|
import { serializeState } from './state-prune.js';
|
|
51
|
-
import { atomicWriteFileSync, createFreshState, migrateV1ToV2, migrateV2ToV3, migrateV3ToV4, warnMalformedWorkClaims, } from './state-persistence.js';
|
|
58
|
+
import { assertNotNewerVersion, atomicWriteFileSync, createFreshState, migrateV1ToV2, migrateV2ToV3, migrateV3ToV4, warnMalformedWorkClaims, } from './state-persistence.js';
|
|
52
59
|
import { getGistIdPath, getStateCachePath } from './paths.js';
|
|
53
60
|
import { debug, warn } from './logger.js';
|
|
54
|
-
import { ConfigurationError, GistPermissionError, GistConcurrencyError, GistCorruptError, GistFileSizeError, isRateLimitError, isTransientNetworkError, errorMessage, } from './errors.js';
|
|
61
|
+
import { ConfigurationError, GistPermissionError, GistConcurrencyError, GistCorruptError, GistDiscoveryError, GistFileSizeError, NewerStateVersionError, getHttpStatusCode, isRateLimitError, isTransientNetworkError, errorMessage, } from './errors.js';
|
|
55
62
|
const MODULE = 'gist-store';
|
|
56
63
|
/**
|
|
57
64
|
* Extract the ETag header from an Octokit response, tolerating both lower-
|
|
@@ -65,16 +72,14 @@ function extractEtag(headers) {
|
|
|
65
72
|
}
|
|
66
73
|
/**
|
|
67
74
|
* Preserve corrupt Gist content for user recovery. Returns the path written,
|
|
68
|
-
* or null if the preservation itself failed (logged at warn).
|
|
69
|
-
*
|
|
75
|
+
* or null if the preservation itself failed (logged at warn). Shares
|
|
76
|
+
* {@link preserveRejected} with the local-state path.
|
|
70
77
|
*
|
|
71
78
|
* See {@link GistCorruptError} and issue #1201.
|
|
72
79
|
*/
|
|
73
80
|
function preserveRejectedGistContent(raw, gistId) {
|
|
74
81
|
try {
|
|
75
|
-
|
|
76
|
-
fs.writeFileSync(rejectedPath, raw, { encoding: 'utf8', mode: 0o600 });
|
|
77
|
-
return rejectedPath;
|
|
82
|
+
return preserveRejected(getStateCachePath(), { content: raw });
|
|
78
83
|
}
|
|
79
84
|
catch (err) {
|
|
80
85
|
warn(MODULE, `Could not preserve rejected Gist content for ${gistId}: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -158,15 +163,15 @@ export class GistStateStore {
|
|
|
158
163
|
return { gistId: localId, state, created: false };
|
|
159
164
|
}
|
|
160
165
|
catch (err) {
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
//
|
|
164
|
-
|
|
166
|
+
// Only a 404 (the saved Gist is gone) falls through to search.
|
|
167
|
+
// Anything else goes to the outer catch: corrupt, permission and
|
|
168
|
+
// rate-limit errors surface (#1367), and a transient failure
|
|
169
|
+
// degrades. Searching after a transient failure could end in
|
|
170
|
+
// creating a Gist and overwriting the saved ID (#1926).
|
|
171
|
+
if (getHttpStatusCode(err) !== 404)
|
|
165
172
|
throw err;
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
warn(MODULE, `Failed to fetch Gist ${localId}, will search/create`, err);
|
|
169
|
-
// Fall through to search
|
|
173
|
+
this.gistId = null;
|
|
174
|
+
warn(MODULE, `Saved Gist ${localId} no longer exists, searching for the state Gist`, err);
|
|
170
175
|
}
|
|
171
176
|
}
|
|
172
177
|
// Step 2: Search user's Gists by description
|
|
@@ -196,12 +201,12 @@ export class GistStateStore {
|
|
|
196
201
|
throw err;
|
|
197
202
|
if (isRateLimitError(err))
|
|
198
203
|
throw err;
|
|
199
|
-
//
|
|
204
|
+
// The Gist could not be reached: enter degraded mode. Disarm the remote write
|
|
200
205
|
// path first: a degraded store never verified its Gist, so it must
|
|
201
206
|
// never be able to push to one (#1367).
|
|
202
207
|
this.gistId = null;
|
|
203
208
|
this.lastFetchedEtag = null;
|
|
204
|
-
warn(MODULE, '
|
|
209
|
+
warn(MODULE, 'Gist bootstrap failed, entering degraded mode', err);
|
|
205
210
|
// Try reading from local cache file
|
|
206
211
|
const cachePath = getStateCachePath();
|
|
207
212
|
let cacheRaw = null;
|
|
@@ -209,6 +214,7 @@ export class GistStateStore {
|
|
|
209
214
|
if (fs.existsSync(cachePath)) {
|
|
210
215
|
cacheRaw = fs.readFileSync(cachePath, 'utf8');
|
|
211
216
|
let obj = JSON.parse(cacheRaw);
|
|
217
|
+
assertNotNewerVersion(obj, 'local state cache');
|
|
212
218
|
// Chain migrations
|
|
213
219
|
if (typeof obj === 'object' && obj !== null) {
|
|
214
220
|
const record = obj;
|
|
@@ -226,6 +232,8 @@ export class GistStateStore {
|
|
|
226
232
|
}
|
|
227
233
|
}
|
|
228
234
|
catch (cacheErr) {
|
|
235
|
+
if (cacheErr instanceof NewerStateVersionError)
|
|
236
|
+
throw cacheErr;
|
|
229
237
|
// Promote to warn (#1201) and preserve corrupt cache so fresh-state
|
|
230
238
|
// fallback doesn't silently destroy recoverable data on next push.
|
|
231
239
|
if (cacheRaw) {
|
|
@@ -261,14 +269,11 @@ export class GistStateStore {
|
|
|
261
269
|
return { gistId: localId, state, created: false, migrated: false };
|
|
262
270
|
}
|
|
263
271
|
catch (err) {
|
|
264
|
-
// See bootstrap():
|
|
265
|
-
|
|
266
|
-
if (err instanceof ConfigurationError)
|
|
267
|
-
throw err;
|
|
268
|
-
if (isRateLimitError(err))
|
|
272
|
+
// See bootstrap(): only a 404 falls through to search (#1367, #1926).
|
|
273
|
+
if (getHttpStatusCode(err) !== 404)
|
|
269
274
|
throw err;
|
|
270
|
-
|
|
271
|
-
|
|
275
|
+
this.gistId = null;
|
|
276
|
+
warn(MODULE, `bootstrapWithMigration: saved Gist ${localId} no longer exists, searching`, err);
|
|
272
277
|
}
|
|
273
278
|
}
|
|
274
279
|
// Step 2: Search user's Gists by description
|
|
@@ -293,11 +298,11 @@ export class GistStateStore {
|
|
|
293
298
|
throw err;
|
|
294
299
|
if (isRateLimitError(err))
|
|
295
300
|
throw err;
|
|
296
|
-
//
|
|
297
|
-
// disarmed (see bootstrap()).
|
|
301
|
+
// The Gist could not be reached: enter degraded mode with the push
|
|
302
|
+
// path disarmed (see bootstrap()).
|
|
298
303
|
this.gistId = null;
|
|
299
304
|
this.lastFetchedEtag = null;
|
|
300
|
-
warn(MODULE, 'bootstrapWithMigration:
|
|
305
|
+
warn(MODULE, 'bootstrapWithMigration: Gist bootstrap failed, entering degraded mode', err);
|
|
301
306
|
// Try reading from local cache file
|
|
302
307
|
const cachePath = getStateCachePath();
|
|
303
308
|
let cacheRaw = null;
|
|
@@ -305,6 +310,7 @@ export class GistStateStore {
|
|
|
305
310
|
if (fs.existsSync(cachePath)) {
|
|
306
311
|
cacheRaw = fs.readFileSync(cachePath, 'utf8');
|
|
307
312
|
let obj = JSON.parse(cacheRaw);
|
|
313
|
+
assertNotNewerVersion(obj, 'local state cache');
|
|
308
314
|
// Chain migrations
|
|
309
315
|
if (typeof obj === 'object' && obj !== null) {
|
|
310
316
|
const record = obj;
|
|
@@ -322,6 +328,8 @@ export class GistStateStore {
|
|
|
322
328
|
}
|
|
323
329
|
}
|
|
324
330
|
catch (cacheErr) {
|
|
331
|
+
if (cacheErr instanceof NewerStateVersionError)
|
|
332
|
+
throw cacheErr;
|
|
325
333
|
if (cacheRaw) {
|
|
326
334
|
const rejectedPath = preserveRejectedGistContent(cacheRaw, 'local-cache');
|
|
327
335
|
warn(MODULE, `bootstrapWithMigration: local cache failed to parse: ${cacheErr instanceof Error ? cacheErr.message : String(cacheErr)}. ` +
|
|
@@ -521,6 +529,9 @@ export class GistStateStore {
|
|
|
521
529
|
// would hit the same wall, so surface it as-is.
|
|
522
530
|
if (readErr instanceof GistFileSizeError)
|
|
523
531
|
throw readErr;
|
|
532
|
+
// Nor is a Gist from a newer release: the answer is to update, not to re-run (#1951).
|
|
533
|
+
if (readErr instanceof NewerStateVersionError)
|
|
534
|
+
throw readErr;
|
|
524
535
|
if (isRateLimitError(readErr))
|
|
525
536
|
throw readErr;
|
|
526
537
|
throw new GistConcurrencyError(preReadEtag, null);
|
|
@@ -605,6 +616,9 @@ export class GistStateStore {
|
|
|
605
616
|
return { status: 'refreshed' };
|
|
606
617
|
}
|
|
607
618
|
catch (err) {
|
|
619
|
+
// Not a failed fetch: the Gist is fine and this client is too old for it (#1951).
|
|
620
|
+
if (err instanceof NewerStateVersionError)
|
|
621
|
+
throw err;
|
|
608
622
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
609
623
|
warn(MODULE, `refreshFromGist failed: ${error.message}`);
|
|
610
624
|
this.lastRefreshError = error;
|
|
@@ -750,6 +764,7 @@ export class GistStateStore {
|
|
|
750
764
|
}
|
|
751
765
|
try {
|
|
752
766
|
let obj = JSON.parse(raw);
|
|
767
|
+
assertNotNewerVersion(obj, 'Gist state');
|
|
753
768
|
// Chain migrations using shared helpers from state-persistence
|
|
754
769
|
if (typeof obj === 'object' && obj !== null) {
|
|
755
770
|
const record = obj;
|
|
@@ -768,6 +783,8 @@ export class GistStateStore {
|
|
|
768
783
|
return state;
|
|
769
784
|
}
|
|
770
785
|
catch (err) {
|
|
786
|
+
if (err instanceof NewerStateVersionError)
|
|
787
|
+
throw err;
|
|
771
788
|
const rejectedPath = preserveRejectedGistContent(raw, this.gistId ?? 'unknown');
|
|
772
789
|
warn(MODULE, `Gist state.json failed to parse — refusing to overwrite with fresh state. ` +
|
|
773
790
|
`Corrupt content preserved at: ${rejectedPath ?? '(could not preserve)'}`);
|
|
@@ -775,30 +792,60 @@ export class GistStateStore {
|
|
|
775
792
|
}
|
|
776
793
|
}
|
|
777
794
|
/**
|
|
778
|
-
* Search the authenticated user's Gists for one with the
|
|
779
|
-
* Pages through up to 10 pages (100 Gists per page)
|
|
795
|
+
* Search the authenticated user's Gists for the private one with the
|
|
796
|
+
* well-known description. Pages through up to 10 pages (100 Gists per page).
|
|
797
|
+
* The list has ended when a response carries no `rel="next"` Link header;
|
|
798
|
+
* page length is not used, since a short page need not be the last.
|
|
799
|
+
*
|
|
800
|
+
* Returns `null` only when the search ran to the end of the list and found
|
|
801
|
+
* no Gist with the description. The callers create a new Gist on `null`, so
|
|
802
|
+
* anything short of that must not read as "no Gist exists" or this machine
|
|
803
|
+
* forks onto an empty one (#1926): API errors propagate, and a list longer
|
|
804
|
+
* than the search window or a public-only match throws
|
|
805
|
+
* {@link GistDiscoveryError}.
|
|
780
806
|
*/
|
|
781
807
|
async searchForGist() {
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
808
|
+
const maxPages = 10;
|
|
809
|
+
const perPage = 100;
|
|
810
|
+
let publicId;
|
|
811
|
+
let hasReachedEnd = false;
|
|
812
|
+
for (let page = 1; !hasReachedEnd && page <= maxPages; page++) {
|
|
813
|
+
const { data: gists, headers } = await this.octokit.gists.list({ per_page: perPage, page });
|
|
814
|
+
const matches = gists.filter((g) => g.description === GIST_DESCRIPTION);
|
|
815
|
+
const [first, ...rest] = matches.filter((g) => !g.public);
|
|
816
|
+
if (first)
|
|
817
|
+
return this.pickStateGist(first, rest);
|
|
818
|
+
publicId ??= matches[0]?.id;
|
|
819
|
+
hasReachedEnd = !headers?.link?.includes('rel="next"');
|
|
820
|
+
}
|
|
821
|
+
if (hasReachedEnd && !publicId)
|
|
822
|
+
return null;
|
|
823
|
+
const idHint = `to ${getGistIdPath()}`;
|
|
824
|
+
if (hasReachedEnd) {
|
|
825
|
+
throw new GistDiscoveryError(`Found a public Gist (${publicId}) with the "${GIST_DESCRIPTION}" description. A public Gist is not ` +
|
|
826
|
+
`adopted automatically. To keep using it, write its ID ${idHint}; to start fresh, delete that Gist.`);
|
|
827
|
+
}
|
|
828
|
+
const publicNote = publicId
|
|
829
|
+
? ` A public Gist with that description (${publicId}) was seen; it is not adopted automatically, ` +
|
|
830
|
+
`but writing its ID there keeps using it.`
|
|
831
|
+
: '';
|
|
832
|
+
throw new GistDiscoveryError(`Searched the first ${maxPages * perPage} Gists without finding a private "${GIST_DESCRIPTION}" Gist or ` +
|
|
833
|
+
`reaching the end of the list, so no new Gist was created. Write the state Gist's ID (the last path ` +
|
|
834
|
+
`segment of its URL) ${idHint}.${publicNote}`);
|
|
835
|
+
}
|
|
836
|
+
/** Pick the oldest of the private state Gists found on a page, warning when there are several. */
|
|
837
|
+
pickStateGist(first, rest) {
|
|
838
|
+
let chosen = first;
|
|
839
|
+
for (const g of rest) {
|
|
840
|
+
if (Date.parse(g.created_at) < Date.parse(chosen.created_at))
|
|
841
|
+
chosen = g;
|
|
842
|
+
}
|
|
843
|
+
if (rest.length > 0) {
|
|
844
|
+
const others = [first, ...rest].filter((g) => g !== chosen).map((g) => g.id);
|
|
845
|
+
warn(MODULE, `Found ${others.length + 1} private "${GIST_DESCRIPTION}" Gists. Using the oldest, ${chosen.id}; ` +
|
|
846
|
+
`ignoring ${others.join(', ')}. Delete the others, or write ${chosen.id} to ${getGistIdPath()}.`);
|
|
847
|
+
}
|
|
848
|
+
return chosen.id;
|
|
802
849
|
}
|
|
803
850
|
/**
|
|
804
851
|
* Create a new private Gist with seed files and store it in memory.
|
|
@@ -25,6 +25,27 @@ export declare function closingIssueUrl(body: string | null | undefined, prUrl:
|
|
|
25
25
|
* appearance; HTML comments and code are ignored like in `closingIssueUrl`.
|
|
26
26
|
*/
|
|
27
27
|
export declare function mentionedIssueUrls(title: string | null | undefined, body: string | null | undefined, prUrl: string): string[];
|
|
28
|
+
/** The search scope every ledger and count query shares; see {@link externalPRScope}. */
|
|
29
|
+
export interface ExternalPRScope {
|
|
30
|
+
/** Qualifiers to append to `is:pr <state>`. */
|
|
31
|
+
query: string;
|
|
32
|
+
/**
|
|
33
|
+
* True when `query` excludes every untracked organisation, so the search's
|
|
34
|
+
* `total_count` is the number of PRs the ledger may hold. False when the
|
|
35
|
+
* list did not fit GitHub's limits: results must still be filtered with
|
|
36
|
+
* `isUntrackedOrg`, and the total is an overcount.
|
|
37
|
+
*/
|
|
38
|
+
isExact: boolean;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Which of the user's PRs the ledgers and their counts cover: public
|
|
42
|
+
* repositories only, not the user's own, and not organisations in
|
|
43
|
+
* `config.untrackedOrgs` (the user's employer). One fragment, so the merged
|
|
44
|
+
* and closed ledger fetches and the count searches cannot drift apart: a
|
|
45
|
+
* count taken over a wider set than the ledger can hold would report a gap
|
|
46
|
+
* no back-fill closes.
|
|
47
|
+
*/
|
|
48
|
+
export declare function externalPRScope(username: string, untrackedOrgs?: readonly string[]): ExternalPRScope;
|
|
28
49
|
/** Return type shared by both merged and closed PR count functions. */
|
|
29
50
|
export interface PRCountsResult<R> {
|
|
30
51
|
repos: Map<string, R>;
|
|
@@ -45,6 +66,14 @@ export interface PRCountsResult<R> {
|
|
|
45
66
|
* so `repos` undercounts and a repo missing from it may still have PRs.
|
|
46
67
|
*/
|
|
47
68
|
truncated: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* GitHub's `total_count` for the search: every PR in {@link externalPRScope},
|
|
71
|
+
* before the star filter and whatever the pagination cap. Absent when
|
|
72
|
+
* unknown (failed fetch, a result cached before the field existed, or
|
|
73
|
+
* untracked organisations that did not fit in the query), which is not the
|
|
74
|
+
* same as zero.
|
|
75
|
+
*/
|
|
76
|
+
totalCount?: number;
|
|
48
77
|
}
|
|
49
78
|
/** Returns an empty PRCountsResult. Used as the fallback when stats fetches fail or username is empty. */
|
|
50
79
|
export declare function emptyPRCountsResult<R>(): PRCountsResult<R>;
|
|
@@ -52,7 +81,7 @@ export declare function emptyPRCountsResult<R>(): PRCountsResult<R>;
|
|
|
52
81
|
* Fetch merged PR counts and latest merge dates per repository for the configured user.
|
|
53
82
|
* Also builds a monthly histogram of all merges for the contribution timeline.
|
|
54
83
|
*/
|
|
55
|
-
export declare function fetchUserMergedPRCounts(octokit: Octokit, githubUsername: string, starFilter?: StarFilter): Promise<PRCountsResult<{
|
|
84
|
+
export declare function fetchUserMergedPRCounts(octokit: Octokit, githubUsername: string, starFilter?: StarFilter, untrackedOrgs?: readonly string[]): Promise<PRCountsResult<{
|
|
56
85
|
count: number;
|
|
57
86
|
lastMergedAt: string;
|
|
58
87
|
}>>;
|
|
@@ -60,7 +89,18 @@ export declare function fetchUserMergedPRCounts(octokit: Octokit, githubUsername
|
|
|
60
89
|
* Fetch closed-without-merge PR counts per repository for the configured user.
|
|
61
90
|
* Used to populate closedWithoutMergeCount in repo scores for accurate merge rate.
|
|
62
91
|
*/
|
|
63
|
-
export declare function fetchUserClosedPRCounts(octokit: Octokit, githubUsername: string, starFilter?: StarFilter): Promise<PRCountsResult<number>>;
|
|
92
|
+
export declare function fetchUserClosedPRCounts(octokit: Octokit, githubUsername: string, starFilter?: StarFilter, untrackedOrgs?: readonly string[]): Promise<PRCountsResult<number>>;
|
|
93
|
+
/**
|
|
94
|
+
* A recently merged or recently closed PR list that is missing entries
|
|
95
|
+
* (#1928): the recent-list truncation. Not the count-search truncation of
|
|
96
|
+
* the all-time merged and closed counts (`PRCountsResult.truncated`).
|
|
97
|
+
*/
|
|
98
|
+
export interface RecentListTruncation {
|
|
99
|
+
/** Short form for lists of degraded operations, e.g. `recently merged PR search truncated (300 of 450)`. */
|
|
100
|
+
label: string;
|
|
101
|
+
/** Full sentence for logs and the daily warnings. */
|
|
102
|
+
message: string;
|
|
103
|
+
}
|
|
64
104
|
/**
|
|
65
105
|
* Fetch PRs closed without merge in the last N days.
|
|
66
106
|
* Returns lightweight ClosedPR objects for surfacing in the daily digest.
|
|
@@ -68,7 +108,7 @@ export declare function fetchUserClosedPRCounts(octokit: Octokit, githubUsername
|
|
|
68
108
|
export declare function fetchRecentlyClosedPRs(octokit: Octokit, config: {
|
|
69
109
|
githubUsername: string;
|
|
70
110
|
untrackedOrgs?: string[];
|
|
71
|
-
}, days?: number): Promise<ClosedPR[]>;
|
|
111
|
+
}, days?: number, truncations?: RecentListTruncation[]): Promise<ClosedPR[]>;
|
|
72
112
|
/**
|
|
73
113
|
* Fetch PRs merged in the last N days.
|
|
74
114
|
* Returns lightweight MergedPR objects for surfacing as wins in the dashboard.
|
|
@@ -76,21 +116,75 @@ export declare function fetchRecentlyClosedPRs(octokit: Octokit, config: {
|
|
|
76
116
|
export declare function fetchRecentlyMergedPRs(octokit: Octokit, config: {
|
|
77
117
|
githubUsername: string;
|
|
78
118
|
untrackedOrgs?: string[];
|
|
79
|
-
}, days?: number): Promise<MergedPR[]>;
|
|
119
|
+
}, days?: number, truncations?: RecentListTruncation[]): Promise<MergedPR[]>;
|
|
80
120
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
121
|
+
* Most PRs a ledger gap fetch takes in one run (the Search API's own cap for
|
|
122
|
+
* a single query). A search matching more returns nothing: the caller stores
|
|
123
|
+
* no rows, so the ledger's newest entry stays where it was, the next run asks
|
|
124
|
+
* for the same range, and `ledger-backfill` (no limit) is the way out.
|
|
84
125
|
*/
|
|
85
|
-
export declare
|
|
86
|
-
|
|
87
|
-
|
|
126
|
+
export declare const LEDGER_GAP_MAX_RESULTS = 1000;
|
|
127
|
+
/** What the daily run and the dashboard report when a merged-ledger gap fetch is truncated. */
|
|
128
|
+
export declare const MERGED_LEDGER_TRUNCATED_MESSAGE: string;
|
|
129
|
+
/** What the daily run and the dashboard report when a closed-ledger gap fetch is truncated. */
|
|
130
|
+
export declare const CLOSED_LEDGER_TRUNCATED_MESSAGE: string;
|
|
131
|
+
/**
|
|
132
|
+
* A ledger with fewer rows than this that is short of GitHub's all-time count
|
|
133
|
+
* is refetched from the start (#1504, #1925): a recent row stored ahead of the
|
|
134
|
+
* history behind it would otherwise hide that history from every gap fetch.
|
|
135
|
+
* Past it a short ledger keeps its watermark, so a contributor whose count
|
|
136
|
+
* legitimately exceeds the ledger doesn't refetch everything on every run;
|
|
137
|
+
* the count warning and `ledger-backfill` cover that case.
|
|
138
|
+
*/
|
|
139
|
+
export declare const LEDGER_BACKFILL_CEILING = 300;
|
|
140
|
+
/**
|
|
141
|
+
* The watermark a ledger gap fetch starts from: undefined (all time) when the
|
|
142
|
+
* ledger holds `stored` rows, fewer than `allTimeCount` and under
|
|
143
|
+
* {@link LEDGER_BACKFILL_CEILING}, and the whole history fits in one gap fetch
|
|
144
|
+
* ({@link LEDGER_GAP_MAX_RESULTS}); otherwise `watermark`. An unknown count
|
|
145
|
+
* keeps the watermark.
|
|
146
|
+
*
|
|
147
|
+
* A history larger than one fetch would come back truncated with no rows, and
|
|
148
|
+
* the caller then stores nothing, the recent list included, on every run. So
|
|
149
|
+
* that ledger keeps growing from its watermark and the count warning points
|
|
150
|
+
* at `ledger-backfill`, which fetches without a limit.
|
|
151
|
+
*/
|
|
152
|
+
export declare function gapFetchWatermark(watermark: string | undefined, stored: number, allTimeCount: number | undefined): string | undefined;
|
|
153
|
+
/** Result of a since-watermark ledger fetch. */
|
|
154
|
+
export interface PRsSinceResult<T> {
|
|
155
|
+
/** Every matching PR. Empty when `truncated`: a partial range is never returned. */
|
|
156
|
+
prs: T[];
|
|
157
|
+
/** The search matched more than the caller's limit, so the range was not fetched. */
|
|
158
|
+
truncated: boolean;
|
|
159
|
+
}
|
|
88
160
|
/**
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* Uses `is:unmerged` to exclude merged PRs (which are also "closed" in GitHub's model).
|
|
161
|
+
* The search bound for a ledger watermark (its newest stored date): one
|
|
162
|
+
* overlap earlier, at second precision. An absent or unparseable watermark
|
|
163
|
+
* gives undefined, which means "all time".
|
|
93
164
|
*/
|
|
94
|
-
export declare function
|
|
165
|
+
export declare function withLedgerOverlap(watermark?: string): string | undefined;
|
|
166
|
+
/** What a ledger fetch reads from the user's config. */
|
|
167
|
+
export interface LedgerFetchConfig {
|
|
95
168
|
githubUsername: string;
|
|
96
|
-
|
|
169
|
+
/** Organisations whose PRs are never stored (the user's employer). */
|
|
170
|
+
untrackedOrgs?: readonly string[];
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The one fetch that fills the merged-PR ledger (#1924), shared by the daily
|
|
174
|
+
* run, the dashboard and `ledger-backfill`: every merged PR updated since
|
|
175
|
+
* `watermark` (the ledger's newest `mergedAt`) minus a one-day overlap, or
|
|
176
|
+
* all of them when there is no watermark.
|
|
177
|
+
*
|
|
178
|
+
* `truncated` (more than `maxResults` matches) returns no rows. Callers must
|
|
179
|
+
* then add nothing newer to the ledger, so its watermark does not move past
|
|
180
|
+
* the range that was not fetched. `ledger-backfill` passes `Infinity`.
|
|
181
|
+
*/
|
|
182
|
+
export declare function fetchMergedPRsSince(octokit: Octokit, config: LedgerFetchConfig, watermark?: string, maxResults?: number): Promise<PRsSinceResult<StoredMergedPR>>;
|
|
183
|
+
/**
|
|
184
|
+
* The closed-without-merge mirror of {@link fetchMergedPRsSince} (#1925),
|
|
185
|
+
* shared by the daily run, the dashboard and `ledger-backfill`: every closed
|
|
186
|
+
* PR updated since `watermark` (the ledger's newest `closedAt`) minus a
|
|
187
|
+
* one-day overlap, or all of them when there is no watermark. Same
|
|
188
|
+
* `truncated` contract: no rows, so the watermark does not move.
|
|
189
|
+
*/
|
|
190
|
+
export declare function fetchClosedPRsSince(octokit: Octokit, config: LedgerFetchConfig, watermark?: string, maxResults?: number): Promise<PRsSinceResult<StoredClosedPR>>;
|