@robhowley/pi-structured-return 1.10.1 → 2.0.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.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -83
  3. package/extensions/structured-return/config/registry.ts +4 -36
  4. package/extensions/structured-return/index.ts +105 -90
  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 +21 -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
@@ -0,0 +1,73 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { chmodSync, copyFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { homedir } from 'node:os';
5
+ import { host, root, sha256, sourceHash, targets, version } from './native-artifacts.mjs';
6
+
7
+ const key = process.argv[2] ?? host;
8
+ const target = targets[key];
9
+ if (!target) throw new Error(`Unsupported native target: ${key}. Windows is not supported.`);
10
+ const manifest = path.join(root, 'native/Cargo.toml');
11
+ const lock = readFileSync(path.join(root, 'native/Cargo.lock'), 'utf8');
12
+ if (
13
+ !readFileSync(manifest, 'utf8').includes(`version = "${version}"`) ||
14
+ !lock.includes(
15
+ `name = "pi-structured-return-native"\nversion = "${version}" # x-release-please-version`,
16
+ )
17
+ ) {
18
+ throw new Error(
19
+ "Cargo.toml/Cargo.lock must match package.json before building. Preserve the native package version's x-release-please-version marker in Cargo.lock after dependency updates.",
20
+ );
21
+ }
22
+ const expectedSource = sourceHash();
23
+ const build = spawnSync(
24
+ 'cargo',
25
+ ['+1.88.0', 'build', '--release', '--locked', '--target', target, '--manifest-path', manifest],
26
+ {
27
+ stdio: 'inherit',
28
+ env: {
29
+ ...process.env,
30
+ CARGO_TARGET_DIR: path.join(root, 'native/target'),
31
+ ...(key.startsWith('darwin-')
32
+ ? { MACOSX_DEPLOYMENT_TARGET: '11.0' }
33
+ : {
34
+ [`CARGO_TARGET_${target.toUpperCase().replaceAll('-', '_')}_LINKER`]: 'musl-gcc',
35
+ }),
36
+ CARGO_ENCODED_RUSTFLAGS: [
37
+ `--remap-path-prefix=${homedir()}=/builder`,
38
+ `--remap-path-prefix=${root}=/structured-return`,
39
+ ].join('\x1f'),
40
+ },
41
+ },
42
+ );
43
+ if (build.error || build.status !== 0) {
44
+ throw new Error(
45
+ `Native build failed. Use Rust 1.88.0 with target ${target}. ${build.error?.message ?? ''}`,
46
+ );
47
+ }
48
+ if (sourceHash() !== expectedSource) {
49
+ throw new Error('Native sources changed during build. Retry with unchanged sources.');
50
+ }
51
+ const directory = path.join(root, 'native/bin', key);
52
+ mkdirSync(directory, { recursive: true });
53
+ const destination = path.join(directory, 'structured-return-native');
54
+ copyFileSync(
55
+ path.join(root, 'native/target', target, 'release/structured-return-native'),
56
+ destination,
57
+ );
58
+ chmodSync(destination, 0o755);
59
+ writeFileSync(
60
+ path.join(directory, 'build.json'),
61
+ JSON.stringify(
62
+ {
63
+ target,
64
+ version,
65
+ sourceHash: expectedSource,
66
+ sha256: sha256(readFileSync(destination)),
67
+ rust: '1.88.0',
68
+ },
69
+ null,
70
+ 2,
71
+ ) + '\n',
72
+ );
73
+ console.log(`Built native helper: ${key}`);
@@ -0,0 +1,69 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { existsSync, readFileSync, readdirSync, statSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ export const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
7
+ export const targets = {
8
+ 'darwin-x64': 'x86_64-apple-darwin',
9
+ 'darwin-arm64': 'aarch64-apple-darwin',
10
+ 'linux-x64-musl': 'x86_64-unknown-linux-musl',
11
+ 'linux-arm64-musl': 'aarch64-unknown-linux-musl',
12
+ };
13
+ export const host = `${process.platform}-${process.arch}${process.platform === 'linux' ? '-musl' : ''}`;
14
+ export const version = JSON.parse(readFileSync(path.join(root, 'package.json'))).version;
15
+ export const sha256 = (bytes) => createHash('sha256').update(bytes).digest('hex');
16
+ export function sourceHash() {
17
+ const hash = createHash('sha256');
18
+ function visit(directory) {
19
+ for (const name of readdirSync(directory).sort()) {
20
+ const file = path.join(directory, name);
21
+ if (statSync(file).isDirectory()) visit(file);
22
+ else hash.update(path.relative(root, file)).update(readFileSync(file));
23
+ }
24
+ }
25
+ visit(path.join(root, 'native/src'));
26
+ for (const name of [
27
+ 'native/Cargo.toml',
28
+ 'native/Cargo.lock',
29
+ 'scripts/build-native.mjs',
30
+ 'scripts/native-artifacts.mjs',
31
+ ])
32
+ hash.update(readFileSync(path.join(root, name)));
33
+ return hash.digest('hex');
34
+ }
35
+ export function verifyArtifacts(keys = Object.keys(targets)) {
36
+ if (!existsSync(path.join(root, 'native/bin'))) {
37
+ throw new Error(
38
+ 'Native artifacts are missing. Assemble the four tested CI artifacts before publishing.',
39
+ );
40
+ }
41
+ const actual = readdirSync(path.join(root, 'native/bin')).sort();
42
+ if (JSON.stringify(actual) !== JSON.stringify([...keys].sort())) {
43
+ throw new Error(`Expected native artifact set ${keys.join(', ')}, found ${actual.join(', ')}.`);
44
+ }
45
+ const expectedSource = sourceHash();
46
+ for (const key of keys) {
47
+ if (!targets[key]) throw new Error(`Unsupported native target: ${key}`);
48
+ const directory = path.join(root, 'native/bin', key);
49
+ const metadata = JSON.parse(readFileSync(path.join(directory, 'build.json')));
50
+ const binaryPath = path.join(directory, 'structured-return-native');
51
+ if ((statSync(binaryPath).mode & 0o111) === 0) {
52
+ throw new Error(`Native artifact is not executable: ${key}`);
53
+ }
54
+ const binary = readFileSync(binaryPath);
55
+ if (
56
+ metadata.target !== targets[key] ||
57
+ metadata.version !== version ||
58
+ metadata.rust !== '1.88.0' ||
59
+ metadata.sourceHash !== expectedSource ||
60
+ metadata.sha256 !== sha256(binary)
61
+ ) {
62
+ throw new Error(`Stale or mismatched native artifact: ${key}`);
63
+ }
64
+ }
65
+ }
66
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
67
+ verifyArtifacts(process.argv.includes('--host') ? [host] : undefined);
68
+ console.log('Native artifact hashes, targets and versions verified.');
69
+ }
@@ -5,255 +5,109 @@ description: Choose compact, machine-readable commands across common test, lint,
5
5
 
6
6
  # structured-return
7
7
 
8
- Prefer better output at the source.
9
-
10
- ## What structured_return does
11
-
12
- `structured_return` is a tool — use it instead of `bash` for lint, test, and build commands. It runs the command, stores the full log, and returns a compact parsed result to the model. When a parser matches, only the signal (failures, errors, summary) comes back into context. When no parser matches, it falls back to the last 200 lines of output plus a log path — still better than dumping everything into context via `bash`.
8
+ Use `structured_return` for noisy checks and builds; it runs the command, saves full logs, and parses supported output. Use `bash` when the expected output is already short. For missing diagnostics, inspect a bounded section of the saved log.
13
9
 
14
10
  ## Rules
15
11
 
16
- 1. Before running any lint, test, or build command, check for project-defined scripts (`package.json`, `Makefile`, `pyproject.toml`, etc.). If a script exists for the task, inspect it to identify the underlying tool and the scope/paths it uses. Then invoke that tool directly with machine-readable flags and the same scope — rather than running through the script wrapper.
17
- 2. Use `structured_return` instead of `bash` for lint, test, and build commands. For tools with a built-in parser, use the command form shown in the examples below. For tools without one, use known machine-readable flags (`--json`, `--format json`, `--message-format=json`, `--console=plain`, `--porcelain`, etc.) and let the tail fallback handle the result.
18
- 3. Otherwise prefer quiet, plain, no-color, and narrow-scope modes.
19
- 4. Prefer file/test-specific runs before full-suite runs.
20
- 5. Prefer bounded log reads over full log dumps.
21
- 6. Do not invent flags. Use known patterns from examples below or your own knowledge of the tool.
22
- 7. When using `structured_return`, pass explicit parser hints when known.
23
- 8. If a repo defines project-local parser mappings in `.pi/structured-return.json`, prefer those mappings.
24
-
25
- ## Examples
26
-
27
- ### pytest
28
-
29
- - `structured_return({ command: "pytest [any pytest args] --junitxml=.tmp/report.xml", parseAs: "junit-xml", artifactPaths: [".tmp/report.xml"] })` — `--junitxml` is built into pytest, no extra dependencies needed; scope, filters, markers, etc. go in `[any pytest args]`
30
-
31
- ### ruff check
32
-
33
- - `structured_return({ command: "ruff check [any ruff args] --output-format=json", parseAs: "ruff-json" })` — scope, selects, ignores, etc. go in `[any ruff args]`
34
-
35
- ### mypy
36
-
37
- - `structured_return({ command: "mypy [any mypy args] --output json", parseAs: "mypy-json" })` — `--output json` is built into mypy (1.0+); outputs NDJSON to stderr with file, line, column, message, error code, and severity; notes are folded into their parent error's message
38
-
39
- ### htmlhint
40
-
41
- - `structured_return({ command: "npx htmlhint --format json [any htmlhint args]", parseAs: "htmlhint-json" })` — `--format json` outputs structured array; strips ANSI codes, source evidence, rule descriptions, and URLs
42
-
43
- ### isort
44
-
45
- - `structured_return({ command: "isort --check --diff [any isort args]", parseAs: "isort-text" })` — parses `--check` output; strips diff hunks, absolute paths, timestamps; lists files with unsorted imports
46
-
47
- ### npm audit
48
-
49
- - `structured_return({ command: "npm audit --json", parseAs: "npm-audit-json" })` — `--json` is built into npm; strips advisory URLs, CVSS vectors, fix instructions; advisory titles joined per package; severity breakdown in summary
50
-
51
- ### jsonlint
52
-
53
- - `structured_return({ command: "npx jsonlint [file]", parseAs: "jsonlint-text" })` — strips stack trace and source pointer; extracts line number and "Expecting X, got Y" message
54
-
55
- ### tidy (HTML Tidy)
56
-
57
- - `structured_return({ command: "tidy -errors [any tidy args]", parseAs: "tidy-text" })` — parses `line N column N - Warning/Error: message` from stderr; strips remediation advice, accessibility tips, reformatted HTML output, and Info lines
58
-
59
- ### vale
60
-
61
- - `structured_return({ command: "vale --output JSON [any vale args]", parseAs: "vale-json" })` — `--output JSON` is built into vale; strips ANSI codes, Action/Span metadata, column-aligned formatting; severity breakdown in summary
62
-
63
- ### prettier
64
-
65
- - `structured_return({ command: "prettier --check [any prettier args]", parseAs: "prettier-text" })` — parses `--check` output; strips "Checking formatting..." preamble, [warn] prefixes, and "Run Prettier with --write to fix" footer
66
-
67
- ### markdownlint
68
-
69
- - `structured_return({ command: "markdownlint --json [any markdownlint args]", parseAs: "markdownlint-json" })` — `--json` outputs structured array; strips context quotes, rule info URLs, fix info, and error ranges; error details folded into description
70
-
71
- ### black
72
-
73
- - `structured_return({ command: "black --check [any black args]", parseAs: "black-text" })` — parses `--check` output; strips diff hunks, emoji banners, timestamps; lists files needing reformatting; also handles `--check --diff` mode
74
-
75
- ### bandit
76
-
77
- - `structured_return({ command: "bandit -f json [any bandit args]", parseAs: "bandit-json" })` — `-f json` is built into bandit; strips source snippets, CWE URLs, run metrics, and confidence labels; severity breakdown in summary
78
-
79
- ### gcc / clang
80
-
81
- - `structured_return({ command: "gcc -c [any gcc args]", parseAs: "clang-text" })` — works with gcc, g++, clang, clang++; parses `file:line:col: error: message` from stderr; source snippets and caret indicators stripped; warning flags preserved as rule
82
-
83
- ### dotnet build
84
-
85
- - `structured_return({ command: "dotnet build [any dotnet args]", parseAs: "dotnet-build-text" })` — parses MSBuild `file(line,col): error CODE: message` format; strips restore/timing noise; deduplicates the inline+summary error repetition; absolute paths relativized
86
-
87
- ### javac
88
-
89
- - `structured_return({ command: "javac [any javac args]", parseAs: "javac-text" })` — parses `file:line: error: message` from stderr; source snippets and caret indicators stripped; `cannot find symbol` errors fold the symbol continuation line into the message
90
-
91
- ### pyright
92
-
93
- - `structured_return({ command: "pyright --outputjson [any pyright args]", parseAs: "pyright-json" })` — `--outputjson` is built into pyright; JSON output includes file, line, message, and rule code; multi-line detail messages collapsed; warnings excluded from failures
94
-
95
- ### tsc
96
-
97
- - `structured_return({ command: "tsc --noEmit --pretty false [any tsc args]", parseAs: "tsc-text" })` — `--pretty false` suppresses source snippets and ANSI codes; parser extracts file, line, TS error code, and message from the compact `file(line,col): error TSXXXX: message` format
98
-
99
- ### pylint
100
-
101
- - `structured_return({ command: "pylint [any pylint args] --output-format=json", parseAs: "pylint-json" })` — `--output-format=json` is built into pylint; rule includes both message-id and symbol name (e.g. `W0612(unused-variable)`)
102
-
103
- ### shellcheck
104
-
105
- - `structured_return({ command: "shellcheck [any shellcheck args] --format=json", parseAs: "shellcheck-json" })` — `--format=json` is built into shellcheck; strips source snippets, caret indicators, "Did you mean" suggestions, and wiki URLs
106
-
107
- ### rubocop
108
-
109
- - `structured_return({ command: "rubocop [any rubocop args] --format json", parseAs: "rubocop-json" })` — `--format json` is built into rubocop; cop name prefix stripped from messages; source snippets and caret indicators removed
110
-
111
- ### swiftc
112
-
113
- - `structured_return({ command: "swiftc -typecheck [any swiftc args]", parseAs: "swiftc-text" })` — parses `file:line:col: error: message` from stderr; source annotations and duplicate error lines deduplicated; warnings filtered out
114
-
115
- ### hadolint
116
-
117
- - `structured_return({ command: "hadolint [any hadolint args] --format json", parseAs: "hadolint-json" })` — `--format json` is built into hadolint; strips ANSI color codes and level labels from text output
118
-
119
- ### stylelint
120
-
121
- - `structured_return({ command: "stylelint [any stylelint args] --formatter json", parseAs: "stylelint-json" })` — `--formatter json` is built into stylelint; rule name suffix stripped from message text; requires a `.stylelintrc` config
122
-
123
- ### node --test
124
-
125
- - `structured_return({ command: "node --test [any node test args]", parseAs: "node-test-text" })` — parses the default spec reporter output; strips full stack traces, assertion error internals, timing data; preserves expected/actual values from assertion failures
126
-
127
- ### ava
128
-
129
- - `structured_return({ command: "npx ava [any ava args] --no-color", parseAs: "ava-text" })` — parses default text output from stderr; assertion failures extract expected/actual from diff lines and file:line; runtime errors extract message and file:line from stack trace
130
-
131
- ### mocha
132
-
133
- - `structured_return({ command: "mocha [any mocha args] --reporter json", parseAs: "mocha-json" })` — `--reporter json` is built into mocha; assertion failures surface explicit expected/actual values; runtime errors surface message and file:line from stack trace
134
-
135
- ### Python unittest
136
-
137
- - `structured_return({ command: "python3 -m unittest [any unittest args]", parseAs: "unittest-text" })` — no special flags needed; parses the default verbose traceback output from stderr; assertion messages extracted from `AssertionError` lines; file:line from traceback frames
138
-
139
- ### go test
140
-
141
- - `structured_return({ command: "go test -json [any go test args]", parseAs: "go-test-json" })` — `-json` is built into `go test`; NDJSON output; assertion failures extract file:line and message from `t.Error`/`t.Errorf` output; panics extract message and user-code file:line from stack trace; 97% reduction vs raw NDJSON
142
-
143
- ### vitest
144
-
145
- - `structured_return({ command: "vitest run [any vitest args] --reporter=json", parseAs: "vitest-json" })` — file paths, filters, etc. go in `[any vitest args]`
146
-
147
- ### eslint
148
-
149
- - `structured_return({ command: "eslint [any eslint args] -f json", parseAs: "eslint-json" })` — paths, configs, rules, etc. go in `[any eslint args]`
150
-
151
- ### rspec
152
-
153
- - `structured_return({ command: "bundle exec rspec [any rspec args] --format json", parseAs: "rspec-json" })` — `--format json` is required; without it output is not parseable
154
-
155
- ### minitest
156
-
157
- - `structured_return({ command: "ruby [any minitest args]", parseAs: "minitest-text" })` — no format flags needed; works with plain ruby invocation
158
-
159
- ### dbt (run, test, compile)
160
-
161
- - `structured_return({ command: "dbt run [any dbt args] --log-format json", parseAs: "dbt-json" })` — `--log-format json` required; model selectors, flags, etc. go in `[any dbt args]`
162
- - `structured_return({ command: "dbt test [any dbt args] --log-format json", parseAs: "dbt-json" })` — same parser handles run and test; unit test diffs preserved verbatim
163
- - `structured_return({ command: "dbt compile [any dbt args] --log-format json", parseAs: "dbt-json" })` — returns compiled SQL; preamble stripped
164
-
165
- ### cargo build
166
-
167
- - `structured_return({ command: "cargo build --message-format=json", parseAs: "cargo-build" })` — `--message-format=json` is built into cargo; errors include file, line, error code (E0308 etc.), and primary span label (expected X, found Y); warnings are filtered out
168
-
169
- ### cargo test
170
-
171
- - `structured_return({ command: "cargo test", parseAs: "cargo-test" })` — no extra flags needed; assertion failures surface left/right values and file:line; panics surface the message and file:line; if compilation fails, the summary says so and tells the model to run `cargo build --message-format=json` for structured errors
172
- - `structured_return({ command: "cargo test [filter]", parseAs: "cargo-test" })` — filter by test name substring, module path, or `--test integration_test_name`
173
-
174
- ### junit-xml
175
-
176
- JUnit XML is the de facto standard output format across the JVM ecosystem and many others — Maven, Gradle, pytest (`--junitxml`), Playwright (`--reporter=junit`), PHPUnit/Pest (`--log-junit`), Go (`go-junit-report`), .NET (`--logger trx` with conversion), Jest (`jest-junit`), and more. If a tool can emit JUnit XML, `junit-xml` covers it without a custom parser.
177
-
178
- `artifactPaths` supports glob patterns — the parser aggregates results across all matching files. Use globs for tools that write one XML per test class (Gradle, Maven/Surefire). Use a single path for tools that write one consolidated file (pytest, Jest, etc.).
179
-
180
- - `structured_return({ command: "[tool] [args] --junitxml=.tmp/report.xml", parseAs: "junit-xml", artifactPaths: [".tmp/report.xml"] })` — pytest, nose2, and any other tool that writes to a file via `--junitxml`
181
- - `structured_return({ command: "go test [any go test args] 2>&1 | go-junit-report > .tmp/report.xml", parseAs: "junit-xml", artifactPaths: [".tmp/report.xml"] })` — Go requires `go-junit-report` (`go install github.com/jstemmer/go-junit-report/v2@latest`); pipe `go test -v` output through it
182
-
183
- #### Gradle
184
-
185
- Gradle writes one XML file per test class — there is no single-file option. Always use a glob pattern.
186
-
187
- - `structured_return({ command: "gradle test", parseAs: "junit-xml", artifactPaths: ["build/test-results/test/TEST-*.xml"] })` — full test suite; results aggregated across all matched files
188
- - `structured_return({ command: "gradle test --tests 'com.example.FooTest'", parseAs: "junit-xml", artifactPaths: ["build/test-results/test/TEST-*.xml"] })` — single class; glob still works (matches the one file)
189
- - For multi-module projects, use `*` in directory positions to match across modules: `structured_return({ command: "gradle test", parseAs: "junit-xml", artifactPaths: ["*/build/test-results/test/TEST-*.xml"] })` — or scope to one module: `structured_return({ command: "gradle :module:test", parseAs: "junit-xml", artifactPaths: ["module/build/test-results/test/TEST-*.xml"] })`
190
-
191
- #### Maven
192
-
193
- Maven Surefire writes one XML per test class — same as Gradle. Always use a glob pattern.
194
-
195
- - `structured_return({ command: "mvn test", parseAs: "junit-xml", artifactPaths: ["target/surefire-reports/TEST-*.xml"] })` — full test suite; any maven args (e.g. `-pl module`, `-Dtest=ClassName`) go before `test`
196
- - For multi-module projects, use `*` in directory positions: `structured_return({ command: "mvn test", parseAs: "junit-xml", artifactPaths: ["*/target/surefire-reports/TEST-*.xml"] })` — or scope to one module: `structured_return({ command: "mvn test -pl module", parseAs: "junit-xml", artifactPaths: ["module/target/surefire-reports/TEST-*.xml"] })`
197
-
198
- #### .NET / xUnit
199
-
200
- `dotnet test` requires the `JunitXml.TestLogger` package (`dotnet add package JunitXml.TestLogger`). Pass the logger inline — no config file changes needed. Add a namespace to your test class or the logger will fall back to `UnknownNamespace.UnknownType` for classnames.
201
-
202
- - `structured_return({ command: "dotnet test --logger \"junit;LogFilePath=.tmp/report.xml\"", parseAs: "junit-xml", artifactPaths: [".tmp/report.xml"] })` — any dotnet test args (project path, `--filter`, etc.) go before `--logger`
203
-
204
- #### Jest
205
-
206
- Jest requires the `jest-junit` reporter (`npm install --save-dev jest-junit`). Pass it via `--reporters` on the CLI — no permanent config change needed.
207
-
208
- - `structured_return({ command: "jest [any jest args] --reporters=jest-junit", parseAs: "junit-xml", artifactPaths: [".tmp/junit.xml"] })` — set `JEST_JUNIT_OUTPUT_FILE=.tmp/junit.xml` or configure `outputFile` in `jest-junit` config; file paths, `--testPathPattern`, etc. go in `[any jest args]`
209
-
210
- #### Playwright
211
-
212
- Playwright has a built-in JUnit reporter. Set the output file inline so `junit-xml` has a concrete artifact to parse.
213
-
214
- - `structured_return({ command: "PLAYWRIGHT_JUNIT_OUTPUT_FILE=.tmp/report.xml playwright test [any playwright args] --reporter=junit", parseAs: "junit-xml", artifactPaths: [".tmp/report.xml"] })` — built-in JUnit reporter; file paths, `--grep`, project names, and shard flags go in `[any playwright args]`
215
-
216
- #### PHPUnit
217
-
218
- PHPUnit writes JUnit XML directly via `--log-junit`.
219
-
220
- - `structured_return({ command: "vendor/bin/phpunit [any phpunit args] --log-junit .tmp/report.xml", parseAs: "junit-xml", artifactPaths: [".tmp/report.xml"] })` — built-in JUnit logging; test paths, `--filter`, and suite selection flags go in `[any phpunit args]`
221
-
222
- #### Pest
223
-
224
- Pest supports the same JUnit XML logging flag as PHPUnit.
225
-
226
- - `structured_return({ command: "vendor/bin/pest [any pest args] --log-junit .tmp/report.xml", parseAs: "junit-xml", artifactPaths: [".tmp/report.xml"] })` — built-in JUnit logging; file paths, `--filter`, and parallelization flags go in `[any pest args]`
227
-
228
- #### Swift / XCTest (Swift Package Manager)
229
-
230
- `swift test` has native JUnit XML output via `--xunit-output` (Swift 5.7+). Use this for all SPM projects — no third-party reporter needed.
231
-
232
- - `structured_return({ command: "swift test --xunit-output .tmp/report.xml", parseAs: "junit-xml", artifactPaths: [".tmp/report.xml"] })` — full test suite
233
- - `structured_return({ command: "swift test --filter MathTests --xunit-output .tmp/report.xml", parseAs: "junit-xml", artifactPaths: [".tmp/report.xml"] })` — single test target or test case; `--filter` accepts a target name, class name, or `ClassName/testMethodName`
234
-
235
- #### Swift / XCTest (Xcode projects)
236
-
237
- `xcodebuild` output is high-volume and not directly parseable. Pipe through `xcbeautify` (install with `brew install xcbeautify`) to get JUnit XML:
238
-
239
- - `structured_return({ command: "xcodebuild test -scheme [scheme] -destination '[destination]' 2>&1 | xcbeautify --report junit --output .tmp", parseAs: "junit-xml", artifactPaths: [".tmp/report.junit.xml"] })` — xcbeautify writes `report.junit.xml` into the `--output` directory; run `xcodebuild -showdestinations -scheme [scheme]` first to find the correct `[destination]` string for the project
240
-
241
- ### checkstyle
242
-
243
- Checkstyle is the standard Java linter — `checkstyle-xml` parses its XML output. Supports both Checkstyle and ktlint (which emits compatible XML).
244
-
245
- - `structured_return({ command: "checkstyle -c [config.xml] -f xml [files]", parseAs: "checkstyle-xml" })` — Checkstyle native; scope goes in `[files]`
246
- - `structured_return({ command: "ktlint [files] --reporter=checkstyle", parseAs: "checkstyle-xml" })` — ktlint with built-in checkstyle reporter
247
-
248
- ## Already compact — use `bash` directly
249
-
250
- These tools were evaluated for structured parsing but their output is already compact enough that a parser adds no token reduction. Use `bash` instead of `structured_return`.
251
-
252
- - `flake8 [any flake8 args]` — `file:line:col: CODE message`, one line per violation
253
- - `ruff format --check .` — just lists files needing formatting
254
- - `go build [any go build args]` — `file:line:col: message`, one line per error
255
- - `go vet [any go vet args]` — same format as go build
256
- - `golangci-lint run [any golangci-lint args]` — `file:line:col: message (linter)`, already minimal
257
- - `yamllint [any yamllint args]` — `file:line:col level message (rule)`, one line per issue
258
- - `pydocstyle [any pydocstyle args]` — `file:line context + CODE: message`, two lines per issue
259
- - `vulture [any vulture args]` — `file:line: message (confidence%)`, one line per finding
12
+ Inspect the project's scripts/config first. Preserve its working directory, local tool runner, environment, setup steps, configuration, and scope. Invoke the tool directly only when equivalent; otherwise retain the wrapper and pass output flags through it.
13
+
14
+ Prefer a focused check unless the task requires broader coverage. Change output formatting, not the work requested: do not turn builds into type checks, remove required steps, or install a reporter just to shorten output.
15
+
16
+ Use the built-in `parseAs` ID below for the command's output format.
17
+
18
+ Preserve existing arguments in every recipe. Use only known flags. For an unsupported format, prefer concise plain/no-color output; requesting JSON alone does not make the tail fallback parse it.
19
+
20
+ Supply `artifactPaths` when results are written to files. Paths/globs are relative to `cwd`; use the actual paths for this run and avoid unrelated old reports. Preserve the checker's exit status through any pipeline.
21
+
22
+ ## Invocation
23
+
24
+ ```js
25
+ structured_return({
26
+ command: 'pytest tests/unit --junitxml=.tmp/report.xml',
27
+ parseAs: 'junit-xml',
28
+ artifactPaths: ['.tmp/report.xml'],
29
+ });
30
+ ```
31
+
32
+ Set `cwd` when needed; omit `artifactPaths` for output read directly from stdout/stderr.
33
+
34
+ ## Command recipes
35
+
36
+ `<args>` stands for the project's existing paths, filters, flags, and configuration. Keep its local runner (for example, `pnpm exec`, `uv run`, or `bundle exec`) where needed.
37
+
38
+ | Command/output form | `parseAs` |
39
+ | ------------------------------------------------------------ | ------------------- |
40
+ | `ruff check <args> --output-format=json` | `ruff-json` |
41
+ | `mypy <args> --output json` | `mypy-json` |
42
+ | `htmlhint --format json <args>` | `htmlhint-json` |
43
+ | `isort --check --diff <args>` | `isort-text` |
44
+ | `npm audit --json` | `npm-audit-json` |
45
+ | `jsonlint <file>` | `jsonlint-text` |
46
+ | `tidy -errors <args>` | `tidy-text` |
47
+ | `vale --output JSON <args>` | `vale-json` |
48
+ | `prettier --check <args>` | `prettier-text` |
49
+ | `markdownlint --json <args>` | `markdownlint-json` |
50
+ | `black --check <args>` | `black-text` |
51
+ | `bandit -f json <args>` | `bandit-json` |
52
+ | `gcc <args>`, `g++ <args>`, `clang <args>`, `clang++ <args>` | `clang-text` |
53
+ | `dotnet build <args>` | `dotnet-build-text` |
54
+ | `javac <args>` | `javac-text` |
55
+ | `pyright --outputjson <args>` | `pyright-json` |
56
+ | `tsc <args> --pretty false` | `tsc-text` |
57
+ | `pylint <args> --output-format=json` | `pylint-json` |
58
+ | `shellcheck <args> --format=json` | `shellcheck-json` |
59
+ | `rubocop <args> --format json` | `rubocop-json` |
60
+ | `swiftc <args>` | `swiftc-text` |
61
+ | `hadolint <args> --format json` | `hadolint-json` |
62
+ | `stylelint <args> --formatter json` | `stylelint-json` |
63
+ | `node --test --test-reporter=spec <args>` | `node-test-text` |
64
+ | `ava <args> --no-color` | `ava-text` |
65
+ | `mocha <args> --reporter json` | `mocha-json` |
66
+ | `python3 -m unittest <args>` | `unittest-text` |
67
+ | `go test -json <args>` | `go-test-json` |
68
+ | `vitest run <args> --reporter=json` | `vitest-json` |
69
+ | `eslint <args> -f json` | `eslint-json` |
70
+ | `bundle exec rspec <args> --format json` | `rspec-json` |
71
+ | `ruby <minitest args>` | `minitest-text` |
72
+ | `dbt run/test/compile <args> --log-format json` | `dbt-json` |
73
+ | `cargo build <args> --message-format=json` | `cargo-build` |
74
+ | `cargo test <args>` | `cargo-test` |
75
+ | `checkstyle -c <config.xml> -f xml <files>` | `checkstyle-xml` |
76
+ | `ktlint <files> --reporter=checkstyle` | `checkstyle-xml` |
77
+
78
+ For dbt, choose one subcommand; compile returns compiled SQL. For Cargo test compilation errors in ordinary test targets, use `cargo test --no-run --message-format=json` with `parseAs: "cargo-build"` and the same relevant Cargo package/features/target selection. For doctests or incompatible selections, inspect the saved log instead. Use `tsc --noEmit` or `swiftc -typecheck` only for type-check tasks.
79
+
80
+ ## JUnit reports
81
+
82
+ Use `parseAs: "junit-xml"` and the corresponding `artifactPaths`. Globs aggregate matching reports; Gradle and Maven write one XML per class, so retain their globs.
83
+
84
+ | Command/output form | `artifactPaths` entry |
85
+ | -------------------------------------------------------------------------------------- | ------------------------------------ |
86
+ | `pytest <args> --junitxml=.tmp/report.xml` | `.tmp/report.xml` |
87
+ | `gradle test <args>` | `build/test-results/test/TEST-*.xml` |
88
+ | `mvn <args> test` | `target/surefire-reports/TEST-*.xml` |
89
+ | `dotnet test <args> --logger "junit;LogFilePath=.tmp/report.xml"` | `.tmp/report.xml` |
90
+ | `JEST_JUNIT_OUTPUT_FILE=.tmp/junit.xml jest <args> --reporters=jest-junit` | `.tmp/junit.xml` |
91
+ | `PLAYWRIGHT_JUNIT_OUTPUT_FILE=.tmp/report.xml playwright test <args> --reporter=junit` | `.tmp/report.xml` |
92
+ | `vendor/bin/phpunit <args> --log-junit .tmp/report.xml` | `.tmp/report.xml` |
93
+ | `vendor/bin/pest <args> --log-junit .tmp/report.xml` | `.tmp/report.xml` |
94
+ | `swift test <args> --xunit-output .tmp/report.xml` | `.tmp/report.xml` |
95
+ | Xcode pipeline below | `.tmp/report.junit.xml` |
96
+
97
+ For Gradle/Maven modules, prefix the artifact pattern with the selected module directory, or `*/` when running across modules. Preserve selectors such as `--tests`, `-Dtest`, and `-pl`.
98
+
99
+ .NET needs `JunitXml.TestLogger`; Jest needs `jest-junit`; Xcode needs `xcbeautify`. Use these when available; otherwise choose an existing reporter or plain fallback. .NET test namespaces improve reported class names.
100
+
101
+ For Xcode, preserve the project's scheme and destination; use `xcodebuild -showdestinations -scheme <scheme>` if needed. Run the pipeline through Bash with `pipefail` so a failed build remains a failure. For Swift packages, `--xunit-output` requires Swift 5.7+.
102
+
103
+ Other JUnit producers work with the same parser when given their actual output file. For Go, prefer the built-in JSON recipe above.
104
+
105
+ Xcode command form (substitute and quote the project's arguments):
106
+
107
+ ```bash
108
+ bash -o pipefail -c 'xcodebuild test <args> 2>&1 | xcbeautify --report junit --output .tmp'
109
+ ```
110
+
111
+ ## Usually compact
112
+
113
+ Use `bash` for short output from `flake8`, `ruff format --check`, `go build`, `go vet`, `golangci-lint run`, `yamllint`, `pydocstyle`, and `vulture`. If a run may produce substantial output, use `structured_return` to retain logs and bound the response.
@@ -1,10 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import type { ParserConfigFile, ParserRegistration } from '../types';
4
-
5
- export function loadProjectConfig(cwd: string): ParserRegistration[] {
6
- const configPath = path.join(cwd, '.pi', 'structured-return.json');
7
- if (!fs.existsSync(configPath)) return [];
8
- const data = JSON.parse(fs.readFileSync(configPath, 'utf8')) as ParserConfigFile;
9
- return Array.isArray(data.parsers) ? data.parsers : [];
10
- }
@@ -1,18 +0,0 @@
1
- {
2
- "parsers": [
3
- {
4
- "id": "acme-junit",
5
- "match": {
6
- "argvIncludes": ["acme", "test"]
7
- },
8
- "parseAs": "junit-xml"
9
- },
10
- {
11
- "id": "foo-json",
12
- "match": {
13
- "argvIncludes": ["foo-cli", "check"]
14
- },
15
- "module": "parsers/foo-cli.js"
16
- }
17
- ]
18
- }
@@ -1,25 +0,0 @@
1
- import fs from 'node:fs';
2
- import type { RunContext } from '../../../src/types.js';
3
-
4
- type FooError = { id?: string; file?: string; line?: number; message?: string };
5
- type FooResult = { ok: boolean; errors?: FooError[] };
6
-
7
- export default {
8
- id: 'foo-json',
9
- async parse(ctx: RunContext) {
10
- const stdout = fs.readFileSync(ctx.stdoutPath, 'utf8');
11
- const data = JSON.parse(stdout) as FooResult;
12
- return {
13
- tool: 'foo-cli',
14
- status: data.ok ? 'pass' : 'fail',
15
- summary: data.ok ? 'foo-cli passed' : `${data.errors?.length ?? 0} foo-cli errors`,
16
- failures: (data.errors ?? []).map((e: FooError, i: number) => ({
17
- id: e.id ?? `error-${i + 1}`,
18
- file: e.file,
19
- line: e.line,
20
- message: e.message,
21
- })),
22
- logPath: ctx.logPath,
23
- };
24
- },
25
- };