Skip to content

Commit 8ddb980

Browse files
committed
Slightly different variation
1 parent 2bcc9d8 commit 8ddb980

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

src/core/checkpoints/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,14 @@ export function getCheckpointService(cline: Task) {
9393
try {
9494
provider?.postMessageToWebview({ type: "currentCheckpointUpdated", text: to })
9595

96-
cline.say("checkpoint_saved", to, undefined, undefined, { isFirst, from, to }).catch((err) => {
97-
log("[Cline#getCheckpointService] caught unexpected error in say('checkpoint_saved')")
98-
console.error(err)
99-
})
96+
cline
97+
.say("checkpoint_saved", to, undefined, undefined, { isFirst, from, to }, undefined, {
98+
isNonInteractive: true,
99+
})
100+
.catch((err) => {
101+
log("[Cline#getCheckpointService] caught unexpected error in say('checkpoint_saved')")
102+
console.error(err)
103+
})
100104
} catch (err) {
101105
log("[Cline#getCheckpointService] caught unexpected error in on('checkpoint'), disabling checkpoints")
102106
console.error(err)

src/core/task/Task.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -492,25 +492,30 @@ export class Task extends EventEmitter<ClineEvents> {
492492
partial?: boolean,
493493
checkpoint?: Record<string, unknown>,
494494
progressStatus?: ToolProgressStatus,
495+
options: {
496+
isNonInteractive?: boolean
497+
} = {},
495498
): Promise<undefined> {
496499
if (this.abort) {
497500
throw new Error(`[Cline#say] task ${this.taskId}.${this.instanceId} aborted`)
498501
}
499502

500503
if (partial !== undefined) {
501504
const lastMessage = this.clineMessages.at(-1)
505+
502506
const isUpdatingPreviousPartial =
503507
lastMessage && lastMessage.partial && lastMessage.type === "say" && lastMessage.say === type
508+
504509
if (partial) {
505510
if (isUpdatingPreviousPartial) {
506-
// existing partial message, so update it
511+
// Existing partial message, so update it.
507512
lastMessage.text = text
508513
lastMessage.images = images
509514
lastMessage.partial = partial
510515
lastMessage.progressStatus = progressStatus
511516
this.updateClineMessage(lastMessage)
512517
} else {
513-
// this is a new partial message, so add it with partial state
518+
// This is a new partial message, so add it with partial state.
514519
const sayTs = Date.now()
515520
this.lastMessageTs = sayTs
516521
await this.addToClineMessages({ ts: sayTs, type: "say", say: type, text, images, partial })
@@ -521,15 +526,14 @@ export class Task extends EventEmitter<ClineEvents> {
521526
// This is the complete version of a previously partial
522527
// message, so replace the partial with the complete version.
523528
this.lastMessageTs = lastMessage.ts
524-
// lastMessage.ts = sayTs
525529
lastMessage.text = text
526530
lastMessage.images = images
527531
lastMessage.partial = false
528532
lastMessage.progressStatus = progressStatus
529533
// Instead of streaming partialMessage events, we do a save
530534
// and post like normal to persist to disk.
531535
await this.saveClineMessages()
532-
// More performant than an entire postStateToWebview.
536+
// More performant than an entire `postStateToWebview`.
533537
this.updateClineMessage(lastMessage)
534538
} else {
535539
// This is a new and complete message, so add it like normal.
@@ -539,11 +543,17 @@ export class Task extends EventEmitter<ClineEvents> {
539543
}
540544
}
541545
} else {
542-
// this is a new non-partial message, so add it like normal
546+
// This is a new non-partial message, so add it like normal.
543547
const sayTs = Date.now()
544-
if (type !== "checkpoint_saved") {
548+
549+
// A "non-interactive" message is a message is one that the user
550+
// does not need to respond to. We don't want these message types
551+
// to trigger an update to `lastMessageTs` since they can be created
552+
// asynchronously and could interrupt a pending ask.
553+
if (!options.isNonInteractive) {
545554
this.lastMessageTs = sayTs
546555
}
556+
547557
await this.addToClineMessages({ ts: sayTs, type: "say", say: type, text, images, checkpoint })
548558
}
549559
}
@@ -561,8 +571,12 @@ export class Task extends EventEmitter<ClineEvents> {
561571
// Start / Abort / Resume
562572

563573
private async startTask(task?: string, images?: string[]): Promise<void> {
564-
// conversationHistory (for API) and clineMessages (for webview) need to be in sync
565-
// if the extension process were killed, then on restart the clineMessages might not be empty, so we need to set it to [] when we create a new Cline client (otherwise webview would show stale messages from previous session)
574+
// `conversationHistory` (for API) and `clineMessages` (for webview)
575+
// need to be in sync.
576+
// If the extension process were killed, then on restart the
577+
// `clineMessages` might not be empty, so we need to set it to [] when
578+
// we create a new Cline client (otherwise webview would show stale
579+
// messages from previous session).
566580
this.clineMessages = []
567581
this.apiConversationHistory = []
568582
await this.providerRef.deref()?.postStateToWebview()
@@ -584,28 +598,25 @@ export class Task extends EventEmitter<ClineEvents> {
584598
}
585599

586600
public async resumePausedTask(lastMessage: string) {
587-
// release this Cline instance from paused state
601+
// Release this Cline instance from paused state.
588602
this.isPaused = false
589603
this.emit("taskUnpaused")
590604

591-
// fake an answer from the subtask that it has completed running and this is the result of what it has done
592-
// add the message to the chat history and to the webview ui
605+
// Fake an answer from the subtask that it has completed running and
606+
// this is the result of what it has done add the message to the chat
607+
// history and to the webview ui.
593608
try {
594609
await this.say("subtask_result", lastMessage)
595610

596611
await this.addToApiConversationHistory({
597612
role: "user",
598-
content: [
599-
{
600-
type: "text",
601-
text: `[new_task completed] Result: ${lastMessage}`,
602-
},
603-
],
613+
content: [{ type: "text", text: `[new_task completed] Result: ${lastMessage}` }],
604614
})
605615
} catch (error) {
606616
this.providerRef
607617
.deref()
608618
?.log(`Error failed to add reply from subtast into conversation of parent task, error: ${error}`)
619+
609620
throw error
610621
}
611622
}

0 commit comments

Comments
 (0)