Compare commits

...

3 Commits

Author SHA1 Message Date
Eve Killaby e680ffa326 feat(hooks): Fix implementation from manual testing 2025-10-16 13:53:35 -07:00
Eve Killaby 2beb10a1b7 feat(hooks): Change as per code review feedback from ellipsis-dev 2025-10-16 13:49:39 -07:00
Eve Killaby cc118562f7 feat(hooks): Implement TaskStart hook 2025-10-16 13:49:39 -07:00
+48
View File
@@ -878,6 +878,54 @@ export class Task {
}
}
// Add TaskStart hook context to the conversation if provided
// This follows the same pattern as PreToolUse, PostToolUse, and UserPromptSubmit hooks
const hooksEnabled = featureFlagsService.getHooksEnabled() && this.stateManager.getGlobalSettingsKey("hooksEnabled")
if (hooksEnabled) {
try {
const { HookFactory } = await import("../hooks/hook-factory")
const hookFactory = new HookFactory()
const taskStartHook = await hookFactory.create("TaskStart")
const taskStartResult = await taskStartHook.run({
taskId: this.taskId,
taskStart: {
taskMetadata: {
taskId: this.taskId,
ulid: this.ulid,
initialTask: task || "",
},
},
})
if (!taskStartResult.shouldContinue) {
const errorMessage = taskStartResult.errorMessage || "TaskStart hook prevented task from starting"
await this.say("error", errorMessage)
// Ensure the error message is saved and posted before aborting
await this.messageStateHandler.saveClineMessagesAndUpdateHistory()
await this.postStateToWebview()
this.abortTask()
return
}
// Add context modification to the conversation if provided
if (taskStartResult.contextModification) {
const contextText = taskStartResult.contextModification.trim()
if (contextText) {
userContent.push({
type: "text",
text: `<hook_context source="TaskStart">\n${contextText}\n</hook_context>`,
})
}
}
} catch (hookError) {
const errorMessage = `TaskStart hook failed: ${hookError instanceof Error ? hookError.message : String(hookError)}`
Logger.error(errorMessage, hookError)
// Show error to user but continue with task (non-fatal)
await this.say("error", errorMessage)
}
}
await this.initiateTaskLoop(userContent)
}