@robhowley/pi-structured-return 1.10.1 → 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 +20 -6
  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,76 +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 StylelintWarning {
6
- line: number;
7
- column: number;
8
- rule: string;
9
- severity: string;
10
- text: string;
11
- }
12
-
13
- interface StylelintResult {
14
- source: string;
15
- warnings: StylelintWarning[];
16
- }
17
-
18
- const parser: ParserModule = {
19
- id: 'stylelint-json',
20
- async parse(ctx) {
21
- const stdout = safeReadFile(ctx.stdoutPath).trim();
22
- if (!stdout || stdout === '[]') {
23
- return {
24
- tool: 'stylelint',
25
- status: 'pass',
26
- summary: 'no lint errors',
27
- failures: [],
28
- logPath: ctx.logPath,
29
- };
30
- }
31
-
32
- let results: StylelintResult[];
33
- try {
34
- results = JSON.parse(stdout) as StylelintResult[];
35
- } catch {
36
- return {
37
- tool: 'stylelint',
38
- status: 'error',
39
- summary: 'failed to parse stylelint JSON output',
40
- logPath: ctx.logPath,
41
- };
42
- }
43
-
44
- const failures: ParsedFailure[] = [];
45
- for (const result of results) {
46
- const relPath = path.isAbsolute(result.source)
47
- ? path.relative(ctx.cwd, result.source)
48
- : result.source;
49
- for (const w of result.warnings) {
50
- // Strip the trailing " (rule-name)" from text, but only if the
51
- // parenthesized content matches the actual rule name. Avoids
52
- // over-stripping when the message itself ends with parens
53
- // (e.g. CSS values like "calc(100% - 10px)").
54
- const suffix = ` (${w.rule})`;
55
- const msg = w.text.endsWith(suffix) ? w.text.slice(0, -suffix.length) : w.text;
56
- failures.push({
57
- id: `${relPath}:${w.line}:${w.rule}`,
58
- file: relPath,
59
- line: w.line,
60
- message: msg,
61
- rule: w.rule,
62
- });
63
- }
64
- }
65
-
66
- return {
67
- tool: 'stylelint',
68
- status: failures.length > 0 ? 'fail' : 'pass',
69
- summary: failures.length > 0 ? `${failures.length} lint errors` : 'no lint errors',
70
- failures,
71
- logPath: ctx.logPath,
72
- };
73
- },
74
- };
75
-
76
- export default parser;
3
+ export default nativeParser('stylelint-json');
@@ -1,53 +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
- // swiftc format: file:line:col: error: message (or warning:, note:)
6
- const SWIFT_LINE = /^(.+?):(\d+):\d+:\s+(error|warning):\s+(.+)$/;
7
-
8
- const parser: ParserModule = {
9
- id: 'swiftc-text',
10
- async parse(ctx) {
11
- // swiftc writes diagnostics (errors, warnings, notes) to stderr.
12
- const stderr = safeReadFile(ctx.stderrPath).trim();
13
- if (!stderr) {
14
- return {
15
- tool: 'swiftc',
16
- status: 'pass',
17
- summary: 'no errors',
18
- failures: [],
19
- logPath: ctx.logPath,
20
- };
21
- }
22
-
23
- const failures: ParsedFailure[] = [];
24
- const seen = new Set<string>();
25
- for (const line of stderr.split('\n')) {
26
- const m = line.match(SWIFT_LINE);
27
- if (!m) continue;
28
- const [, file, lineNum, severity, message] = m;
29
- if (severity !== 'error') continue; // skip warnings for now
30
- const relPath = path.isAbsolute(file) ? path.relative(ctx.cwd, file) : file;
31
- // Deduplicate: swiftc repeats the same error in source annotation lines
32
- const id = `${relPath}:${lineNum}:${message}`;
33
- if (seen.has(id)) continue;
34
- seen.add(id);
35
- failures.push({
36
- id,
37
- file: relPath,
38
- line: Number(lineNum),
39
- message,
40
- });
41
- }
42
-
43
- return {
44
- tool: 'swiftc',
45
- status: failures.length > 0 ? 'fail' : 'pass',
46
- summary: failures.length > 0 ? `${failures.length} errors` : 'no errors',
47
- failures,
48
- logPath: ctx.logPath,
49
- };
50
- },
51
- };
52
-
53
- export default parser;
3
+ export default nativeParser('swiftc-text');
@@ -1,20 +1,3 @@
1
- import type { ParserModule } from '../types';
2
- import { safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
3
2
 
4
- const parser: ParserModule = {
5
- id: 'tail-fallback',
6
- async parse(ctx) {
7
- const log = safeReadFile(ctx.logPath);
8
- const lines = log.split(/\r?\n/);
9
- const tail = lines.slice(-200).join('\n');
10
- return {
11
- tool: 'unknown',
12
- status: 'error',
13
- summary: 'no parser matched; returning tail + log path',
14
- logPath: ctx.logPath,
15
- rawTail: tail,
16
- };
17
- },
18
- };
19
-
20
- export default parser;
3
+ export default nativeParser('tail-fallback');
@@ -1,67 +1,3 @@
1
- import type { ParserModule, ParsedFailure } from '../types';
2
- import { safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
3
2
 
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;
3
+ export default nativeParser('tidy-text');
@@ -1,47 +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
- // tsc --pretty false format: file(line,col): error TSXXXX: message
6
- const TSC_LINE = /^(.+?)\((\d+),(\d+)\):\s+error\s+(TS\d+):\s+(.+)$/;
7
-
8
- const parser: ParserModule = {
9
- id: 'tsc-text',
10
- async parse(ctx) {
11
- const raw = safeReadFile(ctx.stdoutPath).trim();
12
- if (!raw) {
13
- return {
14
- tool: 'tsc',
15
- status: 'pass',
16
- summary: 'no type errors',
17
- failures: [],
18
- logPath: ctx.logPath,
19
- };
20
- }
21
-
22
- const failures: ParsedFailure[] = [];
23
- for (const line of raw.split('\n')) {
24
- const m = line.match(TSC_LINE);
25
- if (!m) continue;
26
- const [, file, lineNum, , code, message] = m;
27
- const relPath = path.isAbsolute(file) ? path.relative(ctx.cwd, file) : file;
28
- failures.push({
29
- id: `${relPath}:${lineNum}:${code}`,
30
- file: relPath,
31
- line: Number(lineNum),
32
- message,
33
- rule: code,
34
- });
35
- }
36
-
37
- return {
38
- tool: 'tsc',
39
- status: failures.length > 0 ? 'fail' : 'pass',
40
- summary: failures.length > 0 ? `${failures.length} type errors` : 'no type errors',
41
- failures,
42
- logPath: ctx.logPath,
43
- };
44
- },
45
- };
46
-
47
- export default parser;
3
+ export default nativeParser('tsc-text');
@@ -1,126 +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
- // unittest output blocks are separated by ======
6
- // Each block starts with ERROR: or FAIL: line
7
- // Then a Traceback with file:line, and the final line is the error/assertion message
8
-
9
- const BLOCK_HEADER = /(ERROR|FAIL):\s+(\S+)\s+\(([^)]+)\)/;
10
- const FILE_LINE = /File\s+"([^"]+)",\s+line\s+(\d+)/;
11
-
12
- const parser: ParserModule = {
13
- id: 'unittest-text',
14
- async parse(ctx) {
15
- // Python unittest writes all output (results, tracebacks, summary) to stderr.
16
- const stderr = safeReadFile(ctx.stderrPath).trim();
17
- if (!stderr) {
18
- return {
19
- tool: 'unittest',
20
- status: 'pass',
21
- summary: 'no output',
22
- failures: [],
23
- logPath: ctx.logPath,
24
- };
25
- }
26
-
27
- // Parse the summary line: "Ran N tests in Xs" and "FAILED (failures=N, errors=N)" or "OK"
28
- const ranMatch = stderr.match(/Ran\s+(\d+)\s+test/);
29
- const totalTests = ranMatch ? Number(ranMatch[1]) : 0;
30
- // Parse skipped count from "FAILED (failures=N, skipped=N)" or "OK (skipped=N)"
31
- const skippedMatch = stderr.match(/skipped=(\d+)/);
32
- const skipped = skippedMatch ? Number(skippedMatch[1]) : 0;
33
- const isOk = stderr.includes('\nOK');
34
-
35
- if (isOk) {
36
- const passed = totalTests - skipped;
37
- return {
38
- tool: 'unittest',
39
- status: 'pass',
40
- summary: `${passed} passed`,
41
- failures: [],
42
- logPath: ctx.logPath,
43
- };
44
- }
45
-
46
- // Split into blocks by the ====== separator
47
- const blocks = stderr.split(/={50,}/);
48
- const failures: ParsedFailure[] = [];
49
-
50
- for (const block of blocks) {
51
- const headerMatch = block.match(BLOCK_HEADER);
52
- if (!headerMatch) continue;
53
-
54
- const [, kind, testName] = headerMatch;
55
- const lines = block.split('\n');
56
-
57
- // Find the last File "..." line in the traceback (the user code, not framework)
58
- let file: string | undefined;
59
- let line: number | undefined;
60
- for (const l of lines) {
61
- const fm = l.match(FILE_LINE);
62
- if (fm) {
63
- file = fm[1];
64
- line = Number(fm[2]);
65
- }
66
- }
67
-
68
- // The error message is the last non-empty line of the traceback block.
69
- // Stop at dashed separators (------) that come AFTER the traceback,
70
- // summary lines ("Ran N tests"), or FAILED/OK lines.
71
- const traceLines: string[] = [];
72
- let pastHeader = false;
73
- for (const l of lines) {
74
- const trimmed = l.trim();
75
- if (!pastHeader) {
76
- // Skip until we're past the initial header + first dashed separator
77
- if (/^-{10,}/.test(trimmed)) {
78
- pastHeader = true;
79
- }
80
- continue;
81
- }
82
- // Stop at the next dashed separator (before summary) or summary lines
83
- if (/^-{10,}/.test(trimmed)) break;
84
- if (/^Ran\s+\d+\s+test/.test(trimmed)) break;
85
- if (/^(FAILED|OK)/.test(trimmed)) break;
86
- traceLines.push(trimmed);
87
- }
88
- const nonEmpty = traceLines.filter(Boolean);
89
- const errorLine = nonEmpty[nonEmpty.length - 1] ?? 'test failed';
90
-
91
- // For assertions, extract expected/actual from "AssertionError: X != Y"
92
- let message = errorLine;
93
- const assertMatch = errorLine.match(/AssertionError:\s*(.+)/);
94
- if (assertMatch) {
95
- message = assertMatch[1];
96
- }
97
-
98
- const relFile = file
99
- ? path.isAbsolute(file)
100
- ? path.relative(ctx.cwd, file)
101
- : file
102
- : undefined;
103
-
104
- failures.push({
105
- id: `${testName}`,
106
- file: relFile,
107
- line,
108
- message,
109
- rule: kind === 'ERROR' ? 'error' : 'assertion',
110
- });
111
- }
112
-
113
- const failed = failures.length;
114
- const passed = totalTests - failed - skipped;
115
-
116
- return {
117
- tool: 'unittest',
118
- status: failed > 0 ? 'fail' : 'pass',
119
- summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
120
- failures,
121
- logPath: ctx.logPath,
122
- };
123
- },
124
- };
125
-
126
- export default parser;
3
+ export default nativeParser('unittest-text');
@@ -13,6 +13,34 @@ export function safeReadFile(filePath: string): string {
13
13
  }
14
14
  }
15
15
 
16
+ /** Preserve the last 200 lines without loading the whole command log into Pi. */
17
+ export function readTail(filePath: string): string {
18
+ let descriptor: number;
19
+ try {
20
+ descriptor = fs.openSync(filePath, 'r');
21
+ } catch (error) {
22
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') return '';
23
+ throw error;
24
+ }
25
+ try {
26
+ let position = fs.fstatSync(descriptor).size;
27
+ let newlines = 0;
28
+ const chunks: Buffer[] = [];
29
+ while (position > 0 && newlines < 200) {
30
+ const length = Math.min(65536, position);
31
+ position -= length;
32
+ const chunk = Buffer.allocUnsafe(length);
33
+ const bytes = fs.readSync(descriptor, chunk, 0, length, position);
34
+ const read = chunk.subarray(0, bytes);
35
+ for (const byte of read) if (byte === 10) newlines++;
36
+ chunks.push(read);
37
+ }
38
+ return Buffer.concat(chunks.reverse()).toString('utf8').split(/\r?\n/).slice(-200).join('\n');
39
+ } finally {
40
+ fs.closeSync(descriptor);
41
+ }
42
+ }
43
+
16
44
  /**
17
45
  * Extract the first user-code file:line from a JS/TS stack trace string.
18
46
  * Skips node_modules and Node.js internal frames.
@@ -1,80 +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 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;
3
+ export default nativeParser('vale-json');
@@ -1,60 +1,3 @@
1
- import path from 'node:path';
2
- import type { ParserModule } from '../types';
3
- import { safeReadFile } from './utils';
1
+ import { nativeParser } from '../native';
4
2
 
5
- interface VitestAssertionResult {
6
- fullName: string;
7
- status: 'passed' | 'failed';
8
- failureMessages: string[];
9
- }
10
-
11
- interface VitestTestResult {
12
- name: string;
13
- status: 'passed' | 'failed';
14
- assertionResults: VitestAssertionResult[];
15
- }
16
-
17
- interface VitestReport {
18
- numPassedTests: number;
19
- numFailedTests: number;
20
- testResults: VitestTestResult[];
21
- }
22
-
23
- const parser: ParserModule = {
24
- id: 'vitest-json',
25
- async parse(ctx) {
26
- const stdout = safeReadFile(ctx.stdoutPath).trim();
27
- const report = stdout ? (JSON.parse(stdout) as VitestReport) : null;
28
- if (!report) {
29
- return {
30
- tool: 'vitest',
31
- status: 'error',
32
- summary: 'no output',
33
- logPath: ctx.logPath,
34
- };
35
- }
36
-
37
- const failures = report.testResults.flatMap((suite) =>
38
- suite.assertionResults
39
- .filter((t) => t.status === 'failed')
40
- .map((t) => ({
41
- id: t.fullName,
42
- file: path.relative(ctx.cwd, suite.name),
43
- message: t.failureMessages[0]?.split('\n')[0] ?? 'test failed',
44
- })),
45
- );
46
-
47
- const failed = report.numFailedTests;
48
- const passed = report.numPassedTests;
49
-
50
- return {
51
- tool: 'vitest',
52
- status: failed > 0 ? 'fail' : 'pass',
53
- summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
54
- failures,
55
- logPath: ctx.logPath,
56
- };
57
- },
58
- };
59
-
60
- export default parser;
3
+ export default nativeParser('vitest-json');
@@ -6,18 +6,3 @@ export function ensureRunDir(cwd: string): string {
6
6
  fs.mkdirSync(dir, { recursive: true });
7
7
  return dir;
8
8
  }
9
-
10
- export function writeRunArtifacts(
11
- dir: string,
12
- runId: string,
13
- stdout: string,
14
- stderr: string,
15
- ): { stdoutPath: string; stderrPath: string; logPath: string } {
16
- const stdoutPath = path.join(dir, `${runId}.stdout.log`);
17
- const stderrPath = path.join(dir, `${runId}.stderr.log`);
18
- const logPath = path.join(dir, `${runId}.combined.log`);
19
- fs.writeFileSync(stdoutPath, stdout);
20
- fs.writeFileSync(stderrPath, stderr);
21
- fs.writeFileSync(logPath, [stdout, stderr].filter(Boolean).join('\n'));
22
- return { stdoutPath, stderrPath, logPath };
23
- }
@@ -27,6 +27,7 @@ export type ObservedRunArgs = {
27
27
  };
28
28
 
29
29
  export type RunContext = {
30
+ signal?: AbortSignal;
30
31
  command: string;
31
32
  argv: string[];
32
33
  cwd: string;
@@ -40,17 +41,3 @@ export type ParserModule = {
40
41
  id: string;
41
42
  parse: (ctx: RunContext) => Promise<Omit<ParsedResult, 'exitCode'>>;
42
43
  };
43
-
44
- export type ParserRegistration = {
45
- id: string;
46
- match?: {
47
- argvIncludes?: string[];
48
- regex?: string;
49
- };
50
- parseAs?: string;
51
- module?: string;
52
- };
53
-
54
- export type ParserConfigFile = {
55
- parsers: ParserRegistration[];
56
- };