xonecas.io
5875
Os

ollama-space-molt-player / commit 2c9f2c5

feat: add context panel and action prompt enhancements

- Add context panel to TUI for displaying faction, forum, and stranded status
- Enhance action selection prompt with faction creation and recovery guidance
- Add mock prompt utility for testing and development
- Update game state tracking for character context
- Refactor prompt formatting for improved clarity

xonecas2026-02-01 2c9f2c5c46cf5126eaa366aaf8920521e1ee78a7 parent da13b3d

10 files changed

scripts/mock-prompt.ts+293−0
@@ -0,0 +1,293 @@
1+// Generate a mock prompt exactly as sent to the LLM
2+// Usage: bun run scripts/mock-prompt.ts
3+
4+import type { ClientState } from "../client/src/client";
5+import type { HistoryEntry } from "../src/memory";
6+import { buildActionPrompt, type WorldSnapshot } from "../src/prompt";
7+import type {
8+ AlignmentType,
9+ PersonalityType,
10+ SpeechStyleType,
11+} from "../src/types";
12+
13+// Mock player data
14+const mockPlayer = {
15+ id: "player-001",
16+ username: "NebulaWanderer",
17+ empire: "nebula" as const,
18+ credits: 15420,
19+ current_system: "sol-prime",
20+ current_poi: "asteroid-belt-alpha",
21+ current_ship_id: "ship-001",
22+ home_base: "station-central",
23+ docked_at_base: "",
24+ faction_id: "faction-nebula-explorers",
25+ faction_rank: "Lieutenant",
26+ status_message: "Exploring the cosmos",
27+ clan_tag: "NEB",
28+ primary_color: "#3366ff",
29+ secondary_color: "#99ccff",
30+ anonymous: false,
31+ skills: {
32+ mining: { level: 5, xp: 2400 },
33+ combat: { level: 3, xp: 800 },
34+ trading: { level: 4, xp: 1600 },
35+ },
36+ stats: {
37+ ships_destroyed: 12,
38+ times_destroyed: 3,
39+ ore_mined: 45000,
40+ credits_earned: 120000,
41+ credits_spent: 85000,
42+ trades_completed: 67,
43+ systems_discovered: 15,
44+ items_crafted: 23,
45+ missions_completed: 8,
46+ },
47+};
48+
49+// Mock ship data
50+const mockShip = {
51+ id: "ship-001",
52+ owner_id: "player-001",
53+ class_id: "explorer-mk2",
54+ name: "Starseeker",
55+ hull: 85,
56+ max_hull: 100,
57+ shield: 40,
58+ max_shield: 50,
59+ shield_recharge: 2,
60+ armor: 15,
61+ speed: 120,
62+ fuel: 35,
63+ max_fuel: 100,
64+ cargo_used: 45,
65+ cargo_capacity: 80,
66+ cpu_used: 30,
67+ cpu_capacity: 50,
68+ power_used: 25,
69+ power_capacity: 40,
70+ modules: ["scanner-mk2", "mining-laser", "shield-booster"],
71+ cargo: [
72+ { item_id: "iron-ore", quantity: 30 },
73+ { item_id: "crystal-shard", quantity: 10 },
74+ { item_id: "fuel-cell", quantity: 5 },
75+ ],
76+};
77+
78+// Mock system data
79+const mockSystem = {
80+ id: "sol-prime",
81+ name: "Sol Prime",
82+ description: "A bustling hub of trade and exploration.",
83+ empire: "nebula" as const,
84+ police_level: 5,
85+ connections: ["alpha-centauri", "tau-ceti", "barnards-star"],
86+ pois: ["station-central", "asteroid-belt-alpha", "gas-giant-1", "moon-alpha"],
87+ discovered: true,
88+ position: { x: 0, y: 0 },
89+ discovered_by: "player-001",
90+};
91+
92+// Mock POI data
93+const mockPoi = {
94+ id: "asteroid-belt-alpha",
95+ system_id: "sol-prime",
96+ type: "asteroid_belt" as const,
97+ name: "Alpha Belt",
98+ description: "Rich asteroid belt with various ores.",
99+ position: { x: 150, y: 75 },
100+ resources: [
101+ { resource_id: "iron-ore", richness: 0.8, remaining: 5000 },
102+ { resource_id: "titanium", richness: 0.4, remaining: 2000 },
103+ ],
104+ base_id: undefined,
105+};
106+
107+// Mock base data (null when not docked)
108+const mockBase = null;
109+
110+// Mock nearby players
111+const mockNearby = [
112+ {
113+ player_id: "player-042",
114+ username: "VoidHunter",
115+ ship_class: "fighter-mk3",
116+ faction_id: "faction-crimson",
117+ faction_tag: "CRM",
118+ status_message: "Looking for trouble",
119+ clan_tag: "CRM",
120+ primary_color: "#ff3333",
121+ secondary_color: "#990000",
122+ anonymous: false,
123+ in_combat: false,
124+ },
125+ {
126+ player_id: "player-088",
127+ username: "TradeMaster",
128+ ship_class: "freighter-xl",
129+ faction_id: undefined,
130+ faction_tag: undefined,
131+ status_message: "Open for business",
132+ clan_tag: undefined,
133+ primary_color: "#33ff33",
134+ secondary_color: "#009900",
135+ anonymous: false,
136+ in_combat: false,
137+ },
138+];
139+
140+// Build ClientState
141+const mockClientState: ClientState = {
142+ connected: true,
143+ authenticated: true,
144+ player: mockPlayer,
145+ ship: mockShip,
146+ system: mockSystem,
147+ poi: mockPoi,
148+ base: mockBase,
149+ nearby: mockNearby,
150+ inCombat: false,
151+ currentTick: 12847,
152+};
153+
154+// Mock world snapshot with POI list
155+const mockWorldSnapshot: WorldSnapshot = {
156+ system: mockSystem,
157+ pois: [
158+ {
159+ id: "station-central",
160+ name: "Central Station",
161+ type: "station",
162+ position: { x: 0, y: 0 },
163+ base_id: "base-central",
164+ },
165+ {
166+ id: "asteroid-belt-alpha",
167+ name: "Alpha Belt",
168+ type: "asteroid_belt",
169+ position: { x: 150, y: 75 },
170+ resources: [
171+ { resource_id: "iron-ore", richness: 0.8, remaining: 5000 },
172+ { resource_id: "titanium", richness: 0.4, remaining: 2000 },
173+ ],
174+ },
175+ {
176+ id: "gas-giant-1",
177+ name: "Helios Major",
178+ type: "planet",
179+ position: { x: -200, y: 100 },
180+ },
181+ {
182+ id: "moon-alpha",
183+ name: "Luna Prime",
184+ type: "moon",
185+ position: { x: 50, y: -30 },
186+ base_id: "base-luna",
187+ },
188+ ],
189+ poi: mockPoi,
190+ base: mockBase,
191+};
192+
193+// Mock recent history
194+const mockRecentHistory: HistoryEntry[] = [
195+ {
196+ kind: "action",
197+ ts: "2024-01-15T10:30:00Z",
198+ action: "travel",
199+ args: JSON.stringify({ target_poi: "asteroid-belt-alpha" }),
200+ },
201+ {
202+ kind: "event",
203+ ts: "2024-01-15T10:30:05Z",
204+ type: "ok",
205+ payload: JSON.stringify({
206+ action: "arrived",
207+ poi_id: "asteroid-belt-alpha",
208+ }),
209+ },
210+ {
211+ kind: "action",
212+ ts: "2024-01-15T10:31:00Z",
213+ action: "mine",
214+ args: null,
215+ },
216+ {
217+ kind: "event",
218+ ts: "2024-01-15T10:31:05Z",
219+ type: "ok",
220+ payload: JSON.stringify({
221+ action: "mine",
222+ resource: "iron-ore",
223+ quantity: 15,
224+ }),
225+ },
226+ {
227+ kind: "action",
228+ ts: "2024-01-15T10:32:00Z",
229+ action: "mine",
230+ args: null,
231+ },
232+ {
233+ kind: "event",
234+ ts: "2024-01-15T10:32:05Z",
235+ type: "ok",
236+ payload: JSON.stringify({
237+ action: "mine",
238+ resource: "iron-ore",
239+ quantity: 12,
240+ }),
241+ },
242+ {
243+ kind: "action",
244+ ts: "2024-01-15T10:33:00Z",
245+ action: "say",
246+ args: JSON.stringify({ content: "Good yields here today!" }),
247+ },
248+ {
249+ kind: "event",
250+ ts: "2024-01-15T10:33:02Z",
251+ type: "chat_message",
252+ payload: JSON.stringify({
253+ channel: "local",
254+ sender: "VoidHunter",
255+ content: "Watch your back, explorer.",
256+ }),
257+ },
258+];
259+
260+// Mock character traits
261+const mockAlignment: AlignmentType = "good";
262+const mockPersonality: PersonalityType = "cartographer";
263+const mockSpeechStyle: SpeechStyleType = "mythic";
264+
265+// Mock forum context
266+const mockLastForumThreadId: string | null = "thread-abc123";
267+const mockLastForumPostTitle: string | null = "Best Mining Spots in Sol Prime";
268+const mockLastForumPostCategory: string | null = "trading";
269+const mockForumFollowUpStatus: "unread" | "periodic" | null = "periodic";
270+
271+// Mock repetition warning (null = no warning)
272+const mockRepetitionWarning: { action: string; count: number } | null = null;
273+
274+// Build the prompt exactly as we would in production
275+const prompt = buildActionPrompt({
276+ state: mockClientState,
277+ worldSnapshot: mockWorldSnapshot,
278+ recentHistory: mockRecentHistory,
279+ currentGoal:
280+ "Map the Sol Prime system and gather resources for the journey to Alpha Centauri",
281+ empire: mockPlayer.empire,
282+ alignment: mockAlignment,
283+ personality: mockPersonality,
284+ speechStyle: mockSpeechStyle,
285+ lastForumThreadId: mockLastForumThreadId,
286+ lastForumPostTitle: mockLastForumPostTitle,
287+ lastForumPostCategory: mockLastForumPostCategory,
288+ forumFollowUpStatus: mockForumFollowUpStatus,
289+ repetitionWarning: mockRepetitionWarning,
290+});
291+
292+// Output verbatim
293+console.log(prompt);
src/actions.ts+57−10
@@ -2,7 +2,7 @@ import type { SpaceMoltClient } from "../client/src/client";
22 import type { EmpireID } from "../client/src/types";
33 import { ACTION_DEFINITIONS, MAX_GOAL_LENGTH } from "./constants";
44 import type { ActionDecision } from "./types";
5-import { isValidEmpire, isValidPersonality } from "./utils";
5+import { isValidEmpire } from "./utils";
66
77 export { MAX_GOAL_LENGTH, PERSONALITY_ARCHETYPES } from "./constants";
88 export type { ActionDecision, PersonalityType } from "./types";
@@ -56,8 +56,14 @@ export function validateAction(decision: unknown): {
5656
5757 if (action === "chat") {
5858 const channel = String(args.channel ?? "");
59- if (!channel || !["local", "faction", "private"].includes(channel)) {
60- return { ok: false, error: "chat.channel must be local|faction|private" };
59+ if (
60+ !channel ||
61+ !["local", "system", "faction", "private", "global"].includes(channel)
62+ ) {
63+ return {
64+ ok: false,
65+ error: "chat.channel must be local|system|faction|private|global",
66+ };
6167 }
6268 const content = String(args.content ?? "");
6369 if (!content) {
@@ -103,7 +109,6 @@ export function validateAction(decision: unknown): {
103109 if (action === "register") {
104110 const username = String(args.username ?? "").trim();
105111 const empire = String(args.empire ?? "").trim();
106- const personality = String(args.personality ?? "").trim();
107112 if (!username) {
108113 return { ok: false, error: "register.username is required" };
109114 }
@@ -113,12 +118,6 @@ export function validateAction(decision: unknown): {
113118 if (!isValidEmpire(empire)) {
114119 return { ok: false, error: "register.empire is invalid" };
115120 }
116- if (!personality) {
117- return { ok: false, error: "register.personality is required" };
118- }
119- if (!isValidPersonality(personality)) {
120- return { ok: false, error: "register.personality is invalid" };
121- }
122121 }
123122
124123 if (action === "login") {
@@ -191,6 +190,37 @@ export function validateAction(decision: unknown): {
191190 }
192191 }
193192
193+ if (action === "set_status") {
194+ const statusMessage = String(args.status_message ?? "").trim();
195+ const clanTag = String(args.clan_tag ?? "").trim();
196+ if (!statusMessage && !clanTag) {
197+ return {
198+ ok: false,
199+ error: "set_status requires status_message or clan_tag",
200+ };
201+ }
202+ }
203+
204+ if (action === "set_colors") {
205+ const primaryColor = String(args.primary_color ?? "").trim();
206+ const secondaryColor = String(args.secondary_color ?? "").trim();
207+ if (!primaryColor) {
208+ return { ok: false, error: "set_colors.primary_color is required" };
209+ }
210+ if (!secondaryColor) {
211+ return { ok: false, error: "set_colors.secondary_color is required" };
212+ }
213+ }
214+
215+ if (action === "set_anonymous") {
216+ if (typeof args.anonymous !== "boolean") {
217+ return {
218+ ok: false,
219+ error: "set_anonymous.anonymous must be a boolean",
220+ };
221+ }
222+ }
223+
194224 return { ok: true, action: { action, args, goal } };
195225 }
196226
@@ -268,6 +298,23 @@ export function dispatchAction(
268298 client.createFaction(name, tag);
269299 return `create faction ${name} [${tag}]`;
270300 }
301+ case "set_status": {
302+ const statusMessage = String(args.status_message ?? "");
303+ const clanTag = String(args.clan_tag ?? "");
304+ client.setStatus(statusMessage, clanTag);
305+ return `set status "${statusMessage}" [${clanTag}]`;
306+ }
307+ case "set_colors": {
308+ const primaryColor = String(args.primary_color);
309+ const secondaryColor = String(args.secondary_color);
310+ client.setColors(primaryColor, secondaryColor);
311+ return `set colors ${primaryColor}/${secondaryColor}`;
312+ }
313+ case "set_anonymous": {
314+ const anonymous = Boolean(args.anonymous);
315+ client.setAnonymous(anonymous);
316+ return `set anonymous ${anonymous}`;
317+ }
271318 case "status":
272319 client.getStatus();
273320 return "get status";
src/constants.ts+3−0
@@ -141,6 +141,9 @@ export const ACTION_DEFINITIONS: Record<string, string[]> = {
141141 faction: ["content"],
142142 msg: ["target_id", "content"],
143143 create_faction: ["name", "tag"],
144+ set_status: ["status_message", "clan_tag"],
145+ set_colors: ["primary_color", "secondary_color"],
146+ set_anonymous: ["anonymous"],
144147 status: [],
145148 system: [],
146149 poi: [],
src/game-state.ts+4−0
@@ -1,5 +1,6 @@
11 import type { ClientState } from "../client/src/client";
22 import type { WorldSnapshot } from "./prompt";
3+import type { TuiContext } from "./tui/index";
34 import type { Credentials, RegistrationChoice } from "./types";
45
56 export class GameState {
@@ -32,5 +33,8 @@ export class GameState {
3233 registrationRetries = 0;
3334 failedRegistrationNames: string[] = [];
3435
36+ // TUI context (warnings + forum) - updated during action loop
37+ tuiContext: TuiContext = {};
38+
3539 readonly MAX_REGISTRATION_RETRIES = 3;
3640 }
src/index.ts+21−2
@@ -16,7 +16,7 @@ import { OllamaAgent, OllamaTimeoutError } from "./ollama";
1616 import { FileLoggerOutput } from "./output/file-logger-output";
1717 import { TuiOutput } from "./output/tui-output";
1818 import type { OutputInterface } from "./output-interface";
19-import { buildActionPrompt, type WorldSnapshot } from "./prompt";
19+import { buildActionPrompt, isStranded, type WorldSnapshot } from "./prompt";
2020 import { runRegistrationFlow } from "./registration";
2121 import {
2222 formatAiAction,
@@ -117,6 +117,7 @@ function updateOutput(): void {
117117 jumpTarget: gameState.lastJumpTarget,
118118 goal: gameState.currentGoal,
119119 inCombat: gameState.inCombat,
120+ context: gameState.tuiContext,
120121 });
121122 }
122123
@@ -246,6 +247,24 @@ async function startActionLoop(): Promise<void> {
246247 recentActions,
247248 REPETITION_THRESHOLD,
248249 );
250+ const forumFollowUpStatus = getForumFollowUpStatus();
251+ const stranded = isStranded(client.state, gameState.worldSnapshot);
252+
253+ // Update TUI context with warnings and forum data
254+ gameState.tuiContext = {
255+ warnings: {
256+ repetition: repetitionWarning,
257+ stranded,
258+ },
259+ forum: {
260+ followUpStatus: forumFollowUpStatus,
261+ lastThreadId: gameState.lastForumThreadId,
262+ lastPostTitle: gameState.lastForumPostTitle,
263+ lastPostCategory: gameState.lastForumPostCategory,
264+ },
265+ };
266+ updateOutput();
267+
249268 const prompt = buildActionPrompt({
250269 state: client.state,
251270 worldSnapshot: gameState.worldSnapshot,
@@ -258,7 +277,7 @@ async function startActionLoop(): Promise<void> {
258277 lastForumThreadId: gameState.lastForumThreadId,
259278 lastForumPostTitle: gameState.lastForumPostTitle,
260279 lastForumPostCategory: gameState.lastForumPostCategory,
261- forumFollowUpStatus: getForumFollowUpStatus(),
280+ forumFollowUpStatus,
262281 repetitionWarning,
263282 });
264283
src/output/file-logger-output.ts+1−0
@@ -95,6 +95,7 @@ export class FileLoggerOutput implements OutputInterface {
9595 if (data.inCombat !== undefined) this.state.inCombat = data.inCombat;
9696 if (data.combatTarget !== undefined)
9797 this.state.combatTarget = data.combatTarget;
98+ if (data.context !== undefined) this.state.context = data.context;
9899 }
99100
100101 private logStateChanges(): void {
src/prompt.ts+27−36
@@ -48,7 +48,7 @@ function getPersonalityGuidance(personality: PersonalityType): string {
4848 return `As a Merchant, you prioritize profit:
4949 - Dock at stations to check market prices and listings
5050 - Buy low in one system, sell high in another
51-- Post trade offers in faction chat or forums
51+- Post or create trade offers in faction chat or forums
5252 - Track profitable routes and cargo opportunities`;
5353
5454 case "warrior":
@@ -56,7 +56,7 @@ function getPersonalityGuidance(personality: PersonalityType): string {
5656 - Engage hostile or rival players when you spot them
5757 - Scan targets before attacking to assess threats
5858 - Seek out contested POIs and combat zones
59-- Boast victories in local or faction chat`;
59+- Boast victories in social actions`;
6060
6161 case "diplomat":
6262 return `As a Diplomat, you prioritize relationships:
@@ -130,7 +130,10 @@ function getEmpireDescription(empire: EmpireID): string {
130130 }
131131 }
132132
133-function isStranded(state: ClientState, snapshot?: WorldSnapshot): boolean {
133+export function isStranded(
134+ state: ClientState,
135+ snapshot?: WorldSnapshot,
136+): boolean {
134137 const player = state.player;
135138 const ship = state.ship;
136139 if (!player || !ship) return false;
@@ -143,7 +146,6 @@ function isStranded(state: ClientState, snapshot?: WorldSnapshot): boolean {
143146 }
144147
145148 const HELP_TEXT = `Available actions:
146-==========================
147149
148150 Connection Commands:
149151 register <username> <empire> - Create new account (empires: solarian, voidborn, crimson, nebula, outerrim)
@@ -181,6 +183,11 @@ Chat:
181183 msg <player_id> <message> - Send private message
182184 create_faction <name> <tag> - Create a faction
183185
186+Profile:
187+ set_status <message> <tag> - Set status message and clan tag
188+ set_colors <primary> <secondary> - Set profile colors
189+ set_anonymous <true|false> - Toggle anonymous mode
190+
184191 Forum:
185192 forum [page] [category] - List forum threads (categories: general, bugs, suggestions, trading, factions)
186193 forum_thread <thread_id> - Read a forum thread
@@ -198,7 +205,7 @@ export function buildActionPrompt(context: PromptContext): string {
198205 const memoryText = formatGroupedMemory(context.recentHistory);
199206 const forumFollowUpBlock = formatForumFollowUp(context);
200207 const forumContextBlock = formatForumContext(context.recentHistory);
201- const helpBlock = `\nHELP MENU:\n${HELP_TEXT}`;
208+ const helpBlock = `\nGAME INFORMATION:\n${HELP_TEXT}`;
202209 const goalText = context.currentGoal?.trim()
203210 ? context.currentGoal.trim()
204211 : "(none yet)";
@@ -225,19 +232,17 @@ Example: {"goal":"Request rescue","action":"faction","args":{"content":"Stranded
225232 `
226233 : "";
227234
228- return `You are an autonomous player for the SpaceMolt MMO.
235+ return `You are playing the SpaceMolt.
229236 SpaceMolt is a massively multiplayer space game built for AI agents, set in "The Crustacean Cosmos."
230237 Agents explore, trade, battle, and build empires in a living universe with emergent wars and a player-driven economy.
231238 The game emphasizes real-time AI fleet combat, ongoing discoveries of new systems, and shifting trade routes and alliances.
232-Players can run their own agent via a JSON-over-WebSocket protocol (one action per 10-second tick) or a reference client, and choose from five empires with distinct bonuses.
233239
234240 HOW TO PLAY:
235-You will receive current game state and recent events. Choose exactly one action to perform next.
236-Use your goal to plan what you want to achieve. You can change your goal at any action. You must have a goal.
241+Use all of the provided information to consider your goal. Then decide how to act next.
237242 Respond ONLY with a single JSON object. No extra text.
238243 ${helpBlock}
239244
240-CURRENT GOAL:
245+YOUR GOAL:
241246 ${goalText}
242247
243248 YOUR EMPIRE: ${getEmpireDescription(empire)}
@@ -256,21 +261,20 @@ YOUR SPEECH STYLE: ${speechStyleInfo.name}
256261 ${getSpeechStyleGuidance(speechStyle)}
257262 ${warningBlock}
258263 ${strandedBlock}
259-CURRENT STATE:
264+YOUR PLAYER:
260265 ${stateText}
261266
262-WORLD SNAPSHOT:
267+WORLD INFORMATION:
263268 ${worldText}
264269
265270 RECENT MEMORY:
266271 ${memoryText}
267272
268273 ${forumFollowUpBlock}
269-
270274 ${forumContextBlock}
271275
272276 ACTION SCHEMA (JSON ONLY):
273- {"goal":"...","action":"register|login|logout|travel|jump|dock|undock|mine|attack|scan|buy|sell|refuel|repair|craft|chat|say|faction|msg|create_faction|status|system|poi|base|skills|recipes|version|nearby|cargo|forum|forum_thread|forum_post|forum_reply|forum_upvote|help|wait","args":{...}}
277+ {"goal":"...","action":"register|login|logout|travel|jump|dock|undock|mine|attack|scan|buy|sell|refuel|repair|craft|chat|say|faction|msg|create_faction|set_status|set_colors|set_anonymous|status|system|poi|base|skills|recipes|version|nearby|cargo|forum|forum_thread|forum_post|forum_reply|forum_upvote|help|wait","args":{...}}
274278
275279 REQUIRED ARGS:
276280 - travel: {"target_poi":"..."}
@@ -280,12 +284,15 @@ REQUIRED ARGS:
280284 - buy: {"listing_id":"...","quantity":number}
281285 - sell: {"item_id":"...","quantity":number}
282286 - craft: {"recipe_id":"..."}
283-- chat: {"channel":"local|faction|private","content":"...","target_id":"..." if channel is private}
284- - say: {"content":"..."}
285- - faction: {"content":"..."}
286- - msg: {"target_id":"...","content":"..."}
287- - create_faction: {"name":"...","tag":"..."}
288- - forum: {"page":number,"category":"general|bugs|suggestions|trading|factions"} (both optional)
287+- chat: {"channel":"local|system|faction|private|global","content":"...","target_id":"..." if channel is private}
288+- say: {"content":"..."}
289+- faction: {"content":"..."}
290+- msg: {"target_id":"...","content":"..."}
291+- create_faction: {"name":"...","tag":"..."}
292+- set_status: {"status_message":"...","clan_tag":"..."}
293+- set_colors: {"primary_color":"...","secondary_color":"..."}
294+- set_anonymous: {"anonymous":true|false}
295+- forum: {"page":number,"category":"general|bugs|suggestions|trading|factions"} (both optional)
289296 - forum_thread: {"thread_id":"..."}
290297 - forum_post: {"category":"...","title":"...","content":"..."}
291298 - forum_reply: {"thread_id":"...","content":"..."}
@@ -299,34 +306,18 @@ FORMAT RULES:
299306 - Only use info actions (status/system/poi/base/nearby/cargo) when state is missing.
300307 - IDs must come from current state or world snapshot.
301308 - Never omit required args or leave them blank.
302-- If unsure, use {"goal":"...","action":"status"}.
303309
304310 ERROR RECOVERY:
305311 - If an action FAILED in recent memory, do NOT retry it with the same arguments.
306312 - Change your approach: try a different action, move to a different location, or update your goal.
307-- Common fixes: dock before refuel/repair, travel to belt before mine, undock before travel/jump.
308-- If fuel is 0 and there is no base at your current POI, travel/jump/refuel/dock will fail. Ask for help or wait.
309-
310-GAMEPLAY HEURISTIC (use as a tie-breaker):
311-- In combat: attack or scan nearby targets
312-- Docked and damaged/low fuel: repair or refuel
313-- Stranded (fuel=0, not docked, no base here): request help via say/faction/msg or wait
314-- Docked with cargo: sell; with credits and listings: buy
315-- At asteroid belt with cargo space: mine
316-- Need station services: dock first
317-- Want to travel while docked: undock first
318-- Have POI list: travel to unexplored POIs
319-- Current system exhausted: jump to connected system
320313
321314 INTERACTION GUIDELINES:
322- - Be respectful but competitive play is encouraged (attacking, boasting, complaining is fine)
323315 - Stay in character with your personality archetype and empire
324316 - Avoid spam - don't repeat identical messages rapidly
325317 - If you want to use faction chat but you are not in a faction, create one first
326318 - After creating a forum thread, read it immediately and revisit it occasionally when idle
327319 - Keep messages concise and game-relevant
328320 - If unsure what to say, stay silent rather than post nonsense
329-- You're an AI agent - play authentically but don't explicitly announce you're AI unless asked
330321 `;
331322 }
332323
src/tui/index.ts+37−0
@@ -7,6 +7,7 @@ import type { AlignmentType } from "../types";
77 import { applyColor, COLORS, THRESHOLDS } from "./colors";
88 import type { FormattedMessage } from "./formatters";
99 import { computeLayout, createBoxOptions } from "./layout";
10+import { renderContextPanel } from "./panels/context";
1011 import { type LocationData, renderLocationPanel } from "./panels/location";
1112 import { LogPanel, type LogTab } from "./panels/log";
1213 import {
@@ -16,6 +17,26 @@ import {
1617 import { renderTacticalPanel, type TacticalData } from "./panels/tactical";
1718 import { renderWorldInfoPanel, type WorldInfoData } from "./panels/world-info";
1819
20+export interface ContextWarnings {
21+ repetition?: {
22+ action: string;
23+ count: number;
24+ } | null;
25+ stranded?: boolean;
26+}
27+
28+export interface ContextForum {
29+ followUpStatus?: "unread" | "periodic" | null;
30+ lastThreadId?: string | null;
31+ lastPostTitle?: string | null;
32+ lastPostCategory?: string | null;
33+}
34+
35+export interface TuiContext {
36+ warnings?: ContextWarnings;
37+ forum?: ContextForum;
38+}
39+
1940 export interface TuiUpdateData {
2041 player?: Player | null;
2142 ship?: Ship | null;
@@ -41,6 +62,7 @@ export interface TuiUpdateData {
4162 shield?: number;
4263 maxShield?: number;
4364 };
65+ context?: TuiContext;
4466 }
4567
4668 export class Tui {
@@ -50,6 +72,7 @@ export class Tui {
5072 private logPanel: LogPanel;
5173 private locationBox: blessed.Widgets.BoxElement;
5274 private tacticalBox: blessed.Widgets.BoxElement;
75+ private contextBox: blessed.Widgets.BoxElement;
5376 private statusBar: blessed.Widgets.BoxElement;
5477 private debugBox: blessed.Widgets.BoxElement | null;
5578 private exitHandler: (() => void) | null = null;
@@ -117,6 +140,11 @@ export class Tui {
117140 );
118141 this.screen.append(this.tacticalBox);
119142
143+ this.contextBox = blessed.box(
144+ createBoxOptions(layout.context, "Context", COLORS.PANEL_BORDER_INACTIVE),
145+ );
146+ this.screen.append(this.contextBox);
147+
120148 this.statusBar = blessed.box({
121149 parent: this.screen,
122150 bottom: 0,
@@ -219,6 +247,7 @@ export class Tui {
219247 if (data.inCombat !== undefined) this.state.inCombat = data.inCombat;
220248 if (data.combatTarget !== undefined)
221249 this.state.combatTarget = data.combatTarget;
250+ if (data.context !== undefined) this.state.context = data.context;
222251
223252 this.updatePanels();
224253 this.render();
@@ -282,6 +311,9 @@ export class Tui {
282311 };
283312 this.tacticalBox.setContent(renderTacticalPanel(tacticalData));
284313
314+ // Context panel
315+ this.contextBox.setContent(renderContextPanel(this.state.context));
316+
285317 // Status bar
286318 this.updateStatusBar();
287319 }
@@ -368,6 +400,11 @@ export class Tui {
368400 this.tacticalBox.width = layout.tactical.width;
369401 this.tacticalBox.height = layout.tactical.height;
370402
403+ this.contextBox.left = layout.context.left;
404+ this.contextBox.top = layout.context.top;
405+ this.contextBox.width = layout.context.width;
406+ this.contextBox.height = layout.context.height;
407+
371408 this.statusBar.top = layout.statusBar.top;
372409 this.statusBar.width = layout.statusBar.width;
373410
src/tui/layout.ts+15−3
@@ -18,7 +18,7 @@ export const DEFAULT_LAYOUT: LayoutConfig = {
1818 leftWidth: 20, // 20% for left sidebar
1919 rightWidth: 20, // 20% for right sidebar (center gets 60%)
2020 leftTopHeightPercent: 40, // 40% of left sidebar for player/ship panel
21- rightTopHeightPercent: 60, // 60% of right sidebar for location panel
21+ rightTopHeightPercent: 40, // 40% of right sidebar for location panel
2222 };
2323
2424 export interface ComputedLayout {
@@ -27,6 +27,7 @@ export interface ComputedLayout {
2727 log: PanelDimensions;
2828 location: PanelDimensions;
2929 tactical: PanelDimensions;
30+ context: PanelDimensions;
3031 statusBar: PanelDimensions;
3132 }
3233
@@ -67,14 +68,19 @@ export function computeLayout(
6768 availableHeight - leftTopHeight,
6869 );
6970
70- // Right sidebar split
71+ // Right sidebar split into 3 panels: location (40%), tactical (30%), context (30%)
7172 const rightTopHeight = Math.max(
7273 MIN_PANEL_HEIGHT,
7374 Math.floor((availableHeight * config.rightTopHeightPercent) / 100),
7475 );
76+ const rightRemainingHeight = availableHeight - rightTopHeight;
77+ const rightMiddleHeight = Math.max(
78+ MIN_PANEL_HEIGHT,
79+ Math.floor(rightRemainingHeight / 2),
80+ );
7581 const rightBottomHeight = Math.max(
7682 MIN_PANEL_HEIGHT,
77- availableHeight - rightTopHeight,
83+ rightRemainingHeight - rightMiddleHeight,
7884 );
7985
8086 return {
@@ -106,6 +112,12 @@ export function computeLayout(
106112 left: leftWidthAbs + centerWidthAbs,
107113 top: rightTopHeight,
108114 width: rightWidthAbs,
115+ height: rightMiddleHeight,
116+ },
117+ context: {
118+ left: leftWidthAbs + centerWidthAbs,
119+ top: rightTopHeight + rightMiddleHeight,
120+ width: rightWidthAbs,
109121 height: rightBottomHeight,
110122 },
111123 statusBar: {
src/tui/panels/context.ts+66−0
@@ -0,0 +1,66 @@
1+// Context panel - warnings and forum status (prompt-only data not shown elsewhere)
2+
3+import { applyBold, applyColor, COLORS } from "../colors";
4+import type { TuiContext } from "../index";
5+
6+export function renderContextPanel(context: TuiContext | undefined): string {
7+ const lines: string[] = [];
8+
9+ // Warnings section
10+ lines.push(applyColor(applyBold("== Warnings =="), COLORS.PANEL_TITLE));
11+
12+ const warnings = context?.warnings;
13+ let hasWarnings = false;
14+
15+ if (warnings?.stranded) {
16+ lines.push(applyColor("STRANDED: No fuel, no base", COLORS.STATUS_DANGER));
17+ hasWarnings = true;
18+ }
19+
20+ if (warnings?.repetition) {
21+ lines.push(
22+ applyColor(
23+ `REPETITION: "${warnings.repetition.action}" x${warnings.repetition.count}`,
24+ COLORS.STATUS_WARNING,
25+ ),
26+ );
27+ hasWarnings = true;
28+ }
29+
30+ if (!hasWarnings) {
31+ lines.push(applyColor("None", COLORS.STATUS_INACTIVE));
32+ }
33+
34+ lines.push("");
35+
36+ // Forum section
37+ lines.push(applyColor(applyBold("== Forum =="), COLORS.PANEL_TITLE));
38+
39+ const forum = context?.forum;
40+ const status = forum?.followUpStatus ?? null;
41+ const threadId = forum?.lastThreadId ?? null;
42+ const title = forum?.lastPostTitle ?? null;
43+ const category = forum?.lastPostCategory ?? null;
44+
45+ if (status === "unread") {
46+ lines.push(applyColor("NEW THREAD - read now", COLORS.STATUS_WARNING));
47+ } else if (status === "periodic") {
48+ lines.push(applyColor("Active thread", COLORS.STATUS_SAFE));
49+ } else {
50+ lines.push(applyColor("No active thread", COLORS.STATUS_INACTIVE));
51+ }
52+
53+ if (threadId) {
54+ lines.push(`Thread: ${threadId}`);
55+ } else if (title || category) {
56+ if (category && title) {
57+ lines.push(`[${category}] ${title}`);
58+ } else if (title) {
59+ lines.push(`Title: ${title}`);
60+ } else if (category) {
61+ lines.push(`Category: ${category}`);
62+ }
63+ }
64+
65+ return lines.join("\n");
66+}