@robhowley/pi-structured-return 1.5.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -63
- package/extensions/structured-return/src/config/registry.ts +92 -0
- package/extensions/structured-return/src/parsers/bandit-json.test.ts +90 -0
- package/extensions/structured-return/src/parsers/bandit-json.ts +78 -0
- package/extensions/structured-return/src/parsers/black-text.test.ts +67 -0
- package/extensions/structured-return/src/parsers/black-text.ts +74 -0
- package/extensions/structured-return/src/parsers/clang-text.test.ts +61 -0
- package/extensions/structured-return/src/parsers/clang-text.ts +59 -0
- package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +85 -0
- package/extensions/structured-return/src/parsers/dotnet-build-text.ts +48 -0
- package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +72 -0
- package/extensions/structured-return/src/parsers/htmlhint-json.ts +72 -0
- package/extensions/structured-return/src/parsers/isort-text.test.ts +58 -0
- package/extensions/structured-return/src/parsers/isort-text.ts +64 -0
- package/extensions/structured-return/src/parsers/javac-text.test.ts +75 -0
- package/extensions/structured-return/src/parsers/javac-text.ts +81 -0
- package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +52 -0
- package/extensions/structured-return/src/parsers/jsonlint-text.ts +64 -0
- package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +76 -0
- package/extensions/structured-return/src/parsers/markdownlint-json.ts +73 -0
- package/extensions/structured-return/src/parsers/node-test-text.test.ts +117 -0
- package/extensions/structured-return/src/parsers/node-test-text.ts +90 -0
- package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +83 -0
- package/extensions/structured-return/src/parsers/npm-audit-json.ts +88 -0
- package/extensions/structured-return/src/parsers/prettier-text.test.ts +76 -0
- package/extensions/structured-return/src/parsers/prettier-text.ts +63 -0
- package/extensions/structured-return/src/parsers/pyright-json.test.ts +112 -0
- package/extensions/structured-return/src/parsers/pyright-json.ts +81 -0
- package/extensions/structured-return/src/parsers/tidy-text.test.ts +74 -0
- package/extensions/structured-return/src/parsers/tidy-text.ts +67 -0
- package/extensions/structured-return/src/parsers/vale-json.test.ts +84 -0
- package/extensions/structured-return/src/parsers/vale-json.ts +80 -0
- package/package.json +8 -3
- package/skills/structured-return/SKILL.md +58 -6
|
@@ -0,0 +1,76 @@
|
|
|
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 "./prettier-text";
|
|
6
|
+
import type { RunContext } from "../types";
|
|
7
|
+
|
|
8
|
+
function makeCtx(stdout: string, stderr = "", cwd = "/project"): RunContext {
|
|
9
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "prettier-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
const stderrPath = path.join(dir, "stderr");
|
|
12
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
13
|
+
fs.writeFileSync(stderrPath, stderr);
|
|
14
|
+
return {
|
|
15
|
+
command: "prettier --check .",
|
|
16
|
+
argv: ["prettier", "--check", "."],
|
|
17
|
+
cwd,
|
|
18
|
+
artifactPaths: [],
|
|
19
|
+
stdoutPath,
|
|
20
|
+
stderrPath,
|
|
21
|
+
logPath: path.join(dir, "log"),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("prettier-text parser", () => {
|
|
26
|
+
it("files needing formatting → strips preamble/footer, lists files", async () => {
|
|
27
|
+
const cwd = "/project";
|
|
28
|
+
const stdout = `Checking formatting...
|
|
29
|
+
[warn] /project/src/app.ts
|
|
30
|
+
[warn] /project/src/utils.ts
|
|
31
|
+
[warn] Code style issues found in 2 files. Run Prettier with --write to fix.`;
|
|
32
|
+
const result = await parser.parse(makeCtx(stdout, "", cwd));
|
|
33
|
+
expect(result.status).toBe("fail");
|
|
34
|
+
expect(result.summary).toBe("2 files have formatting issues");
|
|
35
|
+
expect(result.failures).toHaveLength(2);
|
|
36
|
+
expect(result.failures![0].file).toBe("src/app.ts");
|
|
37
|
+
expect(result.failures![1].file).toBe("src/utils.ts");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("all formatted → status pass", async () => {
|
|
41
|
+
const stdout = `Checking formatting...
|
|
42
|
+
All matched files use Prettier code style!`;
|
|
43
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
44
|
+
expect(result.status).toBe("pass");
|
|
45
|
+
expect(result.summary).toBe("all files formatted");
|
|
46
|
+
expect(result.failures).toHaveLength(0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("single file → singular grammar", async () => {
|
|
50
|
+
const stdout = `Checking formatting...
|
|
51
|
+
[warn] /project/bad.ts
|
|
52
|
+
[warn] Code style issues found in the above file. Run Prettier with --write to fix.`;
|
|
53
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
54
|
+
expect(result.status).toBe("fail");
|
|
55
|
+
expect(result.summary).toBe("1 file has formatting issues");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("extensionless files (Dockerfile, Makefile) → not dropped", async () => {
|
|
59
|
+
const cwd = "/project";
|
|
60
|
+
const stdout = `Checking formatting...
|
|
61
|
+
[warn] /project/Dockerfile
|
|
62
|
+
[warn] /project/src/app.ts
|
|
63
|
+
[warn] Code style issues found in 2 files. Run Prettier with --write to fix.`;
|
|
64
|
+
const result = await parser.parse(makeCtx(stdout, "", cwd));
|
|
65
|
+
expect(result.status).toBe("fail");
|
|
66
|
+
expect(result.failures).toHaveLength(2);
|
|
67
|
+
expect(result.failures![0].file).toBe("Dockerfile");
|
|
68
|
+
expect(result.failures![1].file).toBe("src/app.ts");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("empty output → no crash, status pass", async () => {
|
|
72
|
+
const result = await parser.parse(makeCtx(""));
|
|
73
|
+
expect(result.status).toBe("pass");
|
|
74
|
+
expect(result.failures).toHaveLength(0);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
// [warn] /path/to/file — but not summary lines like "[warn] Code style issues..."
|
|
6
|
+
const WARN_LINE = /^\[warn\] (.+)$/;
|
|
7
|
+
const SUMMARY_PREFIX = /^Code style issues|^Run Prettier/;
|
|
8
|
+
|
|
9
|
+
const parser: ParserModule = {
|
|
10
|
+
id: "prettier-text",
|
|
11
|
+
async parse(ctx) {
|
|
12
|
+
const combined = (safeReadFile(ctx.stdoutPath) + "\n" + safeReadFile(ctx.stderrPath)).trim();
|
|
13
|
+
if (!combined) {
|
|
14
|
+
return {
|
|
15
|
+
tool: "prettier",
|
|
16
|
+
status: "pass",
|
|
17
|
+
summary: "all files formatted",
|
|
18
|
+
failures: [],
|
|
19
|
+
logPath: ctx.logPath,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const lines = combined.split("\n");
|
|
24
|
+
const failures: ParsedFailure[] = [];
|
|
25
|
+
|
|
26
|
+
for (const line of lines) {
|
|
27
|
+
const warnMatch = line.match(WARN_LINE);
|
|
28
|
+
if (warnMatch && !SUMMARY_PREFIX.test(warnMatch[1])) {
|
|
29
|
+
const relPath = path.relative(ctx.cwd, warnMatch[1]);
|
|
30
|
+
failures.push({
|
|
31
|
+
id: relPath,
|
|
32
|
+
file: relPath,
|
|
33
|
+
message: "needs formatting",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// All done, no warnings
|
|
39
|
+
if (failures.length === 0 && combined.includes("All matched files use Prettier code style")) {
|
|
40
|
+
return {
|
|
41
|
+
tool: "prettier",
|
|
42
|
+
status: "pass",
|
|
43
|
+
summary: "all files formatted",
|
|
44
|
+
failures: [],
|
|
45
|
+
logPath: ctx.logPath,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const n = failures.length;
|
|
50
|
+
const summary =
|
|
51
|
+
n > 0 ? (n === 1 ? "1 file has formatting issues" : `${n} files have formatting issues`) : "all files formatted";
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
tool: "prettier",
|
|
55
|
+
status: n > 0 ? "fail" : "pass",
|
|
56
|
+
summary,
|
|
57
|
+
failures,
|
|
58
|
+
logPath: ctx.logPath,
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default parser;
|
|
@@ -0,0 +1,112 @@
|
|
|
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 "./pyright-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(), "pyright-test-"));
|
|
10
|
+
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
+
fs.writeFileSync(stdoutPath, stdout);
|
|
12
|
+
return {
|
|
13
|
+
command: "pyright --outputjson .",
|
|
14
|
+
argv: ["pyright", "--outputjson", "."],
|
|
15
|
+
cwd,
|
|
16
|
+
artifactPaths: [],
|
|
17
|
+
stdoutPath,
|
|
18
|
+
stderrPath: path.join(dir, "stderr"),
|
|
19
|
+
logPath: path.join(dir, "log"),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("pyright-json parser", () => {
|
|
24
|
+
it("single error → correct relative path, 1-based line, rule mapped, status fail", async () => {
|
|
25
|
+
const cwd = "/project";
|
|
26
|
+
const stdout = JSON.stringify({
|
|
27
|
+
version: "1.1.408",
|
|
28
|
+
generalDiagnostics: [
|
|
29
|
+
{
|
|
30
|
+
file: "/project/src/app.py",
|
|
31
|
+
severity: "error",
|
|
32
|
+
message: 'Type "str" is not assignable to declared type "int"\n "str" is not assignable to "int"',
|
|
33
|
+
range: { start: { line: 3, character: 14 }, end: { line: 3, character: 28 } },
|
|
34
|
+
rule: "reportAssignmentType",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
summary: { filesAnalyzed: 1, errorCount: 1, warningCount: 0, informationCount: 0 },
|
|
38
|
+
});
|
|
39
|
+
const result = await parser.parse(makeCtx(stdout, cwd));
|
|
40
|
+
expect(result.status).toBe("fail");
|
|
41
|
+
expect(result.summary).toBe("1 error");
|
|
42
|
+
expect(result.failures).toHaveLength(1);
|
|
43
|
+
expect(result.failures![0].file).toBe("src/app.py");
|
|
44
|
+
expect(result.failures![0].line).toBe(4); // 0-based → 1-based
|
|
45
|
+
expect(result.failures![0].rule).toBe("reportAssignmentType");
|
|
46
|
+
expect(result.failures![0].message).not.toContain("\n");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("multiple errors across files → correct count and paths", async () => {
|
|
50
|
+
const cwd = "/project";
|
|
51
|
+
const stdout = JSON.stringify({
|
|
52
|
+
generalDiagnostics: [
|
|
53
|
+
{
|
|
54
|
+
file: "/project/a.py",
|
|
55
|
+
severity: "error",
|
|
56
|
+
message: 'Cannot access attribute "foo" for class "Bar"',
|
|
57
|
+
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 5 } },
|
|
58
|
+
rule: "reportAttributeAccessIssue",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
file: "/project/b.py",
|
|
62
|
+
severity: "error",
|
|
63
|
+
message: 'Argument missing for parameter "x"',
|
|
64
|
+
range: { start: { line: 9, character: 0 }, end: { line: 9, character: 10 } },
|
|
65
|
+
rule: "reportCallIssue",
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
summary: { filesAnalyzed: 2, errorCount: 2, warningCount: 0, informationCount: 0 },
|
|
69
|
+
});
|
|
70
|
+
const result = await parser.parse(makeCtx(stdout, cwd));
|
|
71
|
+
expect(result.status).toBe("fail");
|
|
72
|
+
expect(result.summary).toBe("2 errors");
|
|
73
|
+
expect(result.failures).toHaveLength(2);
|
|
74
|
+
expect(result.failures![0].file).toBe("a.py");
|
|
75
|
+
expect(result.failures![1].file).toBe("b.py");
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("warnings only (no errors) → status pass, empty failures", async () => {
|
|
79
|
+
const stdout = JSON.stringify({
|
|
80
|
+
generalDiagnostics: [
|
|
81
|
+
{
|
|
82
|
+
file: "/project/c.py",
|
|
83
|
+
severity: "warning",
|
|
84
|
+
message: 'Import "os" is not accessed',
|
|
85
|
+
range: { start: { line: 0, character: 0 }, end: { line: 0, character: 9 } },
|
|
86
|
+
rule: "reportUnusedImport",
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
summary: { filesAnalyzed: 1, errorCount: 0, warningCount: 1, informationCount: 0 },
|
|
90
|
+
});
|
|
91
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
92
|
+
expect(result.status).toBe("pass");
|
|
93
|
+
expect(result.summary).toBe("1 warning");
|
|
94
|
+
expect(result.failures).toHaveLength(0);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("no diagnostics → status pass", async () => {
|
|
98
|
+
const stdout = JSON.stringify({
|
|
99
|
+
generalDiagnostics: [],
|
|
100
|
+
summary: { filesAnalyzed: 1, errorCount: 0, warningCount: 0, informationCount: 0 },
|
|
101
|
+
});
|
|
102
|
+
const result = await parser.parse(makeCtx(stdout));
|
|
103
|
+
expect(result.status).toBe("pass");
|
|
104
|
+
expect(result.failures).toHaveLength(0);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("empty stdout → no crash, status pass", async () => {
|
|
108
|
+
const result = await parser.parse(makeCtx(""));
|
|
109
|
+
expect(result.status).toBe("pass");
|
|
110
|
+
expect(result.failures).toHaveLength(0);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import type { ParserModule, ParsedFailure } from "../types";
|
|
3
|
+
import { safeReadFile } from "./utils";
|
|
4
|
+
|
|
5
|
+
interface PyrightDiagnostic {
|
|
6
|
+
file: string;
|
|
7
|
+
severity: string;
|
|
8
|
+
message: string;
|
|
9
|
+
range?: { start: { line: number; character: number } };
|
|
10
|
+
rule?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface PyrightOutput {
|
|
14
|
+
generalDiagnostics?: PyrightDiagnostic[];
|
|
15
|
+
summary?: {
|
|
16
|
+
errorCount: number;
|
|
17
|
+
warningCount: number;
|
|
18
|
+
informationCount: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const parser: ParserModule = {
|
|
23
|
+
id: "pyright-json",
|
|
24
|
+
async parse(ctx) {
|
|
25
|
+
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
26
|
+
if (!stdout) {
|
|
27
|
+
return {
|
|
28
|
+
tool: "pyright",
|
|
29
|
+
status: "pass",
|
|
30
|
+
summary: "no type errors",
|
|
31
|
+
failures: [],
|
|
32
|
+
logPath: ctx.logPath,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let output: PyrightOutput;
|
|
37
|
+
try {
|
|
38
|
+
output = JSON.parse(stdout);
|
|
39
|
+
} catch {
|
|
40
|
+
return {
|
|
41
|
+
tool: "pyright",
|
|
42
|
+
status: "error",
|
|
43
|
+
summary: "failed to parse pyright JSON output",
|
|
44
|
+
logPath: ctx.logPath,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const diagnostics = (output.generalDiagnostics ?? []).filter((d) => d.severity === "error");
|
|
49
|
+
const failures: ParsedFailure[] = diagnostics.map((d) => {
|
|
50
|
+
const relPath = path.relative(ctx.cwd, d.file);
|
|
51
|
+
// pyright uses 0-based lines in JSON
|
|
52
|
+
const line = d.range ? d.range.start.line + 1 : undefined;
|
|
53
|
+
// Collapse multi-line messages (detail line after \n) into a single line
|
|
54
|
+
const message = d.message.split("\n")[0];
|
|
55
|
+
return {
|
|
56
|
+
id: `${relPath}:${line}:${d.rule ?? "error"}`,
|
|
57
|
+
file: relPath,
|
|
58
|
+
line,
|
|
59
|
+
message,
|
|
60
|
+
rule: d.rule,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const summary = output.summary;
|
|
65
|
+
const parts: string[] = [];
|
|
66
|
+
if (summary) {
|
|
67
|
+
if (summary.errorCount) parts.push(`${summary.errorCount} error${summary.errorCount !== 1 ? "s" : ""}`);
|
|
68
|
+
if (summary.warningCount) parts.push(`${summary.warningCount} warning${summary.warningCount !== 1 ? "s" : ""}`);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
tool: "pyright",
|
|
73
|
+
status: failures.length > 0 ? "fail" : "pass",
|
|
74
|
+
summary: parts.length > 0 ? parts.join(", ") : "no type errors",
|
|
75
|
+
failures,
|
|
76
|
+
logPath: ctx.logPath,
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export default parser;
|
|
@@ -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,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;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robhowley/pi-structured-return",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.6.1",
|
|
4
|
+
"description": "Turn noisy CLI output into compact structured results (fewer tokens), full logs preserved.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -12,7 +12,12 @@
|
|
|
12
12
|
"url": "https://github.com/robhowley/pi-structured-return/issues"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
|
-
"pi-package"
|
|
15
|
+
"pi-package",
|
|
16
|
+
"pi-coding-agent",
|
|
17
|
+
"pi",
|
|
18
|
+
"pi-extension",
|
|
19
|
+
"token-reduction",
|
|
20
|
+
"structured-output"
|
|
16
21
|
],
|
|
17
22
|
"files": [
|
|
18
23
|
"extensions",
|