24 lines
1.0 KiB
TypeScript
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)}`,
|
|
]);
|
|
});
|
|
}
|