diff --git a/claude_bridge.py b/claude_bridge.py index 457bb10..af06954 100644 --- a/claude_bridge.py +++ b/claude_bridge.py @@ -70,7 +70,10 @@ async def stream_claude( ) try: - async for raw_line in proc.stdout: + while True: + raw_line = await proc.stdout.readline() + if not raw_line: + break line = raw_line.decode().strip() if not line: continue @@ -82,7 +85,6 @@ async def stream_claude( etype = event.get("type", "") if etype == "assistant": - # Extract text from content blocks msg = event.get("message", {}) for block in msg.get("content", []): if block.get("type") == "text": @@ -90,16 +92,14 @@ async def stream_claude( yield f"event: text\ndata: {json.dumps({'text': text}, ensure_ascii=False)}\n\n" elif block.get("type") == "tool_use": name = block.get("name", "") - inp = block.get("input", {}) - yield f"event: tool\ndata: {json.dumps({'tool': name, 'input': inp}, ensure_ascii=False)}\n\n" + yield f"event: tool\ndata: {json.dumps({'tool': name}, ensure_ascii=False)}\n\n" elif etype == "result": sid = event.get("session_id", "") if sid: set_session_id(tab_id, sid) result_text = event.get("result", "") - cost = event.get("total_cost_usd", 0) - yield f"event: done\ndata: {json.dumps({'result': result_text, 'cost': cost}, ensure_ascii=False)}\n\n" + yield f"event: done\ndata: {json.dumps({'result': result_text}, ensure_ascii=False)}\n\n" finally: if proc.returncode is None: diff --git a/static/chat.html b/static/chat.html index 330ab38..30de7a7 100644 --- a/static/chat.html +++ b/static/chat.html @@ -280,12 +280,17 @@ async function sendMessage() { aiDiv.textContent = aiText; msgs.scrollTop = msgs.scrollHeight; } else if (eventType === 'tool') { - addMsg('tool', '🔧 ' + data.tool + (data.input.command ? ': ' + data.input.command : data.input.file_path ? ': ' + data.input.file_path : '')); + // Show minimal status, not raw code + const toolNames = {Bash: 'Выполняю...', Read: 'Читаю файл...', Write: 'Создаю файл...', Edit: 'Редактирую...', Glob: 'Ищу файлы...', Grep: 'Ищу в файлах...'}; + const label = toolNames[data.tool] || 'Обрабатываю...'; + removeTyping(); + addTyping().textContent = label; } else if (eventType === 'done') { - if (!aiDiv && data.result) { + removeTyping(); + // Always show final result if we haven't shown text yet + if (!aiText && data.result) { aiDiv = addMsg('ai', data.result); } - // cost info hidden from user } eventType = ''; }