Add blockImages setting to prevent images from being sent to LLM providers

- Setting controls filtering at convertToLlm layer (defense-in-depth)
- Images are always stored in session, filtered dynamically based on current setting
- Toggle mid-session works: LLM sees/doesn't see images already in session
- Fixed SettingsManager.save() to handle inMemory mode for all setters

Closes #492
This commit is contained in:
Mario Zechner 2026-01-06 11:59:09 +01:00
parent b582a6b70d
commit 1fc2a912d4
8 changed files with 80 additions and 127 deletions

View file

@ -54,42 +54,27 @@ describe("blockImages setting", () => {
rmSync(testDir, { recursive: true, force: true });
});
it("should return text message when blockImages is true", async () => {
it("should always read images (filtering happens at convertToLlm layer)", async () => {
// Create test image
const imagePath = join(testDir, "test.png");
writeFileSync(imagePath, Buffer.from(TINY_PNG_BASE64, "base64"));
const tool = createReadTool(testDir, { blockImages: true });
const tool = createReadTool(testDir);
const result = await tool.execute("test-1", { path: imagePath });
expect(result.content).toHaveLength(1);
expect(result.content[0].type).toBe("text");
const textContent = result.content[0] as { type: "text"; text: string };
expect(textContent.text).toContain("Image reading is disabled");
expect(textContent.text).toContain("blockImages");
});
it("should return image content when blockImages is false", async () => {
// Create test image
const imagePath = join(testDir, "test.png");
writeFileSync(imagePath, Buffer.from(TINY_PNG_BASE64, "base64"));
const tool = createReadTool(testDir, { blockImages: false });
const result = await tool.execute("test-2", { path: imagePath });
// Should have text note + image content
expect(result.content.length).toBeGreaterThanOrEqual(1);
const hasImage = result.content.some((c) => c.type === "image");
expect(hasImage).toBe(true);
});
it("should read text files normally even when blockImages is true", async () => {
it("should read text files normally", async () => {
// Create test text file
const textPath = join(testDir, "test.txt");
writeFileSync(textPath, "Hello, world!");
const tool = createReadTool(testDir, { blockImages: true });
const result = await tool.execute("test-3", { path: textPath });
const tool = createReadTool(testDir);
const result = await tool.execute("test-2", { path: textPath });
expect(result.content).toHaveLength(1);
expect(result.content[0].type).toBe("text");
@ -110,35 +95,23 @@ describe("blockImages setting", () => {
rmSync(testDir, { recursive: true, force: true });
});
it("should skip image files when blockImages is true", async () => {
it("should always process images (filtering happens at convertToLlm layer)", async () => {
// Create test image
const imagePath = join(testDir, "test.png");
writeFileSync(imagePath, Buffer.from(TINY_PNG_BASE64, "base64"));
const result = await processFileArguments([imagePath], { blockImages: true });
expect(result.images).toHaveLength(0);
// Text should be empty since image was skipped
expect(result.text).toBe("");
});
it("should include image files when blockImages is false", async () => {
// Create test image
const imagePath = join(testDir, "test.png");
writeFileSync(imagePath, Buffer.from(TINY_PNG_BASE64, "base64"));
const result = await processFileArguments([imagePath], { blockImages: false });
const result = await processFileArguments([imagePath]);
expect(result.images).toHaveLength(1);
expect(result.images[0].type).toBe("image");
});
it("should process text files normally when blockImages is true", async () => {
it("should process text files normally", async () => {
// Create test text file
const textPath = join(testDir, "test.txt");
writeFileSync(textPath, "Hello, world!");
const result = await processFileArguments([textPath], { blockImages: true });
const result = await processFileArguments([textPath]);
expect(result.images).toHaveLength(0);
expect(result.text).toContain("Hello, world!");