diff --git a/coverage.txt b/coverage.txt index 484ff37a..c5920595 100644 --- a/coverage.txt +++ b/coverage.txt @@ -188,7 +188,7 @@ ℹ git | | | | ℹ index.js | 87.41 | 64.37 | 83.69 | 324-326 379-380 393-396 481-483 515-516 626-643 689-691 722-723 755-757 821-824 840-843 866-872 906 908-912 914-917 929-933 976-980 984 989-991 1006-1015 1024 1038-1044 1046-1049 1057-1063 1086-1091 1093-1099 1101-1110 1112-1115 1122-1126 1136-1143 1191-1192 1194-1199 1291-1292 1314-1315 1323-1324 1331-1332 1334-1340 1362 1366-1368 1373-1376 1428-1435 1439-1447 1450-1453 1455-1458 ℹ graphql | | | | -ℹ index.js | 97.50 | 97.17 | 93.75 | 47-48 57-68 +ℹ index.js | 97.85 | 98.13 | 93.75 | 57-68 ℹ image | | | | ℹ index.js | 100.00 | 100.00 | 50.00 | ℹ readImage.js | 94.16 | 72.22 | 100.00 | 79-80 88-89 95-96 103-104 @@ -285,6 +285,6 @@ ℹ loadAgents.js | 74.29 | 78.57 | 50.00 | 25-26 41 56-70 ℹ project.js | 100.00 | 100.00 | 100.00 | ℹ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -ℹ all files | 93.38 | 86.70 | 88.50 | +ℹ all files | 93.38 | 86.72 | 88.50 | ℹ --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ℹ end of coverage report diff --git a/src/tui/conversationArea.js b/src/tui/conversationArea.js index 20617110..25b868bd 100644 --- a/src/tui/conversationArea.js +++ b/src/tui/conversationArea.js @@ -899,6 +899,9 @@ const ConversationArea = forwardRef(function ConversationArea( onContextUpdate, completedToolCalls = {}, ) => { + // Reasoning text streamed this turn. It is sent back to the provider as + // context, so it counts toward the live window like message text. + let streamedReasoning = ""; // Debounced context size update — coalesces rapid chunks into a single // token calculation every ~200ms so the status bar stays responsive. const debouncedContextUpdate = (content) => { @@ -908,7 +911,9 @@ const ConversationArea = forwardRef(function ConversationArea( pendingContextRef.current.content = content; contextUpdateTimerRef.current = setTimeout(async () => { contextUpdateTimerRef.current = null; - const text = pendingContextRef.current.content; + const text = [streamedReasoning, pendingContextRef.current.content] + .filter(Boolean) + .join("\n"); const cached = tokenCacheRef.current; if (text && cached.content !== text) { cached.content = text; @@ -987,6 +992,8 @@ const ConversationArea = forwardRef(function ConversationArea( if (event.type === "reasoning") { const reasoningText = event.data?.text || event.text || ""; if (reasoningText) { + streamedReasoning += reasoningText; + debouncedContextUpdate(committedContentRef.current); if ( !( committedReasoningRef.current.endsWith(".") || @@ -1026,6 +1033,8 @@ const ConversationArea = forwardRef(function ConversationArea( } if (event.data?.chunk?.reasoning) { const reasoningChunk = event.data.chunk.reasoning; + streamedReasoning += reasoningChunk; + debouncedContextUpdate(committedContentRef.current); if ( !( committedReasoningRef.current.endsWith(".") || @@ -1046,6 +1055,16 @@ const ConversationArea = forwardRef(function ConversationArea( } if (event.type === "on_tool_start") { + // The call's name and arguments live in the AI message and are + // sent back as context, so count them like the tool result. + let callText = ""; + try { + callText = `${event.name || ""} ${JSON.stringify(event.data?.input ?? "")}`.trim(); + } catch { + callText = event.name || ""; + } + toolMessageTokensRef.current += await countToolMessageTokens(model, callText); + debouncedContextUpdate(committedContentRef.current); messageListRef.current?.updateMessage(streamingMsgIdRef.current, { activeToolCall: { name: event.name,