Skip to content

Commit f0aa229

Browse files
TurboTheTurtleclawsweeper[bot]
authored andcommitted
fix(images): skip CLI image cache refs
1 parent 7275304 commit f0aa229

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

src/agents/cli-runner.helpers.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ describe("loadPromptRefImages", () => {
3939
expect(sanitizeImageBlocksSpy).not.toHaveBeenCalled();
4040
});
4141

42+
it("does not reload OpenClaw CLI image cache paths from prior prompt text", async () => {
43+
const loadImageFromRefSpy = vi.spyOn(promptImageUtils, "loadImageFromRef");
44+
const sanitizeImageBlocksSpy = vi.spyOn(toolImages, "sanitizeImageBlocks");
45+
46+
await expect(
47+
loadPromptRefImages({
48+
prompt:
49+
'Called the Read tool with {"file_path":"/workspace/.openclaw-cli-images/stale.png"}',
50+
workspaceDir: "/workspace",
51+
}),
52+
).resolves.toStrictEqual([]);
53+
54+
expect(loadImageFromRefSpy).not.toHaveBeenCalled();
55+
expect(sanitizeImageBlocksSpy).not.toHaveBeenCalled();
56+
});
57+
4258
it("passes the max-byte guardrail through load and sanitize", async () => {
4359
const loadedImage: ImageContent = {
4460
type: "image",

src/agents/embedded-agent-runner/run/images.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,35 @@ describe("detectImageReferences", () => {
8181
});
8282
});
8383

84+
it("ignores OpenClaw CLI image cache paths from prior prompt transcripts", () => {
85+
const refs = detectImageReferences(
86+
[
87+
'<system-reminder>Called the Read tool with {"file_path":"/Users/ada/.openclaw/workspace/.openclaw-cli-images/stale.png"}</system-reminder>',
88+
"Compare it with /Users/ada/Pictures/current.png",
89+
].join("\n"),
90+
);
91+
92+
expect(refs).toStrictEqual([
93+
{
94+
raw: "/Users/ada/Pictures/current.png",
95+
type: "path",
96+
resolved: "/Users/ada/Pictures/current.png",
97+
},
98+
]);
99+
});
100+
101+
it("ignores temporary OpenClaw CLI image cache paths", () => {
102+
expectNoImageReferences(
103+
`Prior turn wrote ${path.join(os.tmpdir(), "openclaw-cli-images", "stale.jpg")}`,
104+
);
105+
});
106+
107+
it("ignores file URLs into the OpenClaw CLI image cache", () => {
108+
const stalePath = path.join(os.tmpdir(), "openclaw-cli-images", "stale.png");
109+
110+
expectNoImageReferences(`Prior turn wrote ${pathToFileURL(stalePath).href}`);
111+
});
112+
84113
it("detects multiple image references in a prompt", () => {
85114
const refs = expectImageReferenceCount(
86115
`

src/agents/embedded-agent-runner/run/images.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ function normalizeRefForDedupe(raw: string): string {
102102
return process.platform === "win32" ? normalizeLowercaseStringOrEmpty(raw) : raw;
103103
}
104104

105+
function isOpenClawCliImageCachePath(filePath: string): boolean {
106+
const normalized = filePath.replaceAll("\\", "/");
107+
return normalized.split("/").some((part) => {
108+
return part === ".openclaw-cli-images" || part === "openclaw-cli-images";
109+
});
110+
}
111+
105112
export function mergePromptAttachmentImages(params: {
106113
imageOrder?: PromptImageOrderEntry[];
107114
existingImages?: ImageContent[];
@@ -321,8 +328,11 @@ export function detectImageReferences(prompt: string): DetectedImageRef[] {
321328
} catch {
322329
return;
323330
}
324-
seen.add(dedupeKey);
325331
const resolved = trimmed.startsWith("~") ? resolveUserPath(trimmed) : trimmed;
332+
if (isOpenClawCliImageCachePath(resolved)) {
333+
return;
334+
}
335+
seen.add(dedupeKey);
326336
refs.push({ raw: trimmed, type: "path", resolved });
327337
};
328338

@@ -388,6 +398,9 @@ export function detectImageReferences(prompt: string): DetectedImageRef[] {
388398
// Use fileURLToPath for proper handling (e.g., file://localhost/path)
389399
try {
390400
const resolved = safeFileURLToPath(raw);
401+
if (isOpenClawCliImageCachePath(resolved)) {
402+
continue;
403+
}
391404
refs.push({ raw, type: "path", resolved });
392405
} catch {
393406
// Skip malformed file:// URLs

0 commit comments

Comments
 (0)