diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index e7123e9..f68d59b 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -171,6 +171,9 @@ jobs:
--exclude='docs/' \
--exclude='*.csproj' \
--exclude='*.sln' \
+ --exclude='.coderabbit.yaml' \
+ --exclude='.pre-commit-config.yaml' \
+ --exclude='INTRODUCTION.txt' \
--exclude='.gitignore' \
--exclude='.gitattributes' \
--exclude='*.md' \
diff --git a/About/About.xml b/About/About.xml
index 214bbb2..868da32 100644
--- a/About/About.xml
+++ b/About/About.xml
@@ -8,7 +8,75 @@
1.6
1.7
- AI-driven dialogue system for RimWorld colonists. Intercepts game events to generate contextual AI responses, injects dialogue Thoughts, and allows player-initiated conversations. [v2.0 BREAKING CHANGES]
+ [h1]RimMind - Dialogue (v2.0)[/h1]
+Contextual social dialogue, native spoken ToolCalls, and overhead speech bubble system for RimWorld colonists. Powered by the structured [code]express_dialogue[/code] function-calling pipeline, colonists converse naturally during dining, work shifts, recreation, and crisis moments—dynamically shaping moods and interpersonal relationships.
+
+[b]v2.0 Clean Architecture & RimWorld 1.6 / 1.7 Dual-Version Support:[/b]
+[list]
+[*][b]RimWorld 1.6 & 1.7 (Waylith / .NET 10) Ready[/b]: Native multi-target compilation supporting both RimWorld 1.6 (.NET Framework 4.8) and RimWorld 1.7 (.NET 10 / Harmony 2.x & 3.x).
+[*][b]v2.0 Native [code]express_dialogue[/code] ToolCall Pipeline[/b]: Transmits spoken lines ([code]reply[/code]), inner psychological subtext ([code]thought[/code]), and relationship delta ([code]relation_delta[/code]) as structured tool calls. Note: v1.x saves are not compatible with v2.0.
+[*][b]Multi-Stage Anti-Pollution Sanitizer[/b]: [code]DialogueTextSanitizer[/code] strips [code]think[/code] reasoning blocks, code fences, and raw JSON fragments so overhead speech bubbles remain 100% clean and immersive.
+[/list]
+
+[h2]What Is RimMind[/h2]
+RimMind is an enterprise-grade, AI-powered RimWorld mod suite. Integrated with Large Language Models (LLM), it transforms colonists into self-reflecting agents with distinct personalities, three-tier memories, natural spoken dialogues, autonomous mechanisms, and dynamic storytelling.
+
+[h2]Sub-mod List & Dependency Relationships[/h2]
+[table]
+[tr][th]Mod[/th][th]Responsibility[/th][th]Dependencies[/th][th]GitHub[/th][/tr]
+[tr][td]RimMind-Core[/td][td]LLM runtime, 4-Zone context engine, async queue, ToolCall registry & F8 Hub[/td][td]Harmony[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Core]Link[/url][/td][/tr]
+[tr][td]RimMind-Actions[/td][td]Composite ToolCall mechanisms, battlefield triage & autonomous construction[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Actions]Link[/url][/td][/tr]
+[tr][td]RimMind-Advisor[/td][td]Colonist self-reflective advice cards, 5-domain autonomy & player approval[/td][td]Core, Actions[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Advisor]Link[/url][/td][/tr]
+[tr][td][b]RimMind-Dialogue[/b][/td][td]Contextual spoken dialogue via express_dialogue ToolCall & speech bubbles[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Dialogue]Link[/url][/td][/tr]
+[tr][td]RimMind-Memory[/td][td]3-Tier cognitive memory hierarchy, work aggregation & temporal decay[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Memory]Link[/url][/td][/tr]
+[tr][td]RimMind-Personality[/td][td]Big-Five psychological profiles, dawn monologues & dynamic mood thoughts[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Personality]Link[/url][/td][/tr]
+[tr][td]RimMind-Storyteller[/td][td]AI Story Director, dramatic tension curve, chained arcs & Storyteller Altar[/td][td]Core, Memory[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Storyteller]Link[/url][/td][/tr]
+[tr][td]RimMind-Extension-ModelService[/td][td]Multi-provider routing, Anthropic KV cache, local gateways & load balancing[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Extension-ModelService]Link[/url][/td][/tr]
+[tr][td]RimMind-Bridge-RimChat[/td][td]RimChat compatibility bridge: dialogue/action mutual exclusion & context sync[/td][td]Core, RimChat[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Bridge-RimChat]Link[/url][/td][/tr]
+[tr][td]RimMind-Bridge-RimTalk[/td][td]RimTalk compatibility bridge: bubble harmonization & bidirectional context[/td][td]Core, RimTalk[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Bridge-RimTalk]Link[/url][/td][/tr]
+[/table]
+[code]Core ──┬── Actions ── Advisor
+ ├── Dialogue
+ ├── Memory ── Storyteller
+ ├── Personality
+ ├── Extension-ModelService
+ ├── Bridge-RimChat
+ └── Bridge-RimTalk[/code]
+
+[h2]Core Features[/h2]
+[list]
+[*][b]Event-Responsive & Proximity Banter[/b] - Replaces vanilla Chitchat and DeepTalk with context-aware AI conversations when awake colonists are within 6.9 tiles during dining, crafting, or relaxation, plus monologues on injuries, skill milestones, and mood swings.
+[*][b]Player-Initiated Multi-Turn Chat[/b] - Start direct conversations via pawn Gizmo buttons or right-click menus with persistent session memory.
+[*][b]Dynamic Relationship & Thought Injection[/b] - Conversations apply real-time social opinion modifiers (-5 to +5) and inject emotional Thoughts ([i]ENCOURAGED, VALUED, CONNECTED, HURT, STRESSED, IRRITATED[/i]) that affect colonist mood and notify [code]RimMind-Advisor[/code].
+[*][b]Strict Liveness & Consciousness Gating[/b] - Guarded by [code]RimMindPawnLookup[/code] so sleeping, downed, dead, imprisoned, or off-map pawns never emit ghost dialogues.
+[*][b]Draggable Floating Chat HUD & History Log[/b] - Real-time corner dialogue overlay with adjustable opacity, plus a categorized dual-panel conversation log window.
+[/list]
+
+[h2]Trigger Scenarios[/h2]
+[table]
+[tr][th]Trigger Source[/th][th]Description[/th][th]Interaction Type[/th][/tr]
+[tr][td]Social Interaction[/td][td]Overrides vanilla Chitchat & DeepTalk between nearby awake colonists[/td][td]Two-Party Dialogue & Reply Chain[/td][/tr]
+[tr][td]Health & Injury[/td][td]Reacts to combat wounds, illnesses, or recovery[/td][td]Personal Monologue[/td][/tr]
+[tr][td]Skill Milestones[/td][td]Celebrates or reflects on skill level upgrades[/td][td]Personal Monologue[/td][/tr]
+[tr][td]Mood Fluctuations[/td][td]Reacts when mood shifts exceed configured threshold[/td][td]Personal Monologue[/td][/tr]
+[tr][td]Player Manual Chat[/td][td]Initiated via pawn Gizmo or right-click menu[/td][td]Multi-Turn Interactive Chat[/td][/tr]
+[/table]
+
+[h2]Thought Tags & Mood Impacts[/h2]
+[table]
+[tr][th]Tag[/th][th]Mood Offset[/th][th]Description[/th][/tr]
+[tr][td]VALUED / CONNECTED[/td][td]+2[/td][td]Feeling appreciated and emotionally close to companions[/td][/tr]
+[tr][td]ENCOURAGED[/td][td]+1[/td][td]Reassured by supportive words[/td][/tr]
+[tr][td]HURT / IRRITATED[/td][td]-1[/td][td]Stung or annoyed by friction in conversation[/td][/tr]
+[tr][td]STRESSED[/td][td]-2[/td][td]Weighed down by tense exchanges[/td][/tr]
+[/table]
+
+[h2]Frequently Asked Questions[/h2]
+[b]Q: Will dialogues slow down the game?[/b]
+A: No. Requests run asynchronously in the background with per-pawn and per-pair cooldowns.
+
+[b]Q: Does it conflict with RimTalk or RimChat?[/b]
+A: Use [code]RimMind-Bridge-RimTalk[/code] or [code]RimMind-Bridge-RimChat[/code] for automatic mutual exclusion gating and unified bubble rendering.
brrainz.harmony
diff --git a/Source/Comps/CompRimMindDialogue.cs b/Source/Comps/CompRimMindDialogue.cs
index 75d44d4..15c123f 100644
--- a/Source/Comps/CompRimMindDialogue.cs
+++ b/Source/Comps/CompRimMindDialogue.cs
@@ -13,16 +13,17 @@ public class CompRimMindDialogue : ThingComp
{
private int _lastTriggerTick = -99999;
- private Pawn Pawn => (Pawn)parent;
+ private Pawn? PawnOrNull => parent as Pawn;
+ private Pawn? Pawn => parent as Pawn;
public override void CompTick()
{
base.CompTick();
- if (!Pawn.IsColonist) return;
+ if (parent is not Pawn pawn || !pawn.IsColonist) return;
var settings = RimMindDialogueSettings.Get();
if (!settings.enabled || !settings.autoDialogueEnabled) return;
- // Sample natural encounters every 250 ticks (≈4 seconds)
- if (!Pawn.IsHashIntervalTick(250)) return;
+ // Sample natural encounters every 250 ticks (~4 seconds)
+ if (!pawn.IsHashIntervalTick(250)) return;
if (!RimMindAPI.IsConfigured()) return;
if (!IsEligible()) return;
@@ -39,41 +40,41 @@ public override void CompTick()
if (nearbyCompanion != null)
{
// Dining Encounter (Shared Meal)
- if (Pawn.CurJob?.def == JobDefOf.Ingest && nearbyCompanion.CurJob?.def == JobDefOf.Ingest)
+ if (pawn.CurJob?.def == JobDefOf.Ingest && nearbyCompanion.CurJob?.def == JobDefOf.Ingest)
{
- float dynamicChance = CalculateDynamicSocialChance(settings.diningSocialChance, Pawn, nearbyCompanion, activityScale);
+ float dynamicChance = CalculateDynamicSocialChance(settings.diningSocialChance, pawn, nearbyCompanion, activityScale);
if (settings.enableDiningSocial && Rand.Value < dynamicChance)
{
string contextMsg = "RimMind.Dialogue.Context.DiningEncounter".Translate(nearbyCompanion.LabelShort);
- TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
+ TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
return;
}
}
// Recreation Encounter (Shared Play / Joy)
- if (Pawn.CurJob?.def?.joyKind != null && nearbyCompanion.CurJob?.def?.joyKind != null)
+ if (pawn.CurJob?.def?.joyKind != null && nearbyCompanion.CurJob?.def?.joyKind != null)
{
- float dynamicChance = CalculateDynamicSocialChance(settings.recreationSocialChance, Pawn, nearbyCompanion, activityScale);
+ float dynamicChance = CalculateDynamicSocialChance(settings.recreationSocialChance, pawn, nearbyCompanion, activityScale);
if (settings.enableRecreationSocial && Rand.Value < dynamicChance)
{
string contextMsg = "RimMind.Dialogue.Context.RecreationEncounter".Translate(nearbyCompanion.LabelShort);
- TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
+ TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
return;
}
}
// Co-working Encounter (Working side-by-side)
- if (Pawn.CurJob != null && nearbyCompanion.CurJob != null)
+ if (pawn.CurJob != null && nearbyCompanion.CurJob != null)
{
- if (!IsIdleOrResting(Pawn.CurJob.def) && !IsIdleOrResting(nearbyCompanion.CurJob.def)
- && Pawn.CurJob.def != JobDefOf.Ingest && nearbyCompanion.CurJob.def != JobDefOf.Ingest
- && Pawn.CurJob.def?.joyKind == null && nearbyCompanion.CurJob.def?.joyKind == null)
+ if (!IsIdleOrResting(pawn.CurJob.def) && !IsIdleOrResting(nearbyCompanion.CurJob.def)
+ && pawn.CurJob.def != JobDefOf.Ingest && nearbyCompanion.CurJob.def != JobDefOf.Ingest
+ && pawn.CurJob.def?.joyKind == null && nearbyCompanion.CurJob.def?.joyKind == null)
{
- float dynamicChance = CalculateDynamicSocialChance(settings.coworkerSocialChance, Pawn, nearbyCompanion, activityScale);
+ float dynamicChance = CalculateDynamicSocialChance(settings.coworkerSocialChance, pawn, nearbyCompanion, activityScale);
if (settings.enableCoworkerSocial && Rand.Value < dynamicChance)
{
string contextMsg = "RimMind.Dialogue.Context.CoworkerEncounter".Translate(nearbyCompanion.LabelShort);
- TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
+ TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Chitchat, nearbyCompanion, currentTick, ref _lastTriggerTick);
return;
}
}
@@ -81,27 +82,27 @@ public override void CompTick()
}
else
{
- float mood = Pawn.needs?.mood?.CurLevel ?? 0.5f;
+ float mood = pawn.needs?.mood?.CurLevel ?? 0.5f;
float jitter = Rand.Range(0.85f, 1.15f);
// Solitary contemplation & recreation monologue
- if (Pawn.CurJobDef?.defName == "Skygaze" || Pawn.CurJobDef?.defName == "Meditate")
+ if (pawn.CurJobDef?.defName == "Skygaze" || pawn.CurJobDef?.defName == "Meditate")
{
float monologueChance = 0.35f * (mood > 0.8f || mood < 0.3f ? 1.25f : 1.0f) * jitter * activityScale;
if (settings.autoDialogueEnabled && Rand.Value < monologueChance)
{
string contextMsg = "RimMind.Dialogue.Context.ContemplationMonologue".Translate();
- TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
+ TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
return;
}
}
- else if (Pawn.CurJob?.def?.joyKind != null)
+ else if (pawn.CurJob?.def?.joyKind != null)
{
float monologueChance = (settings.recreationSocialChance * 0.4f) * jitter * activityScale;
if (settings.autoDialogueEnabled && Rand.Value < monologueChance)
{
string contextMsg = "RimMind.Dialogue.Context.RecreationMonologue".Translate();
- TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
+ TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
return;
}
}
@@ -113,37 +114,26 @@ public override void CompTick()
if (settings.autoDialogueEnabled && (currentTick - _lastTriggerTick >= idleCooldown))
{
string contextMsg = "RimMind.Dialogue.Context.IdleState".Translate();
- TryDispatchTrigger(Pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
+ TryDispatchTrigger(pawn, contextMsg, DialogueTriggerType.Auto, null, currentTick, ref _lastTriggerTick);
}
}
- ///
- /// Dynamically adjusts base social encounter chance according to:
- /// 1. Inter-pawn social opinion (-100 to +100).
- /// 2. Romantic relationship status (lovers/spouses communicate significantly more often).
- /// 3. Speaker's emotional state (cheerfulness vs deep depression).
- /// 4. Organic ±15% natural daily jitter.
- /// 5. Global ActivityFrequencyScale setting multiplier.
- ///
public static float CalculateDynamicSocialChance(float baseChance, Pawn speaker, Pawn listener, float activityScale = 1.0f)
{
float chance = baseChance * activityScale;
- // 1. Social relations & opinion modifier (-100 to +100)
if (speaker.relations != null && listener != null)
{
int opinion = speaker.relations.OpinionOf(listener);
float opinionMod = 1.0f + (opinion / 200f);
chance *= Mathf.Clamp(opinionMod, 0.30f, 1.60f);
- // Romantic partner boost (+40%)
if (LovePartnerRelationUtility.LovePartnerRelationExists(speaker, listener))
{
chance *= 1.4f;
}
}
- // 2. Speaker mood modifier (happy colonists are more communicative)
if (speaker.needs?.mood != null)
{
float mood = speaker.needs.mood.CurLevel;
@@ -151,7 +141,6 @@ public static float CalculateDynamicSocialChance(float baseChance, Pawn speaker,
else if (mood < 0.25f) chance *= 0.65f;
}
- // 3. Organic jitter (±15% natural variance)
float jitter = Rand.Range(0.85f, 1.15f);
chance *= jitter;
@@ -202,14 +191,15 @@ internal static bool TryDispatchTrigger(
private Pawn? FindNearbyCompanion()
{
- Map? map = Pawn.Map;
+ if (PawnOrNull is not Pawn pawn) return null;
+ Map? map = pawn.Map;
var spawnedColonists = map?.mapPawns?.FreeColonistsSpawned;
if (spawnedColonists == null) return null;
for (int i = 0; i < spawnedColonists.Count; i++)
{
Pawn other = spawnedColonists[i];
- if (other != null && other != Pawn && RimMindPawnLookup.IsEligibleColonist(other) && RestUtility.Awake(other) && Pawn.Position.InHorDistOf(other.Position, 6.9f))
+ if (other != null && other != pawn && RimMindPawnLookup.IsEligibleColonist(other) && RestUtility.Awake(other) && pawn.Position.InHorDistOf(other.Position, 6.9f))
{
return other;
}
@@ -219,6 +209,7 @@ internal static bool TryDispatchTrigger(
public override IEnumerable CompGetGizmosExtra()
{
+ if (PawnOrNull is not Pawn pawn) yield break;
if (!IsEligible()) yield break;
if (!RimMindDialogueSettings.Get().enabled) yield break;
if (!RimMindDialogueSettings.Get().playerDialogueEnabled) yield break;
@@ -229,7 +220,7 @@ public override IEnumerable CompGetGizmosExtra()
? "RimMind.Dialogue.UI.Gizmo.ChatWith".Translate(parent.LabelShort).ToString()
: $"Chat with {parent.LabelShort}",
icon = ContentFinder.Get("UI/RimMindDialogue_Icon", reportFailure: false),
- action = () => Find.WindowStack.Add(new Window_Dialogue((Pawn)parent))
+ action = () => Find.WindowStack.Add(new Window_Dialogue(pawn))
};
}
@@ -241,10 +232,11 @@ public override void PostExposeData()
private bool IsEligible()
{
- return RimMindPawnLookup.IsEligibleColonist(Pawn)
- && RestUtility.Awake(Pawn)
- && !(Pawn.drafter?.Drafted ?? false)
- && Pawn.needs?.mood != null;
+ return PawnOrNull is Pawn pawn
+ && RimMindPawnLookup.IsEligibleColonist(pawn)
+ && RestUtility.Awake(pawn)
+ && !(pawn.drafter?.Drafted ?? false)
+ && pawn.needs?.mood != null;
}
}
}
diff --git a/Source/Core/DialogueRequestCoordinator.cs b/Source/Core/DialogueRequestCoordinator.cs
index 62bdf9f..1b98797 100644
--- a/Source/Core/DialogueRequestCoordinator.cs
+++ b/Source/Core/DialogueRequestCoordinator.cs
@@ -300,6 +300,7 @@ void ReportFailure(string error, bool showAutomaticError = true)
.WithToolDispatchMode(ToolCallDispatchMode.Manual)
.WithMaxTokens(800)
.WithTemperature(type == DialogueTriggerType.PlayerInput ? 0.85f : 0.8f)
+ .WithReasoningEffort(ReasoningEffort.None)
.WithCancellation(lifetime.Token);
if (!string.IsNullOrEmpty(speakerName))
{
diff --git a/Source/Patches/AddCompToHumanlikePatch.cs b/Source/Patches/AddCompToHumanlikePatch.cs
index 5ed74c8..cdc66a9 100644
--- a/Source/Patches/AddCompToHumanlikePatch.cs
+++ b/Source/Patches/AddCompToHumanlikePatch.cs
@@ -13,6 +13,8 @@ public static class AddCompToHumanlikePatch
[HarmonyPostfix]
public static void Postfix(ThingDef __instance)
{
+ if (__instance == null || __instance.IsCorpse) return;
+ if (__instance.thingClass == null || !typeof(Pawn).IsAssignableFrom(__instance.thingClass)) return;
if (__instance.race?.intelligence != Intelligence.Humanlike) return;
__instance.comps ??= new List();