@robhowley/pi-structured-return 1.10.0 → 2.0.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 (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -83
  3. package/extensions/structured-return/config/registry.ts +4 -30
  4. package/extensions/structured-return/index.ts +105 -76
  5. package/extensions/structured-return/native.ts +223 -0
  6. package/extensions/structured-return/parsers/ava-text.ts +2 -168
  7. package/extensions/structured-return/parsers/bandit-json.ts +2 -79
  8. package/extensions/structured-return/parsers/black-text.ts +2 -73
  9. package/extensions/structured-return/parsers/cargo-build.ts +2 -78
  10. package/extensions/structured-return/parsers/cargo-test.ts +2 -135
  11. package/extensions/structured-return/parsers/checkstyle-xml.ts +2 -182
  12. package/extensions/structured-return/parsers/clang-text.ts +2 -60
  13. package/extensions/structured-return/parsers/dbt-json.ts +2 -135
  14. package/extensions/structured-return/parsers/dotnet-build-text.ts +2 -49
  15. package/extensions/structured-return/parsers/eslint-json.ts +2 -38
  16. package/extensions/structured-return/parsers/go-test-json.ts +2 -138
  17. package/extensions/structured-return/parsers/hadolint-json.ts +2 -60
  18. package/extensions/structured-return/parsers/htmlhint-json.ts +2 -73
  19. package/extensions/structured-return/parsers/isort-text.ts +2 -63
  20. package/extensions/structured-return/parsers/javac-text.ts +2 -82
  21. package/extensions/structured-return/parsers/jsonlint-text.ts +2 -65
  22. package/extensions/structured-return/parsers/junit-xml.ts +2 -325
  23. package/extensions/structured-return/parsers/markdownlint-json.ts +2 -74
  24. package/extensions/structured-return/parsers/minitest-text.ts +2 -107
  25. package/extensions/structured-return/parsers/mocha-json.ts +2 -83
  26. package/extensions/structured-return/parsers/mypy-json.ts +2 -79
  27. package/extensions/structured-return/parsers/node-test-text.ts +2 -92
  28. package/extensions/structured-return/parsers/npm-audit-json.ts +2 -90
  29. package/extensions/structured-return/parsers/prettier-text.ts +2 -66
  30. package/extensions/structured-return/parsers/pylint-json.ts +2 -63
  31. package/extensions/structured-return/parsers/pyright-json.ts +2 -82
  32. package/extensions/structured-return/parsers/rspec-json.ts +2 -75
  33. package/extensions/structured-return/parsers/rubocop-json.ts +2 -75
  34. package/extensions/structured-return/parsers/ruff-json.ts +2 -36
  35. package/extensions/structured-return/parsers/shellcheck-json.ts +2 -60
  36. package/extensions/structured-return/parsers/stylelint-json.ts +2 -75
  37. package/extensions/structured-return/parsers/swiftc-text.ts +2 -52
  38. package/extensions/structured-return/parsers/tail-fallback.ts +2 -19
  39. package/extensions/structured-return/parsers/tidy-text.ts +2 -66
  40. package/extensions/structured-return/parsers/tsc-text.ts +2 -46
  41. package/extensions/structured-return/parsers/unittest-text.ts +2 -125
  42. package/extensions/structured-return/parsers/utils.ts +28 -0
  43. package/extensions/structured-return/parsers/vale-json.ts +2 -79
  44. package/extensions/structured-return/parsers/vitest-json.ts +2 -59
  45. package/extensions/structured-return/storage/log-store.ts +0 -15
  46. package/extensions/structured-return/types.ts +1 -14
  47. package/native/Cargo.lock +193 -0
  48. package/native/Cargo.toml +21 -0
  49. package/native/THIRD-PARTY-LICENSES.txt +3660 -0
  50. package/native/bin/darwin-arm64/build.json +7 -0
  51. package/native/bin/darwin-arm64/structured-return-native +0 -0
  52. package/native/bin/darwin-x64/build.json +7 -0
  53. package/native/bin/darwin-x64/structured-return-native +0 -0
  54. package/native/bin/linux-arm64-musl/build.json +7 -0
  55. package/native/bin/linux-arm64-musl/structured-return-native +0 -0
  56. package/native/bin/linux-x64-musl/build.json +7 -0
  57. package/native/bin/linux-x64-musl/structured-return-native +0 -0
  58. package/native/src/common.rs +118 -0
  59. package/native/src/main.rs +55 -0
  60. package/native/src/parsers/ava_text.rs +125 -0
  61. package/native/src/parsers/bandit_json.rs +120 -0
  62. package/native/src/parsers/black_text.rs +45 -0
  63. package/native/src/parsers/cargo_build.rs +96 -0
  64. package/native/src/parsers/cargo_test.rs +140 -0
  65. package/native/src/parsers/checkstyle_xml.rs +137 -0
  66. package/native/src/parsers/clang_text.rs +39 -0
  67. package/native/src/parsers/compiler_helpers.rs +74 -0
  68. package/native/src/parsers/dbt_json.rs +243 -0
  69. package/native/src/parsers/dotnet_build_text.rs +50 -0
  70. package/native/src/parsers/eslint_json.rs +58 -0
  71. package/native/src/parsers/go_test_json.rs +346 -0
  72. package/native/src/parsers/hadolint_json.rs +37 -0
  73. package/native/src/parsers/htmlhint_json.rs +71 -0
  74. package/native/src/parsers/isort_text.rs +22 -0
  75. package/native/src/parsers/javac_text.rs +49 -0
  76. package/native/src/parsers/json_support.rs +287 -0
  77. package/native/src/parsers/jsonlint_text.rs +50 -0
  78. package/native/src/parsers/junit_xml.rs +430 -0
  79. package/native/src/parsers/markdownlint_json.rs +68 -0
  80. package/native/src/parsers/minitest_text.rs +91 -0
  81. package/native/src/parsers/mocha_json.rs +75 -0
  82. package/native/src/parsers/mod.rs +119 -0
  83. package/native/src/parsers/mypy_json.rs +93 -0
  84. package/native/src/parsers/node_test_text.rs +106 -0
  85. package/native/src/parsers/npm_audit_json.rs +119 -0
  86. package/native/src/parsers/prettier_text.rs +34 -0
  87. package/native/src/parsers/pylint_json.rs +44 -0
  88. package/native/src/parsers/pyright_json.rs +88 -0
  89. package/native/src/parsers/rspec_json.rs +84 -0
  90. package/native/src/parsers/rubocop_json.rs +46 -0
  91. package/native/src/parsers/ruff_json.rs +30 -0
  92. package/native/src/parsers/shellcheck_json.rs +40 -0
  93. package/native/src/parsers/stylelint_json.rs +46 -0
  94. package/native/src/parsers/swiftc_text.rs +38 -0
  95. package/native/src/parsers/tail_fallback.rs +51 -0
  96. package/native/src/parsers/test_helpers.rs +172 -0
  97. package/native/src/parsers/tidy_text.rs +77 -0
  98. package/native/src/parsers/tsc_text.rs +28 -0
  99. package/native/src/parsers/unittest_text.rs +125 -0
  100. package/native/src/parsers/vale_json.rs +66 -0
  101. package/native/src/parsers/vitest_json.rs +71 -0
  102. package/native/src/parsers/xml_support.rs +241 -0
  103. package/native/src/runner.rs +252 -0
  104. package/package.json +22 -7
  105. package/scripts/build-native.mjs +73 -0
  106. package/scripts/native-artifacts.mjs +69 -0
  107. package/skills/structured-return/SKILL.md +103 -249
  108. package/extensions/structured-return/config/project-config.ts +0 -10
  109. package/extensions/structured-return/examples/.pi/machine-readable.json +0 -18
  110. package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +0 -25
@@ -1,139 +1,3 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import type { ParserModule, ParsedFailure } from '../types';
1
+ import { nativeParser } from '../native';
4
2
 
5
- interface GoTestEvent {
6
- Action: string;
7
- Package?: string;
8
- Test?: string;
9
- Output?: string;
10
- Elapsed?: number;
11
- }
12
-
13
- /** Extract file:line and message from a Go t.Error/t.Errorf output line. */
14
- function parseTestOutput(
15
- output: string,
16
- ): { file?: string; line?: number; message?: string } | undefined {
17
- // Format: " file.go:line: message"
18
- const m = output.match(/^\s+(\S+\.go):(\d+):\s+(.+)/);
19
- if (m) return { file: m[1], line: Number(m[2]), message: m[3].trim() };
20
- return undefined;
21
- }
22
-
23
- /** Extract panic message and user-code file:line from a stack trace. */
24
- function parsePanic(
25
- outputs: string[],
26
- testName: string,
27
- ): { message?: string; file?: string; line?: number } | undefined {
28
- const panicLine = outputs.find((o) => o.trim().startsWith('panic:'));
29
- if (!panicLine) return undefined;
30
- const message = panicLine
31
- .trim()
32
- .replace(/^panic:\s*/, '')
33
- .replace(/\s*\[.*\]$/, '')
34
- .trim();
35
-
36
- // Find the user code frame: "module.TestName(..." followed by "\tfile.go:line"
37
- for (let i = 0; i < outputs.length - 1; i++) {
38
- if (outputs[i].includes(`.${testName}(`)) {
39
- const m = outputs[i + 1].match(/\t([^\t]+\.go):(\d+)/);
40
- if (m) return { message, file: m[1], line: Number(m[2]) };
41
- }
42
- }
43
- return { message };
44
- }
45
-
46
- const parser: ParserModule = {
47
- id: 'go-test-json',
48
- async parse(ctx) {
49
- const stdout = fs.readFileSync(ctx.stdoutPath, 'utf8').trim();
50
- if (!stdout) {
51
- return { tool: 'go test', status: 'error', summary: 'no output', logPath: ctx.logPath };
52
- }
53
-
54
- const events: GoTestEvent[] = [];
55
- for (const line of stdout.split('\n')) {
56
- if (!line.trim()) continue;
57
- try {
58
- events.push(JSON.parse(line) as GoTestEvent);
59
- } catch {
60
- // skip non-JSON lines
61
- }
62
- }
63
-
64
- // Collect outputs per test
65
- const testOutputs = new Map<string, string[]>();
66
- let passed = 0;
67
- let failed = 0;
68
-
69
- for (const e of events) {
70
- if (!e.Test) continue;
71
- if (e.Action === 'output') {
72
- const outputs = testOutputs.get(e.Test) ?? [];
73
- outputs.push(e.Output ?? '');
74
- testOutputs.set(e.Test, outputs);
75
- } else if (e.Action === 'pass') {
76
- passed++;
77
- } else if (e.Action === 'fail') {
78
- failed++;
79
- }
80
- }
81
-
82
- const failures: ParsedFailure[] = [];
83
- for (const e of events) {
84
- if (e.Action !== 'fail' || !e.Test) continue;
85
- const outputs = testOutputs.get(e.Test) ?? [];
86
-
87
- // Try parsing as a t.Error/t.Errorf output first
88
- let found = false;
89
- for (const o of outputs) {
90
- const parsed = parseTestOutput(o);
91
- if (parsed) {
92
- const relFile = parsed.file
93
- ? path.isAbsolute(parsed.file)
94
- ? path.relative(ctx.cwd, parsed.file)
95
- : parsed.file
96
- : undefined;
97
- failures.push({
98
- id: e.Test,
99
- file: relFile,
100
- line: parsed.line,
101
- message: parsed.message,
102
- });
103
- found = true;
104
- break;
105
- }
106
- }
107
-
108
- if (!found) {
109
- // Try parsing as a panic
110
- const panic = parsePanic(outputs, e.Test);
111
- if (panic) {
112
- const relFile = panic.file
113
- ? path.isAbsolute(panic.file)
114
- ? path.relative(ctx.cwd, panic.file)
115
- : panic.file
116
- : undefined;
117
- failures.push({
118
- id: e.Test,
119
- file: relFile,
120
- line: panic.line,
121
- message: panic.message ?? 'panic',
122
- });
123
- } else {
124
- failures.push({ id: e.Test, message: 'test failed' });
125
- }
126
- }
127
- }
128
-
129
- return {
130
- tool: 'go test',
131
- status: failed > 0 ? 'fail' : 'pass',
132
- summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
133
- failures,
134
- logPath: ctx.logPath,
135
- };
136
- },
137
- };
138
-
139
- export default parser;
3
+ export default nativeParser('go-test-json');
@@ -1,61 +1,3 @@
1
- import path from 'node:path';
2
- import type { ParserModule, ParsedFailure } from '../types';
3
- import { safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
4
2
 
5
- interface HadolintItem {
6
- code: string;
7
- column: number;
8
- file: string;
9
- level: string;
10
- line: number;
11
- message: string;
12
- }
13
-
14
- const parser: ParserModule = {
15
- id: 'hadolint-json',
16
- async parse(ctx) {
17
- const stdout = safeReadFile(ctx.stdoutPath).trim();
18
- if (!stdout || stdout === '[]') {
19
- return {
20
- tool: 'hadolint',
21
- status: 'pass',
22
- summary: 'no lint errors',
23
- failures: [],
24
- logPath: ctx.logPath,
25
- };
26
- }
27
-
28
- let items: HadolintItem[];
29
- try {
30
- items = JSON.parse(stdout) as HadolintItem[];
31
- } catch {
32
- return {
33
- tool: 'hadolint',
34
- status: 'error',
35
- summary: 'failed to parse hadolint JSON output',
36
- logPath: ctx.logPath,
37
- };
38
- }
39
-
40
- const failures: ParsedFailure[] = items.map((item) => {
41
- const relPath = path.isAbsolute(item.file) ? path.relative(ctx.cwd, item.file) : item.file;
42
- return {
43
- id: `${relPath}:${item.line}:${item.code}`,
44
- file: relPath,
45
- line: item.line,
46
- message: item.message,
47
- rule: item.code,
48
- };
49
- });
50
-
51
- return {
52
- tool: 'hadolint',
53
- status: failures.length > 0 ? 'fail' : 'pass',
54
- summary: failures.length > 0 ? `${failures.length} lint errors` : 'no lint errors',
55
- failures,
56
- logPath: ctx.logPath,
57
- };
58
- },
59
- };
60
-
61
- export default parser;
3
+ export default nativeParser('hadolint-json');
@@ -1,74 +1,3 @@
1
- import path from 'node:path';
2
- import type { ParserModule, ParsedFailure } from '../types';
3
- import { safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
4
2
 
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
61
- ? `${failures.length} lint error${failures.length !== 1 ? 's' : ''}`
62
- : 'no lint errors';
63
-
64
- return {
65
- tool: 'htmlhint',
66
- status: failures.length > 0 ? 'fail' : 'pass',
67
- summary,
68
- failures,
69
- logPath: ctx.logPath,
70
- };
71
- },
72
- };
73
-
74
- export default parser;
3
+ export default nativeParser('htmlhint-json');
@@ -1,64 +1,3 @@
1
- import path from 'node:path';
2
- import type { ParserModule, ParsedFailure } from '../types';
3
- import { safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
4
2
 
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;
3
+ export default nativeParser('isort-text');
@@ -1,83 +1,3 @@
1
- import path from 'node:path';
2
- import type { ParserModule, ParsedFailure } from '../types';
3
- import { safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
4
2
 
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
70
- ? `${failures.length} error${failures.length !== 1 ? 's' : ''}`
71
- : 'compilation successful');
72
-
73
- return {
74
- tool: 'javac',
75
- status: failures.length > 0 ? 'fail' : 'pass',
76
- summary,
77
- failures,
78
- logPath: ctx.logPath,
79
- };
80
- },
81
- };
82
-
83
- export default parser;
3
+ export default nativeParser('javac-text');
@@ -1,66 +1,3 @@
1
- import type { ParserModule, ParsedFailure } from '../types';
2
- import { safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
3
2
 
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 =
26
- ctx.argv.filter((a) => !a.startsWith('-') && a !== 'jsonlint' && a !== 'npx').pop() ??
27
- 'input';
28
-
29
- const lines = combined.split('\n');
30
- const failures: ParsedFailure[] = [];
31
- let line: number | undefined;
32
- let message = '';
33
-
34
- for (const l of lines) {
35
- const headerMatch = l.match(ERROR_HEADER);
36
- if (headerMatch) {
37
- line = parseInt(headerMatch[1], 10);
38
- continue;
39
- }
40
- const expectMatch = l.match(EXPECTING_LINE);
41
- if (expectMatch) {
42
- message = expectMatch[1];
43
- continue;
44
- }
45
- }
46
-
47
- if (line !== undefined) {
48
- failures.push({
49
- id: `${file}:${line}`,
50
- file,
51
- line,
52
- message: message || 'parse error',
53
- });
54
- }
55
-
56
- return {
57
- tool: 'jsonlint',
58
- status: failures.length > 0 ? 'fail' : 'pass',
59
- summary: failures.length > 0 ? 'parse error' : 'valid JSON',
60
- failures,
61
- logPath: ctx.logPath,
62
- };
63
- },
64
- };
65
-
66
- export default parser;
3
+ export default nativeParser('jsonlint-text');