@@ -4,6 +4,47 @@ import type { TuiContext } from "../index";
44 import { PALETTE, THEME } from "../theme";
55 import { applyColor, renderSectionTitle } from "../widgets";
66
7+function truncateThinking(text: string, maxChars = 200): string {
8+ const trimmed = text.trim();
9+
10+ // If short enough, return as-is
11+ if (trimmed.length <= maxChars) {
12+ return trimmed;
13+ }
14+
15+ // Try sentence-based approach
16+ const sentences = trimmed.match(/[^.!?]+[.!?]+/g);
17+
18+ if (sentences && sentences.length > 0) {
19+ // Collect sentences from end backwards
20+ const collected: string[] = [];
21+ let totalLength = 0;
22+
23+ for (let i = sentences.length - 1; i >= 0; i--) {
24+ const sentence = sentences[i].trim();
25+ const newLength =
26+ totalLength + sentence.length + (collected.length > 0 ? 1 : 0); // +1 for space
27+
28+ if (newLength > maxChars) {
29+ break;
30+ }
31+
32+ collected.unshift(sentence);
33+ totalLength = newLength;
34+ }
35+
36+ if (collected.length > 0) {
37+ const result = collected.join(" ");
38+ const isPartial = collected.length < sentences.length;
39+ return isPartial ? `[...] ${result}` : result;
40+ }
41+ }
42+
43+ // Fallback: character truncation
44+ const excerpt = trimmed.slice(-maxChars).trim();
45+ return `[...] ${excerpt}`;
46+}
47+
748 export function renderContextPanel(context: TuiContext | undefined): string {
849 const lines: string[] = [];
950
@@ -43,5 +84,14 @@ export function renderContextPanel(context: TuiContext | undefined): string {
4384 lines.push(applyColor("No memory available.", THEME.INACTIVE));
4485 }
4586
87+ // Thinking section
88+ const thinking = context?.thinking?.trim();
89+ if (thinking) {
90+ lines.push("");
91+ lines.push(renderSectionTitle("CURRENT THINKING"));
92+ const truncated = truncateThinking(thinking, 200);
93+ lines.push(applyColor(truncated, THEME.VALUE));
94+ }
95+
4696 return lines.join("\n");
4797 }