Willem van den Ende a43b58f7cf refactor: remove duplication
Parsing no longer depends on ui widget
2026-06-28 12:21:54 +02:00

24 lines
1.0 KiB
TypeScript

import {type ExtensionAPI, isBashToolResult, ThemeColor} from "@earendil-works/pi-coding-agent";
import {isTestCommand, parseTestOutput} 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;
const testResult = parseTestOutput(output);
const feedbackTheme : ThemeColor = (testResult.status === "Success") ? "success" : "error";
ctx.ui.setWidget("test-status", [
`${theme.fg(feedbackTheme, "●")} ${theme.fg("text", testResult.summary)}`,
]);
});
}