Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add next step suggestions and XML utilities #1084

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
"diff": "^5.2.0",
"diff-match-patch": "^1.0.5",
"fast-deep-equal": "^3.1.3",
"fast-xml-parser": "^4.5.1",
"fastest-levenshtein": "^1.0.16",
"get-folder-size": "^5.0.0",
"globby": "^14.0.2",
Expand Down
43 changes: 42 additions & 1 deletion src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { McpHub } from "../services/mcp/McpHub"
import crypto from "crypto"
import { insertGroups } from "./diff/insert-groups"
import { EXPERIMENT_IDS, experiments as Experiments, ExperimentId } from "../shared/experiments"
import { parseXml } from "../utils/xml"

const cwd =
vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) ?? path.join(os.homedir(), "Desktop") // may or may not exist but fs checking existence would immediately ask for permission which would be bad UX, need to come up with a better solution
Expand Down Expand Up @@ -2659,6 +2660,7 @@ export class Cline {
*/
const result: string | undefined = block.params.result
const command: string | undefined = block.params.command
const next_step: string | undefined = block.params.next_step
try {
const lastMessage = this.clineMessages.at(-1)
if (block.partial) {
Expand Down Expand Up @@ -2707,8 +2709,44 @@ export class Cline {
)
break
}

if (!next_step) {
this.consecutiveMistakeCount++
pushToolResult(
await this.sayAndCreateMissingParamError("attempt_completion", "next_step"),
)
break
}

let normalizedSuggest = null

type Suggest = {
task: string
mode: string
}

let parsedSuggest: {
suggest: Suggest[] | Suggest
}

try {
parsedSuggest = parseXml(next_step, ["suggest.task", "suggest.mode"]) as {
suggest: Suggest[] | Suggest
}
console.log("next_step", next_step)
} catch (error) {
this.consecutiveMistakeCount++
await this.say("error", `Failed to parse operations: ${error.message}`)
pushToolResult(formatResponse.toolError("Invalid operations xml format"))
break
}

this.consecutiveMistakeCount = 0

normalizedSuggest = Array.isArray(parsedSuggest?.suggest)
? parsedSuggest.suggest
: [parsedSuggest?.suggest].filter((sug): sug is Suggest => sug !== undefined)

let commandResult: ToolResponse | undefined
if (command) {
if (lastMessage && lastMessage.ask !== "command") {
Expand All @@ -2733,6 +2771,10 @@ export class Cline {
await this.say("completion_result", result, undefined, false)
}

const toolResults: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[] = []

await this.say("next_step_suggest", JSON.stringify(normalizedSuggest))

// we already sent completion_result says, an empty string asks relinquishes control over button and field
const { response, text, images } = await this.ask("completion_result", "", false)
if (response === "yesButtonClicked") {
Expand All @@ -2741,7 +2783,6 @@ export class Cline {
}
await this.say("user_feedback", text ?? "", images)

const toolResults: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[] = []
if (commandResult) {
if (typeof commandResult === "string") {
toolResults.push({ type: "text", text: commandResult })
Expand Down
3 changes: 2 additions & 1 deletion src/core/assistant-message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const toolParamNames = [
"operations",
"mode",
"message",
"next_step",
] as const

export type ToolParamName = (typeof toolParamNames)[number]
Expand Down Expand Up @@ -126,7 +127,7 @@ export interface AskFollowupQuestionToolUse extends ToolUse {

export interface AttemptCompletionToolUse extends ToolUse {
name: "attempt_completion"
params: Partial<Pick<Record<ToolParamName, string>, "result" | "command">>
params: Partial<Pick<Record<ToolParamName, string>, "result" | "command" | "next_step">>
}

export interface SwitchModeToolUse extends ToolUse {
Expand Down
Loading
Loading