Merge pull request #131 from continuedev/dallin/checklist-tool

feat: checklist tool
This commit is contained in:
Nate Sesti 2025-07-31 12:20:47 -07:00 • committed by GitHub
commit 9eaa642ffb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 160 additions and 6 deletions

View file

@ -13,6 +13,8 @@ const TOOL_NAME_MAPPINGS: Record<string, string> = {
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<string, string> = {
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<string, string> = {
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;
}
}

View file

@ -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})`;
}

View file

@ -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;
}
}

View file

@ -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");
});
});

View file

@ -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}`;
},
};

View file

@ -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<ToolResultSummaryProps> = ({
const chars = content.length;
const displayName = toolName ? getToolDisplayName(toolName) : "Tool";
// Handle write_checklist specially with styled display
if (toolName === "write_checklist") {
return (
<Box flexDirection="column">
<Box marginBottom={1}>
<Text color="gray">⎿ </Text>
<Text color="blue">Task List Updated</Text>
</Box>
<ChecklistDisplay content={`Task list status:\n${content}`} />
</Box>
);
}
// Handle write_file with diff specially
if (toolName === "write_file" && content.includes("Diff:\n")) {
const diffSection = content.split("Diff:\n")[1];

View file

@ -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<ChecklistDisplayProps> = ({
content,
}) => {
const lines = content.split("\n");
return (
<Box flexDirection="column" paddingLeft={2}>
{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 (
<Box key={index}>
<Text>{indent}</Text>
<Text color={isCompleted ? "green" : "yellow"}>
{isCompleted ? "✓" : "○"}
</Text>
<Text> </Text>
<Text
color={isCompleted ? "gray" : "white"}
strikethrough={isCompleted}
>
{taskText}
</Text>
</Box>
);
} else if (line.trim()) {
// Non-checkbox lines (headers, etc.)
return (
<Box key={index}>
<Text color="white">{line}</Text>
</Box>
);
} else {
// Empty lines
return <Box key={index} height={1} />;
}
})}
</Box>
);
};

View file

@ -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<ToolPreviewProps> = ({
<Text color={preview.color ?? "gray"}>{preview.content}</Text>
</Box>
);
} else if (preview.type === "checklist") {
return (
<Box key={index}>
<ChecklistDisplay
content={`Task list status:\n${preview.content}`}
/>
</Box>
);
} else {
return <ColoredDiff key={index} diffContent={preview.content} />;
}