Skip to content

Commit c9cea1e

Browse files
committed
Cline events are subscribed earlier, added taskCreated event to API
1 parent f1efeca commit c9cea1e

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

src/core/Cline.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export type ClineOptions = {
114114
rootTask?: Cline
115115
parentTask?: Cline
116116
taskNumber?: number
117+
onCreated?: (cline: Cline) => void
117118
}
118119

119120
export class Cline extends EventEmitter<ClineEvents> {
@@ -191,6 +192,7 @@ export class Cline extends EventEmitter<ClineEvents> {
191192
rootTask,
192193
parentTask,
193194
taskNumber,
195+
onCreated,
194196
}: ClineOptions) {
195197
super()
196198

@@ -234,6 +236,8 @@ export class Cline extends EventEmitter<ClineEvents> {
234236
Experiments.isEnabled(experiments ?? {}, EXPERIMENT_IDS.MULTI_SEARCH_AND_REPLACE),
235237
)
236238

239+
onCreated?.(this)
240+
237241
if (startTask) {
238242
if (task || images) {
239243
this.startTask(task, images)

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import { getWorkspacePath } from "../../utils/path"
7474
*/
7575

7676
export type ClineProviderEvents = {
77-
clineAdded: [cline: Cline]
77+
clineCreated: [cline: Cline]
7878
}
7979

8080
export class ClineProvider extends EventEmitter<ClineProviderEvents> implements vscode.WebviewViewProvider {
@@ -133,8 +133,6 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
133133
// Add this cline instance into the stack that represents the order of all the called tasks.
134134
this.clineStack.push(cline)
135135

136-
this.emit("clineAdded", cline)
137-
138136
// Ensure getState() resolves correctly.
139137
const state = await this.getState()
140138

@@ -485,6 +483,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
485483
rootTask: this.clineStack.length > 0 ? this.clineStack[0] : undefined,
486484
parentTask,
487485
taskNumber: this.clineStack.length + 1,
486+
onCreated: (cline) => this.emit("clineCreated", cline),
488487
})
489488

490489
await this.addClineToStack(cline)
@@ -550,6 +549,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
550549
rootTask: historyItem.rootTask,
551550
parentTask: historyItem.parentTask,
552551
taskNumber: historyItem.number,
552+
onCreated: (cline) => this.emit("clineCreated", cline),
553553
})
554554

555555
await this.addClineToStack(cline)

src/exports/api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
2020
this.history = new MessageHistory()
2121
this.tokenUsage = {}
2222

23-
this.provider.on("clineAdded", (cline) => {
23+
this.provider.on("clineCreated", (cline) => {
2424
cline.on("message", (message) => this.emit("message", { taskId: cline.taskId, ...message }))
2525
cline.on("taskStarted", () => this.emit("taskStarted", cline.taskId))
2626
cline.on("taskPaused", () => this.emit("taskPaused", cline.taskId))
2727
cline.on("taskUnpaused", () => this.emit("taskUnpaused", cline.taskId))
2828
cline.on("taskAskResponded", () => this.emit("taskAskResponded", cline.taskId))
2929
cline.on("taskAborted", () => this.emit("taskAborted", cline.taskId))
3030
cline.on("taskSpawned", (taskId) => this.emit("taskSpawned", cline.taskId, taskId))
31+
this.emit("taskCreated", cline.taskId)
3132
})
3233

3334
this.on("message", ({ taskId, action, message }) => {

src/exports/roo-code.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface TokenUsage {
1111

1212
export interface RooCodeEvents {
1313
message: [{ taskId: string; action: "created" | "updated"; message: ClineMessage }]
14+
taskCreated: [taskId: string]
1415
taskStarted: [taskId: string]
1516
taskPaused: [taskId: string]
1617
taskUnpaused: [taskId: string]

0 commit comments

Comments
 (0)