From f572f60f22f98387186b11e433ca37047448688f Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 31 Jul 2025 11:09:26 -0700 Subject: [PATCH 1/5] feat: write checklist tool --- src/tools/index.ts | 4 +- src/tools/writeChecklist.test.ts | 22 +++++++++ src/tools/writeChecklist.ts | 21 +++++++++ src/ui/ToolResultSummary.tsx | 8 +++- src/ui/components/ChecklistDisplay.tsx | 62 ++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 src/tools/writeChecklist.test.ts create mode 100644 src/tools/writeChecklist.ts create mode 100644 src/ui/components/ChecklistDisplay.tsx diff --git a/src/tools/index.ts b/src/tools/index.ts index bafcd1b2a..d02901056 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] : []), ]; @@ -213,4 +215,4 @@ export function formatToolCall(toolName: string, args?: any): string { const formattedValue = formatToolArgument(firstValue); return `${displayName}(${formattedValue})`; -} +} \ 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..3f7adb2a9 --- /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"); + }); +}); \ No newline at end of file diff --git a/src/tools/writeChecklist.ts b/src/tools/writeChecklist.ts new file mode 100644 index 000000000..4c0984bb8 --- /dev/null +++ b/src/tools/writeChecklist.ts @@ -0,0 +1,21 @@ +import type { Tool } from "./types.js"; + +export const writeChecklistTool: Tool = { + name: "write_checklist", + displayName: "Update Task List", + description: + "Create or update a task checklist. Use this to plan/prepare and then mark tasks completed as you go. 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 full checklist in markdown format using - [ ] for incomplete tasks and - [x] for completed tasks. Avoid content other than checkbox items unless it is labels to split up groups of checkboxes", + required: true, + }, + }, + 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..88843554d 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,11 @@ 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 ; + } + // Handle write_file with diff specially if (toolName === "write_file" && content.includes("Diff:\n")) { const diffSection = content.split("Diff:\n")[1]; @@ -143,4 +149,4 @@ const ToolResultSummary: React.FC = ({ ); }; -export default ToolResultSummary; +export default ToolResultSummary; \ No newline at end of file diff --git a/src/ui/components/ChecklistDisplay.tsx b/src/ui/components/ChecklistDisplay.tsx new file mode 100644 index 000000000..976781f7b --- /dev/null +++ b/src/ui/components/ChecklistDisplay.tsx @@ -0,0 +1,62 @@ +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, +}) => { + // Parse the content to extract the checklist after "Task list status:\n" + const checklistMatch = content.match(/Task list status:\n([\s\S]*)/); + const checklistContent = checklistMatch ? checklistMatch[1] : content; + + const lines = checklistContent.split("\n"); + + return ( + + + ⎿ + Task List Updated + + + {lines.map((line, index) => { + // 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 ; + } + })} + + + ); +}; \ No newline at end of file From 20bd304507f5711efd177df1505e4279863f716d Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 31 Jul 2025 11:09:54 -0700 Subject: [PATCH 2/5] feat: write checklist tool --- src/tools/index.ts | 2 +- src/tools/writeChecklist.test.ts | 2 +- src/ui/ToolResultSummary.tsx | 2 +- src/ui/components/ChecklistDisplay.tsx | 11 +++++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/tools/index.ts b/src/tools/index.ts index d02901056..08ed65e44 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -215,4 +215,4 @@ export function formatToolCall(toolName: string, args?: any): string { const formattedValue = formatToolArgument(firstValue); return `${displayName}(${formattedValue})`; -} \ No newline at end of file +} diff --git a/src/tools/writeChecklist.test.ts b/src/tools/writeChecklist.test.ts index 3f7adb2a9..b0986cdc2 100644 --- a/src/tools/writeChecklist.test.ts +++ b/src/tools/writeChecklist.test.ts @@ -19,4 +19,4 @@ describe("writeChecklistTool", () => { expect(writeChecklistTool.parameters.checklist.required).toBe(true); expect(writeChecklistTool.parameters.checklist.type).toBe("string"); }); -}); \ No newline at end of file +}); diff --git a/src/ui/ToolResultSummary.tsx b/src/ui/ToolResultSummary.tsx index 88843554d..d71f011f3 100644 --- a/src/ui/ToolResultSummary.tsx +++ b/src/ui/ToolResultSummary.tsx @@ -149,4 +149,4 @@ const ToolResultSummary: React.FC = ({ ); }; -export default ToolResultSummary; \ No newline at end of file +export default ToolResultSummary; diff --git a/src/ui/components/ChecklistDisplay.tsx b/src/ui/components/ChecklistDisplay.tsx index 976781f7b..512b653d1 100644 --- a/src/ui/components/ChecklistDisplay.tsx +++ b/src/ui/components/ChecklistDisplay.tsx @@ -27,11 +27,11 @@ export const ChecklistDisplay: React.FC = ({ {lines.map((line, index) => { // 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} @@ -39,7 +39,10 @@ export const ChecklistDisplay: React.FC = ({ {isCompleted ? "✓" : "○"} - + {taskText} @@ -59,4 +62,4 @@ export const ChecklistDisplay: React.FC = ({ ); -}; \ No newline at end of file +}; From 8137de41702a74130e61e0a52a67796f18469980 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 31 Jul 2025 11:34:59 -0700 Subject: [PATCH 3/5] fix: checklist tool updates --- src/tools/index.ts | 13 +++- src/tools/types.ts | 4 +- src/tools/writeChecklist.ts | 15 ++++- src/ui/ToolResultSummary.tsx | 10 +++- src/ui/components/ChecklistDisplay.tsx | 83 ++++++++++++-------------- src/ui/components/ToolPreview.tsx | 9 +++ 6 files changed, 81 insertions(+), 53 deletions(-) diff --git a/src/tools/index.ts b/src/tools/index.ts index 08ed65e44..5dcb59c92 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -210,9 +210,16 @@ 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); + } 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.ts b/src/tools/writeChecklist.ts index 4c0984bb8..5fb58d64f 100644 --- a/src/tools/writeChecklist.ts +++ b/src/tools/writeChecklist.ts @@ -4,17 +4,28 @@ export const writeChecklistTool: Tool = { name: "write_checklist", displayName: "Update Task List", description: - "Create or update a task checklist. Use this to plan/prepare and then mark tasks completed as you go. 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.", + "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 full checklist in markdown format using - [ ] for incomplete tasks and - [x] for completed tasks. Avoid content other than checkbox items unless it is labels to split up groups of checkboxes", + "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 d71f011f3..91ae6cf8a 100644 --- a/src/ui/ToolResultSummary.tsx +++ b/src/ui/ToolResultSummary.tsx @@ -29,7 +29,15 @@ const ToolResultSummary: React.FC = ({ // Handle write_checklist specially with styled display if (toolName === "write_checklist") { - return ; + return ( + + + ⎿ + Task List Updated + + + + ); } // Handle write_file with diff specially diff --git a/src/ui/components/ChecklistDisplay.tsx b/src/ui/components/ChecklistDisplay.tsx index 512b653d1..926a4193f 100644 --- a/src/ui/components/ChecklistDisplay.tsx +++ b/src/ui/components/ChecklistDisplay.tsx @@ -11,55 +11,48 @@ interface ChecklistDisplayProps { export const ChecklistDisplay: React.FC = ({ content, }) => { - // Parse the content to extract the checklist after "Task list status:\n" - const checklistMatch = content.match(/Task list status:\n([\s\S]*)/); - const checklistContent = checklistMatch ? checklistMatch[1] : content; - - const lines = checklistContent.split("\n"); + const lines = content.split("\n"); return ( - - - ⎿ - Task List Updated - - - {lines.map((line, index) => { - // Match both completed [x] and incomplete [ ] checkboxes - const checkboxMatch = line.match(/^(\s*)-\s*\[([ x])\]\s*(.*)$/); + + {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"; + 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 ; - } - })} - + 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 ; } From dd53644ce5b8800ba388bf410273855b3d42f426 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 31 Jul 2025 11:42:52 -0700 Subject: [PATCH 4/5] fix: tests --- src/tools/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tools/index.ts b/src/tools/index.ts index 5dcb59c92..3f0eea3f9 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -219,6 +219,11 @@ export function formatToolCall(toolName: string, args?: any): string { 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})`; From 420e84650b569cb3128959ec750675aa7eb5afa6 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 31 Jul 2025 11:49:27 -0700 Subject: [PATCH 5/5] checklist tool permissions --- src/permissions/toolNameMapping.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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