Browse Source

Fix task completion events (#1981)

* Fix task completion events

* Create polite-singers-greet.md

---------

Co-authored-by: Matt Rubens <[email protected]>
Chris Estreich 11 months ago
parent
commit
599d451bd1
4 changed files with 17 additions and 10 deletions
  1. 5 0
      .changeset/polite-singers-greet.md
  2. 1 0
      package-lock.json
  3. 8 5
      src/core/Cline.ts
  4. 3 5
      src/exports/api.ts

+ 5 - 0
.changeset/polite-singers-greet.md

@@ -0,0 +1,5 @@
+---
+"roo-cline": patch
+---
+
+Fix task completion events

+ 1 - 0
package-lock.json

@@ -13024,6 +13024,7 @@
 			"resolved": "https://registry.npmjs.org/npm-run-all/-/npm-run-all-4.1.5.tgz",
 			"integrity": "sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ==",
 			"dev": true,
+			"license": "MIT",
 			"dependencies": {
 				"ansi-styles": "^3.2.1",
 				"chalk": "^2.4.1",

+ 8 - 5
src/core/Cline.ts

@@ -3202,6 +3202,9 @@ export class Cline extends EventEmitter<ClineEvents> {
 											false,
 										)
 
+										telemetryService.captureTaskCompleted(this.taskId)
+										this.emit("taskCompleted", this.taskId, this.getTokenUsage())
+
 										await this.ask(
 											"command",
 											removeClosingTag("command", command),
@@ -3233,9 +3236,10 @@ export class Cline extends EventEmitter<ClineEvents> {
 
 								if (command) {
 									if (lastMessage && lastMessage.ask !== "command") {
-										// Haven't sent a command message yet so
-										// first send completion_result then command.
+										// Haven't sent a command message yet so first send completion_result then command.
 										await this.say("completion_result", result, undefined, false)
+										telemetryService.captureTaskCompleted(this.taskId)
+										this.emit("taskCompleted", this.taskId, this.getTokenUsage())
 									}
 
 									// Complete command message.
@@ -3257,11 +3261,10 @@ export class Cline extends EventEmitter<ClineEvents> {
 									commandResult = execCommandResult
 								} else {
 									await this.say("completion_result", result, undefined, false)
+									telemetryService.captureTaskCompleted(this.taskId)
+									this.emit("taskCompleted", this.taskId, this.getTokenUsage())
 								}
 
-								telemetryService.captureTaskCompleted(this.taskId)
-								this.emit("taskCompleted", this.taskId, this.getTokenUsage())
-
 								if (this.parentTask) {
 									const didApprove = await askFinishSubTaskApproval()
 

+ 3 - 5
src/exports/api.ts

@@ -27,15 +27,13 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
 			cline.on("taskUnpaused", () => this.emit("taskUnpaused", cline.taskId))
 			cline.on("taskAskResponded", () => this.emit("taskAskResponded", cline.taskId))
 			cline.on("taskAborted", () => this.emit("taskAborted", cline.taskId))
-			cline.on("taskSpawned", (taskId) => this.emit("taskSpawned", cline.taskId, taskId))
+			cline.on("taskSpawned", (childTaskId) => this.emit("taskSpawned", cline.taskId, childTaskId))
+			cline.on("taskCompleted", (_, usage) => this.emit("taskCompleted", cline.taskId, usage))
+			cline.on("taskTokenUsageUpdated", (_, usage) => this.emit("taskTokenUsageUpdated", cline.taskId, usage))
 			this.emit("taskCreated", cline.taskId)
 		})
 
 		this.on("message", ({ taskId, action, message }) => {
-			// if (message.type === "say") {
-			// 	console.log("message", { taskId, action, message })
-			// }
-
 			if (action === "created") {
 				this.history.add(taskId, message)
 			} else if (action === "updated") {