Skip to content
Merged
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
34 changes: 14 additions & 20 deletions src/core/task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -987,32 +987,26 @@ export class Task extends EventEmitter<ClineEvents> {
return "just now"
})()

const lastTaskResumptionIndex = newUserContent.findIndex(
(x) => x.type === "text" && x.text.startsWith("[TASK RESUMPTION]"),
)
if (lastTaskResumptionIndex !== -1) {
newUserContent.splice(lastTaskResumptionIndex, newUserContent.length - lastTaskResumptionIndex)
if (responseText) {
newUserContent.push({
type: "text",
text: `\n\nNew instructions for task continuation:\n<user_message>\n${responseText}\n</user_message>`,
})
}

const wasRecent = lastClineMessage?.ts && Date.now() - lastClineMessage.ts < 30_000

newUserContent.push({
type: "text",
text:
`[TASK RESUMPTION] This task was interrupted ${agoText}. It may or may not be complete, so please reassess the task context. Be aware that the project state may have changed since then. If the task has not been completed, retry the last step before interruption and proceed with completing the task.\n\nNote: If you previously attempted a tool use that the user did not provide a result for, you should assume the tool use was not successful and assess whether you should retry. If the last tool was a browser_action, the browser has been closed and you must launch a new browser if needed.${
wasRecent
? "\n\nIMPORTANT: If the last tool use was a write_to_file that was interrupted, the file was reverted back to its original state before the interrupted edit, and you do NOT need to re-read the file as you already have its up-to-date contents."
: ""
}` +
(responseText
? `\n\nNew instructions for task continuation:\n<user_message>\n${responseText}\n</user_message>`
: ""),
})

if (responseImages && responseImages.length > 0) {
newUserContent.push(...formatResponse.imageBlocks(responseImages))
}

// Ensure we have at least some content to send to the API
// If newUserContent is empty, add a minimal resumption message
if (newUserContent.length === 0) {
newUserContent.push({
type: "text",
text: "[TASK RESUMPTION] Resuming task...",
})
}

await this.overwriteApiConversationHistory(modifiedApiConversationHistory)

console.log(`[subtasks] task ${this.taskId}.${this.instanceId} resuming from history item`)
Expand Down