diff --git a/frontend/packages/swarm-ui/src/agent/terminal/AgentInputForm.tsx b/frontend/packages/swarm-ui/src/agent/terminal/AgentInputForm.tsx index 309d9e9f5..efa1f4e7d 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/AgentInputForm.tsx +++ b/frontend/packages/swarm-ui/src/agent/terminal/AgentInputForm.tsx @@ -24,6 +24,7 @@ import { enterSends, matchCommands, menuQuery, + textToSend, moveSelection, type AgentCommand, } from "./command-menu.js"; @@ -61,7 +62,7 @@ export function AgentInputForm({ agentName }: { agentName: string }) { : fetch(`${base}/input`, { method: "POST", headers: { "content-type": "application/json" }, - body: JSON.stringify({ body }), + body: JSON.stringify({ body: textToSend(body) }), }), { onDone: () => setBody("") }, ); diff --git a/frontend/packages/swarm-ui/src/agent/terminal/command-menu.ts b/frontend/packages/swarm-ui/src/agent/terminal/command-menu.ts index 16fb9fb96..3daa31e1f 100644 --- a/frontend/packages/swarm-ui/src/agent/terminal/command-menu.ts +++ b/frontend/packages/swarm-ui/src/agent/terminal/command-menu.ts @@ -108,3 +108,14 @@ export function controlRoute( commands.some((c) => c.kind === "command" && c.name === "clear"); return isClear ? "new-session" : null; } + +/** + * The text to send for what the box holds: a lone `/word`, which completion + * leaves with a space after it, goes without that space, so a command such as + * `/compact` reaches the agent exactly as typed by hand. Any other message goes + * as it is. + */ +export function textToSend(text: string): string { + const trimmed = text.trim(); + return menuQuery(trimmed) === null ? text : trimmed; +} diff --git a/frontend/packages/swarm-ui/test/command-menu.test.mjs b/frontend/packages/swarm-ui/test/command-menu.test.mjs index 83d309147..53166c9a1 100644 --- a/frontend/packages/swarm-ui/test/command-menu.test.mjs +++ b/frontend/packages/swarm-ui/test/command-menu.test.mjs @@ -10,6 +10,7 @@ import { menuQuery, moveSelection, splitName, + textToSend, } from "../src/agent/terminal/command-menu.ts"; const cmd = (name, kind = "command", description = "") => ({ @@ -113,3 +114,16 @@ test("without the backend's /clear command, or with a skill of that name, it is assert.equal(controlRoute("/clear", []), null); assert.equal(controlRoute("/clear", [cmd("clear", "skill")]), null); }); + +test("a lone slash word goes without the space completion left", () => { + assert.equal(textToSend("/compact "), "/compact"); + assert.equal(textToSend("/compact"), "/compact"); + assert.equal(textToSend(" /base:pr-review "), "/base:pr-review"); +}); + +test("any other message goes as it is", () => { + assert.equal(textToSend("hello "), "hello "); + assert.equal(textToSend("/compact now "), "/compact now "); + assert.equal(textToSend("fix /etc/hosts"), "fix /etc/hosts"); + assert.equal(textToSend(" "), " "); +});