@@ -11,7 +11,12 @@ import type {
1111 StateUpdatePayload,
1212 WelcomePayload,
1313 } from "../client/src/types";
14-import { dispatchAction, validateAction } from "./actions";
14+import {
15+ dispatchAction,
16+ PERSONALITY_ARCHETYPES,
17+ type PersonalityType,
18+ validateAction,
19+} from "./actions";
1520 import { config } from "./config";
1621 import { MemoryStore } from "./memory";
1722 import { OllamaAgent, OllamaTimeoutError } from "./ollama";
@@ -22,14 +27,25 @@ import {
2227 } from "./prompt";
2328 import { Tui } from "./tui";
2429
25-type Credentials = { username: string; token: string };
26-type RegistrationChoice = { username: string; empire: EmpireID };
30+type Credentials = {
31+ username: string;
32+ token: string;
33+ personality: PersonalityType;
34+};
35+type RegistrationChoice = {
36+ username: string;
37+ empire: EmpireID;
38+ personality: PersonalityType;
39+ personality_reason?: string;
40+};
2741
2842 const memory = new MemoryStore(config.memoryPath);
2943 const ollama = new OllamaAgent(
3044 config.ollamaUrl,
3145 config.ollamaModel,
3246 config.ollamaTimeoutMs,
47+ config.ollamaTemperature,
48+ config.ollamaThinking,
3349 );
3450 const tui = new Tui(config.debug);
3551
@@ -46,7 +62,12 @@ const worldSnapshot: WorldSnapshot = {};
4662 let registrationRetries = 0;
4763 let travelInProgress = false;
4864 let lastTravelTarget: string | null = null;
65+let jumpInProgress = false;
66+let lastJumpTarget: string | null = null;
4967 let currentGoal: string | null = null;
68+let lastSystemId: string | null = null;
69+let lastPoiId: string | null = null;
70+let lastDocked = false;
5071 const MAX_REGISTRATION_RETRIES = 3;
5172 const failedRegistrationNames: string[] = [];
5273
@@ -62,8 +83,12 @@ async function loadCredentials(): Promise<Credentials | null> {
6283 return null;
6384 }
6485
65-async function saveCredentials(username: string, token: string): Promise<void> {
66- const data: Credentials = { username, token };
86+async function saveCredentials(
87+ username: string,
88+ token: string,
89+ personality: PersonalityType,
90+): Promise<void> {
91+ const data: Credentials = { username, token, personality };
6792 await Bun.write(config.credentialsFile, JSON.stringify(data, null, 2));
6893 }
6994
@@ -83,6 +108,8 @@ function updateStatus(): void {
83108 worldSnapshot,
84109 travelInProgress,
85110 lastTravelTarget,
111+ jumpInProgress,
112+ lastJumpTarget,
86113 currentGoal,
87114 );
88115 const sidebarText = formatSidebar(
@@ -90,6 +117,9 @@ function updateStatus(): void {
90117 worldSnapshot,
91118 travelInProgress,
92119 lastTravelTarget,
120+ jumpInProgress,
121+ lastJumpTarget,
122+ credentials?.personality,
93123 );
94124 tui.setStatus(statusText);
95125 tui.setSidebar(sidebarText);
@@ -116,13 +146,37 @@ async function runRegistrationFlow(): Promise<void> {
116146 const prompt = buildRegistrationPrompt(true, failedRegistrationNames);
117147 tui.setPrompt(prompt);
118148 const result = await ollama.generateJson<RegistrationChoice>(prompt);
149+ if (result.thinking) {
150+ log(
151+ `[Thinking] ${result.thinking.slice(0, 200)}${result.thinking.length > 200 ? "..." : ""}`,
152+ );
153+ }
119154 const username = String(result.json.username ?? "").trim();
120155 const empire = String(result.json.empire ?? "").trim() as EmpireID;
121- if (!username || !isValidEmpire(empire)) {
156+ const personality = String(
157+ result.json.personality ?? "",
158+ ).trim() as PersonalityType;
159+ const personalityReason = result.json.personality_reason
160+ ? String(result.json.personality_reason).trim()
161+ : undefined;
162+ if (
163+ !username ||
164+ !isValidEmpire(empire) ||
165+ !isValidPersonality(personality)
166+ ) {
122167 throw new Error("Invalid registration response");
123168 }
124- pendingRegistration = { username, empire };
169+ pendingRegistration = {
170+ username,
171+ empire,
172+ personality,
173+ personality_reason: personalityReason,
174+ };
175+ const personalityInfo = PERSONALITY_ARCHETYPES[personality];
125176 log(`Registering new account: ${username} (${empire})`);
177+ log(
178+ `Chosen personality: ${personalityInfo.emoji} ${personalityInfo.name}${personalityReason ? ` - ${personalityReason}` : ""}`,
179+ );
126180 client.register(username, empire);
127181 return;
128182 } catch (error) {
@@ -131,8 +185,12 @@ async function runRegistrationFlow(): Promise<void> {
131185 }
132186
133187 const fallback = `molt-bot-${Math.floor(Math.random() * 10000)}`;
134- pendingRegistration = { username: fallback, empire: "solarian" };
135- log(`Falling back to account: ${fallback} (solarian)`);
188+ pendingRegistration = {
189+ username: fallback,
190+ empire: "solarian",
191+ personality: "pragmatist",
192+ };
193+ log(`Falling back to account: ${fallback} (solarian, pragmatist)`);
136194 client.register(fallback, "solarian");
137195 }
138196
@@ -142,13 +200,70 @@ function isValidEmpire(empire: string): empire is EmpireID {
142200 );
143201 }
144202
203+function isValidPersonality(
204+ personality: string,
205+): personality is PersonalityType {
206+ return ["explorer", "merchant", "warrior", "diplomat", "pragmatist"].includes(
207+ personality,
208+ );
209+}
210+
211+function refreshSnapshotForLocation(player: {
212+ current_system?: string;
213+ current_poi?: string;
214+ docked_at_base?: string | boolean | null;
215+}): void {
216+ const systemId = player.current_system ?? null;
217+ const poiId = player.current_poi ?? null;
218+ const docked = Boolean(player.docked_at_base);
219+ const systemChanged = systemId && systemId !== lastSystemId;
220+ const poiChanged = poiId && poiId !== lastPoiId;
221+
222+ if (systemChanged) {
223+ worldSnapshot.system = null;
224+ worldSnapshot.pois = [];
225+ worldSnapshot.poi = null;
226+ worldSnapshot.base = null;
227+ client.state.system = null;
228+ client.state.poi = null;
229+ client.state.base = null;
230+ client.getSystem();
231+ client.getPOI();
232+ if (docked) {
233+ client.getBase();
234+ }
235+ } else if (poiChanged) {
236+ worldSnapshot.poi = null;
237+ worldSnapshot.base = null;
238+ client.state.poi = null;
239+ client.state.base = null;
240+ client.getPOI();
241+ if (docked) {
242+ client.getBase();
243+ }
244+ }
245+
246+ if (!docked && lastDocked) {
247+ worldSnapshot.base = null;
248+ client.state.base = null;
249+ }
250+
251+ if (docked && !lastDocked && !systemChanged && !poiChanged) {
252+ client.getBase();
253+ }
254+
255+ if (systemId) lastSystemId = systemId;
256+ if (poiId) lastPoiId = poiId;
257+ lastDocked = docked;
258+}
259+
145260 async function startActionLoop(): Promise<void> {
146261 if (actionLoopRunning) return;
147262 actionLoopRunning = true;
148263
149264 while (client.state.authenticated) {
150265 try {
151- if (travelInProgress) {
266+ if (travelInProgress || jumpInProgress) {
152267 await sleep(config.tickDelayMs);
153268 continue;
154269 }
@@ -161,12 +276,18 @@ async function startActionLoop(): Promise<void> {
161276 worldSnapshot,
162277 recentHistory,
163278 currentGoal,
279+ personality: credentials?.personality,
164280 });
165281
166282 tui.setPrompt(prompt);
167283
168284 const promptExcerpt = prompt.slice(0, 1000);
169285 const result = await ollama.generateJson(prompt);
286+ if (result.thinking) {
287+ log(
288+ `[Thinking] ${result.thinking.slice(0, 200)}${result.thinking.length > 200 ? "..." : ""}`,
289+ );
290+ }
170291 const validation = validateAction(result.json);
171292 if (!validation.ok || !validation.action) {
172293 const message = `Invalid action from LLM: ${validation.error ?? "unknown"}`;
@@ -213,6 +334,10 @@ async function startActionLoop(): Promise<void> {
213334 lastTravelTarget =
214335 String(validation.action.args?.target_poi ?? "").trim() || null;
215336 }
337+ if (actionName === "jump") {
338+ lastJumpTarget =
339+ String(validation.action.args?.target_system ?? "").trim() || null;
340+ }
216341 const actionLog = dispatchAction(client, validation.action);
217342 log(`Action: ${actionLog}`);
218343 memory.appendEvent("action_sent", { action: validation.action });
@@ -327,7 +452,16 @@ client.on<RegisteredPayload>("registered", async (data) => {
327452 registrationRetries = 0;
328453 failedRegistrationNames.length = 0;
329454 if (pendingRegistration) {
330- await saveCredentials(pendingRegistration.username, data.token);
455+ await saveCredentials(
456+ pendingRegistration.username,
457+ data.token,
458+ pendingRegistration.personality,
459+ );
460+ credentials = {
461+ username: pendingRegistration.username,
462+ token: data.token,
463+ personality: pendingRegistration.personality,
464+ };
331465 log(`Registered. Saved credentials for ${pendingRegistration.username}`);
332466 pendingRegistration = null;
333467 } else {
@@ -340,6 +474,9 @@ client.on<LoggedInPayload>("logged_in", (data) => {
340474 memory.appendEvent("logged_in", data);
341475 worldSnapshot.system = data.system;
342476 worldSnapshot.poi = data.poi;
477+ lastSystemId = data.player.current_system ?? null;
478+ lastPoiId = data.player.current_poi ?? null;
479+ lastDocked = Boolean(data.player.docked_at_base);
343480 currentGoal = memory.getLatestGoal(data.player.username);
344481 client.getSystem();
345482 client.getPOI();
@@ -374,6 +511,7 @@ client.on<ErrorPayload>("error", (data) => {
374511
375512 client.on<StateUpdatePayload>("state_update", (data) => {
376513 memory.appendEvent("state_update", data);
514+ refreshSnapshotForLocation(data.player);
377515 updateStatus();
378516 saveSnapshot();
379517 if (data.in_combat) {
@@ -401,12 +539,21 @@ client.on("ok", (data: Record<string, unknown>) => {
401539 if (action === "travel") {
402540 travelInProgress = true;
403541 }
542+ if (action === "jump") {
543+ jumpInProgress = true;
544+ }
404545 if (action === "arrived") {
405546 travelInProgress = false;
406547 lastTravelTarget = null;
407548 client.getSystem();
408549 client.getPOI();
409550 }
551+ if (action === "jumped") {
552+ jumpInProgress = false;
553+ lastJumpTarget = null;
554+ client.getSystem();
555+ client.getPOI();
556+ }
410557 });
411558
412559 client.on("version_info", (data: Record<string, unknown>) => {
@@ -415,6 +562,22 @@ client.on("version_info", (data: Record<string, unknown>) => {
415562 });
416563
417564 credentials = await loadCredentials();
565+
566+// Force re-registration if personality is missing
567+if (credentials && !credentials.personality) {
568+ log("Credentials missing personality field - forcing re-registration");
569+ try {
570+ await Bun.write(config.credentialsFile, ""); // Clear file
571+ const file = Bun.file(config.credentialsFile);
572+ if (await file.exists()) {
573+ await file.remove?.();
574+ }
575+ } catch (error) {
576+ log(`Failed to delete credentials: ${(error as Error).message}`);
577+ }
578+ credentials = null;
579+}
580+
418581 await client.connect();
419582 updateStatus();
420583
@@ -441,10 +604,16 @@ function buildStatusText(
441604 snapshot: WorldSnapshot,
442605 traveling: boolean,
443606 travelTargetId: string | null,
607+ jumping: boolean,
608+ jumpTargetId: string | null,
444609 goal: string | null,
445610 ): string {
446611 if (!state.player || !state.ship) return "Not logged in";
447612 const goalText = goal?.trim() ? ` | Goal: ${goal.trim()}` : "";
613+ if (jumping) {
614+ const destination = resolveSystemName(jumpTargetId, snapshot, state);
615+ return `Jumping to ${destination}${goalText}`;
616+ }
448617 if (traveling) {
449618 const destination = resolvePoiName(travelTargetId, snapshot, state);
450619 return `Traveling to ${destination}${goalText}`;
@@ -459,6 +628,9 @@ function formatSidebar(
459628 snapshot: WorldSnapshot,
460629 traveling: boolean,
461630 travelTargetId: string | null,
631+ jumping: boolean,
632+ jumpTargetId: string | null,
633+ personality?: PersonalityType,
462634 ): string {
463635 if (!state.player || !state.ship) return "Not logged in.";
464636
@@ -480,13 +652,27 @@ function formatSidebar(
480652 const base = snapshot.base ?? state.base;
481653 const pois = snapshot.pois ?? [];
482654
483- pushSection("Player", [
655+ const playerLines = [
484656 formatLine("Name", state.player.username, width),
485657 formatLine("Empire", state.player.empire, width),
658+ ];
659+ if (personality) {
660+ const personalityInfo = PERSONALITY_ARCHETYPES[personality];
661+ playerLines.push(
662+ formatLine(
663+ "Role",
664+ `${personalityInfo.emoji} ${personalityInfo.name}`,
665+ width,
666+ ),
667+ );
668+ }
669+ playerLines.push(
486670 formatLine("Credits", String(state.player.credits), width),
487671 formatLine("Docked", state.player.docked_at_base ? "Y" : "N", width),
488672 formatLine("Tick", String(state.currentTick), width),
489- ]);
673+ );
674+
675+ pushSection("Player", playerLines);
490676
491677 pushSection("Ship", [
492678 formatLine("Hull", `${state.ship.hull}/${state.ship.max_hull}`, width),
@@ -511,6 +697,7 @@ function formatSidebar(
511697 ),
512698 formatLine("POI", poi?.name ?? state.player.current_poi ?? "-", width),
513699 formatLine("Travel", traveling ? "Y" : "N", width),
700+ formatLine("Jump", jumping ? "Y" : "N", width),
514701 ];
515702 if (traveling) {
516703 locationLines.push(
@@ -521,6 +708,15 @@ function formatSidebar(
521708 ),
522709 );
523710 }
711+ if (jumping) {
712+ locationLines.push(
713+ formatLine(
714+ "JumpDest",
715+ resolveSystemName(jumpTargetId, snapshot, state),
716+ width,
717+ ),
718+ );
719+ }
524720 pushSection("Location", locationLines);
525721
526722 const poiLines = formatPoiLines(pois, system?.pois, width);
@@ -562,6 +758,19 @@ function styleLine(line: string): string {
562758 return line;
563759 }
564760
761+function resolveSystemName(
762+ systemId: string | null | undefined,
763+ snapshot: WorldSnapshot,
764+ state: ClientState,
765+): string {
766+ if (!systemId) return "Unknown";
767+ if (snapshot.system?.id === systemId && snapshot.system.name)
768+ return snapshot.system.name;
769+ if (state.system?.id === systemId && state.system.name)
770+ return state.system.name;
771+ return systemId;
772+}
773+
565774 function resolvePoiName(
566775 poiId: string | null | undefined,
567776 snapshot: WorldSnapshot,