MCPcopy
hub / github.com/codeaashu/claude-code / getMessagePreview

Function getMessagePreview

src/components/Spinner/TeammateSpinnerLine.tsx:29–71  ·  view source on GitHub ↗

* Extract the last 3 lines of content from a teammate's conversation. * Shows recent activity from any message type (user or assistant).

(messages: InProcessTeammateTaskState['messages'])

Source from the content-addressed store, hash-verified

27 * Shows recent activity from any message type (user or assistant).
28 */
29function getMessagePreview(messages: InProcessTeammateTaskState['messages']): string[] {
30 if (!messages?.length) return [];
31 const allLines: string[] = [];
32 const maxLineLength = 80;
33
34 // Collect lines from recent messages (newest first)
35 for (let i = messages.length - 1; i >= 0 && allLines.length < 3; i--) {
36 const msg = messages[i];
37 // Only process messages that have content (user/assistant messages)
38 if (!msg || msg.type !== 'user' && msg.type !== 'assistant' || !msg.message?.content?.length) {
39 continue;
40 }
41 const content = msg.message.content;
42 for (const block of content) {
43 if (allLines.length >= 3) break;
44 if (!block || typeof block !== 'object') continue;
45 if ('type' in block && block.type === 'tool_use' && 'name' in block) {
46 // Try to show meaningful info from tool input
47 const input = 'input' in block ? block.input as Record<string, unknown> : null;
48 let toolLine = `Using ${block.name}…`;
49 if (input) {
50 // Look for common descriptive fields
51 const desc = input.description as string | undefined || input.prompt as string | undefined || input.command as string | undefined || input.query as string | undefined || input.pattern as string | undefined;
52 if (desc) {
53 toolLine = desc.split('\n')[0] ?? toolLine;
54 }
55 }
56 allLines.push(truncateToWidth(toolLine, maxLineLength));
57 } else if ('type' in block && block.type === 'text' && 'text' in block) {
58 const textLines = (block.text as string).split('\n').filter(l => l.trim());
59 // Take from end of text (most recent lines)
60 for (let j = textLines.length - 1; j >= 0 && allLines.length < 3; j--) {
61 const line = textLines[j];
62 if (!line) continue;
63 allLines.push(truncateToWidth(line, maxLineLength));
64 }
65 }
66 }
67 }
68
69 // Reverse so oldest of the 3 is first (reading order)
70 return allLines.reverse();
71}
72export function TeammateSpinnerLine({
73 teammate,
74 isLast,

Callers 1

TeammateSpinnerLineFunction · 0.85

Calls 2

truncateToWidthFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected