diff --git a/src/permissions/toolNameMapping.ts b/src/permissions/toolNameMapping.ts index b15f354e6..1aea0165c 100644 --- a/src/permissions/toolNameMapping.ts +++ b/src/permissions/toolNameMapping.ts @@ -13,6 +13,8 @@ const TOOL_NAME_MAPPINGS: Record = { Exit: "exit", Diff: "view_diff", Edit: "edit_file", + "Update Task List": "write_checklist", + Checklist: "write_checklist", // Common variations (case insensitive) read: "read_file", @@ -27,6 +29,7 @@ const TOOL_NAME_MAPPINGS: Record = { exit: "exit", diff: "view_diff", edit: "edit_file", + checklist: "write_checklist", // Actual tool names (passthrough) read_file: "read_file", @@ -36,6 +39,7 @@ const TOOL_NAME_MAPPINGS: Record = { run_terminal_command: "run_terminal_command", view_diff: "view_diff", edit_file: "edit_file", + write_checklist: "write_checklist", }; /** @@ -74,7 +78,8 @@ export function getDisplayName(normalizedName: string): string { fetch: "Fetch", exit: "Exit", view_diff: "Diff", + write_checklist: "Update Task List", }; return reverseMapping[normalizedName] || normalizedName; -} +} \ No newline at end of file diff --git a/src/tools/index.ts b/src/tools/index.ts index bafcd1b2a..3f0eea3f9 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -16,6 +16,7 @@ import { type ToolCall, PreprocessedToolCall, } from "./types.js"; +import { writeChecklistTool } from "./writeChecklist.js"; import { writeFileTool } from "./writeFile.js"; export type { Tool, ToolParameters, ToolCall }; @@ -28,6 +29,7 @@ const ALL_BUILTIN_TOOLS: Tool[] = [ searchCodeTool, runTerminalCommandTool, fetchTool, + writeChecklistTool, // When in headless mode, there is a tool that the LLM can call to make the GitHub Action fail ...(parseArgs().isHeadless ? [exitTool] : []), ]; @@ -208,9 +210,21 @@ export function formatToolCall(toolName: string, args?: any): string { return displayName; } - // Get the first argument value - const firstValue = Object.values(args)[0]; - const formattedValue = formatToolArgument(firstValue); + // Get the first argument value if it's a simple one + let formattedValue = ""; + const [key, value] = Object.entries(args)[0]; + if ( + key.toLowerCase().includes("path") || + typeof value === "number" || + typeof value === "boolean" + ) { + formattedValue = formatToolArgument(value); + } else if (typeof value === "string") { + const valueLines = value.split("\n"); + if (valueLines.length === 1) { + formattedValue = formatToolArgument(value); + } + } return `${displayName}(${formattedValue})`; } diff --git a/src/tools/types.ts b/src/tools/types.ts index 7026f3f9f..48758e46f 100644 --- a/src/tools/types.ts +++ b/src/tools/types.ts @@ -11,7 +11,7 @@ export type ToolParameters = Record< >; export interface ToolCallPreview { - type: "text" | "diff"; + type: "text" | "diff" | "checklist"; content: string; color?: string; paddingLeft?: number; @@ -44,4 +44,4 @@ export interface ToolCall { export interface PreprocessedToolCall extends ToolCall { tool: Tool; preprocessResult?: PreprocessToolCallResult; -} +} \ No newline at end of file diff --git a/src/tools/writeChecklist.test.ts b/src/tools/writeChecklist.test.ts new file mode 100644 index 000000000..b0986cdc2 --- /dev/null +++ b/src/tools/writeChecklist.test.ts @@ -0,0 +1,22 @@ +import { writeChecklistTool } from "./writeChecklist.js"; + +describe("writeChecklistTool", () => { + it("should return formatted task list status", async () => { + const checklist = `- [ ] Task 1 +- [x] Task 2 +- [ ] Task 3`; + + const result = await writeChecklistTool.run({ checklist }); + + expect(result).toBe(`Task list status:\n${checklist}`); + }); + + it("should have correct tool properties", () => { + expect(writeChecklistTool.name).toBe("write_checklist"); + expect(writeChecklistTool.displayName).toBe("Update Task List"); + expect(writeChecklistTool.readonly).toBe(false); + expect(writeChecklistTool.isBuiltIn).toBe(true); + expect(writeChecklistTool.parameters.checklist.required).toBe(true); + expect(writeChecklistTool.parameters.checklist.type).toBe("string"); + }); +}); diff --git a/src/tools/writeChecklist.ts b/src/tools/writeChecklist.ts new file mode 100644 index 000000000..5fb58d64f --- /dev/null +++ b/src/tools/writeChecklist.ts @@ -0,0 +1,32 @@ +import type { Tool } from "./types.js"; + +export const writeChecklistTool: Tool = { + name: "write_checklist", + displayName: "Update Task List", + description: + "Create or update a task checklist. The old checklist can be seen in the chat history if it exists. Use this tool to write a new checklist or edit the existing one.", + readonly: false, + isBuiltIn: true, + parameters: { + checklist: { + type: "string", + description: + "The complete checklist in markdown format using - [ ] for incomplete tasks and - [x] for completed tasks. Avoid headers and additional content unless specifically being used to group checkboxes", + required: true, + }, + }, + preprocess: async (args: { checklist: string }) => { + return { + preview: [ + { + type: "checklist" as const, + content: args.checklist, + }, + ], + args, + }; + }, + run: async (args: { checklist: string }) => { + return `Task list status:\n${args.checklist}`; + }, +}; diff --git a/src/ui/ToolResultSummary.tsx b/src/ui/ToolResultSummary.tsx index 5c3449029..91ae6cf8a 100644 --- a/src/ui/ToolResultSummary.tsx +++ b/src/ui/ToolResultSummary.tsx @@ -3,6 +3,7 @@ import path from "path"; import React from "react"; import { ColoredDiff } from "./ColoredDiff.js"; import { getToolDisplayName } from "../tools/index.js"; +import { ChecklistDisplay } from "./components/ChecklistDisplay.js"; interface ToolResultSummaryProps { toolName?: string; @@ -26,6 +27,19 @@ const ToolResultSummary: React.FC = ({ const chars = content.length; const displayName = toolName ? getToolDisplayName(toolName) : "Tool"; + // Handle write_checklist specially with styled display + if (toolName === "write_checklist") { + return ( + + + ⎿ + Task List Updated + + + + ); + } + // Handle write_file with diff specially if (toolName === "write_file" && content.includes("Diff:\n")) { const diffSection = content.split("Diff:\n")[1]; diff --git a/src/ui/components/ChecklistDisplay.tsx b/src/ui/components/ChecklistDisplay.tsx new file mode 100644 index 000000000..926a4193f --- /dev/null +++ b/src/ui/components/ChecklistDisplay.tsx @@ -0,0 +1,58 @@ +import { Box, Text } from "ink"; +import React from "react"; + +interface ChecklistDisplayProps { + content: string; +} + +/** + * Renders checklist content with styled checkboxes + */ +export const ChecklistDisplay: React.FC = ({ + content, +}) => { + const lines = content.split("\n"); + + return ( + + {lines.map((line, index) => { + if (line.startsWith("Task list")) { + return null; + } + // Match both completed [x] and incomplete [ ] checkboxes + const checkboxMatch = line.match(/^(\s*)-\s*\[([ x])\]\s*(.*)$/); + + if (checkboxMatch) { + const [, indent, status, taskText] = checkboxMatch; + const isCompleted = status === "x"; + + return ( + + {indent} + + {isCompleted ? "✓" : "○"} + + + + {taskText} + + + ); + } else if (line.trim()) { + // Non-checkbox lines (headers, etc.) + return ( + + {line} + + ); + } else { + // Empty lines + return ; + } + })} + + ); +}; diff --git a/src/ui/components/ToolPreview.tsx b/src/ui/components/ToolPreview.tsx index 4f04e3fec..2b91f0907 100644 --- a/src/ui/components/ToolPreview.tsx +++ b/src/ui/components/ToolPreview.tsx @@ -3,6 +3,7 @@ import React from "react"; import { ColoredDiff } from "../ColoredDiff.js"; import { ToolCallPreview } from "../../tools/types.js"; import { getToolDisplayName } from "../../tools/index.js"; +import { ChecklistDisplay } from "./ChecklistDisplay.js"; interface ToolPreviewProps { toolCallPreview?: ToolCallPreview[]; @@ -29,6 +30,14 @@ export const ToolPreview: React.FC = ({ {preview.content} ); + } else if (preview.type === "checklist") { + return ( + + + + ); } else { return ; }