xonecas.io
5875
Os

ollama-space-molt-player / commit cb4e733

feat: add context panel to TUI with dynamic tracking display

xonecas2026-02-02 cb4e73383c01a9b852340c1839eb3d925e00a368 parent 267ee49

4 files changed

src/index.ts+3−2
@@ -27,7 +27,6 @@ import { runRegistrationFlow } from "./registration";
2727 import {
2828 formatAiAction,
2929 formatAiMission,
30- formatAiThinking,
3130 formatChatMessage,
3231 formatError,
3332 formatLoggedIn,
@@ -346,8 +345,10 @@ async function startActionLoop(): Promise<void> {
346345 const result = await ollama.generateJson(prompt);
347346 output.logDebug("LLM_RESPONSE_RAW", result.raw);
348347 if (result.thinking) {
349- output.log(formatAiThinking(result.thinking, getCurrentTick()));
350348 output.logDebug("LLM_THINKING", result.thinking);
349+ // Update TUI context with thinking message
350+ gameState.tuiContext.thinking = result.thinking;
351+ output.update({ context: gameState.tuiContext });
351352 }
352353 const validation = validateAction(result.json);
353354 if (!validation.ok || !validation.action) {
src/registration.ts+1−2
@@ -8,7 +8,7 @@ import {
88 import type { OllamaAgent } from "./ollama";
99 import type { OutputInterface } from "./output-interface";
1010 import { buildRegistrationPrompt } from "./prompt";
11-import { formatAiThinking, formatSystemMessage } from "./tui/formatters";
11+import { formatSystemMessage } from "./tui/formatters";
1212 import type {
1313 AlignmentType,
1414 RegistrationChoice,
@@ -44,7 +44,6 @@ export async function runRegistrationFlow(
4444 const result = await ollama.generateJson<RegistrationChoice>(prompt);
4545 output.logDebug("REGISTRATION_RESPONSE_RAW", result.raw);
4646 if (result.thinking) {
47- output.log(formatAiThinking(result.thinking));
4847 output.logDebug("REGISTRATION_THINKING", result.thinking);
4948 }
5049 const username = String(result.json.username ?? "").trim();
src/tui/index.ts+1−0
@@ -40,6 +40,7 @@ export interface TuiContext {
4040 forum?: ContextForum;
4141 memorySummary?: string | null;
4242 lastActionResult?: string | null;
43+ thinking?: string | null;
4344 }
4445
4546 export interface TuiUpdateData {
src/tui/panels/context.ts+50−0
@@ -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 }