xonecas.io
5875
Os

ollama-space-molt-player / commit b60bedb

feat: add response summarizer util and integrate with tool call pipeline

- Add `response-summarizer.ts`: summarizes verbose tool results for better LLM context management and prevents context window overflow.
- Integrate summarization step into tool result handling in `game-client.ts`.
- Add initial tests for response summarization.
- Remove obsolete `logging.ts`, update project references.
- Create basic packages/cui utility modules (`formatter`, `logger`, `types`) and corresponding tests.
- Update project configuration and dependencies for new modules.
- Various minor updates to maintain strict and clean codebase.

xonecas2026-02-03 b60bedb6a09163691dfe326adda85421c742cd1f parent 4a4677c

15 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

bun.lock+10−0
@@ -16,11 +16,19 @@
1616 "version": "0.2.0",
1717 "dependencies": {
1818 "@modelcontextprotocol/sdk": "^1.25.3",
19+ "@spacemolt/cui": "workspace:*",
1920 },
2021 "devDependencies": {
2122 "@types/bun": "latest",
2223 },
2324 },
25+ "packages/cui": {
26+ "name": "@spacemolt/cui",
27+ "version": "0.1.0",
28+ "devDependencies": {
29+ "@types/bun": "latest",
30+ },
31+ },
2432 "packages/tui": {
2533 "name": "@spacemolt/tui",
2634 "version": "0.1.0",
@@ -50,6 +58,8 @@
5058
5159 "@spacemolt/client": ["@spacemolt/client@workspace:packages/client"],
5260
61+ "@spacemolt/cui": ["@spacemolt/cui@workspace:packages/cui"],
62+
5363 "@spacemolt/tui": ["@spacemolt/tui@workspace:packages/tui"],
5464
5565 "@types/bun": ["@types/bun@1.3.8", "", { "dependencies": { "bun-types": "1.3.8" } }, "sha512-3LvWJ2q5GerAXYxO2mffLTqOzEu5qnhEAlh48Vnu8WQfnmSwbgagjGZV6BoHKJztENYEDn6QmVd949W4uESRJA=="],
packages/client/package.json+3−2
@@ -12,9 +12,10 @@
1212 "strip-comments": "bun ../../scripts/strip-comments.ts"
1313 },
1414 "dependencies": {
15- "@modelcontextprotocol/sdk": "^1.25.3"
15+ "@modelcontextprotocol/sdk": "^1.25.3",
16+ "@spacemolt/cui": "workspace:*"
1617 },
1718 "devDependencies": {
1819 "@types/bun": "latest"
1920 }
20-}
21+}
packages/client/src/game-client.ts+48−14
@@ -7,10 +7,11 @@ import {
77 logToolCall,
88 logToolResult,
99 type LogContext,
10-} from "./logging.ts";
10+} from "@spacemolt/cui";
1111 import { loadModelConfig } from "./model-config.ts";
1212 import { MCPClient, type OllamaTool } from "./mcp-client.ts";
1313 import { OllamaClient, type ChatMessage, type ToolCall } from "./ollama.ts";
14+import { summarizeToolResult } from "./response-summarizer.ts";
1415 import type { ClientConfig } from "./types.ts";
1516
1617 interface ResolvedAccount {
@@ -61,7 +62,6 @@ export class GameClient {
6162 this.tools = this.mcp.getOllamaTools();
6263 logClientEvent(this.getLogContext(), "MCP connected", { tool_count: this.tools.length });
6364
64-
6565 const username = this.db.getActiveUsername();
6666
6767 if (username) {
@@ -99,7 +99,7 @@ export class GameClient {
9999 this.messages.push({
100100 role: "user",
101101 content: `You are resuming play as "${account.username}".
102-Use login(username="${account.username}", token="${account.token}") to authenticate, then continue playing.
102+Use login(username="${account.username}", password="${account.token}") to authenticate, then continue playing.
103103 After login, check your status with get_status() and decide what to do next.`,
104104 });
105105 }
@@ -120,8 +120,10 @@ Create your character:
120120 2. Choose empire: "solarian" (only one available currently)
121121 3. Call register(username="YourName", empire="solarian")
122122
123+Note: Empire is your starting civilization - it's NOT a player faction. To use faction chat or faction features, you'll need to create or join a player faction later with create_faction() or faction_join().
124+
123125 After registration succeeds, you'll receive a token. The system will save your credentials automatically.
124-Then check your status with get_status() and begin playing!`;
126+Then check your status with get_status() to see your starting location and ship, then begin playing!`;
125127
126128 const systemPrompt = this.buildSystemPrompt("", this.config.hint);
127129 this.messages = [
@@ -146,9 +148,32 @@ Then check your status with get_status() and begin playing!`;
146148 parts.push(`
147149 You have full agency. Make your own decisions. You are NOT an assistant - you are a player.
148150
151+CRITICAL - Track Your State:
152+- After jump/travel: response shows "ticks: N" - you're IN TRANSIT until arrival
153+- While in transit: CANNOT dock, undock, attack, mine, or modify ship - just wait
154+- Check docked_at_base in get_status() - if set, you're docked; if empty, you're in space
155+- Read error messages carefully - they tell you exactly what's wrong
156+
157+Action Prerequisites:
158+- To jump between systems: must NOT be docked (call undock first)
159+- To dock at a base: must be at a POI with a base_id (check with get_poi)
160+- To attack: need a weapon module (starter ship has mining module, not weapon)
161+- To install_mod/repair/refuel: must be docked at a base with those services
162+- To use faction chat: must be in a player faction (empire is NOT a faction)
163+
164+Key Concepts:
165+- Empire (solarian/voidborn/equilibrium): Your starting civilization - NOT a player faction
166+- Faction: Player-created organization via create_faction() - required for faction chat/war
167+- POI: Point of Interest in a system - some have bases (base_id), some don't
168+
169+Efficiency Tips:
170+- Use limit: 5 for get_nearby/get_notifications unless you need more
171+- Don't retry failed actions immediately - understand WHY it failed first
172+- When in transit, use time productively: check notifications, read forums, plan ahead
173+
149174 Key behaviors:
150-- Use get_notifications() periodically to check for chat messages, combat alerts, trade offers
151-- If rate limited, wait and try again - the error tells you how long
175+- Use get_notifications() periodically to check for chat, combat alerts, trade offers
176+- If rate limited, wait the time specified in the error
152177 - Be social! Chat with other players, form alliances, make enemies
153178 - Keep a captain's log of your adventures with captains_log_add()
154179 - Post on the forums to share discoveries and discuss strategy
@@ -248,7 +273,14 @@ You decide your goals: mining, trading, combat, exploration, faction politics -
248273
249274 const result = await this.mcp.callTool(name, args);
250275
251- logToolResult(this.getLogContext(), name, result);
276+ // Summarize tool result to reduce token count in LLM context
277+ const summarized = summarizeToolResult(name, result.content, result.success);
278+
279+ // Log with comparison: show both raw server data and what LLM sees
280+ logToolResult(this.getLogContext(), name, {
281+ ...result,
282+ summarized,
283+ });
252284
253285 this.db.saveMessage(Date.now(), "server", {
254286 tool: name,
@@ -263,7 +295,7 @@ You decide your goals: mining, trading, combat, exploration, faction politics -
263295 this.messages.push({
264296 role: "tool",
265297 name,
266- content: JSON.stringify(result.content),
298+ content: JSON.stringify(summarized),
267299 });
268300 }
269301
@@ -274,17 +306,17 @@ You decide your goals: mining, trading, combat, exploration, faction politics -
274306 const username = args.username as string;
275307 const empire = args.empire as string;
276308
277- let token: string | undefined;
309+ let password: string | undefined;
278310 let playerId: string | undefined;
279311
280312 if (typeof response === "object" && response !== null) {
281313 const resp = response as Record<string, unknown>;
282- token = resp.token as string | undefined;
314+ password = resp.password as string | undefined;
283315 playerId = resp.player_id as string | undefined;
284316 }
285317
286- if (!token || !playerId) {
287- logClientError(this.getLogContext(), "Registration response missing token or player_id", {
318+ if (!password || !playerId) {
319+ logClientError(this.getLogContext(), "Registration response missing password or player_id", {
288320 response,
289321 });
290322 return;
@@ -292,7 +324,7 @@ You decide your goals: mining, trading, combat, exploration, faction politics -
292324
293325 const characterPrompt = await this.generateCharacterPrompt(username, empire);
294326
295- this.db.saveUsername(username, token, characterPrompt, playerId, Date.now());
327+ this.db.saveUsername(username, password, characterPrompt, playerId, Date.now());
296328
297329 logClientEvent(this.getLogContext(username), "Account saved", { username, playerId });
298330
@@ -367,10 +399,12 @@ Respond with ONLY the character prompt, no explanations.`,
367399 ],
368400 });
369401 } else if (data.tool && data.content !== undefined) {
402+ // Summarize historical tool results to reduce context size
403+ const summarized = summarizeToolResult(data.tool, data.content, data.success !== false);
370404 this.messages.push({
371405 role: "tool",
372406 name: data.tool,
373- content: JSON.stringify(data.content),
407+ content: JSON.stringify(summarized),
374408 });
375409 } else if (data.response) {
376410 this.messages.push({
packages/client/src/logging.ts+0−234
@@ -1,234 +0,0 @@
1-const DETAIL_LINE_MAX_LENGTH = 300;
2-
3-const useColor = !process.env.NO_COLOR && process.env.TERM !== "dumb";
4-
5-const ANSI = {
6- reset: useColor ? "\x1b[0m" : "",
7- dim: useColor ? "\x1b[90m" : "",
8- cyan: useColor ? "\x1b[36m" : "",
9- green: useColor ? "\x1b[32m" : "",
10- yellow: useColor ? "\x1b[33m" : "",
11- red: useColor ? "\x1b[31m" : "",
12- magenta: useColor ? "\x1b[35m" : "",
13-};
14-
15-export type LogContext = {
16- tick: number;
17- instanceId: string;
18- username?: string | null;
19- verbose: boolean;
20-};
21-
22-type LogDirection = "in" | "out";
23-type LogLevel = "info" | "warn" | "error";
24-
25-function getColor(direction: LogDirection, level: LogLevel): string {
26- if (level === "error") return ANSI.red;
27- if (level === "warn") return ANSI.yellow;
28- return direction === "in" ? ANSI.cyan : ANSI.green;
29-}
30-
31-export function log(
32- context: LogContext,
33- direction: LogDirection,
34- summary: string,
35- details?: unknown,
36- level: LogLevel = "info",
37-): void {
38- const identifier = context.username || context.instanceId;
39- const arrow = direction === "in" ? "←" : "→";
40- const color = getColor(direction, level);
41- const header = `${color}[${identifier}] ${arrow} ${summary}${ANSI.reset}`;
42- const lines = formatDetailLines(details, context.verbose);
43- const logger = level === "error" ? console.error : level === "warn" ? console.warn : console.log;
44- logger(header);
45- if (lines.length > 0) {
46- lines.forEach((line) => logger(`${ANSI.dim} ${line}${ANSI.reset}`));
47- }
48- logger("");
49-}
50-
51-export function logClientEvent(context: LogContext, message: string, details?: unknown): void {
52- log(context, "out", message, details);
53-}
54-
55-export function logClientWarning(context: LogContext, message: string, details?: unknown): void {
56- log(context, "out", message, details, "warn");
57-}
58-
59-export function logClientError(context: LogContext, message: string, details?: unknown): void {
60- const normalized = normalizeErrorDetails(details);
61- log(context, "out", message, normalized, "error");
62-}
63-
64-export function logThinking(context: LogContext, thinking: string): void {
65- const formatted = formatThinking(thinking, context.verbose);
66- log(context, "out", "thinking", formatted);
67-}
68-
69-export function logToolCall(
70- context: LogContext,
71- toolName: string,
72- args: Record<string, unknown>,
73-): void {
74- const maskedArgs = maskSensitiveData(args);
75- log(context, "out", `tool call: ${toolName}`, maskedArgs);
76-}
77-
78-export function logToolResult(
79- context: LogContext,
80- toolName: string,
81- result: { success: boolean; content: unknown; error?: string },
82-): void {
83- const level = result.success ? "info" : "warn";
84- const summary = result.success ? `tool result: ${toolName}` : `tool error: ${toolName}`;
85- const details = result.success
86- ? result.content
87- : { error: result.error, content: result.content };
88- log(context, "in", summary, maskSensitiveData(details), level);
89-}
90-
91-function formatThinking(thinking: string, verbose: boolean): string {
92- if (verbose) {
93- return thinking;
94- }
95-
96- const sentences = splitSentences(thinking);
97- if (sentences.length <= 3) {
98- return sentences.join(" ").trim();
99- }
100- const first = sentences[0];
101- const lastTwo = sentences.slice(-2);
102- const omittedCount = sentences.length - 3;
103- return `${first} [... ${omittedCount} sentences omitted ...] ${lastTwo.join(" ")}`.trim();
104-}
105-
106-function splitSentences(text: string): string[] {
107- const normalized = text.replace(/\s+/g, " ").trim();
108- if (!normalized) {
109- return [];
110- }
111- const matches = normalized.match(/[^.!?]+[.!?]+|[^.!?]+$/g);
112- if (!matches) {
113- return [normalized];
114- }
115- return matches.map((sentence) => sentence.trim()).filter((sentence) => sentence.length > 0);
116-}
117-
118-function normalizeErrorDetails(details: unknown): unknown {
119- if (details instanceof Error) {
120- return {
121- message: details.message,
122- stack: details.stack,
123- };
124- }
125- return details;
126-}
127-
128-function formatDetailLines(details: unknown, verbose: boolean): string[] {
129- if (details === undefined || details === null) {
130- return [];
131- }
132- if (typeof details === "string") {
133- return formatMultiline(details, verbose);
134- }
135- return formatPayloadLines(details, "", verbose, { current: 0 });
136-}
137-
138-function formatMultiline(text: string, verbose: boolean): string[] {
139- const lines = text.split("\n");
140- const truncated =
141- verbose || lines.length <= 5
142- ? lines
143- : [lines[0], `[... ${lines.length - 4} more lines ...]`, ...lines.slice(-3)];
144- return truncated.map((line) => truncateLine(line));
145-}
146-
147-function truncateLine(line: string): string {
148- if (line.length <= DETAIL_LINE_MAX_LENGTH) {
149- return line;
150- }
151- return `${line.substring(0, DETAIL_LINE_MAX_LENGTH)}...`;
152-}
153-
154-function formatPayloadLines(
155- payload: unknown,
156- indent: string,
157- verbose: boolean,
158- lineCount: { current: number },
159-): string[] {
160- if (!payload || typeof payload !== "object") {
161- lineCount.current++;
162- return [`${indent}${String(payload)}`];
163- }
164-
165- const lines: string[] = [];
166- for (const [key, value] of Object.entries(payload)) {
167- if (!verbose && lineCount.current >= 4) {
168- lines.push(`${indent}...`);
169- return lines;
170- }
171- if (value === null || value === undefined) {
172- continue;
173- }
174- if (Array.isArray(value)) {
175- if (value.length === 0) {
176- lines.push(`${indent}${key}: []`);
177- lineCount.current++;
178- } else if (typeof value[0] === "object") {
179- lines.push(`${indent}${key}: [${value.length} items]`);
180- lineCount.current++;
181- if (verbose) {
182- value.forEach((item, idx) => {
183- lines.push(`${indent} [${idx}]:`);
184- lineCount.current++;
185- lines.push(...formatPayloadLines(item, `${indent} `, verbose, lineCount));
186- });
187- }
188- } else {
189- lines.push(`${indent}${key}: [${value.join(", ")}]`);
190- lineCount.current++;
191- }
192- } else if (typeof value === "object") {
193- lines.push(`${indent}${key}:`);
194- lineCount.current++;
195- if (verbose || lineCount.current < 4) {
196- lines.push(...formatPayloadLines(value, `${indent} `, verbose, lineCount));
197- }
198- } else if (typeof value === "string") {
199- const truncated = value.length > 100 ? `${value.substring(0, 100)}...` : value;
200- lines.push(`${indent}${key}: ${truncated}`);
201- lineCount.current++;
202- } else {
203- lines.push(`${indent}${key}: ${String(value)}`);
204- lineCount.current++;
205- }
206- }
207-
208- return lines.map((line) => truncateLine(line));
209-}
210-
211-function maskSensitiveData(payload: unknown): unknown {
212- if (payload === null || payload === undefined) {
213- return payload;
214- }
215- if (typeof payload !== "object") {
216- return payload;
217- }
218- if (Array.isArray(payload)) {
219- return payload.map((item) => maskSensitiveData(item));
220- }
221- const result: Record<string, unknown> = {};
222- for (const [key, value] of Object.entries(payload as Record<string, unknown>)) {
223- if (typeof key === "string" && key.toLowerCase().includes("token")) {
224- if (typeof value === "string") {
225- result[key] = value.length > 8 ? `${value.substring(0, 8)}...` : value;
226- } else {
227- result[key] = value;
228- }
229- } else {
230- result[key] = maskSensitiveData(value);
231- }
232- }
233- return result;
234-}
packages/client/src/response-summarizer.ts+513−0
@@ -0,0 +1,513 @@
1+/**
2+ * Response summarizer for tool results.
3+ *
4+ * Reduces token count in LLM context by extracting only essential information
5+ * from verbose tool responses. This helps prevent "lost in the middle" problems
6+ * and allows more effective use of the context window.
7+ */
8+
9+type SummarizerFn = (content: unknown) => unknown;
10+
11+/**
12+ * Summarize a tool result for inclusion in LLM context.
13+ * Errors are always preserved in full for learning value.
14+ */
15+export function summarizeToolResult(toolName: string, content: unknown, success: boolean): unknown {
16+ // Always preserve error messages in full
17+ if (!success) {
18+ return content;
19+ }
20+
21+ // Apply tool-specific summarizer if available
22+ const summarizer = TOOL_SUMMARIZERS[toolName];
23+ if (summarizer) {
24+ try {
25+ return summarizer(content);
26+ } catch {
27+ // If summarization fails, return original
28+ return content;
29+ }
30+ }
31+
32+ // Default: apply generic summarization
33+ return summarizeGeneric(content);
34+}
35+
36+/**
37+ * Generic summarizer for unknown tool responses.
38+ * Removes common verbose fields and truncates arrays.
39+ */
40+function summarizeGeneric(content: unknown): unknown {
41+ if (!content || typeof content !== "object") {
42+ return content;
43+ }
44+
45+ if (Array.isArray(content)) {
46+ // Truncate arrays to first 5 items with simplified entries
47+ return content.slice(0, 5).map((item) => summarizeGeneric(item));
48+ }
49+
50+ const obj = content as Record<string, unknown>;
51+ const result: Record<string, unknown> = {};
52+
53+ for (const [key, value] of Object.entries(obj)) {
54+ // Skip verbose/redundant fields
55+ if (SKIP_FIELDS.has(key)) {
56+ continue;
57+ }
58+
59+ // Recursively summarize nested objects
60+ if (value && typeof value === "object") {
61+ result[key] = summarizeGeneric(value);
62+ } else {
63+ result[key] = value;
64+ }
65+ }
66+
67+ return result;
68+}
69+
70+/**
71+ * Fields to skip in generic summarization.
72+ * These are typically verbose, redundant, or not useful for decision-making.
73+ */
74+const SKIP_FIELDS = new Set([
75+ // Timestamps (rarely needed for decisions)
76+ "created_at",
77+ "last_login_at",
78+ "last_active_at",
79+ "joined_at",
80+ "last_seen",
81+ "timestamp",
82+ "discovered_at",
83+ // Colors (cosmetic)
84+ "primary_color",
85+ "secondary_color",
86+ // Empty or default values
87+ "status_message",
88+ "clan_tag",
89+ "description",
90+ // Detailed stats (rarely needed in-flight)
91+ "stats",
92+ "skill_xp",
93+ "skills",
94+ "experience",
95+ // Full discovery data (too verbose)
96+ "discovered_systems",
97+ // Position data (usually not needed)
98+ "position",
99+]);
100+
101+/**
102+ * Tool-specific summarizers.
103+ * Each function extracts only the fields essential for LLM decision-making.
104+ */
105+const TOOL_SUMMARIZERS: Record<string, SummarizerFn> = {
106+ // Status tools - extract key decision-making info
107+ get_status: (content) => {
108+ const c = content as Record<string, unknown>;
109+ const player = c.player as Record<string, unknown> | undefined;
110+ const ship = c.ship as Record<string, unknown> | undefined;
111+
112+ return {
113+ player: player
114+ ? {
115+ username: player.username,
116+ credits: player.credits,
117+ current_system: player.current_system,
118+ current_poi: player.current_poi,
119+ docked_at_base: player.docked_at_base || null,
120+ home_base: player.home_base,
121+ }
122+ : undefined,
123+ ship: ship
124+ ? {
125+ name: ship.name,
126+ class_id: ship.class_id,
127+ hull: ship.hull,
128+ max_hull: ship.max_hull,
129+ fuel: ship.fuel,
130+ max_fuel: ship.max_fuel,
131+ cargo_used: ship.cargo_used,
132+ cargo_capacity: ship.cargo_capacity,
133+ modules: ship.modules,
134+ }
135+ : undefined,
136+ };
137+ },
138+
139+ // Registration - extract essentials, password already logged separately
140+ register: (content) => {
141+ const c = content as Record<string, unknown>;
142+ const player = c.player as Record<string, unknown> | undefined;
143+ const ship = c.ship as Record<string, unknown> | undefined;
144+ const system = c.system as Record<string, unknown> | undefined;
145+ const poi = c.poi as Record<string, unknown> | undefined;
146+
147+ return {
148+ message: c.message,
149+ player_id: c.player_id,
150+ player: player
151+ ? {
152+ username: player.username,
153+ empire: player.empire,
154+ credits: player.credits,
155+ current_system: player.current_system,
156+ current_poi: player.current_poi,
157+ docked_at_base: player.docked_at_base,
158+ }
159+ : undefined,
160+ ship: ship
161+ ? {
162+ name: ship.name,
163+ class_id: ship.class_id,
164+ hull: ship.hull,
165+ max_hull: ship.max_hull,
166+ fuel: ship.fuel,
167+ max_fuel: ship.max_fuel,
168+ }
169+ : undefined,
170+ system: system
171+ ? {
172+ id: system.id,
173+ name: system.name,
174+ connections: system.connections,
175+ pois: system.pois,
176+ }
177+ : undefined,
178+ poi: poi
179+ ? {
180+ id: poi.id,
181+ name: poi.name,
182+ type: poi.type,
183+ base_id: poi.base_id,
184+ }
185+ : undefined,
186+ password: c.password,
187+ };
188+ },
189+
190+ // Login - similar to register
191+ login: (content) => {
192+ const c = content as Record<string, unknown>;
193+ const player = c.player as Record<string, unknown> | undefined;
194+ const ship = c.ship as Record<string, unknown> | undefined;
195+
196+ return {
197+ message: c.message,
198+ player: player
199+ ? {
200+ username: player.username,
201+ credits: player.credits,
202+ current_system: player.current_system,
203+ current_poi: player.current_poi,
204+ docked_at_base: player.docked_at_base,
205+ }
206+ : undefined,
207+ ship: ship
208+ ? {
209+ name: ship.name,
210+ hull: ship.hull,
211+ max_hull: ship.max_hull,
212+ fuel: ship.fuel,
213+ max_fuel: ship.max_fuel,
214+ }
215+ : undefined,
216+ };
217+ },
218+
219+ // Nearby players - just username and key identifiers
220+ get_nearby: (content) => {
221+ const c = content as Record<string, unknown>;
222+ const nearby = c.nearby as Array<Record<string, unknown>> | undefined;
223+
224+ return {
225+ count: c.count,
226+ nearby: nearby
227+ ? nearby.slice(0, 10).map((p) => ({
228+ username: p.username,
229+ player_id: p.player_id,
230+ ship_class: p.ship_class,
231+ in_combat: p.in_combat,
232+ }))
233+ : [],
234+ };
235+ },
236+
237+ // Notifications - keep type and essential content
238+ get_notifications: (content) => {
239+ const c = content as Record<string, unknown>;
240+ const notifications = c.notifications as Array<Record<string, unknown>> | undefined;
241+
242+ return {
243+ count: c.count,
244+ remaining: c.remaining,
245+ notifications: notifications
246+ ? notifications.slice(0, 10).map((n) => ({
247+ type: n.type,
248+ message: n.message,
249+ data: n.data,
250+ }))
251+ : [],
252+ };
253+ },
254+
255+ // Navigation actions - keep just the outcome
256+ travel: (content) => {
257+ const c = content as Record<string, unknown>;
258+ return {
259+ action: c.action || "travel",
260+ ticks: c.ticks,
261+ destination: c.destination || c.target_poi,
262+ message: c.message,
263+ };
264+ },
265+
266+ jump: (content) => {
267+ const c = content as Record<string, unknown>;
268+ return {
269+ action: c.action || "jump",
270+ ticks: c.ticks,
271+ destination: c.destination || c.target_system,
272+ message: c.message,
273+ };
274+ },
275+
276+ dock: (content) => {
277+ const c = content as Record<string, unknown>;
278+ return {
279+ action: c.action || "dock",
280+ base_id: c.base_id,
281+ base_name: c.base_name,
282+ message: c.message,
283+ };
284+ },
285+
286+ undock: (content) => {
287+ const c = content as Record<string, unknown>;
288+ return {
289+ action: c.action || "undock",
290+ message: c.message,
291+ };
292+ },
293+
294+ // Combat actions
295+ attack: (content) => {
296+ const c = content as Record<string, unknown>;
297+ return {
298+ action: c.action || "attack",
299+ target: c.target,
300+ damage: c.damage,
301+ result: c.result,
302+ message: c.message,
303+ };
304+ },
305+
306+ mine: (content) => {
307+ const c = content as Record<string, unknown>;
308+ return {
309+ action: c.action || "mine",
310+ ore_type: c.ore_type,
311+ quantity: c.quantity,
312+ message: c.message,
313+ };
314+ },
315+
316+ // System info - key navigation data only
317+ get_system: (content) => {
318+ const c = content as Record<string, unknown>;
319+ return {
320+ id: c.id,
321+ name: c.name,
322+ empire: c.empire,
323+ connections: c.connections,
324+ pois: c.pois,
325+ police_level: c.police_level,
326+ };
327+ },
328+
329+ get_poi: (content) => {
330+ const c = content as Record<string, unknown>;
331+ return {
332+ id: c.id,
333+ name: c.name,
334+ type: c.type,
335+ system_id: c.system_id,
336+ base_id: c.base_id || null,
337+ };
338+ },
339+
340+ // Faction info - essential data
341+ faction_info: (content) => {
342+ const c = content as Record<string, unknown>;
343+ const members = c.members as Array<Record<string, unknown>> | undefined;
344+
345+ return {
346+ id: c.id,
347+ name: c.name,
348+ tag: c.tag,
349+ leader_username: c.leader_username,
350+ member_count: c.member_count,
351+ members: members
352+ ? members.slice(0, 5).map((m) => ({
353+ username: m.username,
354+ role: m.role,
355+ }))
356+ : undefined,
357+ is_member: c.is_member,
358+ at_war: c.at_war,
359+ };
360+ },
361+
362+ create_faction: (content) => {
363+ const c = content as Record<string, unknown>;
364+ return {
365+ action: c.action || "create_faction",
366+ faction_id: c.faction_id,
367+ name: c.name,
368+ };
369+ },
370+
371+ // Chat - already compact, just ensure structure
372+ chat: (content) => {
373+ const c = content as Record<string, unknown>;
374+ const notification = c.notification as Record<string, unknown> | undefined;
375+ const message = notification?.Message as Record<string, unknown> | undefined;
376+
377+ return {
378+ message: c.message,
379+ sent_at: c.sent_at,
380+ channel: notification?.Channel,
381+ content: message?.content,
382+ };
383+ },
384+
385+ // Forum
386+ forum_list: (content) => {
387+ const c = content as Record<string, unknown>;
388+ const threads = c.threads as Array<Record<string, unknown>> | undefined;
389+
390+ return {
391+ count: c.count,
392+ threads: threads
393+ ? threads.slice(0, 5).map((t) => ({
394+ id: t.id,
395+ title: t.title,
396+ author: t.author,
397+ replies: t.reply_count || t.replies,
398+ }))
399+ : [],
400+ };
401+ },
402+
403+ forum_get_thread: (content) => {
404+ const c = content as Record<string, unknown>;
405+ const replies = c.replies as Array<Record<string, unknown>> | undefined;
406+
407+ return {
408+ id: c.id,
409+ title: c.title,
410+ author: c.author,
411+ content: c.content,
412+ reply_count: replies?.length || c.reply_count,
413+ replies: replies
414+ ? replies.slice(0, 5).map((r) => ({
415+ author: r.author,
416+ content: typeof r.content === "string" ? r.content.slice(0, 200) : r.content,
417+ }))
418+ : [],
419+ };
420+ },
421+
422+ forum_create_thread: (content) => {
423+ const c = content as Record<string, unknown>;
424+ return {
425+ message: c.message,
426+ thread_id: c.thread_id,
427+ title: c.title,
428+ };
429+ },
430+
431+ forum_reply: (content) => {
432+ const c = content as Record<string, unknown>;
433+ return {
434+ message: c.message,
435+ reply_id: c.reply_id,
436+ };
437+ },
438+
439+ // Market
440+ get_market: (content) => {
441+ const c = content as Record<string, unknown>;
442+ const listings = c.listings as Array<Record<string, unknown>> | undefined;
443+
444+ return {
445+ count: c.count,
446+ listings: listings
447+ ? listings.slice(0, 10).map((l) => ({
448+ id: l.id,
449+ item_id: l.item_id,
450+ item_name: l.item_name,
451+ quantity: l.quantity,
452+ price: l.price,
453+ seller: l.seller,
454+ }))
455+ : [],
456+ };
457+ },
458+
459+ // Ship management
460+ get_ship: (content) => {
461+ const c = content as Record<string, unknown>;
462+ const modules = c.modules as Array<Record<string, unknown>> | undefined;
463+ const cargo = c.cargo as Array<Record<string, unknown>> | undefined;
464+
465+ return {
466+ id: c.id,
467+ name: c.name,
468+ class_id: c.class_id,
469+ hull: c.hull,
470+ max_hull: c.max_hull,
471+ shield: c.shield,
472+ max_shield: c.max_shield,
473+ fuel: c.fuel,
474+ max_fuel: c.max_fuel,
475+ cargo_used: c.cargo_used,
476+ cargo_capacity: c.cargo_capacity,
477+ modules: modules
478+ ? modules.map((m) => ({
479+ id: m.id,
480+ type: m.type,
481+ name: m.name,
482+ }))
483+ : c.modules,
484+ cargo: cargo
485+ ? cargo.map((item) => ({
486+ id: item.id,
487+ name: item.name,
488+ quantity: item.quantity,
489+ }))
490+ : [],
491+ };
492+ },
493+
494+ // Captain's log
495+ captains_log_add: (content) => {
496+ const c = content as Record<string, unknown>;
497+ return {
498+ message: c.message,
499+ entry_id: c.entry_id,
500+ };
501+ },
502+
503+ captains_log_get: (content) => {
504+ const c = content as Record<string, unknown>;
505+ return {
506+ entry: c.entry,
507+ index: c.index,
508+ };
509+ },
510+
511+ // Help - keep full content (it's instructional)
512+ help: (content) => content,
513+};
packages/client/src/tool-schemas.ts+10−4
@@ -41,9 +41,9 @@ export const TOOL_SCHEMA_PATCHES: Record<string, SchemaPatch> = {
4141 login: {
4242 properties: {
4343 username: { type: "string", description: "Your username" },
44- token: { type: "string", description: "Your 256-bit authentication token" },
44+ password: { type: "string", description: "Your 256-bit hex password" },
4545 },
46- required: ["username", "token"],
46+ required: ["username", "password"],
4747 },
4848
4949 // Navigation
@@ -242,7 +242,10 @@ export const TOOL_SCHEMA_PATCHES: Record<string, SchemaPatch> = {
242242 },
243243 faction_info: {
244244 properties: {
245- faction_id: { type: "string", description: "Faction ID (optional, defaults to your faction)" },
245+ faction_id: {
246+ type: "string",
247+ description: "Faction ID (optional, defaults to your faction)",
248+ },
246249 },
247250 required: [],
248251 },
@@ -519,7 +522,10 @@ export const TOOL_SCHEMA_PATCHES: Record<string, SchemaPatch> = {
519522 get_notifications: {
520523 properties: {
521524 limit: { type: "number", description: "Max notifications (default 50)" },
522- types: { type: "array", description: "Filter by types: chat, combat, trade, faction, friend, forum, system" },
525+ types: {
526+ type: "array",
527+ description: "Filter by types: chat, combat, trade, faction, friend, forum, system",
528+ },
523529 clear: { type: "boolean", description: "Clear notifications after reading (default true)" },
524530 },
525531 required: [],
packages/client/tests/response-summarizer.test.ts+282−0
@@ -0,0 +1,282 @@
1+import { describe, expect, test } from "bun:test";
2+import { summarizeToolResult } from "../src/response-summarizer.ts";
3+
4+describe("Response Summarizer", () => {
5+ describe("Error handling", () => {
6+ test("should preserve error messages in full", () => {
7+ const errorContent = { error: "not_docked", message: "You must be docked to do this" };
8+ const result = summarizeToolResult("dock", errorContent, false);
9+ expect(result).toEqual(errorContent);
10+ });
11+ });
12+
13+ describe("get_status summarization", () => {
14+ test("should extract essential player and ship info", () => {
15+ const fullStatus = {
16+ player: {
17+ id: "abc123",
18+ username: "TestPlayer",
19+ empire: "solarian",
20+ credits: 1000,
21+ created_at: "2026-01-01T00:00:00Z",
22+ last_login_at: "2026-02-03T12:00:00Z",
23+ last_active_at: "2026-02-03T12:00:00Z",
24+ status_message: "",
25+ clan_tag: "",
Cut short: this commit's diff is over 1000 lines.
packages/cui/package.json+15−0
Cut short: this commit's diff is over 1000 lines.
packages/cui/src/formatter.ts+180−0
Cut short: this commit's diff is over 1000 lines.
packages/cui/src/index.ts+33−0
Cut short: this commit's diff is over 1000 lines.
packages/cui/src/logger.ts+164−0
Cut short: this commit's diff is over 1000 lines.
packages/cui/src/types.ts+21−0
Cut short: this commit's diff is over 1000 lines.
packages/cui/tests/formatter.test.ts+181−0
Cut short: this commit's diff is over 1000 lines.
packages/cui/tsconfig.json+28−0
Cut short: this commit's diff is over 1000 lines.
tsconfig.json+2−1
Cut short: this commit's diff is over 1000 lines.