Skip to content

Commit e2bdee3

Browse files
authored
Merge pull request RooCodeInc#1494 from qdaxb/support_tool_progress_status
support tool progress status
2 parents e945dcf + 80139d8 commit e2bdee3

File tree

6 files changed

+72
-1
lines changed

6 files changed

+72
-1
lines changed

src/core/Cline.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
ClineSay,
4949
ClineSayBrowserAction,
5050
ClineSayTool,
51+
ToolProgressStatus,
5152
} from "../shared/ExtensionMessage"
5253
import { getApiMetrics } from "../shared/getApiMetrics"
5354
import { HistoryItem } from "../shared/HistoryItem"
@@ -408,6 +409,7 @@ export class Cline {
408409
type: ClineAsk,
409410
text?: string,
410411
partial?: boolean,
412+
progressStatus?: ToolProgressStatus,
411413
): Promise<{ response: ClineAskResponse; text?: string; images?: string[] }> {
412414
// If this Cline instance was aborted by the provider, then the only thing keeping us alive is a promise still running in the background, in which case we don't want to send its result to the webview as it is attached to a new instance of Cline now. So we can safely ignore the result of any active promises, and this class will be deallocated. (Although we set Cline = undefined in provider, that simply removes the reference to this instance, but the instance is still alive until this promise resolves or rejects.)
413415
if (this.abort) {
@@ -423,6 +425,7 @@ export class Cline {
423425
// existing partial message, so update it
424426
lastMessage.text = text
425427
lastMessage.partial = partial
428+
lastMessage.progressStatus = progressStatus
426429
// todo be more efficient about saving and posting only new data or one whole message at a time so ignore partial for saves, and only post parts of partial message instead of whole array in new listener
427430
// await this.saveClineMessages()
428431
// await this.providerRef.deref()?.postStateToWebview()
@@ -460,6 +463,8 @@ export class Cline {
460463
// lastMessage.ts = askTs
461464
lastMessage.text = text
462465
lastMessage.partial = false
466+
lastMessage.progressStatus = progressStatus
467+
463468
await this.saveClineMessages()
464469
// await this.providerRef.deref()?.postStateToWebview()
465470
await this.providerRef
@@ -511,6 +516,7 @@ export class Cline {
511516
images?: string[],
512517
partial?: boolean,
513518
checkpoint?: Record<string, unknown>,
519+
progressStatus?: ToolProgressStatus,
514520
): Promise<undefined> {
515521
if (this.abort) {
516522
throw new Error(`Task: ${this.taskNumber} Roo Code instance aborted (#2)`)
@@ -526,6 +532,7 @@ export class Cline {
526532
lastMessage.text = text
527533
lastMessage.images = images
528534
lastMessage.partial = partial
535+
lastMessage.progressStatus = progressStatus
529536
await this.providerRef
530537
.deref()
531538
?.postMessageToWebview({ type: "partialMessage", partialMessage: lastMessage })
@@ -545,6 +552,7 @@ export class Cline {
545552
lastMessage.text = text
546553
lastMessage.images = images
547554
lastMessage.partial = false
555+
lastMessage.progressStatus = progressStatus
548556

549557
// instead of streaming partialMessage events, we do a save and post like normal to persist to disk
550558
await this.saveClineMessages()
@@ -1703,8 +1711,16 @@ export class Cline {
17031711
try {
17041712
if (block.partial) {
17051713
// update gui message
1714+
let toolProgressStatus
1715+
if (this.diffStrategy && this.diffStrategy.getProgressStatus) {
1716+
toolProgressStatus = this.diffStrategy.getProgressStatus(block)
1717+
}
1718+
17061719
const partialMessage = JSON.stringify(sharedMessageProps)
1707-
await this.ask("tool", partialMessage, block.partial).catch(() => {})
1720+
1721+
await this.ask("tool", partialMessage, block.partial, toolProgressStatus).catch(
1722+
() => {},
1723+
)
17081724
break
17091725
} else {
17101726
if (!relPath) {
@@ -1799,6 +1815,14 @@ export class Cline {
17991815
diff: diffContent,
18001816
} satisfies ClineSayTool)
18011817

1818+
let toolProgressStatus
1819+
if (this.diffStrategy && this.diffStrategy.getProgressStatus) {
1820+
toolProgressStatus = this.diffStrategy.getProgressStatus(block, diffResult)
1821+
}
1822+
await this.ask("tool", completeMessage, block.partial, toolProgressStatus).catch(
1823+
() => {},
1824+
)
1825+
18021826
const didApprove = await askApproval("tool", completeMessage)
18031827
if (!didApprove) {
18041828
await this.diffViewProvider.revertChanges() // This likely handles closing the diff view

src/core/diff/strategies/multi-search-replace.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { DiffStrategy, DiffResult } from "../types"
22
import { addLineNumbers, everyLineHasLineNumbers, stripLineNumbers } from "../../../integrations/misc/extract-text"
33
import { distance } from "fastest-levenshtein"
4+
import { ToolProgressStatus } from "../../../shared/ExtensionMessage"
5+
import { ToolUse } from "../../assistant-message"
46

57
const BUFFER_LINES = 40 // Number of extra context lines to show before and after matches
68

@@ -362,4 +364,25 @@ Only use a single line of '=======' between search and replacement content, beca
362364
failParts: diffResults,
363365
}
364366
}
367+
368+
getProgressStatus(toolUse: ToolUse, result?: DiffResult): ToolProgressStatus {
369+
const diffContent = toolUse.params.diff
370+
if (diffContent) {
371+
if (toolUse.partial) {
372+
if (diffContent.length < 1000 || (diffContent.length / 50) % 10 === 0) {
373+
return { text: `progressing ${(diffContent.match(/SEARCH/g) || []).length} blocks...` }
374+
}
375+
} else if (result) {
376+
const searchBlockCount = (diffContent.match(/SEARCH/g) || []).length
377+
if (result.failParts) {
378+
return {
379+
text: `progressed ${searchBlockCount - result.failParts.length}/${searchBlockCount} blocks.`,
380+
}
381+
} else {
382+
return { text: `progressed ${searchBlockCount} blocks.` }
383+
}
384+
}
385+
}
386+
return {}
387+
}
365388
}

src/core/diff/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* Interface for implementing different diff strategies
33
*/
44

5+
import { ToolProgressStatus } from "../../shared/ExtensionMessage"
6+
import { ToolUse } from "../assistant-message"
7+
58
export type DiffResult =
69
| { success: true; content: string; failParts?: DiffResult[] }
710
| ({
@@ -34,4 +37,6 @@ export interface DiffStrategy {
3437
* @returns A DiffResult object containing either the successful result or error details
3538
*/
3639
applyDiff(originalContent: string, diffContent: string, startLine?: number, endLine?: number): Promise<DiffResult>
40+
41+
getProgressStatus?(toolUse: ToolUse, result?: any): ToolProgressStatus
3742
}

src/shared/ExtensionMessage.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ export interface ClineMessage {
155155
reasoning?: string
156156
conversationHistoryIndex?: number
157157
checkpoint?: Record<string, unknown>
158+
progressStatus?: ToolProgressStatus
158159
}
159160

160161
export type ClineAsk =
@@ -274,3 +275,7 @@ export interface HumanRelayCancelMessage {
274275
}
275276

276277
export type ClineApiReqCancelReason = "streaming_failed" | "user_cancelled"
278+
279+
export type ToolProgressStatus = {
280+
text?: string
281+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ export const ChatRowContent = ({
258258
<span style={{ fontWeight: "bold" }}>Roo wants to edit this file:</span>
259259
</div>
260260
<CodeAccordian
261+
progressStatus={message.progressStatus}
261262
isLoading={message.partial}
262263
diff={tool.diff!}
263264
path={tool.path!}

webview-ui/src/components/common/CodeAccordian.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { memo, useMemo } from "react"
22
import { getLanguageFromPath } from "../../utils/getLanguageFromPath"
33
import CodeBlock, { CODE_BLOCK_BG_COLOR } from "./CodeBlock"
4+
import { ToolProgressStatus } from "../../../../src/shared/ExtensionMessage"
45

56
interface CodeAccordianProps {
67
code?: string
@@ -12,6 +13,7 @@ interface CodeAccordianProps {
1213
isExpanded: boolean
1314
onToggleExpand: () => void
1415
isLoading?: boolean
16+
progressStatus?: ToolProgressStatus
1517
}
1618

1719
/*
@@ -32,6 +34,7 @@ const CodeAccordian = ({
3234
isExpanded,
3335
onToggleExpand,
3436
isLoading,
37+
progressStatus,
3538
}: CodeAccordianProps) => {
3639
const inferredLanguage = useMemo(
3740
() => code && (language ?? (path ? getLanguageFromPath(path) : undefined)),
@@ -95,6 +98,16 @@ const CodeAccordian = ({
9598
</>
9699
)}
97100
<div style={{ flexGrow: 1 }}></div>
101+
{progressStatus && progressStatus.text && (
102+
<span
103+
style={{
104+
color: "var(--vscode-descriptionForeground)",
105+
borderTop: isExpanded ? "1px solid var(--vscode-editorGroup-border)" : "none",
106+
marginLeft: "auto", // Right-align the text
107+
}}>
108+
{progressStatus.text}
109+
</span>
110+
)}
98111
<span className={`codicon codicon-chevron-${isExpanded ? "up" : "down"}`}></span>
99112
</div>
100113
)}

0 commit comments

Comments
 (0)