@oss-autopilot/core 3.31.0 → 3.31.1
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.bundle.cjs +109 -108
- package/dist/commands/dashboard-server.js +5 -7
- package/dist/core/ci-analysis.js +15 -1
- package/dist/core/compliance-score.js +95 -15
- package/dist/core/errors.d.ts +14 -0
- package/dist/core/errors.js +18 -0
- package/dist/core/gist-state-store.d.ts +30 -0
- package/dist/core/gist-state-store.js +114 -15
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/pr-assembly.d.ts +9 -7
- package/dist/core/pr-assembly.js +14 -10
- package/dist/core/pr-monitor.d.ts +2 -2
- package/dist/core/pr-monitor.js +9 -4
- package/dist/core/pr-quality-rubric.js +1 -1
- package/dist/core/state.js +22 -9
- package/dist/core/strategy.js +22 -3
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ import * as http from 'node:http';
|
|
|
14
14
|
import * as fs from 'node:fs';
|
|
15
15
|
import * as path from 'node:path';
|
|
16
16
|
import * as crypto from 'node:crypto';
|
|
17
|
-
import { getGitHubToken, getCLIVersion
|
|
17
|
+
import { getGitHubToken, getCLIVersion } from '../core/index.js';
|
|
18
18
|
import { errorMessage, ValidationError, ConcurrencyError, GistConcurrencyError } from '../core/errors.js';
|
|
19
19
|
import { warn } from '../core/logger.js';
|
|
20
20
|
import { validateUrl, validateGitHubUrl, PR_URL_PATTERN, ISSUE_URL_PATTERN } from './validation.js';
|
|
@@ -469,13 +469,11 @@ export async function startDashboardServer(options) {
|
|
|
469
469
|
};
|
|
470
470
|
}
|
|
471
471
|
else {
|
|
472
|
-
// dismiss_issue_response
|
|
472
|
+
// dismiss_issue_response: same command the CLI and MCP surfaces run.
|
|
473
|
+
const { runDismiss } = await import('./dismiss.js');
|
|
473
474
|
applyMutation = async () => {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
// Gist and surfaces the warning. Never throws — failures come back
|
|
477
|
-
// as the warning string.
|
|
478
|
-
gistSyncWarning = await maybeCheckpoint(gistSync.stateManager, MODULE);
|
|
475
|
+
const output = await runDismiss({ url: body.url });
|
|
476
|
+
gistSyncWarning = output.gistSyncWarning ?? null;
|
|
479
477
|
};
|
|
480
478
|
}
|
|
481
479
|
// Reload state before mutating to avoid overwriting external CLI changes.
|
package/dist/core/ci-analysis.js
CHANGED
|
@@ -204,7 +204,21 @@ export function analyzeCheckRuns(checkRuns) {
|
|
|
204
204
|
failingCheckNames.push(check.name);
|
|
205
205
|
failingCheckConclusions.set(check.name, check.conclusion);
|
|
206
206
|
}
|
|
207
|
-
else if (check.
|
|
207
|
+
else if (check.conclusion === null && check.status === 'waiting') {
|
|
208
|
+
// `waiting` is an environment protection rule holding the job for a
|
|
209
|
+
// deployment approval. Like an action_required run, only a maintainer
|
|
210
|
+
// can clear it, so it is an auth gate: not passing, but not pending
|
|
211
|
+
// either, which would turn into a stuck-CI rerun nudge the contributor
|
|
212
|
+
// cannot act on. Recorded as action_required so classifyCICheck files
|
|
213
|
+
// it under auth_gate.
|
|
214
|
+
hasFailingChecks = true;
|
|
215
|
+
failingCheckNames.push(check.name);
|
|
216
|
+
failingCheckConclusions.set(check.name, 'action_required');
|
|
217
|
+
}
|
|
218
|
+
else if (check.conclusion === null && check.status !== 'completed') {
|
|
219
|
+
// Any other run without a conclusion that has not completed is
|
|
220
|
+
// pending: in_progress and queued, but also pending (concurrency
|
|
221
|
+
// group) and requested.
|
|
208
222
|
hasPendingChecks = true;
|
|
209
223
|
}
|
|
210
224
|
else if (check.conclusion === 'success') {
|
|
@@ -156,28 +156,108 @@ function checkIssueReference(meta, repoContext) {
|
|
|
156
156
|
}
|
|
157
157
|
const SECTION_WHAT = /(?:^|\n)#{1,3}\s*(?:summary|overview|what(?:\s+changed)?)\b/i;
|
|
158
158
|
const SECTION_WHY = /(?:^|\n)#{1,3}\s*(?:why|motivation|context|background|rationale)\b/i;
|
|
159
|
-
const
|
|
159
|
+
const CLOSING_REF = /\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+(?:[\w.-]+\/[\w.-]+)?#\d+/gi;
|
|
160
|
+
// Closed code fences: a line opening with 3+ backticks, closed by a later line
|
|
161
|
+
// opening with at least as many. An unclosed fence is text.
|
|
162
|
+
function fenceSpans(body) {
|
|
163
|
+
const spans = [];
|
|
164
|
+
let open;
|
|
165
|
+
let offset = 0;
|
|
166
|
+
for (const line of body.split('\n')) {
|
|
167
|
+
const len = /^ {0,3}(`{3,})/.exec(line)?.[1].length ?? 0;
|
|
168
|
+
if (len > 0 && !open) {
|
|
169
|
+
open = { start: offset, len };
|
|
170
|
+
}
|
|
171
|
+
else if (len > 0 && open && len >= open.len) {
|
|
172
|
+
spans.push([open.start, offset + line.length]);
|
|
173
|
+
open = undefined;
|
|
174
|
+
}
|
|
175
|
+
offset += line.length + 1;
|
|
176
|
+
}
|
|
177
|
+
return spans;
|
|
178
|
+
}
|
|
179
|
+
// Balanced inline code spans in body[from, to): a run of N backticks closes at
|
|
180
|
+
// the next run of exactly N. An unmatched run is text.
|
|
181
|
+
function inlineSpans(body, from, to) {
|
|
182
|
+
const runs = [...body.slice(from, to).matchAll(/`+/g)].map((m) => ({ start: from + m.index, len: m[0].length }));
|
|
183
|
+
const closer = new Map();
|
|
184
|
+
const nextByLen = new Map();
|
|
185
|
+
for (let r = runs.length - 1; r >= 0; r--) {
|
|
186
|
+
const next = nextByLen.get(runs[r].len);
|
|
187
|
+
if (next !== undefined)
|
|
188
|
+
closer.set(r, next);
|
|
189
|
+
nextByLen.set(runs[r].len, r);
|
|
190
|
+
}
|
|
191
|
+
const spans = [];
|
|
192
|
+
let r = 0;
|
|
193
|
+
while (r < runs.length) {
|
|
194
|
+
const close = closer.get(r);
|
|
195
|
+
if (close === undefined) {
|
|
196
|
+
r += 1;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
spans.push([runs[r].start, runs[close].start + runs[close].len]);
|
|
200
|
+
r = close + 1;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return spans;
|
|
204
|
+
}
|
|
205
|
+
// 1 for each character inside code (fenced or inline). Linear time.
|
|
206
|
+
function codeMask(body) {
|
|
207
|
+
const mask = new Uint8Array(body.length);
|
|
208
|
+
const fences = fenceSpans(body);
|
|
209
|
+
const gaps = [];
|
|
210
|
+
let from = 0;
|
|
211
|
+
for (const [start, end] of fences) {
|
|
212
|
+
gaps.push([from, start]);
|
|
213
|
+
from = end;
|
|
214
|
+
}
|
|
215
|
+
gaps.push([from, body.length]);
|
|
216
|
+
const inline = gaps.flatMap(([start, end]) => inlineSpans(body, start, end));
|
|
217
|
+
for (const [start, end] of [...fences, ...inline])
|
|
218
|
+
mask.fill(1, start, end);
|
|
219
|
+
return mask;
|
|
220
|
+
}
|
|
221
|
+
function proseOf(body) {
|
|
222
|
+
// Drop closed `<!-- ... -->` comments outside code; an unclosed opener, or
|
|
223
|
+
// one in code, is text.
|
|
224
|
+
const code = codeMask(body);
|
|
225
|
+
let uncommented = '';
|
|
226
|
+
let hasClosers = true;
|
|
227
|
+
let i = 0;
|
|
228
|
+
while (i < body.length) {
|
|
229
|
+
const end = hasClosers && code[i] === 0 && body.startsWith('<!--', i) ? body.indexOf('-->', i + 4) : -1;
|
|
230
|
+
if (end === -1) {
|
|
231
|
+
// An opener with no closer means no later opener can close either.
|
|
232
|
+
if (code[i] === 0 && body.startsWith('<!--', i))
|
|
233
|
+
hasClosers = false;
|
|
234
|
+
uncommented += body[i];
|
|
235
|
+
i += 1;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
i = end + 3;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return (uncommented
|
|
242
|
+
// A heading is a short title line, not a sentence that starts with "# ".
|
|
243
|
+
.replace(/^ {0,3}#{1,6}[ \t]+[^\n]{0,60}$/gm, (line) => (/[.!?。]\s*$/.test(line) ? line : ''))
|
|
244
|
+
.replace(CLOSING_REF, '')
|
|
245
|
+
.trim());
|
|
246
|
+
}
|
|
247
|
+
// Headings are never required: a sentence or two of what and why is a full
|
|
248
|
+
// description, and requiring a heading set pads small PRs with filler sections.
|
|
160
249
|
function checkDescription(meta) {
|
|
161
250
|
const weight = WEIGHTS.description;
|
|
162
251
|
const trimmed = meta.body.trim();
|
|
163
252
|
if (trimmed.length === 0) {
|
|
164
253
|
return { status: 'fail', weight, detail: 'description is empty' };
|
|
165
254
|
}
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (present === 3) {
|
|
171
|
-
return { status: 'pass', weight, detail: 'what / why / test sections present' };
|
|
172
|
-
}
|
|
173
|
-
if (present >= 1 || trimmed.length >= 80) {
|
|
174
|
-
return {
|
|
175
|
-
status: 'warn',
|
|
176
|
-
weight,
|
|
177
|
-
detail: `${present} of 3 sections present (what/why/test)`,
|
|
178
|
-
};
|
|
255
|
+
const prose = proseOf(meta.body);
|
|
256
|
+
const hasHeading = SECTION_WHAT.test(meta.body) || SECTION_WHY.test(meta.body);
|
|
257
|
+
if (prose.length >= 80 || (hasHeading && /\p{L}/u.test(prose))) {
|
|
258
|
+
return { status: 'pass', weight, detail: 'describes the change' };
|
|
179
259
|
}
|
|
180
|
-
return { status: '
|
|
260
|
+
return { status: 'warn', weight, detail: 'short description; say what changed and why' };
|
|
181
261
|
}
|
|
182
262
|
function checkFocusedChanges(meta) {
|
|
183
263
|
const weight = WEIGHTS.focusedChanges;
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -91,6 +91,20 @@ export declare class GistConcurrencyError extends OssAutopilotError {
|
|
|
91
91
|
readonly remoteEtag: string | null;
|
|
92
92
|
constructor(expectedEtag: string | null, remoteEtag: string | null);
|
|
93
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* A Gist file is too large to round-trip: the Gist API truncated it (over
|
|
96
|
+
* 1 MB inline) and `raw_url` is missing, off-host, or refused (404/413), or
|
|
97
|
+
* a push would exceed the 10 MB `raw_url` limit. A {@link ConfigurationError}
|
|
98
|
+
* because retrying cannot fix it: bootstrap halts with this message instead
|
|
99
|
+
* of degrading and re-bootstrapping forever, and the repair commands
|
|
100
|
+
* (config, setup, state-unlink) still run. Transient raw_url failures are
|
|
101
|
+
* not wrapped in this error and stay retryable.
|
|
102
|
+
*/
|
|
103
|
+
/** What a user can do about a {@link GistFileSizeError}. Shared by every surface that renders one. */
|
|
104
|
+
export declare const GIST_FILE_SIZE_REMEDY: string;
|
|
105
|
+
export declare class GistFileSizeError extends ConfigurationError {
|
|
106
|
+
constructor(message: string);
|
|
107
|
+
}
|
|
94
108
|
/**
|
|
95
109
|
* Extract a human-readable message from an unknown error value.
|
|
96
110
|
*/
|
package/dist/core/errors.js
CHANGED
|
@@ -139,6 +139,24 @@ export class GistConcurrencyError extends OssAutopilotError {
|
|
|
139
139
|
this.name = 'GistConcurrencyError';
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* A Gist file is too large to round-trip: the Gist API truncated it (over
|
|
144
|
+
* 1 MB inline) and `raw_url` is missing, off-host, or refused (404/413), or
|
|
145
|
+
* a push would exceed the 10 MB `raw_url` limit. A {@link ConfigurationError}
|
|
146
|
+
* because retrying cannot fix it: bootstrap halts with this message instead
|
|
147
|
+
* of degrading and re-bootstrapping forever, and the repair commands
|
|
148
|
+
* (config, setup, state-unlink) still run. Transient raw_url failures are
|
|
149
|
+
* not wrapped in this error and stay retryable.
|
|
150
|
+
*/
|
|
151
|
+
/** What a user can do about a {@link GistFileSizeError}. Shared by every surface that renders one. */
|
|
152
|
+
export const GIST_FILE_SIZE_REMEDY = 'trim the large state fields in the Gist (repoScores and searchSeen are usually the biggest), ' +
|
|
153
|
+
'or run state-unlink to fall back to local state';
|
|
154
|
+
export class GistFileSizeError extends ConfigurationError {
|
|
155
|
+
constructor(message) {
|
|
156
|
+
super(message);
|
|
157
|
+
this.name = 'GistFileSizeError';
|
|
158
|
+
}
|
|
159
|
+
}
|
|
142
160
|
/**
|
|
143
161
|
* Extract a human-readable message from an unknown error value.
|
|
144
162
|
*/
|
|
@@ -118,6 +118,16 @@ export interface OctokitLike {
|
|
|
118
118
|
headers?: Record<string, string | undefined>;
|
|
119
119
|
}>;
|
|
120
120
|
};
|
|
121
|
+
/**
|
|
122
|
+
* Generic request, used only to fetch the `raw_url` of a file the Gist API
|
|
123
|
+
* truncated. Optional so test mocks that never truncate can omit it.
|
|
124
|
+
*/
|
|
125
|
+
request?: (route: {
|
|
126
|
+
method: 'GET';
|
|
127
|
+
url: string;
|
|
128
|
+
}) => Promise<{
|
|
129
|
+
data: unknown;
|
|
130
|
+
}>;
|
|
121
131
|
}
|
|
122
132
|
/** Shape of a single Gist in a list response (subset). */
|
|
123
133
|
interface GistListItem {
|
|
@@ -131,6 +141,8 @@ interface GistResponseData {
|
|
|
131
141
|
files: Record<string, {
|
|
132
142
|
filename: string;
|
|
133
143
|
content?: string;
|
|
144
|
+
truncated?: boolean;
|
|
145
|
+
raw_url?: string;
|
|
134
146
|
} | null>;
|
|
135
147
|
}
|
|
136
148
|
/**
|
|
@@ -263,6 +275,12 @@ export declare class GistStateStore {
|
|
|
263
275
|
* - `{ status: 'error', error }` — fetch attempt failed.
|
|
264
276
|
*/
|
|
265
277
|
refreshFromGist(): Promise<RefreshResult>;
|
|
278
|
+
/**
|
|
279
|
+
* Refuse to write a file the Gist could no longer serve back (raw_url stops
|
|
280
|
+
* at 10 MB), and warn once a file passes ~900 KB so growth is visible before
|
|
281
|
+
* reads start depending on the truncated-file path.
|
|
282
|
+
*/
|
|
283
|
+
private checkPushSize;
|
|
266
284
|
/**
|
|
267
285
|
* Preflight check: verify the token has Gist API scope.
|
|
268
286
|
* Costs one cheap API call; catches permission issues early with a clear message.
|
|
@@ -273,6 +291,18 @@ export declare class GistStateStore {
|
|
|
273
291
|
* and write the local cache file.
|
|
274
292
|
*/
|
|
275
293
|
private fetchAndCache;
|
|
294
|
+
/**
|
|
295
|
+
* Fetch the full body of a file the Gist API truncated (>1 MB of content).
|
|
296
|
+
*
|
|
297
|
+
* Throws {@link GistFileSizeError} when the body cannot be read for a
|
|
298
|
+
* reason a retry will not fix (no raw_url, off-host raw_url, a non-text
|
|
299
|
+
* body, or a non-transient HTTP error such as 404/413). Rate limits and
|
|
300
|
+
* transient network errors (5xx, ECONNRESET, timeouts) are rethrown as-is
|
|
301
|
+
* so callers keep treating them as retryable: bootstrap degrades to the
|
|
302
|
+
* local cache and the pre-write re-read reports a GistConcurrencyError.
|
|
303
|
+
* Either way the cache is left unchanged.
|
|
304
|
+
*/
|
|
305
|
+
private fetchRawContent;
|
|
276
306
|
/**
|
|
277
307
|
* Parse `state.json` from the in-memory cache. Handles v1→v4 migration
|
|
278
308
|
* by running through the Zod schema (which requires version: 4).
|
|
@@ -50,7 +50,7 @@ import { AgentStateSchema } from './state-schema.js';
|
|
|
50
50
|
import { atomicWriteFileSync, createFreshState, migrateV1ToV2, migrateV2ToV3, migrateV3ToV4, } from './state-persistence.js';
|
|
51
51
|
import { getGistIdPath, getStateCachePath } from './paths.js';
|
|
52
52
|
import { debug, warn } from './logger.js';
|
|
53
|
-
import { ConfigurationError, GistPermissionError, GistConcurrencyError, GistCorruptError, isRateLimitError, } from './errors.js';
|
|
53
|
+
import { ConfigurationError, GistPermissionError, GistConcurrencyError, GistCorruptError, GistFileSizeError, isRateLimitError, isTransientNetworkError, errorMessage, } from './errors.js';
|
|
54
54
|
const MODULE = 'gist-store';
|
|
55
55
|
/**
|
|
56
56
|
* Extract the ETag header from an Octokit response, tolerating both lower-
|
|
@@ -84,6 +84,18 @@ function preserveRejectedGistContent(raw, gistId) {
|
|
|
84
84
|
export const GIST_DESCRIPTION = 'oss-autopilot-state';
|
|
85
85
|
/** Primary state file name inside the Gist. */
|
|
86
86
|
export const STATE_FILE_NAME = 'state.json';
|
|
87
|
+
/**
|
|
88
|
+
* The Gist API returns at most 1 MB of `content` per file and sets
|
|
89
|
+
* `truncated: true` past that; the full body (up to 10 MB) is only available
|
|
90
|
+
* from `raw_url`. Above 10 MB even `raw_url` stops working, so `push()`
|
|
91
|
+
* refuses to write a file that large and warns as it approaches 1 MB.
|
|
92
|
+
*/
|
|
93
|
+
const GIST_CONTENT_WARN_BYTES = 900 * 1024;
|
|
94
|
+
const GIST_RAW_MAX_BYTES = 10 * 1024 * 1024;
|
|
95
|
+
const GIST_RAW_HOST = 'gist.githubusercontent.com';
|
|
96
|
+
const SIZE_WARN_BAND_BYTES = 100 * 1024;
|
|
97
|
+
/** Highest size band already warned about, per filename, for this process. */
|
|
98
|
+
const warnedSizeBands = new Map();
|
|
87
99
|
/**
|
|
88
100
|
* Gist-backed state store with in-memory file cache and local write-through.
|
|
89
101
|
*/
|
|
@@ -407,6 +419,7 @@ export class GistStateStore {
|
|
|
407
419
|
if (this.gistId === null) {
|
|
408
420
|
throw new Error('GistStateStore: cannot push before bootstrap — gistId is null');
|
|
409
421
|
}
|
|
422
|
+
this.checkPushSize();
|
|
410
423
|
const buildFiles = () => {
|
|
411
424
|
const out = {};
|
|
412
425
|
for (const filename of this.dirtyFiles) {
|
|
@@ -474,13 +487,9 @@ export class GistStateStore {
|
|
|
474
487
|
this.cachedFiles.set(filename, content);
|
|
475
488
|
}
|
|
476
489
|
};
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
catch (readErr) {
|
|
481
|
-
warn(MODULE, `Pre-write re-read failed: ${readErr}`);
|
|
482
|
-
// Roll back any partial mutation so the caller's retry path sees the
|
|
483
|
-
// prior in-memory state with local mutations re-applied on top.
|
|
490
|
+
// Restore the pre-read cache, baseline, and ETag, then re-apply the
|
|
491
|
+
// staged edits on top, so the caller sees the prior in-memory state.
|
|
492
|
+
const rollBackPreRead = () => {
|
|
484
493
|
this.cachedFiles.clear();
|
|
485
494
|
for (const [filename, content] of preReadCache) {
|
|
486
495
|
this.cachedFiles.set(filename, content);
|
|
@@ -488,6 +497,15 @@ export class GistStateStore {
|
|
|
488
497
|
this.baselineFiles = preReadBaseline;
|
|
489
498
|
this.lastFetchedEtag = preReadEtag;
|
|
490
499
|
reapplyStaged();
|
|
500
|
+
};
|
|
501
|
+
try {
|
|
502
|
+
await this.fetchAndCache(this.gistId);
|
|
503
|
+
}
|
|
504
|
+
catch (readErr) {
|
|
505
|
+
warn(MODULE, `Pre-write re-read failed: ${errorMessage(readErr)}`);
|
|
506
|
+
// Roll back any partial mutation so the caller's retry path sees the
|
|
507
|
+
// prior in-memory state with local mutations re-applied on top.
|
|
508
|
+
rollBackPreRead();
|
|
491
509
|
// Preserve GistCorruptError so callers don't retry against a corrupt
|
|
492
510
|
// remote, and let rate-limit errors propagate unchanged so they aren't
|
|
493
511
|
// mistaken for a concurrency conflict — a "refresh + retry" remediation
|
|
@@ -496,6 +514,10 @@ export class GistStateStore {
|
|
|
496
514
|
// caller can refresh + retry.
|
|
497
515
|
if (readErr instanceof GistCorruptError)
|
|
498
516
|
throw readErr;
|
|
517
|
+
// An unreadable oversized file is not a conflict: refresh + retry
|
|
518
|
+
// would hit the same wall, so surface it as-is.
|
|
519
|
+
if (readErr instanceof GistFileSizeError)
|
|
520
|
+
throw readErr;
|
|
499
521
|
if (isRateLimitError(readErr))
|
|
500
522
|
throw readErr;
|
|
501
523
|
throw new GistConcurrencyError(preReadEtag, null);
|
|
@@ -504,9 +526,14 @@ export class GistStateStore {
|
|
|
504
526
|
if (baselineStateJson !== remoteStateJson) {
|
|
505
527
|
warn(MODULE, 'state.json changed remotely since our last fetch; surfacing GistConcurrencyError instead of clobbering (#1235, #1510)');
|
|
506
528
|
// Preserve local state.json (and other staged dirty files) in memory
|
|
507
|
-
// so the caller can refresh and reapply if appropriate.
|
|
508
|
-
|
|
509
|
-
|
|
529
|
+
// so the caller can refresh and reapply if appropriate. The baseline
|
|
530
|
+
// must go back to the pre-read snapshot too: leaving it at the remote
|
|
531
|
+
// we just refused to overwrite would let the next push() pass this
|
|
532
|
+
// comparison and clobber the other machine's write with the same
|
|
533
|
+
// stale local state.
|
|
534
|
+
const remoteEtag = this.lastFetchedEtag;
|
|
535
|
+
rollBackPreRead();
|
|
536
|
+
throw new GistConcurrencyError(preReadEtag, remoteEtag);
|
|
510
537
|
}
|
|
511
538
|
// No conflict — re-apply our staged dirty contents on top of the
|
|
512
539
|
// refreshed remote so the write carries our edits.
|
|
@@ -579,6 +606,34 @@ export class GistStateStore {
|
|
|
579
606
|
}
|
|
580
607
|
}
|
|
581
608
|
// ── Private helpers ─────────────────────────────────────────────────
|
|
609
|
+
/**
|
|
610
|
+
* Refuse to write a file the Gist could no longer serve back (raw_url stops
|
|
611
|
+
* at 10 MB), and warn once a file passes ~900 KB so growth is visible before
|
|
612
|
+
* reads start depending on the truncated-file path.
|
|
613
|
+
*/
|
|
614
|
+
checkPushSize() {
|
|
615
|
+
for (const filename of this.dirtyFiles) {
|
|
616
|
+
const content = this.cachedFiles.get(filename);
|
|
617
|
+
if (content === undefined)
|
|
618
|
+
continue;
|
|
619
|
+
const bytes = Buffer.byteLength(content, 'utf8');
|
|
620
|
+
if (bytes > GIST_RAW_MAX_BYTES) {
|
|
621
|
+
throw new GistFileSizeError(`Refusing to push Gist file ${filename}: ${bytes} bytes exceeds the ${GIST_RAW_MAX_BYTES}-byte limit ` +
|
|
622
|
+
'the Gist API can serve back. The local change is kept in memory but was not synced.');
|
|
623
|
+
}
|
|
624
|
+
if (bytes > GIST_CONTENT_WARN_BYTES) {
|
|
625
|
+
// Once per file per 100 KB band per process, so a long-lived server
|
|
626
|
+
// warns as the file grows instead of on every push.
|
|
627
|
+
const band = Math.floor(bytes / SIZE_WARN_BAND_BYTES);
|
|
628
|
+
if ((warnedSizeBands.get(filename) ?? -1) < band) {
|
|
629
|
+
warnedSizeBands.set(filename, band);
|
|
630
|
+
warn(MODULE, `Gist file ${filename} is ${bytes} bytes, near or past the 1 MB the Gist API returns inline. ` +
|
|
631
|
+
'Reads fall back to raw_url, which works up to 10 MB; to stay well under that, trim large ' +
|
|
632
|
+
'state fields (repoScores and searchSeen are usually the biggest).');
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
582
637
|
/**
|
|
583
638
|
* Preflight check: verify the token has Gist API scope.
|
|
584
639
|
* Costs one cheap API call; catches permission issues early with a clear message.
|
|
@@ -604,15 +659,23 @@ export class GistStateStore {
|
|
|
604
659
|
async fetchAndCache(gistId) {
|
|
605
660
|
const response = await this.octokit.gists.get({ gist_id: gistId });
|
|
606
661
|
this.gistId = gistId;
|
|
662
|
+
// Resolve every file's full content before touching the cache or ETag, so
|
|
663
|
+
// a truncated file we cannot read leaves the store as it was.
|
|
664
|
+
const contents = new Map();
|
|
665
|
+
for (const [filename, file] of Object.entries(response.data.files)) {
|
|
666
|
+
if (!file)
|
|
667
|
+
continue;
|
|
668
|
+
const content = file.truncated ? await this.fetchRawContent(filename, file.raw_url) : file.content;
|
|
669
|
+
if (content != null)
|
|
670
|
+
contents.set(filename, content);
|
|
671
|
+
}
|
|
607
672
|
// Capture the ETag for optimistic-concurrency push (#1115). Header
|
|
608
673
|
// names from Octokit are lower-cased; tolerate both shapes for robustness.
|
|
609
674
|
this.lastFetchedEtag = extractEtag(response.headers);
|
|
610
675
|
// Populate in-memory cache with ALL files from the Gist
|
|
611
676
|
this.cachedFiles.clear();
|
|
612
|
-
for (const [filename,
|
|
613
|
-
|
|
614
|
-
this.cachedFiles.set(filename, file.content);
|
|
615
|
-
}
|
|
677
|
+
for (const [filename, content] of contents) {
|
|
678
|
+
this.cachedFiles.set(filename, content);
|
|
616
679
|
}
|
|
617
680
|
// Snapshot the just-fetched contents as the per-file baseline (#1235).
|
|
618
681
|
// The 412 merge path uses this to detect whether a concurrent write
|
|
@@ -624,6 +687,42 @@ export class GistStateStore {
|
|
|
624
687
|
this.writeLocalStateCache(state);
|
|
625
688
|
return state;
|
|
626
689
|
}
|
|
690
|
+
/**
|
|
691
|
+
* Fetch the full body of a file the Gist API truncated (>1 MB of content).
|
|
692
|
+
*
|
|
693
|
+
* Throws {@link GistFileSizeError} when the body cannot be read for a
|
|
694
|
+
* reason a retry will not fix (no raw_url, off-host raw_url, a non-text
|
|
695
|
+
* body, or a non-transient HTTP error such as 404/413). Rate limits and
|
|
696
|
+
* transient network errors (5xx, ECONNRESET, timeouts) are rethrown as-is
|
|
697
|
+
* so callers keep treating them as retryable: bootstrap degrades to the
|
|
698
|
+
* local cache and the pre-write re-read reports a GistConcurrencyError.
|
|
699
|
+
* Either way the cache is left unchanged.
|
|
700
|
+
*/
|
|
701
|
+
async fetchRawContent(filename, rawUrl) {
|
|
702
|
+
const fail = (reason) => new GistFileSizeError(`Gist file ${filename} is larger than the 1 MB the Gist API returns inline and its full content ` +
|
|
703
|
+
`could not be read from raw_url (${reason}). Local state was left unchanged.`);
|
|
704
|
+
if (!this.octokit.request)
|
|
705
|
+
throw fail('no HTTP client available');
|
|
706
|
+
if (!rawUrl)
|
|
707
|
+
throw fail('the API returned no raw_url');
|
|
708
|
+
const parsed = URL.canParse(rawUrl) ? new URL(rawUrl) : undefined;
|
|
709
|
+
const host = parsed?.protocol === 'https:' ? parsed.hostname : '';
|
|
710
|
+
// The request carries the GitHub token, so only send it to the Gist raw host.
|
|
711
|
+
if (host !== GIST_RAW_HOST)
|
|
712
|
+
throw fail(`unexpected raw_url host`);
|
|
713
|
+
let data;
|
|
714
|
+
try {
|
|
715
|
+
({ data } = await this.octokit.request({ method: 'GET', url: rawUrl }));
|
|
716
|
+
}
|
|
717
|
+
catch (err) {
|
|
718
|
+
if (isRateLimitError(err) || isTransientNetworkError(err))
|
|
719
|
+
throw err;
|
|
720
|
+
throw fail(errorMessage(err));
|
|
721
|
+
}
|
|
722
|
+
if (typeof data !== 'string')
|
|
723
|
+
throw fail('response body was not text');
|
|
724
|
+
return data;
|
|
725
|
+
}
|
|
627
726
|
/**
|
|
628
727
|
* Parse `state.json` from the in-memory cache. Handles v1→v4 migration
|
|
629
728
|
* by running through the Zod schema (which requires version: 4).
|
package/dist/core/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export { daysBetween, formatRelativeTime, byDateDescending } from './dates.js';
|
|
|
16
16
|
export { getCLIVersion, getDataDir, getStatePath, getBackupDir, getCacheDir, stateFileExists } from './paths.js';
|
|
17
17
|
export { getGitHubToken, getGitHubTokenAsync, requireGitHubToken, resetGitHubTokenCache, detectGitHubUsername, } from './auth.js';
|
|
18
18
|
export { DEFAULT_CONCURRENCY } from './concurrency.js';
|
|
19
|
-
export { OssAutopilotError, ConfigurationError, ValidationError, GistPermissionError, ConcurrencyError, GistConcurrencyError, errorMessage, getHttpStatusCode, isRateLimitError, isRateLimitOrAuthError, nonFatalCatch, resolveErrorCode, } from './errors.js';
|
|
19
|
+
export { OssAutopilotError, ConfigurationError, ValidationError, GistPermissionError, ConcurrencyError, GistConcurrencyError, GistFileSizeError, GIST_FILE_SIZE_REMEDY, errorMessage, getHttpStatusCode, isRateLimitError, isRateLimitOrAuthError, nonFatalCatch, resolveErrorCode, } from './errors.js';
|
|
20
20
|
export { enableDebug, isDebugEnabled, debug, info, warn, timed } from './logger.js';
|
|
21
21
|
export { HttpCache, getHttpCache, cachedRequest, type CacheEntry } from './http-cache.js';
|
|
22
22
|
export { CRITICAL_STATUSES, applyStatusOverrides, computeRepoSignals, groupPRsByRepo, assessCapacity, collectActionableIssues, computeActionMenu, toShelvedPRRef, buildStarFilter, firstMaintainerResponseFromDigest, formatActionHint, formatBriefSummary, formatSummary, printDigest, } from './daily-logic.js';
|
package/dist/core/index.js
CHANGED
|
@@ -17,7 +17,7 @@ export { daysBetween, formatRelativeTime, byDateDescending } from './dates.js';
|
|
|
17
17
|
export { getCLIVersion, getDataDir, getStatePath, getBackupDir, getCacheDir, stateFileExists } from './paths.js';
|
|
18
18
|
export { getGitHubToken, getGitHubTokenAsync, requireGitHubToken, resetGitHubTokenCache, detectGitHubUsername, } from './auth.js';
|
|
19
19
|
export { DEFAULT_CONCURRENCY } from './concurrency.js';
|
|
20
|
-
export { OssAutopilotError, ConfigurationError, ValidationError, GistPermissionError, ConcurrencyError, GistConcurrencyError, errorMessage, getHttpStatusCode, isRateLimitError, isRateLimitOrAuthError, nonFatalCatch, resolveErrorCode, } from './errors.js';
|
|
20
|
+
export { OssAutopilotError, ConfigurationError, ValidationError, GistPermissionError, ConcurrencyError, GistConcurrencyError, GistFileSizeError, GIST_FILE_SIZE_REMEDY, errorMessage, getHttpStatusCode, isRateLimitError, isRateLimitOrAuthError, nonFatalCatch, resolveErrorCode, } from './errors.js';
|
|
21
21
|
export { enableDebug, isDebugEnabled, debug, info, warn, timed } from './logger.js';
|
|
22
22
|
export { HttpCache, getHttpCache, cachedRequest } from './http-cache.js';
|
|
23
23
|
export { CRITICAL_STATUSES, applyStatusOverrides, computeRepoSignals, groupPRsByRepo, assessCapacity, collectActionableIssues, computeActionMenu, toShelvedPRRef, buildStarFilter, firstMaintainerResponseFromDigest, formatActionHint, formatBriefSummary, formatSummary, printDigest, } from './daily-logic.js';
|
|
@@ -68,12 +68,14 @@ export interface CommitInfo {
|
|
|
68
68
|
/**
|
|
69
69
|
* Assemble a {@link FetchedPR} from normalized signals.
|
|
70
70
|
*
|
|
71
|
-
* `
|
|
71
|
+
* `commitInfo` is either the HEAD commit already in hand (the GraphQL batch
|
|
72
|
+
* carries it) or a thunk the REST path uses to avoid an extra
|
|
73
|
+
* `repos.getCommit` call. The thunk is invoked only when the status logic
|
|
72
74
|
* needs the HEAD commit date (an unresponded maintainer comment or a
|
|
73
|
-
* changes-requested review).
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
75
|
+
* changes-requested review). `determineStatus` consults the date only in
|
|
76
|
+
* those same branches, so status is identical either way; the difference is
|
|
77
|
+
* that a known commit is always recorded on the PR, which keeps
|
|
78
|
+
* `latestActivityAt` (override auto-clear, #1713) off `updatedAt` for PRs
|
|
79
|
+
* with no human comments.
|
|
78
80
|
*/
|
|
79
|
-
export declare function assembleFetchedPR(signals: PRSignals, config: AssemblyConfig,
|
|
81
|
+
export declare function assembleFetchedPR(signals: PRSignals, config: AssemblyConfig, commitInfo: CommitInfo | undefined | (() => Promise<CommitInfo | undefined>)): Promise<FetchedPR>;
|
package/dist/core/pr-assembly.js
CHANGED
|
@@ -19,15 +19,17 @@ import { computeDisplayLabel } from './display-utils.js';
|
|
|
19
19
|
/**
|
|
20
20
|
* Assemble a {@link FetchedPR} from normalized signals.
|
|
21
21
|
*
|
|
22
|
-
* `
|
|
22
|
+
* `commitInfo` is either the HEAD commit already in hand (the GraphQL batch
|
|
23
|
+
* carries it) or a thunk the REST path uses to avoid an extra
|
|
24
|
+
* `repos.getCommit` call. The thunk is invoked only when the status logic
|
|
23
25
|
* needs the HEAD commit date (an unresponded maintainer comment or a
|
|
24
|
-
* changes-requested review).
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* changes-requested review). `determineStatus` consults the date only in
|
|
27
|
+
* those same branches, so status is identical either way; the difference is
|
|
28
|
+
* that a known commit is always recorded on the PR, which keeps
|
|
29
|
+
* `latestActivityAt` (override auto-clear, #1713) off `updatedAt` for PRs
|
|
30
|
+
* with no human comments.
|
|
29
31
|
*/
|
|
30
|
-
export async function assembleFetchedPR(signals, config,
|
|
32
|
+
export async function assembleFetchedPR(signals, config, commitInfo) {
|
|
31
33
|
const { comments, reviews, reviewComments } = signals;
|
|
32
34
|
// Determine review decision (delegated to review-analysis module)
|
|
33
35
|
const reviewDecision = determineReviewDecision(reviews);
|
|
@@ -42,9 +44,11 @@ export async function assembleFetchedPR(signals, config, getCommitInfo) {
|
|
|
42
44
|
// no new commits pushed). Fetched lazily so the REST path skips the call when
|
|
43
45
|
// it isn't needed.
|
|
44
46
|
const needCommitDate = hasUnrespondedComment || reviewDecision === 'changes_requested';
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
let headCommit = typeof commitInfo === 'function' ? undefined : commitInfo;
|
|
48
|
+
if (typeof commitInfo === 'function' && needCommitDate)
|
|
49
|
+
headCommit = await commitInfo();
|
|
50
|
+
const latestCommitDate = headCommit?.date;
|
|
51
|
+
const latestCommitAuthor = headCommit?.author;
|
|
48
52
|
// Analyze PR body for incomplete checklists (delegated to checklist-analysis module)
|
|
49
53
|
const { hasIncompleteChecklist, checklistStats } = analyzeChecklist(signals.body || '');
|
|
50
54
|
// Extract maintainer action hints from comments (delegated to maintainer-analysis module)
|
|
@@ -96,8 +96,8 @@ export declare class PRMonitor {
|
|
|
96
96
|
private fetchCommitInfo;
|
|
97
97
|
/**
|
|
98
98
|
* Assemble a {@link FetchedPR} from GraphQL-batched {@link NormalizedPRData}.
|
|
99
|
-
* No network calls: the batch already carries the commit info, so
|
|
100
|
-
*
|
|
99
|
+
* No network calls: the batch already carries the commit info, so it is
|
|
100
|
+
* passed directly and always recorded on the PR.
|
|
101
101
|
*/
|
|
102
102
|
private assembleFromNormalized;
|
|
103
103
|
/**
|
package/dist/core/pr-monitor.js
CHANGED
|
@@ -369,6 +369,11 @@ export class PRMonitor {
|
|
|
369
369
|
// The commit date is only consulted (and only fetched) when the PR has an
|
|
370
370
|
// unresponded maintainer comment or a changes-requested review — the shared
|
|
371
371
|
// pipeline decides via `needCommitDate` and invokes this thunk lazily.
|
|
372
|
+
// A PR with a status override is the exception: override auto-clear keys
|
|
373
|
+
// on the commit date (#1713), so fetch it up front for those PRs only.
|
|
374
|
+
const commitInfo = config.statusOverrides?.[prUrl]
|
|
375
|
+
? await this.fetchCommitInfo(owner, repo, ghPR.head.sha)
|
|
376
|
+
: () => this.fetchCommitInfo(owner, repo, ghPR.head.sha);
|
|
372
377
|
return assembleFetchedPR({
|
|
373
378
|
prUrl,
|
|
374
379
|
owner,
|
|
@@ -384,7 +389,7 @@ export class PRMonitor {
|
|
|
384
389
|
reviews,
|
|
385
390
|
reviewComments,
|
|
386
391
|
ciStatus,
|
|
387
|
-
}, config,
|
|
392
|
+
}, config, commitInfo);
|
|
388
393
|
}
|
|
389
394
|
/**
|
|
390
395
|
* Fetch the HEAD commit's author date and login via REST `repos.getCommit`.
|
|
@@ -419,8 +424,8 @@ export class PRMonitor {
|
|
|
419
424
|
}
|
|
420
425
|
/**
|
|
421
426
|
* Assemble a {@link FetchedPR} from GraphQL-batched {@link NormalizedPRData}.
|
|
422
|
-
* No network calls: the batch already carries the commit info, so
|
|
423
|
-
*
|
|
427
|
+
* No network calls: the batch already carries the commit info, so it is
|
|
428
|
+
* passed directly and always recorded on the PR.
|
|
424
429
|
*/
|
|
425
430
|
assembleFromNormalized(ref, data) {
|
|
426
431
|
const config = this.stateManager.getState().config;
|
|
@@ -439,7 +444,7 @@ export class PRMonitor {
|
|
|
439
444
|
reviews: data.reviews,
|
|
440
445
|
reviewComments: data.reviewComments,
|
|
441
446
|
ciStatus: data.ciStatus,
|
|
442
|
-
}, config,
|
|
447
|
+
}, config, data.commitInfo);
|
|
443
448
|
}
|
|
444
449
|
/**
|
|
445
450
|
* Fetch merged PR counts and latest merge dates per repository for the configured user.
|
|
@@ -98,7 +98,7 @@ export const PR_QUALITY_RUBRIC = [
|
|
|
98
98
|
{
|
|
99
99
|
id: 'screenshots',
|
|
100
100
|
label: 'Screenshots',
|
|
101
|
-
description: '
|
|
101
|
+
description: 'Only for visible changes when the template or a maintainer asks',
|
|
102
102
|
tier: 'optional',
|
|
103
103
|
weight: null,
|
|
104
104
|
},
|