@robhowley/pi-structured-return 1.8.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.
Files changed (97) hide show
  1. package/README.md +84 -73
  2. package/extensions/structured-return/config/project-config.ts +10 -0
  3. package/extensions/structured-return/config/registry.ts +306 -0
  4. package/extensions/structured-return/examples/.pi/machine-readable.json +18 -0
  5. package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +25 -0
  6. package/extensions/structured-return/{src/index.ts → index.ts} +94 -69
  7. package/extensions/structured-return/{src/parsers → parsers}/ava-text.ts +23 -15
  8. package/extensions/structured-return/{src/parsers → parsers}/bandit-json.ts +17 -15
  9. package/extensions/structured-return/{src/parsers → parsers}/black-text.ts +18 -18
  10. package/extensions/structured-return/{src/parsers → parsers}/cargo-build.ts +19 -14
  11. package/extensions/structured-return/{src/parsers → parsers}/cargo-test.ts +20 -19
  12. package/extensions/structured-return/parsers/checkstyle-xml.ts +183 -0
  13. package/extensions/structured-return/{src/parsers → parsers}/clang-text.ts +15 -13
  14. package/extensions/structured-return/{src/parsers → parsers}/dbt-json.ts +28 -23
  15. package/extensions/structured-return/{src/parsers → parsers}/dotnet-build-text.ts +10 -8
  16. package/extensions/structured-return/{src/parsers → parsers}/eslint-json.ts +15 -9
  17. package/extensions/structured-return/{src/parsers → parsers}/go-test-json.ts +23 -21
  18. package/extensions/structured-return/{src/parsers → parsers}/hadolint-json.ts +18 -12
  19. package/extensions/structured-return/{src/parsers → parsers}/htmlhint-json.ts +15 -13
  20. package/extensions/structured-return/{src/parsers → parsers}/isort-text.ts +18 -18
  21. package/extensions/structured-return/{src/parsers → parsers}/javac-text.ts +14 -12
  22. package/extensions/structured-return/{src/parsers → parsers}/jsonlint-text.ts +16 -14
  23. package/extensions/structured-return/{src/parsers → parsers}/junit-xml.ts +149 -50
  24. package/extensions/structured-return/{src/parsers → parsers}/markdownlint-json.ts +19 -17
  25. package/extensions/structured-return/{src/parsers → parsers}/minitest-text.ts +24 -15
  26. package/extensions/structured-return/{src/parsers → parsers}/mocha-json.ts +17 -10
  27. package/extensions/structured-return/{src/parsers → parsers}/mypy-json.ts +16 -16
  28. package/extensions/structured-return/{src/parsers → parsers}/node-test-text.ts +17 -14
  29. package/extensions/structured-return/{src/parsers → parsers}/npm-audit-json.ts +19 -16
  30. package/extensions/structured-return/{src/parsers → parsers}/prettier-text.ts +21 -17
  31. package/extensions/structured-return/{src/parsers → parsers}/pylint-json.ts +17 -17
  32. package/extensions/structured-return/{src/parsers → parsers}/pyright-json.ts +20 -18
  33. package/extensions/structured-return/{src/parsers → parsers}/rspec-json.ts +14 -14
  34. package/extensions/structured-return/{src/parsers → parsers}/rubocop-json.ts +22 -11
  35. package/extensions/structured-return/{src/parsers → parsers}/ruff-json.ts +7 -7
  36. package/extensions/structured-return/{src/parsers → parsers}/shellcheck-json.ts +14 -14
  37. package/extensions/structured-return/{src/parsers → parsers}/stylelint-json.ts +21 -13
  38. package/extensions/structured-return/{src/parsers → parsers}/swiftc-text.ts +16 -10
  39. package/extensions/structured-return/parsers/tail-fallback.ts +20 -0
  40. package/extensions/structured-return/{src/parsers → parsers}/tidy-text.ts +13 -13
  41. package/extensions/structured-return/{src/parsers → parsers}/tsc-text.ts +11 -11
  42. package/extensions/structured-return/{src/parsers → parsers}/unittest-text.ts +24 -14
  43. package/extensions/structured-return/{src/parsers → parsers}/utils.ts +9 -6
  44. package/extensions/structured-return/{src/parsers → parsers}/vale-json.ts +18 -18
  45. package/extensions/structured-return/{src/parsers → parsers}/vitest-json.ts +14 -14
  46. package/extensions/structured-return/{src/storage → storage}/log-store.ts +5 -5
  47. package/extensions/structured-return/{src/storage → storage}/session-stats.ts +11 -11
  48. package/extensions/structured-return/{src/types.ts → types.ts} +4 -2
  49. package/package.json +27 -43
  50. package/skills/structured-return/SKILL.md +62 -1
  51. package/LICENSE +0 -21
  52. package/extensions/structured-return/src/config/project-config.ts +0 -10
  53. package/extensions/structured-return/src/config/registry.test.ts +0 -171
  54. package/extensions/structured-return/src/config/registry.ts +0 -282
  55. package/extensions/structured-return/src/index.test.ts +0 -220
  56. package/extensions/structured-return/src/parsers/ava-text.test.ts +0 -116
  57. package/extensions/structured-return/src/parsers/bandit-json.test.ts +0 -90
  58. package/extensions/structured-return/src/parsers/black-text.test.ts +0 -67
  59. package/extensions/structured-return/src/parsers/cargo-build.test.ts +0 -170
  60. package/extensions/structured-return/src/parsers/cargo-test.test.ts +0 -191
  61. package/extensions/structured-return/src/parsers/clang-text.test.ts +0 -61
  62. package/extensions/structured-return/src/parsers/dbt-json.test.ts +0 -172
  63. package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +0 -85
  64. package/extensions/structured-return/src/parsers/eslint-json.test.ts +0 -60
  65. package/extensions/structured-return/src/parsers/go-test-json.test.ts +0 -119
  66. package/extensions/structured-return/src/parsers/hadolint-json.test.ts +0 -73
  67. package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +0 -72
  68. package/extensions/structured-return/src/parsers/isort-text.test.ts +0 -58
  69. package/extensions/structured-return/src/parsers/javac-text.test.ts +0 -75
  70. package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +0 -52
  71. package/extensions/structured-return/src/parsers/junit-xml.test.ts +0 -410
  72. package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +0 -76
  73. package/extensions/structured-return/src/parsers/minitest-text.test.ts +0 -110
  74. package/extensions/structured-return/src/parsers/mocha-json.test.ts +0 -108
  75. package/extensions/structured-return/src/parsers/mypy-json.test.ts +0 -101
  76. package/extensions/structured-return/src/parsers/node-test-text.test.ts +0 -117
  77. package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +0 -83
  78. package/extensions/structured-return/src/parsers/prettier-text.test.ts +0 -76
  79. package/extensions/structured-return/src/parsers/pylint-json.test.ts +0 -120
  80. package/extensions/structured-return/src/parsers/pyright-json.test.ts +0 -112
  81. package/extensions/structured-return/src/parsers/rspec-json.test.ts +0 -126
  82. package/extensions/structured-return/src/parsers/rubocop-json.test.ts +0 -118
  83. package/extensions/structured-return/src/parsers/ruff-json.test.ts +0 -57
  84. package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +0 -110
  85. package/extensions/structured-return/src/parsers/stylelint-json.test.ts +0 -120
  86. package/extensions/structured-return/src/parsers/swiftc-text.test.ts +0 -73
  87. package/extensions/structured-return/src/parsers/tail-fallback.test.ts +0 -41
  88. package/extensions/structured-return/src/parsers/tail-fallback.ts +0 -20
  89. package/extensions/structured-return/src/parsers/tidy-text.test.ts +0 -74
  90. package/extensions/structured-return/src/parsers/tsc-text.test.ts +0 -81
  91. package/extensions/structured-return/src/parsers/unittest-text.test.ts +0 -126
  92. package/extensions/structured-return/src/parsers/vale-json.test.ts +0 -84
  93. package/extensions/structured-return/src/parsers/vitest-json.test.ts +0 -118
  94. package/extensions/structured-return/src/storage/session-stats.test.ts +0 -156
  95. package/extensions/structured-return/tsconfig.json +0 -11
  96. package/extensions/structured-return/vitest.config.ts +0 -9
  97. /package/extensions/structured-return/{src/ui → ui}/widget.ts +0 -0
package/README.md CHANGED
@@ -5,6 +5,7 @@ A [Pi](https://pi.dev/) extension that adds a `structured_return` tool alongside
5
5
  A failing test run, before and after:
6
6
 
7
7
  **Raw pytest output (262 tokens):**
8
+
8
9
  ```
9
10
  ============================= test session starts ==============================
10
11
  platform darwin -- Python 3.14.2, pytest-9.0.2
@@ -37,6 +38,7 @@ FAILED test_math.py::test_does_not_divide_by_zero - ZeroDivisionError: ...
37
38
  ```
38
39
 
39
40
  **Structured result returned to the model (56 tokens):**
41
+
40
42
  ```
41
43
  pytest test_math.py --junitxml=.tmp/report.xml → cwd: project
42
44
  2 failed, 1 passed
@@ -64,66 +66,70 @@ Measured with `cl100k_base` (tiktoken). All benchmarks use tiny fixtures — red
64
66
 
65
67
  Benchmark: 3 tests — 1 passing, 1 assertion failure, 1 unexpected error.
66
68
 
67
- | Tool | Raw | Structured | Reduction | Notes |
68
- |---|---|---|---|---|
69
- | `mvn test` | 1063 | 86 | **92%** | build lifecycle noise with surefire stack traces per failure |
70
- | `node --test` | 629 | 64 | **90%** | strips full stack traces, assertion internals, timing; preserves expected/actual |
71
- | `npx ava` | 483 | 56 | **88%** | source snippets, diffs, full stack traces stripped; expected/actual preserved |
72
- | `go test` | 394 | 48 | **88%** | stack traces, goroutine frames, panic recovery noise stripped; file:line + expected/actual preserved |
73
- | `dotnet test` | 487 | 107 | **78%** | build header and VSTest output with per-failure stack traces |
74
- | `npx vitest` | 348 | 75 | **78%** | source diff with inline arrows and ANSI color codes per failure |
75
- | `python -m unittest` | 231 | 52 | **78%** | full tracebacks with source annotations; expected/actual from AssertionError |
76
- | `cargo test` | 285 | 68 | **76%** | cargo progress + test binary output with panic traces per failure |
77
- | `pytest` | 289 | 71 | **75%** | verbose output with source snippets and summary footer |
78
- | `rspec` | 212 | 55 | **74%** | default output with backtrace |
79
- | `gradle test` | 263 | 81 | **69%** | gradle console output with build lifecycle noise |
80
- | `npx mocha` | 180 | 55 | **69%** | stack traces + assertion diff formatting; expected/actual preserved |
81
- | `npx jest` | 309 | 99 | **68%** | source annotations with deep jest-circus stack traces per failure |
82
- | `ruby` (minitest) | 168 | 59 | **65%** | default output with backtrace |
69
+ | Tool | Raw | Structured | Reduction | Notes |
70
+ | --------------------- | ---- | ---------- | --------- | ---------------------------------------------------------------------------------------------------------------- |
71
+ | `mvn test` | 1063 | 86 | **92%** | build lifecycle noise with surefire stack traces per failure |
72
+ | `node --test` | 629 | 64 | **90%** | strips full stack traces, assertion internals, timing; preserves expected/actual |
73
+ | `npx ava` | 483 | 56 | **88%** | source snippets, diffs, full stack traces stripped; expected/actual preserved |
74
+ | `go test` | 394 | 48 | **88%** | stack traces, goroutine frames, panic recovery noise stripped; file:line + expected/actual preserved |
75
+ | `npx playwright test` | 542 | 91 | **83%** | ANSI output, attachment paths, source snippets, and stack traces stripped; file:line + expected/actual preserved |
76
+ | `pest` | 382 | 81 | **79%** | source snippets, test-name prefixes, and repeated file refs stripped; file:line preserved |
77
+ | `dotnet test` | 487 | 107 | **78%** | build header and VSTest output with per-failure stack traces |
78
+ | `npx vitest` | 348 | 75 | **78%** | source diff with inline arrows and ANSI color codes per failure |
79
+ | `python -m unittest` | 231 | 52 | **78%** | full tracebacks with source annotations; expected/actual from AssertionError |
80
+ | `cargo test` | 285 | 68 | **76%** | cargo progress + test binary output with panic traces per failure |
81
+ | `pytest` | 289 | 71 | **75%** | verbose output with source snippets and summary footer |
82
+ | `phpunit` | 288 | 75 | **74%** | method headers and absolute paths stripped; body file:line preferred over tc.line |
83
+ | `rspec` | 212 | 55 | **74%** | default output with backtrace |
84
+ | `gradle test` | 263 | 81 | **69%** | gradle console output with build lifecycle noise |
85
+ | `npx mocha` | 180 | 55 | **69%** | stack traces + assertion diff formatting; expected/actual preserved |
86
+ | `npx jest` | 309 | 99 | **68%** | source annotations with deep jest-circus stack traces per failure |
87
+ | `ruby` (minitest) | 168 | 59 | **65%** | default output with backtrace |
83
88
 
84
89
  ### Build tools and compilers
85
90
 
86
91
  Benchmark: 1 file, 1–2 errors. Reduction scales with error count since raw output includes source snippets, caret indicators, and annotations per error.
87
92
 
88
- | Tool | Raw | Structured | Reduction | Notes |
89
- |---|---|---|---|---|
90
- | `dotnet build` | 383 | 53 | **86%** | strips restore/timing noise, deduplicates repeated error lines, absolute paths relativized |
91
- | `npx jsonlint` | 148 | 28 | **81%** | strips stack trace, source pointer line; preserves line number and expecting message |
92
- | `tidy` | 233 | 51 | **78%** | strips remediation advice, accessibility tips, reformatted HTML output, Info lines |
93
- | `cargo build` | 225 | 77 | **66%** | rustc error annotations with code spans and help text per error |
94
- | `swiftc` | 161 | 58 | **64%** | source annotations with backtick markers deduplicated |
95
- | `gcc` / `clang` | 109 | 77 | **29%** | strips source snippets, caret indicators, line numbers from gutter |
96
- | `javac` | 79 | 66 | **16%** | strips source snippets, caret indicators; folds symbol/location into message |
93
+ | Tool | Raw | Structured | Reduction | Notes |
94
+ | --------------- | --- | ---------- | --------- | ------------------------------------------------------------------------------------------ |
95
+ | `dotnet build` | 383 | 53 | **86%** | strips restore/timing noise, deduplicates repeated error lines, absolute paths relativized |
96
+ | `npx jsonlint` | 148 | 28 | **81%** | strips stack trace, source pointer line; preserves line number and expecting message |
97
+ | `tidy` | 233 | 51 | **78%** | strips remediation advice, accessibility tips, reformatted HTML output, Info lines |
98
+ | `cargo build` | 225 | 77 | **66%** | rustc error annotations with code spans and help text per error |
99
+ | `swiftc` | 161 | 58 | **64%** | source annotations with backtick markers deduplicated |
100
+ | `gcc` / `clang` | 109 | 77 | **29%** | strips source snippets, caret indicators, line numbers from gutter |
101
+ | `javac` | 79 | 66 | **16%** | strips source snippets, caret indicators; folds symbol/location into message |
97
102
 
98
103
  ### Linters and type checkers
99
104
 
100
105
  Benchmark: 1 file, 1–2 violations. Reduction is a conservative lower bound — scales with file and error count since raw output repeats paths, source snippets, and annotations per violation.
101
106
 
102
- | Tool | Raw | Structured | Reduction | Notes |
103
- |---|---|---|---|---|
104
- | `isort --check` | 143 | 29 | **80%** | strips diff hunks, absolute paths, timestamps; lists files with unsorted imports |
105
- | `black --check` | 155 | 31 | **80%** | strips diff hunks, emoji, timestamps; lists files needing reformatting |
106
- | `ruff check` | 107 | 52 | **51%** | source context + help text per error |
107
- | `shellcheck` | 224 | 117 | **48%** | strips source snippets, carets, suggestions, wiki URLs |
108
- | `npx htmlhint` | 174 | 92 | **47%** | strips ANSI codes, source evidence, rule descriptions, URLs |
109
- | `vale` | 141 | 79 | **44%** | strips ANSI codes, Action/Span metadata, column-aligned formatting |
110
- | `markdownlint` | 199 | 117 | **41%** | strips context quotes, URLs, fix info, error ranges |
111
- | `pyright` | 100 | 59 | **41%** | strips version, timing, absolute paths; detail lines collapsed |
112
- | `rubocop` | 149 | 90 | **40%** | strips source snippets, caret indicators, summary line |
113
- | `tsc` | 107 | 72 | **33%** | vs `--pretty true` default; source snippets and underlines stripped |
114
- | `stylelint` | 70 | 51 | **27%** | strips summary footer and fix hint |
115
- | `pylint` | 141 | 120 | **15%** | strips header, score line, separator; scales with error count |
116
- | `prettier --check` | 38 | 33 | **13%** | strips preamble, [warn] prefixes, footer hint; scales with file count |
117
- | `hadolint` | 178 | 156 | **12%** | strips ANSI color codes and level labels; measured vs colored output |
118
- | `eslint` | 64 | 59 | **8%** | already compact formatter |
119
- | `mypy` | 75 | 72 | **4%** | mypy text is already compact; notes folded into parent errors |
107
+ | Tool | Raw | Structured | Reduction | Notes |
108
+ | ------------------ |-----|------------|-----------|----------------------------------------------------------------------------------|
109
+ | `isort --check` | 143 | 29 | **80%** | strips diff hunks, absolute paths, timestamps; lists files with unsorted imports |
110
+ | `black --check` | 155 | 31 | **80%** | strips diff hunks, emoji, timestamps; lists files needing reformatting |
111
+ | `ruff check` | 107 | 52 | **51%** | source context + help text per error |
112
+ | `shellcheck` | 224 | 117 | **48%** | strips source snippets, carets, suggestions, wiki URLs |
113
+ | `npx htmlhint` | 174 | 92 | **47%** | strips ANSI codes, source evidence, rule descriptions, URLs |
114
+ | `vale` | 141 | 79 | **44%** | strips ANSI codes, Action/Span metadata, column-aligned formatting |
115
+ | `markdownlint` | 199 | 117 | **41%** | strips context quotes, URLs, fix info, error ranges |
116
+ | `pyright` | 100 | 59 | **41%** | strips version, timing, absolute paths; detail lines collapsed |
117
+ | `rubocop` | 149 | 90 | **40%** | strips source snippets, caret indicators, summary line |
118
+ | `tsc` | 107 | 72 | **33%** | vs `--pretty true` default; source snippets and underlines stripped |
119
+ | `stylelint` | 70 | 51 | **27%** | strips summary footer and fix hint |
120
+ | `checkstyle` | 126 | 100 | **21%** | relative paths, preamble, footer |
121
+ | `pylint` | 141 | 120 | **15%** | strips header, score line, separator; scales with error count |
122
+ | `prettier --check` | 38 | 33 | **13%** | strips preamble, [warn] prefixes, footer hint; scales with file count |
123
+ | `hadolint` | 178 | 156 | **12%** | strips ANSI color codes and level labels; measured vs colored output |
124
+ | `eslint` | 64 | 59 | **8%** | already compact formatter |
125
+ | `mypy` | 75 | 72 | **4%** | mypy text is already compact; notes folded into parent errors |
120
126
 
121
127
  ### Security and audit
122
128
 
123
- | Tool | Raw | Structured | Reduction | Notes |
124
- |---|---|---|---|---|
125
- | `bandit` | 402 | 99 | **75%** | strips source snippets, CWE URLs, run metrics, confidence labels |
126
- | `npm audit` | 158 | 50 | **68%** | strips advisory URLs, fix instructions, CVSS vectors; advisory titles joined per package |
129
+ | Tool | Raw | Structured | Reduction | Notes |
130
+ | ----------- | --- | ---------- | --------- | ---------------------------------------------------------------------------------------- |
131
+ | `bandit` | 402 | 99 | **75%** | strips source snippets, CWE URLs, run metrics, confidence labels |
132
+ | `npm audit` | 158 | 50 | **68%** | strips advisory URLs, fix instructions, CVSS vectors; advisory titles joined per package |
127
133
 
128
134
  ### Pipeline tools
129
135
 
@@ -131,12 +137,12 @@ dbt output is the noisiest tool in this repo relative to useful signal. Every ru
131
137
 
132
138
  The numbers below use 3–4 model toy examples; real projects run hundreds of models where the noise scales linearly and reduction compounds.
133
139
 
134
- | Tool | Raw | Structured | Reduction | Notes |
135
- |---|---|---|---|---|
136
- | `dbt run` (success) | 428 | 20 | **95%** | version, adapter, concurrency, per-model start/finish — all noise on success |
137
- | `dbt run` (failure) | 618 | 198 | **68%** | error messages, model paths, compiled code paths preserved |
138
- | `dbt test` | 720 | 274 | **62%** | unit test diff tables preserved verbatim; preamble stripped |
139
- | `dbt compile` | 775 | 683 | **12%** | compiled SQL is the signal and returned verbatim |
140
+ | Tool | Raw | Structured | Reduction | Notes |
141
+ | ------------------- | --- | ---------- | --------- | ---------------------------------------------------------------------------- |
142
+ | `dbt run` (success) | 428 | 20 | **95%** | version, adapter, concurrency, per-model start/finish — all noise on success |
143
+ | `dbt run` (failure) | 618 | 198 | **68%** | error messages, model paths, compiled code paths preserved |
144
+ | `dbt test` | 720 | 274 | **62%** | unit test diff tables preserved verbatim; preamble stripped |
145
+ | `dbt compile` | 775 | 683 | **12%** | compiled SQL is the signal and returned verbatim |
140
146
 
141
147
  At 12 models, run failures hit 85% reduction. An 18-model DAG success: 1,645 → 20 tokens (99%).
142
148
 
@@ -144,15 +150,15 @@ At 12 models, run failures hit 85% reduction. An 18-model DAG success: 1,645 →
144
150
 
145
151
  Evaluated for structured parsing but raw output is already compact enough that a parser adds no reduction (or goes negative). Use `bash` instead of `structured_return` for these tools.
146
152
 
147
- | Tool | Raw tokens | Format | Why no parser |
148
- |---|---|---|---|
149
- | `go build` | 85 | `file:line:col: message` | one line per error, no decoration |
150
- | `flake8` | 75 | `file:line:col: CODE message` | no JSON without a plugin; text is already one line per violation |
151
- | `yamllint` | 72 | `file:line:col level message (rule)` | filename printed once; one line per issue |
152
- | `golangci-lint` | 59 | `file:line:col: message (linter)` | text output already minimal; JSON includes massive linter report |
153
- | `go vet` | ~60 | `file:line:col: message` | same format as `go build` |
154
- | `vulture` | 58 | `file:line: message (confidence%)` | single line per finding |
155
- | `pydocstyle` | 48 | `file:line context + CODE: message` | two lines per issue; structured format would repeat file paths |
153
+ | Tool | Raw tokens | Format | Why no parser |
154
+ | --------------- | ---------- | ------------------------------------ | ---------------------------------------------------------------- |
155
+ | `go build` | 85 | `file:line:col: message` | one line per error, no decoration |
156
+ | `flake8` | 75 | `file:line:col: CODE message` | no JSON without a plugin; text is already one line per violation |
157
+ | `yamllint` | 72 | `file:line:col level message (rule)` | filename printed once; one line per issue |
158
+ | `golangci-lint` | 59 | `file:line:col: message (linter)` | text output already minimal; JSON includes massive linter report |
159
+ | `go vet` | ~60 | `file:line:col: message` | same format as `go build` |
160
+ | `vulture` | 58 | `file:line: message (confidence%)` | single line per finding |
161
+ | `pydocstyle` | 48 | `file:line context + CODE: message` | two lines per issue; structured format would repeat file paths |
156
162
 
157
163
  ## How it works
158
164
 
@@ -220,7 +226,12 @@ export default {
220
226
  tool: "foo-cli",
221
227
  status: data.ok ? "pass" : "fail",
222
228
  summary: data.ok ? "passed" : `${data.errors.length} errors`,
223
- failures: data.errors.map((e, i) => ({ id: e.id ?? `error-${i}`, file: e.file, line: e.line, message: e.message })),
229
+ failures: data.errors.map((e, i) => ({
230
+ id: e.id ?? `error-${i}`,
231
+ file: e.file,
232
+ line: e.line,
233
+ message: e.message,
234
+ })),
224
235
  logPath: ctx.logPath,
225
236
  };
226
237
  },
@@ -233,13 +244,13 @@ The parser receives a `RunContext` (command, argv, cwd, stdout/stderr paths, art
233
244
 
234
245
  Every parser returns the same shape. The model always knows where to look.
235
246
 
236
- | Field | Type | Description |
237
- |---|---|---|
238
- | `tool` | `string` | Name of the tool that ran (`eslint`, `pytest`, etc.) |
239
- | `exitCode` | `number` | Raw process exit code |
240
- | `status` | `pass \| fail \| error` | Normalized outcome |
241
- | `summary` | `string` | One-line human+model readable result (`3 failed, 12 passed`) |
242
- | `cwd` | `string` | Working directory — anchor for resolving relative paths in failures |
243
- | `failures` | `{ id, file?, line?, message?, rule? }[]` | Per-failure details with relative file paths |
244
- | `logPath` | `string` | Path to full stdout+stderr log |
245
- | `rawTail` | `string?` | Last 200 lines of log, included on fallback when no parser matched |
247
+ | Field | Type | Description |
248
+ | ---------- | ----------------------------------------- | ------------------------------------------------------------------- |
249
+ | `tool` | `string` | Name of the tool that ran (`eslint`, `pytest`, etc.) |
250
+ | `exitCode` | `number` | Raw process exit code |
251
+ | `status` | `pass \| fail \| error` | Normalized outcome |
252
+ | `summary` | `string` | One-line human+model readable result (`3 failed, 12 passed`) |
253
+ | `cwd` | `string` | Working directory — anchor for resolving relative paths in failures |
254
+ | `failures` | `{ id, file?, line?, message?, rule? }[]` | Per-failure details with relative file paths |
255
+ | `logPath` | `string` | Path to full stdout+stderr log |
256
+ | `rawTail` | `string?` | Last 200 lines of log, included on fallback when no parser matched |
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,306 @@
1
+ import path from 'node:path';
2
+ import type { ParserModule, ParserRegistration } from '../types';
3
+ import ruffJson from '../parsers/ruff-json';
4
+ import eslintJson from '../parsers/eslint-json';
5
+ import vitestJson from '../parsers/vitest-json';
6
+ import rspecJson from '../parsers/rspec-json';
7
+ import minitestText from '../parsers/minitest-text';
8
+ import junitXml from '../parsers/junit-xml';
9
+ import cargoBuild from '../parsers/cargo-build';
10
+ import cargoTest from '../parsers/cargo-test';
11
+ import dbtJson from '../parsers/dbt-json';
12
+ import mypyJson from '../parsers/mypy-json';
13
+ import tscText from '../parsers/tsc-text';
14
+ import pylintJson from '../parsers/pylint-json';
15
+ import shellcheckJson from '../parsers/shellcheck-json';
16
+ import rubocopJson from '../parsers/rubocop-json';
17
+ import swiftcText from '../parsers/swiftc-text';
18
+ import hadolintJson from '../parsers/hadolint-json';
19
+ import stylelintJson from '../parsers/stylelint-json';
20
+ import mochaJson from '../parsers/mocha-json';
21
+ import unittestText from '../parsers/unittest-text';
22
+ import goTestJson from '../parsers/go-test-json';
23
+ import avaText from '../parsers/ava-text';
24
+ import pyrightJson from '../parsers/pyright-json';
25
+ import banditJson from '../parsers/bandit-json';
26
+ import javacText from '../parsers/javac-text';
27
+ import dotnetBuildText from '../parsers/dotnet-build-text';
28
+ import clangText from '../parsers/clang-text';
29
+ import nodeTestText from '../parsers/node-test-text';
30
+ import blackText from '../parsers/black-text';
31
+ import markdownlintJson from '../parsers/markdownlint-json';
32
+ import prettierText from '../parsers/prettier-text';
33
+ import valeJson from '../parsers/vale-json';
34
+ import tidyText from '../parsers/tidy-text';
35
+ import jsonlintText from '../parsers/jsonlint-text';
36
+ import npmAuditJson from '../parsers/npm-audit-json';
37
+ import isortText from '../parsers/isort-text';
38
+ import htmlhintJson from '../parsers/htmlhint-json';
39
+ import checkstyleXml from '../parsers/checkstyle-xml';
40
+ import tailFallback from '../parsers/tail-fallback';
41
+
42
+ const builtIns: Record<string, ParserModule> = {
43
+ 'ruff-json': ruffJson,
44
+ 'eslint-json': eslintJson,
45
+ 'vitest-json': vitestJson,
46
+ 'rspec-json': rspecJson,
47
+ 'minitest-text': minitestText,
48
+ 'junit-xml': junitXml,
49
+ 'cargo-build': cargoBuild,
50
+ 'cargo-test': cargoTest,
51
+ 'dbt-json': dbtJson,
52
+ 'mypy-json': mypyJson,
53
+ 'tsc-text': tscText,
54
+ 'pylint-json': pylintJson,
55
+ 'shellcheck-json': shellcheckJson,
56
+ 'rubocop-json': rubocopJson,
57
+ 'swiftc-text': swiftcText,
58
+ 'hadolint-json': hadolintJson,
59
+ 'stylelint-json': stylelintJson,
60
+ 'mocha-json': mochaJson,
61
+ 'unittest-text': unittestText,
62
+ 'go-test-json': goTestJson,
63
+ 'ava-text': avaText,
64
+ 'pyright-json': pyrightJson,
65
+ 'bandit-json': banditJson,
66
+ 'javac-text': javacText,
67
+ 'dotnet-build-text': dotnetBuildText,
68
+ 'clang-text': clangText,
69
+ 'node-test-text': nodeTestText,
70
+ 'black-text': blackText,
71
+ 'markdownlint-json': markdownlintJson,
72
+ 'prettier-text': prettierText,
73
+ 'vale-json': valeJson,
74
+ 'tidy-text': tidyText,
75
+ 'jsonlint-text': jsonlintText,
76
+ 'npm-audit-json': npmAuditJson,
77
+ 'isort-text': isortText,
78
+ 'htmlhint-json': htmlhintJson,
79
+ 'checkstyle-xml': checkstyleXml,
80
+ 'tail-fallback': tailFallback,
81
+ };
82
+
83
+ /**
84
+ * Check whether argv contains `--flag=value` (joined) or `--flag value` (adjacent).
85
+ * Also handles short flags like `-fxml` (no separator) or `-f xml` (adjacent).
86
+ * Avoids false positives from bare `value` tokens appearing elsewhere in argv.
87
+ */
88
+ function hasFlag(argv: string[], flag: string, value: string): boolean {
89
+ // Handle joined flags like --flag=value or -f=xml
90
+ const joinedPattern = flag.length === 1 ? `-${flag}=${value}` : `${flag}=${value}`;
91
+ if (argv.includes(joinedPattern)) return true;
92
+ // Handle concatenated short flags like -fxml (no separator)
93
+ const concatenatedPattern = `-${flag}${value}`;
94
+ if (argv.includes(concatenatedPattern)) return true;
95
+ // Handle adjacent flags like --flag value or -f xml
96
+ for (let i = 0; i < argv.length - 1; i++) {
97
+ if (argv[i] === flag && argv[i + 1] === value) return true;
98
+ }
99
+ return false;
100
+ }
101
+
102
+ /** Built-in detection patterns — fire when no explicit parseAs or project registration matched. */
103
+ const AUTO_DETECT: Array<{ parserId: string; detect: (argv: string[]) => boolean }> = [
104
+ {
105
+ parserId: 'eslint-json',
106
+ detect: (argv) => argv.includes('eslint') && hasFlag(argv, '-f', 'json'),
107
+ },
108
+ {
109
+ parserId: 'ruff-json',
110
+ detect: (argv) => argv.includes('ruff') && hasFlag(argv, '--output-format', 'json'),
111
+ },
112
+ {
113
+ parserId: 'vitest-json',
114
+ detect: (argv) => argv.includes('vitest') && hasFlag(argv, '--reporter', 'json'),
115
+ },
116
+ {
117
+ parserId: 'rspec-json',
118
+ detect: (argv) => argv.includes('rspec') && hasFlag(argv, '--format', 'json'),
119
+ },
120
+ {
121
+ parserId: 'junit-xml',
122
+ detect: (argv) =>
123
+ argv.some(
124
+ (a) => a.startsWith('--junitxml') || a.startsWith('--junit-xml') || a === '--format=junit',
125
+ ),
126
+ },
127
+ {
128
+ parserId: 'cargo-build',
129
+ detect: (argv) =>
130
+ argv.includes('cargo') && argv.includes('build') && hasFlag(argv, '--message-format', 'json'),
131
+ },
132
+ {
133
+ parserId: 'cargo-test',
134
+ detect: (argv) => argv.includes('cargo') && argv.includes('test'),
135
+ },
136
+ {
137
+ parserId: 'dbt-json',
138
+ detect: (argv) =>
139
+ argv.includes('dbt') &&
140
+ (argv.includes('run') || argv.includes('test') || argv.includes('compile')) &&
141
+ hasFlag(argv, '--log-format', 'json'),
142
+ },
143
+ {
144
+ parserId: 'mypy-json',
145
+ detect: (argv) => argv.includes('mypy') && hasFlag(argv, '--output', 'json'),
146
+ },
147
+ {
148
+ parserId: 'tsc-text',
149
+ detect: (argv) => argv.includes('tsc') && hasFlag(argv, '--pretty', 'false'),
150
+ },
151
+ {
152
+ parserId: 'pylint-json',
153
+ detect: (argv) => argv.includes('pylint') && hasFlag(argv, '--output-format', 'json'),
154
+ },
155
+ {
156
+ parserId: 'shellcheck-json',
157
+ detect: (argv) => argv.includes('shellcheck') && hasFlag(argv, '--format', 'json'),
158
+ },
159
+ {
160
+ parserId: 'rubocop-json',
161
+ detect: (argv) => argv.includes('rubocop') && hasFlag(argv, '--format', 'json'),
162
+ },
163
+ {
164
+ parserId: 'swiftc-text',
165
+ detect: (argv) => argv.includes('swiftc') && argv.includes('-typecheck'),
166
+ },
167
+ {
168
+ parserId: 'hadolint-json',
169
+ detect: (argv) => argv.includes('hadolint') && hasFlag(argv, '--format', 'json'),
170
+ },
171
+ {
172
+ parserId: 'stylelint-json',
173
+ detect: (argv) => argv.includes('stylelint') && hasFlag(argv, '--formatter', 'json'),
174
+ },
175
+ {
176
+ parserId: 'mocha-json',
177
+ detect: (argv) => argv.includes('mocha') && hasFlag(argv, '--reporter', 'json'),
178
+ },
179
+ {
180
+ parserId: 'unittest-text',
181
+ detect: (argv) =>
182
+ argv.includes('unittest') ||
183
+ (argv.includes('python3') && argv.includes('-m') && argv.includes('unittest')),
184
+ },
185
+ {
186
+ parserId: 'go-test-json',
187
+ detect: (argv) => argv.includes('go') && argv.includes('test') && argv.includes('-json'),
188
+ },
189
+ {
190
+ parserId: 'ava-text',
191
+ detect: (argv) => argv.includes('ava'),
192
+ },
193
+ {
194
+ parserId: 'pyright-json',
195
+ detect: (argv) => argv.includes('pyright') && argv.includes('--outputjson'),
196
+ },
197
+ {
198
+ parserId: 'bandit-json',
199
+ detect: (argv) => argv.includes('bandit') && hasFlag(argv, '-f', 'json'),
200
+ },
201
+ {
202
+ parserId: 'javac-text',
203
+ detect: (argv) => argv.includes('javac') && !argv.includes('-version'),
204
+ },
205
+ {
206
+ parserId: 'dotnet-build-text',
207
+ detect: (argv) => argv.includes('dotnet') && argv.includes('build'),
208
+ },
209
+ {
210
+ parserId: 'node-test-text',
211
+ detect: (argv) => argv.includes('node') && argv.includes('--test'),
212
+ },
213
+ {
214
+ parserId: 'black-text',
215
+ detect: (argv) => argv.includes('black') && argv.includes('--check'),
216
+ },
217
+ {
218
+ parserId: 'markdownlint-json',
219
+ detect: (argv) => argv.includes('markdownlint') && argv.includes('--json'),
220
+ },
221
+ {
222
+ parserId: 'prettier-text',
223
+ detect: (argv) => argv.includes('prettier') && argv.includes('--check'),
224
+ },
225
+ {
226
+ parserId: 'tidy-text',
227
+ detect: (argv) => argv.includes('tidy'),
228
+ },
229
+ {
230
+ parserId: 'jsonlint-text',
231
+ detect: (argv) => argv.includes('jsonlint'),
232
+ },
233
+ {
234
+ parserId: 'htmlhint-json',
235
+ detect: (argv) => argv.includes('htmlhint') && hasFlag(argv, '--format', 'json'),
236
+ },
237
+ {
238
+ parserId: 'isort-text',
239
+ detect: (argv) => argv.includes('isort') && argv.includes('--check'),
240
+ },
241
+ {
242
+ parserId: 'npm-audit-json',
243
+ detect: (argv) => argv.includes('npm') && argv.includes('audit') && argv.includes('--json'),
244
+ },
245
+ {
246
+ parserId: 'vale-json',
247
+ detect: (argv) => argv.includes('vale') && hasFlag(argv, '--output', 'JSON'),
248
+ },
249
+ {
250
+ parserId: 'clang-text',
251
+ detect: (argv) =>
252
+ (argv.includes('gcc') ||
253
+ argv.includes('g++') ||
254
+ argv.includes('clang') ||
255
+ argv.includes('clang++')) &&
256
+ (argv.includes('-c') || argv.includes('-o')),
257
+ },
258
+ {
259
+ parserId: 'checkstyle-xml',
260
+ detect: (argv) => argv.includes('checkstyle') && hasFlag(argv, '-f', 'xml'),
261
+ },
262
+ {
263
+ parserId: 'checkstyle-xml',
264
+ detect: (argv) => argv.includes('ktlint') && hasFlag(argv, '--reporter', 'checkstyle'),
265
+ },
266
+ ];
267
+
268
+ export function listParsers(): { id: string; autoDetect: boolean }[] {
269
+ const builtInIds = Object.keys(builtIns).filter((id) => id !== 'tail-fallback');
270
+ const autoDetectIds = new Set(AUTO_DETECT.map((d) => d.parserId));
271
+ return builtInIds.map((id) => ({ id, autoDetect: autoDetectIds.has(id) }));
272
+ }
273
+
274
+ export async function resolveParser(opts: {
275
+ cwd: string;
276
+ parseAs?: string;
277
+ argv: string[];
278
+ registrations: ParserRegistration[];
279
+ }): Promise<ParserModule> {
280
+ if (opts.parseAs && builtIns[opts.parseAs]) return builtIns[opts.parseAs];
281
+
282
+ const matched = opts.registrations.find((reg) => matches(reg, opts.argv));
283
+ if (matched?.parseAs && builtIns[matched.parseAs]) return builtIns[matched.parseAs];
284
+ if (matched?.module) {
285
+ const modulePath = path.resolve(opts.cwd, '.pi', matched.module);
286
+ const loaded = await import(modulePath);
287
+ return loaded.default ?? loaded;
288
+ }
289
+
290
+ const autoMatched = AUTO_DETECT.find((d) => d.detect(opts.argv));
291
+ if (autoMatched) return builtIns[autoMatched.parserId];
292
+
293
+ return builtIns['tail-fallback'];
294
+ }
295
+
296
+ function matches(reg: ParserRegistration, argv: string[]): boolean {
297
+ if (reg.match?.argvIncludes?.length) {
298
+ const ok = reg.match.argvIncludes.every((token) => argv.includes(token));
299
+ if (!ok) return false;
300
+ }
301
+ if (reg.match?.regex) {
302
+ const text = argv.join(' ');
303
+ if (!new RegExp(reg.match.regex).test(text)) return false;
304
+ }
305
+ return Boolean(reg.match?.argvIncludes?.length || reg.match?.regex);
306
+ }
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,25 @@
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
+ };