Skip to content

Commit cfc3cb6

Browse files
committed
refactor: streamline suggestion handling and remove debug logs
- Remove console.log debug statements - Refactor suggest handling logic to be more efficient - Add dedicated prompt_suggest message type - Add proper state management for suggestions in UI - Fix ESLint warning in ChatRow.tsx
1 parent 5605295 commit cfc3cb6

File tree

4 files changed

+47
-37
lines changed

4 files changed

+47
-37
lines changed

src/core/Cline.ts

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,6 @@ export class Cline {
27082708
let normalizedSuggest = null
27092709

27102710
if (values) {
2711-
console.log("values", values)
27122711
type Suggest = {
27132712
suggest: string
27142713
}
@@ -2721,7 +2720,6 @@ export class Cline {
27212720
parsedSuggest = parseXml(values, ["values.suggest"]) as {
27222721
suggest: Suggest[] | Suggest
27232722
}
2724-
console.log("parsedSuggest", parsedSuggest)
27252723
} catch (error) {
27262724
this.consecutiveMistakeCount++
27272725
await this.say("error", `Failed to parse operations: ${error.message}`)
@@ -2734,8 +2732,6 @@ export class Cline {
27342732
normalizedSuggest = Array.isArray(parsedSuggest?.suggest)
27352733
? parsedSuggest.suggest
27362734
: [parsedSuggest?.suggest].filter((sug): sug is Suggest => sug !== undefined)
2737-
2738-
console.log("normalizedSuggest", normalizedSuggest)
27392735
} else {
27402736
this.consecutiveMistakeCount = 0
27412737
}
@@ -2765,45 +2761,39 @@ export class Cline {
27652761
}
27662762

27672763
const toolResults: (Anthropic.TextBlockParam | Anthropic.ImageBlockParam)[] = []
2764+
27682765
if (normalizedSuggest) {
27692766
console.log("normalizedSuggest", normalizedSuggest)
2770-
const { text, images } = await this.ask(
2771-
"prompt_suggest",
2772-
JSON.stringify(normalizedSuggest),
2773-
false,
2774-
)
2775-
await this.say("user_feedback", text ?? "", images)
2776-
pushToolResult(
2777-
formatResponse.toolResult(`<user_feedback>\n${text}\n</user_feedback>`, images),
2778-
)
2779-
} else {
2780-
// we already sent completion_result says, an empty string asks relinquishes control over button and field
2781-
const { response, text, images } = await this.ask("completion_result", "", false)
2782-
if (response === "yesButtonClicked") {
2783-
pushToolResult("") // signals to recursive loop to stop (for now this never happens since yesButtonClicked will trigger a new task)
2784-
break
2785-
}
2786-
await this.say("user_feedback", text ?? "", images)
2767+
await this.say("prompt_suggest", JSON.stringify(normalizedSuggest))
2768+
}
27872769

2788-
if (commandResult) {
2789-
if (typeof commandResult === "string") {
2790-
toolResults.push({ type: "text", text: commandResult })
2791-
} else if (Array.isArray(commandResult)) {
2792-
toolResults.push(...commandResult)
2793-
}
2770+
// we already sent completion_result says, an empty string asks relinquishes control over button and field
2771+
const { response, text, images } = await this.ask("completion_result", "", false)
2772+
if (response === "yesButtonClicked") {
2773+
pushToolResult("") // signals to recursive loop to stop (for now this never happens since yesButtonClicked will trigger a new task)
2774+
break
2775+
}
2776+
await this.say("user_feedback", text ?? "", images)
2777+
2778+
if (commandResult) {
2779+
if (typeof commandResult === "string") {
2780+
toolResults.push({ type: "text", text: commandResult })
2781+
} else if (Array.isArray(commandResult)) {
2782+
toolResults.push(...commandResult)
27942783
}
2795-
toolResults.push({
2796-
type: "text",
2797-
text: `The user has provided feedback on the results. Consider their input to continue the task, and then attempt completion again.\n<feedback>\n${text}\n</feedback>`,
2798-
})
2799-
toolResults.push(...formatResponse.imageBlocks(images))
2800-
this.userMessageContent.push({
2801-
type: "text",
2802-
text: `${toolDescription()} Result:`,
2803-
})
2804-
this.userMessageContent.push(...toolResults)
28052784
}
28062785

2786+
toolResults.push({
2787+
type: "text",
2788+
text: `The user has provided feedback on the results. Consider their input to continue the task, and then attempt completion again.\n<feedback>\n${text}\n</feedback>`,
2789+
})
2790+
toolResults.push(...formatResponse.imageBlocks(images))
2791+
this.userMessageContent.push({
2792+
type: "text",
2793+
text: `${toolDescription()} Result:`,
2794+
})
2795+
this.userMessageContent.push(...toolResults)
2796+
28072797
break
28082798
}
28092799
} catch (error) {

src/shared/ExtensionMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export type ClineSay =
182182
| "new_task_started"
183183
| "new_task"
184184
| "checkpoint_saved"
185+
| "prompt_suggest"
185186

186187
export interface ClineSayTool {
187188
tool:

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,8 @@ export const ChatRowContent = ({
773773
checkpoint={message.checkpoint}
774774
/>
775775
)
776+
case "prompt_suggest":
777+
return null
776778
default:
777779
return (
778780
<>

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,22 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
236236
setTextAreaDisabled(true)
237237
setSelectedImages([])
238238
setClineAsk(undefined)
239+
setPromptSuggest([])
239240
setEnableButtons(false)
240241
}
241242
break
243+
case "prompt_suggest": {
244+
const isPartial = lastMessage.partial === true
245+
if (!isPartial) {
246+
try {
247+
let temp_suggest = JSON.parse(lastMessage.text ?? "[]")
248+
setPromptSuggest(temp_suggest || [])
249+
} catch (error) {
250+
console.error(error)
251+
}
252+
}
253+
break
254+
}
242255
case "api_req_finished":
243256
case "task":
244257
case "error":
@@ -268,6 +281,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
268281
if (messages.length === 0) {
269282
setTextAreaDisabled(false)
270283
setClineAsk(undefined)
284+
setPromptSuggest([])
271285
setEnableButtons(false)
272286
setPrimaryButtonText(undefined)
273287
setSecondaryButtonText(undefined)
@@ -343,6 +357,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
343357
setSelectedImages([])
344358
setClineAsk(undefined)
345359
setEnableButtons(false)
360+
setPromptSuggest([])
346361
// Do not reset mode here as it should persist
347362
// setPrimaryButtonText(undefined)
348363
// setSecondaryButtonText(undefined)
@@ -413,6 +428,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
413428
setClineAsk(undefined)
414429
setEnableButtons(false)
415430
disableAutoScrollRef.current = false
431+
setPromptSuggest([])
416432
},
417433
[clineAsk, startNewTask],
418434
)
@@ -459,6 +475,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
459475
setTextAreaDisabled(true)
460476
setClineAsk(undefined)
461477
setEnableButtons(false)
478+
setPromptSuggest([])
462479
disableAutoScrollRef.current = false
463480
},
464481
[clineAsk, startNewTask, isStreaming],

0 commit comments

Comments
 (0)