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
import type { SessionMessage } from 'claude-code'
import TurnOf from './turn-of'
import type Types from './types'
/**
* The transcript's turns that edited files, newest first, each numbered by
* its place among all prompts, read over `$.session.messages()`.
*
* Recomputed whole from the rows given, so a rewind that shrinks the
* transcript simply yields fewer turns.
*
* @param messages the transcript rows, oldest first
* @returns the turns with edits, newest first
*/
export function turnDiffsOf(
messages: readonly SessionMessage[],
): Types.TurnDiff[] {
const starts = messages.flatMap((message, at) =>
TurnOf.isPromptRow(message) ? [at] : [],
)
return starts
.map((start, ordinal) =>
TurnOf.turnOf(messages.slice(start, starts[ordinal + 1]), ordinal + 1),
)
.filter(turn => turn.files.length > 0)
.toReversed()
}