|
1 | 1 | import type { |
2 | 2 | AgentContentBlock, |
3 | 3 | ContentBlock, |
4 | | - TextContentBlock, |
5 | 4 | ToolContentBlock, |
6 | 5 | } from '../types/chat' |
7 | 6 |
|
@@ -112,116 +111,6 @@ export function extractValueForKey(output: string, key: string): string | null { |
112 | 111 | return null |
113 | 112 | } |
114 | 113 |
|
115 | | -/** |
116 | | - * Get the latest commentary (text block content) from agent blocks |
117 | | - * Returns a single-line string with newlines replaced by spaces |
118 | | - */ |
119 | | -export function getLatestCommentary( |
120 | | - blocks: ContentBlock[] | undefined, |
121 | | -): string | undefined { |
122 | | - if (!blocks || blocks.length === 0) return undefined |
123 | | - |
124 | | - // Find the last text block that isn't reasoning |
125 | | - for (let i = blocks.length - 1; i >= 0; i--) { |
126 | | - const block = blocks[i] |
127 | | - if (block.type === 'text' && block.textType !== 'reasoning') { |
128 | | - // Replace newlines with spaces and collapse multiple spaces |
129 | | - const content = block.content |
130 | | - .replace(/\n+/g, ' ') |
131 | | - .replace(/\s+/g, ' ') |
132 | | - .trim() |
133 | | - if (content) return content |
134 | | - } |
135 | | - } |
136 | | - return undefined |
137 | | -} |
138 | | - |
139 | | -/** |
140 | | - * Count edit operations (str_replace, write_file tools) |
141 | | - */ |
142 | | -export function countEdits(blocks: ContentBlock[] | undefined): number { |
143 | | - if (!blocks || blocks.length === 0) return 0 |
144 | | - |
145 | | - return blocks.filter( |
146 | | - (block) => |
147 | | - block.type === 'tool' && |
148 | | - EDIT_TOOL_NAMES.includes(block.toolName as (typeof EDIT_TOOL_NAMES)[number]), |
149 | | - ).length |
150 | | -} |
151 | | - |
152 | | -/** |
153 | | - * Get list of unique file paths edited by the agent |
154 | | - */ |
155 | | -export function getEditedFiles(blocks: ContentBlock[] | undefined): string[] { |
156 | | - if (!blocks || blocks.length === 0) return [] |
157 | | - |
158 | | - const files = new Set<string>() |
159 | | - |
160 | | - for (const block of blocks) { |
161 | | - if ( |
162 | | - block.type === 'tool' && |
163 | | - EDIT_TOOL_NAMES.includes(block.toolName as (typeof EDIT_TOOL_NAMES)[number]) |
164 | | - ) { |
165 | | - const filePath = extractFilePath(block) |
166 | | - if (filePath) { |
167 | | - files.add(filePath) |
168 | | - } |
169 | | - } |
170 | | - } |
171 | | - |
172 | | - return Array.from(files) |
173 | | -} |
174 | | - |
175 | | -export interface FileSnippet { |
176 | | - path: string |
177 | | - snippet?: string |
178 | | - isCreate: boolean |
179 | | -} |
180 | | - |
181 | | -/** |
182 | | - * Get list of files with content snippets |
183 | | - */ |
184 | | -export function getEditedFileSnippets(blocks: ContentBlock[] | undefined): FileSnippet[] { |
185 | | - if (!blocks || blocks.length === 0) return [] |
186 | | - |
187 | | - const visited = new Set<string>() |
188 | | - const results: FileSnippet[] = [] |
189 | | - |
190 | | - for (const block of blocks) { |
191 | | - if ( |
192 | | - block.type === 'tool' && |
193 | | - EDIT_TOOL_NAMES.includes(block.toolName as (typeof EDIT_TOOL_NAMES)[number]) |
194 | | - ) { |
195 | | - const filePath = extractFilePath(block) |
196 | | - if (filePath && !visited.has(filePath)) { |
197 | | - visited.add(filePath) |
198 | | - |
199 | | - const diff = extractDiff(block) |
200 | | - let snippet: string | undefined |
201 | | - if (diff) { |
202 | | - // Extract first non-header line as preview |
203 | | - const lines = diff.split('\n') |
204 | | - const interestingLine = lines.find(l => |
205 | | - (l.startsWith('+') || l.startsWith('-')) && |
206 | | - !l.startsWith('+++') && !l.startsWith('---') |
207 | | - ) |
208 | | - if (interestingLine) { |
209 | | - snippet = interestingLine.trim().slice(0, 50) |
210 | | - } |
211 | | - } |
212 | | - |
213 | | - results.push({ |
214 | | - path: filePath, |
215 | | - isCreate: isCreateFile(block), |
216 | | - snippet |
217 | | - }) |
218 | | - } |
219 | | - } |
220 | | - } |
221 | | - |
222 | | - return results |
223 | | -} |
224 | | - |
225 | 114 | /** |
226 | 115 | * Extract file path from tool block |
227 | 116 | */ |
@@ -448,20 +337,6 @@ export function getFileStatsFromBlocks(blocks: ContentBlock[] | undefined): File |
448 | 337 | return Array.from(fileMap.values()) |
449 | 338 | } |
450 | 339 |
|
451 | | -/** |
452 | | - * Get total stats across all files |
453 | | - */ |
454 | | -export function getTotalStats(fileStats: FileStats[]): DiffStats { |
455 | | - return fileStats.reduce( |
456 | | - (acc, file) => ({ |
457 | | - linesAdded: acc.linesAdded + file.stats.linesAdded, |
458 | | - linesRemoved: acc.linesRemoved + file.stats.linesRemoved, |
459 | | - hunks: acc.hunks + file.stats.hunks, |
460 | | - }), |
461 | | - { linesAdded: 0, linesRemoved: 0, hunks: 0 } |
462 | | - ) |
463 | | -} |
464 | | - |
465 | 340 | /** |
466 | 341 | * Build an activity timeline from agent blocks |
467 | 342 | * Interleaves commentary (text blocks) and edits (tool calls) |
|
0 commit comments