fix(image): propagate workspace root for image allowlist (#16722)
Merged via /review-pr -> /prepare-pr -> /merge-pr. Prepared head SHA: 24a13675cbc71b261726d83656233691e2e44b0e Co-authored-by: steipete <58493+steipete@users.noreply.github.com> Co-authored-by: steipete <58493+steipete@users.noreply.github.com> Reviewed-by: @steipete
This commit is contained in:
committed by
GitHub
parent
69dd1a31bf
commit
b79e7fdb7a
@@ -25,6 +25,7 @@ Docs: https://docs.openclaw.ai
|
||||
- WhatsApp: honor per-account `dmPolicy` overrides (account-level settings now take precedence over channel defaults for inbound DMs). (#10082) Thanks @mcaxtr.
|
||||
- Media: accept `MEDIA:`-prefixed paths (lenient whitespace) when loading outbound media to prevent `ENOENT` for tool-returned local media paths. (#13107) Thanks @mcaxtr.
|
||||
- Agents/Image tool: allow workspace-local image paths by including the active workspace directory in local media allowlists, and trust sandbox-validated paths in image loaders to prevent false "not under an allowed directory" rejections. (#15541)
|
||||
- Agents/Image tool: propagate the effective workspace root into tool wiring so workspace-local image paths are accepted by default when running without an explicit `workspaceDir`. (#16722)
|
||||
- Cron/Slack: preserve agent identity (name and icon) when cron jobs deliver outbound messages. (#16242) Thanks @robbyczgw-cla.
|
||||
- Cron: prevent `cron list`/`cron status` from silently skipping past-due recurring jobs by using maintenance recompute semantics. (#16156) Thanks @zerone0x.
|
||||
- Cron: repair missing/corrupt `nextRunAtMs` for the updated job without globally recomputing unrelated due jobs during `cron update`. (#15750)
|
||||
|
||||
@@ -60,11 +60,12 @@ export function createOpenClawTools(options?: {
|
||||
/** If true, omit the message tool from the tool list. */
|
||||
disableMessageTool?: boolean;
|
||||
}): AnyAgentTool[] {
|
||||
const workspaceDir = options?.workspaceDir?.trim() || process.cwd();
|
||||
const imageTool = options?.agentDir?.trim()
|
||||
? createImageTool({
|
||||
config: options?.config,
|
||||
agentDir: options.agentDir,
|
||||
workspaceDir: options?.workspaceDir,
|
||||
workspaceDir,
|
||||
sandbox:
|
||||
options?.sandboxRoot && options?.sandboxFsBridge
|
||||
? { root: options.sandboxRoot, bridge: options.sandboxFsBridge }
|
||||
@@ -157,7 +158,7 @@ export function createOpenClawTools(options?: {
|
||||
const pluginTools = resolvePluginTools({
|
||||
context: {
|
||||
config: options?.config,
|
||||
workspaceDir: options?.workspaceDir,
|
||||
workspaceDir,
|
||||
agentDir: options?.agentDir,
|
||||
agentId: resolveSessionAgentId({
|
||||
sessionKey: options?.agentSessionKey,
|
||||
|
||||
@@ -321,7 +321,7 @@ export function createOpenClawCodingTools(options?: {
|
||||
pathPrepend: options?.exec?.pathPrepend ?? execConfig.pathPrepend,
|
||||
safeBins: options?.exec?.safeBins ?? execConfig.safeBins,
|
||||
agentId,
|
||||
cwd: options?.workspaceDir,
|
||||
cwd: workspaceRoot,
|
||||
allowBackground,
|
||||
scopeKey,
|
||||
sessionKey: options?.sessionKey,
|
||||
@@ -386,7 +386,7 @@ export function createOpenClawCodingTools(options?: {
|
||||
agentDir: options?.agentDir,
|
||||
sandboxRoot,
|
||||
sandboxFsBridge,
|
||||
workspaceDir: options?.workspaceDir,
|
||||
workspaceDir: workspaceRoot,
|
||||
sandboxed: !!sandbox,
|
||||
config: options?.config,
|
||||
pluginToolAllowlist: collectExplicitAllowlist([
|
||||
|
||||
@@ -3,6 +3,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { createOpenClawCodingTools } from "../pi-tools.js";
|
||||
import { createHostSandboxFsBridge } from "../test-helpers/host-sandbox-fs-bridge.js";
|
||||
import { __testing, createImageTool, resolveImageModelConfigForTool } from "./image-tool.js";
|
||||
|
||||
@@ -219,6 +220,64 @@ describe("image tool implicit imageModel config", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("allows workspace images via createOpenClawCodingTools default workspace root", async () => {
|
||||
const workspaceParent = await fs.mkdtemp(
|
||||
path.join(process.cwd(), ".openclaw-workspace-image-"),
|
||||
);
|
||||
try {
|
||||
const workspaceDir = path.join(workspaceParent, "workspace");
|
||||
await fs.mkdir(workspaceDir, { recursive: true });
|
||||
const imagePath = path.join(workspaceDir, "photo.png");
|
||||
const pngB64 =
|
||||
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/woAAn8B9FD5fHAAAAAASUVORK5CYII=";
|
||||
await fs.writeFile(imagePath, Buffer.from(pngB64, "base64"));
|
||||
|
||||
const fetch = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
status: 200,
|
||||
statusText: "OK",
|
||||
headers: new Headers(),
|
||||
json: async () => ({
|
||||
content: "ok",
|
||||
base_resp: { status_code: 0, status_msg: "" },
|
||||
}),
|
||||
});
|
||||
// @ts-expect-error partial global
|
||||
global.fetch = fetch;
|
||||
vi.stubEnv("MINIMAX_API_KEY", "minimax-test");
|
||||
|
||||
const agentDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-image-"));
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
defaults: {
|
||||
model: { primary: "minimax/MiniMax-M2.1" },
|
||||
imageModel: { primary: "minimax/MiniMax-VL-01" },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const tools = createOpenClawCodingTools({ config: cfg, agentDir });
|
||||
const tool = tools.find((candidate) => candidate.name === "image");
|
||||
expect(tool).not.toBeNull();
|
||||
if (!tool) {
|
||||
throw new Error("expected image tool");
|
||||
}
|
||||
|
||||
await expect(
|
||||
tool.execute("t1", {
|
||||
prompt: "Describe the image.",
|
||||
image: imagePath,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
content: [{ type: "text", text: "ok" }],
|
||||
});
|
||||
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
await fs.rm(workspaceParent, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("sandboxes image paths like the read tool", async () => {
|
||||
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-image-sandbox-"));
|
||||
const agentDir = path.join(stateDir, "agent");
|
||||
|
||||
@@ -358,9 +358,14 @@ export function createImageTool(options?: {
|
||||
if (!workspaceDir) {
|
||||
return roots;
|
||||
}
|
||||
const normalized = workspaceDir.startsWith("~") ? resolveUserPath(workspaceDir) : workspaceDir;
|
||||
if (!roots.includes(normalized)) {
|
||||
roots.push(normalized);
|
||||
const expanded = workspaceDir.startsWith("~") ? resolveUserPath(workspaceDir) : workspaceDir;
|
||||
const resolved = path.resolve(expanded);
|
||||
// Defensive: never allow "/" as an implicit media root.
|
||||
if (resolved === path.parse(resolved).root) {
|
||||
return roots;
|
||||
}
|
||||
if (!roots.includes(resolved)) {
|
||||
roots.push(resolved);
|
||||
}
|
||||
return roots;
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user