From 2ed95634fe636e9a686c145c0966c80ead3fb396 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 12 Jan 2026 18:12:51 +0000 Subject: [PATCH] fix: relax image tool agentDir guard --- src/agents/pi-embedded-runner.test.ts | 8 ++++++-- src/agents/sandbox-explain.test.ts | 4 ++-- src/agents/tools/image-tool.ts | 10 +++++++--- src/cli/models-cli.test.ts | 8 ++++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/agents/pi-embedded-runner.test.ts b/src/agents/pi-embedded-runner.test.ts index faa82b9c8..5cfaf41b6 100644 --- a/src/agents/pi-embedded-runner.test.ts +++ b/src/agents/pi-embedded-runner.test.ts @@ -703,7 +703,9 @@ describe("runEmbeddedPiAgent", () => { ).resolves.toBeTruthy(); }); - it("persists the first user message before assistant output", async () => { + it( + "persists the first user message before assistant output", + async () => { const agentDir = await fs.mkdtemp( path.join(os.tmpdir(), "clawdbot-agent-"), ); @@ -741,7 +743,9 @@ describe("runEmbeddedPiAgent", () => { if (firstAssistantIndex !== -1) { expect(firstUserIndex).toBeLessThan(firstAssistantIndex); } - }); + }, + 15_000, + ); it("persists the user message when prompt fails before assistant output", async () => { const agentDir = await fs.mkdtemp( diff --git a/src/agents/sandbox-explain.test.ts b/src/agents/sandbox-explain.test.ts index f596e6e69..27bbd7a57 100644 --- a/src/agents/sandbox-explain.test.ts +++ b/src/agents/sandbox-explain.test.ts @@ -25,11 +25,11 @@ describe("sandbox explain helpers", () => { }; const resolved = resolveSandboxConfigForAgent(cfg, "work"); - expect(resolved.tools.allow).toEqual(["write"]); + expect(resolved.tools.allow).toEqual(["write", "image"]); expect(resolved.tools.deny).toEqual(["browser"]); const policy = resolveSandboxToolPolicyForAgent(cfg, "work"); - expect(policy.allow).toEqual(["write"]); + expect(policy.allow).toEqual(["write", "image"]); expect(policy.sources.allow.source).toBe("agent"); expect(policy.deny).toEqual(["browser"]); expect(policy.sources.deny.source).toBe("global"); diff --git a/src/agents/tools/image-tool.ts b/src/agents/tools/image-tool.ts index c309695a4..7b6b6628d 100644 --- a/src/agents/tools/image-tool.ts +++ b/src/agents/tools/image-tool.ts @@ -299,9 +299,13 @@ export function createImageTool(options?: { agentDir?: string; sandboxRoot?: string; }): AnyAgentTool | null { - const agentDir = options?.agentDir; - if (!agentDir?.trim()) { - throw new Error("createImageTool requires agentDir when enabled"); + const agentDir = options?.agentDir?.trim(); + if (!agentDir) { + const explicit = coerceImageModelConfig(options?.config); + if (explicit.primary?.trim() || (explicit.fallbacks?.length ?? 0) > 0) { + throw new Error("createImageTool requires agentDir when enabled"); + } + return null; } const imageModelConfig = resolveImageModelConfigForTool({ cfg: options?.config, diff --git a/src/cli/models-cli.test.ts b/src/cli/models-cli.test.ts index 81cd36ed8..d959981a7 100644 --- a/src/cli/models-cli.test.ts +++ b/src/cli/models-cli.test.ts @@ -14,7 +14,9 @@ vi.mock("../commands/models.js", async () => { }); describe("models cli", () => { - it("registers github-copilot login command", async () => { + it( + "registers github-copilot login command", + async () => { const { Command } = await import("commander"); const { registerModelsCli } = await import("./models-cli.js"); @@ -44,5 +46,7 @@ describe("models cli", () => { expect.objectContaining({ yes: true }), expect.any(Object), ); - }); + }, + 15_000, + ); });