Skip to content
Closed
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 @@ -342,6 +342,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 @@ -78,6 +78,7 @@ import { DiffStrategy, getDiffStrategy } from "./diff/DiffStrategy"
import { insertGroups } from "./diff/insert-groups"
import { telemetryService } from "../services/telemetry/TelemetryService"
import { validateToolUse, isToolAllowedForMode, ToolName } from "./mode-validator"
import { parseXml } from "../utils/xml"
import { getWorkspacePath } from "../utils/path"

type ToolResponse = string | Array<Anthropic.TextBlockParam | Anthropic.ImageBlockParam>
Expand Down Expand Up @@ -2945,6 +2946,7 @@ export class Cline extends EventEmitter<ClineEvents> {
case "attempt_completion": {
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 @@ -2995,8 +2997,44 @@ export class Cline extends EventEmitter<ClineEvents> {
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) {
Expand Down Expand Up @@ -3042,6 +3080,10 @@ export class Cline extends EventEmitter<ClineEvents> {
break
}

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.
Expand All @@ -3056,7 +3098,6 @@ export class Cline extends EventEmitter<ClineEvents> {
}

await this.say("user_feedback", text ?? "", images)
const toolResults: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[] = []

if (commandResult) {
if (typeof commandResult === "string") {
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 @@ -57,6 +57,7 @@ export const toolParamNames = [
"mode",
"message",
"cwd",
"next_step",
] as const

export type ToolParamName = (typeof toolParamNames)[number]
Expand Down Expand Up @@ -127,7 +128,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