Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
21 changes: 20 additions & 1 deletion src/tui/conversationArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
Expand Down Expand Up @@ -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(".") ||
Expand Down Expand Up @@ -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(".") ||
Expand All @@ -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,
Expand Down
Loading