spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / mods / diff / hooks / todos / todo-progress-of.ts
33 lines · 957 BRaw
1import type { SessionMessage } from 'claude-code'
2
3import { arrayOf } from '../array-of'
4import { countOf } from '../count-of'
5import { isRecord } from '../is-record'
6import Tools from '../tools'
7import type { TodoProgress } from './todo-progress'
8
9/**
10 * The todo list as the latest TodoWrite call left it, counted: the pane's
11 * progress bar (ReplDiffSidebar's, read from the transcript instead).
12 *
13 * No call yet reads as an empty list.
14 *
15 * @param messages the transcript rows, oldest first
16 * @returns completed over total
17 */
18export function todoProgressOf(
19 messages: readonly SessionMessage[],
20): TodoProgress {
21 const latest = messages
22 .flatMap(message => message.toolUses)
23 .findLast(use => use.tool === Tools.TODO_TOOL)
24
25 const statuses = arrayOf(latest?.input.todos).map(todo =>
26 isRecord(todo) ? todo.status : null,
27 )
28
29 return {
30 done: countOf(statuses, status => status === 'completed'),
31 total: statuses.length,
32 }
33}