feat: add todo tracking and custom tool views

Adds todo tracking infrastructure with TodoWrite tool integration to extract
and persist todos in sessions. Refactors ToolCard component to support
custom tool view rendering and displays todo progress in SessionList.
This commit is contained in:
weishu
2025-12-17 11:45:17 +08:00
parent 031116bfce
commit 9cc13b51be
21 changed files with 1103 additions and 277 deletions
@@ -0,0 +1,37 @@
import type { ToolViewProps } from '@/components/ToolCard/views/_all'
import { DiffView } from '@/components/DiffView'
function isObject(value: unknown): value is Record<string, unknown> {
return Boolean(value) && typeof value === 'object'
}
type Edit = { old_string: string; new_string: string }
function extractEdits(input: unknown): Edit[] {
if (!isObject(input) || !Array.isArray(input.edits)) return []
return input.edits
.filter(isObject)
.map((edit) => ({
old_string: typeof edit.old_string === 'string' ? edit.old_string : '',
new_string: typeof edit.new_string === 'string' ? edit.new_string : ''
}))
.filter((edit) => edit.old_string.length > 0 || edit.new_string.length > 0)
}
export function MultiEditView(props: ToolViewProps) {
const edits = extractEdits(props.block.tool.input)
if (edits.length === 0) return null
return (
<div className="flex flex-col gap-2">
{edits.map((edit, idx) => (
<DiffView
key={idx}
oldString={edit.old_string}
newString={edit.new_string}
/>
))}
</div>
)
}