@virling/ciwhy 0.0.0-stage → 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses [Semantic Versioning](https://semver.org/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [0.1.1] - 2026-11-27
8
+
9
+ ### Fixed
10
+
11
+ - A job whose log GitHub has deleted (after about 90 days) is shown as `log unavailable` instead of stopping the whole report.
12
+
13
+ ## [0.1.0] - 2026-11-27
14
+
15
+ ### Added
16
+
17
+ - `ciwhy` finds the failed jobs of a GitHub Actions run, across every attempt, and prints the failing step and the relevant log lines from the raw job log.
18
+ - Flaky verdict per job: passed on a later attempt, passed on another run of the same commit, or new since the last default-branch run.
19
+ - Pick a run by id, URL, `--pr` or `--branch`; `--rerun` re-runs failed jobs and reports the result; `--json` output.
20
+
21
+ [Unreleased]: https://github.com/virling/ciwhy/compare/v0.1.1...HEAD
22
+ [0.1.1]: https://github.com/virling/ciwhy/compare/v0.1.0...v0.1.1
23
+ [0.1.0]: https://github.com/virling/ciwhy/releases/tag/v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,75 @@
1
+ # PolyForm Noncommercial License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
12
+
13
+ ## Distribution License
14
+
15
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
16
+
17
+ ## Notices
18
+
19
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
20
+
21
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
22
+
23
+ ## Changes and New Works License
24
+
25
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
26
+
27
+ ## Patent License
28
+
29
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
30
+
31
+ ## Noncommercial Purposes
32
+
33
+ Any noncommercial purpose is a permitted purpose.
34
+
35
+ ## Personal Uses
36
+
37
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
38
+
39
+ ## Noncommercial Organizations
40
+
41
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
42
+
43
+ ## Fair Use
44
+
45
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
46
+
47
+ ## No Other Rights
48
+
49
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
50
+
51
+ ## Patent Defense
52
+
53
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
54
+
55
+ ## Violations
56
+
57
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
58
+
59
+ ## No Liability
60
+
61
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
62
+
63
+ ## Definitions
64
+
65
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
66
+
67
+ **You** refers to the individual or entity agreeing to these terms.
68
+
69
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
70
+
71
+ **Your licenses** are all the licenses granted to you for the software under these terms.
72
+
73
+ **Use** means anything you do with the software requiring one of your licenses.
74
+
75
+ Required Notice: Copyright 2026 Virling (https://github.com/virling)
package/README.md CHANGED
@@ -1,3 +1,76 @@
1
- # Temporary Holding Version
1
+ # ciwhy
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Why did CI fail, and is it flaky? One command for GitHub Actions. Zero dependencies, uses the `gh` CLI you already have.
4
+
5
+ - **Finds the real error.** Downloads the raw job log, strips ANSI codes and timestamps, and keeps only the error region: `##[error]`, `Error:`, `FAIL`, `not ok`, tracebacks, panics, exit codes.
6
+ - **Reads Node test runner output.** Shows the failing TAP subtest and the `# ...` diagnostic lines the process printed near it, which `gh run view --log-failed` often hides.
7
+ - **Checks every attempt.** A job that failed and then passed on re-run is still found.
8
+ - **Flaky verdict.** `flaky` if the job passed on a later attempt or on another run of the same commit, `new failure` if it passed on the previous default branch run, otherwise `unknown`.
9
+ - **Re-run and wait.** `--rerun` re-runs the failed jobs and tells you if they pass this time.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npx @virling/ciwhy
15
+ ```
16
+
17
+ Or `npm install -g @virling/ciwhy` to get `ciwhy` on your PATH.
18
+
19
+ ## Example
20
+
21
+ ```
22
+ $ ciwhy 45871759993 --repo virling/agentmem
23
+ virling/agentmem test run 45871759993 main 93de02f 2 attempts, success
24
+ https://github.com/virling/agentmem/actions/runs/45871759993
25
+
26
+ FAILED test (macos-latest, 18) attempt 1 step: Run npm test
27
+ flaky: passed on attempt 2 of this run
28
+ https://github.com/virling/agentmem/actions/runs/45871759993/job/140088664991
29
+
30
+ # warning: --depth is ignored in local clones; use file:// instead.
31
+ # agentmem: spawnSync tar ENOTCONN
32
+ --
33
+ not ok 11 - guard-check cannot be bypassed by removing the guard, renaming, or unusual names
34
+ location: 'file:///Users/runner/work/agentmem/agentmem/test/features.test.js:108:1'
35
+ failureType: 'testCodeFailure'
36
+ error: |-
37
+ The input did not match the regular expression /error: src\/gen\/client\.ts/. Input:
38
+ ''
39
+ code: 'ERR_ASSERTION'
40
+ ...
41
+ --
42
+ ##[error]Process completed with exit code 1.
43
+ ```
44
+
45
+ ## Options
46
+
47
+ ```
48
+ ciwhy latest failed run on the current branch
49
+ ciwhy <run-id|run-url> a specific run (every attempt is checked)
50
+ ciwhy --pr <number> latest failed run on the pull request's head commit
51
+ ciwhy --branch <name> latest failed run on a branch
52
+
53
+ --repo owner/name repository (default: the repo in the current folder)
54
+ --rerun re-run the failed jobs, wait, and report if they pass
55
+ --timeout <minutes> how long --rerun waits (default 30)
56
+ --json machine-readable output
57
+ --help
58
+ ```
59
+
60
+ Exit code is 0 after a report, even when jobs failed. It is non-zero only for usage errors (2) or `gh` errors (1).
61
+
62
+ ## Requirements
63
+
64
+ - Node.js 20 or newer
65
+ - [GitHub CLI](https://cli.github.com/) (`gh`), authenticated with `gh auth login`
66
+
67
+ ## More tools from Virling
68
+
69
+ - [agentmem](https://github.com/virling/agentmem): project memory for AI coding agents, shared across Claude Code, Cursor, Codex and other MCP clients.
70
+ - [ccdoctor](https://github.com/virling/ccdoctor): checks your Claude Code setup: hooks, MCP servers and plugins that are registered but not working.
71
+ - [npmship](https://github.com/virling/npmship): releases an npm package and verifies it landed on npm, in CI and on GitHub.
72
+ - [subagents](https://github.com/virling/subagents): reviews what Claude Code subagents did in a session and flags repeated or wasted work.
73
+
74
+ ## License
75
+
76
+ [PolyForm Noncommercial 1.0.0](LICENSE)
package/bin/ciwhy.js ADDED
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env node
2
+ import { execFileSync } from "node:child_process";
3
+ import { analyze, currentRepo, findRun, gh, parseTarget, render, renderRerun, rerun } from "../src/ciwhy.js";
4
+
5
+ const HELP = `ciwhy: why did CI fail, and is it flaky?
6
+
7
+ ciwhy latest failed run on the current branch
8
+ ciwhy <run-id|run-url> a specific run (every attempt is checked)
9
+ ciwhy --pr <number> latest failed run on the pull request's head commit
10
+ ciwhy --branch <name> latest failed run on a branch
11
+
12
+ --repo owner/name repository (default: the repo in the current folder)
13
+ --rerun re-run the failed jobs, wait, and report if they pass
14
+ --timeout <minutes> how long --rerun waits (default 30)
15
+ --json machine-readable output
16
+ --help
17
+
18
+ Requires the GitHub CLI (gh), authenticated.`;
19
+
20
+ const BOOLEAN_FLAGS = ["rerun", "json", "help"];
21
+ const VALUE_FLAGS = ["pr", "branch", "repo", "timeout"];
22
+
23
+ function usage(message) {
24
+ console.error(`ciwhy: ${message}\n\n${HELP}`);
25
+ process.exit(2);
26
+ }
27
+
28
+ function parseArgs(argv) {
29
+ const positional = [];
30
+ const flags = {};
31
+ for (let i = 0; i < argv.length; i++) {
32
+ const name = argv[i].slice(2);
33
+ if (!argv[i].startsWith("--")) positional.push(argv[i]);
34
+ else if (BOOLEAN_FLAGS.includes(name)) flags[name] = true;
35
+ else if (VALUE_FLAGS.includes(name) && i + 1 < argv.length) flags[name] = argv[++i];
36
+ else usage(`unknown or incomplete option ${argv[i]}`);
37
+ }
38
+ return { positional, flags };
39
+ }
40
+
41
+ async function main() {
42
+ const { positional, flags } = parseArgs(process.argv.slice(2));
43
+ if (flags.help) return console.log(HELP);
44
+ if (positional.length > 1) usage("expected at most one run id or URL");
45
+ const target = positional[0] ? parseTarget(positional[0]) : {};
46
+ if (!target) usage(`not a run id or run URL: ${positional[0]}`);
47
+ if (flags.pr && !/^\d+$/.test(flags.pr)) usage(`not a pull request number: ${flags.pr}`);
48
+ if (flags.timeout && !(Number(flags.timeout) > 0)) usage(`not a number of minutes: ${flags.timeout}`);
49
+ const repo = flags.repo || target.repo || currentRepo(gh);
50
+ const branch = flags.branch || (!target.id && !flags.pr && execFileSync("git", ["rev-parse", "--abbrev-ref", "HEAD"], { encoding: "utf8" }).trim());
51
+ const run = findRun(gh, repo, { id: target.id, pr: flags.pr, branch });
52
+ if (!run) {
53
+ const where = flags.pr ? `pull request #${flags.pr}` : `branch ${branch}`;
54
+ return console.log(flags.json ? JSON.stringify({ repo, run: null, jobs: [] }, null, 2) : `No failed runs for ${where} in ${repo}.`);
55
+ }
56
+ const report = analyze(gh, repo, run);
57
+ if (!flags.json) console.log(render(report));
58
+ if (flags.rerun && report.jobs.length) {
59
+ if (!flags.json) console.log(`\nRe-running failed jobs of run ${run.id} and waiting...`);
60
+ report.rerun = await rerun(gh, repo, run, report.jobs.map((j) => j.name), { timeoutMs: (Number(flags.timeout) || 30) * 60000 });
61
+ if (!flags.json) console.log(renderRerun(report.rerun));
62
+ }
63
+ if (flags.json) console.log(JSON.stringify(report, null, 2));
64
+ }
65
+
66
+ main().catch((e) => {
67
+ console.error(`ciwhy: ${e.stderr?.trim() || e.message}`);
68
+ process.exit(1);
69
+ });
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@virling/ciwhy",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Why did GitHub Actions fail, and is it flaky? One command, using the gh CLI",
5
+ "type": "module",
6
+ "bin": {
7
+ "ciwhy": "bin/ciwhy.js"
8
+ },
9
+ "scripts": {
10
+ "test": "node --test"
11
+ },
12
+ "engines": {
13
+ "node": ">=20"
14
+ },
15
+ "license": "PolyForm-Noncommercial-1.0.0",
16
+ "keywords": [
17
+ "github-actions",
18
+ "ci",
19
+ "flaky-tests",
20
+ "gh",
21
+ "logs"
22
+ ],
23
+ "files": [
24
+ "bin",
25
+ "src",
26
+ "README.md",
27
+ "LICENSE",
28
+ "CHANGELOG.md"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/virling/ciwhy.git"
36
+ },
37
+ "homepage": "https://github.com/virling/ciwhy#readme",
38
+ "bugs": {
39
+ "url": "https://github.com/virling/ciwhy/issues"
40
+ }
41
+ }
package/src/ciwhy.js ADDED
@@ -0,0 +1,126 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { setTimeout as delay } from "node:timers/promises";
3
+ import { cleanLog, extractErrors } from "./log.js";
4
+
5
+ const FAILED = ["failure", "timed_out"];
6
+
7
+ export function gh(args) {
8
+ return execFileSync("gh", args, { encoding: "utf8", maxBuffer: 256 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
9
+ }
10
+
11
+ const api = (gh, path) => JSON.parse(gh(["api", path]));
12
+
13
+ export function parseTarget(arg) {
14
+ if (/^\d+$/.test(arg)) return { id: arg };
15
+ const m = arg.match(/github\.com\/([^/]+\/[^/]+)\/actions\/runs\/(\d+)/);
16
+ return m && { repo: m[1], id: m[2] };
17
+ }
18
+
19
+ export function currentRepo(gh) {
20
+ return gh(["repo", "view", "--json", "nameWithOwner", "--jq", ".nameWithOwner"]).trim();
21
+ }
22
+
23
+ export function findRun(gh, repo, { id, pr, branch }) {
24
+ if (id) return api(gh, `repos/${repo}/actions/runs/${id}`);
25
+ const filter = pr ? `head_sha=${api(gh, `repos/${repo}/pulls/${pr}`).head.sha}` : `branch=${encodeURIComponent(branch)}`;
26
+ return api(gh, `repos/${repo}/actions/runs?${filter}&status=failure&per_page=1`).workflow_runs[0] || null;
27
+ }
28
+
29
+ const allJobs = (gh, repo, id) => api(gh, `repos/${repo}/actions/runs/${id}/jobs?filter=all&per_page=100`).jobs;
30
+ const passed = (jobs, name) => jobs.find((j) => j.name === name && j.conclusion === "success");
31
+
32
+ function failedJobs(jobs) {
33
+ const latest = new Map();
34
+ for (const j of jobs) if (FAILED.includes(j.conclusion) && !(latest.get(j.name)?.run_attempt > j.run_attempt)) latest.set(j.name, j);
35
+ return [...latest.values()];
36
+ }
37
+
38
+ function evidence(gh, repo, target, jobs) {
39
+ let sameSha, previous;
40
+ const sameShaRuns = () =>
41
+ (sameSha ??= api(gh, `repos/${repo}/actions/runs?head_sha=${target.head_sha}&per_page=100`)
42
+ .workflow_runs.filter((r) => r.id !== target.id && r.workflow_id === target.workflow_id)
43
+ .map((r) => ({ run: r, jobs: allJobs(gh, repo, r.id) })));
44
+ const previousRun = () => {
45
+ if (previous !== undefined) return previous;
46
+ const branch = api(gh, `repos/${repo}`).default_branch;
47
+ const prev = api(gh, `repos/${repo}/actions/workflows/${target.workflow_id}/runs?branch=${encodeURIComponent(branch)}&status=completed&per_page=20`)
48
+ .workflow_runs.find((r) => r.id !== target.id && r.created_at < target.created_at);
49
+ return (previous = prev ? { run: prev, branch, jobs: api(gh, `repos/${repo}/actions/runs/${prev.id}/jobs?per_page=100`).jobs } : null);
50
+ };
51
+ return (job) => {
52
+ const later = jobs.find((j) => j.name === job.name && j.run_attempt > job.run_attempt && j.conclusion === "success");
53
+ if (later) return { verdict: "flaky", evidence: `passed on attempt ${later.run_attempt} of this run` };
54
+ const other = sameShaRuns().find((r) => passed(r.jobs, job.name));
55
+ if (other) return { verdict: "flaky", evidence: `passed in run ${other.run.id} on the same commit` };
56
+ const prev = previousRun();
57
+ if (!prev) return { verdict: "unknown", evidence: "no earlier run of this workflow on the default branch, and no pass on this commit" };
58
+ const pj = prev.jobs.find((j) => j.name === job.name);
59
+ if (pj?.conclusion === "success") return { verdict: "new failure", evidence: `passed on the previous ${prev.branch} run ${prev.run.id}` };
60
+ return { verdict: "unknown", evidence: `no pass on this commit; ${pj ? pj.conclusion : "not run"} on the previous ${prev.branch} run ${prev.run.id}` };
61
+ };
62
+ }
63
+
64
+ // GitHub deletes job logs after about 90 days, so one missing log must not stop the report.
65
+ function jobLog(gh, repo, id) {
66
+ try {
67
+ return { lines: extractErrors(cleanLog(gh(["api", "--allow-escape-sequences", `repos/${repo}/actions/jobs/${id}/logs`]))) };
68
+ } catch (err) {
69
+ return { lines: [], logError: String(err.stderr || err.message).trim().split("\n")[0] };
70
+ }
71
+ }
72
+
73
+ export function analyze(gh, repo, target) {
74
+ const jobs = allJobs(gh, repo, target.id);
75
+ const judge = evidence(gh, repo, target, jobs);
76
+ return {
77
+ repo,
78
+ run: { id: target.id, name: target.name, url: target.html_url, branch: target.head_branch, sha: target.head_sha, attempts: target.run_attempt, conclusion: target.conclusion },
79
+ jobs: failedJobs(jobs).map((job) => ({
80
+ id: job.id,
81
+ name: job.name,
82
+ attempt: job.run_attempt,
83
+ url: job.html_url,
84
+ step: job.steps?.find((s) => FAILED.includes(s.conclusion))?.name ?? null,
85
+ ...judge(job),
86
+ ...jobLog(gh, repo, job.id),
87
+ })),
88
+ };
89
+ }
90
+
91
+ export async function rerun(gh, repo, target, names, { sleep = delay, intervalMs = 15000, timeoutMs = 30 * 60000 } = {}) {
92
+ gh(["run", "rerun", String(target.id), "--failed", "--repo", repo]);
93
+ for (let waited = 0; waited < timeoutMs; waited += intervalMs) {
94
+ await sleep(intervalMs);
95
+ const r = api(gh, `repos/${repo}/actions/runs/${target.id}`);
96
+ if (r.run_attempt <= target.run_attempt || r.status !== "completed") continue;
97
+ const jobs = api(gh, `repos/${repo}/actions/runs/${target.id}/attempts/${r.run_attempt}/jobs?per_page=100`).jobs;
98
+ return {
99
+ attempt: r.run_attempt,
100
+ conclusion: r.conclusion,
101
+ jobs: names.map((name) => {
102
+ const conclusion = jobs.find((j) => j.name === name)?.conclusion ?? "not run";
103
+ return { name, conclusion, verdict: conclusion === "success" ? "flaky" : "failed again" };
104
+ }),
105
+ };
106
+ }
107
+ return { attempt: null, conclusion: "timed out", jobs: [] };
108
+ }
109
+
110
+ export function render(report) {
111
+ const { run } = report;
112
+ const out = [`${report.repo} ${run.name} run ${run.id} ${run.branch} ${run.sha.slice(0, 7)} ${run.attempts} attempt${run.attempts === 1 ? "" : "s"}, ${run.conclusion}`, run.url];
113
+ if (!report.jobs.length) out.push("", "No failed jobs in any attempt.");
114
+ for (const job of report.jobs) {
115
+ out.push("", `FAILED ${job.name} attempt ${job.attempt}${job.step ? ` step: ${job.step}` : ""}`, ` ${job.verdict}: ${job.evidence}`, ` ${job.url}`, "");
116
+ const empty = job.logError ? `(log unavailable: ${job.logError})` : "(no error lines found in the log)";
117
+ out.push(...(job.lines.length ? job.lines : [empty]).map((l) => ` ${l}`));
118
+ }
119
+ if (report.rerun) out.push("", renderRerun(report.rerun));
120
+ return out.join("\n");
121
+ }
122
+
123
+ export function renderRerun(r) {
124
+ const head = r.attempt ? `Re-run attempt ${r.attempt}: ${r.conclusion}` : `Re-run: ${r.conclusion}`;
125
+ return [head, ...r.jobs.map((j) => ` ${j.name}: ${j.conclusion} (${j.verdict})`)].join("\n");
126
+ }
package/src/log.js ADDED
@@ -0,0 +1,52 @@
1
+ const ANSI = /\x1b\[[0-9;?]*[A-Za-z]/g;
2
+ const STAMP = /^\uFEFF?\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?Z ?/;
3
+ const ERROR = /##\[error\]|\bError:|ERR!|\bFAIL\b|^\s*not ok\b|✖|Traceback|panic:|fatal:|[Ee]xit code|exited with code/;
4
+ const SUMMARY = /^\s*# (tests|suites|pass|fail|cancelled|skipped|todo|duration_ms)\b/;
5
+ const DIAGNOSTIC = /^\s*# (?!Subtest:)/;
6
+ const NOISE = /node:internal\/|\(node:[a-z_]+:\d+|duration_ms|^\s*(---|\.\.\.)$|^##\[(end)?group\]|^Post job cleanup|^\[command\]/;
7
+ const CONTEXT = 2;
8
+ const DIAGNOSTIC_WINDOW = 60;
9
+ export const MAX_LINES = 40;
10
+
11
+ export function cleanLog(text) {
12
+ return text.replace(/\r/g, "").split("\n").map((l) => l.replace(ANSI, "").replace(STAMP, "").trimEnd());
13
+ }
14
+
15
+ function tapBlock(lines, i) {
16
+ const indent = lines[i].match(/^\s*/)[0] + " ";
17
+ let end = i;
18
+ while (end + 1 < lines.length && (lines[end + 1].startsWith(indent) || !lines[end + 1].trim())) {
19
+ end++;
20
+ if (lines[end] === `${indent}...`) break;
21
+ }
22
+ return end;
23
+ }
24
+
25
+ export function extractErrors(lines) {
26
+ const keep = new Set();
27
+ lines.forEach((line, i) => {
28
+ if (!ERROR.test(line)) return;
29
+ if (/^\s*not ok\b/.test(line)) {
30
+ for (let j = Math.max(0, i - DIAGNOSTIC_WINDOW); j < i; j++) if (DIAGNOSTIC.test(lines[j]) && !SUMMARY.test(lines[j])) keep.add(j);
31
+ for (let j = i; j <= tapBlock(lines, i); j++) keep.add(j);
32
+ return;
33
+ }
34
+ for (let j = Math.max(0, i - CONTEXT); j <= Math.min(lines.length - 1, i + CONTEXT); j++) keep.add(j);
35
+ });
36
+ const out = [];
37
+ const seen = new Set();
38
+ let prev = -1;
39
+ let gap = false;
40
+ for (const i of [...keep].sort((a, b) => a - b)) {
41
+ const line = lines[i];
42
+ gap ||= prev >= 0 && i > prev + 1;
43
+ prev = i;
44
+ if (!line.trim() || NOISE.test(line) || SUMMARY.test(line) || seen.has(line.trim())) continue;
45
+ if (seen.size === MAX_LINES) break;
46
+ if (gap && out.length) out.push("--");
47
+ gap = false;
48
+ seen.add(line.trim());
49
+ out.push(line);
50
+ }
51
+ return out;
52
+ }