From 4c72bd96ab5bc199b2592d60bf3fc777e2e5ef88 Mon Sep 17 00:00:00 2001 From: pashpashpash Date: Tue, 8 Apr 2025 17:20:30 -0700 Subject: [PATCH] New Horizons (#2747) * new task tool added * small fix * fixed numbering * system prompt --- .changeset/spicy-radios-tie.md | 5 ++ docs/tools/cline-tools-guide.md | 16 +++++++ src/core/assistant-message/index.ts | 2 + src/core/prompts/responses.ts | 3 ++ src/core/prompts/system.ts | 38 +++++++++++++-- src/core/task/index.ts | 47 +++++++++++++++++++ src/shared/ExtensionMessage.ts | 5 ++ src/test/new-task-tool.test.ts | 27 +++++++++++ webview-ui/src/components/chat/ChatRow.tsx | 16 +++++++ webview-ui/src/components/chat/ChatView.tsx | 17 ++++++- .../src/components/chat/NewTaskPreview.tsx | 16 +++++++ 11 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 .changeset/spicy-radios-tie.md create mode 100644 src/test/new-task-tool.test.ts create mode 100644 webview-ui/src/components/chat/NewTaskPreview.tsx diff --git a/.changeset/spicy-radios-tie.md b/.changeset/spicy-radios-tie.md new file mode 100644 index 00000000..ea2262a5 --- /dev/null +++ b/.changeset/spicy-radios-tie.md @@ -0,0 +1,5 @@ +--- +"claude-dev": minor +--- + +Added a new task tool to cline's arsenal diff --git a/docs/tools/cline-tools-guide.md b/docs/tools/cline-tools-guide.md index 02f7ee70..4e4b5dab 100644 --- a/docs/tools/cline-tools-guide.md +++ b/docs/tools/cline-tools-guide.md @@ -82,6 +82,7 @@ Cline has access to the following tools for various tasks: 4. **Interaction Tools** - `ask_followup_question`: Ask user for clarification - `attempt_completion`: Present final results + - `new_task`: Start a new task with preloaded context Each tool has specific parameters and usage patterns. Here are some examples: @@ -114,6 +115,21 @@ Each tool has specific parameters and usage patterns. Here are some examples: ``` +- Start a new task with context (new_task): + ```xml + + + We've completed the backend API with these endpoints: + - GET /api/tasks + - POST /api/tasks + - PUT /api/tasks/:id + - DELETE /api/tasks/:id + + Now we need to implement the React frontend. + + + ``` + ## Common Tasks 1. **Create a New Component** diff --git a/src/core/assistant-message/index.ts b/src/core/assistant-message/index.ts index 96973a40..80270444 100644 --- a/src/core/assistant-message/index.ts +++ b/src/core/assistant-message/index.ts @@ -23,6 +23,7 @@ export const toolUseNames = [ "plan_mode_respond", "load_mcp_documentation", "attempt_completion", + "new_task", ] as const // Converts array of tool call names into a union type ("execute_command" | "read_file" | ...) @@ -49,6 +50,7 @@ export const toolParamNames = [ "options", "response", "result", + "context", ] as const export type ToolParamName = (typeof toolParamNames)[number] diff --git a/src/core/prompts/responses.ts b/src/core/prompts/responses.ts index caf3827f..1f4a573b 100644 --- a/src/core/prompts/responses.ts +++ b/src/core/prompts/responses.ts @@ -209,6 +209,9 @@ Otherwise, if you have not completed the task and do not need additional informa clineRulesFileInstructions: (cwd: string, content: string) => `# .clinerules\n\nThe following is provided by a root-level .clinerules file where the user has specified instructions for this working directory (${cwd.toPosix()})\n\n${content}`, + + newTaskContext: (context: string) => + `Cline wants to start a new task with the following context:\n\n${context}\n\nClick "Start New Task" to start a new task with this context preloaded.`, } // to avoid circular dependency diff --git a/src/core/prompts/system.ts b/src/core/prompts/system.ts index d18f6874..1ad4d5df 100644 --- a/src/core/prompts/system.ts +++ b/src/core/prompts/system.ts @@ -233,6 +233,20 @@ Your final result description here Command to demonstrate result (optional) +## new_task +Description: Request to create a new task with preloaded context. The user will be presented with a preview of the context and can choose to create a new task or keep chatting in the current conversation. The user may choose to start a new task at any point. +Parameters: +- context: (required) The context to preload the new task with. This should include: + * Comprehensively explain what has been accomplished in the current task - mention specific file names that are relevant + * The specific next steps or focus for the new task - mention specific file names that are relevant + * Any critical information needed to continue the work + * Clear indication of how this new task relates to the overall workflow + * This should be akin to a long handoff file, enough for a totally new developer to be able to pick up where you left off and know exactly what to do next and which files to look at. +Usage: + +context to preload new task with + + ## plan_mode_respond Description: Respond to the user's inquiry in an effort to plan a solution to the user's task. This tool should be used when you need to provide a response to a question or statement from the user about how you plan to accomplish the task. This tool is only available in PLAN MODE. The environment_details will specify the current mode, if it is not PLAN MODE then you should not use this tool. Depending on the user's message, you may ask questions to get clarification about the user's request, architect a solution to the task, and to brainstorm ideas with the user. For example, if the user's task is to create a website, you may start by asking some clarifying questions, then present a detailed plan for how you will accomplish the task given the context, and perhaps engage in a back and forth to finalize the details before the user switches you to ACT MODE to implement the solution. Parameters: @@ -284,7 +298,25 @@ Usage: -## Example 3: Requesting to make targeted edits to a file +## Example 3: Creating a new task + + + +Authentication System Implementation: +- We've implemented the basic user model with email/password +- Password hashing is working with bcrypt +- Login endpoint is functional with proper validation +- JWT token generation is implemented + +Next Steps: +- Implement refresh token functionality +- Add token validation middleware +- Create password reset flow +- Implement role-based access control + + + +## Example 4: Requesting to make targeted edits to a file src/components/App.tsx @@ -319,7 +351,7 @@ return ( -## Example 4: Requesting to use an MCP tool +## Example 5: Requesting to use an MCP tool weather-server @@ -332,7 +364,7 @@ return ( -## Example 5: Another example of using an MCP tool (where the server name is a unique identifier such as a URL) +## Example 6: Another example of using an MCP tool (where the server name is a unique identifier such as a URL) github.com/modelcontextprotocol/servers/tree/main/src/github diff --git a/src/core/task/index.ts b/src/core/task/index.ts index 57d6aec0..105c5f47 100644 --- a/src/core/task/index.ts +++ b/src/core/task/index.ts @@ -1482,6 +1482,8 @@ export class Task { return `[${block.name}]` case "attempt_completion": return `[${block.name}]` + case "new_task": + return `[${block.name} for creating a new task]` } } @@ -2750,6 +2752,51 @@ export class Task { break } } + case "new_task": { + const context: string | undefined = block.params.context + try { + if (block.partial) { + await this.ask("new_task", removeClosingTag("context", context), block.partial).catch(() => {}) + break + } else { + if (!context) { + this.consecutiveMistakeCount++ + pushToolResult(await this.sayAndCreateMissingParamError("new_task", "context")) + break + } + this.consecutiveMistakeCount = 0 + + if (this.autoApprovalSettings.enabled && this.autoApprovalSettings.enableNotifications) { + showSystemNotification({ + subtitle: "Cline wants to start a new task...", + message: "Cline is suggesting to start a new task with preloaded context.", + }) + } + + const { text, images } = await this.ask("new_task", context, false) + + // If the user provided a response, treat it as feedback + if (text || images?.length) { + await this.say("user_feedback", text ?? "", images) + pushToolResult( + formatResponse.toolResult( + `The user provided feedback instead of creating a new task:\n\n${text}\n`, + images, + ), + ) + } else { + // If no response, the user clicked the "Create New Task" button + pushToolResult( + formatResponse.toolResult(`The user has created a new task with the provided context.`), + ) + } + break + } + } catch (error) { + await handleError("creating new task", error) + break + } + } case "plan_mode_respond": { const response: string | undefined = block.params.response const optionsRaw: string | undefined = block.params.options diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index a734ba9a..7d36de3e 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -169,6 +169,7 @@ export type ClineAsk = | "auto_approval_max_req_reached" | "browser_action_launch" | "use_mcp_server" + | "new_task" export type ClineSay = | "task" @@ -256,6 +257,10 @@ export interface ClineAskQuestion { selected?: string } +export interface ClineAskNewTask { + context: string +} + export interface ClineApiReqInfo { request?: string tokensIn?: number diff --git a/src/test/new-task-tool.test.ts b/src/test/new-task-tool.test.ts new file mode 100644 index 00000000..c23fb159 --- /dev/null +++ b/src/test/new-task-tool.test.ts @@ -0,0 +1,27 @@ +import * as assert from "assert" +import { ClineMessage } from "../shared/ExtensionMessage" +import { formatResponse } from "../core/prompts/responses" + +suite("New Task Tool Tests", () => { + test("formatResponse.newTaskContext formats context correctly", () => { + const context = "This is a test context for a new task" + const result = formatResponse.newTaskContext(context) + + assert.strictEqual( + result, + `Cline wants to create a new task with the following context:\n\nThis is a test context for a new task\n\nClick "Create New Task" to start a new task with this context preloaded in Plan Mode.`, + ) + }) + + test("ClineAskNewTask interface exists", () => { + // This is a type check test, it will fail at compile time if the interface doesn't exist + const message: ClineMessage = { + ts: Date.now(), + type: "ask", + ask: "new_task", + text: JSON.stringify({ context: "Test context" }), + } + + assert.ok(message) + }) +}) diff --git a/webview-ui/src/components/chat/ChatRow.tsx b/webview-ui/src/components/chat/ChatRow.tsx index 4753daf1..0e2dcd0a 100644 --- a/webview-ui/src/components/chat/ChatRow.tsx +++ b/webview-ui/src/components/chat/ChatRow.tsx @@ -30,6 +30,7 @@ import { OptionsButtons } from "@/components/chat/OptionsButtons" import { highlightMentions } from "./TaskHeader" import SuccessButton from "@/components/common/SuccessButton" import TaskFeedbackButtons from "@/components/chat/TaskFeedbackButtons" +import NewTaskPreview from "./NewTaskPreview" import McpResourceRow from "@/components/mcp/configuration/tabs/installed/server-row/McpResourceRow" const ChatRowContainer = styled.div` @@ -1248,6 +1249,21 @@ export const ChatRowContent = ({ message, isExpanded, onToggleExpand, lastModifi ) + case "new_task": + return ( + <> +
+ + Cline wants to start a new task: +
+ + + ) case "plan_mode_respond": { let response: string | undefined let options: string[] | undefined diff --git a/webview-ui/src/components/chat/ChatView.tsx b/webview-ui/src/components/chat/ChatView.tsx index dd8cd47b..e1ea8822 100644 --- a/webview-ui/src/components/chat/ChatView.tsx +++ b/webview-ui/src/components/chat/ChatView.tsx @@ -195,6 +195,13 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie setSecondaryButtonText(undefined) setDidClickCancel(false) break + case "new_task": + setTextAreaDisabled(isPartial) + setClineAsk("new_task") + setEnableButtons(!isPartial) + setPrimaryButtonText("Start New Task with Context") + setSecondaryButtonText(undefined) + break } break case "say": @@ -296,6 +303,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie case "resume_task": case "resume_completed_task": case "mistake_limit_reached": + case "new_task": // user can provide feedback or reject the new task suggestion vscode.postMessage({ type: "askResponse", askResponse: "messageResponse", @@ -361,6 +369,13 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie // extension waiting for feedback. but we can just present a new task button startNewTask() break + case "new_task": + console.info("new task button clicked!", { lastMessage, messages, clineAsk, text }) + vscode.postMessage({ + type: "newTask", + text: lastMessage?.text, + }) + break } setTextAreaDisabled(true) setClineAsk(undefined) @@ -369,7 +384,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie // setSecondaryButtonText(undefined) disableAutoScrollRef.current = false }, - [clineAsk, startNewTask], + [clineAsk, startNewTask, lastMessage], ) const handleSecondaryButtonClick = useCallback( diff --git a/webview-ui/src/components/chat/NewTaskPreview.tsx b/webview-ui/src/components/chat/NewTaskPreview.tsx new file mode 100644 index 00000000..3a601929 --- /dev/null +++ b/webview-ui/src/components/chat/NewTaskPreview.tsx @@ -0,0 +1,16 @@ +import React from "react" +import MarkdownBlock from "../common/MarkdownBlock" + +interface NewTaskPreviewProps { + context: string +} + +const NewTaskPreview: React.FC = ({ context }) => { + return ( +
+ +
+ ) +} + +export default NewTaskPreview