xonecas.io
5875
Os

ollama-space-molt-player / commit 0795cc6

feat: add stranded detection and recovery guidance to action prompt

xonecas2026-02-01 0795cc60485a768590a0a3fccddee3f8ecc941f9 parent 97fc975

1 file changed

src/prompt.ts+27−0
@@ -126,6 +126,18 @@ function getEmpireDescription(empire: EmpireID): string {
126126 }
127127 }
128128
129+function isStranded(state: ClientState, snapshot?: WorldSnapshot): boolean {
130+ const player = state.player;
131+ const ship = state.ship;
132+ if (!player || !ship) return false;
133+ if (player.docked_at_base) return false;
134+ if (ship.fuel > 0) return false;
135+ const currentPoi = snapshot?.poi ?? state.poi;
136+ const hasBase =
137+ Boolean(currentPoi?.base_id) || Boolean(snapshot?.base ?? state.base);
138+ return !hasBase;
139+}
140+
129141 const HELP_TEXT = `Available actions:
130142 ==========================
131143
@@ -195,6 +207,14 @@ export function buildActionPrompt(context: PromptContext): string {
195207 REPETITION DETECTED: You performed "${context.repetitionWarning.action}" ${context.repetitionWarning.count} times in a row without progress.
196208 STOP this action immediately. Choose something DIFFERENT or set a new goal.
197209 If your goal is blocked or impossible, abandon it now.
210+`
211+ : "";
212+ const strandedBlock = isStranded(context.state, context.worldSnapshot)
213+ ? `
214+STRANDED: Fuel is 0 and there is no base at this POI.
215+Travel/jump/refuel/dock will FAIL. Do NOT repeat those actions.
216+Ask for help or wait. Recommended actions: say, faction, msg, forum, forum_post, forum_reply, help, wait.
217+Example: {"goal":"Request rescue","action":"faction","args":{"content":"Stranded with 0 fuel at current system/POI. Need assistance."}}
198218 `
199219 : "";
200220
@@ -228,6 +248,7 @@ ${getPersonalityGuidance(personality)}
228248 YOUR SPEECH STYLE: ${speechStyleInfo.name}
229249 ${getSpeechStyleGuidance(speechStyle)}
230250 ${warningBlock}
251+${strandedBlock}
231252 CURRENT STATE:
232253 ${stateText}
233254
@@ -272,10 +293,12 @@ ERROR RECOVERY:
272293 - If an action FAILED in recent memory, do NOT retry it with the same arguments.
273294 - Change your approach: try a different action, move to a different location, or update your goal.
274295 - Common fixes: dock before refuel/repair, travel to belt before mine, undock before travel/jump.
296+- If fuel is 0 and there is no base at your current POI, travel/jump/refuel/dock will fail. Ask for help or wait.
275297
276298 GAMEPLAY HEURISTIC (use as a tie-breaker):
277299 - In combat: attack or scan nearby targets
278300 - Docked and damaged/low fuel: repair or refuel
301+- Stranded (fuel=0, not docked, no base here): request help via say/faction/msg or wait
279302 - Docked with cargo: sell; with credits and listings: buy
280303 - At asteroid belt with cargo space: mine
281304 - Need station services: dock first
@@ -541,6 +564,10 @@ function formatWorldSnapshot(
541564 lines.push(
542565 `Base: ${base.name} (${base.id}) services=${services || "none"}`,
543566 );
567+ } else if (currentPoi?.base_id) {
568+ lines.push(`Base: ${currentPoi.base_id} (details unavailable)`);
569+ } else {
570+ lines.push("Base: none");
544571 }
545572
546573 if (state.nearby?.length) {