@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.
- package/README.md +84 -73
- package/extensions/structured-return/config/project-config.ts +10 -0
- package/extensions/structured-return/config/registry.ts +306 -0
- package/extensions/structured-return/examples/.pi/machine-readable.json +18 -0
- package/extensions/structured-return/examples/.pi/parsers/foo-cli.ts +25 -0
- package/extensions/structured-return/{src/index.ts → index.ts} +94 -69
- package/extensions/structured-return/{src/parsers → parsers}/ava-text.ts +23 -15
- package/extensions/structured-return/{src/parsers → parsers}/bandit-json.ts +17 -15
- package/extensions/structured-return/{src/parsers → parsers}/black-text.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/cargo-build.ts +19 -14
- package/extensions/structured-return/{src/parsers → parsers}/cargo-test.ts +20 -19
- package/extensions/structured-return/parsers/checkstyle-xml.ts +183 -0
- package/extensions/structured-return/{src/parsers → parsers}/clang-text.ts +15 -13
- package/extensions/structured-return/{src/parsers → parsers}/dbt-json.ts +28 -23
- package/extensions/structured-return/{src/parsers → parsers}/dotnet-build-text.ts +10 -8
- package/extensions/structured-return/{src/parsers → parsers}/eslint-json.ts +15 -9
- package/extensions/structured-return/{src/parsers → parsers}/go-test-json.ts +23 -21
- package/extensions/structured-return/{src/parsers → parsers}/hadolint-json.ts +18 -12
- package/extensions/structured-return/{src/parsers → parsers}/htmlhint-json.ts +15 -13
- package/extensions/structured-return/{src/parsers → parsers}/isort-text.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/javac-text.ts +14 -12
- package/extensions/structured-return/{src/parsers → parsers}/jsonlint-text.ts +16 -14
- package/extensions/structured-return/{src/parsers → parsers}/junit-xml.ts +149 -50
- package/extensions/structured-return/{src/parsers → parsers}/markdownlint-json.ts +19 -17
- package/extensions/structured-return/{src/parsers → parsers}/minitest-text.ts +24 -15
- package/extensions/structured-return/{src/parsers → parsers}/mocha-json.ts +17 -10
- package/extensions/structured-return/{src/parsers → parsers}/mypy-json.ts +16 -16
- package/extensions/structured-return/{src/parsers → parsers}/node-test-text.ts +17 -14
- package/extensions/structured-return/{src/parsers → parsers}/npm-audit-json.ts +19 -16
- package/extensions/structured-return/{src/parsers → parsers}/prettier-text.ts +21 -17
- package/extensions/structured-return/{src/parsers → parsers}/pylint-json.ts +17 -17
- package/extensions/structured-return/{src/parsers → parsers}/pyright-json.ts +20 -18
- package/extensions/structured-return/{src/parsers → parsers}/rspec-json.ts +14 -14
- package/extensions/structured-return/{src/parsers → parsers}/rubocop-json.ts +22 -11
- package/extensions/structured-return/{src/parsers → parsers}/ruff-json.ts +7 -7
- package/extensions/structured-return/{src/parsers → parsers}/shellcheck-json.ts +14 -14
- package/extensions/structured-return/{src/parsers → parsers}/stylelint-json.ts +21 -13
- package/extensions/structured-return/{src/parsers → parsers}/swiftc-text.ts +16 -10
- package/extensions/structured-return/parsers/tail-fallback.ts +20 -0
- package/extensions/structured-return/{src/parsers → parsers}/tidy-text.ts +13 -13
- package/extensions/structured-return/{src/parsers → parsers}/tsc-text.ts +11 -11
- package/extensions/structured-return/{src/parsers → parsers}/unittest-text.ts +24 -14
- package/extensions/structured-return/{src/parsers → parsers}/utils.ts +9 -6
- package/extensions/structured-return/{src/parsers → parsers}/vale-json.ts +18 -18
- package/extensions/structured-return/{src/parsers → parsers}/vitest-json.ts +14 -14
- package/extensions/structured-return/{src/storage → storage}/log-store.ts +5 -5
- package/extensions/structured-return/{src/storage → storage}/session-stats.ts +11 -11
- package/extensions/structured-return/{src/types.ts → types.ts} +4 -2
- package/package.json +27 -43
- package/skills/structured-return/SKILL.md +62 -1
- package/LICENSE +0 -21
- package/extensions/structured-return/src/config/project-config.ts +0 -10
- package/extensions/structured-return/src/config/registry.test.ts +0 -171
- package/extensions/structured-return/src/config/registry.ts +0 -282
- package/extensions/structured-return/src/index.test.ts +0 -220
- package/extensions/structured-return/src/parsers/ava-text.test.ts +0 -116
- package/extensions/structured-return/src/parsers/bandit-json.test.ts +0 -90
- package/extensions/structured-return/src/parsers/black-text.test.ts +0 -67
- package/extensions/structured-return/src/parsers/cargo-build.test.ts +0 -170
- package/extensions/structured-return/src/parsers/cargo-test.test.ts +0 -191
- package/extensions/structured-return/src/parsers/clang-text.test.ts +0 -61
- package/extensions/structured-return/src/parsers/dbt-json.test.ts +0 -172
- package/extensions/structured-return/src/parsers/dotnet-build-text.test.ts +0 -85
- package/extensions/structured-return/src/parsers/eslint-json.test.ts +0 -60
- package/extensions/structured-return/src/parsers/go-test-json.test.ts +0 -119
- package/extensions/structured-return/src/parsers/hadolint-json.test.ts +0 -73
- package/extensions/structured-return/src/parsers/htmlhint-json.test.ts +0 -72
- package/extensions/structured-return/src/parsers/isort-text.test.ts +0 -58
- package/extensions/structured-return/src/parsers/javac-text.test.ts +0 -75
- package/extensions/structured-return/src/parsers/jsonlint-text.test.ts +0 -52
- package/extensions/structured-return/src/parsers/junit-xml.test.ts +0 -410
- package/extensions/structured-return/src/parsers/markdownlint-json.test.ts +0 -76
- package/extensions/structured-return/src/parsers/minitest-text.test.ts +0 -110
- package/extensions/structured-return/src/parsers/mocha-json.test.ts +0 -108
- package/extensions/structured-return/src/parsers/mypy-json.test.ts +0 -101
- package/extensions/structured-return/src/parsers/node-test-text.test.ts +0 -117
- package/extensions/structured-return/src/parsers/npm-audit-json.test.ts +0 -83
- package/extensions/structured-return/src/parsers/prettier-text.test.ts +0 -76
- package/extensions/structured-return/src/parsers/pylint-json.test.ts +0 -120
- package/extensions/structured-return/src/parsers/pyright-json.test.ts +0 -112
- package/extensions/structured-return/src/parsers/rspec-json.test.ts +0 -126
- package/extensions/structured-return/src/parsers/rubocop-json.test.ts +0 -118
- package/extensions/structured-return/src/parsers/ruff-json.test.ts +0 -57
- package/extensions/structured-return/src/parsers/shellcheck-json.test.ts +0 -110
- package/extensions/structured-return/src/parsers/stylelint-json.test.ts +0 -120
- package/extensions/structured-return/src/parsers/swiftc-text.test.ts +0 -73
- package/extensions/structured-return/src/parsers/tail-fallback.test.ts +0 -41
- package/extensions/structured-return/src/parsers/tail-fallback.ts +0 -20
- package/extensions/structured-return/src/parsers/tidy-text.test.ts +0 -74
- package/extensions/structured-return/src/parsers/tsc-text.test.ts +0 -81
- package/extensions/structured-return/src/parsers/unittest-text.test.ts +0 -126
- package/extensions/structured-return/src/parsers/vale-json.test.ts +0 -84
- package/extensions/structured-return/src/parsers/vitest-json.test.ts +0 -118
- package/extensions/structured-return/src/storage/session-stats.test.ts +0 -156
- package/extensions/structured-return/tsconfig.json +0 -11
- package/extensions/structured-return/vitest.config.ts +0 -9
- /package/extensions/structured-return/{src/ui → ui}/widget.ts +0 -0
|
@@ -1,51 +1,61 @@
|
|
|
1
|
-
import { spawn } from
|
|
2
|
-
import path from
|
|
3
|
-
import { randomUUID } from
|
|
4
|
-
import { globSync } from
|
|
5
|
-
import { Type } from
|
|
6
|
-
import type { ExtensionAPI, ExtensionContext } from
|
|
7
|
-
import { Text } from
|
|
8
|
-
import type { ObservedRunArgs, ParsedResult, RunContext } from
|
|
9
|
-
import { ensureRunDir, writeRunArtifacts } from
|
|
10
|
-
import { loadProjectConfig } from
|
|
11
|
-
import { resolveParser, listParsers } from
|
|
12
|
-
import { safeReadFile } from
|
|
13
|
-
import {
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { globSync } from 'glob';
|
|
5
|
+
import { Type } from '@sinclair/typebox';
|
|
6
|
+
import type { ExtensionAPI, ExtensionContext } from '@mariozechner/pi-coding-agent';
|
|
7
|
+
import { Text } from '@mariozechner/pi-tui';
|
|
8
|
+
import type { ObservedRunArgs, ParsedResult, RunContext } from './types';
|
|
9
|
+
import { ensureRunDir, writeRunArtifacts } from './storage/log-store';
|
|
10
|
+
import { loadProjectConfig } from './config/project-config';
|
|
11
|
+
import { resolveParser, listParsers } from './config/registry';
|
|
12
|
+
import { safeReadFile } from './parsers/utils';
|
|
13
|
+
import {
|
|
14
|
+
appendRun,
|
|
15
|
+
readLifetimeStats,
|
|
16
|
+
formatStatsBlock,
|
|
17
|
+
type AggregatedStats,
|
|
18
|
+
} from './storage/session-stats';
|
|
14
19
|
|
|
15
20
|
export default function structuredReturn(pi: ExtensionAPI) {
|
|
16
|
-
pi.registerCommand(
|
|
17
|
-
description:
|
|
21
|
+
pi.registerCommand('sr-parsers', {
|
|
22
|
+
description: 'List all structured-return parsers: built-ins and project-local registrations',
|
|
18
23
|
handler: async (_args, ctx) => {
|
|
19
|
-
const lines: string[] = [
|
|
24
|
+
const lines: string[] = ['structured-return parsers', ''];
|
|
20
25
|
|
|
21
|
-
lines.push(
|
|
26
|
+
lines.push('built-in:');
|
|
22
27
|
for (const { id, autoDetect } of listParsers()) {
|
|
23
|
-
lines.push(` ${id}${autoDetect ?
|
|
28
|
+
lines.push(` ${id}${autoDetect ? ' (auto-detect)' : ''}`);
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
const projectRegistrations = loadProjectConfig(ctx.cwd);
|
|
27
|
-
lines.push(
|
|
28
|
-
lines.push(
|
|
32
|
+
lines.push('');
|
|
33
|
+
lines.push('project-local (.pi/structured-return.json):');
|
|
29
34
|
if (projectRegistrations.length === 0) {
|
|
30
|
-
lines.push(
|
|
35
|
+
lines.push(' (none)');
|
|
31
36
|
} else {
|
|
32
37
|
for (const reg of projectRegistrations) {
|
|
33
|
-
const via = reg.parseAs
|
|
38
|
+
const via = reg.parseAs
|
|
39
|
+
? `→ ${reg.parseAs}`
|
|
40
|
+
: reg.module
|
|
41
|
+
? `→ module: ${reg.module}`
|
|
42
|
+
: '';
|
|
34
43
|
const match = reg.match?.argvIncludes
|
|
35
|
-
? `argv includes [${reg.match.argvIncludes.join(
|
|
44
|
+
? `argv includes [${reg.match.argvIncludes.join(', ')}]`
|
|
36
45
|
: reg.match?.regex
|
|
37
46
|
? `regex: ${reg.match.regex}`
|
|
38
|
-
:
|
|
47
|
+
: '(no match rule)';
|
|
39
48
|
lines.push(` ${reg.id} ${match} ${via}`);
|
|
40
49
|
}
|
|
41
50
|
}
|
|
42
51
|
|
|
43
|
-
ctx.ui.notify(lines.join(
|
|
52
|
+
ctx.ui.notify(lines.join('\n'), 'info');
|
|
44
53
|
},
|
|
45
54
|
});
|
|
46
55
|
|
|
47
|
-
pi.registerCommand(
|
|
48
|
-
description:
|
|
56
|
+
pi.registerCommand('sr-stats', {
|
|
57
|
+
description:
|
|
58
|
+
'Show token savings from structured-return (current session + cwd lifetime + lifetime)',
|
|
49
59
|
handler: async (_args, ctx) => {
|
|
50
60
|
const currentCwd = ctx.cwd ?? process.cwd();
|
|
51
61
|
|
|
@@ -54,7 +64,7 @@ export default function structuredReturn(pi: ExtensionAPI) {
|
|
|
54
64
|
try {
|
|
55
65
|
const entries = ctx.sessionManager?.getEntries?.() ?? [];
|
|
56
66
|
for (const entry of entries) {
|
|
57
|
-
if (entry.type !==
|
|
67
|
+
if (entry.type !== 'message') continue;
|
|
58
68
|
const msg = (
|
|
59
69
|
entry as {
|
|
60
70
|
message?: {
|
|
@@ -64,9 +74,9 @@ export default function structuredReturn(pi: ExtensionAPI) {
|
|
|
64
74
|
};
|
|
65
75
|
}
|
|
66
76
|
).message;
|
|
67
|
-
if (msg?.role !==
|
|
77
|
+
if (msg?.role !== 'toolResult' || msg?.toolName !== 'structured_return') continue;
|
|
68
78
|
const details = msg.details;
|
|
69
|
-
if (details?.rawBytes
|
|
79
|
+
if (details?.rawBytes !== undefined && details?.parsedBytes !== undefined) {
|
|
70
80
|
sessionStats.runs++;
|
|
71
81
|
sessionStats.rawBytes += details.rawBytes;
|
|
72
82
|
sessionStats.parsedBytes += details.parsedBytes;
|
|
@@ -81,24 +91,24 @@ export default function structuredReturn(pi: ExtensionAPI) {
|
|
|
81
91
|
// Lifetime: read all JSONL files
|
|
82
92
|
const lifetime = readLifetimeStats();
|
|
83
93
|
|
|
84
|
-
const lines: string[] = [
|
|
85
|
-
lines.push(...formatStatsBlock(
|
|
86
|
-
lines.push(
|
|
87
|
-
lines.push(...formatStatsBlock(
|
|
88
|
-
lines.push(
|
|
89
|
-
lines.push(...formatStatsBlock(
|
|
94
|
+
const lines: string[] = ['structured-return stats', ''];
|
|
95
|
+
lines.push(...formatStatsBlock('session', sessionStats));
|
|
96
|
+
lines.push('');
|
|
97
|
+
lines.push(...formatStatsBlock('cwd lifetime', cwdLifetime));
|
|
98
|
+
lines.push('');
|
|
99
|
+
lines.push(...formatStatsBlock('lifetime', lifetime));
|
|
90
100
|
|
|
91
|
-
ctx.ui.notify(lines.join(
|
|
101
|
+
ctx.ui.notify(lines.join('\n'), 'info');
|
|
92
102
|
},
|
|
93
103
|
});
|
|
94
104
|
|
|
95
105
|
pi.registerTool({
|
|
96
|
-
name:
|
|
97
|
-
label:
|
|
106
|
+
name: 'structured_return',
|
|
107
|
+
label: 'Structured Return',
|
|
98
108
|
description:
|
|
99
|
-
|
|
109
|
+
'Run a command, store full logs, apply an explicit or registered parser when available, and fall back to tail + log path.',
|
|
100
110
|
promptGuidelines: [
|
|
101
|
-
|
|
111
|
+
'Prefer structured_return over bash for test suites, linters, type checkers, and build commands - it returns compact results. Check the structured-return skill for the right flags and parseAs value for each tool.',
|
|
102
112
|
],
|
|
103
113
|
parameters: Type.Object({
|
|
104
114
|
command: Type.String(),
|
|
@@ -111,7 +121,7 @@ export default function structuredReturn(pi: ExtensionAPI) {
|
|
|
111
121
|
args: ObservedRunArgs,
|
|
112
122
|
_signal: AbortSignal | undefined,
|
|
113
123
|
_onUpdate: unknown,
|
|
114
|
-
ctx: ExtensionContext
|
|
124
|
+
ctx: ExtensionContext,
|
|
115
125
|
) {
|
|
116
126
|
const cwd = args.cwd ?? ctx.cwd ?? process.cwd();
|
|
117
127
|
const runDir = ensureRunDir(cwd);
|
|
@@ -150,7 +160,9 @@ export default function structuredReturn(pi: ExtensionAPI) {
|
|
|
150
160
|
}
|
|
151
161
|
|
|
152
162
|
return {
|
|
153
|
-
content: [
|
|
163
|
+
content: [
|
|
164
|
+
{ type: 'text' as const, text: `${stripCdPrefix(args.command)} → ${resultText}` },
|
|
165
|
+
],
|
|
154
166
|
details: { exitCode, logPath: logs.logPath, parser: parser.id, rawBytes, parsedBytes },
|
|
155
167
|
};
|
|
156
168
|
},
|
|
@@ -158,7 +170,7 @@ export default function structuredReturn(pi: ExtensionAPI) {
|
|
|
158
170
|
return new Text(`structured_return ${args.command}`, 0, 0);
|
|
159
171
|
},
|
|
160
172
|
renderResult(result: { content?: Array<{ type: string; text?: string }> }) {
|
|
161
|
-
const text = result?.content?.[0]?.text ??
|
|
173
|
+
const text = result?.content?.[0]?.text ?? 'structured_return complete';
|
|
162
174
|
return new Text(text, 0, 0);
|
|
163
175
|
},
|
|
164
176
|
});
|
|
@@ -169,19 +181,23 @@ export function formatResult(result: ParsedResult): string {
|
|
|
169
181
|
if (result.cwd) lines.push(`cwd: ${result.cwd}`);
|
|
170
182
|
lines.push(result.summary);
|
|
171
183
|
for (const f of result.failures ?? []) {
|
|
172
|
-
const location = [f.file, f.line].filter(Boolean).join(
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
|
|
184
|
+
const location = [f.file, f.line, f.column].filter(Boolean).join(':');
|
|
185
|
+
const severity = f.severity ? ` [${f.severity}]` : '';
|
|
186
|
+
const rule = f.rule ? ` [${f.rule}]` : '';
|
|
187
|
+
const msgLines = (f.message ?? '').split('\n');
|
|
188
|
+
lines.push(` ${location} ${msgLines[0]}${severity}${rule}`);
|
|
176
189
|
for (const extra of msgLines.slice(1)) lines.push(` ${extra}`);
|
|
177
190
|
}
|
|
178
191
|
// If the parser detected failures but couldn't extract details, surface the
|
|
179
192
|
// log path and raw tail so the model has a path forward instead of a dead end.
|
|
180
|
-
if (
|
|
193
|
+
if (
|
|
194
|
+
(result.status === 'fail' || result.status === 'error') &&
|
|
195
|
+
(result.failures ?? []).length === 0
|
|
196
|
+
) {
|
|
181
197
|
if (result.logPath) lines.push(`log: ${result.logPath}`);
|
|
182
198
|
if (result.rawTail) lines.push(result.rawTail);
|
|
183
199
|
}
|
|
184
|
-
return lines.join(
|
|
200
|
+
return lines.join('\n');
|
|
185
201
|
}
|
|
186
202
|
|
|
187
203
|
/** Resolve and glob-expand artifact paths. Patterns that match nothing are kept as-is (parser handles missing files). */
|
|
@@ -194,43 +210,48 @@ export function expandArtifactPaths(raw: string[], cwd: string): string[] {
|
|
|
194
210
|
}
|
|
195
211
|
|
|
196
212
|
export function stripCdPrefix(command: string): string {
|
|
197
|
-
return command.replace(/^cd\s+\S+\s*&&\s*/,
|
|
213
|
+
return command.replace(/^cd\s+\S+\s*&&\s*/, '');
|
|
198
214
|
}
|
|
199
215
|
|
|
200
216
|
function shellSplit(command: string): string[] {
|
|
201
|
-
return
|
|
217
|
+
return (
|
|
218
|
+
command.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g)?.map((s) => s.replace(/^['"]|['"]$/g, '')) ?? []
|
|
219
|
+
);
|
|
202
220
|
}
|
|
203
221
|
|
|
204
|
-
function runCommand(
|
|
222
|
+
function runCommand(
|
|
223
|
+
command: string,
|
|
224
|
+
cwd: string,
|
|
225
|
+
): Promise<{ stdout: string; stderr: string; exitCode: number }> {
|
|
205
226
|
return new Promise((resolve) => {
|
|
206
|
-
const proc = spawn(command, { cwd, shell: true, stdio: [
|
|
207
|
-
let stdout =
|
|
208
|
-
let stderr =
|
|
209
|
-
proc.stdout.on(
|
|
227
|
+
const proc = spawn(command, { cwd, shell: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
228
|
+
let stdout = '';
|
|
229
|
+
let stderr = '';
|
|
230
|
+
proc.stdout.on('data', (d) => {
|
|
210
231
|
stdout += d.toString();
|
|
211
232
|
});
|
|
212
|
-
proc.stderr.on(
|
|
233
|
+
proc.stderr.on('data', (d) => {
|
|
213
234
|
stderr += d.toString();
|
|
214
235
|
});
|
|
215
|
-
proc.on(
|
|
236
|
+
proc.on('close', (code) => resolve({ stdout, stderr, exitCode: code ?? 1 }));
|
|
216
237
|
});
|
|
217
238
|
}
|
|
218
239
|
|
|
219
240
|
export function finalizeResult(
|
|
220
|
-
result: Omit<ParsedResult,
|
|
241
|
+
result: Omit<ParsedResult, 'exitCode'>,
|
|
221
242
|
exitCode: number,
|
|
222
243
|
logPath: string,
|
|
223
|
-
cwd: string
|
|
244
|
+
cwd: string,
|
|
224
245
|
): ParsedResult {
|
|
225
|
-
if (result.status ===
|
|
246
|
+
if (result.status === 'error' && exitCode === 0) {
|
|
226
247
|
return {
|
|
227
248
|
...result,
|
|
228
249
|
exitCode,
|
|
229
250
|
cwd,
|
|
230
|
-
status:
|
|
251
|
+
status: 'pass',
|
|
231
252
|
summary:
|
|
232
|
-
result.summary ===
|
|
233
|
-
?
|
|
253
|
+
result.summary === 'no parser matched; returning tail + log path'
|
|
254
|
+
? 'command completed; no parser matched'
|
|
234
255
|
: result.summary,
|
|
235
256
|
logPath,
|
|
236
257
|
};
|
|
@@ -238,18 +259,22 @@ export function finalizeResult(
|
|
|
238
259
|
const finalized: ParsedResult = { ...result, exitCode, cwd, logPath };
|
|
239
260
|
// Surface catastrophic failures (command not found, permission denied, missing
|
|
240
261
|
// interpreter, etc.) — the combined log contains the actual diagnostic.
|
|
241
|
-
if (finalized.status ===
|
|
262
|
+
if (finalized.status === 'error' && exitCode !== 0 && !finalized.rawTail) {
|
|
242
263
|
const log = safeReadFile(logPath);
|
|
243
264
|
const lines = log.split(/\r?\n/);
|
|
244
|
-
finalized.rawTail = lines.slice(-200).join(
|
|
265
|
+
finalized.rawTail = lines.slice(-200).join('\n');
|
|
245
266
|
}
|
|
246
267
|
// Safety net: if the parser reports failures but couldn't extract any details
|
|
247
268
|
// (e.g., tool output format changed), append the log tail so the model isn't
|
|
248
269
|
// left with "2 failed" and nothing actionable.
|
|
249
|
-
if (
|
|
270
|
+
if (
|
|
271
|
+
finalized.status === 'fail' &&
|
|
272
|
+
(finalized.failures ?? []).length === 0 &&
|
|
273
|
+
!finalized.rawTail
|
|
274
|
+
) {
|
|
250
275
|
const log = safeReadFile(logPath);
|
|
251
276
|
const lines = log.split(/\r?\n/);
|
|
252
|
-
finalized.rawTail = lines.slice(-200).join(
|
|
277
|
+
finalized.rawTail = lines.slice(-200).join('\n');
|
|
253
278
|
}
|
|
254
279
|
return finalized;
|
|
255
280
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import type { ParserModule, ParsedFailure } from
|
|
3
|
-
import { extractJsStackLocation, safeReadFile } from
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
+
import { extractJsStackLocation, safeReadFile } from './utils';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Parses AVA's default text output (--no-color).
|
|
@@ -14,11 +14,11 @@ const SUMMARY_RE = /(\d+) tests? (passed|failed)/g;
|
|
|
14
14
|
const FAIL_MARKER_RE = /^\s*✘\s+\[fail\]:\s+(.+?)(?:\s+Error thrown in test)?$/;
|
|
15
15
|
|
|
16
16
|
const parser: ParserModule = {
|
|
17
|
-
id:
|
|
17
|
+
id: 'ava-text',
|
|
18
18
|
async parse(ctx) {
|
|
19
19
|
const stderr = safeReadFile(ctx.stdoutPath);
|
|
20
20
|
if (!stderr.trim()) {
|
|
21
|
-
return { tool:
|
|
21
|
+
return { tool: 'ava', status: 'error', summary: 'no output', logPath: ctx.logPath };
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
// Extract pass/fail counts from summary lines at the end
|
|
@@ -27,19 +27,24 @@ const parser: ParserModule = {
|
|
|
27
27
|
let m: RegExpExecArray | null;
|
|
28
28
|
while ((m = SUMMARY_RE.exec(stderr)) !== null) {
|
|
29
29
|
const count = parseInt(m[1], 10);
|
|
30
|
-
if (m[2] ===
|
|
30
|
+
if (m[2] === 'passed') passed = count;
|
|
31
31
|
else failed = count;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
if (passed === 0 && failed === 0) {
|
|
35
|
-
return {
|
|
35
|
+
return {
|
|
36
|
+
tool: 'ava',
|
|
37
|
+
status: 'error',
|
|
38
|
+
summary: 'could not parse ava output',
|
|
39
|
+
logPath: ctx.logPath,
|
|
40
|
+
};
|
|
36
41
|
}
|
|
37
42
|
|
|
38
43
|
const failures = parseFailureBlocks(stderr, ctx.cwd);
|
|
39
44
|
|
|
40
45
|
return {
|
|
41
|
-
tool:
|
|
42
|
-
status: failed > 0 ?
|
|
46
|
+
tool: 'ava',
|
|
47
|
+
status: failed > 0 ? 'fail' : 'pass',
|
|
43
48
|
summary: failed > 0 ? `${failed} failed, ${passed} passed` : `${passed} passed`,
|
|
44
49
|
failures,
|
|
45
50
|
logPath: ctx.logPath,
|
|
@@ -58,7 +63,7 @@ export default parser;
|
|
|
58
63
|
* by those names to get per-failure blocks.
|
|
59
64
|
*/
|
|
60
65
|
function parseFailureBlocks(output: string, cwd: string): ParsedFailure[] {
|
|
61
|
-
const lines = output.split(
|
|
66
|
+
const lines = output.split('\n');
|
|
62
67
|
|
|
63
68
|
// Collect failed test names from ✘ markers
|
|
64
69
|
const failedNames: string[] = [];
|
|
@@ -101,7 +106,7 @@ function parseFailureBlocks(output: string, cwd: string): ParsedFailure[] {
|
|
|
101
106
|
|
|
102
107
|
function parseBlock(name: string, lines: string[], cwd: string): ParsedFailure {
|
|
103
108
|
// Determine type by looking for "Error thrown in test:"
|
|
104
|
-
const isRuntimeError = lines.some((l) => l.trim() ===
|
|
109
|
+
const isRuntimeError = lines.some((l) => l.trim() === 'Error thrown in test:');
|
|
105
110
|
|
|
106
111
|
if (isRuntimeError) {
|
|
107
112
|
return parseRuntimeError(name, lines, cwd);
|
|
@@ -129,14 +134,17 @@ function parseAssertionFailure(name: string, lines: string[], cwd: string): Pars
|
|
|
129
134
|
}
|
|
130
135
|
|
|
131
136
|
// Diff values: "- 12" (actual), "+ 99" (expected)
|
|
132
|
-
if (trimmed.startsWith(
|
|
137
|
+
if (trimmed.startsWith('- ') && actual === undefined) {
|
|
133
138
|
actual = trimmed.slice(2);
|
|
134
|
-
} else if (trimmed.startsWith(
|
|
139
|
+
} else if (trimmed.startsWith('+ ') && expected === undefined) {
|
|
135
140
|
expected = trimmed.slice(2);
|
|
136
141
|
}
|
|
137
142
|
}
|
|
138
143
|
|
|
139
|
-
const message =
|
|
144
|
+
const message =
|
|
145
|
+
actual !== undefined && expected !== undefined
|
|
146
|
+
? `expected ${expected}, got ${actual}`
|
|
147
|
+
: undefined;
|
|
140
148
|
|
|
141
149
|
return { id: name, file, line, message };
|
|
142
150
|
}
|
|
@@ -154,7 +162,7 @@ function parseRuntimeError(name: string, lines: string[], cwd: string): ParsedFa
|
|
|
154
162
|
}
|
|
155
163
|
|
|
156
164
|
// Extract file:line from the first user stack frame
|
|
157
|
-
const loc = extractJsStackLocation(lines.join(
|
|
165
|
+
const loc = extractJsStackLocation(lines.join('\n'));
|
|
158
166
|
const file = loc.file ? path.relative(cwd, path.resolve(cwd, loc.file)) : undefined;
|
|
159
167
|
|
|
160
168
|
return { id: name, file, line: loc.line, message };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import type { ParserModule, ParsedFailure } from
|
|
3
|
-
import { safeReadFile } from
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
+
import { safeReadFile } from './utils';
|
|
4
4
|
|
|
5
5
|
interface BanditResult {
|
|
6
6
|
filename: string;
|
|
@@ -16,14 +16,14 @@ interface BanditOutput {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
const parser: ParserModule = {
|
|
19
|
-
id:
|
|
19
|
+
id: 'bandit-json',
|
|
20
20
|
async parse(ctx) {
|
|
21
21
|
const stdout = safeReadFile(ctx.stdoutPath).trim();
|
|
22
22
|
if (!stdout) {
|
|
23
23
|
return {
|
|
24
|
-
tool:
|
|
25
|
-
status:
|
|
26
|
-
summary:
|
|
24
|
+
tool: 'bandit',
|
|
25
|
+
status: 'pass',
|
|
26
|
+
summary: 'no security issues',
|
|
27
27
|
failures: [],
|
|
28
28
|
logPath: ctx.logPath,
|
|
29
29
|
};
|
|
@@ -34,9 +34,9 @@ const parser: ParserModule = {
|
|
|
34
34
|
output = JSON.parse(stdout);
|
|
35
35
|
} catch {
|
|
36
36
|
return {
|
|
37
|
-
tool:
|
|
38
|
-
status:
|
|
39
|
-
summary:
|
|
37
|
+
tool: 'bandit',
|
|
38
|
+
status: 'error',
|
|
39
|
+
summary: 'failed to parse bandit JSON output',
|
|
40
40
|
logPath: ctx.logPath,
|
|
41
41
|
};
|
|
42
42
|
}
|
|
@@ -58,16 +58,18 @@ const parser: ParserModule = {
|
|
|
58
58
|
const sev = r.issue_severity.toLowerCase();
|
|
59
59
|
bySeverity[sev] = (bySeverity[sev] ?? 0) + 1;
|
|
60
60
|
}
|
|
61
|
-
const sevParts = [
|
|
61
|
+
const sevParts = ['high', 'medium', 'low']
|
|
62
|
+
.filter((s) => bySeverity[s])
|
|
63
|
+
.map((s) => `${bySeverity[s]} ${s}`);
|
|
62
64
|
|
|
63
65
|
const summary =
|
|
64
66
|
results.length > 0
|
|
65
|
-
? `${results.length} issue${results.length !== 1 ?
|
|
66
|
-
:
|
|
67
|
+
? `${results.length} issue${results.length !== 1 ? 's' : ''} (${sevParts.join(', ')})`
|
|
68
|
+
: 'no security issues';
|
|
67
69
|
|
|
68
70
|
return {
|
|
69
|
-
tool:
|
|
70
|
-
status: failures.length > 0 ?
|
|
71
|
+
tool: 'bandit',
|
|
72
|
+
status: failures.length > 0 ? 'fail' : 'pass',
|
|
71
73
|
summary,
|
|
72
74
|
failures,
|
|
73
75
|
logPath: ctx.logPath,
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import type { ParserModule, ParsedFailure } from
|
|
3
|
-
import { safeReadFile } from
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
+
import { safeReadFile } from './utils';
|
|
4
4
|
|
|
5
5
|
const REFORMAT_LINE = /^would reformat (.+)$/;
|
|
6
6
|
const ERROR_FORMAT = /^error: cannot format (.+?): (.+)$/;
|
|
7
7
|
|
|
8
8
|
const parser: ParserModule = {
|
|
9
|
-
id:
|
|
9
|
+
id: 'black-text',
|
|
10
10
|
async parse(ctx) {
|
|
11
|
-
const combined = (safeReadFile(ctx.stdoutPath) +
|
|
11
|
+
const combined = (safeReadFile(ctx.stdoutPath) + '\n' + safeReadFile(ctx.stderrPath)).trim();
|
|
12
12
|
if (!combined) {
|
|
13
13
|
return {
|
|
14
|
-
tool:
|
|
15
|
-
status:
|
|
16
|
-
summary:
|
|
14
|
+
tool: 'black',
|
|
15
|
+
status: 'pass',
|
|
16
|
+
summary: 'all files formatted',
|
|
17
17
|
failures: [],
|
|
18
18
|
logPath: ctx.logPath,
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const lines = combined.split(
|
|
22
|
+
const lines = combined.split('\n');
|
|
23
23
|
const failures: ParsedFailure[] = [];
|
|
24
24
|
for (const line of lines) {
|
|
25
25
|
const reformatMatch = line.match(REFORMAT_LINE);
|
|
@@ -28,7 +28,7 @@ const parser: ParserModule = {
|
|
|
28
28
|
failures.push({
|
|
29
29
|
id: relPath,
|
|
30
30
|
file: relPath,
|
|
31
|
-
message:
|
|
31
|
+
message: 'would reformat',
|
|
32
32
|
});
|
|
33
33
|
continue;
|
|
34
34
|
}
|
|
@@ -46,11 +46,11 @@ const parser: ParserModule = {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// If "All done!" and no reformats needed
|
|
49
|
-
if (failures.length === 0 && combined.includes(
|
|
49
|
+
if (failures.length === 0 && combined.includes('All done!')) {
|
|
50
50
|
return {
|
|
51
|
-
tool:
|
|
52
|
-
status:
|
|
53
|
-
summary:
|
|
51
|
+
tool: 'black',
|
|
52
|
+
status: 'pass',
|
|
53
|
+
summary: 'all files formatted',
|
|
54
54
|
failures: [],
|
|
55
55
|
logPath: ctx.logPath,
|
|
56
56
|
};
|
|
@@ -58,12 +58,12 @@ const parser: ParserModule = {
|
|
|
58
58
|
|
|
59
59
|
const summary =
|
|
60
60
|
failures.length > 0
|
|
61
|
-
? `${failures.length} file${failures.length !== 1 ?
|
|
62
|
-
:
|
|
61
|
+
? `${failures.length} file${failures.length !== 1 ? 's' : ''} would be reformatted`
|
|
62
|
+
: 'all files formatted';
|
|
63
63
|
|
|
64
64
|
return {
|
|
65
|
-
tool:
|
|
66
|
-
status: failures.length > 0 ?
|
|
65
|
+
tool: 'black',
|
|
66
|
+
status: failures.length > 0 ? 'fail' : 'pass',
|
|
67
67
|
summary,
|
|
68
68
|
failures,
|
|
69
69
|
logPath: ctx.logPath,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import path from
|
|
2
|
-
import type { ParserModule, ParsedFailure } from
|
|
3
|
-
import { safeReadFile } from
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { ParserModule, ParsedFailure } from '../types';
|
|
3
|
+
import { safeReadFile } from './utils';
|
|
4
4
|
|
|
5
5
|
interface CargoSpan {
|
|
6
6
|
file_name: string;
|
|
@@ -21,19 +21,19 @@ interface CargoMessage {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
interface CargoCompilerMessage {
|
|
24
|
-
reason:
|
|
24
|
+
reason: 'compiler-message';
|
|
25
25
|
message: CargoMessage;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const parser: ParserModule = {
|
|
29
|
-
id:
|
|
29
|
+
id: 'cargo-build',
|
|
30
30
|
async parse(ctx) {
|
|
31
31
|
// --message-format=json writes NDJSON to stdout; one JSON object per line
|
|
32
32
|
const stdout = safeReadFile(ctx.stdoutPath);
|
|
33
33
|
const failures: ParsedFailure[] = [];
|
|
34
34
|
|
|
35
|
-
for (const line of stdout.split(
|
|
36
|
-
if (!line.trim().startsWith(
|
|
35
|
+
for (const line of stdout.split('\n')) {
|
|
36
|
+
if (!line.trim().startsWith('{')) continue;
|
|
37
37
|
let obj: Partial<CargoCompilerMessage>;
|
|
38
38
|
try {
|
|
39
39
|
obj = JSON.parse(line);
|
|
@@ -41,18 +41,20 @@ const parser: ParserModule = {
|
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
if (obj.reason !==
|
|
44
|
+
if (obj.reason !== 'compiler-message') continue;
|
|
45
45
|
const msg = obj.message;
|
|
46
|
-
if (!msg || msg.level !==
|
|
46
|
+
if (!msg || msg.level !== 'error') continue;
|
|
47
47
|
|
|
48
48
|
const primarySpan = msg.spans?.find((s) => s.is_primary);
|
|
49
|
-
const file = primarySpan
|
|
49
|
+
const file = primarySpan
|
|
50
|
+
? path.relative(ctx.cwd, path.resolve(ctx.cwd, primarySpan.file_name))
|
|
51
|
+
: undefined;
|
|
50
52
|
const lineNum = primarySpan?.line_start;
|
|
51
53
|
const label = primarySpan?.label ?? undefined;
|
|
52
54
|
const code = msg.code?.code;
|
|
53
55
|
|
|
54
56
|
failures.push({
|
|
55
|
-
id: [file, lineNum, code].filter(Boolean).join(
|
|
57
|
+
id: [file, lineNum, code].filter(Boolean).join(':'),
|
|
56
58
|
file,
|
|
57
59
|
line: lineNum,
|
|
58
60
|
// Surface the primary span label (e.g. "expected `i32`, found `&str`") as a second line
|
|
@@ -62,9 +64,12 @@ const parser: ParserModule = {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
return {
|
|
65
|
-
tool:
|
|
66
|
-
status: failures.length > 0 ?
|
|
67
|
-
summary:
|
|
67
|
+
tool: 'cargo',
|
|
68
|
+
status: failures.length > 0 ? 'fail' : 'pass',
|
|
69
|
+
summary:
|
|
70
|
+
failures.length > 0
|
|
71
|
+
? `${failures.length} error${failures.length === 1 ? '' : 's'}`
|
|
72
|
+
: 'build succeeded',
|
|
68
73
|
failures,
|
|
69
74
|
logPath: ctx.logPath,
|
|
70
75
|
};
|