Skip to content

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.

TypeScript
957 B
Raw Blame
import type { SessionMessage } from 'claude-code'

import { arrayOf } from '../array-of'
import { countOf } from '../count-of'
import { isRecord } from '../is-record'
import Tools from '../tools'
import type { TodoProgress } from './todo-progress'

/**
 * The todo list as the latest TodoWrite call left it, counted: the pane's
 * progress bar (ReplDiffSidebar's, read from the transcript instead).
 *
 * No call yet reads as an empty list.
 *
 * @param messages the transcript rows, oldest first
 * @returns completed over total
 */
export function todoProgressOf(
  messages: readonly SessionMessage[],
): TodoProgress {
  const latest = messages
    .flatMap(message => message.toolUses)
    .findLast(use => use.tool === Tools.TODO_TOOL)

  const statuses = arrayOf(latest?.input.todos).map(todo =>
    isRecord(todo) ? todo.status : null,
  )

  return {
    done: countOf(statuses, status => status === 'completed'),
    total: statuses.length,
  }
}