fix(browser): show saved screenshot path
This commit is contained in:
@@ -23,6 +23,7 @@ import { formatDimensionNote, resizeImage } from "../utils/image-resize";
|
||||
import { htmlToBasicMarkdown } from "../web/scrapers/types";
|
||||
import type { OutputMeta } from "./output-meta";
|
||||
import { expandPath } from "./path-utils";
|
||||
import { formatSavedScreenshotLine } from "./render-utils";
|
||||
import stealthTamperingScript from "./puppeteer/00_stealth_tampering.txt" with { type: "text" };
|
||||
import stealthActivityScript from "./puppeteer/01_stealth_activity.txt" with { type: "text" };
|
||||
import stealthHairlineScript from "./puppeteer/02_stealth_hairline.txt" with { type: "text" };
|
||||
@@ -1394,7 +1395,7 @@ export class BrowserTool implements AgentTool<typeof browserSchema, BrowserToolD
|
||||
|
||||
const lines = ["Screenshot captured"];
|
||||
if (saveFullRes) {
|
||||
lines.push(`Saved: ${savedMimeType} (${(savedBuffer.length / 1024).toFixed(2)} KB)`);
|
||||
lines.push(formatSavedScreenshotLine(savedMimeType, savedBuffer.length, dest));
|
||||
lines.push(
|
||||
`Model: ${resized.mimeType} (${(resized.buffer.length / 1024).toFixed(2)} KB, ${resized.width}x${resized.height})`,
|
||||
);
|
||||
|
||||
@@ -527,6 +527,10 @@ export function shortenPath(filePath: string, homeDir?: string): string {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
export function formatSavedScreenshotLine(mimeType: string, byteLength: number, filePath: string): string {
|
||||
return `Saved: ${mimeType} (${(byteLength / 1024).toFixed(2)} KB) to ${shortenPath(filePath)}`;
|
||||
}
|
||||
|
||||
export function wrapBrackets(text: string, theme: Theme): string {
|
||||
return `${theme.format.bracketLeft}${text}${theme.format.bracketRight}`;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { dedupeParseErrors, formatParseErrors } from "@oh-my-pi/pi-coding-agent/tools/render-utils";
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import { dedupeParseErrors, formatParseErrors, formatSavedScreenshotLine } from "@oh-my-pi/pi-coding-agent/tools/render-utils";
|
||||
|
||||
describe("parse error formatting", () => {
|
||||
it("deduplicates parse errors while preserving order", () => {
|
||||
@@ -30,3 +32,19 @@ describe("parse error formatting", () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("browser screenshot path formatting", () => {
|
||||
it("shows home-relative saved paths with tilde shorthand", () => {
|
||||
const filePath = path.join(os.homedir(), "screenshots", "capture.png");
|
||||
|
||||
expect(formatSavedScreenshotLine("image/png", 2048, filePath)).toBe(
|
||||
"Saved: image/png (2.00 KB) to ~/screenshots/capture.png",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps non-home saved paths unchanged", () => {
|
||||
expect(formatSavedScreenshotLine("image/png", 2048, "/tmp/capture.png")).toBe(
|
||||
"Saved: image/png (2.00 KB) to /tmp/capture.png",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user