MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / extractTodosFromTranscript

Function extractTodosFromTranscript

src/utils/sessionRestore.ts:77–93  ·  view source on GitHub ↗

* 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[])

Source from the content-addressed store, hash-verified

75 * survives session restarts without file persistence.
76 */
77function 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.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected