{"version":3,"file":"todo-read.d.ts","sourceRoot":"","sources":["../../../src/core/tools/todo-read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE7D,QAAA,MAAM,cAAc,yCAAqF,CAAC;AAE1G,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,cAAc,CAAC,CAAC;AAO1D,MAAM,WAAW,eAAe;IAC/B,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;CACpB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CACjC,eAAe,EAAE,MAAM,QAAQ,EAAE,EACjC,WAAW,CAAC,EAAE,MAAM,MAAM,EAC1B,OAAO,CAAC,EAAE,eAAe,EACzB,MAAM,GAAE,UAAsC,GAC5C,SAAS,CAAC,OAAO,cAAc,CAAC,CAuDlC;AAED,eAAO,MAAM,YAAY,EAAE,SAAS,CAAC,OAAO,cAAc,CAAgC,CAAC","sourcesContent":["import type { AgentTool } from \"@apholdings/jensen-agent-core\";\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport { TodoEngine, type TodoItem } from \"../todo/index.js\";\n\nconst todoReadSchema = Type.Object({}, { description: \"Read current todo list without modifying state\" });\n\nexport type TodoReadInput = Static<typeof todoReadSchema>;\n\nfunction formatTodoItem(todo: TodoItem): string {\n\tconst statusMark = todo.status === \"completed\" ? \"x\" : todo.status === \"in_progress\" ? \">\" : \" \";\n\treturn `- [${statusMark}] ${todo.status === \"in_progress\" ? todo.activeForm : todo.content}  (id: ${todo.id})`;\n}\n\nexport interface TodoReadOptions {\n\t/** Called after a successful read to record the read snapshot */\n\tonRead?: () => void;\n}\n\n/**\n * Create the todo_read tool.\n * @param getSessionTodos - Callback to get the current todos from session\n * @param getRevision - Callback to get the current revision number\n * @param options - Optional callbacks for snapshot tracking\n * @param engine - Optional shared TodoEngine (records read snapshots + progress)\n */\nexport function createTodoReadTool(\n\tgetSessionTodos: () => TodoItem[],\n\tgetRevision?: () => number,\n\toptions?: TodoReadOptions,\n\tengine: TodoEngine = new TodoEngine(\"session\"),\n): AgentTool<typeof todoReadSchema> {\n\treturn {\n\t\tname: \"todo_read\",\n\t\tlabel: \"todo_read\",\n\t\tdescription:\n\t\t\t\"Read the session's structured task/todo list state and summary without modifying it. \" +\n\t\t\t\"Returns stable IDs and current revision for use with todo_update. \" +\n\t\t\t\"Use todo_update for progress transitions, not todo_write.\",\n\t\tparameters: todoReadSchema,\n\t\texecute: async (_toolCallId: string, _input: TodoReadInput, _signal?: AbortSignal) => {\n\t\t\tconst current = getSessionTodos();\n\t\t\tconst revision = getRevision?.();\n\t\t\tengine.emit({ type: \"TODO_STATE_READ\", currentRevision: revision });\n\t\t\t// Record the read snapshot for internal rebase + progress-aware loop reset.\n\t\t\tif (revision !== undefined) {\n\t\t\t\tengine.recordReadSnapshot(revision, current);\n\t\t\t\tengine.recordTodoRead(revision);\n\t\t\t}\n\t\t\t// Record the read snapshot for host-side enforcement\n\t\t\toptions?.onRead?.();\n\t\t\tif (current.length === 0) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\t\ttext: \"Todo list is empty. Current todo state retrieved. Use todo_write to create a new plan.\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\tdetails: { todos: [], revision },\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst lines = current.map(formatTodoItem);\n\t\t\tconst pending = current.filter((t) => t.status === \"pending\").length;\n\t\t\tconst inProgress = current.filter((t) => t.status === \"in_progress\").length;\n\t\t\tconst completed = current.filter((t) => t.status === \"completed\").length;\n\t\t\tconst header = `Current todo list (${current.length} total, revision ${revision}): ${pending} pending, ${inProgress} in progress, ${completed} completed.`;\n\t\t\treturn {\n\t\t\t\tcontent: [\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"text\",\n\t\t\t\t\t\ttext: `${header}\\n${lines.join(\"\\n\")}\\n\\nCurrent todo state retrieved. Use todo_update for progress transitions.`,\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdetails: {\n\t\t\t\t\ttodos: current.map((t) => ({\n\t\t\t\t\t\tid: t.id,\n\t\t\t\t\t\tcontent: t.content,\n\t\t\t\t\t\tactiveForm: t.activeForm,\n\t\t\t\t\t\tstatus: t.status,\n\t\t\t\t\t})),\n\t\t\t\t\trevision,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\nexport const todoReadTool: AgentTool<typeof todoReadSchema> = createTodoReadTool(() => []);\n"]}