Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(cli): reject extra edit arguments with named targets

Afloat3cdceb5df5da
diff --git a/server/headless/commands.ts b/server/headless/commands.ts
index 351fdbfd71..33734dd6b2 100644
--- a/server/headless/commands.ts
+++ b/server/headless/commands.ts
@@ -216,6 +216,8 @@ export async function setModel(ctx: VerbContext): Promise<VerbOutcome> {
export async function edit(ctx: VerbContext): Promise<VerbOutcome> {
const named = Boolean(flag(ctx.flags, "bot") ?? flag(ctx.flags, "channel") ?? flag(ctx.flags, "thread"));
const [first, second] = ctx.positionals;
+ if (named && second !== undefined) throw usageError("edit with a named target takes at most one message argument",
+ "openmausbot edit --thread ID --message ID TEXT, or edit BOT --message ID TEXT");
if (!named && !first) throw usageError("a bot is required", "openmausbot edit BOT --message ID TEXT, or --bot ID or --thread ID");
const messageId = requiredFlag(ctx.flags, "message");
const text = await readMessage(ctx, named ? first : second);
diff --git a/server/headless/edit.test.ts b/server/headless/edit.test.ts
index 306364a982..f9184bde5d 100644
--- a/server/headless/edit.test.ts
+++ b/server/headless/edit.test.ts
@@ -45,6 +45,24 @@ describe("edit conversation selection", () => {
}, expect.any(Function), undefined, undefined);
});
+ it("keeps a positional bot and message", async () => {
+ const h = harness();
+ expect((await h.run(["Lead", "Corrected request"])).code).toBe(0);
+ expect(h.callTool).toHaveBeenCalledWith("edit_bot_message", {
+ bot_id: "lead", message_id: "m1", text: "Corrected request",
+ }, expect.any(Function), undefined, undefined);
+ });
+
+ it.each([["--thread", "earlier"], ["--bot", "lead"]])(
+ "refuses a positional bot and message alongside %j before editing", async (...target) => {
+ const h = harness();
+ const result = await h.run(["Lead", "Corrected request", ...target]);
+ expect(result.code).toBe(2);
+ expect(result.result).toMatchObject({ ok: false, error: expect.stringContaining("one message argument") });
+ expect(h.callTool).not.toHaveBeenCalled();
+ },
+ );
+
it("previews the selected thread without editing it", async () => {
const h = harness();
const preview = await h.run(["--thread", "earlier", "--text", "Corrected request", "--dry-run"]);