@robhowley/pi-structured-return 1.9.0 → 1.10.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.
Files changed (97) hide show
  1. package/README.md +2 -1
  2. package/extensions/structured-return/config/project-config.ts +10 -0
  3. package/extensions/structured-return/config/registry.ts +306 -0
  4. package/extensions/structured-return/examples/.pi/machine-readable.json +18 -0
  5. package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +25 -0
  6. package/extensions/structured-return/{src/index.ts → index.ts} +94 -69
  7. package/extensions/structured-return/{src/parsers → parsers}/ava-text.ts +23 -15
  8. package/extensions/structured-return/{src/parsers → parsers}/bandit-json.ts +17 -15
  9. package/extensions/structured-return/{src/parsers → parsers}/black-text.ts +18 -18
  10. package/extensions/structured-return/{src/parsers → parsers}/cargo-build.ts +19 -14
  11. package/extensions/structured-return/{src/parsers → parsers}/cargo-test.ts +20 -19
  12. package/extensions/structured-return/parsers/checkstyle-xml.ts +183 -0
  13. package/extensions/structured-return/{src/parsers → parsers}/clang-text.ts +15 -13
  14. package/extensions/structured-return/{src/parsers → parsers}/dbt-json.ts +28 -23
  15. package/extensions/structured-return/{src/parsers → parsers}/dotnet-build-text.ts +10 -8
  16. package/extensions/structured-return/{src/parsers → parsers}/eslint-json.ts +15 -9
  17. package/extensions/structured-return/{src/parsers → parsers}/go-test-json.ts +23 -21
  18. package/extensions/structured-return/{src/parsers → parsers}/hadolint-json.ts +18 -12
  19. package/extensions/structured-return/{src/parsers → parsers}/htmlhint-json.ts +15 -13
  20. package/extensions/structured-return/{src/parsers → parsers}/isort-text.ts +18 -18
  21. package/extensions/structured-return/{src/parsers → parsers}/javac-text.ts +14 -12
  22. package/extensions/structured-return/{src/parsers → parsers}/jsonlint-text.ts +16 -14
  23. package/extensions/structured-return/{src/parsers → parsers}/junit-xml.ts +61 -43
  24. package/extensions/structured-return/{src/parsers → parsers}/markdownlint-json.ts +19 -17
  25. package/extensions/structured-return/{src/parsers → parsers}/minitest-text.ts +24 -15
  26. package/extensions/structured-return/{src/parsers → parsers}/mocha-json.ts +17 -10
  27. package/extensions/structured-return/{src/parsers → parsers}/mypy-json.ts +16 -16
  28. package/extensions/structured-return/{src/parsers → parsers}/node-test-text.ts +17 -14
  29. package/extensions/structured-return/{src/parsers → parsers}/npm-audit-json.ts +19 -16
  30. package/extensions/structured-return/{src/parsers → parsers}/prettier-text.ts +21 -17
  31. package/extensions/structured-return/{src/parsers → parsers}/pylint-json.ts +17 -17
  32. package/extensions/structured-return/{src/parsers → parsers}/pyright-json.ts +20 -18
  33. package/extensions/structured-return/{src/parsers → parsers}/rspec-json.ts +14 -14
  34. package/extensions/structured-return/{src/parsers → parsers}/rubocop-json.ts +22 -11
  35. package/extensions/structured-return/{src/parsers → parsers}/ruff-json.ts +7 -7
  36. package/extensions/structured-return/{src/parsers → parsers}/shellcheck-json.ts +14 -14
  37. package/extensions/structured-return/{src/parsers → parsers}/stylelint-json.ts +21 -13
  38. package/extensions/structured-return/{src/parsers → parsers}/swiftc-text.ts +16 -10
  39. package/extensions/structured-return/parsers/tail-fallback.ts +20 -0
  40. package/extensions/structured-return/{src/parsers → parsers}/tidy-text.ts +13 -13
  41. package/extensions/structured-return/{src/parsers → parsers}/tsc-text.ts +11 -11
  42. package/extensions/structured-return/{src/parsers → parsers}/unittest-text.ts +24 -14
  43. package/extensions/structured-return/{src/parsers → parsers}/utils.ts +9 -6
  44. package/extensions/structured-return/{src/parsers → parsers}/vale-json.ts +18 -18
  45. package/extensions/structured-return/{src/parsers → parsers}/vitest-json.ts +14 -14
  46. package/extensions/structured-return/{src/storage → storage}/log-store.ts +5 -5
  47. package/extensions/structured-return/{src/storage → storage}/session-stats.ts +11 -11
  48. package/extensions/structured-return/{src/types.ts → types.ts} +4 -2
  49. package/package.json +29 -44
  50. package/skills/structured-return/SKILL.md +7 -0
  51. package/LICENSE +0 -21
  52. package/extensions/structured-return/src/config/project-config.ts +0 -10
  53. package/extensions/structured-return/src/config/registry.test.ts +0 -171
  54. package/extensions/structured-return/src/config/registry.ts +0 -282
  55. package/extensions/structured-return/src/index.test.ts +0 -220
  56. package/extensions/structured-return/src/parsers/ava-text.test.ts +0 -116
  57. package/extensions/structured-return/src/parsers/bandit-json.test.ts +0 -90
  58. package/extensions/structured-return/src/parsers/black-text.test.ts +0 -67
  59. package/extensions/structured-return/src/parsers/cargo-build.test.ts +0 -170
  60. package/extensions/structured-return/src/parsers/cargo-test.test.ts +0 -191
  61. package/extensions/structured-return/src/parsers/clang-text.test.ts +0 -61
  62. package/extensions/structured-return/src/parsers/dbt-json.test.ts +0 -172
  63. package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +0 -85
  64. package/extensions/structured-return/src/parsers/eslint-json.test.ts +0 -60
  65. package/extensions/structured-return/src/parsers/go-test-json.test.ts +0 -119
  66. package/extensions/structured-return/src/parsers/hadolint-json.test.ts +0 -73
  67. package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +0 -72
  68. package/extensions/structured-return/src/parsers/isort-text.test.ts +0 -58
  69. package/extensions/structured-return/src/parsers/javac-text.test.ts +0 -75
  70. package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +0 -52
  71. package/extensions/structured-return/src/parsers/junit-xml.test.ts +0 -627
  72. package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +0 -76
  73. package/extensions/structured-return/src/parsers/minitest-text.test.ts +0 -110
  74. package/extensions/structured-return/src/parsers/mocha-json.test.ts +0 -108
  75. package/extensions/structured-return/src/parsers/mypy-json.test.ts +0 -101
  76. package/extensions/structured-return/src/parsers/node-test-text.test.ts +0 -117
  77. package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +0 -83
  78. package/extensions/structured-return/src/parsers/prettier-text.test.ts +0 -76
  79. package/extensions/structured-return/src/parsers/pylint-json.test.ts +0 -120
  80. package/extensions/structured-return/src/parsers/pyright-json.test.ts +0 -112
  81. package/extensions/structured-return/src/parsers/rspec-json.test.ts +0 -126
  82. package/extensions/structured-return/src/parsers/rubocop-json.test.ts +0 -118
  83. package/extensions/structured-return/src/parsers/ruff-json.test.ts +0 -57
  84. package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +0 -110
  85. package/extensions/structured-return/src/parsers/stylelint-json.test.ts +0 -120
  86. package/extensions/structured-return/src/parsers/swiftc-text.test.ts +0 -73
  87. package/extensions/structured-return/src/parsers/tail-fallback.test.ts +0 -41
  88. package/extensions/structured-return/src/parsers/tail-fallback.ts +0 -20
  89. package/extensions/structured-return/src/parsers/tidy-text.test.ts +0 -74
  90. package/extensions/structured-return/src/parsers/tsc-text.test.ts +0 -81
  91. package/extensions/structured-return/src/parsers/unittest-text.test.ts +0 -126
  92. package/extensions/structured-return/src/parsers/vale-json.test.ts +0 -84
  93. package/extensions/structured-return/src/parsers/vitest-json.test.ts +0 -118
  94. package/extensions/structured-return/src/storage/session-stats.test.ts +0 -156
  95. package/extensions/structured-return/tsconfig.json +0 -11
  96. package/extensions/structured-return/vitest.config.ts +0 -9
  97. /package/extensions/structured-return/{src/ui → ui}/widget.ts +0 -0
@@ -1,51 +1,61 @@
1
- import { spawn } from "node:child_process";
2
- import path from "node:path";
3
- import { randomUUID } from "node:crypto";
4
- import { globSync } from "glob";
5
- import { Type } from "@sinclair/typebox";
6
- import type { ExtensionAPI, ExtensionContext } from "@mariozechner/pi-coding-agent";
7
- import { Text } from "@mariozechner/pi-tui";
8
- import type { ObservedRunArgs, ParsedResult, RunContext } from "./types";
9
- import { ensureRunDir, writeRunArtifacts } from "./storage/log-store";
10
- import { loadProjectConfig } from "./config/project-config";
11
- import { resolveParser, listParsers } from "./config/registry";
12
- import { safeReadFile } from "./parsers/utils";
13
- import { appendRun, readLifetimeStats, formatStatsBlock, type AggregatedStats } from "./storage/session-stats";
1
+ import { spawn } from 'node:child_process';
2
+ import path from 'node:path';
3
+ import { randomUUID } from 'node:crypto';
4
+ import { globSync } from 'glob';
5
+ import { Type } from '@sinclair/typebox';
6
+ import type { ExtensionAPI, ExtensionContext } from '@mariozechner/pi-coding-agent';
7
+ import { Text } from '@mariozechner/pi-tui';
8
+ import type { ObservedRunArgs, ParsedResult, RunContext } from './types';
9
+ import { ensureRunDir, writeRunArtifacts } from './storage/log-store';
10
+ import { loadProjectConfig } from './config/project-config';
11
+ import { resolveParser, listParsers } from './config/registry';
12
+ import { safeReadFile } from './parsers/utils';
13
+ import {
14
+ appendRun,
15
+ readLifetimeStats,
16
+ formatStatsBlock,
17
+ type AggregatedStats,
18
+ } from './storage/session-stats';
14
19
 
15
20
  export default function structuredReturn(pi: ExtensionAPI) {
16
- pi.registerCommand("sr-parsers", {
17
- description: "List all structured-return parsers: built-ins and project-local registrations",
21
+ pi.registerCommand('sr-parsers', {
22
+ description: 'List all structured-return parsers: built-ins and project-local registrations',
18
23
  handler: async (_args, ctx) => {
19
- const lines: string[] = ["structured-return parsers", ""];
24
+ const lines: string[] = ['structured-return parsers', ''];
20
25
 
21
- lines.push("built-in:");
26
+ lines.push('built-in:');
22
27
  for (const { id, autoDetect } of listParsers()) {
23
- lines.push(` ${id}${autoDetect ? " (auto-detect)" : ""}`);
28
+ lines.push(` ${id}${autoDetect ? ' (auto-detect)' : ''}`);
24
29
  }
25
30
 
26
31
  const projectRegistrations = loadProjectConfig(ctx.cwd);
27
- lines.push("");
28
- lines.push("project-local (.pi/structured-return.json):");
32
+ lines.push('');
33
+ lines.push('project-local (.pi/structured-return.json):');
29
34
  if (projectRegistrations.length === 0) {
30
- lines.push(" (none)");
35
+ lines.push(' (none)');
31
36
  } else {
32
37
  for (const reg of projectRegistrations) {
33
- const via = reg.parseAs ? `→ ${reg.parseAs}` : reg.module ? `→ module: ${reg.module}` : "";
38
+ const via = reg.parseAs
39
+ ? `→ ${reg.parseAs}`
40
+ : reg.module
41
+ ? `→ module: ${reg.module}`
42
+ : '';
34
43
  const match = reg.match?.argvIncludes
35
- ? `argv includes [${reg.match.argvIncludes.join(", ")}]`
44
+ ? `argv includes [${reg.match.argvIncludes.join(', ')}]`
36
45
  : reg.match?.regex
37
46
  ? `regex: ${reg.match.regex}`
38
- : "(no match rule)";
47
+ : '(no match rule)';
39
48
  lines.push(` ${reg.id} ${match} ${via}`);
40
49
  }
41
50
  }
42
51
 
43
- ctx.ui.notify(lines.join("\n"), "info");
52
+ ctx.ui.notify(lines.join('\n'), 'info');
44
53
  },
45
54
  });
46
55
 
47
- pi.registerCommand("sr-stats", {
48
- description: "Show token savings from structured-return (current session + cwd lifetime + lifetime)",
56
+ pi.registerCommand('sr-stats', {
57
+ description:
58
+ 'Show token savings from structured-return (current session + cwd lifetime + lifetime)',
49
59
  handler: async (_args, ctx) => {
50
60
  const currentCwd = ctx.cwd ?? process.cwd();
51
61
 
@@ -54,7 +64,7 @@ export default function structuredReturn(pi: ExtensionAPI) {
54
64
  try {
55
65
  const entries = ctx.sessionManager?.getEntries?.() ?? [];
56
66
  for (const entry of entries) {
57
- if (entry.type !== "message") continue;
67
+ if (entry.type !== 'message') continue;
58
68
  const msg = (
59
69
  entry as {
60
70
  message?: {
@@ -64,9 +74,9 @@ export default function structuredReturn(pi: ExtensionAPI) {
64
74
  };
65
75
  }
66
76
  ).message;
67
- if (msg?.role !== "toolResult" || msg?.toolName !== "structured_return") continue;
77
+ if (msg?.role !== 'toolResult' || msg?.toolName !== 'structured_return') continue;
68
78
  const details = msg.details;
69
- if (details?.rawBytes != null && details?.parsedBytes != null) {
79
+ if (details?.rawBytes !== undefined && details?.parsedBytes !== undefined) {
70
80
  sessionStats.runs++;
71
81
  sessionStats.rawBytes += details.rawBytes;
72
82
  sessionStats.parsedBytes += details.parsedBytes;
@@ -81,24 +91,24 @@ export default function structuredReturn(pi: ExtensionAPI) {
81
91
  // Lifetime: read all JSONL files
82
92
  const lifetime = readLifetimeStats();
83
93
 
84
- const lines: string[] = ["structured-return stats", ""];
85
- lines.push(...formatStatsBlock("session", sessionStats));
86
- lines.push("");
87
- lines.push(...formatStatsBlock("cwd lifetime", cwdLifetime));
88
- lines.push("");
89
- lines.push(...formatStatsBlock("lifetime", lifetime));
94
+ const lines: string[] = ['structured-return stats', ''];
95
+ lines.push(...formatStatsBlock('session', sessionStats));
96
+ lines.push('');
97
+ lines.push(...formatStatsBlock('cwd lifetime', cwdLifetime));
98
+ lines.push('');
99
+ lines.push(...formatStatsBlock('lifetime', lifetime));
90
100
 
91
- ctx.ui.notify(lines.join("\n"), "info");
101
+ ctx.ui.notify(lines.join('\n'), 'info');
92
102
  },
93
103
  });
94
104
 
95
105
  pi.registerTool({
96
- name: "structured_return",
97
- label: "Structured Return",
106
+ name: 'structured_return',
107
+ label: 'Structured Return',
98
108
  description:
99
- "Run a command, store full logs, apply an explicit or registered parser when available, and fall back to tail + log path.",
109
+ 'Run a command, store full logs, apply an explicit or registered parser when available, and fall back to tail + log path.',
100
110
  promptGuidelines: [
101
- "Prefer structured_return over bash for test suites, linters, type checkers, and build commands - it returns compact results. Check the structured-return skill for the right flags and parseAs value for each tool.",
111
+ 'Prefer structured_return over bash for test suites, linters, type checkers, and build commands - it returns compact results. Check the structured-return skill for the right flags and parseAs value for each tool.',
102
112
  ],
103
113
  parameters: Type.Object({
104
114
  command: Type.String(),
@@ -111,7 +121,7 @@ export default function structuredReturn(pi: ExtensionAPI) {
111
121
  args: ObservedRunArgs,
112
122
  _signal: AbortSignal | undefined,
113
123
  _onUpdate: unknown,
114
- ctx: ExtensionContext
124
+ ctx: ExtensionContext,
115
125
  ) {
116
126
  const cwd = args.cwd ?? ctx.cwd ?? process.cwd();
117
127
  const runDir = ensureRunDir(cwd);
@@ -150,7 +160,9 @@ export default function structuredReturn(pi: ExtensionAPI) {
150
160
  }
151
161
 
152
162
  return {
153
- content: [{ type: "text" as const, text: `${stripCdPrefix(args.command)} → ${resultText}` }],
163
+ content: [
164
+ { type: 'text' as const, text: `${stripCdPrefix(args.command)} → ${resultText}` },
165
+ ],
154
166
  details: { exitCode, logPath: logs.logPath, parser: parser.id, rawBytes, parsedBytes },
155
167
  };
156
168
  },
@@ -158,7 +170,7 @@ export default function structuredReturn(pi: ExtensionAPI) {
158
170
  return new Text(`structured_return ${args.command}`, 0, 0);
159
171
  },
160
172
  renderResult(result: { content?: Array<{ type: string; text?: string }> }) {
161
- const text = result?.content?.[0]?.text ?? "structured_return complete";
173
+ const text = result?.content?.[0]?.text ?? 'structured_return complete';
162
174
  return new Text(text, 0, 0);
163
175
  },
164
176
  });
@@ -169,19 +181,23 @@ export function formatResult(result: ParsedResult): string {
169
181
  if (result.cwd) lines.push(`cwd: ${result.cwd}`);
170
182
  lines.push(result.summary);
171
183
  for (const f of result.failures ?? []) {
172
- const location = [f.file, f.line].filter(Boolean).join(":");
173
- const rule = f.rule ? ` [${f.rule}]` : "";
174
- const msgLines = (f.message ?? "").split("\n");
175
- lines.push(` ${location} ${msgLines[0]}${rule}`);
184
+ const location = [f.file, f.line, f.column].filter(Boolean).join(':');
185
+ const severity = f.severity ? ` [${f.severity}]` : '';
186
+ const rule = f.rule ? ` [${f.rule}]` : '';
187
+ const msgLines = (f.message ?? '').split('\n');
188
+ lines.push(` ${location} ${msgLines[0]}${severity}${rule}`);
176
189
  for (const extra of msgLines.slice(1)) lines.push(` ${extra}`);
177
190
  }
178
191
  // If the parser detected failures but couldn't extract details, surface the
179
192
  // log path and raw tail so the model has a path forward instead of a dead end.
180
- if ((result.status === "fail" || result.status === "error") && (result.failures ?? []).length === 0) {
193
+ if (
194
+ (result.status === 'fail' || result.status === 'error') &&
195
+ (result.failures ?? []).length === 0
196
+ ) {
181
197
  if (result.logPath) lines.push(`log: ${result.logPath}`);
182
198
  if (result.rawTail) lines.push(result.rawTail);
183
199
  }
184
- return lines.join("\n");
200
+ return lines.join('\n');
185
201
  }
186
202
 
187
203
  /** Resolve and glob-expand artifact paths. Patterns that match nothing are kept as-is (parser handles missing files). */
@@ -194,43 +210,48 @@ export function expandArtifactPaths(raw: string[], cwd: string): string[] {
194
210
  }
195
211
 
196
212
  export function stripCdPrefix(command: string): string {
197
- return command.replace(/^cd\s+\S+\s*&&\s*/, "");
213
+ return command.replace(/^cd\s+\S+\s*&&\s*/, '');
198
214
  }
199
215
 
200
216
  function shellSplit(command: string): string[] {
201
- return command.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g)?.map((s) => s.replace(/^['"]|['"]$/g, "")) ?? [];
217
+ return (
218
+ command.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g)?.map((s) => s.replace(/^['"]|['"]$/g, '')) ?? []
219
+ );
202
220
  }
203
221
 
204
- function runCommand(command: string, cwd: string): Promise<{ stdout: string; stderr: string; exitCode: number }> {
222
+ function runCommand(
223
+ command: string,
224
+ cwd: string,
225
+ ): Promise<{ stdout: string; stderr: string; exitCode: number }> {
205
226
  return new Promise((resolve) => {
206
- const proc = spawn(command, { cwd, shell: true, stdio: ["ignore", "pipe", "pipe"] });
207
- let stdout = "";
208
- let stderr = "";
209
- proc.stdout.on("data", (d) => {
227
+ const proc = spawn(command, { cwd, shell: true, stdio: ['ignore', 'pipe', 'pipe'] });
228
+ let stdout = '';
229
+ let stderr = '';
230
+ proc.stdout.on('data', (d) => {
210
231
  stdout += d.toString();
211
232
  });
212
- proc.stderr.on("data", (d) => {
233
+ proc.stderr.on('data', (d) => {
213
234
  stderr += d.toString();
214
235
  });
215
- proc.on("close", (code) => resolve({ stdout, stderr, exitCode: code ?? 1 }));
236
+ proc.on('close', (code) => resolve({ stdout, stderr, exitCode: code ?? 1 }));
216
237
  });
217
238
  }
218
239
 
219
240
  export function finalizeResult(
220
- result: Omit<ParsedResult, "exitCode">,
241
+ result: Omit<ParsedResult, 'exitCode'>,
221
242
  exitCode: number,
222
243
  logPath: string,
223
- cwd: string
244
+ cwd: string,
224
245
  ): ParsedResult {
225
- if (result.status === "error" && exitCode === 0) {
246
+ if (result.status === 'error' && exitCode === 0) {
226
247
  return {
227
248
  ...result,
228
249
  exitCode,
229
250
  cwd,
230
- status: "pass",
251
+ status: 'pass',
231
252
  summary:
232
- result.summary === "no parser matched; returning tail + log path"
233
- ? "command completed; no parser matched"
253
+ result.summary === 'no parser matched; returning tail + log path'
254
+ ? 'command completed; no parser matched'
234
255
  : result.summary,
235
256
  logPath,
236
257
  };
@@ -238,18 +259,22 @@ export function finalizeResult(
238
259
  const finalized: ParsedResult = { ...result, exitCode, cwd, logPath };
239
260
  // Surface catastrophic failures (command not found, permission denied, missing
240
261
  // interpreter, etc.) — the combined log contains the actual diagnostic.
241
- if (finalized.status === "error" && exitCode !== 0 && !finalized.rawTail) {
262
+ if (finalized.status === 'error' && exitCode !== 0 && !finalized.rawTail) {
242
263
  const log = safeReadFile(logPath);
243
264
  const lines = log.split(/\r?\n/);
244
- finalized.rawTail = lines.slice(-200).join("\n");
265
+ finalized.rawTail = lines.slice(-200).join('\n');
245
266
  }
246
267
  // Safety net: if the parser reports failures but couldn't extract any details
247
268
  // (e.g., tool output format changed), append the log tail so the model isn't
248
269
  // left with "2 failed" and nothing actionable.
249
- if (finalized.status === "fail" && (finalized.failures ?? []).length === 0 && !finalized.rawTail) {
270
+ if (
271
+ finalized.status === 'fail' &&
272
+ (finalized.failures ?? []).length === 0 &&
273
+ !finalized.rawTail
274
+ ) {
250
275
  const log = safeReadFile(logPath);
251
276
  const lines = log.split(/\r?\n/);
252
- finalized.rawTail = lines.slice(-200).join("\n");
277
+ finalized.rawTail = lines.slice(-200).join('\n');
253
278
  }
254
279
  return finalized;
255
280
  }
@@ -1,6 +1,6 @@
1
- import path from "node:path";
2
- import type { ParserModule, ParsedFailure } from "../types";
3
- import { extractJsStackLocation, safeReadFile } from "./utils";
1
+ import path from 'node:path';
2
+ import type { ParserModule, ParsedFailure } from '../types';
3
+ import { extractJsStackLocation, safeReadFile } from './utils';
4
4
 
5
5
  /**
6
6
  * Parses AVA's default text output (--no-color).
@@ -14,11 +14,11 @@ const SUMMARY_RE = /(\d+) tests? (passed|failed)/g;
14
14
  const FAIL_MARKER_RE = /^\s*✘\s+\[fail\]:\s+(.+?)(?:\s+Error thrown in test)?$/;
15
15
 
16
16
  const parser: ParserModule = {
17
- id: "ava-text",
17
+ id: 'ava-text',
18
18
  async parse(ctx) {
19
19
  const stderr = safeReadFile(ctx.stdoutPath);
20
20
  if (!stderr.trim()) {
21
- return { tool: "ava", status: "error", summary: "no output", logPath: ctx.logPath };
21
+ return { tool: 'ava', status: 'error', summary: 'no output', logPath: ctx.logPath };
22
22
  }
23
23
 
24
24
  // Extract pass/fail counts from summary lines at the end
@@ -27,19 +27,24 @@ const parser: ParserModule = {
27
27
  let m: RegExpExecArray | null;
28
28
  while ((m = SUMMARY_RE.exec(stderr)) !== null) {
29
29
  const count = parseInt(m[1], 10);
30
- if (m[2] === "passed") passed = count;
30
+ if (m[2] === 'passed') passed = count;
31
31
  else failed = count;
32
32
  }
33
33
 
34
34
  if (passed === 0 && failed === 0) {
35
- return { tool: "ava", status: "error", summary: "could not parse ava output", logPath: ctx.logPath };
35
+ return {
36
+ tool: 'ava',
37
+ status: 'error',
38
+ summary: 'could not parse ava output',
39
+ logPath: ctx.logPath,
40
+ };
36
41
  }
37
42
 
38
43
  const failures = parseFailureBlocks(stderr, ctx.cwd);
39
44
 
40
45
  return {
41
- tool: "ava",
42
- status: failed > 0 ? "fail" : "pass",
46
+ tool: 'ava',
47
+ status: failed > 0 ? 'fail' : 'pass',
43
48
  summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
44
49
  failures,
45
50
  logPath: ctx.logPath,
@@ -58,7 +63,7 @@ export default parser;
58
63
  * by those names to get per-failure blocks.
59
64
  */
60
65
  function parseFailureBlocks(output: string, cwd: string): ParsedFailure[] {
61
- const lines = output.split("\n");
66
+ const lines = output.split('\n');
62
67
 
63
68
  // Collect failed test names from ✘ markers
64
69
  const failedNames: string[] = [];
@@ -101,7 +106,7 @@ function parseFailureBlocks(output: string, cwd: string): ParsedFailure[] {
101
106
 
102
107
  function parseBlock(name: string, lines: string[], cwd: string): ParsedFailure {
103
108
  // Determine type by looking for "Error thrown in test:"
104
- const isRuntimeError = lines.some((l) => l.trim() === "Error thrown in test:");
109
+ const isRuntimeError = lines.some((l) => l.trim() === 'Error thrown in test:');
105
110
 
106
111
  if (isRuntimeError) {
107
112
  return parseRuntimeError(name, lines, cwd);
@@ -129,14 +134,17 @@ function parseAssertionFailure(name: string, lines: string[], cwd: string): Pars
129
134
  }
130
135
 
131
136
  // Diff values: "- 12" (actual), "+ 99" (expected)
132
- if (trimmed.startsWith("- ") && actual === undefined) {
137
+ if (trimmed.startsWith('- ') && actual === undefined) {
133
138
  actual = trimmed.slice(2);
134
- } else if (trimmed.startsWith("+ ") && expected === undefined) {
139
+ } else if (trimmed.startsWith('+ ') && expected === undefined) {
135
140
  expected = trimmed.slice(2);
136
141
  }
137
142
  }
138
143
 
139
- const message = actual !== undefined && expected !== undefined ? `expected ${expected}, got ${actual}` : undefined;
144
+ const message =
145
+ actual !== undefined && expected !== undefined
146
+ ? `expected ${expected}, got ${actual}`
147
+ : undefined;
140
148
 
141
149
  return { id: name, file, line, message };
142
150
  }
@@ -154,7 +162,7 @@ function parseRuntimeError(name: string, lines: string[], cwd: string): ParsedFa
154
162
  }
155
163
 
156
164
  // Extract file:line from the first user stack frame
157
- const loc = extractJsStackLocation(lines.join("\n"));
165
+ const loc = extractJsStackLocation(lines.join('\n'));
158
166
  const file = loc.file ? path.relative(cwd, path.resolve(cwd, loc.file)) : undefined;
159
167
 
160
168
  return { id: name, file, line: loc.line, message };
@@ -1,6 +1,6 @@
1
- import path from "node:path";
2
- import type { ParserModule, ParsedFailure } from "../types";
3
- import { safeReadFile } from "./utils";
1
+ import path from 'node:path';
2
+ import type { ParserModule, ParsedFailure } from '../types';
3
+ import { safeReadFile } from './utils';
4
4
 
5
5
  interface BanditResult {
6
6
  filename: string;
@@ -16,14 +16,14 @@ interface BanditOutput {
16
16
  }
17
17
 
18
18
  const parser: ParserModule = {
19
- id: "bandit-json",
19
+ id: 'bandit-json',
20
20
  async parse(ctx) {
21
21
  const stdout = safeReadFile(ctx.stdoutPath).trim();
22
22
  if (!stdout) {
23
23
  return {
24
- tool: "bandit",
25
- status: "pass",
26
- summary: "no security issues",
24
+ tool: 'bandit',
25
+ status: 'pass',
26
+ summary: 'no security issues',
27
27
  failures: [],
28
28
  logPath: ctx.logPath,
29
29
  };
@@ -34,9 +34,9 @@ const parser: ParserModule = {
34
34
  output = JSON.parse(stdout);
35
35
  } catch {
36
36
  return {
37
- tool: "bandit",
38
- status: "error",
39
- summary: "failed to parse bandit JSON output",
37
+ tool: 'bandit',
38
+ status: 'error',
39
+ summary: 'failed to parse bandit JSON output',
40
40
  logPath: ctx.logPath,
41
41
  };
42
42
  }
@@ -58,16 +58,18 @@ const parser: ParserModule = {
58
58
  const sev = r.issue_severity.toLowerCase();
59
59
  bySeverity[sev] = (bySeverity[sev] ?? 0) + 1;
60
60
  }
61
- const sevParts = ["high", "medium", "low"].filter((s) => bySeverity[s]).map((s) => `${bySeverity[s]} ${s}`);
61
+ const sevParts = ['high', 'medium', 'low']
62
+ .filter((s) => bySeverity[s])
63
+ .map((s) => `${bySeverity[s]} ${s}`);
62
64
 
63
65
  const summary =
64
66
  results.length > 0
65
- ? `${results.length} issue${results.length !== 1 ? "s" : ""} (${sevParts.join(", ")})`
66
- : "no security issues";
67
+ ? `${results.length} issue${results.length !== 1 ? 's' : ''} (${sevParts.join(', ')})`
68
+ : 'no security issues';
67
69
 
68
70
  return {
69
- tool: "bandit",
70
- status: failures.length > 0 ? "fail" : "pass",
71
+ tool: 'bandit',
72
+ status: failures.length > 0 ? 'fail' : 'pass',
71
73
  summary,
72
74
  failures,
73
75
  logPath: ctx.logPath,
@@ -1,25 +1,25 @@
1
- import path from "node:path";
2
- import type { ParserModule, ParsedFailure } from "../types";
3
- import { safeReadFile } from "./utils";
1
+ import path from 'node:path';
2
+ import type { ParserModule, ParsedFailure } from '../types';
3
+ import { safeReadFile } from './utils';
4
4
 
5
5
  const REFORMAT_LINE = /^would reformat (.+)$/;
6
6
  const ERROR_FORMAT = /^error: cannot format (.+?): (.+)$/;
7
7
 
8
8
  const parser: ParserModule = {
9
- id: "black-text",
9
+ id: 'black-text',
10
10
  async parse(ctx) {
11
- const combined = (safeReadFile(ctx.stdoutPath) + "\n" + safeReadFile(ctx.stderrPath)).trim();
11
+ const combined = (safeReadFile(ctx.stdoutPath) + '\n' + safeReadFile(ctx.stderrPath)).trim();
12
12
  if (!combined) {
13
13
  return {
14
- tool: "black",
15
- status: "pass",
16
- summary: "all files formatted",
14
+ tool: 'black',
15
+ status: 'pass',
16
+ summary: 'all files formatted',
17
17
  failures: [],
18
18
  logPath: ctx.logPath,
19
19
  };
20
20
  }
21
21
 
22
- const lines = combined.split("\n");
22
+ const lines = combined.split('\n');
23
23
  const failures: ParsedFailure[] = [];
24
24
  for (const line of lines) {
25
25
  const reformatMatch = line.match(REFORMAT_LINE);
@@ -28,7 +28,7 @@ const parser: ParserModule = {
28
28
  failures.push({
29
29
  id: relPath,
30
30
  file: relPath,
31
- message: "would reformat",
31
+ message: 'would reformat',
32
32
  });
33
33
  continue;
34
34
  }
@@ -46,11 +46,11 @@ const parser: ParserModule = {
46
46
  }
47
47
 
48
48
  // If "All done!" and no reformats needed
49
- if (failures.length === 0 && combined.includes("All done!")) {
49
+ if (failures.length === 0 && combined.includes('All done!')) {
50
50
  return {
51
- tool: "black",
52
- status: "pass",
53
- summary: "all files formatted",
51
+ tool: 'black',
52
+ status: 'pass',
53
+ summary: 'all files formatted',
54
54
  failures: [],
55
55
  logPath: ctx.logPath,
56
56
  };
@@ -58,12 +58,12 @@ const parser: ParserModule = {
58
58
 
59
59
  const summary =
60
60
  failures.length > 0
61
- ? `${failures.length} file${failures.length !== 1 ? "s" : ""} would be reformatted`
62
- : "all files formatted";
61
+ ? `${failures.length} file${failures.length !== 1 ? 's' : ''} would be reformatted`
62
+ : 'all files formatted';
63
63
 
64
64
  return {
65
- tool: "black",
66
- status: failures.length > 0 ? "fail" : "pass",
65
+ tool: 'black',
66
+ status: failures.length > 0 ? 'fail' : 'pass',
67
67
  summary,
68
68
  failures,
69
69
  logPath: ctx.logPath,
@@ -1,6 +1,6 @@
1
- import path from "node:path";
2
- import type { ParserModule, ParsedFailure } from "../types";
3
- import { safeReadFile } from "./utils";
1
+ import path from 'node:path';
2
+ import type { ParserModule, ParsedFailure } from '../types';
3
+ import { safeReadFile } from './utils';
4
4
 
5
5
  interface CargoSpan {
6
6
  file_name: string;
@@ -21,19 +21,19 @@ interface CargoMessage {
21
21
  }
22
22
 
23
23
  interface CargoCompilerMessage {
24
- reason: "compiler-message";
24
+ reason: 'compiler-message';
25
25
  message: CargoMessage;
26
26
  }
27
27
 
28
28
  const parser: ParserModule = {
29
- id: "cargo-build",
29
+ id: 'cargo-build',
30
30
  async parse(ctx) {
31
31
  // --message-format=json writes NDJSON to stdout; one JSON object per line
32
32
  const stdout = safeReadFile(ctx.stdoutPath);
33
33
  const failures: ParsedFailure[] = [];
34
34
 
35
- for (const line of stdout.split("\n")) {
36
- if (!line.trim().startsWith("{")) continue;
35
+ for (const line of stdout.split('\n')) {
36
+ if (!line.trim().startsWith('{')) continue;
37
37
  let obj: Partial<CargoCompilerMessage>;
38
38
  try {
39
39
  obj = JSON.parse(line);
@@ -41,18 +41,20 @@ const parser: ParserModule = {
41
41
  continue;
42
42
  }
43
43
 
44
- if (obj.reason !== "compiler-message") continue;
44
+ if (obj.reason !== 'compiler-message') continue;
45
45
  const msg = obj.message;
46
- if (!msg || msg.level !== "error") continue;
46
+ if (!msg || msg.level !== 'error') continue;
47
47
 
48
48
  const primarySpan = msg.spans?.find((s) => s.is_primary);
49
- const file = primarySpan ? path.relative(ctx.cwd, path.resolve(ctx.cwd, primarySpan.file_name)) : undefined;
49
+ const file = primarySpan
50
+ ? path.relative(ctx.cwd, path.resolve(ctx.cwd, primarySpan.file_name))
51
+ : undefined;
50
52
  const lineNum = primarySpan?.line_start;
51
53
  const label = primarySpan?.label ?? undefined;
52
54
  const code = msg.code?.code;
53
55
 
54
56
  failures.push({
55
- id: [file, lineNum, code].filter(Boolean).join(":"),
57
+ id: [file, lineNum, code].filter(Boolean).join(':'),
56
58
  file,
57
59
  line: lineNum,
58
60
  // Surface the primary span label (e.g. "expected `i32`, found `&str`") as a second line
@@ -62,9 +64,12 @@ const parser: ParserModule = {
62
64
  }
63
65
 
64
66
  return {
65
- tool: "cargo",
66
- status: failures.length > 0 ? "fail" : "pass",
67
- summary: failures.length > 0 ? `${failures.length} error${failures.length === 1 ? "" : "s"}` : "build succeeded",
67
+ tool: 'cargo',
68
+ status: failures.length > 0 ? 'fail' : 'pass',
69
+ summary:
70
+ failures.length > 0
71
+ ? `${failures.length} error${failures.length === 1 ? '' : 's'}`
72
+ : 'build succeeded',
68
73
  failures,
69
74
  logPath: ctx.logPath,
70
75
  };