Skip to content

Commit 203728d

Browse files
committed
Improve command output handling: return specific success message for empty output
1 parent 1d94261 commit 203728d

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/agent/state.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ export const useStore = create<AppState & AppActions>((set, get) => ({
240240
{ toolName: toolCall.toolName, args: toolCall.input },
241241
config,
242242
);
243+
const output =
244+
result === ""
245+
? "Tool executed successfully and produced no output."
246+
: result;
243247
toolResults.push({
244248
id: crypto.randomUUID(),
245249
role: "tool",
@@ -249,7 +253,7 @@ export const useStore = create<AppState & AppActions>((set, get) => ({
249253
toolCallId: toolCall.toolCallId,
250254
toolName: toolCall.toolName,
251255
// eslint-disable-next-line @typescript-eslint/no-explicit-any
252-
output: result as any,
256+
output: output as any,
253257
},
254258
],
255259
});

src/agent/tools/definitions/bash.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ async function implementation(args: z.infer<typeof bashSchema>["arguments"]): Pr
4242

4343
child.on("close", (code) => {
4444
if (code === 0) {
45-
resolve(output);
45+
if (output.trim() === "") {
46+
resolve("Command executed successfully with no output.");
47+
} else {
48+
resolve(output);
49+
}
4650
} else {
4751
reject(new ToolError(`Command exited with code: ${code}\nOutput:\n${output}`));
4852
}

tests/agent/tools/definitions/bash.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe("bash tool", () => {
5353

5454
childProcessMock.emit("close", 0);
5555

56-
await expect(promise).resolves.toBe("");
56+
await expect(promise).resolves.toBe("Command executed successfully with no output.");
5757
expect(spawnMock).toHaveBeenCalledWith("sleep 5", {
5858
cwd: process.cwd(),
5959
shell: "/bin/bash",

0 commit comments

Comments
 (0)