@robhowley/pi-structured-return 1.5.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 (34) hide show
  1. package/README.md +34 -4
  2. package/extensions/structured-return/src/config/registry.ts +92 -0
  3. package/extensions/structured-return/src/parsers/bandit-json.test.ts +90 -0
  4. package/extensions/structured-return/src/parsers/bandit-json.ts +78 -0
  5. package/extensions/structured-return/src/parsers/black-text.test.ts +67 -0
  6. package/extensions/structured-return/src/parsers/black-text.ts +74 -0
  7. package/extensions/structured-return/src/parsers/clang-text.test.ts +61 -0
  8. package/extensions/structured-return/src/parsers/clang-text.ts +59 -0
  9. package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +85 -0
  10. package/extensions/structured-return/src/parsers/dotnet-build-text.ts +48 -0
  11. package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +72 -0
  12. package/extensions/structured-return/src/parsers/htmlhint-json.ts +72 -0
  13. package/extensions/structured-return/src/parsers/isort-text.test.ts +58 -0
  14. package/extensions/structured-return/src/parsers/isort-text.ts +64 -0
  15. package/extensions/structured-return/src/parsers/javac-text.test.ts +75 -0
  16. package/extensions/structured-return/src/parsers/javac-text.ts +81 -0
  17. package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +52 -0
  18. package/extensions/structured-return/src/parsers/jsonlint-text.ts +64 -0
  19. package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +76 -0
  20. package/extensions/structured-return/src/parsers/markdownlint-json.ts +73 -0
  21. package/extensions/structured-return/src/parsers/node-test-text.test.ts +117 -0
  22. package/extensions/structured-return/src/parsers/node-test-text.ts +90 -0
  23. package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +83 -0
  24. package/extensions/structured-return/src/parsers/npm-audit-json.ts +88 -0
  25. package/extensions/structured-return/src/parsers/prettier-text.test.ts +76 -0
  26. package/extensions/structured-return/src/parsers/prettier-text.ts +63 -0
  27. package/extensions/structured-return/src/parsers/pyright-json.test.ts +112 -0
  28. package/extensions/structured-return/src/parsers/pyright-json.ts +81 -0
  29. package/extensions/structured-return/src/parsers/tidy-text.test.ts +74 -0
  30. package/extensions/structured-return/src/parsers/tidy-text.ts +67 -0
  31. package/extensions/structured-return/src/parsers/vale-json.test.ts +84 -0
  32. package/extensions/structured-return/src/parsers/vale-json.ts +80 -0
  33. package/package.json +1 -1
  34. package/skills/structured-return/SKILL.md +58 -6
@@ -0,0 +1,85 @@
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 "./dotnet-build-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(), "dotnet-build-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ const stderrPath = path.join(dir, "stderr");
12
+ fs.writeFileSync(stdoutPath, stdout);
13
+ fs.writeFileSync(stderrPath, "");
14
+ return {
15
+ command: "dotnet build",
16
+ argv: ["dotnet", "build"],
17
+ cwd,
18
+ artifactPaths: [],
19
+ stdoutPath,
20
+ stderrPath,
21
+ logPath: path.join(dir, "log"),
22
+ };
23
+ }
24
+
25
+ describe("dotnet-build-text parser", () => {
26
+ it("duplicated errors → deduplicated, relative paths, rule code extracted", async () => {
27
+ const cwd = "/project";
28
+ const stdout = ` Determining projects to restore...
29
+ All projects are up-to-date for restore.
30
+ /project/src/App.cs(7,25): error CS0029: Cannot implicitly convert type 'int' to 'string' [/project/src/App.csproj]
31
+ /project/src/App.cs(8,16): error CS0029: Cannot implicitly convert type 'string' to 'int' [/project/src/App.csproj]
32
+
33
+ Build FAILED.
34
+
35
+ /project/src/App.cs(7,25): error CS0029: Cannot implicitly convert type 'int' to 'string' [/project/src/App.csproj]
36
+ /project/src/App.cs(8,16): error CS0029: Cannot implicitly convert type 'string' to 'int' [/project/src/App.csproj]
37
+ 0 Warning(s)
38
+ 2 Error(s)
39
+
40
+ Time Elapsed 00:00:01.58`;
41
+ const result = await parser.parse(makeCtx(stdout, cwd));
42
+ expect(result.status).toBe("fail");
43
+ expect(result.summary).toBe("2 errors");
44
+ expect(result.failures).toHaveLength(2); // deduplicated from 4 lines
45
+ expect(result.failures![0].file).toBe("src/App.cs");
46
+ expect(result.failures![0].line).toBe(7);
47
+ expect(result.failures![0].rule).toBe("CS0029");
48
+ });
49
+
50
+ it("no errors → status pass", async () => {
51
+ const stdout = ` Determining projects to restore...
52
+ All projects are up-to-date for restore.
53
+ App -> /project/bin/Debug/net10.0/App.dll
54
+
55
+ Build succeeded.
56
+ 0 Warning(s)
57
+ 0 Error(s)
58
+
59
+ Time Elapsed 00:00:01.00`;
60
+ const result = await parser.parse(makeCtx(stdout));
61
+ expect(result.status).toBe("pass");
62
+ expect(result.summary).toBe("build succeeded");
63
+ expect(result.failures).toHaveLength(0);
64
+ });
65
+
66
+ it("empty stdout → no crash, status pass", async () => {
67
+ const result = await parser.parse(makeCtx(""));
68
+ expect(result.status).toBe("pass");
69
+ expect(result.failures).toHaveLength(0);
70
+ });
71
+
72
+ it("single error → singular 'error' in summary", async () => {
73
+ const stdout = `/project/a.cs(1,1): error CS0246: The type or namespace name 'Foo' could not be found [/project/a.csproj]
74
+
75
+ Build FAILED.
76
+
77
+ /project/a.cs(1,1): error CS0246: The type or namespace name 'Foo' could not be found [/project/a.csproj]
78
+ 0 Warning(s)
79
+ 1 Error(s)`;
80
+ const result = await parser.parse(makeCtx(stdout));
81
+ expect(result.status).toBe("fail");
82
+ expect(result.summary).toBe("1 error");
83
+ expect(result.failures).toHaveLength(1);
84
+ });
85
+ });
@@ -0,0 +1,48 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ // MSBuild error format: file(line,col): error CODE: message [project]
6
+ const ERROR_LINE = /^(.+?)\((\d+),\d+\): error (\w+): (.+?)(?:\s+\[.+\])?$/;
7
+
8
+ const parser: ParserModule = {
9
+ id: "dotnet-build-text",
10
+ async parse(ctx) {
11
+ const combined = safeReadFile(ctx.stdoutPath) + safeReadFile(ctx.stderrPath);
12
+ const lines = combined.split("\n");
13
+
14
+ // Deduplicate — MSBuild prints errors twice (inline + summary)
15
+ const seen = new Set<string>();
16
+ const failures: ParsedFailure[] = [];
17
+
18
+ for (const line of lines) {
19
+ const match = line.trim().match(ERROR_LINE);
20
+ if (!match) continue;
21
+ const [, filePath, lineNum, code, message] = match;
22
+ const relPath = path.relative(ctx.cwd, filePath);
23
+ const key = `${relPath}:${lineNum}:${code}`;
24
+ if (seen.has(key)) continue;
25
+ seen.add(key);
26
+ failures.push({
27
+ id: key,
28
+ file: relPath,
29
+ line: parseInt(lineNum, 10),
30
+ message,
31
+ rule: code,
32
+ });
33
+ }
34
+
35
+ const summary =
36
+ failures.length > 0 ? `${failures.length} error${failures.length !== 1 ? "s" : ""}` : "build succeeded";
37
+
38
+ return {
39
+ tool: "dotnet build",
40
+ status: failures.length > 0 ? "fail" : "pass",
41
+ summary,
42
+ failures,
43
+ logPath: ctx.logPath,
44
+ };
45
+ },
46
+ };
47
+
48
+ export default parser;
@@ -0,0 +1,72 @@
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 "./htmlhint-json";
6
+ import type { RunContext } from "../types";
7
+
8
+ function makeCtx(stderr: string, cwd = "/project"): RunContext {
9
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "htmlhint-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ const stderrPath = path.join(dir, "stderr");
12
+ fs.writeFileSync(stdoutPath, "");
13
+ fs.writeFileSync(stderrPath, stderr);
14
+ return {
15
+ command: "npx htmlhint --format json .",
16
+ argv: ["npx", "htmlhint", "--format", "json", "."],
17
+ cwd,
18
+ artifactPaths: [],
19
+ stdoutPath,
20
+ stderrPath,
21
+ logPath: path.join(dir, "log"),
22
+ };
23
+ }
24
+
25
+ describe("htmlhint-json parser", () => {
26
+ it("multiple errors → correct relative paths, rule IDs, messages", async () => {
27
+ const cwd = "/project";
28
+ const stderr = JSON.stringify([
29
+ {
30
+ file: "/project/src/index.html",
31
+ messages: [
32
+ {
33
+ type: "error",
34
+ message: "Doctype must be declared before any non-comment content.",
35
+ line: 1,
36
+ col: 1,
37
+ rule: { id: "doctype-first", description: "...", link: "https://example.com" },
38
+ },
39
+ {
40
+ type: "error",
41
+ message: "The html element name of [ DIV ] must be in lowercase.",
42
+ line: 5,
43
+ col: 1,
44
+ rule: { id: "tagname-lowercase", description: "...", link: "https://example.com" },
45
+ },
46
+ ],
47
+ time: 1,
48
+ },
49
+ ]);
50
+ const result = await parser.parse(makeCtx(stderr, cwd));
51
+ expect(result.status).toBe("fail");
52
+ expect(result.summary).toBe("2 lint errors");
53
+ expect(result.failures).toHaveLength(2);
54
+ expect(result.failures![0].file).toBe("src/index.html");
55
+ expect(result.failures![0].rule).toBe("doctype-first");
56
+ expect(result.failures![1].line).toBe(5);
57
+ // No URLs in output
58
+ expect(result.failures![0].message).not.toContain("https://");
59
+ });
60
+
61
+ it("no errors → status pass", async () => {
62
+ const result = await parser.parse(makeCtx(JSON.stringify([])));
63
+ expect(result.status).toBe("pass");
64
+ expect(result.failures).toHaveLength(0);
65
+ });
66
+
67
+ it("empty output → no crash, status pass", async () => {
68
+ const result = await parser.parse(makeCtx(""));
69
+ expect(result.status).toBe("pass");
70
+ expect(result.failures).toHaveLength(0);
71
+ });
72
+ });
@@ -0,0 +1,72 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ interface HtmlHintMessage {
6
+ type: string;
7
+ message: string;
8
+ line: number;
9
+ col: number;
10
+ rule: { id: string };
11
+ }
12
+
13
+ interface HtmlHintFile {
14
+ file: string;
15
+ messages: HtmlHintMessage[];
16
+ }
17
+
18
+ const parser: ParserModule = {
19
+ id: "htmlhint-json",
20
+ async parse(ctx) {
21
+ // htmlhint --format json writes JSON to stderr (not stdout), so read stderr first.
22
+ const output = (safeReadFile(ctx.stderrPath) + safeReadFile(ctx.stdoutPath)).trim();
23
+ if (!output) {
24
+ return {
25
+ tool: "htmlhint",
26
+ status: "pass",
27
+ summary: "no lint errors",
28
+ failures: [],
29
+ logPath: ctx.logPath,
30
+ };
31
+ }
32
+
33
+ let files: HtmlHintFile[];
34
+ try {
35
+ files = JSON.parse(output);
36
+ } catch {
37
+ return {
38
+ tool: "htmlhint",
39
+ status: "error",
40
+ summary: "failed to parse htmlhint JSON output",
41
+ logPath: ctx.logPath,
42
+ };
43
+ }
44
+
45
+ const failures: ParsedFailure[] = [];
46
+ for (const file of files) {
47
+ const relPath = path.relative(ctx.cwd, file.file);
48
+ for (const msg of file.messages) {
49
+ failures.push({
50
+ id: `${relPath}:${msg.line}:${msg.rule.id}`,
51
+ file: relPath,
52
+ line: msg.line,
53
+ message: msg.message,
54
+ rule: msg.rule.id,
55
+ });
56
+ }
57
+ }
58
+
59
+ const summary =
60
+ failures.length > 0 ? `${failures.length} lint error${failures.length !== 1 ? "s" : ""}` : "no lint errors";
61
+
62
+ return {
63
+ tool: "htmlhint",
64
+ status: failures.length > 0 ? "fail" : "pass",
65
+ summary,
66
+ failures,
67
+ logPath: ctx.logPath,
68
+ };
69
+ },
70
+ };
71
+
72
+ export default parser;
@@ -0,0 +1,58 @@
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 "./isort-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(), "isort-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ const stderrPath = path.join(dir, "stderr");
12
+ fs.writeFileSync(stdoutPath, "");
13
+ fs.writeFileSync(stderrPath, stderr);
14
+ return {
15
+ command: "isort --check --diff .",
16
+ argv: ["isort", "--check", "--diff", "."],
17
+ cwd,
18
+ artifactPaths: [],
19
+ stdoutPath,
20
+ stderrPath,
21
+ logPath: path.join(dir, "log"),
22
+ };
23
+ }
24
+
25
+ describe("isort-text parser", () => {
26
+ it("unsorted imports with diff → strips diff, extracts file, status fail", async () => {
27
+ const cwd = "/project";
28
+ const stderr = `ERROR: /project/src/app.py Imports are incorrectly sorted and/or formatted.
29
+ --- /project/src/app.py:before\t2026-03-19 18:00:00
30
+ +++ /project/src/app.py:after\t2026-03-19 18:00:00
31
+ @@ -1,3 +1,3 @@
32
+ +import json
33
+ import os
34
+ -import json
35
+ ERROR: /project/src/utils.py Imports are incorrectly sorted and/or formatted.`;
36
+ const result = await parser.parse(makeCtx(stderr, cwd));
37
+ expect(result.status).toBe("fail");
38
+ expect(result.summary).toBe("2 files have incorrectly sorted imports");
39
+ expect(result.failures).toHaveLength(2);
40
+ expect(result.failures![0].file).toBe("src/app.py");
41
+ expect(result.failures![1].file).toBe("src/utils.py");
42
+ // No diff content in failures
43
+ expect(result.failures![0].message).not.toContain("---");
44
+ });
45
+
46
+ it("all sorted → status pass", async () => {
47
+ const result = await parser.parse(makeCtx(""));
48
+ expect(result.status).toBe("pass");
49
+ expect(result.summary).toBe("all imports sorted");
50
+ expect(result.failures).toHaveLength(0);
51
+ });
52
+
53
+ it("single file → singular grammar", async () => {
54
+ const stderr = `ERROR: /project/bad.py Imports are incorrectly sorted and/or formatted.`;
55
+ const result = await parser.parse(makeCtx(stderr));
56
+ expect(result.summary).toBe("1 file has incorrectly sorted imports");
57
+ });
58
+ });
@@ -0,0 +1,64 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ // ERROR: /path/to/file.py Imports are incorrectly sorted and/or formatted.
6
+ const ERROR_LINE = /^ERROR: (.+?) Imports are incorrectly sorted/;
7
+ const parser: ParserModule = {
8
+ id: "isort-text",
9
+ async parse(ctx) {
10
+ const combined = (safeReadFile(ctx.stdoutPath) + "\n" + safeReadFile(ctx.stderrPath)).trim();
11
+ if (!combined) {
12
+ return {
13
+ tool: "isort",
14
+ status: "pass",
15
+ summary: "all imports sorted",
16
+ failures: [],
17
+ logPath: ctx.logPath,
18
+ };
19
+ }
20
+
21
+ const lines = combined.split("\n");
22
+ const failures: ParsedFailure[] = [];
23
+
24
+ for (const line of lines) {
25
+ const errorMatch = line.match(ERROR_LINE);
26
+ if (errorMatch) {
27
+ const relPath = path.relative(ctx.cwd, errorMatch[1]);
28
+ failures.push({
29
+ id: relPath,
30
+ file: relPath,
31
+ message: "imports are incorrectly sorted",
32
+ });
33
+ }
34
+ }
35
+
36
+ if (failures.length === 0 && !combined.includes("ERROR")) {
37
+ return {
38
+ tool: "isort",
39
+ status: "pass",
40
+ summary: "all imports sorted",
41
+ failures: [],
42
+ logPath: ctx.logPath,
43
+ };
44
+ }
45
+
46
+ const n = failures.length;
47
+ const summary =
48
+ n === 0
49
+ ? "all imports sorted"
50
+ : n === 1
51
+ ? "1 file has incorrectly sorted imports"
52
+ : `${n} files have incorrectly sorted imports`;
53
+
54
+ return {
55
+ tool: "isort",
56
+ status: n > 0 ? "fail" : "pass",
57
+ summary,
58
+ failures,
59
+ logPath: ctx.logPath,
60
+ };
61
+ },
62
+ };
63
+
64
+ export default parser;
@@ -0,0 +1,75 @@
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 "./javac-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(), "javac-test-"));
10
+ const stderrPath = path.join(dir, "stderr");
11
+ fs.writeFileSync(stderrPath, stderr);
12
+ return {
13
+ command: "javac src/TypeCheck.java",
14
+ argv: ["javac", "src/TypeCheck.java"],
15
+ cwd,
16
+ artifactPaths: [],
17
+ stdoutPath: path.join(dir, "stdout"),
18
+ stderrPath,
19
+ logPath: path.join(dir, "log"),
20
+ };
21
+ }
22
+
23
+ describe("javac-text parser", () => {
24
+ it("type error with source snippet → strips snippet and caret, extracts file:line and message", async () => {
25
+ const stderr = `/project/src/TypeCheck.java:3: error: incompatible types: String cannot be converted to int
26
+ int x = "hello";
27
+ ^
28
+ 1 error`;
29
+ const result = await parser.parse(makeCtx(stderr));
30
+ expect(result.status).toBe("fail");
31
+ expect(result.summary).toBe("1 error");
32
+ expect(result.failures).toHaveLength(1);
33
+ expect(result.failures![0].file).toBe("src/TypeCheck.java");
34
+ expect(result.failures![0].line).toBe(3);
35
+ expect(result.failures![0].message).toBe("incompatible types: String cannot be converted to int");
36
+ });
37
+
38
+ it("cannot find symbol → folds symbol continuation into message", async () => {
39
+ const stderr = `/project/src/App.java:4: error: cannot find symbol
40
+ String y = unknownMethod();
41
+ ^
42
+ symbol: method unknownMethod()
43
+ location: class App
44
+ 1 error`;
45
+ const result = await parser.parse(makeCtx(stderr));
46
+ expect(result.status).toBe("fail");
47
+ expect(result.failures).toHaveLength(1);
48
+ expect(result.failures![0].message).toBe("cannot find symbol: method unknownMethod()");
49
+ expect(result.failures![0].message).not.toContain("location");
50
+ });
51
+
52
+ it("multiple errors → correct count and relative paths", async () => {
53
+ const stderr = `/project/src/A.java:3: error: incompatible types: String cannot be converted to int
54
+ int x = "hello";
55
+ ^
56
+ /project/src/B.java:10: error: cannot find symbol
57
+ foo();
58
+ ^
59
+ symbol: method foo()
60
+ location: class B
61
+ 2 errors`;
62
+ const result = await parser.parse(makeCtx(stderr));
63
+ expect(result.status).toBe("fail");
64
+ expect(result.summary).toBe("2 errors");
65
+ expect(result.failures).toHaveLength(2);
66
+ expect(result.failures![0].file).toBe("src/A.java");
67
+ expect(result.failures![1].file).toBe("src/B.java");
68
+ });
69
+
70
+ it("empty stderr → no crash, status pass", async () => {
71
+ const result = await parser.parse(makeCtx(""));
72
+ expect(result.status).toBe("pass");
73
+ expect(result.failures).toHaveLength(0);
74
+ });
75
+ });
@@ -0,0 +1,81 @@
1
+ import path from "node:path";
2
+ import type { ParserModule, ParsedFailure } from "../types";
3
+ import { safeReadFile } from "./utils";
4
+
5
+ const ERROR_LINE = /^(.+?):(\d+): error: (.+)$/;
6
+ const SYMBOL_LINE = /^\s+symbol:\s+(.+)$/;
7
+ const SUMMARY_LINE = /^(\d+) errors?$/;
8
+ const CARET_LINE = /^\s+\^/;
9
+ const SOURCE_SNIPPET = /^\s{8,}\S/;
10
+
11
+ const parser: ParserModule = {
12
+ id: "javac-text",
13
+ async parse(ctx) {
14
+ const stderr = safeReadFile(ctx.stderrPath).trim();
15
+ if (!stderr) {
16
+ return {
17
+ tool: "javac",
18
+ status: "pass",
19
+ summary: "compilation successful",
20
+ failures: [],
21
+ logPath: ctx.logPath,
22
+ };
23
+ }
24
+
25
+ const lines = stderr.split("\n");
26
+ const failures: ParsedFailure[] = [];
27
+ let summaryLine = "";
28
+
29
+ for (let i = 0; i < lines.length; i++) {
30
+ const errorMatch = lines[i].match(ERROR_LINE);
31
+ if (errorMatch) {
32
+ const [, filePath, lineNum, message] = errorMatch;
33
+ const relPath = path.relative(ctx.cwd, filePath);
34
+ let fullMessage = message;
35
+
36
+ // Look ahead past source snippet and caret for symbol/location continuation lines
37
+ for (let j = i + 1; j < lines.length; j++) {
38
+ const symbolMatch = lines[j].match(SYMBOL_LINE);
39
+ if (symbolMatch) {
40
+ fullMessage += `: ${symbolMatch[1]}`;
41
+ } else if (/^\s+location:/.test(lines[j])) {
42
+ // Skip location lines — they repeat the class name which is in the file path
43
+ continue;
44
+ } else if (CARET_LINE.test(lines[j]) || SOURCE_SNIPPET.test(lines[j])) {
45
+ // Caret indicator or deeply-indented source snippet — skip
46
+ continue;
47
+ } else {
48
+ break;
49
+ }
50
+ }
51
+
52
+ failures.push({
53
+ id: `${relPath}:${lineNum}`,
54
+ file: relPath,
55
+ line: parseInt(lineNum, 10),
56
+ message: fullMessage,
57
+ });
58
+ continue;
59
+ }
60
+
61
+ const sumMatch = lines[i].match(SUMMARY_LINE);
62
+ if (sumMatch) {
63
+ summaryLine = lines[i];
64
+ }
65
+ }
66
+
67
+ const summary =
68
+ summaryLine ||
69
+ (failures.length > 0 ? `${failures.length} error${failures.length !== 1 ? "s" : ""}` : "compilation successful");
70
+
71
+ return {
72
+ tool: "javac",
73
+ status: failures.length > 0 ? "fail" : "pass",
74
+ summary,
75
+ failures,
76
+ logPath: ctx.logPath,
77
+ };
78
+ },
79
+ };
80
+
81
+ export default parser;
@@ -0,0 +1,52 @@
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 "./jsonlint-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(), "jsonlint-test-"));
10
+ const stdoutPath = path.join(dir, "stdout");
11
+ const stderrPath = path.join(dir, "stderr");
12
+ fs.writeFileSync(stdoutPath, "");
13
+ fs.writeFileSync(stderrPath, stderr);
14
+ return {
15
+ command: "npx jsonlint src/config.json",
16
+ argv: ["npx", "jsonlint", "src/config.json"],
17
+ cwd,
18
+ artifactPaths: [],
19
+ stdoutPath,
20
+ stderrPath,
21
+ logPath: path.join(dir, "log"),
22
+ };
23
+ }
24
+
25
+ describe("jsonlint-text parser", () => {
26
+ it("parse error with stack trace → strips stack, extracts line and expecting message", async () => {
27
+ const stderr = `Error: Parse error on line 1:
28
+ {"name": "test", missing: "quotes", }
29
+ -----------------^
30
+ Expecting 'STRING', got 'undefined'
31
+ at Object.parseError (jsonlint/lib/jsonlint.js:55:11)
32
+ at Object.parse (jsonlint/lib/jsonlint.js:132:22)
33
+ at parse (jsonlint/lib/cli.js:82:14)
34
+ at main (jsonlint/lib/cli.js:135:14)`;
35
+ const result = await parser.parse(makeCtx(stderr));
36
+ expect(result.status).toBe("fail");
37
+ expect(result.summary).toBe("parse error");
38
+ expect(result.failures).toHaveLength(1);
39
+ expect(result.failures![0].file).toBe("src/config.json");
40
+ expect(result.failures![0].line).toBe(1);
41
+ expect(result.failures![0].message).toBe("Expecting 'STRING', got 'undefined'");
42
+ // No stack trace
43
+ expect(result.failures![0].message).not.toContain("at Object");
44
+ });
45
+
46
+ it("valid JSON → status pass", async () => {
47
+ const result = await parser.parse(makeCtx(""));
48
+ expect(result.status).toBe("pass");
49
+ expect(result.summary).toBe("valid JSON");
50
+ expect(result.failures).toHaveLength(0);
51
+ });
52
+ });
@@ -0,0 +1,64 @@
1
+ import type { ParserModule, ParsedFailure } from "../types";
2
+ import { safeReadFile } from "./utils";
3
+
4
+ // Error: Parse error on line N:
5
+ const ERROR_HEADER = /^Error: Parse error on line (\d+):$/;
6
+ // Expecting 'X', got 'Y'
7
+ const EXPECTING_LINE = /^(Expecting .+)$/;
8
+
9
+ const parser: ParserModule = {
10
+ id: "jsonlint-text",
11
+ async parse(ctx) {
12
+ const combined = (safeReadFile(ctx.stdoutPath) + "\n" + safeReadFile(ctx.stderrPath)).trim();
13
+ if (!combined) {
14
+ return {
15
+ tool: "jsonlint",
16
+ status: "pass",
17
+ summary: "valid JSON",
18
+ failures: [],
19
+ logPath: ctx.logPath,
20
+ };
21
+ }
22
+
23
+ // Derive filename from argv — use last non-flag arg since earlier positional
24
+ // args may be flag values (e.g. npx --yes jsonlint file.json).
25
+ const file = ctx.argv.filter((a) => !a.startsWith("-") && a !== "jsonlint" && a !== "npx").pop() ?? "input";
26
+
27
+ const lines = combined.split("\n");
28
+ const failures: ParsedFailure[] = [];
29
+ let line: number | undefined;
30
+ let message = "";
31
+
32
+ for (const l of lines) {
33
+ const headerMatch = l.match(ERROR_HEADER);
34
+ if (headerMatch) {
35
+ line = parseInt(headerMatch[1], 10);
36
+ continue;
37
+ }
38
+ const expectMatch = l.match(EXPECTING_LINE);
39
+ if (expectMatch) {
40
+ message = expectMatch[1];
41
+ continue;
42
+ }
43
+ }
44
+
45
+ if (line !== undefined) {
46
+ failures.push({
47
+ id: `${file}:${line}`,
48
+ file,
49
+ line,
50
+ message: message || "parse error",
51
+ });
52
+ }
53
+
54
+ return {
55
+ tool: "jsonlint",
56
+ status: failures.length > 0 ? "fail" : "pass",
57
+ summary: failures.length > 0 ? "parse error" : "valid JSON",
58
+ failures,
59
+ logPath: ctx.logPath,
60
+ };
61
+ },
62
+ };
63
+
64
+ export default parser;