@robhowley/pi-structured-return 1.9.0 → 1.10.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.
- package/README.md +2 -1
- package/extensions/structured-return/config/project-config.ts +10 -0
- package/extensions/structured-return/config/registry.ts +306 -0
- package/extensions/structured-return/examples/.pi/machine-readable.json +18 -0
- package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +25 -0
- package/extensions/structured-return/{src/index.ts → index.ts} +94 -69
- package/extensions/structured-return/{src/parsers → parsers}/ava-text.ts +23 -15
- package/extensions/structured-return/{src/parsers → parsers}/bandit-json.ts +17 -15
- package/extensions/structured-return/{src/parsers → parsers}/black-text.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/cargo-build.ts +19 -14
- package/extensions/structured-return/{src/parsers → parsers}/cargo-test.ts +20 -19
- package/extensions/structured-return/parsers/checkstyle-xml.ts +183 -0
- package/extensions/structured-return/{src/parsers → parsers}/clang-text.ts +15 -13
- package/extensions/structured-return/{src/parsers → parsers}/dbt-json.ts +28 -23
- package/extensions/structured-return/{src/parsers → parsers}/dotnet-build-text.ts +10 -8
- package/extensions/structured-return/{src/parsers → parsers}/eslint-json.ts +15 -9
- package/extensions/structured-return/{src/parsers → parsers}/go-test-json.ts +23 -21
- package/extensions/structured-return/{src/parsers → parsers}/hadolint-json.ts +18 -12
- package/extensions/structured-return/{src/parsers → parsers}/htmlhint-json.ts +15 -13
- package/extensions/structured-return/{src/parsers → parsers}/isort-text.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/javac-text.ts +14 -12
- package/extensions/structured-return/{src/parsers → parsers}/jsonlint-text.ts +16 -14
- package/extensions/structured-return/{src/parsers → parsers}/junit-xml.ts +61 -43
- package/extensions/structured-return/{src/parsers → parsers}/markdownlint-json.ts +19 -17
- package/extensions/structured-return/{src/parsers → parsers}/minitest-text.ts +24 -15
- package/extensions/structured-return/{src/parsers → parsers}/mocha-json.ts +17 -10
- package/extensions/structured-return/{src/parsers → parsers}/mypy-json.ts +16 -16
- package/extensions/structured-return/{src/parsers → parsers}/node-test-text.ts +17 -14
- package/extensions/structured-return/{src/parsers → parsers}/npm-audit-json.ts +19 -16
- package/extensions/structured-return/{src/parsers → parsers}/prettier-text.ts +21 -17
- package/extensions/structured-return/{src/parsers → parsers}/pylint-json.ts +17 -17
- package/extensions/structured-return/{src/parsers → parsers}/pyright-json.ts +20 -18
- package/extensions/structured-return/{src/parsers → parsers}/rspec-json.ts +14 -14
- package/extensions/structured-return/{src/parsers → parsers}/rubocop-json.ts +22 -11
- package/extensions/structured-return/{src/parsers → parsers}/ruff-json.ts +7 -7
- package/extensions/structured-return/{src/parsers → parsers}/shellcheck-json.ts +14 -14
- package/extensions/structured-return/{src/parsers → parsers}/stylelint-json.ts +21 -13
- package/extensions/structured-return/{src/parsers → parsers}/swiftc-text.ts +16 -10
- package/extensions/structured-return/parsers/tail-fallback.ts +20 -0
- package/extensions/structured-return/{src/parsers → parsers}/tidy-text.ts +13 -13
- package/extensions/structured-return/{src/parsers → parsers}/tsc-text.ts +11 -11
- package/extensions/structured-return/{src/parsers → parsers}/unittest-text.ts +24 -14
- package/extensions/structured-return/{src/parsers → parsers}/utils.ts +9 -6
- package/extensions/structured-return/{src/parsers → parsers}/vale-json.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/vitest-json.ts +14 -14
- package/extensions/structured-return/{src/storage → storage}/log-store.ts +5 -5
- package/extensions/structured-return/{src/storage → storage}/session-stats.ts +11 -11
- package/extensions/structured-return/{src/types.ts → types.ts} +4 -2
- package/package.json +27 -43
- package/skills/structured-return/SKILL.md +7 -0
- package/LICENSE +0 -21
- package/extensions/structured-return/src/config/project-config.ts +0 -10
- package/extensions/structured-return/src/config/registry.test.ts +0 -171
- package/extensions/structured-return/src/config/registry.ts +0 -282
- package/extensions/structured-return/src/index.test.ts +0 -220
- package/extensions/structured-return/src/parsers/ava-text.test.ts +0 -116
- package/extensions/structured-return/src/parsers/bandit-json.test.ts +0 -90
- package/extensions/structured-return/src/parsers/black-text.test.ts +0 -67
- package/extensions/structured-return/src/parsers/cargo-build.test.ts +0 -170
- package/extensions/structured-return/src/parsers/cargo-test.test.ts +0 -191
- package/extensions/structured-return/src/parsers/clang-text.test.ts +0 -61
- package/extensions/structured-return/src/parsers/dbt-json.test.ts +0 -172
- package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +0 -85
- package/extensions/structured-return/src/parsers/eslint-json.test.ts +0 -60
- package/extensions/structured-return/src/parsers/go-test-json.test.ts +0 -119
- package/extensions/structured-return/src/parsers/hadolint-json.test.ts +0 -73
- package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +0 -72
- package/extensions/structured-return/src/parsers/isort-text.test.ts +0 -58
- package/extensions/structured-return/src/parsers/javac-text.test.ts +0 -75
- package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +0 -52
- package/extensions/structured-return/src/parsers/junit-xml.test.ts +0 -627
- package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +0 -76
- package/extensions/structured-return/src/parsers/minitest-text.test.ts +0 -110
- package/extensions/structured-return/src/parsers/mocha-json.test.ts +0 -108
- package/extensions/structured-return/src/parsers/mypy-json.test.ts +0 -101
- package/extensions/structured-return/src/parsers/node-test-text.test.ts +0 -117
- package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +0 -83
- package/extensions/structured-return/src/parsers/prettier-text.test.ts +0 -76
- package/extensions/structured-return/src/parsers/pylint-json.test.ts +0 -120
- package/extensions/structured-return/src/parsers/pyright-json.test.ts +0 -112
- package/extensions/structured-return/src/parsers/rspec-json.test.ts +0 -126
- package/extensions/structured-return/src/parsers/rubocop-json.test.ts +0 -118
- package/extensions/structured-return/src/parsers/ruff-json.test.ts +0 -57
- package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +0 -110
- package/extensions/structured-return/src/parsers/stylelint-json.test.ts +0 -120
- package/extensions/structured-return/src/parsers/swiftc-text.test.ts +0 -73
- package/extensions/structured-return/src/parsers/tail-fallback.test.ts +0 -41
- package/extensions/structured-return/src/parsers/tail-fallback.ts +0 -20
- package/extensions/structured-return/src/parsers/tidy-text.test.ts +0 -74
- package/extensions/structured-return/src/parsers/tsc-text.test.ts +0 -81
- package/extensions/structured-return/src/parsers/unittest-text.test.ts +0 -126
- package/extensions/structured-return/src/parsers/vale-json.test.ts +0 -84
- package/extensions/structured-return/src/parsers/vitest-json.test.ts +0 -118
- package/extensions/structured-return/src/storage/session-stats.test.ts +0 -156
- package/extensions/structured-return/tsconfig.json +0 -11
- package/extensions/structured-return/vitest.config.ts +0 -9
- /package/extensions/structured-return/{src/ui → ui}/widget.ts +0 -0
|
@@ -1,118 +0,0 @@
|
|
|
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 "./vitest-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(), "vitest-test-"));
|
|
10
|
-
const stdoutPath = path.join(dir, "stdout");
|
|
11
|
-
fs.writeFileSync(stdoutPath, stdout);
|
|
12
|
-
return {
|
|
13
|
-
command: "vitest run --reporter=json",
|
|
14
|
-
argv: ["vitest", "run", "--reporter=json"],
|
|
15
|
-
cwd,
|
|
16
|
-
artifactPaths: [],
|
|
17
|
-
stdoutPath,
|
|
18
|
-
stderrPath: path.join(dir, "stderr"),
|
|
19
|
-
logPath: path.join(dir, "log"),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const passing = (name: string) => ({
|
|
24
|
-
fullName: name,
|
|
25
|
-
status: "passed" as const,
|
|
26
|
-
failureMessages: [],
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const failing = (name: string, message: string) => ({
|
|
30
|
-
fullName: name,
|
|
31
|
-
status: "failed" as const,
|
|
32
|
-
failureMessages: [`${message}\n at Object.<anonymous> (test.ts:10:5)`],
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("vitest-json parser", () => {
|
|
36
|
-
it("all passing → status pass, summary reflects passed count", async () => {
|
|
37
|
-
const report = {
|
|
38
|
-
numPassedTests: 5,
|
|
39
|
-
numFailedTests: 0,
|
|
40
|
-
testResults: [
|
|
41
|
-
{
|
|
42
|
-
name: "/project/src/foo.test.ts",
|
|
43
|
-
status: "passed",
|
|
44
|
-
assertionResults: [passing("foo test a"), passing("foo test b")],
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
};
|
|
48
|
-
const result = await parser.parse(makeCtx(JSON.stringify(report)));
|
|
49
|
-
expect(result.status).toBe("pass");
|
|
50
|
-
expect(result.summary).toBe("5 passed");
|
|
51
|
-
expect(result.failures).toHaveLength(0);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("mix of passed and failed → status fail, correct counts, failures listed", async () => {
|
|
55
|
-
const cwd = "/project";
|
|
56
|
-
const report = {
|
|
57
|
-
numPassedTests: 3,
|
|
58
|
-
numFailedTests: 2,
|
|
59
|
-
testResults: [
|
|
60
|
-
{
|
|
61
|
-
name: "/project/src/foo.test.ts",
|
|
62
|
-
status: "failed",
|
|
63
|
-
assertionResults: [passing("foo passes"), failing("foo fails A", "AssertionError: expected 1 to equal 2")],
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: "/project/src/bar.test.ts",
|
|
67
|
-
status: "failed",
|
|
68
|
-
assertionResults: [failing("bar fails B", "AssertionError: expected true to be false")],
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
};
|
|
72
|
-
const result = await parser.parse(makeCtx(JSON.stringify(report), cwd));
|
|
73
|
-
expect(result.status).toBe("fail");
|
|
74
|
-
expect(result.summary).toBe("2 failed, 3 passed");
|
|
75
|
-
expect(result.failures).toHaveLength(2);
|
|
76
|
-
expect(result.failures![0].file).toBe("src/foo.test.ts");
|
|
77
|
-
expect(result.failures![1].file).toBe("src/bar.test.ts");
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("failure message → first line only surfaced", async () => {
|
|
81
|
-
const report = {
|
|
82
|
-
numPassedTests: 0,
|
|
83
|
-
numFailedTests: 1,
|
|
84
|
-
testResults: [
|
|
85
|
-
{
|
|
86
|
-
name: "/project/src/foo.test.ts",
|
|
87
|
-
status: "failed",
|
|
88
|
-
assertionResults: [failing("foo fails", "AssertionError: expected 1 to equal 2")],
|
|
89
|
-
},
|
|
90
|
-
],
|
|
91
|
-
};
|
|
92
|
-
const result = await parser.parse(makeCtx(JSON.stringify(report)));
|
|
93
|
-
expect(result.failures![0].message).toBe("AssertionError: expected 1 to equal 2");
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("relative paths in failure file field", async () => {
|
|
97
|
-
const cwd = "/project";
|
|
98
|
-
const report = {
|
|
99
|
-
numPassedTests: 0,
|
|
100
|
-
numFailedTests: 1,
|
|
101
|
-
testResults: [
|
|
102
|
-
{
|
|
103
|
-
name: "/project/src/deep/foo.test.ts",
|
|
104
|
-
status: "failed",
|
|
105
|
-
assertionResults: [failing("foo fails", "Error")],
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
};
|
|
109
|
-
const result = await parser.parse(makeCtx(JSON.stringify(report), cwd));
|
|
110
|
-
expect(result.failures![0].file).toBe("src/deep/foo.test.ts");
|
|
111
|
-
expect(result.failures![0].file).not.toContain("/project");
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("empty stdout → status error, no crash", async () => {
|
|
115
|
-
const result = await parser.parse(makeCtx(""));
|
|
116
|
-
expect(result.status).toBe("error");
|
|
117
|
-
});
|
|
118
|
-
});
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import {
|
|
6
|
-
appendRun,
|
|
7
|
-
readLifetimeStats,
|
|
8
|
-
formatBytes,
|
|
9
|
-
estimateTokens,
|
|
10
|
-
formatStatsBlock,
|
|
11
|
-
type StatsEntry,
|
|
12
|
-
} from "./session-stats";
|
|
13
|
-
|
|
14
|
-
// Use a temp dir to avoid polluting ~/.pi during tests
|
|
15
|
-
let tempDir: string;
|
|
16
|
-
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "sr-stats-test-"));
|
|
19
|
-
// Override homedir so statsDir() resolves to our temp
|
|
20
|
-
vi.spyOn(os, "homedir").mockReturnValue(tempDir);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
afterEach(() => {
|
|
24
|
-
vi.restoreAllMocks();
|
|
25
|
-
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
function makeEntry(overrides: Partial<StatsEntry> = {}): StatsEntry {
|
|
29
|
-
return {
|
|
30
|
-
ts: new Date().toISOString(),
|
|
31
|
-
session: "/test/session.jsonl",
|
|
32
|
-
parser: "vitest-json",
|
|
33
|
-
rawBytes: 10000,
|
|
34
|
-
parsedBytes: 200,
|
|
35
|
-
command: "vitest run",
|
|
36
|
-
...overrides,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
describe("appendRun", () => {
|
|
41
|
-
it("creates the stats file on first append", () => {
|
|
42
|
-
appendRun(makeEntry());
|
|
43
|
-
const file = path.join(tempDir, ".pi", "structured-return-stats.000.jsonl");
|
|
44
|
-
expect(fs.existsSync(file)).toBe(true);
|
|
45
|
-
const lines = fs.readFileSync(file, "utf-8").trim().split("\n");
|
|
46
|
-
expect(lines).toHaveLength(1);
|
|
47
|
-
expect(JSON.parse(lines[0]).parser).toBe("vitest-json");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("appends multiple entries to the same file", () => {
|
|
51
|
-
appendRun(makeEntry({ command: "first" }));
|
|
52
|
-
appendRun(makeEntry({ command: "second" }));
|
|
53
|
-
appendRun(makeEntry({ command: "third" }));
|
|
54
|
-
const file = path.join(tempDir, ".pi", "structured-return-stats.000.jsonl");
|
|
55
|
-
const lines = fs.readFileSync(file, "utf-8").trim().split("\n");
|
|
56
|
-
expect(lines).toHaveLength(3);
|
|
57
|
-
expect(JSON.parse(lines[1]).command).toBe("second");
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("spills over to a new file when current exceeds 3MB", () => {
|
|
61
|
-
const statsDir = path.join(tempDir, ".pi");
|
|
62
|
-
fs.mkdirSync(statsDir, { recursive: true });
|
|
63
|
-
// Create a file just at the threshold
|
|
64
|
-
const bigContent = "x".repeat(3 * 1024 * 1024);
|
|
65
|
-
fs.writeFileSync(path.join(statsDir, "structured-return-stats.000.jsonl"), bigContent);
|
|
66
|
-
|
|
67
|
-
appendRun(makeEntry());
|
|
68
|
-
|
|
69
|
-
const newFile = path.join(statsDir, "structured-return-stats.001.jsonl");
|
|
70
|
-
expect(fs.existsSync(newFile)).toBe(true);
|
|
71
|
-
const lines = fs.readFileSync(newFile, "utf-8").trim().split("\n");
|
|
72
|
-
expect(lines).toHaveLength(1);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe("readLifetimeStats", () => {
|
|
77
|
-
it("returns zeros when no files exist", () => {
|
|
78
|
-
const stats = readLifetimeStats();
|
|
79
|
-
expect(stats).toEqual({ runs: 0, rawBytes: 0, parsedBytes: 0 });
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("sums entries across multiple files", () => {
|
|
83
|
-
const statsDir = path.join(tempDir, ".pi");
|
|
84
|
-
fs.mkdirSync(statsDir, { recursive: true });
|
|
85
|
-
|
|
86
|
-
const entry1 = JSON.stringify({ rawBytes: 1000, parsedBytes: 100 });
|
|
87
|
-
const entry2 = JSON.stringify({ rawBytes: 2000, parsedBytes: 200 });
|
|
88
|
-
const entry3 = JSON.stringify({ rawBytes: 3000, parsedBytes: 300 });
|
|
89
|
-
|
|
90
|
-
fs.writeFileSync(path.join(statsDir, "structured-return-stats.000.jsonl"), entry1 + "\n" + entry2 + "\n");
|
|
91
|
-
fs.writeFileSync(path.join(statsDir, "structured-return-stats.001.jsonl"), entry3 + "\n");
|
|
92
|
-
|
|
93
|
-
const stats = readLifetimeStats();
|
|
94
|
-
expect(stats.runs).toBe(3);
|
|
95
|
-
expect(stats.rawBytes).toBe(6000);
|
|
96
|
-
expect(stats.parsedBytes).toBe(600);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("skips malformed lines", () => {
|
|
100
|
-
const statsDir = path.join(tempDir, ".pi");
|
|
101
|
-
fs.mkdirSync(statsDir, { recursive: true });
|
|
102
|
-
|
|
103
|
-
const content = [
|
|
104
|
-
JSON.stringify({ rawBytes: 1000, parsedBytes: 100 }),
|
|
105
|
-
"not valid json",
|
|
106
|
-
JSON.stringify({ rawBytes: 2000, parsedBytes: 200 }),
|
|
107
|
-
].join("\n");
|
|
108
|
-
fs.writeFileSync(path.join(statsDir, "structured-return-stats.000.jsonl"), content + "\n");
|
|
109
|
-
|
|
110
|
-
const stats = readLifetimeStats();
|
|
111
|
-
expect(stats.runs).toBe(2);
|
|
112
|
-
expect(stats.rawBytes).toBe(3000);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it("can filter lifetime stats by cwd", () => {
|
|
116
|
-
const statsDir = path.join(tempDir, ".pi");
|
|
117
|
-
fs.mkdirSync(statsDir, { recursive: true });
|
|
118
|
-
|
|
119
|
-
const content = [
|
|
120
|
-
JSON.stringify({ rawBytes: 1000, parsedBytes: 100, cwd: "/repo/a" }),
|
|
121
|
-
JSON.stringify({ rawBytes: 2000, parsedBytes: 200, cwd: "/repo/b" }),
|
|
122
|
-
JSON.stringify({ rawBytes: 3000, parsedBytes: 300, cwd: "/repo/a" }),
|
|
123
|
-
].join("\n");
|
|
124
|
-
fs.writeFileSync(path.join(statsDir, "structured-return-stats.000.jsonl"), content + "\n");
|
|
125
|
-
|
|
126
|
-
const stats = readLifetimeStats({ cwd: "/repo/a" });
|
|
127
|
-
expect(stats).toEqual({ runs: 2, rawBytes: 4000, parsedBytes: 400 });
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
describe("formatBytes", () => {
|
|
132
|
-
it("formats bytes", () => expect(formatBytes(500)).toBe("500 B"));
|
|
133
|
-
it("formats kilobytes", () => expect(formatBytes(2048)).toBe("2.0 KB"));
|
|
134
|
-
it("formats megabytes", () => expect(formatBytes(5 * 1024 * 1024)).toBe("5.0 MB"));
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
describe("estimateTokens", () => {
|
|
138
|
-
it("formats small counts", () => expect(estimateTokens(100)).toBe("25"));
|
|
139
|
-
it("formats thousands", () => expect(estimateTokens(40000)).toBe("10.0k"));
|
|
140
|
-
it("formats millions", () => expect(estimateTokens(8000000)).toBe("2.0M"));
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe("formatStatsBlock", () => {
|
|
144
|
-
it("formats a labeled stats block", () => {
|
|
145
|
-
const block = formatStatsBlock("session", { runs: 5, rawBytes: 50000, parsedBytes: 1000 });
|
|
146
|
-
expect(block[0]).toBe("session:");
|
|
147
|
-
expect(block[1]).toContain("runs: 5");
|
|
148
|
-
expect(block[4]).toContain("98.0% reduction");
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("handles zero runs gracefully", () => {
|
|
152
|
-
const block = formatStatsBlock("lifetime", { runs: 0, rawBytes: 0, parsedBytes: 0 });
|
|
153
|
-
expect(block[1]).toContain("runs: 0");
|
|
154
|
-
expect(block[4]).toContain("0.0%");
|
|
155
|
-
});
|
|
156
|
-
});
|
|
File without changes
|