Gate lobster plugin tool in sandboxed contexts

This commit is contained in:
Vignesh Natarajan
2026-01-17 20:33:31 -08:00
parent b2650ba672
commit e011c764a7
2 changed files with 33 additions and 2 deletions

View File

@@ -3,5 +3,11 @@ import type { ClawdbotPluginApi } from "../../src/plugins/types.js";
import { createLobsterTool } from "./src/lobster-tool.js";
export default function register(api: ClawdbotPluginApi) {
api.registerTool(createLobsterTool(api), { optional: true });
api.registerTool(
(ctx) => {
if (ctx.sandboxed) return null;
return createLobsterTool(api);
},
{ optional: true },
);
}

View File

@@ -4,7 +4,7 @@ import path from "node:path";
import { describe, expect, it } from "vitest";
import type { ClawdbotPluginApi } from "../../../src/plugins/types.js";
import type { ClawdbotPluginApi, ClawdbotPluginToolContext } from "../../../src/plugins/types.js";
import { createLobsterTool } from "./lobster-tool.js";
async function writeFakeLobster(params: {
@@ -39,6 +39,20 @@ function fakeApi(): ClawdbotPluginApi {
};
}
function fakeCtx(overrides: Partial<ClawdbotPluginToolContext> = {}): ClawdbotPluginToolContext {
return {
config: {} as any,
workspaceDir: "/tmp",
agentDir: "/tmp",
agentId: "main",
sessionKey: "main",
messageChannel: undefined,
agentAccountId: undefined,
sandboxed: false,
...overrides,
};
}
describe("lobster plugin tool", () => {
it("runs lobster and returns parsed envelope in details", async () => {
const fake = await writeFakeLobster({
@@ -84,4 +98,15 @@ describe("lobster plugin tool", () => {
}),
).rejects.toThrow(/invalid JSON/);
});
it("can be gated off in sandboxed contexts", async () => {
const api = fakeApi();
const factoryTool = (ctx: ClawdbotPluginToolContext) => {
if (ctx.sandboxed) return null;
return createLobsterTool(api);
};
expect(factoryTool(fakeCtx({ sandboxed: true }))).toBeNull();
expect(factoryTool(fakeCtx({ sandboxed: false }))?.name).toBe("lobster");
});
});