@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,120 @@
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 "./stylelint-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(), "stylelint-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ fs.writeFileSync(stdoutPath, stdout);
12
+ return {
13
+ command: "stylelint lint_check.css --formatter json",
14
+ argv: ["stylelint", "lint_check.css", "--formatter", "json"],
15
+ cwd,
16
+ artifactPaths: [],
17
+ stdoutPath,
18
+ stderrPath: path.join(dir, "stderr"),
19
+ logPath: path.join(dir, "log"),
20
+ };
21
+ }
22
+
23
+ describe("stylelint-json parser", () => {
24
+ it("multiple warnings → correct file, line, message, rule", async () => {
25
+ const stdout = JSON.stringify([
26
+ {
27
+ source: "/project/lint_check.css",
28
+ warnings: [
29
+ {
30
+ line: 2,
31
+ column: 3,
32
+ rule: "declaration-block-no-duplicate-properties",
33
+ severity: "error",
34
+ text: 'Unexpected duplicate "color" (declaration-block-no-duplicate-properties)',
35
+ },
36
+ {
37
+ line: 4,
38
+ column: 19,
39
+ rule: "declaration-no-important",
40
+ severity: "error",
41
+ text: "Unexpected !important (declaration-no-important)",
42
+ },
43
+ ],
44
+ deprecations: [],
45
+ invalidOptionWarnings: [],
46
+ },
47
+ ]);
48
+ const result = await parser.parse(makeCtx(stdout, "/project"));
49
+ expect(result.status).toBe("fail");
50
+ expect(result.summary).toBe("2 lint errors");
51
+ expect(result.failures![0]).toMatchObject({
52
+ file: "lint_check.css",
53
+ line: 2,
54
+ message: 'Unexpected duplicate "color"',
55
+ rule: "declaration-block-no-duplicate-properties",
56
+ });
57
+ expect(result.failures![1]).toMatchObject({ message: "Unexpected !important", rule: "declaration-no-important" });
58
+ });
59
+
60
+ it("no warnings → status pass", async () => {
61
+ const stdout = JSON.stringify([{ source: "clean.css", warnings: [], deprecations: [], invalidOptionWarnings: [] }]);
62
+ const result = await parser.parse(makeCtx(stdout));
63
+ expect(result.status).toBe("pass");
64
+ expect(result.failures).toHaveLength(0);
65
+ });
66
+
67
+ it("empty stdout → status pass", async () => {
68
+ const result = await parser.parse(makeCtx(""));
69
+ expect(result.status).toBe("pass");
70
+ });
71
+
72
+ it("strips rule name suffix from message text", async () => {
73
+ const stdout = JSON.stringify([
74
+ {
75
+ source: "foo.css",
76
+ warnings: [
77
+ {
78
+ line: 1,
79
+ column: 1,
80
+ rule: "color-no-invalid-hex",
81
+ severity: "error",
82
+ text: 'Unexpected invalid hex color "#FG" (color-no-invalid-hex)',
83
+ },
84
+ ],
85
+ },
86
+ ]);
87
+ const result = await parser.parse(makeCtx(stdout));
88
+ expect(result.failures![0].message).toBe('Unexpected invalid hex color "#FG"');
89
+ expect(result.failures![0].rule).toBe("color-no-invalid-hex");
90
+ });
91
+
92
+ it("does not strip trailing parens when they are part of the message, not the rule", async () => {
93
+ const stdout = JSON.stringify([
94
+ {
95
+ source: "foo.css",
96
+ warnings: [
97
+ {
98
+ line: 3,
99
+ column: 10,
100
+ rule: "function-no-unknown",
101
+ severity: "error",
102
+ text: 'Unexpected unknown function "clamp(10px, 5vw, 50px)" (function-no-unknown)',
103
+ },
104
+ {
105
+ line: 7,
106
+ column: 15,
107
+ rule: "value-no-vendor-prefix",
108
+ severity: "error",
109
+ text: "Unexpected value with parentheses calc(100% - 10px)",
110
+ },
111
+ ],
112
+ },
113
+ ]);
114
+ const result = await parser.parse(makeCtx(stdout));
115
+ // First warning: has the standard "(rule-name)" suffix — should be stripped
116
+ expect(result.failures![0].message).toBe('Unexpected unknown function "clamp(10px, 5vw, 50px)"');
117
+ // Second warning: trailing parens are CSS value, not rule suffix — must NOT be stripped
118
+ expect(result.failures![1].message).toBe("Unexpected value with parentheses calc(100% - 10px)");
119
+ });
120
+ });
@@ -0,0 +1,68 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ interface StylelintWarning {
6
+ line: number;
7
+ column: number;
8
+ rule: string;
9
+ severity: string;
10
+ text: string;
11
+ }
12
+
13
+ interface StylelintResult {
14
+ source: string;
15
+ warnings: StylelintWarning[];
16
+ }
17
+
18
+ const parser: ParserModule = {
19
+ id: "stylelint-json",
20
+ async parse(ctx) {
21
+ const stdout = safeReadFile(ctx.stdoutPath).trim();
22
+ if (!stdout || stdout === "[]") {
23
+ return { tool: "stylelint", status: "pass", summary: "no lint errors", failures: [], logPath: ctx.logPath };
24
+ }
25
+
26
+ let results: StylelintResult[];
27
+ try {
28
+ results = JSON.parse(stdout) as StylelintResult[];
29
+ } catch {
30
+ return {
31
+ tool: "stylelint",
32
+ status: "error",
33
+ summary: "failed to parse stylelint JSON output",
34
+ logPath: ctx.logPath,
35
+ };
36
+ }
37
+
38
+ const failures: ParsedFailure[] = [];
39
+ for (const result of results) {
40
+ const relPath = path.isAbsolute(result.source) ? path.relative(ctx.cwd, result.source) : result.source;
41
+ for (const w of result.warnings) {
42
+ // Strip the trailing " (rule-name)" from text, but only if the
43
+ // parenthesized content matches the actual rule name. Avoids
44
+ // over-stripping when the message itself ends with parens
45
+ // (e.g. CSS values like "calc(100% - 10px)").
46
+ const suffix = ` (${w.rule})`;
47
+ const msg = w.text.endsWith(suffix) ? w.text.slice(0, -suffix.length) : w.text;
48
+ failures.push({
49
+ id: `${relPath}:${w.line}:${w.rule}`,
50
+ file: relPath,
51
+ line: w.line,
52
+ message: msg,
53
+ rule: w.rule,
54
+ });
55
+ }
56
+ }
57
+
58
+ return {
59
+ tool: "stylelint",
60
+ status: failures.length > 0 ? "fail" : "pass",
61
+ summary: failures.length > 0 ? `${failures.length} lint errors` : "no lint errors",
62
+ failures,
63
+ logPath: ctx.logPath,
64
+ };
65
+ },
66
+ };
67
+
68
+ export default parser;
@@ -0,0 +1,73 @@
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 "./swiftc-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(), "swiftc-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: "swiftc -typecheck type_check.swift",
16
+ argv: ["swiftc", "-typecheck", "type_check.swift"],
17
+ cwd,
18
+ artifactPaths: [],
19
+ stdoutPath,
20
+ stderrPath,
21
+ logPath: path.join(dir, "log"),
22
+ };
23
+ }
24
+
25
+ describe("swiftc-text parser", () => {
26
+ it("multiple errors with source annotations → deduplicated, correct file/line/message", async () => {
27
+ const stderr = [
28
+ "type_check.swift:5:22: error: cannot convert value of type 'Int' to specified type 'String'",
29
+ "3 | }",
30
+ "4 | ",
31
+ "5 | let result: String = add(1, 2)",
32
+ " | `- error: cannot convert value of type 'Int' to specified type 'String'",
33
+ '6 | let total: Int = add("hello", 3)',
34
+ "",
35
+ "type_check.swift:6:22: error: cannot convert value of type 'String' to expected argument type 'Int'",
36
+ "5 | let result: String = add(1, 2)",
37
+ '6 | let total: Int = add("hello", 3)',
38
+ " | `- error: cannot convert value of type 'String' to expected argument type 'Int'",
39
+ ].join("\n");
40
+ const result = await parser.parse(makeCtx(stderr));
41
+ expect(result.status).toBe("fail");
42
+ expect(result.summary).toBe("2 errors");
43
+ expect(result.failures).toHaveLength(2);
44
+ expect(result.failures![0]).toMatchObject({
45
+ file: "type_check.swift",
46
+ line: 5,
47
+ message: "cannot convert value of type 'Int' to specified type 'String'",
48
+ });
49
+ expect(result.failures![1]).toMatchObject({ file: "type_check.swift", line: 6 });
50
+ });
51
+
52
+ it("empty stderr → status pass", async () => {
53
+ const result = await parser.parse(makeCtx(""));
54
+ expect(result.status).toBe("pass");
55
+ expect(result.failures).toHaveLength(0);
56
+ });
57
+
58
+ it("absolute paths → relativized", async () => {
59
+ const stderr = "/project/Sources/main.swift:10:5: error: use of unresolved identifier 'foo'";
60
+ const result = await parser.parse(makeCtx(stderr, "/project"));
61
+ expect(result.failures![0].file).toBe("Sources/main.swift");
62
+ });
63
+
64
+ it("warnings are skipped", async () => {
65
+ const stderr = [
66
+ "foo.swift:1:1: warning: expression of type 'Int' is unused",
67
+ "foo.swift:2:1: error: cannot find 'bar' in scope",
68
+ ].join("\n");
69
+ const result = await parser.parse(makeCtx(stderr));
70
+ expect(result.failures).toHaveLength(1);
71
+ expect(result.failures![0].message).toBe("cannot find 'bar' in scope");
72
+ });
73
+ });
@@ -0,0 +1,47 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ // swiftc format: file:line:col: error: message (or warning:, note:)
6
+ const SWIFT_LINE = /^(.+?):(\d+):\d+:\s+(error|warning):\s+(.+)$/;
7
+
8
+ const parser: ParserModule = {
9
+ id: "swiftc-text",
10
+ async parse(ctx) {
11
+ // swiftc writes diagnostics (errors, warnings, notes) to stderr.
12
+ const stderr = safeReadFile(ctx.stderrPath).trim();
13
+ if (!stderr) {
14
+ return { tool: "swiftc", status: "pass", summary: "no errors", failures: [], logPath: ctx.logPath };
15
+ }
16
+
17
+ const failures: ParsedFailure[] = [];
18
+ const seen = new Set<string>();
19
+ for (const line of stderr.split("\n")) {
20
+ const m = line.match(SWIFT_LINE);
21
+ if (!m) continue;
22
+ const [, file, lineNum, severity, message] = m;
23
+ if (severity !== "error") continue; // skip warnings for now
24
+ const relPath = path.isAbsolute(file) ? path.relative(ctx.cwd, file) : file;
25
+ // Deduplicate: swiftc repeats the same error in source annotation lines
26
+ const id = `${relPath}:${lineNum}:${message}`;
27
+ if (seen.has(id)) continue;
28
+ seen.add(id);
29
+ failures.push({
30
+ id,
31
+ file: relPath,
32
+ line: Number(lineNum),
33
+ message,
34
+ });
35
+ }
36
+
37
+ return {
38
+ tool: "swiftc",
39
+ status: failures.length > 0 ? "fail" : "pass",
40
+ summary: failures.length > 0 ? `${failures.length} errors` : "no errors",
41
+ failures,
42
+ logPath: ctx.logPath,
43
+ };
44
+ },
45
+ };
46
+
47
+ export default parser;
@@ -1,10 +1,10 @@
1
- import fs from "node:fs";
2
1
  import type { ParserModule } from "../types";
2
+ import { safeReadFile } from "./utils";
3
3
 
4
4
  const parser: ParserModule = {
5
5
  id: "tail-fallback",
6
6
  async parse(ctx) {
7
- const log = fs.readFileSync(ctx.logPath, "utf8");
7
+ const log = safeReadFile(ctx.logPath);
8
8
  const lines = log.split(/\r?\n/);
9
9
  const tail = lines.slice(-200).join("\n");
10
10
  return {
@@ -0,0 +1,74 @@
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 "./tidy-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(), "tidy-test-"));
10
+ const stderrPath = path.join(dir, "stderr");
11
+ fs.writeFileSync(stderrPath, stderr);
12
+ return {
13
+ command: "tidy -errors src/index.html",
14
+ argv: ["tidy", "-errors", "src/index.html"],
15
+ cwd,
16
+ artifactPaths: [],
17
+ stdoutPath: path.join(dir, "stdout"),
18
+ stderrPath,
19
+ logPath: path.join(dir, "log"),
20
+ };
21
+ }
22
+
23
+ describe("tidy-text parser", () => {
24
+ it("warnings with remediation noise → strips advice, extracts line and message", async () => {
25
+ const stderr = `line 1 column 1 - Warning: missing <!DOCTYPE> declaration
26
+ line 1 column 9 - Warning: inserting missing 'title' element
27
+ line 1 column 35 - Warning: <img> lacks "alt" attribute
28
+ Info: Document content looks like HTML 3.2
29
+ 3 warnings, 0 errors were found!
30
+
31
+ The alt attribute should be used to give a short description
32
+ of an image; longer descriptions should be given with the
33
+ longdesc attribute which takes a URL linked to the description.
34
+ These measures are needed for people using non-graphical browsers.
35
+
36
+ For further advice on how to make your pages accessible
37
+ see http://www.w3.org/WAI/GL.
38
+
39
+ To learn more about HTML Tidy see http://tidy.sourceforge.net`;
40
+ const result = await parser.parse(makeCtx(stderr));
41
+ expect(result.status).toBe("pass");
42
+ expect(result.summary).toBe("3 warnings");
43
+ expect(result.failures).toHaveLength(3);
44
+ expect(result.failures![0].file).toBe("src/index.html");
45
+ expect(result.failures![0].line).toBe(1);
46
+ expect(result.failures![0].message).toBe("missing <!DOCTYPE> declaration");
47
+ expect(result.failures![2].message).toBe('<img> lacks "alt" attribute');
48
+ // No remediation text in failures
49
+ expect(result.failures!.every((f) => !f.message!.includes("should be used"))).toBe(true);
50
+ });
51
+
52
+ it("errors and warnings → both counted in summary", async () => {
53
+ const stderr = `line 1 column 1 - Error: unexpected end of file
54
+ line 1 column 1 - Warning: missing <!DOCTYPE> declaration
55
+ 1 warning, 1 error were found!`;
56
+ const result = await parser.parse(makeCtx(stderr));
57
+ expect(result.status).toBe("fail");
58
+ expect(result.summary).toBe("1 error, 1 warning");
59
+ expect(result.failures).toHaveLength(2);
60
+ });
61
+
62
+ it("no issues → status pass", async () => {
63
+ const stderr = `No warnings or errors were found.`;
64
+ const result = await parser.parse(makeCtx(stderr));
65
+ expect(result.status).toBe("pass");
66
+ expect(result.failures).toHaveLength(0);
67
+ });
68
+
69
+ it("empty stderr → no crash, status pass", async () => {
70
+ const result = await parser.parse(makeCtx(""));
71
+ expect(result.status).toBe("pass");
72
+ expect(result.failures).toHaveLength(0);
73
+ });
74
+ });
@@ -0,0 +1,67 @@
1
+ import type { ParserModule, ParsedFailure } from "../types";
2
+ import { safeReadFile } from "./utils";
3
+
4
+ // line N column N - Warning/Error: message
5
+ const ISSUE_LINE = /^line (\d+) column \d+ - (Warning|Error): (.+)$/;
6
+ // Summary: N warnings, N errors were found!
7
+ const SUMMARY_LINE = /^(\d+) warnings?, (\d+) errors? were found/;
8
+
9
+ const parser: ParserModule = {
10
+ id: "tidy-text",
11
+ async parse(ctx) {
12
+ const stderr = safeReadFile(ctx.stderrPath).trim();
13
+ if (!stderr) {
14
+ return {
15
+ tool: "tidy",
16
+ status: "pass",
17
+ summary: "no issues found",
18
+ failures: [],
19
+ logPath: ctx.logPath,
20
+ };
21
+ }
22
+
23
+ const lines = stderr.split("\n");
24
+ const failures: ParsedFailure[] = [];
25
+ let warnings = 0;
26
+ let errors = 0;
27
+
28
+ // Derive filename from command argv — tidy doesn't include filenames in output.
29
+ // Use last non-flag arg since flags like `-indent auto` have value arguments.
30
+ const file = ctx.argv.filter((a) => !a.startsWith("-") && a !== "tidy").pop() ?? "input";
31
+
32
+ for (const line of lines) {
33
+ const issueMatch = line.match(ISSUE_LINE);
34
+ if (issueMatch) {
35
+ const [, lineNum, level, message] = issueMatch;
36
+ failures.push({
37
+ id: `${file}:${lineNum}:${message}`,
38
+ file,
39
+ line: parseInt(lineNum, 10),
40
+ message,
41
+ rule: level.toLowerCase(),
42
+ });
43
+ continue;
44
+ }
45
+ const sumMatch = line.match(SUMMARY_LINE);
46
+ if (sumMatch) {
47
+ warnings = parseInt(sumMatch[1], 10);
48
+ errors = parseInt(sumMatch[2], 10);
49
+ }
50
+ }
51
+
52
+ const parts: string[] = [];
53
+ if (errors > 0) parts.push(`${errors} error${errors !== 1 ? "s" : ""}`);
54
+ if (warnings > 0) parts.push(`${warnings} warning${warnings !== 1 ? "s" : ""}`);
55
+ const summary = parts.join(", ") || "no issues found";
56
+
57
+ return {
58
+ tool: "tidy",
59
+ status: errors > 0 ? "fail" : "pass",
60
+ summary,
61
+ failures,
62
+ logPath: ctx.logPath,
63
+ };
64
+ },
65
+ };
66
+
67
+ export default parser;
@@ -0,0 +1,81 @@
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 "./tsc-text";
6
+ import type { RunContext } from "../types";
7
+
8
+ function makeCtx(stdout: string, cwd = "/project"): RunContext {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "tsc-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ fs.writeFileSync(stdoutPath, stdout);
12
+ return {
13
+ command: "tsc --noEmit --pretty false",
14
+ argv: ["tsc", "--noEmit", "--pretty", "false"],
15
+ cwd,
16
+ artifactPaths: [],
17
+ stdoutPath,
18
+ stderrPath: path.join(dir, "stderr"),
19
+ logPath: path.join(dir, "log"),
20
+ };
21
+ }
22
+
23
+ describe("tsc-text parser", () => {
24
+ it("multiple type errors → correct file, line, message, rule, status fail", async () => {
25
+ const stdout = [
26
+ "type_check.ts(5,7): error TS2322: Type 'number' is not assignable to type 'string'.",
27
+ "type_check.ts(6,27): error TS2345: Argument of type 'string' is not assignable to parameter of type 'number'.",
28
+ ].join("\n");
29
+ const result = await parser.parse(makeCtx(stdout));
30
+ expect(result.status).toBe("fail");
31
+ expect(result.summary).toBe("2 type errors");
32
+ expect(result.failures).toHaveLength(2);
33
+ expect(result.failures![0]).toMatchObject({
34
+ file: "type_check.ts",
35
+ line: 5,
36
+ message: "Type 'number' is not assignable to type 'string'.",
37
+ rule: "TS2322",
38
+ });
39
+ expect(result.failures![1]).toMatchObject({
40
+ file: "type_check.ts",
41
+ line: 6,
42
+ message: "Argument of type 'string' is not assignable to parameter of type 'number'.",
43
+ rule: "TS2345",
44
+ });
45
+ });
46
+
47
+ it("no errors (empty stdout) → status pass", async () => {
48
+ const result = await parser.parse(makeCtx(""));
49
+ expect(result.status).toBe("pass");
50
+ expect(result.summary).toBe("no type errors");
51
+ expect(result.failures).toHaveLength(0);
52
+ });
53
+
54
+ it("absolute file paths → relativized to cwd", async () => {
55
+ const stdout = "/project/src/foo.ts(10,5): error TS2304: Cannot find name 'bar'.";
56
+ const result = await parser.parse(makeCtx(stdout, "/project"));
57
+ expect(result.failures![0].file).toBe("src/foo.ts");
58
+ expect(result.failures![0].file).not.toContain("/project");
59
+ });
60
+
61
+ it("errors across multiple files", async () => {
62
+ const stdout = [
63
+ "src/a.ts(1,1): error TS2304: Cannot find name 'foo'.",
64
+ "src/b.ts(5,3): error TS2551: Property 'baz' does not exist on type 'Bar'.",
65
+ ].join("\n");
66
+ const result = await parser.parse(makeCtx(stdout));
67
+ expect(result.failures).toHaveLength(2);
68
+ expect(result.failures![0].file).toBe("src/a.ts");
69
+ expect(result.failures![1].file).toBe("src/b.ts");
70
+ });
71
+
72
+ it("skips non-error lines (e.g. Found N errors)", async () => {
73
+ const stdout = [
74
+ "type_check.ts(5,7): error TS2322: Type 'number' is not assignable to type 'string'.",
75
+ "",
76
+ "Found 1 error in type_check.ts:5",
77
+ ].join("\n");
78
+ const result = await parser.parse(makeCtx(stdout));
79
+ expect(result.failures).toHaveLength(1);
80
+ });
81
+ });
@@ -0,0 +1,47 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ // tsc --pretty false format: file(line,col): error TSXXXX: message
6
+ const TSC_LINE = /^(.+?)\((\d+),(\d+)\):\s+error\s+(TS\d+):\s+(.+)$/;
7
+
8
+ const parser: ParserModule = {
9
+ id: "tsc-text",
10
+ async parse(ctx) {
11
+ const raw = safeReadFile(ctx.stdoutPath).trim();
12
+ if (!raw) {
13
+ return {
14
+ tool: "tsc",
15
+ status: "pass",
16
+ summary: "no type errors",
17
+ failures: [],
18
+ logPath: ctx.logPath,
19
+ };
20
+ }
21
+
22
+ const failures: ParsedFailure[] = [];
23
+ for (const line of raw.split("\n")) {
24
+ const m = line.match(TSC_LINE);
25
+ if (!m) continue;
26
+ const [, file, lineNum, , code, message] = m;
27
+ const relPath = path.isAbsolute(file) ? path.relative(ctx.cwd, file) : file;
28
+ failures.push({
29
+ id: `${relPath}:${lineNum}:${code}`,
30
+ file: relPath,
31
+ line: Number(lineNum),
32
+ message,
33
+ rule: code,
34
+ });
35
+ }
36
+
37
+ return {
38
+ tool: "tsc",
39
+ status: failures.length > 0 ? "fail" : "pass",
40
+ summary: failures.length > 0 ? `${failures.length} type errors` : "no type errors",
41
+ failures,
42
+ logPath: ctx.logPath,
43
+ };
44
+ },
45
+ };
46
+
47
+ export default parser;