@robhowley/pi-structured-return 1.4.0 → 1.6.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.
Files changed (72) hide show
  1. package/README.md +108 -74
  2. package/extensions/structured-return/src/config/registry.test.ts +171 -0
  3. package/extensions/structured-return/src/config/registry.ts +183 -14
  4. package/extensions/structured-return/src/index.test.ts +54 -0
  5. package/extensions/structured-return/src/index.ts +20 -9
  6. package/extensions/structured-return/src/parsers/ava-text.test.ts +116 -0
  7. package/extensions/structured-return/src/parsers/ava-text.ts +161 -0
  8. package/extensions/structured-return/src/parsers/bandit-json.test.ts +90 -0
  9. package/extensions/structured-return/src/parsers/bandit-json.ts +78 -0
  10. package/extensions/structured-return/src/parsers/black-text.test.ts +67 -0
  11. package/extensions/structured-return/src/parsers/black-text.ts +74 -0
  12. package/extensions/structured-return/src/parsers/cargo-build.ts +2 -2
  13. package/extensions/structured-return/src/parsers/cargo-test.ts +2 -2
  14. package/extensions/structured-return/src/parsers/clang-text.test.ts +61 -0
  15. package/extensions/structured-return/src/parsers/clang-text.ts +59 -0
  16. package/extensions/structured-return/src/parsers/dbt-json.ts +2 -2
  17. package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +85 -0
  18. package/extensions/structured-return/src/parsers/dotnet-build-text.ts +48 -0
  19. package/extensions/structured-return/src/parsers/eslint-json.ts +2 -2
  20. package/extensions/structured-return/src/parsers/go-test-json.test.ts +119 -0
  21. package/extensions/structured-return/src/parsers/go-test-json.ts +137 -0
  22. package/extensions/structured-return/src/parsers/hadolint-json.test.ts +73 -0
  23. package/extensions/structured-return/src/parsers/hadolint-json.ts +55 -0
  24. package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +72 -0
  25. package/extensions/structured-return/src/parsers/htmlhint-json.ts +72 -0
  26. package/extensions/structured-return/src/parsers/isort-text.test.ts +58 -0
  27. package/extensions/structured-return/src/parsers/isort-text.ts +64 -0
  28. package/extensions/structured-return/src/parsers/javac-text.test.ts +75 -0
  29. package/extensions/structured-return/src/parsers/javac-text.ts +81 -0
  30. package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +52 -0
  31. package/extensions/structured-return/src/parsers/jsonlint-text.ts +64 -0
  32. package/extensions/structured-return/src/parsers/junit-xml.ts +2 -2
  33. package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +76 -0
  34. package/extensions/structured-return/src/parsers/markdownlint-json.ts +73 -0
  35. package/extensions/structured-return/src/parsers/minitest-text.ts +2 -2
  36. package/extensions/structured-return/src/parsers/mocha-json.test.ts +108 -0
  37. package/extensions/structured-return/src/parsers/mocha-json.ts +77 -0
  38. package/extensions/structured-return/src/parsers/mypy-json.test.ts +101 -0
  39. package/extensions/structured-return/src/parsers/mypy-json.ts +80 -0
  40. package/extensions/structured-return/src/parsers/node-test-text.test.ts +117 -0
  41. package/extensions/structured-return/src/parsers/node-test-text.ts +90 -0
  42. package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +83 -0
  43. package/extensions/structured-return/src/parsers/npm-audit-json.ts +88 -0
  44. package/extensions/structured-return/src/parsers/prettier-text.test.ts +76 -0
  45. package/extensions/structured-return/src/parsers/prettier-text.ts +63 -0
  46. package/extensions/structured-return/src/parsers/pylint-json.test.ts +120 -0
  47. package/extensions/structured-return/src/parsers/pylint-json.ts +64 -0
  48. package/extensions/structured-return/src/parsers/pyright-json.test.ts +112 -0
  49. package/extensions/structured-return/src/parsers/pyright-json.ts +81 -0
  50. package/extensions/structured-return/src/parsers/rspec-json.ts +2 -2
  51. package/extensions/structured-return/src/parsers/rubocop-json.test.ts +118 -0
  52. package/extensions/structured-return/src/parsers/rubocop-json.ts +65 -0
  53. package/extensions/structured-return/src/parsers/ruff-json.ts +2 -2
  54. package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +110 -0
  55. package/extensions/structured-return/src/parsers/shellcheck-json.ts +61 -0
  56. package/extensions/structured-return/src/parsers/stylelint-json.test.ts +120 -0
  57. package/extensions/structured-return/src/parsers/stylelint-json.ts +68 -0
  58. package/extensions/structured-return/src/parsers/swiftc-text.test.ts +73 -0
  59. package/extensions/structured-return/src/parsers/swiftc-text.ts +47 -0
  60. package/extensions/structured-return/src/parsers/tail-fallback.ts +2 -2
  61. package/extensions/structured-return/src/parsers/tidy-text.test.ts +74 -0
  62. package/extensions/structured-return/src/parsers/tidy-text.ts +67 -0
  63. package/extensions/structured-return/src/parsers/tsc-text.test.ts +81 -0
  64. package/extensions/structured-return/src/parsers/tsc-text.ts +47 -0
  65. package/extensions/structured-return/src/parsers/unittest-text.test.ts +126 -0
  66. package/extensions/structured-return/src/parsers/unittest-text.ts +116 -0
  67. package/extensions/structured-return/src/parsers/utils.ts +43 -0
  68. package/extensions/structured-return/src/parsers/vale-json.test.ts +84 -0
  69. package/extensions/structured-return/src/parsers/vale-json.ts +80 -0
  70. package/extensions/structured-return/src/parsers/vitest-json.ts +2 -2
  71. package/package.json +1 -1
  72. package/skills/structured-return/SKILL.md +93 -2
@@ -0,0 +1,126 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { describe, it, expect } from "vitest";
5
+ import parser from "./unittest-text";
6
+ import type { RunContext } from "../types";
7
+
8
+ function makeCtx(stderr: string, cwd = "/project"): RunContext {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "unittest-test-"));
10
+ const stderrPath = path.join(dir, "stderr");
11
+ fs.writeFileSync(stderrPath, stderr);
12
+ const stdoutPath = path.join(dir, "stdout");
13
+ fs.writeFileSync(stdoutPath, "");
14
+ return {
15
+ command: "python3 -m unittest test_math.py",
16
+ argv: ["python3", "-m", "unittest", "test_math.py"],
17
+ cwd,
18
+ artifactPaths: [],
19
+ stdoutPath,
20
+ stderrPath,
21
+ logPath: path.join(dir, "log"),
22
+ };
23
+ }
24
+
25
+ const REAL_FAILURE_OUTPUT = `.EF
26
+ ======================================================================
27
+ ERROR: test_does_not_divide_by_zero (test_math.TestMath.test_does_not_divide_by_zero)
28
+ ----------------------------------------------------------------------
29
+ Traceback (most recent call last):
30
+ File "/project/test_math.py", line 12, in test_does_not_divide_by_zero
31
+ result = 1 / 0
32
+ ~~^~~
33
+ ZeroDivisionError: division by zero
34
+
35
+ ======================================================================
36
+ FAIL: test_multiplies_two_numbers_correctly (test_math.TestMath.test_multiplies_two_numbers_correctly)
37
+ ----------------------------------------------------------------------
38
+ Traceback (most recent call last):
39
+ File "/project/test_math.py", line 9, in test_multiplies_two_numbers_correctly
40
+ self.assertEqual(3 * 4, 99)
41
+ ~~~~~~~~~~~~~~~~^^^^^^^^^^^
42
+ AssertionError: 12 != 99
43
+
44
+ ----------------------------------------------------------------------
45
+ Ran 3 tests in 0.001s
46
+
47
+ FAILED (failures=1, errors=1)`;
48
+
49
+ describe("unittest-text parser", () => {
50
+ it("real output → assertion failure with expected/actual, runtime error with message", async () => {
51
+ const result = await parser.parse(makeCtx(REAL_FAILURE_OUTPUT));
52
+ expect(result.status).toBe("fail");
53
+ expect(result.summary).toBe("2 failed, 1 passed");
54
+ expect(result.failures).toHaveLength(2);
55
+
56
+ // ERROR block
57
+ const err = result.failures!.find((f) => f.rule === "error")!;
58
+ expect(err.file).toBe("test_math.py");
59
+ expect(err.line).toBe(12);
60
+ expect(err.message).toBe("ZeroDivisionError: division by zero");
61
+
62
+ // FAIL block
63
+ const fail = result.failures!.find((f) => f.rule === "assertion")!;
64
+ expect(fail.file).toBe("test_math.py");
65
+ expect(fail.line).toBe(9);
66
+ expect(fail.message).toBe("12 != 99");
67
+ });
68
+
69
+ it("all passing → status pass", async () => {
70
+ const stderr = `...
71
+ ----------------------------------------------------------------------
72
+ Ran 3 tests in 0.001s
73
+
74
+ OK`;
75
+ const result = await parser.parse(makeCtx(stderr));
76
+ expect(result.status).toBe("pass");
77
+ expect(result.summary).toBe("3 passed");
78
+ expect(result.failures).toHaveLength(0);
79
+ });
80
+
81
+ it("empty stderr → status pass", async () => {
82
+ const result = await parser.parse(makeCtx(""));
83
+ expect(result.status).toBe("pass");
84
+ });
85
+
86
+ it("file paths relativized to cwd", async () => {
87
+ const result = await parser.parse(makeCtx(REAL_FAILURE_OUTPUT, "/project"));
88
+ for (const f of result.failures!) {
89
+ expect(f.file).not.toContain("/project/");
90
+ expect(f.file).toBe("test_math.py");
91
+ }
92
+ });
93
+
94
+ it("skipped tests are not counted as passed", async () => {
95
+ const stderr = `.sF
96
+ ======================================================================
97
+ FAIL: test_fail (test_math.TestMath.test_fail)
98
+ ----------------------------------------------------------------------
99
+ Traceback (most recent call last):
100
+ File "/project/test_math.py", line 8, in test_fail
101
+ self.assertEqual(1, 2)
102
+ ~~~~~~~~~~~~~~~~^^^^^^
103
+ AssertionError: 1 != 2
104
+
105
+ ----------------------------------------------------------------------
106
+ Ran 3 tests in 0.001s
107
+
108
+ FAILED (failures=1, skipped=1)`;
109
+ const result = await parser.parse(makeCtx(stderr));
110
+ expect(result.status).toBe("fail");
111
+ // 3 total - 1 failed - 1 skipped = 1 passed (not 2)
112
+ expect(result.summary).toBe("1 failed, 1 passed");
113
+ expect(result.failures).toHaveLength(1);
114
+ });
115
+
116
+ it("all passing with skips → correct passed count", async () => {
117
+ const stderr = `.s
118
+ ----------------------------------------------------------------------
119
+ Ran 2 tests in 0.001s
120
+
121
+ OK (skipped=1)`;
122
+ const result = await parser.parse(makeCtx(stderr));
123
+ expect(result.status).toBe("pass");
124
+ expect(result.summary).toBe("1 passed");
125
+ });
126
+ });
@@ -0,0 +1,116 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ // unittest output blocks are separated by ======
6
+ // Each block starts with ERROR: or FAIL: line
7
+ // Then a Traceback with file:line, and the final line is the error/assertion message
8
+
9
+ const BLOCK_HEADER = /(ERROR|FAIL):\s+(\S+)\s+\(([^)]+)\)/;
10
+ const FILE_LINE = /File\s+"([^"]+)",\s+line\s+(\d+)/;
11
+
12
+ const parser: ParserModule = {
13
+ id: "unittest-text",
14
+ async parse(ctx) {
15
+ // Python unittest writes all output (results, tracebacks, summary) to stderr.
16
+ const stderr = safeReadFile(ctx.stderrPath).trim();
17
+ if (!stderr) {
18
+ return { tool: "unittest", status: "pass", summary: "no output", failures: [], logPath: ctx.logPath };
19
+ }
20
+
21
+ // Parse the summary line: "Ran N tests in Xs" and "FAILED (failures=N, errors=N)" or "OK"
22
+ const ranMatch = stderr.match(/Ran\s+(\d+)\s+test/);
23
+ const totalTests = ranMatch ? Number(ranMatch[1]) : 0;
24
+ // Parse skipped count from "FAILED (failures=N, skipped=N)" or "OK (skipped=N)"
25
+ const skippedMatch = stderr.match(/skipped=(\d+)/);
26
+ const skipped = skippedMatch ? Number(skippedMatch[1]) : 0;
27
+ const isOk = stderr.includes("\nOK");
28
+
29
+ if (isOk) {
30
+ const passed = totalTests - skipped;
31
+ return {
32
+ tool: "unittest",
33
+ status: "pass",
34
+ summary: `${passed} passed`,
35
+ failures: [],
36
+ logPath: ctx.logPath,
37
+ };
38
+ }
39
+
40
+ // Split into blocks by the ====== separator
41
+ const blocks = stderr.split(/={50,}/);
42
+ const failures: ParsedFailure[] = [];
43
+
44
+ for (const block of blocks) {
45
+ const headerMatch = block.match(BLOCK_HEADER);
46
+ if (!headerMatch) continue;
47
+
48
+ const [, kind, testName] = headerMatch;
49
+ const lines = block.split("\n");
50
+
51
+ // Find the last File "..." line in the traceback (the user code, not framework)
52
+ let file: string | undefined;
53
+ let line: number | undefined;
54
+ for (const l of lines) {
55
+ const fm = l.match(FILE_LINE);
56
+ if (fm) {
57
+ file = fm[1];
58
+ line = Number(fm[2]);
59
+ }
60
+ }
61
+
62
+ // The error message is the last non-empty line of the traceback block.
63
+ // Stop at dashed separators (------) that come AFTER the traceback,
64
+ // summary lines ("Ran N tests"), or FAILED/OK lines.
65
+ const traceLines: string[] = [];
66
+ let pastHeader = false;
67
+ for (const l of lines) {
68
+ const trimmed = l.trim();
69
+ if (!pastHeader) {
70
+ // Skip until we're past the initial header + first dashed separator
71
+ if (/^-{10,}/.test(trimmed)) {
72
+ pastHeader = true;
73
+ }
74
+ continue;
75
+ }
76
+ // Stop at the next dashed separator (before summary) or summary lines
77
+ if (/^-{10,}/.test(trimmed)) break;
78
+ if (/^Ran\s+\d+\s+test/.test(trimmed)) break;
79
+ if (/^(FAILED|OK)/.test(trimmed)) break;
80
+ traceLines.push(trimmed);
81
+ }
82
+ const nonEmpty = traceLines.filter(Boolean);
83
+ const errorLine = nonEmpty[nonEmpty.length - 1] ?? "test failed";
84
+
85
+ // For assertions, extract expected/actual from "AssertionError: X != Y"
86
+ let message = errorLine;
87
+ const assertMatch = errorLine.match(/AssertionError:\s*(.+)/);
88
+ if (assertMatch) {
89
+ message = assertMatch[1];
90
+ }
91
+
92
+ const relFile = file ? (path.isAbsolute(file) ? path.relative(ctx.cwd, file) : file) : undefined;
93
+
94
+ failures.push({
95
+ id: `${testName}`,
96
+ file: relFile,
97
+ line,
98
+ message,
99
+ rule: kind === "ERROR" ? "error" : "assertion",
100
+ });
101
+ }
102
+
103
+ const failed = failures.length;
104
+ const passed = totalTests - failed - skipped;
105
+
106
+ return {
107
+ tool: "unittest",
108
+ status: failed > 0 ? "fail" : "pass",
109
+ summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
110
+ failures,
111
+ logPath: ctx.logPath,
112
+ };
113
+ },
114
+ };
115
+
116
+ export default parser;
@@ -0,0 +1,43 @@
1
+ import fs from "node:fs";
2
+
3
+ /**
4
+ * Safely read a file, returning empty string if it doesn't exist.
5
+ * Handles the case where a command was killed before writing output.
6
+ */
7
+ export function safeReadFile(filePath: string): string {
8
+ try {
9
+ return fs.readFileSync(filePath, "utf8");
10
+ } catch (err: unknown) {
11
+ if (err instanceof Error && "code" in err && err.code === "ENOENT") return "";
12
+ throw err;
13
+ }
14
+ }
15
+
16
+ /**
17
+ * Extract the first user-code file:line from a JS/TS stack trace string.
18
+ * Skips node_modules and Node.js internal frames.
19
+ *
20
+ * Handles both formats:
21
+ * at functionName (file.ts:10:5)
22
+ * at file.ts:10:5
23
+ */
24
+ export function extractJsStackLocation(stack: string | undefined): { file?: string; line?: number } {
25
+ if (!stack) return {};
26
+ for (const line of stack.split("\n")) {
27
+ // "at name (file:line:col)"
28
+ const withParens = line.match(/at\s+\S+\s+\(([^)]+\.(?:[jt]sx?|mjs|cjs)):(\d+):\d+\)/);
29
+ if (withParens && isUserFrame(withParens[1])) {
30
+ return { file: withParens[1], line: Number(withParens[2]) };
31
+ }
32
+ // "at file:line:col" (no parens)
33
+ const bare = line.match(/at\s+([^\s(]+\.(?:[jt]sx?|mjs|cjs)):(\d+):\d+/);
34
+ if (bare && isUserFrame(bare[1])) {
35
+ return { file: bare[1], line: Number(bare[2]) };
36
+ }
37
+ }
38
+ return {};
39
+ }
40
+
41
+ function isUserFrame(filePath: string): boolean {
42
+ return !filePath.includes("node_modules") && !filePath.includes("node:");
43
+ }
@@ -0,0 +1,84 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import { describe, it, expect } from "vitest";
5
+ import parser from "./vale-json";
6
+ import type { RunContext } from "../types";
7
+
8
+ function makeCtx(stdout: string, cwd = "/project"): RunContext {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "vale-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ fs.writeFileSync(stdoutPath, stdout);
12
+ return {
13
+ command: "vale --output JSON .",
14
+ argv: ["vale", "--output", "JSON", "."],
15
+ cwd,
16
+ artifactPaths: [],
17
+ stdoutPath,
18
+ stderrPath: path.join(dir, "stderr"),
19
+ logPath: path.join(dir, "log"),
20
+ };
21
+ }
22
+
23
+ describe("vale-json parser", () => {
24
+ it("multiple errors across files → correct relative paths, rule names, severity summary", async () => {
25
+ const cwd = "/project";
26
+ const stdout = JSON.stringify({
27
+ "/project/docs/readme.md": [
28
+ {
29
+ Line: 3,
30
+ Message: "Did you really mean 'writen'?",
31
+ Severity: "error",
32
+ Check: "Vale.Spelling",
33
+ Action: { Name: "suggest", Params: ["spellings"] },
34
+ Span: [57, 62],
35
+ },
36
+ {
37
+ Line: 5,
38
+ Message: "Use 'basically' instead of 'basicly'.",
39
+ Severity: "warning",
40
+ Check: "Vale.Terms",
41
+ Action: { Name: "replace", Params: ["basically"] },
42
+ Span: [10, 17],
43
+ },
44
+ ],
45
+ });
46
+ const result = await parser.parse(makeCtx(stdout, cwd));
47
+ expect(result.status).toBe("fail");
48
+ expect(result.summary).toBe("1 error, 1 warning");
49
+ expect(result.failures).toHaveLength(2);
50
+ expect(result.failures![0].file).toBe("docs/readme.md");
51
+ expect(result.failures![0].rule).toBe("Vale.Spelling");
52
+ expect(result.failures![1].rule).toBe("Vale.Terms");
53
+ });
54
+
55
+ it("warnings only → status pass (no errors)", async () => {
56
+ const stdout = JSON.stringify({
57
+ "/project/doc.md": [
58
+ {
59
+ Line: 1,
60
+ Message: "Consider using active voice.",
61
+ Severity: "warning",
62
+ Check: "Vale.Passive",
63
+ Action: {},
64
+ Span: [1, 10],
65
+ },
66
+ ],
67
+ });
68
+ const result = await parser.parse(makeCtx(stdout));
69
+ expect(result.status).toBe("pass");
70
+ expect(result.summary).toBe("1 warning");
71
+ });
72
+
73
+ it("no alerts → status pass", async () => {
74
+ const result = await parser.parse(makeCtx(JSON.stringify({})));
75
+ expect(result.status).toBe("pass");
76
+ expect(result.summary).toBe("no prose issues");
77
+ });
78
+
79
+ it("empty stdout → no crash, status pass", async () => {
80
+ const result = await parser.parse(makeCtx(""));
81
+ expect(result.status).toBe("pass");
82
+ expect(result.failures).toHaveLength(0);
83
+ });
84
+ });
@@ -0,0 +1,80 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ interface ValeAlert {
6
+ Line: number;
7
+ Message: string;
8
+ Severity: string;
9
+ Check: string;
10
+ }
11
+
12
+ const parser: ParserModule = {
13
+ id: "vale-json",
14
+ async parse(ctx) {
15
+ const stdout = safeReadFile(ctx.stdoutPath).trim();
16
+ if (!stdout) {
17
+ return {
18
+ tool: "vale",
19
+ status: "pass",
20
+ summary: "no prose issues",
21
+ failures: [],
22
+ logPath: ctx.logPath,
23
+ };
24
+ }
25
+
26
+ let output: Record<string, ValeAlert[]>;
27
+ try {
28
+ output = JSON.parse(stdout);
29
+ } catch {
30
+ return {
31
+ tool: "vale",
32
+ status: "error",
33
+ summary: "failed to parse vale JSON output",
34
+ logPath: ctx.logPath,
35
+ };
36
+ }
37
+
38
+ const failures: ParsedFailure[] = [];
39
+ const bySeverity: Record<string, number> = {};
40
+
41
+ for (const [filePath, alerts] of Object.entries(output)) {
42
+ const relPath = path.relative(ctx.cwd, filePath);
43
+ for (const alert of alerts) {
44
+ const sev = alert.Severity.toLowerCase();
45
+ bySeverity[sev] = (bySeverity[sev] ?? 0) + 1;
46
+ failures.push({
47
+ id: `${relPath}:${alert.Line}:${alert.Check}`,
48
+ file: relPath,
49
+ line: alert.Line,
50
+ message: alert.Message,
51
+ rule: alert.Check,
52
+ });
53
+ }
54
+ }
55
+
56
+ if (failures.length === 0) {
57
+ return {
58
+ tool: "vale",
59
+ status: "pass",
60
+ summary: "no prose issues",
61
+ failures: [],
62
+ logPath: ctx.logPath,
63
+ };
64
+ }
65
+
66
+ const parts = ["error", "warning", "suggestion"]
67
+ .filter((s) => bySeverity[s])
68
+ .map((s) => `${bySeverity[s]} ${s}${bySeverity[s] !== 1 ? "s" : ""}`);
69
+
70
+ return {
71
+ tool: "vale",
72
+ status: bySeverity["error"] ? "fail" : "pass",
73
+ summary: parts.join(", "),
74
+ failures,
75
+ logPath: ctx.logPath,
76
+ };
77
+ },
78
+ };
79
+
80
+ export default parser;
@@ -1,6 +1,6 @@
1
- import fs from "node:fs";
2
1
  import path from "node:path";
3
2
  import type { ParserModule } from "../types";
3
+ import { safeReadFile } from "./utils";
4
4
 
5
5
  interface VitestAssertionResult {
6
6
  fullName: string;
@@ -23,7 +23,7 @@ interface VitestReport {
23
23
  const parser: ParserModule = {
24
24
  id: "vitest-json",
25
25
  async parse(ctx) {
26
- const stdout = fs.readFileSync(ctx.stdoutPath, "utf8").trim();
26
+ const stdout = safeReadFile(ctx.stdoutPath).trim();
27
27
  const report = stdout ? (JSON.parse(stdout) as VitestReport) : null;
28
28
  if (!report) {
29
29
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robhowley/pi-structured-return",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Structured command execution for Pi agents: compact results for the model, full logs for humans.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -30,8 +30,86 @@ Prefer better output at the source.
30
30
  ### ruff check
31
31
  - `structured_return({ command: "ruff check [any ruff args] --output-format=json", parseAs: "ruff-json" })` — scope, selects, ignores, etc. go in `[any ruff args]`
32
32
 
33
- ### ruff format
34
- - `ruff format --check .` (no structured_return — json output not supported)
33
+ ### mypy
34
+ - `structured_return({ command: "mypy [any mypy args] --output json", parseAs: "mypy-json" })` — `--output json` is built into mypy (1.0+); outputs NDJSON to stderr with file, line, column, message, error code, and severity; notes are folded into their parent error's message
35
+
36
+ ### htmlhint
37
+ - `structured_return({ command: "npx htmlhint --format json [any htmlhint args]", parseAs: "htmlhint-json" })` — `--format json` outputs structured array; strips ANSI codes, source evidence, rule descriptions, and URLs
38
+
39
+ ### isort
40
+ - `structured_return({ command: "isort --check --diff [any isort args]", parseAs: "isort-text" })` — parses `--check` output; strips diff hunks, absolute paths, timestamps; lists files with unsorted imports
41
+
42
+ ### npm audit
43
+ - `structured_return({ command: "npm audit --json", parseAs: "npm-audit-json" })` — `--json` is built into npm; strips advisory URLs, CVSS vectors, fix instructions; advisory titles joined per package; severity breakdown in summary
44
+
45
+ ### jsonlint
46
+ - `structured_return({ command: "npx jsonlint [file]", parseAs: "jsonlint-text" })` — strips stack trace and source pointer; extracts line number and "Expecting X, got Y" message
47
+
48
+ ### tidy (HTML Tidy)
49
+ - `structured_return({ command: "tidy -errors [any tidy args]", parseAs: "tidy-text" })` — parses `line N column N - Warning/Error: message` from stderr; strips remediation advice, accessibility tips, reformatted HTML output, and Info lines
50
+
51
+ ### vale
52
+ - `structured_return({ command: "vale --output JSON [any vale args]", parseAs: "vale-json" })` — `--output JSON` is built into vale; strips ANSI codes, Action/Span metadata, column-aligned formatting; severity breakdown in summary
53
+
54
+ ### prettier
55
+ - `structured_return({ command: "prettier --check [any prettier args]", parseAs: "prettier-text" })` — parses `--check` output; strips "Checking formatting..." preamble, [warn] prefixes, and "Run Prettier with --write to fix" footer
56
+
57
+ ### markdownlint
58
+ - `structured_return({ command: "markdownlint --json [any markdownlint args]", parseAs: "markdownlint-json" })` — `--json` outputs structured array; strips context quotes, rule info URLs, fix info, and error ranges; error details folded into description
59
+
60
+ ### black
61
+ - `structured_return({ command: "black --check [any black args]", parseAs: "black-text" })` — parses `--check` output; strips diff hunks, emoji banners, timestamps; lists files needing reformatting; also handles `--check --diff` mode
62
+
63
+ ### bandit
64
+ - `structured_return({ command: "bandit -f json [any bandit args]", parseAs: "bandit-json" })` — `-f json` is built into bandit; strips source snippets, CWE URLs, run metrics, and confidence labels; severity breakdown in summary
65
+
66
+ ### gcc / clang
67
+ - `structured_return({ command: "gcc -c [any gcc args]", parseAs: "clang-text" })` — works with gcc, g++, clang, clang++; parses `file:line:col: error: message` from stderr; source snippets and caret indicators stripped; warning flags preserved as rule
68
+
69
+ ### dotnet build
70
+ - `structured_return({ command: "dotnet build [any dotnet args]", parseAs: "dotnet-build-text" })` — parses MSBuild `file(line,col): error CODE: message` format; strips restore/timing noise; deduplicates the inline+summary error repetition; absolute paths relativized
71
+
72
+ ### javac
73
+ - `structured_return({ command: "javac [any javac args]", parseAs: "javac-text" })` — parses `file:line: error: message` from stderr; source snippets and caret indicators stripped; `cannot find symbol` errors fold the symbol continuation line into the message
74
+
75
+ ### pyright
76
+ - `structured_return({ command: "pyright --outputjson [any pyright args]", parseAs: "pyright-json" })` — `--outputjson` is built into pyright; JSON output includes file, line, message, and rule code; multi-line detail messages collapsed; warnings excluded from failures
77
+
78
+ ### tsc
79
+ - `structured_return({ command: "tsc --noEmit --pretty false [any tsc args]", parseAs: "tsc-text" })` — `--pretty false` suppresses source snippets and ANSI codes; parser extracts file, line, TS error code, and message from the compact `file(line,col): error TSXXXX: message` format
80
+
81
+ ### pylint
82
+ - `structured_return({ command: "pylint [any pylint args] --output-format=json", parseAs: "pylint-json" })` — `--output-format=json` is built into pylint; rule includes both message-id and symbol name (e.g. `W0612(unused-variable)`)
83
+
84
+ ### shellcheck
85
+ - `structured_return({ command: "shellcheck [any shellcheck args] --format=json", parseAs: "shellcheck-json" })` — `--format=json` is built into shellcheck; strips source snippets, caret indicators, "Did you mean" suggestions, and wiki URLs
86
+
87
+ ### rubocop
88
+ - `structured_return({ command: "rubocop [any rubocop args] --format json", parseAs: "rubocop-json" })` — `--format json` is built into rubocop; cop name prefix stripped from messages; source snippets and caret indicators removed
89
+
90
+ ### swiftc
91
+ - `structured_return({ command: "swiftc -typecheck [any swiftc args]", parseAs: "swiftc-text" })` — parses `file:line:col: error: message` from stderr; source annotations and duplicate error lines deduplicated; warnings filtered out
92
+
93
+ ### hadolint
94
+ - `structured_return({ command: "hadolint [any hadolint args] --format json", parseAs: "hadolint-json" })` — `--format json` is built into hadolint; strips ANSI color codes and level labels from text output
95
+
96
+ ### stylelint
97
+ - `structured_return({ command: "stylelint [any stylelint args] --formatter json", parseAs: "stylelint-json" })` — `--formatter json` is built into stylelint; rule name suffix stripped from message text; requires a `.stylelintrc` config
98
+
99
+ ### node --test
100
+ - `structured_return({ command: "node --test [any node test args]", parseAs: "node-test-text" })` — parses the default spec reporter output; strips full stack traces, assertion error internals, timing data; preserves expected/actual values from assertion failures
101
+
102
+ ### ava
103
+ - `structured_return({ command: "npx ava [any ava args] --no-color", parseAs: "ava-text" })` — parses default text output from stderr; assertion failures extract expected/actual from diff lines and file:line; runtime errors extract message and file:line from stack trace
104
+
105
+ ### mocha
106
+ - `structured_return({ command: "mocha [any mocha args] --reporter json", parseAs: "mocha-json" })` — `--reporter json` is built into mocha; assertion failures surface explicit expected/actual values; runtime errors surface message and file:line from stack trace
107
+
108
+ ### Python unittest
109
+ - `structured_return({ command: "python3 -m unittest [any unittest args]", parseAs: "unittest-text" })` — no special flags needed; parses the default verbose traceback output from stderr; assertion messages extracted from `AssertionError` lines; file:line from traceback frames
110
+
111
+ ### go test
112
+ - `structured_return({ command: "go test -json [any go test args]", parseAs: "go-test-json" })` — `-json` is built into `go test`; NDJSON output; assertion failures extract file:line and message from `t.Error`/`t.Errorf` output; panics extract message and user-code file:line from stack trace; 97% reduction vs raw NDJSON
35
113
 
36
114
  ### vitest
37
115
  - `structured_return({ command: "vitest run [any vitest args] --reporter=json", parseAs: "vitest-json" })` — file paths, filters, etc. go in `[any vitest args]`
@@ -95,3 +173,16 @@ Jest requires the `jest-junit` reporter (`npm install --save-dev jest-junit`). P
95
173
  `xcodebuild` output is high-volume and not directly parseable. Pipe through `xcbeautify` (install with `brew install xcbeautify`) to get JUnit XML:
96
174
 
97
175
  - `structured_return({ command: "xcodebuild test -scheme [scheme] -destination '[destination]' 2>&1 | xcbeautify --report junit --output .tmp", parseAs: "junit-xml", artifactPaths: [".tmp/report.junit.xml"] })` — xcbeautify writes `report.junit.xml` into the `--output` directory; run `xcodebuild -showdestinations -scheme [scheme]` first to find the correct `[destination]` string for the project
176
+
177
+ ## Already compact — use `bash` directly
178
+
179
+ These tools were evaluated for structured parsing but their output is already compact enough that a parser adds no token reduction. Use `bash` instead of `structured_return`.
180
+
181
+ - `flake8 [any flake8 args]` — `file:line:col: CODE message`, one line per violation
182
+ - `ruff format --check .` — just lists files needing formatting
183
+ - `go build [any go build args]` — `file:line:col: message`, one line per error
184
+ - `go vet [any go vet args]` — same format as go build
185
+ - `golangci-lint run [any golangci-lint args]` — `file:line:col: message (linter)`, already minimal
186
+ - `yamllint [any yamllint args]` — `file:line:col level message (rule)`, one line per issue
187
+ - `pydocstyle [any pydocstyle args]` — `file:line context + CODE: message`, two lines per issue
188
+ - `vulture [any vulture args]` — `file:line: message (confidence%)`, one line per finding