Start factoring out code from initial spike

This commit is contained in:
2026-06-28 11:12:09 +02:00
parent 2dfafe23d6
commit f521fb3da9
11 changed files with 2494 additions and 1685 deletions
+43
View File
@@ -0,0 +1,43 @@
import {type ExtensionAPI, isBashToolResult} from "@earendil-works/pi-coding-agent";
import {isTestCommand} from "./parsing/typescript-command-output";
// noinspection JSUnusedGlobalSymbols
export default function testStatusExtension(pi: ExtensionAPI) {
// After every tool execution, check if tests just ran
pi.on("tool_result", async (event, ctx) => {
// Only care about bash commands
if (!isBashToolResult(event)) return;
if (!isTestCommand(event.input.command as string) ) return;
const textContent = event.content.find((c): c is { type: "text"; text: string } => c.type === "text");
const output = textContent?.text ?? "";
const theme = ctx.ui.theme;
// Detect pass/fail from vitest summary output
const testsPassed =
/Tests\s+.+passed/.test(output) && !/Tests\s+.+failed/.test(output);
const testsFailed =
/Tests\s+.+failed/.test(output) || event.details?.exitCode !== 0;
if (testsPassed) {
// Extract summary line for inline detail (e.g., "1 passed (242ms)")
const summaryLine = output
.split("\n")
.find((line: string) => /Test Files\s+.+passed/.test(line));
const summary = summaryLine?.trim() ?? "All tests passed";
ctx.ui.setWidget("test-status", [
`${theme.fg("success", "●")} ${theme.fg("text", summary)}`,
]);
} else if (testsFailed) {
const summaryLine = output
.split("\n")
.find((line: string) => /Tests\s+.+failed/.test(line));
const summary = summaryLine?.trim() ?? "Tests failed";
ctx.ui.setWidget("test-status", [
`${theme.fg("error", "●")} ${theme.fg("text", summary)}`,
]);
}
});
}
@@ -0,0 +1,3 @@
export const isTestCommand = (command: string) => {
return command.includes("npm test") || command.includes("vitest")
}