@oss-autopilot/core 3.24.0 → 3.25.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.
@@ -20,7 +20,7 @@ import { execFileSync } from 'node:child_process';
20
20
  import * as fs from 'node:fs';
21
21
  import { errorMessage, getOctokit, getStateManager, isRateLimitError, maybeCheckpoint, parseGitHubUrl, requireGitHubToken, } from '../core/index.js';
22
22
  import { warn } from '../core/logger.js';
23
- import { writePreparedSection } from './overnight.js';
23
+ import { publishReport, writePreparedSection } from './overnight.js';
24
24
  const MODULE = 'overnight-push-prep';
25
25
  /** The only ref namespace this command ever pushes to. */
26
26
  export const PREP_REF_PREFIX = 'refs/heads/prep/';
@@ -286,6 +286,10 @@ export async function runOvernightPushPrep(options) {
286
286
  reportWarning = `could not rewrite ${lastRun.reportPath}: ${errorMessage(err)}`;
287
287
  warn(MODULE, reportWarning);
288
288
  }
289
+ // Outside the try: publishReport warns on its own and must never be
290
+ // mistaken for a failed report write.
291
+ if (!reportWarning)
292
+ publishReport(sm, lastRun.reportPath);
289
293
  gistSyncWarning = await maybeCheckpoint(sm, MODULE);
290
294
  }
291
295
  try {
@@ -18,6 +18,7 @@
18
18
  * the model: a scheduler runs it after the tick, and it only pushes to
19
19
  * `prep/*` on the user's own fork.
20
20
  */
21
+ import { getStateManager } from '../core/index.js';
21
22
  import type { PRCheckFailure } from '../core/pr-monitor.js';
22
23
  import type { ActionableIssueType, OvernightPrepared } from '../core/types.js';
23
24
  import type { DailyOutput, DailyWarning, PendingLearnings } from '../formatters/json.js';
@@ -59,6 +60,8 @@ export interface OvernightFreshness {
59
60
  judgmentCount: number;
60
61
  /** Branches recorded via `overnight record` since the run. */
61
62
  preparedCount: number;
63
+ /** `local`: the file at `reportPath` is here. `gist`: only the published copy, read it with `overnight report`. */
64
+ reportAvailable: ReportAvailability;
62
65
  }
63
66
  /** Pure: split the daily check into prepare vs judgment items. */
64
67
  export declare function bucketize(daily: Pick<DailyOutput, 'actionableIssues' | 'commentedIssues'>): {
@@ -98,6 +101,32 @@ export interface OvernightRecordOutput {
98
101
  export declare function runOvernightRecord(options: OvernightRecordOptions): Promise<OvernightRecordOutput>;
99
102
  /** Pure: swap the "Prepared branches" section (up to the next `## `) for `section`. */
100
103
  export declare function replacePreparedSection(report: string, section: string): string;
104
+ /**
105
+ * Stage the report file's current contents as the Gist's `overnight-report.md`
106
+ * (#1698), so `/oss` on another machine can read what a headless box wrote.
107
+ * Callers checkpoint right after. A report that cannot be read is a warning,
108
+ * not a failure: the run itself succeeded.
109
+ */
110
+ export declare function publishReport(sm: ReturnType<typeof getStateManager>, reportPath: string): void;
111
+ /** Where `overnight report` can read the morning report from. */
112
+ export type ReportAvailability = 'local' | 'gist' | 'none';
113
+ /**
114
+ * The morning report's text and where it came from: the local file when it
115
+ * exists (the machine that ran overnight), else the Gist copy (any other
116
+ * machine in Gist mode), else nothing.
117
+ */
118
+ export declare function readReport(sm: ReturnType<typeof getStateManager>, reportPath: string): {
119
+ source: ReportAvailability;
120
+ content: string | null;
121
+ };
122
+ export interface OvernightReportOutput {
123
+ runAt: string;
124
+ reportPath: string;
125
+ source: ReportAvailability;
126
+ content: string | null;
127
+ }
128
+ /** `overnight report`: print the latest morning report from wherever it is readable. */
129
+ export declare function runOvernightReport(): OvernightReportOutput;
101
130
  /** Freshness for `startup` (#1574); undefined before the first overnight run. */
102
131
  export declare function overnightFreshness(now?: Date): OvernightFreshness | undefined;
103
132
  export interface ScheduleOptions {
@@ -21,7 +21,7 @@
21
21
  import * as fs from 'node:fs';
22
22
  import * as os from 'node:os';
23
23
  import * as path from 'node:path';
24
- import { getStateManager, maybeCheckpoint, requireGitHubToken } from '../core/index.js';
24
+ import { errorMessage, getStateManager, maybeCheckpoint, requireGitHubToken } from '../core/index.js';
25
25
  import { warn } from '../core/logger.js';
26
26
  import { getReportsDir } from '../core/paths.js';
27
27
  import { executeDailyCheck } from './daily.js';
@@ -32,7 +32,14 @@ const BUCKET_BY_TYPE = {
32
32
  ci_failing: { bucket: 'prepare', reason: 'CI is red: an agent can diagnose and prepare a fix branch' },
33
33
  merge_conflict: { bucket: 'prepare', reason: 'merge conflict: an agent can rebase in a worktree' },
34
34
  needs_changes: { bucket: 'prepare', reason: 'changes requested: an agent can prepare the requested edits' },
35
- incomplete_checklist: { bucket: 'prepare', reason: 'checklist incomplete: an agent can fill in the missing items' },
35
+ // The gaps are PR-body checkboxes, and the only way to tick them is
36
+ // `gh pr edit --body`, a write the unattended run must not make. Two
37
+ // nights of preparers spent on these both ended blocked with a suggested
38
+ // body edit for the morning, so that suggestion is now the judgment item.
39
+ incomplete_checklist: {
40
+ bucket: 'judgment',
41
+ reason: 'checklist incomplete: the gaps are PR-body checkboxes, which only you can edit',
42
+ },
36
43
  needs_response: { bucket: 'judgment', reason: 'a maintainer is waiting on your reply' },
37
44
  };
38
45
  /** Pure: split the daily check into prepare vs judgment items. */
@@ -148,6 +155,7 @@ export async function runOvernight() {
148
155
  const previous = sm.getLastOvernight();
149
156
  const carried = previous?.reportPath === reportPath ? previous.prepared : [];
150
157
  fs.writeFileSync(reportPath, renderReport(body, carried), { mode: 0o600 });
158
+ publishReport(sm, reportPath);
151
159
  sm.setLastOvernight({
152
160
  runAt,
153
161
  reportPath,
@@ -182,6 +190,7 @@ export async function runOvernightRecord(options) {
182
190
  const prepared = [...last.prepared, entry];
183
191
  sm.setLastOvernight({ ...last, prepared });
184
192
  const { reportRecreated } = writePreparedSection(last.reportPath, prepared);
193
+ publishReport(sm, last.reportPath);
185
194
  const gistSyncWarning = await maybeCheckpoint(sm, MODULE);
186
195
  return {
187
196
  reportPath: last.reportPath,
@@ -198,6 +207,41 @@ export function replacePreparedSection(report, section) {
198
207
  const next = report.indexOf('\n## ', start + PREPARED_HEADING.length);
199
208
  return report.slice(0, start) + section + (next === -1 ? '' : report.slice(next));
200
209
  }
210
+ /**
211
+ * Stage the report file's current contents as the Gist's `overnight-report.md`
212
+ * (#1698), so `/oss` on another machine can read what a headless box wrote.
213
+ * Callers checkpoint right after. A report that cannot be read is a warning,
214
+ * not a failure: the run itself succeeded.
215
+ */
216
+ export function publishReport(sm, reportPath) {
217
+ if (!sm.isGistMode())
218
+ return;
219
+ try {
220
+ sm.setOvernightReportDocument(fs.readFileSync(reportPath, 'utf8'));
221
+ }
222
+ catch (err) {
223
+ warn(MODULE, `Could not publish ${reportPath} to the Gist: ${errorMessage(err)}`);
224
+ }
225
+ }
226
+ /**
227
+ * The morning report's text and where it came from: the local file when it
228
+ * exists (the machine that ran overnight), else the Gist copy (any other
229
+ * machine in Gist mode), else nothing.
230
+ */
231
+ export function readReport(sm, reportPath) {
232
+ if (fs.existsSync(reportPath))
233
+ return { source: 'local', content: fs.readFileSync(reportPath, 'utf8') };
234
+ const gist = sm.getOvernightReportDocument();
235
+ return gist ? { source: 'gist', content: gist } : { source: 'none', content: null };
236
+ }
237
+ /** `overnight report`: print the latest morning report from wherever it is readable. */
238
+ export function runOvernightReport() {
239
+ const sm = getStateManager();
240
+ const last = sm.getLastOvernight();
241
+ if (!last)
242
+ throw new Error('No overnight run recorded yet; run `overnight` first.');
243
+ return { runAt: last.runAt, reportPath: last.reportPath, ...readReport(sm, last.reportPath) };
244
+ }
201
245
  /** Freshness for `startup` (#1574); undefined before the first overnight run. */
202
246
  export function overnightFreshness(now = new Date()) {
203
247
  const last = getStateManager().getLastOvernight();
@@ -210,6 +254,7 @@ export function overnightFreshness(now = new Date()) {
210
254
  prepareCount: last.prepareCount,
211
255
  judgmentCount: last.judgmentCount,
212
256
  preparedCount: last.prepared.length,
257
+ reportAvailable: readReport(getStateManager(), last.reportPath).source,
213
258
  };
214
259
  // Never emit a non-finite number into the JSON contract (Infinity serialises as null).
215
260
  return Number.isNaN(ageMs)
@@ -266,6 +311,10 @@ const GH_READ_SUBCOMMANDS = [
266
311
  export const OVERNIGHT_DISALLOWED_TOOLS = [
267
312
  'Bash(git push)',
268
313
  'Bash(git push *)',
314
+ // The -C form of push: `git -C <dir> push` would otherwise slip past a
315
+ // prefix rule on `git push`.
316
+ 'Bash(git * push)',
317
+ 'Bash(git * push *)',
269
318
  'Bash(gh pr create *)',
270
319
  'Bash(gh pr comment *)',
271
320
  'Bash(gh pr merge *)',
@@ -295,7 +344,15 @@ export const OVERNIGHT_ALLOWED_TOOLS = [
295
344
  'Glob',
296
345
  'Grep',
297
346
  'Task',
298
- ...GIT_SUBCOMMANDS.map((sub) => `Bash(git ${sub} *)`),
347
+ // Both the bare and the `-C <dir>` forms: a preparer's worktree is never its
348
+ // cwd, and `cd <dir> && git ...` is denied under dontAsk, so without `-C`
349
+ // every preparer blocks (#1697).
350
+ ...GIT_SUBCOMMANDS.flatMap((sub) => [
351
+ `Bash(git ${sub})`,
352
+ `Bash(git ${sub} *)`,
353
+ `Bash(git -C * ${sub})`,
354
+ `Bash(git -C * ${sub} *)`,
355
+ ]),
299
356
  ...GH_READ_SUBCOMMANDS.map((sub) => `Bash(gh ${sub} *)`),
300
357
  'Bash(node *)',
301
358
  'Bash(pnpm *)',
@@ -6,7 +6,7 @@ import { getStateManager } from '../core/index.js';
6
6
  // version where the captures are needed.
7
7
  // eslint-disable-next-line regexp/no-unused-capturing-group
8
8
  const GITHUB_URL_RE = /^https:\/\/github\.com\/([^/]+\/[^/]+)\/(?:issues|pull)\/(\d+)(?:[#/?].*)?$/;
9
- const FILE_HEADER = '# Skipped Issues — auto-culled after 90 days\n# Format: YYYY-MM-DD URL\n\n';
9
+ const FILE_HEADER = '# Skipped Issues — permanent\n# Format: YYYY-MM-DD URL\n\n';
10
10
  function formatUtcDate(d) {
11
11
  return d.toISOString().slice(0, 10);
12
12
  }
@@ -206,9 +206,19 @@ function shouldOpenBrowser(spaResult, throttleMs) {
206
206
  }
207
207
  async function triggerDashboardRefresh(port) {
208
208
  try {
209
- const res = await fetch(`http://127.0.0.1:${port}/api/refresh`, {
209
+ const base = `http://127.0.0.1:${port}`;
210
+ // POST /api/refresh is CSRF-gated and the token is only issued on the
211
+ // X-CSRF-Token header of GET /api/data, so prime it first.
212
+ const prime = await fetch(`${base}/api/data`, { signal: AbortSignal.timeout(5000) });
213
+ const csrfToken = prime.headers.get('x-csrf-token');
214
+ await prime.text().catch(() => { });
215
+ if (!prime.ok || !csrfToken) {
216
+ console.error(`[STARTUP] Dashboard refresh returned ${prime.status}: no CSRF token from /api/data`);
217
+ return false;
218
+ }
219
+ const res = await fetch(`${base}/api/refresh`, {
210
220
  method: 'POST',
211
- headers: { Origin: `http://oss.localhost:${port}` },
221
+ headers: { Origin: `http://oss.localhost:${port}`, 'X-CSRF-Token': csrfToken },
212
222
  signal: AbortSignal.timeout(5000),
213
223
  });
214
224
  if (!res.ok) {
@@ -198,7 +198,7 @@ export const CONFIG_KEY_REGISTRY = [
198
198
  },
199
199
  {
200
200
  key: 'skippedIssuesPath',
201
- description: 'Path to the skipped-issues file (auto-culls entries older than 90 days).',
201
+ description: 'Path to the skipped-issues file (entries are permanent).',
202
202
  settableVia: 'setup',
203
203
  valueHint: 'filesystem path',
204
204
  },
@@ -77,6 +77,7 @@ export interface BatchPRResult {
77
77
  }
78
78
  interface GraphQLActor {
79
79
  login: string;
80
+ __typename?: string;
80
81
  }
81
82
  interface GraphQLCheckRunNode {
82
83
  __typename: 'CheckRun';
@@ -39,6 +39,14 @@ export const THREAD_COMMENTS_CAP = 20;
39
39
  * contexts than this is sent to REST so a failing check beyond the cap can't be
40
40
  * silently dropped and mislabel the PR as passing. */
41
41
  export const CI_CONTEXTS_CAP = 100;
42
+ /**
43
+ * GraphQL reports a GitHub App as `__typename: 'Bot'` with a bare login, where
44
+ * REST reports the same account as `login: 'name[bot]'`. Restore the REST spelling
45
+ * so `isBotAuthor()` and every downstream consumer see one form of the login.
46
+ */
47
+ function restLogin(actor) {
48
+ return actor.__typename === 'Bot' && !actor.login.endsWith('[bot]') ? `${actor.login}[bot]` : actor.login;
49
+ }
42
50
  const PR_FIELDS = `
43
51
  databaseId
44
52
  number
@@ -50,11 +58,11 @@ const PR_FIELDS = `
50
58
  updatedAt
51
59
  comments(last: ${COMMENTS_CAP}) {
52
60
  totalCount
53
- nodes { author { login } body createdAt }
61
+ nodes { author { login __typename } body createdAt }
54
62
  }
55
63
  reviews(last: ${REVIEWS_CAP}) {
56
64
  totalCount
57
- nodes { databaseId state body submittedAt author { login } }
65
+ nodes { databaseId state body submittedAt author { login __typename } }
58
66
  }
59
67
  reviewThreads(last: ${REVIEW_THREADS_CAP}) {
60
68
  totalCount
@@ -65,7 +73,7 @@ const PR_FIELDS = `
65
73
  databaseId
66
74
  body
67
75
  createdAt
68
- author { login }
76
+ author { login __typename }
69
77
  replyTo { databaseId }
70
78
  pullRequestReview { databaseId }
71
79
  }
@@ -164,7 +172,7 @@ export function normalizePRNode(node) {
164
172
  return { kind: 'overflow' };
165
173
  }
166
174
  const comments = node.comments.nodes.map((c) => ({
167
- user: c.author ? { login: c.author.login } : null,
175
+ user: c.author ? { login: restLogin(c.author) } : null,
168
176
  body: c.body,
169
177
  created_at: c.createdAt,
170
178
  }));
@@ -173,7 +181,7 @@ export function normalizePRNode(node) {
173
181
  const reviews = node.reviews.nodes
174
182
  .filter((r) => r.state !== 'PENDING')
175
183
  .map((r) => ({
176
- user: r.author ? { login: r.author.login } : null,
184
+ user: r.author ? { login: restLogin(r.author) } : null,
177
185
  body: r.body,
178
186
  submitted_at: r.submittedAt,
179
187
  state: r.state,
@@ -181,7 +189,7 @@ export function normalizePRNode(node) {
181
189
  }));
182
190
  const reviewComments = node.reviewThreads.nodes.flatMap((thread) => thread.comments.nodes.map((c) => ({
183
191
  id: c.databaseId ?? 0,
184
- user: c.author ? { login: c.author.login } : null,
192
+ user: c.author ? { login: restLogin(c.author) } : null,
185
193
  body: c.body,
186
194
  created_at: c.createdAt,
187
195
  in_reply_to_id: c.replyTo?.databaseId ?? undefined,
@@ -7,6 +7,8 @@ import { AgentState, TrackedIssue, RepoScore, RepoScoreUpdate, DailyDigest, Loca
7
7
  import { type LoadRecoveryInfo } from './state-persistence.js';
8
8
  import type { Stats } from './repo-score-manager.js';
9
9
  import { GistStateStore } from './gist-state-store.js';
10
+ /** Gist file that carries the rendered overnight report across machines (#1698). */
11
+ export declare const OVERNIGHT_REPORT_DOCUMENT = "overnight-report.md";
10
12
  import { type GistHealth } from './gist-health.js';
11
13
  export { acquireLock, releaseLock, atomicWriteFileSync } from './state-persistence.js';
12
14
  export type { LoadRecoveryInfo } from './state-persistence.js';
@@ -371,6 +373,18 @@ export declare class StateManager {
371
373
  * and cull stale entries before calling this; the manager only persists.
372
374
  */
373
375
  setSearchSeen(seen: SearchSeenEntry[]): void;
376
+ /**
377
+ * The rendered morning report as last published to the Gist (#1698), so a
378
+ * machine other than the one that ran overnight can read it. Null in local
379
+ * mode or before the first publish.
380
+ */
381
+ getOvernightReportDocument(): string | null;
382
+ /**
383
+ * Stage the rendered morning report for the next Gist push (#1698).
384
+ * Freeform document, last-write-wins like guidelines. No-op in local mode:
385
+ * the file on disk is the only copy there, which is fine on one machine.
386
+ */
387
+ setOvernightReportDocument(content: string): void;
374
388
  /** Latest overnight run (#1574); `undefined` before the first one. */
375
389
  getLastOvernight(): OvernightRecord | undefined;
376
390
  /** Replace the overnight record (#1574): a new run, or a run plus a recorded branch. */
@@ -11,6 +11,8 @@ import { debug, warn } from './logger.js';
11
11
  import { errorMessage, ConfigurationError, ConcurrencyError, isTransientNetworkError } from './errors.js';
12
12
  import { GistStateStore } from './gist-state-store.js';
13
13
  import * as guidelinesStoreModule from './guidelines-store.js';
14
+ /** Gist file that carries the rendered overnight report across machines (#1698). */
15
+ export const OVERNIGHT_REPORT_DOCUMENT = 'overnight-report.md';
14
16
  import { renderGistWarning } from './gist-health.js';
15
17
  import { getStatePath, getStateCachePath, getGistIdPath } from './paths.js';
16
18
  import { parseGitHubUrl } from './urls.js';
@@ -879,6 +881,23 @@ export class StateManager {
879
881
  this.state.searchSeen = seen;
880
882
  this.autoSave();
881
883
  }
884
+ /**
885
+ * The rendered morning report as last published to the Gist (#1698), so a
886
+ * machine other than the one that ran overnight can read it. Null in local
887
+ * mode or before the first publish.
888
+ */
889
+ getOvernightReportDocument() {
890
+ const content = this.gistStore?.getDocument(OVERNIGHT_REPORT_DOCUMENT) ?? null;
891
+ return content === '' ? null : content;
892
+ }
893
+ /**
894
+ * Stage the rendered morning report for the next Gist push (#1698).
895
+ * Freeform document, last-write-wins like guidelines. No-op in local mode:
896
+ * the file on disk is the only copy there, which is fine on one machine.
897
+ */
898
+ setOvernightReportDocument(content) {
899
+ this.gistStore?.setDocument(OVERNIGHT_REPORT_DOCUMENT, content);
900
+ }
882
901
  /** Latest overnight run (#1574); `undefined` before the first one. */
883
902
  getLastOvernight() {
884
903
  return this.state.lastOvernight;
@@ -1228,6 +1228,17 @@ export declare const LocalReposOutputSchema: z.ZodObject<{
1228
1228
  cachedAt: z.ZodString;
1229
1229
  fromCache: z.ZodBoolean;
1230
1230
  }, z.core.$strip>;
1231
+ /** `overnight report` (#1698): the morning report from wherever it is readable. */
1232
+ export declare const OvernightReportOutputSchema: z.ZodObject<{
1233
+ runAt: z.ZodString;
1234
+ reportPath: z.ZodString;
1235
+ source: z.ZodEnum<{
1236
+ none: "none";
1237
+ local: "local";
1238
+ gist: "gist";
1239
+ }>;
1240
+ content: z.ZodNullable<z.ZodString>;
1241
+ }, z.core.$strip>;
1231
1242
  export declare const OvernightPushPrepOutputSchema: z.ZodObject<{
1232
1243
  dryRun: z.ZodBoolean;
1233
1244
  login: z.ZodString;
@@ -773,6 +773,13 @@ const PushPrepResultSchema = z.object({
773
773
  compareUrl: z.string().optional(),
774
774
  reason: z.string().optional(),
775
775
  });
776
+ /** `overnight report` (#1698): the morning report from wherever it is readable. */
777
+ export const OvernightReportOutputSchema = z.object({
778
+ runAt: z.string(),
779
+ reportPath: z.string(),
780
+ source: z.enum(['local', 'gist', 'none']),
781
+ content: z.string().nullable(),
782
+ });
776
783
  export const OvernightPushPrepOutputSchema = z.object({
777
784
  dryRun: z.boolean(),
778
785
  login: z.string(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oss-autopilot/core",
3
- "version": "3.24.0",
3
+ "version": "3.25.0",
4
4
  "description": "CLI and core library for managing open source contributions",
5
5
  "type": "module",
6
6
  "bin": {
@@ -55,7 +55,7 @@
55
55
  "@octokit/plugin-retry": "^8.1.1",
56
56
  "@octokit/plugin-throttling": "^11.0.5",
57
57
  "@octokit/rest": "^22.0.1",
58
- "@oss-scout/core": "^1.7.0",
58
+ "@oss-scout/core": "^1.8.0",
59
59
  "commander": "^15.0.0",
60
60
  "zod": "^4.5.4"
61
61
  },