@@ -10,14 +10,25 @@ import {
1010 fauxToolCall,
1111 registerFauxProvider,
1212 } from "@mariozechner/pi-ai";
13-import { type AgentEvent, type AgentTool, runAgentLoop } from "./agent.ts";
13+import {
14+ type AgentEvent,
15+ type AgentTool,
16+ runAgentLoop,
17+ type ToolExecResult,
18+} from "./agent.ts";
1419 import {
1520 appendMessage,
1621 createSession,
1722 loadMessages,
1823 openDatabase,
1924 } from "./session.ts";
20-import { editTool, executeEdit, executeShell, shellTool } from "./tools.ts";
25+import {
26+ editTool,
27+ executeEdit,
28+ executeShell,
29+ shellTool,
30+ type ToolResult,
31+} from "./tools.ts";
2132
2233 // ---------------------------------------------------------------------------
2334 // Helpers
@@ -43,24 +54,33 @@ function makeUser(text: string): UserMessage {
4354 return { role: "user", content: text, timestamp: Date.now() };
4455 }
4556
57+/** Wrap a text-only ToolResult into a ToolExecResult with content blocks. */
58+function wrapResult(r: ToolResult): ToolExecResult {
59+ return { content: [{ type: "text", text: r.text }], isError: r.isError };
60+}
61+
4662 /** Create standard built-in tools for tests. */
4763 function builtinTools(): AgentTool[] {
4864 return [
4965 {
5066 definition: shellTool,
51- execute: (args, cwd) =>
52- executeShell({ command: args.command as string }, cwd),
67+ execute: async (args, cwd) =>
68+ wrapResult(
69+ await executeShell({ command: args.command as string }, cwd),
70+ ),
5371 },
5472 {
5573 definition: editTool,
5674 execute: (args, cwd) =>
57- executeEdit(
58- {
59- path: args.path as string,
60- oldText: args.oldText as string,
61- newText: args.newText as string,
62- },
63- cwd,
75+ wrapResult(
76+ executeEdit(
77+ {
78+ path: args.path as string,
79+ oldText: args.oldText as string,
80+ newText: args.newText as string,
81+ },
82+ cwd,
83+ ),
6484 ),
6585 },
6686 ];