MCPcopy Index your code
hub / github.com/winfunc/opcode / handleStreamMessage

Function handleStreamMessage

src/components/ClaudeCodeSession.tsx:548–629  ·  view source on GitHub ↗
(payload: string)

Source from the content-addressed store, hash-verified

546
547 // Helper to process any JSONL stream message string
548 function handleStreamMessage(payload: string) {
549 try {
550 // Don't process if component unmounted
551 if (!isMountedRef.current) return;
552
553 // Store raw JSONL
554 setRawJsonlOutput((prev) => [...prev, payload]);
555
556 const message = JSON.parse(payload) as ClaudeStreamMessage;
557
558 // Track enhanced tool execution
559 if (message.type === 'assistant' && message.message?.content) {
560 const toolUses = message.message.content.filter((c: any) => c.type === 'tool_use');
561 toolUses.forEach((toolUse: any) => {
562 // Increment tools executed counter
563 sessionMetrics.current.toolsExecuted += 1;
564 sessionMetrics.current.lastActivityTime = Date.now();
565
566 // Track file operations
567 const toolName = toolUse.name?.toLowerCase() || '';
568 if (toolName.includes('create') || toolName.includes('write')) {
569 sessionMetrics.current.filesCreated += 1;
570 } else if (toolName.includes('edit') || toolName.includes('multiedit') || toolName.includes('search_replace')) {
571 sessionMetrics.current.filesModified += 1;
572 } else if (toolName.includes('delete')) {
573 sessionMetrics.current.filesDeleted += 1;
574 }
575
576 // Track tool start - we'll track completion when we get the result
577 workflowTracking.trackStep(toolUse.name);
578 });
579 }
580
581 // Track tool results
582 if (message.type === 'user' && message.message?.content) {
583 const toolResults = message.message.content.filter((c: any) => c.type === 'tool_result');
584 toolResults.forEach((result: any) => {
585 const isError = result.is_error || false;
586 // Note: We don't have execution time here, but we can track success/failure
587 if (isError) {
588 sessionMetrics.current.toolsFailed += 1;
589 sessionMetrics.current.errorsEncountered += 1;
590
591 trackEvent.enhancedError({
592 error_type: 'tool_execution',
593 error_code: 'tool_failed',
594 error_message: result.content,
595 context: `Tool execution failed`,
596 user_action_before_error: 'executing_tool',
597 recovery_attempted: false,
598 recovery_successful: false,
599 error_frequency: 1,
600 stack_trace_hash: undefined
601 });
602 }
603 });
604 }
605

Callers 2

handleSendPromptFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected