From 5551849f1db33399e47b71a567549cd4789f1465 Mon Sep 17 00:00:00 2001 From: sumeyaaaa Date: Sat, 21 Feb 2026 13:58:14 +0300 Subject: [PATCH] chore: commit src/hooks/RecordLessonTool.ts --- src/hooks/RecordLessonTool.ts | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/hooks/RecordLessonTool.ts diff --git a/src/hooks/RecordLessonTool.ts b/src/hooks/RecordLessonTool.ts new file mode 100644 index 0000000000..53ece722b7 --- /dev/null +++ b/src/hooks/RecordLessonTool.ts @@ -0,0 +1,46 @@ +import { BaseTool, ToolCallbacks } from "../core/tools/BaseTool" +import type { ToolUse } from "../shared/tools" +import { Task } from "../core/task/Task" +import { OrchestrationDataModel } from "./OrchestrationDataModel" + +interface RecordLessonParams { + lesson: string + context?: { + tool?: string + error?: string + file?: string + } +} + +/** + * Tool for recording lessons learned to AGENT.md (Phase 4 requirement) + * This tool allows the agent to append lessons learned when verification steps fail + * or when important insights are discovered during development. + */ +export class RecordLessonTool extends BaseTool<"record_lesson"> { + readonly name = "record_lesson" as const + + async execute(params: RecordLessonParams, task: Task, callbacks: ToolCallbacks): Promise { + const { pushToolResult, handleError } = callbacks + + if (!params.lesson || params.lesson.trim() === "") { + task.consecutiveMistakeCount++ + task.recordToolError("record_lesson") + pushToolResult("Error: lesson parameter is required and cannot be empty.") + return + } + + try { + const dataModel = new OrchestrationDataModel(task.cwd) + await dataModel.initialize() + await dataModel.appendLesson(params.lesson.trim(), params.context) + + pushToolResult(`Lesson recorded successfully to .orchestration/AGENT.md`) + task.consecutiveMistakeCount = 0 + } catch (error) { + await handleError("recording lesson", error as Error) + } + } +} + +export const recordLessonTool = new RecordLessonTool()