diff --git a/src/services/deepseek.ts b/src/services/deepseek.ts index a178ff0..e5027cb 100644 --- a/src/services/deepseek.ts +++ b/src/services/deepseek.ts @@ -267,6 +267,7 @@ ${story.plot}`; export function buildDynamicContext( session: GameSession, messageCount?: number, + hasCustomRules?: boolean, ): string { const state = session.currentState; const summary = session.storySummary || "The story just began."; @@ -275,8 +276,9 @@ export function buildDynamicContext( : "No significant events yet."; // Add rule reminders after 10+ messages to prevent drift + // Skip if story has custom rules - they take priority const ruleReminder = - messageCount && messageCount >= 10 + messageCount && messageCount >= 10 && !hasCustomRules ? ` === REMINDER === @@ -326,8 +328,9 @@ export async function generateStoryResponse( const worldContext = buildWorldContext(story); // 3. Dynamic context (state + summary + rule reminders after 10+ messages) + const hasCustomRules = Boolean(story.narrativeRules?.trim()); const dynamicContext = session - ? buildDynamicContext(session, chatHistory.length) + ? buildDynamicContext(session, chatHistory.length, hasCustomRules) : ""; // 4. Last N messages (not the full history!) @@ -363,8 +366,9 @@ export async function generateStoryResponseStream( ): Promise { const styleRules = buildStyleRules(story, player); const worldContext = buildWorldContext(story); + const hasCustomRules = Boolean(story.narrativeRules?.trim()); const dynamicContext = session - ? buildDynamicContext(session, chatHistory.length) + ? buildDynamicContext(session, chatHistory.length, hasCustomRules) : ""; const recentMessages = chatHistory.slice(-RECENT_MESSAGES_COUNT); const systemPrompt = styleRules + "\n" + worldContext + "\n" + dynamicContext;