next-issue 7.6.0 → 7.7.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/README.md CHANGED
@@ -180,8 +180,13 @@ the run handles one issue. For each issue:
180
180
  `schedule`) started, since GitHub gives such a run the tip of the
181
181
  default branch as its commit. It also leaves out the `push` runs that a
182
182
  push of a tag or of another branch started on the same commit, such as
183
- a release or a deploy. A failed or errored commit status, or a
184
- workflow run or check run that ends with `failure`, `timed_out` or
183
+ a release or a deploy. It leaves out every GitHub Actions job, check run
184
+ and commit status whose name is in `ignoredChecks`: it does not wait for
185
+ it, its result does not fail the checks and its logs do not go to the
186
+ fixer. With `ignoredChecks` set, the harness judges each workflow run by
187
+ its other jobs, so a run whose only failed job is ignored passes. A
188
+ failed or errored commit status, or a workflow run or check run that
189
+ ends with `failure`, `timed_out` or
185
190
  `action_required`, fails the checks. The harness does not rerun a
186
191
  workflow run that ends `action_required`, since it waits for a person
187
192
  to approve it. When any check ends `cancelled`, for example because
@@ -600,6 +605,7 @@ because no pull request is opened.
600
605
  "keepRunDays": 7,
601
606
  "checks": [],
602
607
  "checksTimeoutMinutes": 30,
608
+ "ignoredChecks": [],
603
609
  "models": {
604
610
  "implementer": null,
605
611
  "reviewer": null,
@@ -637,6 +643,7 @@ because no pull request is opened.
637
643
  | `keepRunDays` | `7` | The number of days to keep the run files; `0` keeps them all |
638
644
  | `checks` | `[]` | Shell commands that must pass in the worktree, in order, before an approved change is pushed; a failure goes to the fixer |
639
645
  | `checksTimeoutMinutes` | `30` | The limit for one command in `checks`, at most `35791` |
646
+ | `ignoredChecks` | `[]` | Names of GitHub Actions jobs, check runs and commit statuses, such as `release`, that the checks on the base branch do not wait for and whose failure does not count |
640
647
  | `setupCommand` | from the lock file | A shell command to run in a new worktree, before the implementer |
641
648
  | `models` | `null` per role | The pi model per agent role, as `provider/model`: `implementer`, `reviewer`, `fixer` |
642
649
  | `labels` | see above | The names of the labels that the harness reads and sets |
@@ -16,11 +16,40 @@ function jsonLines(raw) {
16
16
  .filter((line) => line.trim() !== '')
17
17
  .map((line) => JSON.parse(line));
18
18
  }
19
- async function baseRuns(repo, sha, branch) {
19
+ async function baseRuns(repo, sha, branch, ignored) {
20
20
  const runs = await ghApi(repo, `actions/runs?head_sha=${sha}&per_page=100`, '.workflow_runs[] | {databaseId: .id, name, status, conclusion: (.conclusion // ""), attempt: .run_attempt, event, branch: (.head_branch // "")} | @json', { paginate: true });
21
- return jsonLines(runs).filter((entry) => entry.event === 'push' && entry.branch === branch);
21
+ const pushed = jsonLines(runs).filter((entry) => entry.event === 'push' && entry.branch === branch);
22
+ if (ignored.length === 0) {
23
+ return pushed;
24
+ }
25
+ const judged = await Promise.all(pushed.map((entry) => withoutIgnored(repo, entry, ignored)));
26
+ return judged.filter((entry) => entry !== undefined);
27
+ }
28
+ /** Judges a workflow run by its jobs outside the ignored checks; a run with no job yet, or a running one whose listed jobs all finished, keeps its own state, as a job not listed yet may follow. */
29
+ async function withoutIgnored(repo, run, ignored) {
30
+ const jobs = jsonLines(await ghApi(repo, `actions/runs/${run.databaseId}/jobs?filter=latest&per_page=100`, '.jobs[] | {databaseId: .id, name, status, conclusion: (.conclusion // "")} | @json', { paginate: true }));
31
+ if (jobs.length === 0 || (run.status !== 'completed' && jobs.every(completedJob))) {
32
+ return run;
33
+ }
34
+ const kept = jobs.filter((job) => !ignored.includes(job.name));
35
+ if (kept.length === 0) {
36
+ return undefined;
37
+ }
38
+ if (!kept.every(completedJob)) {
39
+ return { ...run, status: 'in_progress', conclusion: '', jobs: kept };
40
+ }
41
+ return { ...run, status: 'completed', conclusion: jobsConclusion(kept), jobs: kept };
42
+ }
43
+ function completedJob(job) {
44
+ return job.status === 'completed';
45
+ }
46
+ function jobsConclusion(jobs) {
47
+ if (jobs.some(failedRun)) {
48
+ return 'failure';
49
+ }
50
+ return jobs.some((job) => job.conclusion === 'cancelled') ? 'cancelled' : 'success';
22
51
  }
23
- async function externalChecks(repo, sha) {
52
+ async function externalChecks(repo, sha, ignored) {
24
53
  const [runs, statuses] = await Promise.all([
25
54
  ghApi(repo, `commits/${sha}/check-runs?per_page=100`, '.check_runs[] | {name, status, conclusion, app: .app.slug, url: .details_url} | @json', { paginate: true }),
26
55
  ghApi(repo, `commits/${sha}/status?per_page=100`, '.statuses[] | {name: .context, state, url: .target_url} | @json', { paginate: true }),
@@ -39,12 +68,12 @@ async function externalChecks(repo, sha) {
39
68
  conclusion: FAILED_STATES.has(entry.state) ? 'failure' : entry.state,
40
69
  url: entry.url ?? '',
41
70
  }));
42
- return [...checkRuns, ...commitStatuses];
71
+ return [...checkRuns, ...commitStatuses].filter((entry) => !ignored.includes(entry.name));
43
72
  }
44
- async function baseChecks(repo, sha, branch, restarted) {
73
+ async function baseChecks(repo, sha, branch, restarted, ignored) {
45
74
  const [runs, external] = await Promise.all([
46
- baseRuns(repo, sha, branch),
47
- externalChecks(repo, sha),
75
+ baseRuns(repo, sha, branch, ignored),
76
+ externalChecks(repo, sha, ignored),
48
77
  ]);
49
78
  // A rerun run counts as running until a later attempt of it completes, so its old failure never ends the wait.
50
79
  const rerunning = restarted.some((entry) => !runs.some((run) => run.databaseId === entry.id && run.attempt > entry.attempt && run.status === 'completed'));
@@ -71,7 +100,7 @@ function baseState(runs, external) {
71
100
  }
72
101
  return checks.some((entry) => entry.conclusion === 'cancelled') ? 'cancelled' : 'pass';
73
102
  }
74
- export function waitForBaseChecks(repo, sha, branch, options, restarted = []) {
103
+ export function waitForBaseChecks(repo, sha, branch, options, restarted = [], ignored = []) {
75
104
  let read = {
76
105
  runs: [],
77
106
  external: [],
@@ -81,20 +110,20 @@ export function waitForBaseChecks(repo, sha, branch, options, restarted = []) {
81
110
  head: async () => sha,
82
111
  lags: async () => true,
83
112
  list: async () => {
84
- read = await baseChecks(repo, sha, branch, restarted);
113
+ read = await baseChecks(repo, sha, branch, restarted, ignored);
85
114
  return read.runs.length + read.external.length === 0 && !read.rerunning ? 'none' : 'some';
86
115
  },
87
116
  watch: async () => (read.rerunning ? 'pending' : baseState(read.runs, read.external)),
88
117
  }, options);
89
118
  }
90
- export async function rerunFailedBase(repo, sha, branch, started = () => { }) {
91
- const failed = (await baseRuns(repo, sha, branch)).filter(rerunnable);
119
+ export async function rerunFailedBase(repo, sha, branch, started = () => { }, ignored = []) {
120
+ const failed = (await baseRuns(repo, sha, branch, ignored)).filter(rerunnable);
92
121
  for (const entry of failed) {
93
122
  await rerun(repo, entry.databaseId);
94
123
  started({ id: entry.databaseId, attempt: entry.attempt });
95
124
  }
96
125
  if (failed.length > 0) {
97
- await waitForRestart(repo, sha, branch, failed);
126
+ await waitForRestart(repo, sha, branch, failed, ignored);
98
127
  }
99
128
  return failed.map((entry) => String(entry.databaseId));
100
129
  }
@@ -109,9 +138,9 @@ async function rerun(repo, id) {
109
138
  }
110
139
  }
111
140
  }
112
- async function waitForRestart(repo, sha, branch, failed) {
141
+ async function waitForRestart(repo, sha, branch, failed, ignored) {
113
142
  for (let attempt = 1; attempt <= RESTART_TRIES; attempt += 1) {
114
- const runs = await baseRuns(repo, sha, branch);
143
+ const runs = await baseRuns(repo, sha, branch, ignored);
115
144
  const restarted = failed.every((entry) => runs.some((run) => run.databaseId === entry.databaseId && run.attempt > entry.attempt));
116
145
  if (restarted) {
117
146
  return;
@@ -119,13 +148,16 @@ async function waitForRestart(repo, sha, branch, failed) {
119
148
  await delay(secondsToMs(1));
120
149
  }
121
150
  }
122
- export async function failedBaseLogs(repo, sha, branch, maxChars) {
123
- const failed = (await baseRuns(repo, sha, branch))
124
- .filter(failedRun)
125
- .map((entry) => ({ heading: `## ${entry.name}`, runId: String(entry.databaseId) }));
126
- const external = (await externalChecks(repo, sha)).filter(failedRun).map((entry) => ({
151
+ export async function failedBaseLogs(repo, sha, branch, maxChars, ignored = []) {
152
+ const failed = (await baseRuns(repo, sha, branch, ignored)).filter(failedRun).flatMap((entry) => entry.jobs === undefined
153
+ ? [{ heading: `## ${entry.name}`, view: [String(entry.databaseId)] }]
154
+ : entry.jobs.filter(failedRun).map((job) => ({
155
+ heading: `## ${entry.name} / ${job.name}`,
156
+ view: ['--job', String(job.databaseId)],
157
+ })));
158
+ const external = (await externalChecks(repo, sha, ignored)).filter(failedRun).map((entry) => ({
127
159
  heading: entry.url === '' ? `## ${entry.name}` : `## ${entry.name}\n${entry.url}`,
128
- runId: undefined,
160
+ view: undefined,
129
161
  }));
130
162
  return runLogs(repo, [...failed, ...external], maxChars);
131
163
  }
@@ -38,3 +38,9 @@ export function commands(value, field) {
38
38
  }
39
39
  return [...value];
40
40
  }
41
+ export function checkNames(value, field) {
42
+ if (!Array.isArray(value) || !value.every((entry) => typeof entry === 'string' && entry !== '')) {
43
+ throw new Error(`${CONFIG_FILE}: ${field} must be a list of check names that are not empty.`);
44
+ }
45
+ return [...value];
46
+ }
package/dist/config.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { mkdir, readFile, rename } from 'node:fs/promises';
2
2
  import { dirname, join } from 'node:path';
3
- import { CONFIG_FILE, commands, OLD_CONFIG_FILE, record, rejectUnknown, text, whole, } from './config-fields.mjs';
3
+ import { CONFIG_FILE, checkNames, commands, OLD_CONFIG_FILE, record, rejectUnknown, text, whole, } from './config-fields.mjs';
4
4
  import { MAX_TIMER_MS } from './durations.mjs';
5
5
  import { hasCode, message, parseJson } from './errors.mjs';
6
6
  import { readTextIfPresent, unlessMissing, writeJson } from './files.mjs';
@@ -23,6 +23,7 @@ const DEFAULTS = {
23
23
  keepRunDays: 7,
24
24
  checks: [],
25
25
  checksTimeoutMinutes: 30,
26
+ ignoredChecks: [],
26
27
  models: {},
27
28
  labels: {
28
29
  ready: 'status:todo',
@@ -38,6 +39,7 @@ function defaults() {
38
39
  return {
39
40
  ...DEFAULTS,
40
41
  checks: [...DEFAULTS.checks],
42
+ ignoredChecks: [...DEFAULTS.ignoredChecks],
41
43
  models: { ...DEFAULTS.models },
42
44
  labels: { ...DEFAULTS.labels },
43
45
  };
@@ -149,6 +151,9 @@ function parseConfig(value) {
149
151
  if (file.checks !== undefined) {
150
152
  config.checks = commands(file.checks, 'checks');
151
153
  }
154
+ if (file.ignoredChecks !== undefined) {
155
+ config.ignoredChecks = checkNames(file.ignoredChecks, 'ignoredChecks');
156
+ }
152
157
  if (file.models !== undefined) {
153
158
  config.models = parseModels(file.models);
154
159
  }
package/dist/gate.mjs CHANGED
@@ -41,7 +41,7 @@ export async function checkGate(job, sha) {
41
41
  async function waitForChecks(job, sha, fields = {}, restarted = []) {
42
42
  const { context, log } = job;
43
43
  const { repo, config, ports } = context;
44
- const checks = await log.step('main-checks', { sha, ...fields }, () => ports.waitForBaseChecks(repo, sha, context.base, checkWaiting(config, true), restarted));
44
+ const checks = await log.step('main-checks', { sha, ...fields }, () => ports.waitForBaseChecks(repo, sha, context.base, checkWaiting(config, true), restarted, config.ignoredChecks));
45
45
  log.event('main-checks.state', { state: checks, ...fields });
46
46
  return checks;
47
47
  }
@@ -66,7 +66,7 @@ async function rerunFailed(job, sha) {
66
66
  try {
67
67
  const runs = await context.ports.rerunFailedBase(context.repo, sha, context.base, (run) => {
68
68
  restarted.push(run);
69
- });
69
+ }, context.config.ignoredChecks);
70
70
  // An empty list tells why the fixer starts with no rerun: no failed workflow run is left to rerun.
71
71
  log.event('main-checks.rerun', { sha, runs });
72
72
  }
@@ -99,7 +99,7 @@ async function failedChecksFix(job, sha, refused) {
99
99
  await writeState(repo, state);
100
100
  let logs;
101
101
  try {
102
- logs = await refundOnKill(job, 'ciFixes', () => ports.failedBaseLogs(repo, sha, base, config.logMaxChars));
102
+ logs = await refundOnKill(job, 'ciFixes', () => ports.failedBaseLogs(repo, sha, base, config.logMaxChars, config.ignoredChecks));
103
103
  }
104
104
  catch (error) {
105
105
  await refundStopped(job);
package/dist/run-logs.mjs CHANGED
@@ -2,20 +2,20 @@ import { succeeded } from './exec.mjs';
2
2
  import { ghRun } from './gh.mjs';
3
3
  import { joinFilled } from './text.mjs';
4
4
  export async function runLogs(repo, failed, maxChars) {
5
- const withLog = failed.filter(({ runId }) => runId !== undefined).length;
5
+ const withLog = failed.filter(({ view }) => view !== undefined).length;
6
6
  const share = Math.max(1, Math.floor(maxChars / Math.max(1, withLog)));
7
7
  const parts = [];
8
- for (const { heading, runId } of failed) {
8
+ for (const { heading, view } of failed) {
9
9
  parts.push(heading);
10
- if (runId === undefined) {
10
+ if (view === undefined) {
11
11
  continue;
12
12
  }
13
- parts.push(await runLog(repo, runId, share));
13
+ parts.push(await runLog(repo, view, share));
14
14
  }
15
15
  return parts.join('\n\n');
16
16
  }
17
- async function runLog(repo, runId, share) {
18
- const logs = await ghRun(repo, ['run', 'view', runId, '--log-failed'], { tailChars: share });
17
+ async function runLog(repo, view, share) {
18
+ const logs = await ghRun(repo, ['run', 'view', ...view, '--log-failed'], { tailChars: share });
19
19
  if (succeeded(logs)) {
20
20
  return logs.stdout;
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-issue",
3
- "version": "7.6.0",
3
+ "version": "7.7.0",
4
4
  "description": "Autonomous issue harness driven by the pi SDK",
5
5
  "keywords": [
6
6
  "github",