* Scan the transcript for the last TodoWrite tool_use block and return its todos. * Used to hydrate AppState.todos on SDK --resume so the model's todo list * survives session restarts without file persistence.
(messages: Message[])
| 75 | * survives session restarts without file persistence. |
| 76 | */ |
| 77 | function extractTodosFromTranscript(messages: Message[]): TodoList { |
| 78 | for (let i = messages.length - 1; i >= 0; i--) { |
| 79 | const msg = messages[i] |
| 80 | if (msg?.type !== 'assistant') continue |
| 81 | const toolUse = (msg.message!.content as any[]).find( |
| 82 | block => block.type === 'tool_use' && block.name === TODO_WRITE_TOOL_NAME, |
| 83 | ) |
| 84 | if (!toolUse || toolUse.type !== 'tool_use') continue |
| 85 | const input = toolUse.input |
| 86 | if (input === null || typeof input !== 'object') return [] |
| 87 | const parsed = TodoListSchema().safeParse( |
| 88 | (input as Record<string, unknown>).todos, |
| 89 | ) |
| 90 | return parsed.success ? parsed.data : [] |
| 91 | } |
| 92 | return [] |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Restore session state (file history, attribution, todos) from log on resume. |
no outgoing calls
no test coverage detected