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
20 changes: 1 addition & 19 deletions src/core/Cline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export class Cline extends EventEmitter<ClineEvents> {
private askResponse?: ClineAskResponse
private askResponseText?: string
private askResponseImages?: string[]
private lastMessageTs?: number
// Not private since it needs to be accessible by tools
consecutiveMistakeCount: number = 0
consecutiveMistakeCountForApplyDiff: Map<string, number> = new Map()
Expand Down Expand Up @@ -441,7 +440,6 @@ export class Cline extends EventEmitter<ClineEvents> {
// This is a new partial message, so add it with partial
// state.
askTs = Date.now()
this.lastMessageTs = askTs
await this.addToClineMessages({ ts: askTs, type: "ask", ask: type, text, partial })
throw new Error("Current ask promise was ignored (#2)")
}
Expand All @@ -460,8 +458,6 @@ export class Cline extends EventEmitter<ClineEvents> {
So in this case we must make sure that the message ts is never altered after first setting it.
*/
askTs = lastMessage.ts
this.lastMessageTs = askTs
// lastMessage.ts = askTs
lastMessage.text = text
lastMessage.partial = false
lastMessage.progressStatus = progressStatus
Expand All @@ -473,7 +469,6 @@ export class Cline extends EventEmitter<ClineEvents> {
this.askResponseText = undefined
this.askResponseImages = undefined
askTs = Date.now()
this.lastMessageTs = askTs
await this.addToClineMessages({ ts: askTs, type: "ask", ask: type, text })
}
}
Expand All @@ -483,18 +478,10 @@ export class Cline extends EventEmitter<ClineEvents> {
this.askResponseText = undefined
this.askResponseImages = undefined
askTs = Date.now()
this.lastMessageTs = askTs
await this.addToClineMessages({ ts: askTs, type: "ask", ask: type, text })
}

await pWaitFor(() => this.askResponse !== undefined || this.lastMessageTs !== askTs, { interval: 100 })

if (this.lastMessageTs !== askTs) {
// Could happen if we send multiple asks in a row i.e. with
// command_output. It's important that when we know an ask could
// fail, it is handled gracefully.
throw new Error("Current ask promise was ignored")
}
await pWaitFor(() => this.askResponse !== undefined, { interval: 100 })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pWaitFor call waiting on this.askResponse !== undefined lacks a timeout. Without a timeout option, there's a risk that the promise could wait indefinitely if askResponse is never set. Consider adding a timeout or fallback to improve robustness.

Suggested change
await pWaitFor(() => this.askResponse !== undefined, { interval: 100 })
await pWaitFor(() => this.askResponse !== undefined, { interval: 100, timeout: 5000 })


const result = { response: this.askResponse!, text: this.askResponseText, images: this.askResponseImages }
this.askResponse = undefined
Expand Down Expand Up @@ -537,16 +524,13 @@ export class Cline extends EventEmitter<ClineEvents> {
} else {
// this is a new partial message, so add it with partial state
const sayTs = Date.now()
this.lastMessageTs = sayTs
await this.addToClineMessages({ ts: sayTs, type: "say", say: type, text, images, partial })
}
} else {
// New now have a complete version of a previously partial message.
if (isUpdatingPreviousPartial) {
// This is the complete version of a previously partial
// message, so replace the partial with the complete version.
this.lastMessageTs = lastMessage.ts
// lastMessage.ts = sayTs
lastMessage.text = text
lastMessage.images = images
lastMessage.partial = false
Expand All @@ -559,14 +543,12 @@ export class Cline extends EventEmitter<ClineEvents> {
} else {
// This is a new and complete message, so add it like normal.
const sayTs = Date.now()
this.lastMessageTs = sayTs
await this.addToClineMessages({ ts: sayTs, type: "say", say: type, text, images })
}
}
} else {
// this is a new non-partial message, so add it like normal
const sayTs = Date.now()
this.lastMessageTs = sayTs
await this.addToClineMessages({ ts: sayTs, type: "say", say: type, text, images, checkpoint })
}
}
Expand Down